Commit Graph
299 Commits
Author SHA1 Message Date
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
Masayuki Nakano 3e04dd7b06 Bug 1752668 - Restore null-check in HTMLEditor::ClearStyleAt r=m_kato
I don't remember why I removed the null-check in
https://phabricator.services.mozilla.com/D131748#change-Q0aewmYc3vaK

Restoring the null-check should be fine.

Differential Revision: https://phabricator.services.mozilla.com/D137395
2022-01-31 17:15:35 +00:00
Masayuki Nakano 05d0e158a9 Bug 1742748 - Make HTMLEditor::JoinNodesWithTransaction() return JoinNodesResult r=m_kato
This patch implements `JoinNodesResult` class which callers of
`JoinNodesWithTransaction()` can access removed node, existing (joined) node and
joined point with logical named accessors, and makes
`JoinNodesWithTransaction()` return it.

Then, the callers don't need to change at fixing bug 1735608.

Differential Revision: https://phabricator.services.mozilla.com/D132120
2021-11-27 00:05:54 +00:00
Masayuki Nakano a0a6850476 Bug 1739935 - Make HTMLEditor::SplitNodeWithTransaction() return SplitNodeResult r=m_kato
With this patch, callers of it can handle left and right node logically instead
of assuming that one is split and the other is new one.

Depends on D131748

Differential Revision: https://phabricator.services.mozilla.com/D131749
2021-11-24 02:27:41 +00:00
Masayuki Nakano 8ce63d4397 Bug 1740858 - Improve SplitNodeResult r=m_kato
First, left/right node accessors are not used so that we can get rid of them.
However, we should have similar methods which can retrieve original node and
new node.  Therefore, this adds `GetNewContent()` and `GetOriginalContent()`.

Next, `SplitPoint()` should return both `EditorDOMPoint` and `EditorRawDOMPoint`
for avoiding unnecessary conversion from `EditorRawDOMPoint` to
`EditorDOMPoint`.  Therefore, this patch makes it a template method too.

Finally, this patch adds helper methods to get point of each related content.
E.g., `AtNewContent()` corresponding to `GetNewContent()`.

Differential Revision: https://phabricator.services.mozilla.com/D131748
2021-11-24 00:56:33 +00:00
Masayuki Nakano 1e39247e59 Bug 1740859 - part 2: Make HTMLEditor::SplitNodeDeepWithTransaction() callers omit checking whether the editor is destroyed r=m_kato
It touches the DOM tree only with `SplitNodeTransaction()` and it now returns
`NS_ERROR_EDITOR_DESTROYED` so that the callers don't need to check whether
the editor is destroyed or alive by themselves.

Depends on D131043

Differential Revision: https://phabricator.services.mozilla.com/D131044
2021-11-15 02:29:48 +00:00
Masayuki Nakano 617c1cb919 Bug 1740859 - part 1: Make HTMLEditor::SplitNodeWithTransaction() return NS_ERROR_EDITOR_DESTROYED if it happens r=m_kato
For making the code simpler, this patch makes it returns
`Result<nsCOMPtr<nsIContent>, nsresult>` instead of using `ErrorResult`.
This must make the construction faster and callers simpler.

Depends on D130950

Differential Revision: https://phabricator.services.mozilla.com/D131043
2021-11-15 02:23:33 +00:00
Masayuki Nakano 780fbf11f8 Bug 1714914 - Make editor classes treat offset in parent node as uint32_t r=m_kato
It should be treated as `uint32_t` since DOM API does so.  However, there are
some exceptions:

* Result of `nsINode::ComputeIndexOf()`
* Result of `nsAString` methods

They return `-1` as not found, and anyway, they cannot treat large integer
than `INT32_MAX`.  Therefore, this patch does not touch around them.

Differential Revision: https://phabricator.services.mozilla.com/D118933
2021-06-30 07:07:28 +00:00
Masayuki Nakano 961cdfee8a Bug 1717178 - part 4: Get rid of nsIHTMLEditor.getInlineProperty() because of unused r=m_kato
Only `test_bug1140105.html` is its user, but it can be replaced with
`getInlinePropertyWithAttrValue()` since they do exactly same things:
https://searchfox.org/mozilla-central/rev/fc95c6ad297d9d257f05599d01741503f3f57326/editor/libeditor/HTMLStyleEditor.cpp#1685-1687,1719-1721

Depends on D118799

