37 Commits
Author SHA1 Message Date
Sylvestre Ledru 9f5cc05eee Bug 2023419 - Remove Emacs/Vim modelines from editor/ r=masayuki
replaced by .editorconfig
# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D287844
2026-03-16 12:52:41 +00:00
Masayuki Nakano cec7115214 Bug 1996500 - part 2: Make WSRunScanner ignore empty inline containers by default r=m_kato
In the most cases, the scanner users should ignore empty inline
containers so that the behavior should be the default behavior.
Then, the options becomes clearer what the callers can expect.

Differential Revision: https://phabricator.services.mozilla.com/D284963
2026-03-04 06:59:49 +00:00
Masayuki Nakano d670a975c9 Bug 1996500 - part 1: Make HTMLEditUtils have APIs for handling unnecessary line breaks r=m_kato
Perhaps, we should stop using "visible" from the API names because
some API users use the methods while modifying the DOM.  Therefore, the
new APIs explain the position of a line break or whether it's
significant or unnecessary from the layout point of view.

This patch adds API to check a line break position which may return
following/preceding block boundary's element and to scan following
block boundary with ignoring unnecessary line break which is done in
some places with calling
`WSRunScanner::ScanInclusiveNextVisibleNodeOrBlockBoundary()` twice.

Additionally, making the extant internal API mainly `HTMLEditUtils`
use the new API to do the correct handling.

Note that this makes `HTMLEditUtils::GetLeafNodeType` return `Ignore`
if the caller does not want invisible things and the node is in
`display:none` element.  This change is required to keep passing some
tests whose editing host is `display:inline` and it's followed by
invisible text like `<script>`.

Differential Revision: https://phabricator.services.mozilla.com/D284962
2026-03-04 06:59:46 +00:00
Masayuki Nakano 80e02f4320 Bug 1998077 - part 6: Reimplement HTMLEditUtils::Get(First|Last)Child() and HTMLEditUtils::Get(Next|Previous)Sibling() with LeafNodeOptions r=m_kato
`WalkTreeOptions` is similar to `LeafNodeOptions` and it's hard to
maintain both of them.  Additionally, `LeafNodeOptions` can specify
which type of leaf nodes should be ignored at scanning.  Therefore,
`LeafNodeOptions` can be used for them.

Differential Revision: https://phabricator.services.mozilla.com/D277523
2026-01-13 05:27:50 +00:00
Masayuki Nakano 1afcba4cc6 Bug 1998077 - part 3: Add new options to ignore empty/invisible leaf nodes r=m_kato
This adds some options which ignore some types of inline elements.

For example, `IgnoreAnyEmptyInlineContainers` is useful to scan previous
or next editable point because Chrome ignores empty inline elements when
deleting from next to an inline element.

`IgnoreInvisibleInlineVoidElements` is useful to scan invisible line
break from end of a block or checking a line break is invisible because
visible inline element makes a line after the last line break. E.g.,
```html
<div>ABC<br><span></span></div>
```
This shows only one line. However,
```html
<div>ABC<br><span style="border:1px solid"></span></div>
```
This shows 2 lines in the `<div>`.

Additionally, renaming the existing `LeafNodeType` values for making
them easier to understand.

Differential Revision: https://phabricator.services.mozilla.com/D277520
2026-01-13 05:27:41 +00:00
Masayuki Nakano d9e52c123e Bug 1998077 - part 2: Add WSType::EmptyInlineContainerElement r=m_kato
An empty inline container element such as `<span></span>` has 2
meanings, if it's visible with specified style, e.g., has non-zero
padding, it should be treated like a replaced element like `<img>`.
However, if it's invisible, it should be treated as `Comment` or
empty `Text`.  Therefore, the scanner users need a special handling for
them in some cases.  So, it should be identified with the new `WSType`.

Unfortunately, neither
`HTMLEditUtils::IsInclusiveAncestorCSSDisplayNone` nor
`HTMLEditUtils::IsVisibleElementEvenIfLeafNode` is testable within
GTest because it does not have layout information.

Differential Revision: https://phabricator.services.mozilla.com/D277519
2026-01-13 05:27:38 +00:00
Sandor Molnar b77ea8700f Revert "Bug 1998077 - part 7: Reimplement HTMLEditUtils::GetInclusiveDeepestFirstChildWhichHasOneChild with LeafNodeOptions r=m_kato" for causing build bustages @ WSRunScanner.cpp
This reverts commit 5ccf392dce.

