Commit Graph
330 Commits
Author SHA1 Message Date
Masayuki Nakano e468aa0600 Bug 1801028 - part 1: Make HTMLEditor::IsRemovableParentStyleWithNewSpanElement take EditorInlineStyle r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D162501
2022-11-25 00:12:58 +00:00
Masayuki Nakano 29d339af74 Bug 1793694 - part 2: Move some protected inline method definitions of HTMLEditor to non-exposed header r=m_kato
Depends on D158631

Differential Revision: https://phabricator.services.mozilla.com/D158632
2022-10-12 02:44:18 +00:00
Masayuki Nakano 6a157a88b2 Bug 1793694 - part 1: Move some static inline methods of HTMLEditor to HTMLEditUtils r=m_kato
Depends on D158483

Differential Revision: https://phabricator.services.mozilla.com/D158631
2022-10-12 02:44:17 +00:00
Masayuki Nakano af5b2b3933 Bug 1792642 - Make SplitNodeResult treated as ok type of Result r=m_kato
Depends on D158333

Differential Revision: https://phabricator.services.mozilla.com/D158334
2022-10-04 07:28:10 +00:00
Masayuki Nakano f95e379091 Bug 1792641 - Make JoinNodesResult treated as ok type of Result r=m_kato
Depends on D158332

Differential Revision: https://phabricator.services.mozilla.com/D158333
2022-10-03 23:17:02 +00:00
Masayuki Nakano 12cb1be55f Bug 1792639 - Make SplitRangeOffFromNodeResult treated as ok type of Result r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158332
2022-10-03 07:52:45 +00:00
Masayuki Nakano b7ee3d1410 Bug 1792624 - Make SplitRangeOffResult treated as ok type of Result r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158243
2022-10-03 01:19:59 +00:00
Masayuki Nakano 767307c38d Bug 1791501 - Use EditActionResult as ok type of mozilla::Result r=m_kato
Any callers do not refer "ignored", "handled" and "cancel" state without
checking whether the method returns error or not.  Therefore, error state
can be (and should be) managed by `mozilla::Result`'s error state.

Perhaps, it should store a caret position later because deletion handlers
of `HTMLEditor` use it, but update `Selection` immediately.

Differential Revision: https://phabricator.services.mozilla.com/D158080
2022-09-28 07:21:37 +00:00
Masayuki Nakano 21ac65a3c0 Bug 1791224 - Use CreateNodeResultBase as the ok type of mozilla::Result r=m_kato
Similar to the previous patch, this changes a lot of lines.  However, I think
that it's not so hard to investigate regression point in this patch because
`CreateNodeResultBase` is not used so many times at handling on edit action.

Differential Revision: https://phabricator.services.mozilla.com/D157575
2022-09-28 04:00:19 +00:00
Butkovits Atila b4aaa49444 Backed out changeset 865c5d292958 (bug 1791224) for causing build bustages at Result.h. CLOSED TREE 2022-09-27 11:55:04 +03:00
Masayuki Nakano 099575b4bf Bug 1791224 - Use CreateNodeResultBase as the ok type of mozilla::Result r=m_kato
Similar to the previous patch, this changes a lot of lines.  However, I think
that it's not so hard to investigate regression point in this patch because
`CreateNodeResultBase` is not used so many times at handling on edit action.

Differential Revision: https://phabricator.services.mozilla.com/D157575
2022-09-27 05:12:05 +00:00
Masayuki Nakano f1a20cf34a Bug 1791223 - Use MoveNodeResult as the ok type of mozilla::Result r=m_kato
Unfortunately, it's hard to split this (and similar) patch because we need to
touch `MoveNodeResult` itself for making it available as the ok type of
`Result`.  However, I guess that it's not so hard to investigate regression
point if something would be found later because `MoveNodeResult` is mainly
used by deletion which is the most complicated part of `HTMLEditor`, but
`MoveNodeResult` is used only in a few cases.

Differential Revision: https://phabricator.services.mozilla.com/D157574
2022-09-26 00:56:46 +00:00
Masayuki Nakano ad7a74b296 Bug 1782911 - part 9: Make WhiteSpaceVisibilityKeeper::MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement stop creating empty nodes r=m_kato
It splits inline elements at the destination of first line in the right block.
However, it typically creates empty inline elements before the right block and
may be never used because it sets the insertion point to before the right node
of the splitting.

Therefore, it should stop creates empty inline elements (if they are required,
they should be created in `HTMLEditor::MoveNodeOrChildrenWithTransaction`
instead) and adjust split point after the element if it didn't split any nodes.

