Commit Graph

11146 Commits

Author SHA1 Message Date
Mark Banner
4f95e6b415 Bug 1786197 - Turn on ESLint rule for prefer-boolean-length-check for editor. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D155169
2022-08-26 13:39:36 +00:00
Masayuki Nakano
64fe7ed79d Bug 1784192 - part 10: Make PendingStyles::GetTypeInState() return an enum class instead of taking 2 bool out parameters r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D155319
2022-08-26 03:31:26 +00:00
Masayuki Nakano
8bbdf5e967 Bug 1784192 - part 9: Rename TypeInState to PendingStyles r=m_kato
Additionally,
* `PropItem` -> `PendingStyle`
* `StyleCache` -> `PendingStyleCache`
* `AutoStyleCacheArray` -> `AutoPendingStyleCacheArray`

And finally, `PendingStyle` (formally `PropItem`) is changed to `class` and
its members are encapsuled.

Differential Revision: https://phabricator.services.mozilla.com/D155318
2022-08-26 03:31:26 +00:00
Masayuki Nakano
ef559e105f Bug 1784192 - part 8: Make scanner methods of TypeInState return Maybe<size_t> r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D155317
2022-08-26 03:25:19 +00:00
Masayuki Nakano
bfb3d1f8c6 Bug 1784192 - part 7: Rename TypeInState::ClearProp and related methods r=m_kato
For consistency with the previous patch, we should rename them too.  Then, we're
getting rid of unclear word "Prop" from the public methods.

Differential Revision: https://phabricator.services.mozilla.com/D155316
2022-08-26 03:25:19 +00:00
Masayuki Nakano
165e90f341 Bug 1784192 - part 6: Rename TypeInState::SetProp and TypeInState::TakeSetProperty r=m_kato
I usually retry to understand what they mean.  Therefore, I'd like to give new
names for them (and rename `TypeInState` class in a following patch).

Differential Revision: https://phabricator.services.mozilla.com/D155315
2022-08-26 03:20:14 +00:00
Masayuki Nakano
a94d4ffd46 Bug 1784192 - part 5: Make TypeInState manage PropItem instances with UniquePtr r=m_kato
It's ugly to manage them as raw pointer especially when deleting the instances.
We should make it use `UniquePtr`.

Differential Revision: https://phabricator.services.mozilla.com/D155314
2022-08-26 03:20:14 +00:00
Masayuki Nakano
cf8abe2061 Bug 1784192 - part 4: Change PropItem::mSpecifiedStyle to a constant r=m_kato
Only the value member needs to be updated when setting the prop multiple times.
Therefore, we cannot change all members to constants.

Differential Revision: https://phabricator.services.mozilla.com/D155313
2022-08-26 03:10:32 +00:00
Masayuki Nakano
100af2494d Bug 1784192 - part 3: Change other members of PropItem r=m_kato
According to the debug, its value can be CSS property value if in the CSS mode.
For making the value meaning easier to understand, this renames it to
mAttributeValueOrCSSValue.

Differential Revision: https://phabricator.services.mozilla.com/D155312
2022-08-26 03:10:31 +00:00
Masayuki Nakano
491bc57b81 Bug 1784192 - part 2: Change PropItem::attr to a strong pointer r=m_kato
It's currently no problem to manage it with a raw pointer because it may be
set to a dynamic atom only when `nsIHTMLEditor.insertLinkAroundSelection` is
called with unknown attribute, but comm-central uses it only with `href`
attribute.

I think that we should change the API just to take `href` value in the future,
but for now, it should be `RefPtr<nsAtom>`.

Differential Revision: https://phabricator.services.mozilla.com/D155311
2022-08-26 03:10:31 +00:00
Masayuki Nakano
66c9f821f0 Bug 1784192 - part 1: Change PropItem::tag to nsStaticAtom* r=m_kato
It's always a pointer to `nsStaticAtom` instance or `nullptr`.  Therefore,
it can be `nsStaticAtom*` and we can make its users treat `nsStaticAtom`
instead of `nsAtom`.

Additionally, this patch changes some pointer parameters to references if
they are never `nullptr`.

Differential Revision: https://phabricator.services.mozilla.com/D155310
2022-08-26 03:10:30 +00:00
Masayuki Nakano
76c16ceefc Bug 1785801 - Make RangeUpdater::SelAdjJoinNodes take the ex-offset of right node r=m_kato
In bug 1739524, I misunderstood the meaning of `aOffset` of `SelAdjJoinNodes`.