Revert "Bug 1998077 - part 6: Reimplement `HTMLEditUtils::Get(First|Last)Child()` and `HTMLEditUtils::Get(Next|Previous)Sibling()` with `LeafNodeOptions` r=m_kato"

This reverts commit 12eb928cb5.

Revert "Bug 1998077 - part 5: Replace the remaining `HTMLEditUtils::Get(Next|Previous)Content()` with new ones based on `Get(Next|Previous)LeafNodeOr(Next|Previous)BlockElement()` r=m_kato"

This reverts commit 58b4243d10.

Revert "Bug 1998077 - part 4: Replace some callers of `HTMLEditUtils::Get(Next|Previous)Content()` with `HTMLEditUtils::Get(Next|Previous)LeafContentOr(Next|Previous)BlockElement()` r=m_kato"

This reverts commit dd46967eb4.

Revert "Bug 1998077 - part 3: Add new options to ignore empty/invisible leaf nodes r=m_kato"

This reverts commit ca50a4a628.

Revert "Bug 1998077 - part 2: Add `WSType::EmptyInlineContainerElement` r=m_kato"

This reverts commit 4a5d93d631.

Revert "Bug 1998077 - part 1: Make `HTMLEditUtils::IsVisibleElementEvenIfLeafNode` work better if primary frame is available r=m_kato"

This reverts commit b42dc9d35f.
2026-01-07 06:15:59 +00:00
Masayuki Nakano 12eb928cb5 Bug 1998077 - part 6: Reimplement HTMLEditUtils::Get(First|Last)Child() and HTMLEditUtils::Get(Next|Previous)Sibling() with LeafNodeOptions r=m_kato
`WalkTreeOptions` is similar to `LeafNodeOptions` and it's hard to
maintain both of them.  Additionally, `LeafNodeOptions` can specify
which type of leaf nodes should be ignored at scanning.  Therefore,
`LeafNodeOptions` can be used for them.

Differential Revision: https://phabricator.services.mozilla.com/D277523
2026-01-07 01:12:54 +00:00
Masayuki Nakano ca50a4a628 Bug 1998077 - part 3: Add new options to ignore empty/invisible leaf nodes r=m_kato
This adds some options which ignore some types of inline elements.

For example, `IgnoreAnyEmptyInlineContainers` is useful to scan previous
or next editable point because Chrome ignores empty inline elements when
deleting from next to an inline element.

`IgnoreInvisibleInlineVoidElements` is useful to scan invisible line
break from end of a block or checking a line break is invisible because
visible inline element makes a line after the last line break. E.g.,
```html
<div>ABC<br><span></span></div>
```
This shows only one line. However,
```html
<div>ABC<br><span style="border:1px solid"></span></div>
```
This shows 2 lines in the `<div>`.

Additionally, renaming the existing `LeafNodeType` values for making
them easier to understand.

Differential Revision: https://phabricator.services.mozilla.com/D277520
2026-01-07 01:12:46 +00:00
Masayuki Nakano 4a5d93d631 Bug 1998077 - part 2: Add WSType::EmptyInlineContainerElement r=m_kato
An empty inline container element such as `<span></span>` has 2
meanings, if it's visible with specified style, e.g., has non-zero
padding, it should be treated like a replaced element like `<img>`.
However, if it's invisible, it should be treated as `Comment` or
empty `Text`.  Therefore, the scanner users need a special handling for
them in some cases.  So, it should be identified with the new `WSType`.

Unfortunately, neither
`HTMLEditUtils::IsInclusiveAncestorCSSDisplayNone` nor
`HTMLEditUtils::IsVisibleElementEvenIfLeafNode` is testable within
GTest because it does not have layout information.

Differential Revision: https://phabricator.services.mozilla.com/D277519
2026-01-07 01:12:43 +00:00
Masayuki Nakano e5f40f033b Bug 1998838 - Fix the order to refer leafContent in TextFragmentData::GetInclusiveNextCharPoint and TextFragmentData::GetPreviousCharPoint r=m_kato
The null-check should be done before using `IsBlockElement`.

