11904 Commits

Author SHA1 Message Date
Masayuki Nakano
3d600c8b5d Bug 1989861 - Make HTMLEditor::EnsureNoFollowingUnnecessaryLineBreak consider a preceding <br> of a mailcite is necessary a=dmeehan
The serializer needs to make each mailcite starts from head of a line.
However, mailcite may be a blocked `<span>`.  So, its preceding `<br>`
is not required from the HTML point of view, but we need to preserve
it for the serializer.

If we need this hack in some other places, we should make
`HTMLEditUtils::GetFollowingUnnecessaryLineBreak()` aware of this
special handling in a follow up bug.

Differential Revision: https://phabricator.services.mozilla.com/D270784
2025-10-31 12:52:00 +00:00
Masayuki Nakano
8e53bd4fcd Bug 1968820 - Make HTMLEditor::InsertPaddingBRElementIfNeeded() put <br> before the mail-quote a=dmeehan
When we find a block boundary, it may be current block's boundary or
other block's boundary.  The lambda assume only the former, but the
STR of this bug hits the latter case.

So, when user modifies the text before a mail-quote which is a block of
`<span>` element should put `<br>` before it rather than end of it.

Differential Revision: https://phabricator.services.mozilla.com/D270782
2025-10-31 12:51:58 +00:00
Masayuki Nakano
0c6404cf72 Bug 1990586 - Make WhiteSpaceVisibilityKeeper::DeleteContentNodeAndJoinTextNodesAroundIt track given caret point a=pascalc
It's used as the result in some cases.  However, it's not tracked in
some cases when touching the DOM.

This modifies the API of `AutoTrackDOMPoint` to flush the tracking point
but can keep tracking.  We should use the new API in every place later.

(This manually merges `WhiteSpaceVisibilityKeeper.cpp` because ESR140
still has the pref to take the legacy mode back and that blocks applying
the patch cleanly.)

Differential Revision: https://phabricator.services.mozilla.com/D270643
2025-10-30 08:53:18 +00:00
Masayuki Nakano
f3c6a960d9 Bug 1968843 - Make HTMLEditor::HandleInsertText() manage Selection if committing composition a=dmeehan DONTBUILD
When committing composition string,
`WhiteSpaceVisibilityKeeper::InsertOrUpdateCompositionString()` may
replace commit string with normalized white-spaces.  Therefore, if
the last character is a white-space, it may be replaced with the other
white-space (ASCII white-space vs. NBSP).  Then, `Selection` collapsed
after the last character will be moved to start of the replaced
white-spaces.  So, when committing composition,
`HTMLEditor::HandleInsertText()` may need to change `Selection` by
itself.

Original Revision: https://phabricator.services.mozilla.com/D252278

Differential Revision: https://phabricator.services.mozilla.com/D253280
2025-06-11 17:05:48 +00:00
Masayuki Nakano
735e6414f0 Bug 1909020 - Make createDragEventObject() in EventUtils.js aware of HiDPI environments r=smaug
`synthesizePlainDragAndDrop()` sends `drop` event [1] via `PresShell` [2].
Then, the `screenX` and `screenY` values are set to
`WidgetEvent::mRefPoint` [3].  Then, the `drop` event's position is
recorded before dispatch [4].  So, `drop` event is fired on the target
but the `mRefPoint` may be outside the target.  Finally, synthesized
`eMouseMove` after `eDrop` will be fired on the wrong element which is
different from `eDrop`'s target.  This caused the failures of
`test_synthmousemove_after_dnd.html` and `test_dragdrop.html` on Android.

Perhaps, we should improve `nsDOMWindowUtils` or something lower layer
later.  Instead, this patch fixes in `EventUtils.js` level.  This makes
the `createDragEventObject()`.

1. https://searchfox.org/mozilla-central/rev/6a72a6d20eeb1b20b93862a79166938d6ce794a0/testing/mochitest/tests/SimpleTest/EventUtils.js#3893-3900
2. https://searchfox.org/mozilla-central/rev/6a72a6d20eeb1b20b93862a79166938d6ce794a0/testing/mochitest/tests/SimpleTest/EventUtils.js#376-393,400
3. https://searchfox.org/mozilla-central/rev/6a72a6d20eeb1b20b93862a79166938d6ce794a0/dom/events/MouseEvent.cpp#81-84
4. https://searchfox.org/mozilla-central/rev/6a72a6d20eeb1b20b93862a79166938d6ce794a0/layout/base/PresShell.cpp#8987

Differential Revision: https://phabricator.services.mozilla.com/D251091
2025-05-24 23:37:50 +00:00
Joel Maher
7e69b821f2 Bug 1967293 - Update mochitest manifest annotations to support Ubuntu 24.04. r=aryx,webcompat-reviewers,pip-reviewers,credential-management-reviewers,devtools-reviewers,sessionstore-reviewers,profiler-reviewers,dom-storage-reviewers,twisniewski,asuth,accessibility-frontend-reviewers,julienw,dimi,morgan,mconley,ochameau,nsharpley
Differential Revision: https://phabricator.services.mozilla.com/D250070
2025-05-23 20:13:29 +00:00
Hiroyuki Ikezoe
b6731ae61b Bug 1967343 - Disable smooth scrolling in test_bug795785.html. r=masayuki
Thus each scroll operation finishes within a short snap of time.