After joining 2 nodes, and a point points right node which will have ex-left
node content, the point needs to point ex-start of the right node to keep
next insertion point as-is.  Therefore, it's not useful with new join nodes
direction, it needs to know the ex-offset of the right node.

Differential Revision: https://phabricator.services.mozilla.com/D155438
2022-08-26 01:50:07 +00:00
Masayuki Nakano
94b817dc98 Bug 1785311 - Make EditorBase::InsertTextIntoTextNodeWithTransaction update insertion point after executing the transaction r=m_kato
Before the fix of bug 1758420, `TextComposition`'s text node and offset in it
are updated at creating `CompositionTransaction`.  However, it's now put off
until getting the mutations.  Therefore, it always unsets `pointToInsert` at
first time of the composition and fails to notify the listeners.

This patch makes it retrieve the result after calling `DoTransactionInternal`
and handle the post processing with the new point.

Differential Revision: https://phabricator.services.mozilla.com/D155052
2022-08-22 23:56:36 +00:00
Daniel Holbert
4209467c50 Bug 1786210: Remove mentions of unused pref gfx.font_loader.interval. r=emilio
This patch doesn't impact behavior.

The pref "gfx.font_loader.interval" used to control certain aspects of
font-loading behavior, but that code has evolved and we no longer read the
value of this pref anywhere.

Differential Revision: https://phabricator.services.mozilla.com/D155183
2022-08-21 23:45:56 +00:00
Masayuki Nakano
ff67736d1c Bug 1781994 - part 12: Make HTMLEditor::SetCSSBackgroundColorWithTransaction use similar approach as SetInlinePropertiesAsSubAction etc r=m_kato
It's a Gecko specific feature, and it sets background color of parent block
elements of selection ranges.  This does similar things to
`SetInlinePropertiesAsSubAction`, but still refers `Selection` directly and
uses `AutoSelectionRestorer`.  For consistency between similar methods, this
patch makes it use `AutoRangeArray`.

Depends on D154353

Differential Revision: https://phabricator.services.mozilla.com/D154354
2022-08-16 01:17:46 +00:00
Masayuki Nakano
0f6bbf324c Bug 1781994 - part 11: Clean up HTMLEditor::RelativeFontChange r=m_kato
It should use `AutoRangeArray` to stop using `AutoSelectionRestorer`.

Depends on D154352

Differential Revision: https://phabricator.services.mozilla.com/D154353
2022-08-16 01:17:45 +00:00
Masayuki Nakano
d1c4c5d8e2 Bug 1781994 - part 10: Make HTMLEditor::RelativeFontChangeOnNode and HTMLEditor::RelativeFontChangeHelper stop touching Selection directly r=m_kato
They are renamed to `SetFontSizeWithBigOrSmallElement` and
`SetFontSizeOfFontElementChildren`.

Depends on D154351

Differential Revision: https://phabricator.services.mozilla.com/D154352
2022-08-16 01:09:31 +00:00
Masayuki Nakano
3327432a6a Bug 1781994 - part 9: Make HTMLEditor::RelativeFontChangeOnNode and HTMLEditor::RelativeFontChangeHelper use FontSize r=m_kato
`HTMLEditor::RelativeFontChange()` and its helpers are based on
`SetInlinePropertiesAsSubAction()` and its helpers.  Therefore, they may have
similar problem to switch join/split direction.  Therefore, this and the
following patches clean them up too.

Depends on D154350

Differential Revision: https://phabricator.services.mozilla.com/D154351
2022-08-16 01:01:06 +00:00
Masayuki Nakano
648f892bde Bug 1781994 - part 8: Make HTMLEditor::SetInlinePropertyAsSubAction handle multiple styles once r=m_kato
Depends on D154349

Differential Revision: https://phabricator.services.mozilla.com/D154350
2022-08-16 01:01:05 +00:00
Masayuki Nakano
d6991deecb Bug 1781994 - part 7: Make HTMLEditor::RemoveInlinePropertyAsSubAction handle multiple styles once r=m_kato
I think that `HTMLEditor::SetInlinePropertyAsSubAction` and
`HTMLEditor::RemoveInlinePropertyAsSubAction` should not be called multiple
times in one edit action.  Therefore, I'd like to make them take multiple
styles once.  Then, we could collect all targets before touching the DOM tree
in the future.

Depends on D154348