Differential Revision: https://phabricator.services.mozilla.com/D271740
2025-11-14 10:47:51 +00:00
Masayuki Nakano 59dac6a3e4 Bug 1996758 - Make WSRunScanner and HTMLEditUtils return Comment within optional behavior r=m_kato
They should stop at a `Comment` node or treat `Command` as "visible"
node only when:
- The caller wants to handle only with current or adjacent `Text` node
- The caller wants to list all invisible nodes until the first visible thing

In other words, most users must want to ignore `Comment` nodes.
Therefore, their default behavior should be so but they should treat
`Comment` nodes in an optional mode.

Differential Revision: https://phabricator.services.mozilla.com/D270461
2025-11-05 06:34:33 +00:00
Masayuki Nakano 0f95ad06ca Bug 1996501 - part 3: Make HTMLEditUtils select proper BlockInlineCheck for the scanning direction automatically r=m_kato
In theory, the low level APIs of `HTMLEditUtils` should not choose
`BlockInlineCheck` value.  However, the callers may want if the
direction is changed in the API, e.g., when scanning siblings but then
climbing up. For preserving the low level API behavior, this patch
adds new `BlockInlineCheck` value, `Auto`.  Then, the `HTMLEditUtils`
APIs choose proper value for the direction automatically only when
`Auto` is specified.

Differential Revision: https://phabricator.services.mozilla.com/D270118
2025-10-31 05:05:12 +00:00
Masayuki Nakano 6983335537 Bug 1996501 - part 2: Make WSRunScanner take an EnumSet instead of a set of Scan and BlockInlineCheck r=m_kato
It's not required explicitly to specify
`BlockInlineCheck::UseComputedDisplayStyle` and
`BlockInlineCheck::UseComputedDisplayOutsideStyle` to `WSRunScanner`
too.  And it should take an `EnumSet` for making it easier to maintain
the class in the future.

Differential Revision: https://phabricator.services.mozilla.com/D270117
2025-10-31 05:05:10 +00:00
Masayuki Nakano 94124bfa08 Bug 1996501 - part 1: Make TextFragmentData refer proper display value for the scanning direction r=m_kato
In theory, scanning from outside to inside, i.e., checking a sibling
or a child, `display-outside` should be used to check whether the
element is a block or an inline. Similarly, scanning from inside to
outside, i.e., checking a parent, `display-inside` should be used to
check whether the element is a block or an inline.

`HTMLEditUtils`'s related methods are low API, but `WSRunScanner` is
higher API.  Therefore, I think `WSRunScanner` should work with the
theory.

This patch makes the internal scanner of `WSRunScanner`,
`TextFragmentData`, take only whether refer HTML default style or CSS
style and consider itself whether use
`BlockInlineCheck::UseComputedDisplayOutsideStyle` or
`BlockInlineCheck::UseComputedDisplayStyle`.

So, this patch should fix some edge case bugs of
`display: inline-block`.  However, unfortunately, there is not enough
tests for that.

Differential Revision: https://phabricator.services.mozilla.com/D270116
2025-10-31 05:05:07 +00:00
Masayuki Nakano c9af7d0d54 Bug 1988909 - Refine HTMLEditUtils::GetAncestorElement and HTMLEditUtils::GetInclusiveAncestorElement with adding uint tests r=m_kato
These utility methods behave odd in some edge cases and they are not
tested.  Therefore, they should be tested with new unit tests and we
should fix the odd behaviors.

Differential Revision: https://phabricator.services.mozilla.com/D265186
2025-09-21 23:15:27 +00:00
Jan-Niklas Jaeschke 573f34249c Bug 1949053, part 4 - Rename CharacterData::TextFragment() to CharacterData::DataBuffer(). r=masayuki,firefox-style-system-reviewers,emilio
Differential Revision: https://phabricator.services.mozilla.com/D259935
2025-08-06 08:48:09 +00:00
Jan-Niklas Jaeschke 0151e67615 Bug 1949053, part 2 - Rename nsTextFragment to mozilla::dom::CharacterDataBuffer. r=masayuki
This patch updates all occurrences of the type `nsTextFragment` into its new name, `mozilla::dom::CharacterDataBuffer`.
It also updates the includes, including sorting.