Differential Revision: https://phabricator.services.mozilla.com/D250090
2025-05-20 01:00:05 +00:00
Sylvestre Ledru
8ae54ea4f9 Bug 1519636 - Reformat recent changes to the Google coding style r=geckoview-reviewers,profiler-reviewers,win-reviewers,dom-storage-reviewers,nalexander,gstoll,tcampbell,janv,julienw
Updated with clang-format version 19.1.7 (taskcluster-DYvBxDZJRVqTi8E7pTSJAQ)

Differential Revision: https://phabricator.services.mozilla.com/D249880
2025-05-17 19:11:13 +00:00
Sean Feng
59893c42dc Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231588
2025-05-09 18:19:00 +00:00
Masayuki Nakano
487ff798cd Bug 1964011 - part 3: Make operator<< overload for EditorDOMPointeBase export a few characters of container iif the container is a Text r=m_kato
This helps to distinguish which the instance points a `Text`.

Depends on D248369

Differential Revision: https://phabricator.services.mozilla.com/D248370
2025-05-09 06:49:32 +00:00
Masayuki Nakano
8dd9d35fa1 Bug 1964011 - part 2: Make the editor classes log text input r=m_kato
Depends on D248368

Differential Revision: https://phabricator.services.mozilla.com/D248369
2025-05-09 06:49:28 +00:00
Masayuki Nakano
90e1f5ae9a Bug 1964011 - part 1: Make EditorBase log dispatching events r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D248368
2025-05-09 06:49:25 +00:00
Serban Stanca
5691c4beb2 Revert "Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core"
This reverts commit 8d55fdef16.
2025-05-08 20:00:31 +00:00
Sean Feng
8d55fdef16 Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231588
2025-05-08 13:40:01 +00:00
serge-sans-paille
bf3516e81e Bug 1964489 - Avoid duplication in NS_DECLARE_STATIC_IID_ACCESSOR / NS_DEFINE_STATIC_IID_ACCESSOR r=nika,necko-reviewers,media-playback-reviewers,places-reviewers,win-reviewers,dom-storage-reviewers,xpcom-reviewers,gstoll,janv,emilio,padenot,valentin,asuth
In modern C++, static constexpr member variables are automatically
inline (aka weak) so the template trick is not needed. This also avoid
duplication and reduces the amount of parsed code. No impact on
generated binary (actually: smaller debuginfo, close to identical
binary).

Differential Revision: https://phabricator.services.mozilla.com/D247825
2025-05-08 08:05:51 +00:00
Atila Butkovits
da71eedf0a Revert "Bug 1932150 - Fix build bustage" for causing build bustages.
This reverts commit 0681b181d6.

Revert "Bug 1932150 - Fix lint failure" for causing Build bustage.

This reverts commit 60cc0878d3.

Revert "Bug 1932150 - Add new test cases for selection in flat tree r=smaug"

This reverts commit 3dbe5fc183.

Revert "Bug 1932150 - Make selection code to correctly iterate flattened tree r=smaug"

This reverts commit 6f7a1e4886.

Revert "Bug 1932150 - ContentSubtreeIterator #3: Fix a bug in ContentSubtreeIterator where the end container is in the light DOM of a shadow host r=jjaschke"

This reverts commit 19ce2c5806.

Revert "Bug 1932150 - ContentSubtreeIterator #2: Allow ContentSubtreeIterator to iterate nodes in flattened tree r=jjaschke"

This reverts commit d9d192bc3a.

Revert "Bug 1932150 - ContentSubtreeIterator #1: Make the end container related logic in ContentSubtreeIterator more robust r=jjaschke,smaug,dom-core"

This reverts commit 2fbde5b84d.

Revert "Bug 1932150 - Update ranges to correctly set and update nodes for flattened selection r=jjaschke,smaug,dom-core"

This reverts commit 116d26c37f.

Revert "Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core"

This reverts commit 2ba73e1639.

Revert "Bug 1932150 - Fix some inconsistency about indicating whether the selection is allowed to cross the shadow boundary r=jjaschke,dom-core"

This reverts commit 793c2453f1.
2025-05-07 18:30:42 +00:00
Sean Feng
2ba73e1639 Bug 1932150 - Allow using flat tree order for point comparing in selection r=jjaschke,smaug,dom-core
Differential Revision: https://phabricator.services.mozilla.com/D231588
2025-05-07 15:08:34 +00:00
Masayuki Nakano
fb1d603cfd Bug 1961521 - Make HTMLEditor::HandleInsertText() collapse Selection properly after deleting composition r=m_kato
When inserting text or deleting text is for updating composition string,
`InsertTextWithTransaction()` does not suggest caret position because in the
most cases, `CompositionTransaction` updating `Selection` properly.  However,
if it's deleting existing composition (i.e., replacing the composition with
empty string), `HTMLEditor::HandleInsertText()` doesn't use
`CompositionTransaction` to update composition.  Instead, it uses the suggested
caret position from `InsertTextWithTransaction()` even though it's always unset.
Therefore, if the composition string follows some collapsible white-spaces and
they are replaced, `Selection` is automatically moved to the start position of
the replaced range and `HTMLEditor::HandleInsertText()` does not maintain the
caret position.