Differential Revision: https://phabricator.services.mozilla.com/D157418
2022-09-25 12:49:46 +00:00
Magnus Melin 56eb9483d1 Bug 1790725 - Allow useCss for mail editor. r=masayuki
After this change, it's possible to set the pref, or use editor.document.execCommand("styleWithCSS", false, "true") to enable css in mail compose.

Differential Revision: https://phabricator.services.mozilla.com/D157276
2022-09-14 10:27:39 +00:00
Makoto Kato 93b5820110 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
Masayuki Nakano 4b66b7255f 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 a31e91fc29 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 e4d1127db6 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 00ff420891 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 ab78a6de30 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 e4df4c43e2 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 259bd9426d 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 43343bb803 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 4c09fdbb5c 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 a0ac0a7ca4 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 54a054333a 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 4c29eb8cdc 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 35739345a7 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 7c4721729d 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 2f63891f53 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 6a7b048277 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
Masayuki Nakano 830bd376e2 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 eb8aafe328 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 0ec00dc9b2 Bug 1780140 - Make HTMLEditor::ClearStyleAt clean up new empty inline elements which are not contain new text r=m_kato
Currently, `HTMLEditor` assumes that padding `<br>` element for empty last line
is outside of inline elements, but it may happen because of both:
* starting from bug 1778091, `HTMLEditor` move `<br>` element into new empty
inline elements at inserting new paragraph.
* web apps can put it into inline elements.

After splitting inline elements and which do not have meaningful content, users
cannot put caret into the empty inline elements so that the elements stay unless
delete around there.

For avoiding the leak due to meaningless elements, we should delete them at
splitting inline elements at inserting new text.

Note that Chrome does not pass the new tests of resetting ancestor bold style
because Chrome wraps the `<b>` with `<i>`, however, the `<i>` has odd
`style=""`.  Perhaps, the test framework should ignore it because it's not
important for the web-compatibility.

On the other hand, Chrome completely fails only the last testcase since it
unwraps the `<b>` from the last `<br>`, so the bold style which was applied by
the web app to the last `<br>` is lost.  This is not reasonable.

Differential Revision: https://phabricator.services.mozilla.com/D152616
2022-07-27 22:51:18 +00:00
Masayuki Nakano 96a5673280 Bug 1774114 - Make HTMLEditor and its helper classes get split/join node direction dynamically r=m_kato
Currently I'm think that the split/join node direction should be managed per
`HTMLEditor` instance because per transaction makes undo/redo handling
complicated and may require additional space to save it in each transaction
instance.  However, the direction should be changeable with new Gecko specific
`execCommand` to support both direction until creating first split/join node
transaction or anytime with clearing the transactions.

Differential Revision: https://phabricator.services.mozilla.com/D149192
2022-07-01 02:02:03 +00:00
Masayuki Nakano 99aa2d876f Bug 1770877 - part 35: Make HTMLEditor::SetInlinePropertyOnNode and HTMLEditor::SetInlinePropertyOnNodeImpl stop touching Selection directly r=m_kato
Note that `CSSEditUtils` does not change `Selection` except
`RemoveCSSInlineStyleWithTransaction` which is used only by aligning in a block.
Therefore, this patch does not touch `CSSEditUtils`.

Differential Revision: https://phabricator.services.mozilla.com/D149106
2022-06-22 12:57:51 +00:00
Masayuki Nakano 54b1c30eba Bug 1770877 - part 34: Make HTMLEditor::RemoveStyleInside stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149105
2022-06-22 12:36:37 +00:00
Masayuki Nakano db9c8aa4f4 Bug 1770877 - part 33: Make HTMLEditor::RelativeFontChangeOnTextNode stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149104
2022-06-22 08:18:40 +00:00
Masayuki Nakano 788f5cd59f Bug 1770877 - part 32: Make HTMLEditor::InsertContainerWithTransaction stop touching Selection directly r=m_kato
This changes the behavior a little bit, unfortunately.

`InsertContainerWithTransaction` starts return code.  And the behavior changed
WPTs are hit here:
https://searchfox.org/mozilla-central/rev/a8bdd0feeb7ae596a202333ee324a68153f9f4c4/editor/libeditor/EditorBase.cpp#2179-2180

Then, the editor specific error will be converted to `NS_OK` at the
corresponding public method.  Therefore, the return code may be changed from
`NS_ERROR_FAILURE` to `NS_OK`, and that causes the return value change of
`Document.execCommand`.

Differential Revision: https://phabricator.services.mozilla.com/D149103
2022-06-22 08:04:26 +00:00
Masayuki Nakano 8b7dbfe141 Bug 1772022 - Make EditorBase::DeleteNodeWithTransaction() return NS_ERROR_EDITOR_DESTROYED if so r=m_kato
Its callers check `EditorBase::Destroyed()` with at least adding 4 lines, and
some callers do not check this important state.  So, we should make it check
`Destroyed()` at last and omit the additional error check in the caller sites.