Differential Revision: https://phabricator.services.mozilla.com/D259867
2025-08-06 08:48:01 +00:00
Masayuki Nakano 50be9669c0 Bug 1977386 - Make HTMLEditor related code treat the cases that "\n" is not a preformatted line break but is not collapsible white-space r=m_kato
There is a case that "\n" is not a preformatted line break, but it's
rendered as a non-collapsible white-space.  Therefore, for checking
whether a "\n" is a collapsible white-space,
`EditorUtils::IsWhiteSpacePreformatted` should be used instead of
`EditorUtils::IsNewLinePreformatted`.

Differential Revision: https://phabricator.services.mozilla.com/D257458
2025-07-18 05:15:52 +00:00
Masayuki Nakano 997bf4b02b Bug 1976608 - Make WSRunScanner::Scan*VisibleNodeOrBlockBoundary ignore Comments r=m_kato
They are internal APIs to return next/previous visible thing or
a padding `<br>` element.  However, when they reach a `Comment`, they
don't skip it and return it as a special content.  `Comment` is always
invisible so that they should skip such invisible nodes.

Differential Revision: https://phabricator.services.mozilla.com/D257125
2025-07-14 23:39:37 +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
Masayuki Nakano 6e26e7194d Bug 1944437 - Make WSRunScanner::TextFragmentData::InvisibleTrailingWhiteSpaceRangeRef treat white-spaces before invisible preformatted linefeed as visible r=m_kato
A preformatted linefeed works exactly same as `<br>` as far as I know.
Actually, white-spaces before a preformatted linefeed is visible as a space.
Therefore, the method should not keep scanning invisible white-spaces if the
sequence ends with a preformatted linefeed.

The check was introduced in D124560 which is for initial support of
`white-space: pre-*`.  So, this is a traditional hidden bug, but this appeared
by that we started deleting unnecessary linebreaks.

Differential Revision: https://phabricator.services.mozilla.com/D235918
2025-01-29 12:38:54 +00:00
Masayuki Nakano 085a371a0c Bug 1943656 - Make TextFragmentData::BoundaryData::ScanCollapsibleWhiteSpace(End|Start)From treat the ancestor limiter is a block when display: inline-block r=m_kato
Chromium considers whether an element is block or inline with `display-outside`.
Therefore, they treat `inline-block` is an inline element.  For following the
behavior, we use `BlockInlineCheck::UseComputedDisplayOutsideStyle` in many
places.  However, if `WSRunScanner` works for considering a collapsible
white-space visibility, it needs to treat `inline-block` as a block only when
it's an ancestor.

In the reported case, the editing host is `inline-block`.  So, `WSRunScanner`
reached the ancestor limiter if scanning only editable nodes.  To fix this bug,
this changes the behavior only when the scanner reached the ancestor limiter.

In the future, we need to change the scanner methods of `HTMLEditUtils`
use the new inline methods.

Differential Revision: https://phabricator.services.mozilla.com/D235530
2025-01-28 11:11:13 +00:00
Masayuki Nakano 6538e13b56 Bug 1926483 - part 5: Fix some assertion failures which assume WSRunScanner works only with editable nodes r=m_kato
Depends on D233794

Differential Revision: https://phabricator.services.mozilla.com/D234648
2025-01-24 05:00:48 +00:00
Butkovits Atila 173aee505b Backed out 5 changesets (bug 1926483) for causing failures at WSRunScanner.h. CLOSED TREE
Backed out changeset fa4c36cef1c5 (bug 1926483)
Backed out changeset 24bdcd7af3e0 (bug 1926483)
Backed out changeset 1df51ca968f8 (bug 1926483)
Backed out changeset 7aceecb585e4 (bug 1926483)
Backed out changeset 41b040b374a2 (bug 1926483)
2025-01-23 07:35:22 +02:00
Masayuki Nakano 2ddc3752c6 Bug 1926483 - part 5: Fix some assertion failures which assume WSRunScanner works only with editable nodes r=m_kato
Depends on D233794

Differential Revision: https://phabricator.services.mozilla.com/D234648
2025-01-23 05:01:57 +00:00
Masayuki Nakano c6b4e944ef Bug 1939220 - part 6: Make TextFragmentData free from the editing host r=m_kato
It stores the editing host. However, its role is scan the DOM from a point in
a block containing the point.  Therefore, it can know which node is editing
host when it scans without computing the editing host.  So, it does not need
to be specified the editing host.