Differential Revision: https://phabricator.services.mozilla.com/D154349
2022-08-16 00:55:06 +00:00
Masayuki Nakano
da11385641 Bug 1781994 - part 6: Make HTMLEditor::SetInlinePropertyInternal use AutoRangeArray r=m_kato
Depends on D154347

Differential Revision: https://phabricator.services.mozilla.com/D154348
2022-08-16 00:38:30 +00:00
Masayuki Nakano
9d26dd1005 Bug 1781994 - part 5: Make HTMLEditor::RemoveInlinePropertyAsSubAction handle correct text node after splitting a text to any direction r=m_kato
This is a pre-fix for bug 1735608.  Currently, the loop assumes that collected
nodes are always right node, but it'll be changed, therefore, it creates
new array for the follow up loops handle expected nodes.

Depends on D154346

Differential Revision: https://phabricator.services.mozilla.com/D154347
2022-08-16 00:31:45 +00:00
Masayuki Nakano
181da530ee Bug 1781994 - part 4: Make HTMLEditor::RemoveInlinePropertyInternal use AutoRangeArray r=m_kato
I'd like to get rid of `AutoSelectionRangeArray` and `AutoRestoreSelection`,
and I'd like to make it stop touching `Selection` while it is removing style
of each content nodes in the range.  Therefore, this patch rewrites it with
`AutoRangeArray`.  Then, we can reduce the indent level of the nested `for`
loops.

Note that it creates `AutoEditSubActionNotifier`, so it's a sub-edit action
handler.  Therefore, this patch renames it.

Depends on D154345

Differential Revision: https://phabricator.services.mozilla.com/D154346
2022-08-16 00:26:05 +00:00
Masayuki Nakano
55250ca5e0 Bug 1781994 - part 3: Make HTMLEditor::SetInlinePropertyOnTextNode stop touching Selection directly r=m_kato
Depends on D154344

Differential Revision: https://phabricator.services.mozilla.com/D154345
2022-08-16 00:13:40 +00:00
Masayuki Nakano
fcecac970b Bug 1781994 - part 2: Make HTMLEditor::SplitAncestorStyledInlineElementsAtRangeEdges stop touching Selection directly r=m_kato
Depends on D154343

Differential Revision: https://phabricator.services.mozilla.com/D154344
2022-08-16 00:08:07 +00:00
Masayuki Nakano
9f9cd9e318 Bug 1781994 - part 1: Make HTMLEditor::SplitAncestorStyledInlineElementsAt and HTMLEditor::ClearStyleAt stop touching Selection directly r=m_kato
I've already made a caller of `HTMLEditor::ClearStyleAt`,
`HTMLEditor::CreateStyleForInsertText`, in bug 1770877, so this fixes a bug of
the patch.

`HTMLEditor::ClearStyleAt` is still updates `Selection` only in some cases.
And one of the caller has not handle the `Selection` update.  Therefore, once
it completely stop touching `Selection`, `ComputeEditingHost` will fail and
the other paths update `Selection`, so it should do it too.  (Without the
change, `test_dragdrop.html` fails.)

Finally, we don't need `EditResult` anymore because we have
`Result<EditorDOMPoint, nsresult>`.

Differential Revision: https://phabricator.services.mozilla.com/D154343
2022-08-16 00:02:25 +00:00
André Bargull
8c56e722b1 Bug 1784426: Call Locale::Canonicalize() on the newly parsed locale. r=platform-i18n-reviewers,dminor
Differential Revision: https://phabricator.services.mozilla.com/D154489
2022-08-15 15:34:29 +00:00
Masayuki Nakano
64e700332c Bug 1783402 - part 3: Make result of unsafe getter methods of EditorDOMPointBase templated r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D153842
2022-08-09 01:43:24 +00:00
Masayuki Nakano
fe4e77e324 Bug 1783402 - part 2: Make result of safe getter methods of EditorDOMPointBase templated r=m_kato
Similar to the previous patch, and for consistency between editor helper
classes, we should make result of getter methods of `EditorDOMPointBase` too.

Differential Revision: https://phabricator.services.mozilla.com/D153841
2022-08-09 01:43:24 +00:00
Masayuki Nakano
2c1d4805a6 Bug 1783402 - part 1: Make result of the getter methods of SplitRangeOffFromNodeResult templated r=m_kato
We'll need the version to return `dom::Text*` in coming patches for bug 1735608.
For avoiding the class to have a lot of getters, we should make result of the
getters templated.