Therefore, this patch make it collapse `Selection` to end of the inserted text
where the composition string was.

Differential Revision: https://phabricator.services.mozilla.com/D246087
2025-04-21 23:49:31 +00:00
Masayuki Nakano
7aaca7360c Bug 1960558 - Get rid of dom.element.contenteditable.plaintext-only.enabled pref r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D245660
2025-04-17 08:30:29 +00:00
Masayuki Nakano
144cd4c4ad Bug 1959352 - Make WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesToSplitTextNodeAt() return end of its parent when it deletes a last Text r=m_kato
I'm not sure how to make this appear as an unexpected result. I just found
these mistakes when I was debugging bug 1959323

Depends on D244876

Differential Revision: https://phabricator.services.mozilla.com/D244879
2025-04-12 23:50:26 +00:00
Masayuki Nakano
b40c2aeefa Bug 1959323 - Make WSRunScanner::TextFragmentData::Get(Previous|InclusiveNext)CharPoint never cross block boundaries r=m_kato
When `HTMLEditor::InsertElementAtSelectionAsAction` inserts given element,
it tries to normalize the white-spaces around the insertion point [1].

Then, `WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesToSplitAt` tries to
delete invisible white-spaces around the insertion point first [2].

If the insertion point is not in leading white-spaces nor trailing white-spaces
around a block boundary, it tries to scan preceding and following white-spaces
to delete the surrounding invisible white-spaces [3].

At this time, it uses `TextFragmentData::GetInclusiveNextCharPoint()` and
`TextFragmentData::GetPreviousCharPoint()` which was initialized at the
insertion point.

However, they may return a point behind a block boundary with both digging into
a sibling block or skipping a sibling block.  Therefore, the result may
be too far from the insertion point and the following code in
`WhiteSpaceVisibilityKeeper::EnsureNoInvisibleWhiteSpaces()` may extend the
range to contain children because `GetFirstASCIIWhiteSpacePointCollapsedTo()`
and `GetEndOfCollapsibleASCIIWhiteSpaces()` uses `GetInclusiveNextCharPoint`
and `GetPreviousCharPoint()` too.

Therefore, when Thunderbird inserts a `<p>` with a call of
`HTMLEditor::InsertElementAtSelectionAsAction()` after `<blockquote>`,
it may delete the preceding text in the `<blockquote>` accidentally.

So, the scan methods of `WSRunScanner` shouldn't cross the block boundaries
because they handle only text fragment in the same line.

1. https://searchfox.org/mozilla-central/rev/27bb03eebacd679df419dac52a3b99c142cdb5db/editor/libeditor/HTMLEditor.cpp#2264-2269
2. https://searchfox.org/mozilla-central/rev/27bb03eebacd679df419dac52a3b99c142cdb5db/editor/libeditor/WhiteSpaceVisibilityKeeper.cpp#1501-1503
3. https://searchfox.org/mozilla-central/rev/27bb03eebacd679df419dac52a3b99c142cdb5db/editor/libeditor/WhiteSpaceVisibilityKeeper.cpp#2447-2469

Differential Revision: https://phabricator.services.mozilla.com/D244876
2025-04-11 06:25:06 +00:00
Greg Stoll
f84749bbc7 Bug 1957916 - avoid extra Content Analysis call when pasting into Google Sheets r=edgar
If aDataTransfer is non-null we should always use it in
EditorBase::PasteAsAction(), even if we aren't dispatching the event.

This correctly handles a corner case when the focus is changed by the
paste handler (around line 1929) and PasteAsAction() calls itself again.

Differential Revision: https://phabricator.services.mozilla.com/D244235
2025-04-09 14:55:58 +00:00
Masayuki Nakano
c713345b9c Bug 1958411 - Make some AutoTrackDOMRange users flush tracking ranges before post-processing after touching the DOM r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D244542
2025-04-08 05:59:30 +00:00
Edgar Chen
0284661240 Bug 1926775 - Disable test_execCommandPaste_noTarget.html on Linux wayland; r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D244581
2025-04-07 12:33:29 +00:00
Emilio Cobos Álvarez
b7f1e63735 Bug 1958639 - Ignore anonymous boxes and NAC for paragraph selection code. r=masayuki
The inner block of a scroller for example (::-moz-scrolled-content)
shouldn't be considered a line break.

Same for scrollbar nodes, we don't want to break on scrollbars (or
native anonymous content in general), since we can't position the caret
and such there anyways.