Then, it can scan non-editable DOM too.  Therefore, this extends some utility
methods of `HTMLEditUtils` which are used by `TextFragmentData` and
`BoundaryData`.

Differential Revision: https://phabricator.services.mozilla.com/D232937
2025-01-20 08:03:59 +00:00
Masayuki Nakano 0e10d664fc Bug 1939220 - part 5: Make TextFragmentData::Get(EndOf|First)CollapsibleASCIIWhiteSpaces possible to scan non-editable text too r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232936
2025-01-20 08:03:59 +00:00
Masayuki Nakano 693817ee11 Bug 1939220 - part 4: Make TextFragmentData::Get(InclusiveNext|Previous)EditableCharPoint possible to scan non-editable text too r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232935
2025-01-20 08:03:58 +00:00
Masayuki Nakano bd4fdbf30a Bug 1939220 - part 3: Make TextFragmentData::BoundaryData not depend on the editing host r=m_kato
Its role is scanning the DOM.  Therefore, it can know which node is an editing
host during a scan.  Therefore, it does not require the editing host parameter.
To fix that, some utility methods of `HTMLEditUtils` needs to work with
non-editable nodes.  Therefore, this patch also updates `HTMLEditUtils`.

Finally, this gets rid of the `NS_ASSERTION`s in the constructor of
`TextFragmentData` because it'll be available with non-editable nodes too.
Although current all callers assume that it works as in an editing host.

Differential Revision: https://phabricator.services.mozilla.com/D232934
2025-01-20 08:03:58 +00:00
Masayuki Nakano 5b0da1a66e Bug 1939220 - part 2: Split WSRunScanner.cpp to define the methods of the nested classes r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232933
2025-01-20 08:03:57 +00:00
Sandor Molnar 11ae540bbc Backed out 6 changesets (bug 1939220) for causing build bustages CLOSED TREE
Backed out changeset b15602e6fbf5 (bug 1939220)
Backed out changeset 129d2cd2e11e (bug 1939220)
Backed out changeset b663c3b349f0 (bug 1939220)
Backed out changeset cbd9e4f12bd2 (bug 1939220)
Backed out changeset 81260f9e6677 (bug 1939220)
Backed out changeset f33e7201796d (bug 1939220)
2025-01-20 05:02:53 +02:00
Masayuki Nakano 6fd78fc633 Bug 1939220 - part 6: Make TextFragmentData free from the editing host r=m_kato
It stores the editing host. However, its role is scan the DOM from a point in
a block containing the point.  Therefore, it can know which node is editing
host when it scans without computing the editing host.  So, it does not need
to be specified the editing host.

Then, it can scan non-editable DOM too.  Therefore, this extends some utility
methods of `HTMLEditUtils` which are used by `TextFragmentData` and
`BoundaryData`.

Differential Revision: https://phabricator.services.mozilla.com/D232937
2025-01-19 23:35:36 +00:00
Masayuki Nakano 9242ecc01e Bug 1939220 - part 5: Make TextFragmentData::Get(EndOf|First)CollapsibleASCIIWhiteSpaces possible to scan non-editable text too r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232936
2025-01-19 23:35:36 +00:00
Masayuki Nakano 9c1b22c086 Bug 1939220 - part 4: Make TextFragmentData::Get(InclusiveNext|Previous)EditableCharPoint possible to scan non-editable text too r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232935
2025-01-19 23:35:36 +00:00
Masayuki Nakano 5a37bc8a95 Bug 1939220 - part 3: Make TextFragmentData::BoundaryData not depend on the editing host r=m_kato
Its role is scanning the DOM.  Therefore, it can know which node is an editing
host during a scan.  Therefore, it does not require the editing host parameter.
To fix that, some utility methods of `HTMLEditUtils` needs to work with
non-editable nodes.  Therefore, this patch also updates `HTMLEditUtils`.

Finally, this gets rid of the `NS_ASSERTION`s in the constructor of
`TextFragmentData` because it'll be available with non-editable nodes too.
Although current all callers assume that it works as in an editing host.

Differential Revision: https://phabricator.services.mozilla.com/D232934
2025-01-19 23:35:35 +00:00
Masayuki Nakano bdebf6b629 Bug 1939220 - part 2: Split WSRunScanner.cpp to define the methods of the nested classes r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232933
2025-01-19 23:35:35 +00:00