Commit graph

11151 commits

Author SHA1 Message Date
Masayuki Nakano
b6c7be1c68 Bug 1789344 - Make SelectionState::DidMoveNode track DOM points having pointed the moved content correctly r=m_kato
When selection is `abc<b>[def</b>]ghi`, `insertParagraph` command will delete
the `<b>` element first, then, `Selection` becomes `abc{}ghi`.  Then,
`HTMLEditor::InsertParagraphSeparatorAsSubAction` wraps all of the line in
the default paragraph, `<div>`, with
`HTMLEditor::FormatBlockContainerWithTransaction` (although this is incompatible
behavior with the other browsers).  At this time, new `<div>` is inserted before
the first text node and then, move the text nodes into the new `<div>`.

However, `RangeUpdater::DidMoveNode` just slides the offsets if containers of
registered DOM points are the ex-parent of the moving nodes.  Therefore, the
tracked selection range in `HTMLEditor::FormatBlockContainerWithTransaction`
become `<div></div>abc{}def`, then, `<div>abcdef</div>{}`, but the expected
behavior is of course, `<div>abc{}def</div>`, then, split the new `<div>`.

So the problem is, `DidMoveNode` assumes that DOM points won't point the moving
content node.  If the node is pointed, it should keep pointing in the new
parent.

Note that the expectations of new tests are based on Chrome, therefore, the
new known failures are incompatible with Chrome.

Differential Revision: https://phabricator.services.mozilla.com/D156798
2022-09-12 23:53:37 +00:00
Masayuki Nakano
2d65dbd85c Bug 1789345 - Make editor/libeditor/test_bug1318312.html easier to read r=m_kato
It's hard to know how some tests failed in test_bug1318312.html.  Therefore,
this patch makes the selection range comparison easier to read, and add
description to explain what was doing at the failure.

Differential Revision: https://phabricator.services.mozilla.com/D156526
2022-09-07 01:06:47 +00:00
Ting-Yu Lin
527e28018e Bug 1779846 - Remove an unneeded if-statement in TextServicesDocument::OffsetEntryArray::FindWordRange(). r=masayuki
This patch fixed a regression caused by Bug 1730084 Part 4
https://phabricator.services.mozilla.com/D125434, which is intended to preserve
the behavior of `WordBreaker::FindWord()`.

Before Bug 1730084 Part 4, `WordBreaker::FindWord()` returns
`[aTextLen + 1, aTextLen + 1]` only when `aOffset > aTextLen`.
But `WordBreaker::FindWord()` had an assertion `aOffset <= aTextLen`
to guarantee the caller never passes `aOffset > aTextLen`. Thus, we can never
go into the `if (res.mBegin > strLen)` in
`TextServicesDocument::OffsetEntryArray::FindWordRange()`.

However, Bug 1730084 Part 4 wrongly changes the if-statement to
`if (range.mEnd == range.mBegin)`, and makes it reachable when
`TextServicesDocument::OffsetEntryArray::FindWordRange()` passes
`aPos == aLen` into `WordBreaker::FindWord()`. This makes `InitSpellChecker()`
failed when `enableSelectionChecking=true`.

This patch deletes the originally unreachable error handling if-statement, and
adds an assertion to guarantee `strOffset` and `strLen` is valid.

Differential Revision: https://phabricator.services.mozilla.com/D156210
2022-09-02 18:52:36 +00:00
Makoto Kato
fa04356be7 Bug 1787680 - Part 2. Don't create CSSEditUtils instance. r=masayuki
We can change all methods in `CSSEditUtils` to static method if we add
`HTMLEditor` parameter.

Differential Revision: https://phabricator.services.mozilla.com/D155976
2022-09-01 04:33:36 +00:00
Makoto Kato
4d903283b4 Bug 1787680 - Part 1. Move mIsCSSPrefChecked to HTMLEditor. r=masayuki
`CSSEditUtils::IsCSSPrefChecked` is used in HTMLEditor only, so we can move
`mIsCSSPrefChecked` to HTMLEditor.

Differential Revision: https://phabricator.services.mozilla.com/D155975
2022-09-01 04:33:36 +00:00
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