Differential Revision: https://phabricator.services.mozilla.com/D244519
2025-04-07 09:28:20 +00:00
Cosmin Sabou
f28da8586b Backed out changeset 099bd0ee7554 (bug 1958639) for causing bc failures on browser_clipboard. 2025-04-07 04:45:59 +03:00
Emilio Cobos Álvarez
1008751221 Bug 1958639 - Ignore anonymous boxes and NAC for paragraph selection code. r=masayuki
The inner block of a scroller for example (::-moz-scrolled-content)
shouldn't be considered a line break.

Same for scrollbar nodes, we don't want to break on scrollbars (or
native anonymous content in general), since we can't position the caret
and such there anyways.

Differential Revision: https://phabricator.services.mozilla.com/D244519
2025-04-06 23:58:48 +00:00
Joel Maher
34dc8fc793 Bug 1957450 - cleanup chrome.toml files to remove old conditions and standardize remaining conditions. r=aryx,devtools-reviewers,fxview-reviewers,profiler-reviewers,omc-reviewers,migration-reviewers,backup-reviewers,julienw,nchevobbe,mconley,pdahiya,nsharpley
Differential Revision: https://phabricator.services.mozilla.com/D243709
2025-04-01 21:16:45 +00:00
Masayuki Nakano
9253bce1c4 Bug 1955146 - Make WhiteSpaceVisibilityKeeper::MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement ignore empty Text nodes when scanning first character of the right block r=m_kato
Although, the empty text should've been removed, but it may happen without the
normalization.  Therefore, the lambda should keep scanning the first visible
char with ignoring empty `Text` nodes.

Additionally, there are similar methods which have the same lambda.  Therefore,
this fixes them too.

I think we should make the scanner method take an option parameter to ignore
empty `Text` in a follow up bug.

Differential Revision: https://phabricator.services.mozilla.com/D242264
2025-03-21 12:51:03 +00:00
Masayuki Nakano
8e23c15e1b Bug 1951518 - Make HTMLEditor::DeleteRangesWithTransaction stop deleting Text which has only a collapsible white-space r=m_kato
In bug 1925635, I moved the post processing after deleting ranges in
`EditorBase::DeleteRangesWithTransaction` into the `HTMLEditor`'s override.
At this time, I makes it uses `HTMLEditUtils::IsEmptyNode` to check whether
the `Text` and its containers become empty. Therefore, if `Ctrl`+`Backspace`
deletes the only word in the `Text` which starts with a collapsible white-space
causes deleting the `Text` after deleting all visible characters in the `Text`.

Therefore, this makes check it with `Text::TextDataLength` too before searching
the most distant ancestor inline element which becomes empty.

However, it may cause leading invisible white-spaces of the only word visible
because `nsFrameSelection` computes the word range strictly in the `Text`.
Therefore, this patch also makes `HTMLEditor::DeleteRangesWithTransaction` and
`AutoDeleteRangesHandler::ComputeRangesToDeleteRangesWithTransaction` extend
each range to delete to include surrounding invisible white-spaces too.

Therefore, this patch adds the new method to `AutoClonedRangeArray`.

Then, I hit 4 existing bugs with new test failures.

One is `HTMLEditUtils::LineRequiresPaddingLineBreakToBeVisible`.  It checks
whether the candidate point to insert a `<br>` is followed by a block boundary
first.  Then, it checks whether the candidate point follows a collapsible
white-space or a block boundary.  However, it uses
`WSRunScanner::ScanPreviousVisibleNodeOrBlockBoundary()` which ignores invisible
white-spaces.  Therefore, it will ignore the new invisible white-space and
reaches preceding `Text`.  Thus, it fails to put a `<br>` and makes the new
invisible white-space "fixed" as invisible.

Therefore, this patch rewrites the check with using
`HTMLEditUtils::GetPreviousLeafContentOrPreviousBlockElement()`.

Next one is, `HTMLEditor::DeleteEmptyInclusiveAncestorInlineElements()`
returns end of deleted node if it's followed by a non-editable node, i.e.,
an element has `contenteditable="false"`.  Therefore, its caller inserts a
`<br>` to the end of the container when deleting preceding editable node of a
non-editable node.

Therefore, this patch removes the editable state check.