Differential Revision: https://phabricator.services.mozilla.com/D118800
2021-06-28 12:08:50 +00:00
Masayuki Nakano 651ef12aa0 Bug 1716746 - Rename EditorBase::IsPlaintextEditor() to IsInPlaintextMode() r=m_kato
Developers may be confused at `IsTextEditor()` and `IsPlaintextEditor()`. When
the latter is `true`, the former is always `true`, but it may be `true` when the
editor is `HTMLEditor` too. So, it's a mode of  `HTMLEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D118246
2021-06-18 20:35:48 +00:00
Masayuki Nakano 284ea1b8a5 Bug 1627175 - part 66: Move HTMLEditor::IsTextPropertySetByContent() to HTMLEditUtils r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D115178
2021-05-18 06:55:03 +00:00
Masayuki Nakano 589f224651 Bug 1627175 - part 53: Rename HTMLEditUtils::GetFirstLeafChild() and HTMLEditUtils::GetLastLeafChild() r=m_kato
They may return a descendant, and now `HTMLEditUtils` has some methods whose
name ends with `Child` and they scan only direct children of given node.
So, we should rename these methods for avoiding misunderstanding.

Differential Revision: https://phabricator.services.mozilla.com/D115122
2021-05-17 08:01:37 +00:00
Masayuki Nakano 3317dce634 Bug 1627175 - part 50: Move HTMLEditor::GetFirstEditableChild() to HTMLEditUtils r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D115119
2021-05-17 07:08:39 +00:00
Masayuki Nakano 4118203d72 Bug 1627175 - part 49: Move HTMLEditor::GetLastEditableChild() to HTMLEditUtils r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D115118
2021-05-17 05:44:34 +00:00
Masayuki Nakano a92de4a62f Bug 1627175 - part 47: Move HTMLEditor::GetNextHTMLSibling() to HTMLEditUtils r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D115116
2021-05-17 05:25:04 +00:00
Masayuki Nakano 6a94b6a4c2 Bug 1627175 - part 46: Move HTMLEditor::GetPriorHTMLSibling() to HTMLEditUtils r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D115115
2021-05-17 03:05:13 +00:00
Masayuki Nakano 537ba14656 Bug 1627175 - part 23: Move HTMLEditor::IsEmptyNode() into HTMLEditUtils with making it take EnumSet instead of bool arguments r=m_kato
It's hard to understand each caller of `HTMLEditor::IsEmptyNode()` tries to
check with multiple `bool` arguments.  Therefore, they should be replaced
with an `EnumSet`.

Note that only the first argument is reverted the meaning.  Therefore, if
it's omitted or `false`, `EmptyCheckOption::TreatSingleBRElementAsVisible`
is specified explicitly.  Otherwise, i.e., `true`, nothing should be
specified.

Differential Revision: https://phabricator.services.mozilla.com/D112513
2021-04-20 12:02:17 +00:00
Masayuki Nakano bb9b5f8217 Bug 1627175 - part 22: Get rid of HTMLEditor::IsEmptyTextNode() r=m_kato
It returns true only when it's a text node, but the text is empty.
However, `HTMLEditUtils::IsVisibleTextNode()` is used in
`HTMLEditor::IsEmptyNodeImpl()`.  So, we replace it with directly using
`HTMLEditUtils::IsVisibleTextNode()`.

Depends on D112511

Differential Revision: https://phabricator.services.mozilla.com/D112512
2021-04-20 02:00:15 +00:00
Masayuki Nakano eb2fdfe3b2 Bug 1699866 - Make HTMLEditor::SplitAncestorStyledInlineElementsAt return "not handled" if there is no splitable element at given point r=m_kato
When given point is **in** a void element, e.g., this can be when JS inserts
nodes into a void element like `<meta>`,
`HTMLEditor::SplitNodeDeepWithTransaction` may return "not handled" state.
So, it's possible case, we shouldn't assert the case.

This patch adds both WPT and crashtests because I couldn't reproduce it
with WPT's simpler API use.

Differential Revision: https://phabricator.services.mozilla.com/D111231
2021-04-09 02:34:23 +00:00
Masayuki Nakano e1d379d2d9 Bug 1649639 - Add WPT and remove unnecessary MOZ_ASSERT of HTMLEditor::ClearStyleAt r=m_kato
When the method detects the style coming from a parent block, the `MOZ_ASSERT`
checks whether the current mode is "style with CSS" or not because currently,
`HTMLEditor` does not use `<span>` with CSS when the mode is not "style with
CSS".  However, fixing it requires bigger patch, and the change does not match
with the bug's summary.  So, I just remove the `MOZ_ASSERT`, add WPT and filed
bug 1649639 for the root issue.

Differential Revision: https://phabricator.services.mozilla.com/D111067
2021-04-08 07:49:53 +00:00
Masayuki Nakano 04ff975886 Bug 1703144 - Get rid of MOZ_KnownLive for EditorBase::SelectionRefPtr() r=m_kato
The lifetime of it is guaranteed by `AutoEditActionDataSetter` which grabs
`Selection` until it's destroyed, and it's a stack only class and created
at first step of all public method calls.  Therefore, we can mark it as
`MOZ_KNOWN_LIVE` and we can change it returning reference of `Selection`
instead of reference of `RefPtr<Selection>`.