Differential Revision: https://phabricator.services.mozilla.com/D153840
2022-08-09 01:43:23 +00:00
Masayuki Nakano
d636f57443 Bug 1783393 - Get rid of the constructor of SplitRangeOffFromNodeResult which takes 2 SplitNodeResults r=m_kato
`GetLeftContent()` etc is explained as:
> This may return nullptr if the method didn't split at start edge of the node.

On the other hand, `SplitNodeResult::GetPreviousContent()` and
`SplitNodeResult::GetNextContent()` returns previous or next content node
of split point when the split is not performed, but not in error.

Therefore, it should check `SplitNodeResult::DidSplit()` instead of
`SplitNodeResult::isOk()`.

However, there is another problem.  The constructor cannot specify the order
of the 2 splits.  Therefore, it's hard to maintain the constructor.
Fortunately, there is only one user, so we can make the user create the
result with another constructor.

Differential Revision: https://phabricator.services.mozilla.com/D153838
2022-08-08 09:06:24 +00:00
Masayuki Nakano
982149f4f1 Bug 1782874 - part 2: Make HTMLEditor::RemoveEmptyNodesIn remove end container of the range if empty r=m_kato
If splitting node creates new right node instead of new left node,
`TopLevelEditSubActionData::mChangedRange` ends by start of the right node.
However, `RemoveEmptyNodesIn` uses `PostContentIterator` which collects DOM
nodes whose "end tag" appear in the range.  Therefore, for cleaning up new
empty right nodes correctly, we need to extend the range to contain the node.

Additionally, it removes unexpected element which is editable but shouldn't be
removed from the DOM tree.  Therefore, this patch adds new check such as
`HTMLEditUtils::IsRemovalNode()`.

Finally, this patch adds a check whether the editor is a mail editor or not
at considering whether a node is a "mail-cite" because `contenteditable` in
web apps do not need special handling for such Gecko-specific element.

Differential Revision: https://phabricator.services.mozilla.com/D153834
2022-08-08 08:22:44 +00:00
Masayuki Nakano
8b7fb928d3 Bug 1782628 - Make HTMLEditor::HandleInsertBRElement create caret position before moving its container r=m_kato
The test oddly passes without the fix in `HandleInsertBRElement`.  I guess that
post-processing in `HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal()`
handles `Selection`, and anyway the insertion point of the following
`insertText` is wrong.  It seems that we don't need to uplift this.

Differential Revision: https://phabricator.services.mozilla.com/D153832
2022-08-08 01:54:47 +00:00
Masayuki Nakano
bea9bf4233 Bug 1782852 - part 1: Get rid of unused editor commands in the wild r=smaug
`increaseFontSize`, `decreaseFontSize`, `gethtml`, `heading` and `readonly`
commands were disabled for a year in all channels, but no regression reports
have been filed.  Therefore, we can delete the commands and the telemetry
probes.

Note that `cmd_getContents` command which is the internal command of `gethtml`
is not used in comm-central too.  Therefore, this patch deletes the command
handler, `nsClipboardGetContentsCommand`, and `Command::GetHTML` too.

Differential Revision: https://phabricator.services.mozilla.com/D153720
2022-08-05 02:55:22 +00:00
Masayuki Nakano
eddeebefce Bug 1775381 - Move AutoRangeArray from EditorUtils.h to its own header and cpp file r=m_kato
Depends on D152982

Differential Revision: https://phabricator.services.mozilla.com/D153063
2022-08-04 05:39:16 +00:00
Masayuki Nakano
b938b9b105 Bug 1774704 - part 9: Get rid of EditorBase::TopLevelEditSubActionData::mNewBlockElement due to unused r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152982
2022-08-04 05:39:15 +00:00
Masayuki Nakano
aaa97aa9d5 Bug 1774704 - part 8: Make HTMLEditor::SetSelectionToAbsoluteAsSubAction stop setting TopLevelEditSubActionData::mNewBlockElement r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152981
2022-08-04 05:31:12 +00:00
Masayuki Nakano
0196645809 Bug 1774704 - part 7-7: Make HTMLEditor::AlignNodesAndDescendants stop touching Selection directly and setting mNewBlockElement r=m_kato
For doing that, this patch also making `HTMLEditor::AlignContentsAtSelection`
which the only caller of `HTMLEditor::AlignNodesAndDescendants` handle
`Selection` with `AutoRangeArray` because it uses `AutoSelectionRestorer` and
we need to adjust `Selection` after restored.