Next, `AutoBlockElementsJoiner::HandleDeleteNonCollapsedRange` may put a padding
`<br>` after the moved line, but it does not assume that the moved line does not
ends with a block boundary.  This causes failing #46 and #48 tests in
`text_bug772796.html`.  E.g., when pressing `Delete` in
`<div>foo[]<div><span style="white-space:pre"><div>bar</div>baz</span>`, we move
the second `<div>` as a child of the parent `<span>` to end of the first `<div>`
like `<div>foo<span style="white-space:pre"><div>bar</div></span></div>...`.
Without the change, it starts to put unnecessary `<br>` after ` the `<span>`
because of the bug fix in `HTMLEditUtils::LineRequiresPaddingLineBreakToBeVisible`
above.  This result is completely odd from the users point of view (looks like
just move caret), but we should avoid to put the unnecessary `<br>`.

Finally, we'll fail an assertion when putting caret at the last of
`AutoBlockElementsJoiner::DeleteContentInRange` because it forgets to flush
the tracking range before using it. This appeared by the changes above.

Therefore, this patch fixes this bug too.

Differential Revision: https://phabricator.services.mozilla.com/D240703
2025-03-17 23:02:10 +00:00
Masayuki Nakano
d74b5eae46 Bug 1954394 - Mark some nsFrameSelection methods which change selection r=jjaschke
Even in these days, we notify selection listeners of selection changes
**synchronously**.  Thus, we need to mark all selection change methods as
`MOZ_CAN_RUN_SCRIPT` even though they are safe in the most cases.

Depends on D241776

Differential Revision: https://phabricator.services.mozilla.com/D241778
2025-03-17 12:49:59 +00:00
Masayuki Nakano
9add283d50 Bug 1954413 - Get rid of nsINode::GetChromeOnlyAccessSubtreeRootParent() r=smaug
It's an alias of `nsINode::GetClosestNativeAnonymousSubtreeRootParentOrHost()`
and oddly it returns `const nsIContent*` rather than `nsIContent*`.  Therefore,
some callers need to use `const_cast`.

Differential Revision: https://phabricator.services.mozilla.com/D241776
2025-03-17 12:49:58 +00:00
Masayuki Nakano
0ef5624d51 Bug 1954020 - Rename "limiter" of nsFrameSelection to "independent selection root element" r=emilio
It's currently always set to the native anonymous `<div>` for editable content
of text control element.  So, it means that it's an independent selection root.

Depends on D241587

Differential Revision: https://phabricator.services.mozilla.com/D241775
2025-03-17 12:49:58 +00:00
Masayuki Nakano
a5637890c7 Bug 1946001 - Fix some points which may cross independent selection boundary r=emilio,jjaschke
This patch fixes multiple points which may cross independent selection
boundaries which is element boundary of the native anonymous `<div>` for
editable content in text controls.  The reason why I don't split this patch is,
fixing one of them leads another assertion failure.  So, I couldn't pass all
tests with separated patches.

1. `nsFrameTraversal` should take `Element` instead of `nsIFrame` for the
limiter because e.g., inline editing host like `<span contenteditable>` may
have multiple frames if it's wrapped.  Therefore, we should make it take
an element as the ancestor limiter, and check it when getting parent frame
or after getting previous or next frame.
2. `nsIFrame::PeekBackwardAndForward` may cross the boundary because it does not
take the anonymous `<div>` element as ancestor limiter of the selection.  It's
currently used only for extending selection.  Therefore, I rename it to make
it clearer.
3. `SelectionMovementUtils::GetPrevNextBidiLevel` to take the ancestor limiter
for calling `nsIFrame::GetFrameFromDirection()`.
4. `nsINode` should have a method to return the `nsFrameSelection` instance
which manages the selection in the node.  This makes the check simpler, and
this is not expensive.  Then, for making it clearer, I rename
`TextControlElement::GetConstFrameSelection()` to
`GetIndependentFrameSelection()`.
5. `nsINode::GetSelectionRootContent()` should have an option to return
independent selection root when the node is its host for
`nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()`
6. `nsFrameSelection::ConstrainFrameAndPointToAnchorSubtree()` should not
retrieve independent selection root when the given frame is a text control
frame.
7. `RangeUtils` should get parent with checking the independent selection
boundaries.
8. `Selection::Extend` should assert if the destination is managed by its
frame selection to detect a bug.

Differential Revision: https://phabricator.services.mozilla.com/D241587
2025-03-17 12:49:57 +00:00
Masayuki Nakano
f43bf73bb2 Bug 1953933 - Make TextEditor::IsEmpty() return true if it's not been initialized yet r=m_kato
`GetTextNode()` requires that the instance has already been initialized since
it requires the native anonymous `<div>`.  And `IsEmpty()` is a public method.
Therefore, it should return `true` if there is no editor root, i.e., when it's
not been initialized yet after creation or destroyed.

Additionally, `TextControlState::GetValue()` should call
`TextEditor::ComputeTextValue()` if the editor has not been initialized because
it requires the native anonymous subtree to compute the value.  I'm not sure
whether this is a bug when `<textarea>` is being initialized.
(I guess that it should get the default value of the text control element or
`mValue` in the case, but we should do that in another bug separately.)

I couldn't find the crash testcase, so, this does not contain a new test.

Differential Revision: https://phabricator.services.mozilla.com/D241543
2025-03-14 06:41:47 +00:00
Masayuki Nakano
f046a57049 Bug 1952410 - Enable DOM mutation events when running crash tests for the editor module until it's disabled in the release channel r=smaug,m_kato
We added a lot of crash tests for tricky cases for the editor module.  Some of
them use the legacy DOM mutation events, and some of them caused serious issues.

Thus, we should enable the DOM mutation events at least running the tests to
detect regressions as soon as possible.

Differential Revision: https://phabricator.services.mozilla.com/D240709
2025-03-14 01:19:47 +00:00
Masayuki Nakano
6c78ab21c3 Bug 1717155 - part 2: Make InsertTextTransaction, CompositionTransaction, DeleteTextTransaction and ReplaceTextTransaction not store Text node if it's for TextEditor r=m_kato
So, `Text` editor can access the `Text` node quickly and it's not needed to
be grabbed by a lot of transactions.  Additionally, when we support keeping
`TextEditor` instance even if the text control is reflowed (bug 1922141,
bug 1339052 and bug 1620050), transactions need to work with new anonymous
nodes.  Therefore, retrieving `Text` node of `TextEditor` each time does make
sense rather than storing the node.

Depends on D240419

Differential Revision: https://phabricator.services.mozilla.com/D240420
2025-03-13 05:25:46 +00:00
Masayuki Nakano
617c636f1f Bug 1717155 - part 1: Make TextEditor use GetTextNode() more r=m_kato
The anonymous `<div>` of `TextEditor` has only one `Text` as its first child.
Therefore, we can make `TextEditor` simpler to access the `Text` node.

Differential Revision: https://phabricator.services.mozilla.com/D240419
2025-03-13 05:25:45 +00:00
Masayuki Nakano
b6784e43b2 Bug 1950783 - Make HTMLEditor::AutoMoveOneLineHandler::CanMoveOrDeleteSomethingInLine check whether the range wraps only block boundaries r=m_kato
Before the failure, all nodes which entirely selected have already deleted.
Therefore, if the selection range completely removes a list item and it starts
from end of preceding list, the range selects only block boundaries of the
list, e.g.,
```html
<div contenteditable>
 {<dl>}
    <dt>next item</dt>