Differential Revision: https://phabricator.services.mozilla.com/D110896
2021-04-08 01:31:54 +00:00
Masayuki Nakano 44f0dae5b2 Bug 1697249 - Stop creating <span> element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element).  Then, unlink the new link element (i.e.,
clearing the "link style").  At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.

On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.

Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded.  And then,
when preparing for inserting text, this patch makes it pass to the utility
method.

For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.

Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 07:19:33 +00:00
Masayuki Nakano 46441fc0a5 Bug 1677566 - part 2: Make HTMLEditUtils treat a found non-editable element as a leaf node even if it has children r=m_kato
Blink treats each non-editable node as an atomic object.  E.g., deleting or
forward-deleting from next to a non-editable element, it deletes only one
non-editable element.

Unfortunately, our layout treat adjacent non-editable nodes as a node.
Therefore, the adding WPTs do not work, but they are not new regression of
this patch.

Differential Revision: https://phabricator.services.mozilla.com/D107587
2021-03-09 23:57:54 +00:00
Daniel Holbert 498d193041 Bug 1685231: Fix the typo "ot" in various code-comments (to "to", "of", or "not"). r=mccr8
DONTBUILD because this is a comment-only change and hence doesn't affect
behavior at all.

I ran across this typo in nsPageFrame.cpp, and figured I might as well grep for
it and fix it more comprehensively. And while I'm at it, I also fixed some
neighboring instances of a duplicated word around a linebreak, in
nsXMLContentSerializer.h.

Differential Revision: https://phabricator.services.mozilla.com/D100852
2021-01-06 04:54:51 +00:00
Simon Giesecke ab6f0a7137 Bug 1650145 - Replace all value uses of Empty[C]String by 0-length _ns literals. r=froydnj,geckoview-reviewers,agi
Differential Revision: https://phabricator.services.mozilla.com/D82325
2020-09-23 15:17:15 +00:00
Masayuki Nakano 622e0d1a98 Bug 1660378 - part 9: Avoid QI for getting nsStyledElement pointer r=smaug
The editor modules does QI too many times when it sets or removes some style
with `execCommand` or XPCOM API.  Therefore, there should be an API to
retrieve `nsStyledElement` pointer from `nsINode*`.

Differential Revision: https://phabricator.services.mozilla.com/D87990
2020-08-26 05:29:06 +00:00
Masayuki Nakano 2776abb8c6 Bug 1660378 - part 8: Make HTMLEditor::IsSimpleModifiableNode() take Element& instead of nsIContent* r=m_kato
Although it starts to return error if it causes destroying the editor, but
it should not occur because it modifies new and orphan node and it shouldn't
kick any mutation event listeners.  Therefore, this patch makes the callers
handle error as-is rather than ignoring errors except
`NS_ERROR_EDITOR_DESTROYED`.

Differential Revision: https://phabricator.services.mozilla.com/D87989
2020-08-26 04:48:36 +00:00
Masayuki Nakano 8abb67b878 Bug 1660378 - part 7: Make CSSEditUtils::SetCSSEquivalentToHTMLStyle() take nsStyledElement& instead of Element* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D87988
2020-08-26 04:48:32 +00:00
Masayuki Nakano e6bcbb653d Bug 1660378 - part 4: Make CSSEditUtils::DoElementsHaveSameStyle() take nsStyledElement& instead of Element& r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D87985
2020-08-26 04:48:22 +00:00
Masayuki Nakano f91231b39f Bug 1660378 - part 3: Make CSSEditUtils::RemoveCSSEquivalentToHTMLStyle() take nsStyledElement& instead of Element* r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D87984
2020-08-26 04:48:19 +00:00
Masayuki Nakano cda4f82a28 Bug 1660378 - part 2: Make CSSEditUtils::RemoveCSSPoperty() take nsStyledElement& instead of Element& r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D87983
2020-08-26 04:48:16 +00:00
Masayuki Nakano c9e542c37f Bug 1659276 - Make AutoPlaceholderBatch choose whether do or do not ScrollSelectionIntoView r=m_kato
The root cause of this bug is a bug of async `ScrollSelectionIntoView` that
is what it won't be canceled even if web app changes scroll position with
any API.  Fixing it is really risky and this bug affects an existing website.
Therefore, this patch makes the constructors of `AutoPlaceholderBatch` take
whether do or do not `ScrollSelectionIntoView` when it's destructed.  And
makes `HTMLEditor::SetInlinePropertyAsAction()` not request
`ScrollSelectionIntoView` for taking back the traditional behavior.

Note that this patch does not make it an optional argument because it's hard to
guess that it'll run `ScrollSelectionIntoView` automatically.

Differential Revision: https://phabricator.services.mozilla.com/D87819
2020-08-24 06:39:50 +00:00