Differential Revision: https://phabricator.services.mozilla.com/D152980
2022-08-04 05:07:32 +00:00
Masayuki Nakano
3a9a1e4035 Bug 1774704 - part 7-6: Make HTMLEditor::AlignContentsInAllTableCellsAndListItems and HTMLEditor::AlignBlockContentsWithDivElement stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152979
2022-08-04 05:00:38 +00:00
Masayuki Nakano
1da47692c5 Bug 1774704 - part 7-5: Make HTMLEditor::AlignContentsAtSelectionWithEmptyDivElement stop touching Selection directly and setting mNewBlockElement r=m_kato
It's only caller is `HTMLEditor::AlignContentsAtSelection` which is called only
by `HTMLEditor::AlignAsSubAction` at almost last of it.  Therefore, it's safe
to handle `mNewBlockElement` at the caller of
`AlignContentsAtSelectionWithEmptyDivElement` is safe.

Differential Revision: https://phabricator.services.mozilla.com/D152978
2022-08-04 04:53:54 +00:00
Masayuki Nakano
3f4655f24a Bug 1774704 - part 7-4: Make HTMLEditor::SetBlockElementAlign stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152977
2022-08-04 04:40:14 +00:00
Masayuki Nakano
fd641593ca Bug 1774704 - part 7-3: Make HTMLEditor::RemoveAlignFromDescendants stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152976
2022-08-04 04:33:56 +00:00
Masayuki Nakano
efd0248a4c Bug 1774704 - part 7-2: Make CSSEditUtils::RemoveCSSInlineStyleWithTransaction stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152975
2022-08-04 04:28:13 +00:00
Masayuki Nakano
68caf865dc Bug 1774704 - part 7-1: Make HTMLEditor::EnsureHardLineBeginsWithFirstChildOf and HTMLEditor::EnsureHardLineEndsWithLastChildOf stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152974
2022-08-04 04:19:46 +00:00
Masayuki Nakano
b653b11028 Bug 1774704 - part 6: Make HTMLEditor::HandleHTMLIndentAtSelectionInternal stop touching Selection directly and stop setting mNewBlockElement r=m_kato
The change of expected assertion count in the crash test is caused by that the
test calls `execCommand` recursively from the legacy mutation event listeners.
Therefore, stopping updating `Selection` for each DOM tree change causes that
the target range in the nested edit action is changed.  However, the nested
handling has already been disabled by default, so this should not be a problem
for the users.

Differential Revision: https://phabricator.services.mozilla.com/D152973
2022-08-04 04:07:46 +00:00
Masayuki Nakano
c18ae2e047 Bug 1774704 - part 5-3: Make HTMLEditor::HandleCSSIndentAtSelectionInternal stop touching Selection directly and setting mNewBlockElement r=m_kato
It's called only by `HTMLEditor::HandleCSSIndentAtSelection` which is called
only by `HTMLEditor::HandleIndentAtSelection`.  They don't touch `Selection`
after calling it.  Therefore, we can make it adjust collapsing selection point
by itself.

Differential Revision: https://phabricator.services.mozilla.com/D152972
2022-08-04 03:16:28 +00:00
Masayuki Nakano
2296d580e7 Bug 1774704 - part 5-2: Make HTMLEditor::IndentListChild stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152971
2022-08-04 03:00:31 +00:00
Masayuki Nakano
49869c2825 Bug 1774704 - part 5-1: Make HTMLEditor::ChangeMarginStart stop touching Selection directly r=m_kato
And also this patch makes it and an its caller stop computing editing host
with the latest `Selection`.

Differential Revision: https://phabricator.services.mozilla.com/D152970
2022-08-04 02:40:57 +00:00
Masayuki Nakano
6a5e4e03e3 Bug 1774704 - part 4-4: Make HTMLEditor::ChangeSelectedHardLinesToList stop setting TopLevelEditSubActionData::mNewBlockElement r=m_kato
With taking an `AutoRangeArray` which is initialized with `Selection`, it can
restore selection and check if it's collapsed and if collapsed in the expected
list element.  Then, its caller can apply the returned range to `Selection`
because it's an edit sub-action handler.

Differential Revision: https://phabricator.services.mozilla.com/D152969
2022-08-04 02:28:11 +00:00
Masayuki Nakano
cc6f01f78c Bug 1774704 - part 4-3: Make HTMLEditor::MaybeSplitAncestorsForInsertWithTransaction stop computing editing host with current selection r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152968
2022-08-04 02:12:03 +00:00