```
Then, there is no content to move the first line of the right block. However,
if the `<dl>` is not the first child, the method returns `true` [1].
Therefore, it will mismatch with the actual result of `Run()`.  Therefore, this
patch makes it return `false` if the range selects only block boundaries.

Additionally,
`AutoInclusiveAncestorBlockElementsJoiner::CanMergeLeftAndRightBlockElements`
has a bug and not updated when
`WhiteSpaceVisibilityKeeper::MergeFirstLineOfRightBlockElementIntoLeftBlockElement`
is changed.  Therefore, this patch updates it to fix new assertion failures.

1. https://searchfox.org/mozilla-central/source/editor/libeditor/HTMLEditorDeleteHandler.cpp#6678-6680

Differential Revision: https://phabricator.services.mozilla.com/D239986
2025-03-11 12:28:19 +00:00
Tom Schuster
b8d11d463f Bug 1951893 - Remove unneeded StaticAtom suffixes. r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D240598
2025-03-11 11:36:09 +00:00
Masayuki Nakano
de3eb719c4 Bug 1951007 - Make style editing commands check whether the editing host is contenteditable="plaintext-only" to consider whether it's enabled r=m_kato
The style editing commands should be disabled in
`contenteditable="plaintext-only"`.  Currently, we return `false` from
`execCommand`, but we still claim that the commands are enabled for
`queryCommandEnabled`.

Differential Revision: https://phabricator.services.mozilla.com/D239985
2025-03-10 06:06:16 +00:00
Masayuki Nakano
db3f3e752b Bug 1940377 - part 9: Update mochitests to assume the new normalizer's result if it's enabled r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D239474
2025-03-08 22:31:57 +00:00
Masayuki Nakano
b2e66c86f6 Bug 1940377 - part 8: Make HTMLEditor stop normalizing white-spaces during initialization r=m_kato
Enabling the new normalizer causes this assertion failure:
```
###!!! ASSERTION: Want to fire DOMNodeRemoved event, but it's not safe: 'Error', file /builds/worker/checkouts/gecko/dom/base/nsContentUtils.cpp:5586
#01: NS_DebugBreak [xpcom/base/nsDebugImpl.cpp:508]
#02: nsContentUtils::MaybeFireNodeRemoved(nsINode*, nsINode*) [dom/base/nsContentUtils.cpp:5587]
#03: nsINode::RemoveChild(nsINode&, mozilla::ErrorResult&) [dom/base/nsINode.cpp:0]
#04: mozilla::DeleteNodeTransaction::DoTransaction() [editor/libeditor/DeleteNodeTransaction.cpp:112]
#05: mozilla::EditorBase::DoTransactionInternal(nsITransaction*) [editor/libeditor/EditorBase.cpp:929]
#06: mozilla::EditorBase::DeleteNodeWithTransaction(nsIContent&) [editor/libeditor/EditorBase.cpp:2685]
#07: mozilla::WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesToSplitTextNodeAt(mozilla::HTMLEditor&, mozilla::EditorDOMPointBase<RefPtr<mozilla::dom::Text>, nsIContent*> const&, mozilla::EnumSet<mozilla::WhiteSpaceVisibilityKeeper::NormalizeOption, unsigned int>) [editor/libeditor/WhiteSpaceVisibilityKeeper.cpp:1384]
#08: mozilla::WhiteSpaceVisibilityKeeper::NormalizeWhiteSpacesToSplitAt(mozilla::HTMLEditor&, mozilla::EditorDOMPointBase<nsCOMPtr<nsINode>, nsCOMPtr<nsIContent> > const&, mozilla::EnumSet<mozilla::WhiteSpaceVisibilityKeeper::NormalizeOption, unsigned int>) [editor/libeditor/WhiteSpaceVisibilityKeeper.cpp:1599]
#09: mozilla::HTMLEditor::PrepareToInsertLineBreak(mozilla::HTMLEditor::LineBreakType, mozilla::EditorDOMPointBase<nsCOMPtr<nsINode>, nsCOMPtr<nsIContent> > const&) [editor/libeditor/HTMLEditor.cpp:4418]
#10: mozilla::EditorBase::InsertPaddingBRElementForEmptyLastLineWithTransaction(mozilla::EditorDOMPointBase<nsCOMPtr<nsINode>, nsCOMPtr<nsIContent> > const&) [editor/libeditor/EditorBase.cpp:2511]
#11: mozilla::HTMLEditor::InsertBRElementToEmptyListItemsAndTableCellsInRange(mozilla::RangeBoundaryBase<nsINode*, nsIContent*> const&, mozilla::RangeBoundaryBase<nsINode*, nsIContent*> const&) [editor/libeditor/HTMLEditSubActionHandler.cpp:0]
#12: mozilla::HTMLEditor::InitEditorContentAndSelection() [editor/libeditor/HTMLEditSubActionHandler.cpp:187]
#13: mozilla::HTMLEditor::Init(mozilla::dom::Document&, mozilla::ComposerCommandsUpdater&, unsigned int) [editor/libeditor/HTMLEditor.cpp:412]
#14: nsEditingSession::SetupEditorOnWindow(nsPIDOMWindowOuter&) [editor/composer/nsEditingSession.cpp:405]
```

The initialization is required only for empty table cells and empty list items
and they are typically not used at initial document.  So, I think that it's fine
to stop normalizing white-spaces before succeeded to initialize `HTMLEditor`.

If this change causes a web-compat issue in the wild, let's make it run
asynchronously.

Differential Revision: https://phabricator.services.mozilla.com/D239473
2025-03-08 22:31:57 +00:00
Masayuki Nakano
dc6fec20e3 Bug 1940377 - part 7: Make HTMLEditor normalize surrounding white-spaces of commit string r=m_kato
For avoiding invisible white-space issues around composition string and for
avoiding making `CompositionTransaction` confused, we normalize white-spaces
around composition string boundaries with using NBSPs more than usual.
Therefore, we need to recover them as usual when ending the composition.

Differential Revision: https://phabricator.services.mozilla.com/D239469
2025-03-08 22:31:57 +00:00
Masayuki Nakano
2e3d9fe6d5 Bug 1940377 - part 6: Make delete handlers use the new white-space normalizer r=m_kato
Unfortunately, this patch becomes big because this includes multiple utility
methods to normalize white-spaces and touching a lot of places.

In some edge cases, this starts failing when the new white-space normalizer is
enabled.

```
FAIL execCommand("forwarddelete", false, ""): "a &nbsp;[] |&nbsp; &nbsp;b" - assert_equals: Modified text is wrong expected "a &nbsp;" but got "a&nbsp;&nbsp;"
FAIL execCommand("forwarddelete", false, ""): "a&nbsp;&nbsp;&nbsp;[]&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;b" - assert_equals: Modified text is wrong expected "a&nbsp;&nbsp;&nbsp;" but got "a&nbsp; &nbsp;"
FAIL execCommand("forwarddelete", false, ""): "a&nbsp;&nbsp;&nbsp;[]b|&nbsp;&nbsp;&nbsp;&nbsp;c" - assert_equals: Modified text is wrong expected "a&nbsp;&nbsp;&nbsp;" but got "a&nbsp; &nbsp;"
FAIL execCommand("forwarddelete", false, ""): "a&nbsp;&nbsp;&nbsp;[]&nbsp;<span style=white-space:pre;>   </span>" - assert_equals: expected "a&nbsp;&nbsp;&nbsp;<span style=\"white-space:pre;\">   </span>" but got "a&nbsp; &nbsp;<span style=\"white-space:pre;\">   </span>"
```
In these failures, we normalize the trailing white-spaces of the preceding
`Text` too, but Chrome does not do that.  However, in some cases, they do
in similar cases.  Therefore, it's hard to align all cases due to the handling
order difference.  Additionally, these failure results are not odd.  So, these
new failures are acceptable.

```
FAIL execCommand("forwarddelete", false, ""): "<span>abc[]&nbsp;<span> &nbsp;def</span></span>" - assert_equals: expected "<span>abc<span>&nbsp; def</span></span>" but got "<span>abc<span> &nbsp;def</span></span>"
FAIL execCommand("forwarddelete", false, ""): "<span><span>abc[]&nbsp;</span> &nbsp;def</span>" - assert_equals: expected "<span><span>abc</span>&nbsp; def</span>" but got "<span><span>abc</span> &nbsp;def</span>"
FAIL execCommand("forwarddelete", false, ""): "<span>abc[]&nbsp;</span><span> &nbsp;def</span>" - assert_equals: expected "<span>abc</span><span>&nbsp; def</span>" but got "<span>abc</span><span> &nbsp;def</span>"
FAIL execCommand("forwarddelete", false, ""): "<span>abc[]&nbsp; </span><span>&nbsp;&nbsp;def</span>" - assert_equals: expected "<span>abc&nbsp;</span><span>&nbsp;&nbsp;def</span>" but got "<span>abc </span><span>&nbsp;&nbsp;def</span>"