Note that it's a virtual method, but `HTMLEditor` checks whether it's a
removable node or not.  So, we should can merge it into `EditorBase`.  This
patch does it too.

Differential Revision: https://phabricator.services.mozilla.com/D148084
2022-06-03 02:03:47 +00:00
Masayuki Nakano e274b4ce87 Bug 1766355 - part 7: Rewrite HTMLEditor::RemoveContainerWithTransaction with MoveNodeTransaction and make it stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146403
2022-05-20 09:01:40 +00:00
Masayuki Nakano 7bfa21cc89 Bug 1766355 - part 4: Make HTMLEditor::MoveNodeWithTransaction and HTMLEditor::MoveNodeToEndWithTransaction return MoveNodeResult r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D146400
2022-05-20 08:28:09 +00:00
Masayuki Nakano 6d0743491e Bug 1767386 - part 2: Make HTMLEditor::RemoveInlinePropertyInternal stop setting/removing style of an element if it's removed by RemoveStyleInside r=m_kato
`CSSEditUtils` will refer the composed document of the element to compute the
style of it.  However, it'll fail if `RemoveStyleInside` has already removed
the element from the DOM tree.  Therefore, `RemoveInlinePropertyInternal`
should stop handling the element immediately after calling `RemoveStyleInside`
if the element is removed.

Depends on D145303

Differential Revision: https://phabricator.services.mozilla.com/D145304
2022-05-09 06:03:21 +00:00
Masayuki Nakano 3838efc999 Bug 1767386 - part 1: Make some CSSEditUtils methods using GetCSSEquivalentToHTMLInlineStyleSetInternal return error with Result r=m_kato
`CSSEditUtils::GetCSSEquivalentToHTMLInlineStyleSetInternal` may return error
which is unexpected.  And the methods changed by this patch may cause destroying
editor if and only if they treat computed style.  Therefore, they should be
non-static members and they should return error to make each caller avoid the
unexpected cases if necessary.

Differential Revision: https://phabricator.services.mozilla.com/D145303
2022-05-09 06:03:21 +00:00
Masayuki Nakano e67e2e79b6 Bug 1762115 - part 7: Make HTMLEditor::SplitNodeDeepWithTransaction stop touching Selection r=m_kato
Now, it does not require to update selection, and its result may have a point
to put caret it is used to doing.  This patch makes it stop collapsing selection
after each split, and instead, makes all callers of it collapse selection if
it's (probably) necessary.

Note that the method may not split any nodes but return it as "handled".
Therefore, the callers do not check whether a splitting node occurred **but**
suggesting point to put caret is invalid or the other cases.  Therefore, in
strictly speaking, this patch changes the existing behavior, but it should not
affects web apps in the wild because of the low usage of the legacy mutation
event listeners.

Differential Revision: https://phabricator.services.mozilla.com/D144650
2022-05-03 00:19:16 +00:00
Masayuki Nakano 21f26a7ae8 Bug 1762115 - part 6: Make HTMLEditor::SplitNodeWithTransaction stop touching Selection directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D144649
2022-05-03 00:12:01 +00:00
Masayuki Nakano adea39d1ad Bug 1762115 - part 5: Make SplitNodeResult store and suggest new caret position r=m_kato
This patch allows methods which split some nodes to return new candidate
caret position and makes callers of them consider whether applying it to
the selection immediately or not.

Differential Revision: https://phabricator.services.mozilla.com/D144648
2022-05-03 00:06:16 +00:00
Masayuki Nakano af5e61f89c Bug 1761395 - part 5: Make HTMLEditor::SplitNode(Deep)WithTransaction callers refer SplitNodeResult for post-processing r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D142416
2022-04-05 07:02:46 +00:00
Masayuki Nakano e95a9c8c24 Bug 1761159 - Make constructors of SplitNodeResult take content nodes with logical meaning rather than physical meaning r=m_kato
Like `JoinNodesResult`, `SplitNodeResult` should take 2 content nodes as
"new one" and "original one" instead of "previous one" and "next one".
Then, the creators is easier to read.

Additionally, this patch creates some static methods and converter method
to create a result with explaining the result meaning.

Differential Revision: https://phabricator.services.mozilla.com/D141930
2022-03-25 01:00:36 +00:00
Masayuki Nakano 22aa786ab3 Bug 1753508 - Add logger of selection batch r=smaug
This was required for debugging the bug.

Differential Revision: https://phabricator.services.mozilla.com/D139350
2022-03-11 02:24:24 +00:00