```
In these failures, we don't normalize the leading white-spaces of the following
`Text`.  However, Chrome does so in some other cases.  So, it's hard to align
the behavior in these cases too.  The new normalizer ensures that the preceding
`Text` ends with a visible char.  Therefore, the following `Text` won't starts
with new invisible white-spaces.  Therefore, these failures are also acceptable.

```
FAIL execCommand("forwarddelete", false, ""): "<span style=white-space:pre;>  [] </span>&nbsp;&nbsp;&nbsp;a" - assert_equals: expected "<span style=\"white-space:pre;\">  </span>&nbsp; &nbsp;a" but got "<span style=\"white-space:pre;\">  </span>&nbsp;&nbsp;&nbsp;a"
```
In this failure, we don't normalize the following `Text` but Chrome does it.
However, I don't think we should do it because this updates the `Text` which
is preformatted.  Therefore, this is also acceptable.

So, I think that we can accept all new failures.

Differential Revision: https://phabricator.services.mozilla.com/D239468
2025-03-08 22:31:56 +00:00
Masayuki Nakano
1dc6c56a97 Bug 1940377 - part 5: Make HTMLEditor::InsertElementAtSelectionAsAction normalize white-spaces around the insertion point if the new normalizer is enabled r=m_kato
Surprisingly, it has not normalize white-spaces around it. So, in some edge
cases, it might cause changing visibility of surrounding white-spaces.

Differential Revision: https://phabricator.services.mozilla.com/D239467
2025-03-08 22:31:56 +00:00
Masayuki Nakano
a4270d20ef Bug 1940377 - part 4: Make HTMLEditor normalize white-spaces before inserting HTML fragment if the new normalizer is enabled r=m_kato
Unfortunately, this change does not make
`white-spaces-after-insert-image.tentative.html?paste-image` pass because we
paste the `<div>` at pasting the `<img>`, but Chrome pastes only the `<img>`.

Differential Revision: https://phabricator.services.mozilla.com/D239466
2025-03-08 22:31:55 +00:00
Masayuki Nakano
e8e8d245bc Bug 1940377 - part 3: Make "insert paragraph" handlers use the new normalizer if it's enabled r=m_kato
Unfortunately, this change does not make
`white-spaces-after-execCommand-insertparagraph.tentative.html` pass because
the insert paragraph handler inserts a temporary `<br>` element and that causes
normalizing the following white-spaces at the split point.  However, Chrome
does not normalize the following white-spaces if it begins with an NBSP.

Differential Revision: https://phabricator.services.mozilla.com/D239465
2025-03-08 22:31:55 +00:00
Masayuki Nakano
5d714df94f Bug 1940377 - part 2: Make HandleInsertLineBreak use the new normalizer if it's available r=m_kato
When inserting a `<br>` element or a preformatted line break at middle of a
`Text`, we need to split it first.  At this time, we should normalize the
surrounding white-spaces before split.  Then, we can use only one
`ReplaceTextTransaction` instance for the normalization in the most cases.

Differential Revision: https://phabricator.services.mozilla.com/D239464
2025-03-08 22:31:54 +00:00
Masayuki Nakano
c0723c81ee Bug 1940377 - part 1: Make WhiteSpaceVisibilityKeeper::InsertTextOrInsertOrUpdateCompositionString support blink compatible white-space sequence r=m_kato
First, it makes it deletes invisible white-spaces at the insertion point.
This makes the further processing simpler.

Second, it extends the range to update in `Text` which will contain the
insertion string when it's not used for inserting nor updating composition
string, as containing all surrounding white-spaces at the insertion point.

Next, it normalizes the inserting string with the surrounding white-spaces with
the same rules as the other browsers especially as Chrome.
1. a collapsible white-space at start or end of a `Text` is always an NBSP.
2. a collapsible white-space immediately before or after a preformatted line
break is always an NBSP.
3. a collapsible white-space surrounded by non-collapsible chars is always an
ASCII white-space.
4. collapsible white-spaces are pairs of an NBSP and an ASCII white-space.

Then, we can make `HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal()`
stop normalizing white-spaces when inserting text.

Differential Revision: https://phabricator.services.mozilla.com/D239463
2025-03-08 22:31:54 +00:00