330 Commits
Author SHA1 Message Date
serge-sans-paille 20546b3e3c Bug 2038252 - Work around conflicting define in rpcndr.h in libeditor r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D299386
2026-05-10 20:10:48 +00:00
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 cb42ef186c Bug 1996500 - part 4: Make the other parts of HTMLEditor use the new APIs r=m_kato
This simplifies a lot position about inserting new padding line break
for the last empty line and each behavior is improved by the new API.

Differential Revision: https://phabricator.services.mozilla.com/D284965
2026-03-04 06:59:55 +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 71f6752f79 Bug 1982458 - part 1: Clean up the trackers r=m_kato
The `AutoTrackDOMPoint` constructor which takes `nsCOMPtr<nsINode>&` and
`uint32_t` is not used anymore. Thus, we can get rid of the mode.

And `FlushAndStopTracking()` should be replaced with
`Flush(StopTracking::Yes)` and align the relatives to use the same
API style.

Differential Revision: https://phabricator.services.mozilla.com/D283634
2026-02-19 13:43:33 +00:00
Masayuki Nakano 91fa81075a Bug 1998077 - part 7: Reimplement HTMLEditUtils::GetInclusiveDeepestFirstChildWhichHasOneChild with LeafNodeOptions r=m_kato
Similarly, we can implement it with `LeafNodeOptions` to ignore
unnecessary nodes.  Then, we can get rid of `WalkTreeOption` and
`WalkTreeOptions` completely.

Differential Revision: https://phabricator.services.mozilla.com/D277524
2026-01-13 05:27:53 +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
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 5ccf392dce Bug 1998077 - part 7: Reimplement HTMLEditUtils::GetInclusiveDeepestFirstChildWhichHasOneChild with LeafNodeOptions r=m_kato
Similarly, we can implement it with `LeafNodeOptions` to ignore
unnecessary nodes.  Then, we can get rid of `WalkTreeOption` and
`WalkTreeOptions` completely.

Differential Revision: https://phabricator.services.mozilla.com/D277524
2026-01-07 01:12:57 +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 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 5c667a6c58 Bug 1752093 - Make HTMLEditUtils::Is*() take const nsIContent& as far as possible r=m_kato
In the historical reason, some of them still take `nsINode*`.  In these
days, converting from `nsINode` to `nsIContent` or `Element` is faster
than before and most callers already use `nsIContent`.  Therefore, we
should make them take `const nsIContent&`.

Only some methods, allowing callers use pointer makes them simpler.
Therefore, only some methods have overloads which take
`const nsIContent*` instead.

Differential Revision: https://phabricator.services.mozilla.com/D265525
2025-09-30 01:31:25 +00:00
Cristina Horotan 8bdbf9625e Revert "Bug 1752093 - Make HTMLEditUtils::Is*() take const nsIContent& as far as possible r=m_kato" for causing assertion in nsINode.h
This reverts commit d7a3d6e49b.
2025-09-26 06:41:47 +00:00
Masayuki Nakano d7a3d6e49b Bug 1752093 - Make HTMLEditUtils::Is*() take const nsIContent& as far as possible r=m_kato
In the historical reason, some of them still take `nsINode*`.  In these
days, converting from `nsINode` to `nsIContent` or `Element` is faster
than before and most callers already use `nsIContent`.  Therefore, we
should make them take `const nsIContent&`.

Only some methods, allowing callers use pointer makes them simpler.
Therefore, only some methods have overloads which take
`const nsIContent*` instead.

Differential Revision: https://phabricator.services.mozilla.com/D265525
2025-09-26 01:07:57 +00:00
Masayuki Nakano c378809a91 Bug 1977289 - part 1: Make HTMLEditUtils::GetDeepestEditable(Start|End)Point possible to ignore Comment r=m_kato
Typically, we should ignore `Comment` nodes since they are completely
invisible.  One of the exceptions is, when splitting or joining its
parent, `Comment` nodes should be preserved in new container.
Therefore, the new behavior needs to be optional.  So, we can start
ignoring `Comment` nodes when updating `Selection`.

Differential Revision: https://phabricator.services.mozilla.com/D257409
2025-07-23 08:27:39 +00:00
Masayuki Nakano b67e405f29 Bug 1926483 - part 4: Make WSRunScanner::Scan(InclusiveNext|Previous)VisibleNodeOrBlockBoundary take WSRunScanner::Scan and ancestor limiter r=m_kato
Note that this removes a lot of `aEditingHost` params.  This may cause odd
behavior if editing host is changed by a legacy mutation event listener.
However, it'll be completely deleted soon and even if we meet some regressions,
we can just restore the param to set `aAncestorLimiter`.

Differential Revision: https://phabricator.services.mozilla.com/D233794
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 8e2501c776 Bug 1926483 - part 4: Make WSRunScanner::Scan(InclusiveNext|Previous)VisibleNodeOrBlockBoundary take WSRunScanner::Scan and ancestor limiter r=m_kato
Note that this removes a lot of `aEditingHost` params.  This may cause odd
behavior if editing host is changed by a legacy mutation event listener.
However, it'll be completely deleted soon and even if we meet some regressions,
we can just restore the param to set `aAncestorLimiter`.

Differential Revision: https://phabricator.services.mozilla.com/D233794
2025-01-23 05:01:57 +00:00
Masayuki Nakano 771489d350 Bug 1939220 - part 1: Split WSRunObject files for WSRunScanner and WhiteSpaceVisibilityKeeper r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232932
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 0537c53049 Bug 1939220 - part 1: Split WSRunObject files for WSRunScanner and WhiteSpaceVisibilityKeeper r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D232932
2025-01-19 23:35:34 +00:00
Masayuki Nakano 9fd27e7690 Bug 1937289 - Make AutoRangeArray::ExtendAnchorFocusRangeFor stop using nsFrameSelection r=m_kato,jjaschke,dom-core
`AutoRangeArray` is created for making some handlers of the editor classes free
from `Selection` and `nsFrameSelection` while handling the edit actions.
However, the method still depends on `nsFrameSelection` instance since its
callees are instance methods of `nsFrameSelection`.

However, `EditContext` requires completely free methods to compute target
ranges of `beforeinput`.  Therefore, we need to make it not depend on
`Selection` nor `nsFrameSelection`.

The common method, `nsFrameSelection::CreateRangeExtendedToSomewhere`, requires
`PresShell`, selection limiter which is set only when the selection is an
independent selection like in a selection for a text control, selection
ancestor limiter which is set only when an editing host has focus, caret
association hint to put caret to end of preceding line or start of following
line if selection range is collapsed at a line break and caret bidi level for
considering caret position around line break in bidi text.  They are now stored
by `nsFrameSelection` and modified when selection range is changed in some
cases.  Basically, the method is called without updating its ranges and if and
only if it's initialized with `Selection`.  So, simply caching the
`nsFrameSelection`'s values solves the issues in the most cases, but this
patch makes `AutoRangeArray` adjust the value only when its `Collapse` is
called because `Selection` automatically updates it and we can compute the
value without `Selection` nor `nsFrameSelection`.

After applying this patch, `AutoRangeArray` has two meanings, one is the
instance is a proxy for `Selection`.  The other is a container for a range to
call methods which take pointer or reference to it.  To make this differences
checked at build time, this patch creates a new subclass of it, and renamed to
`AutoClonedRangeArray` to make it clearer that what are stored in the array.

Oddly, `AutoRangeArray(nsRange&)` constructor has not been cloned.  Therefore,
I make it and its subclass version clone before storing into the array.  Then,
one caller needs to change which range should be tracked.

Differential Revision: https://phabricator.services.mozilla.com/D232174
2025-01-07 01:56:52 +00:00
Masayuki Nakano 8d4efeeea2 Bug 1940014 - Make HTMLEditor::ClearStyleAt stop forgetting removed line break r=m_kato
It does tricky if the styled element contains a padding line break.

First, it splits the inline containers at the point.  E.g., if the DOM is
`<b>abc []<br></b>`, it's split as `<b>abc </b><b><br></b>`.

Next, it deletes the latter one if it has only a padding line break. Then,
previously, it didn't forget the disconnected `<br>`, but D231655 made it
forget [1].

However, the method needs to insert a padding line break temporarily, i.e.,
It needs to make it as `<b>abc </b><br>`, because `WhiteSpaceVisibilityKeeper`
will treat the collapsible white-space as an invisible trailing white-space
of the block.  Therefore, it does it only when it removes a padding line break
[2].

Therefore, this patch makes it forget the deleted padding line break.

1. https://searchfox.org/mozilla-central/rev/94c62970ba2f9c40efd5a4f83a538595425820d9/editor/libeditor/HTMLStyleEditor.cpp#2465-2467
2. https://searchfox.org/mozilla-central/rev/94c62970ba2f9c40efd5a4f83a538595425820d9/editor/libeditor/HTMLStyleEditor.cpp#2499-2502,2512-2514

Differential Revision: https://phabricator.services.mozilla.com/D233232
2025-01-06 07:03:21 +00:00
Masayuki Nakano 7714f4b009 Bug 1935923 - part 1: Change HTMLEditor::InsertBRElement to InsertLineBreak r=m_kato
For making most callers can insert either `<br>` or a preformatted linefeed,
the inserter should handle both of them.

This patch makes `PrepareToInsertLineBreak` which is renamed from
`PrepareToInsertBRElement` to check whether the container can have the new
line break.  Then, one test starts failing, but it's okay because it's a
test in `<xmp>` which cannot have any elements, so, `<xmp>` is super legacy
element and must not be used in these days especially in editable content.

Differential Revision: https://phabricator.services.mozilla.com/D231656
2024-12-22 01:56:38 +00:00
Alexandru Marc 354231000b Backed out 5 changesets (bug 1935923) for causing build bustages @ EditorLineBreak.h CLOSED TREE
Backed out changeset 7c5e9c2afd3b (bug 1935923)
Backed out changeset 95c8aa202651 (bug 1935923)
Backed out changeset e23ec9a7919d (bug 1935923)
Backed out changeset b3b42030356f (bug 1935923)
Backed out changeset 552b6c2fdc22 (bug 1935923)
2024-12-21 02:38:32 +02:00
Masayuki Nakano 2342800bcd Bug 1935923 - part 1: Change HTMLEditor::InsertBRElement to InsertLineBreak r=m_kato
For making most callers can insert either `<br>` or a preformatted linefeed,
the inserter should handle both of them.

This patch makes `PrepareToInsertLineBreak` which is renamed from
`PrepareToInsertBRElement` to check whether the container can have the new
line break.  Then, one test starts failing, but it's okay because it's a
test in `<xmp>` which cannot have any elements, so, `<xmp>` is super legacy
element and must not be used in these days especially in editable content.

Differential Revision: https://phabricator.services.mozilla.com/D231656
2024-12-20 22:13:43 +00:00
Masayuki Nakano fc0c3d9112 Bug 1935924 - part 2: Make HTMLEditUtils::GetFirstLineBreak return a preformatted line break too r=m_kato,dom-core,jjaschke
The method caller should work with preformatted line break too.  Therefore,
it should return `Maybe<EditorLineBreak>` for representing all the cases.
For the method supports to return a preformatted linefeed, this adds scanner
methods to `nsTextFragment` because calling `nsTextFragment::CharAt` a lot is
slow due to required to consider the right buffer at each call.

Differential Revision: https://phabricator.services.mozilla.com/D231655
2024-12-20 11:42:13 +00:00
Masayuki Nakano a0474a51e8 Bug 1935924 - part 1: Implement EditorLineBreak class to treat both <br> and a preformatted linefeed with one data structure r=m_kato
`HTMLEditor` and its helper classes need to handle both a `<br>` and a
preformatted linefeed in the same way.  However, the former is an independent
node but the latter is a char in a `Text` node.  Therefore, it makes the
implementation simpler for making each `<br>` element handler treat a
preformatted linefeed in same path if there is a class to store the both
types of a line break.

Differential Revision: https://phabricator.services.mozilla.com/D231654
2024-12-20 11:42:13 +00:00
Masayuki Nakano 16078a3914 Bug 1920622 - Make the style setter public methods of HTMLEditor stop handling their jobs if the editing host is plaintext-only r=m_kato
Unfortunately, (even tough we're the last implementor of this feature`,) there
are not editing behavior tests in web-platform tests.  Therefore, this patch
creates new `plaintext-only` directory into `editing` and make the feature
enabled in its `__dir__.ini` to check the implementing behavior with new tests.

This patch also changes how to compute the editing host (whether using `<body>`
or not when selection is outside it), but the new behavior (not limited in the
`<body>`) should work fine in the most cases and I believe that it's better
than current implementation in some methods.

Note that Chrome considers whether the style should be updated or not with
the closest inclusive ancestor of the **focus node** of `Selection`.  However,
it's odd and aligning to the behavior requires bigger change.  Therefore, I'd
like to implement this feature only with checking the focused editing host.

Differential Revision: https://phabricator.services.mozilla.com/D223277
2024-09-30 21:35:42 +00:00
Masayuki Nakano ea3e323dff Bug 1906727 - Make HTMLEditor::SplitAncestorStyledInlineElementsAt check attr value type first r=peterv
Differential Revision: https://phabricator.services.mozilla.com/D215990
2024-07-25 00:41:49 +00:00
Sylvestre Ledru a3ea006705 Bug 1519636 - Reformat recent changes to the Google coding style r=emilio,necko-reviewers,geckoview-reviewers,application-update-reviewers,media-playback-reviewers,devtools-reviewers,anti-tracking-reviewers,profiler-reviewers,win-reviewers,migration-reviewers,padenot,mconley,nchevobbe,kershaw,gstoll,mstange,bytesized,m_kato
This new version of clang 17 also slightly changed the formatting.

# ignore-this-changeset

Differential Revision: https://phabricator.services.mozilla.com/D215914
2024-07-17 11:15:31 +00:00
Masayuki Nakano c7c8dc961d Bug 1891408 - part 2: Make WSScanResult::PointAtContent() return a point in a text node r=m_kato
When it's called, it just returns at the reached content node.  However, this
does not make sense when it reached a character in the text node.

Depends on D207685

Differential Revision: https://phabricator.services.mozilla.com/D207686
2024-04-24 06:12:09 +00:00
Masayuki Nakano 54ab9213e2 Bug 1885822 - part 2: Make WSScanResult always have non-null mContent if it reached something r=m_kato
Currently, it checks whether `mContent` is `nullptr` or not even if the scanner
reached something.  However, this makes the users of this object check whether
it has reasonable content or not and that makes the users messy.  Therefore,
the scanning method should guarantee that it's always error if it does not reach
any content.

Depends on D207681

Differential Revision: https://phabricator.services.mozilla.com/D207682
2024-04-22 06:31:10 +00:00
Masayuki Nakano d5eeec22c1 Bug 1890912 - Fix warning spam in HTMLEditor::SplitAncestorStyledInlineElementsAtRangeEdges() r=m_kato
The cause is an expected case.  Therefore, using `NS_WARN_IF` is wrong.

Differential Revision: https://phabricator.services.mozilla.com/D207240
2024-04-15 02:45:42 +00:00
Masayuki Nakano 5bae101f95 Bug 1874806 - Get rid of editor.inline_style.range.compatible_with_the_other_browsers pref r=m_kato
It was added for safer backout of bug 1792386, but it's shipped in 110. So, the
pref is not necessary anymore.

Differential Revision: https://phabricator.services.mozilla.com/D198660
2024-01-18 03:38:18 +00:00
Masayuki Nakano 8e647c8e23 Bug 1873794 - Make HTMLEditor::SplitAncestorStyledInlineElementsAt stop splitting ancestors of non-splittable elements r=m_kato
The method does not assume that an inline ancestor is not a splittable, but
it may occur in the edge cases.

I tried to make `HTMLEditor` adjust selection range at starting deletion to
stop handling it or select the most distant unmodifiable element, but it
 requires some expectation changes of tentative WPTs. It should be done in
a separate bug instead.

Differential Revision: https://phabricator.services.mozilla.com/D198345
2024-01-14 03:08:22 +00:00
Masayuki Nakano 8ea03990cb Bug 1870962 - Make HTMLEditor::SplitAncestorStyledInlineElementsAt never drop the "did split" state from the result r=m_kato
Oddly, it returns the latest result as split result. However, in the case,
it splits `<kbd>` under `<button>`, but does not split `<button>`, but the
caller expects that whether it did split or not.

Differential Revision: https://phabricator.services.mozilla.com/D197262
2023-12-27 02:53:44 +00:00
Masayuki Nakano f7c639310e Bug 1870222 - part 5: Make HTMLEditor::ClearStyleAt treat non-editable content as visible r=m_kato
Pasting and inserting HTML clears current style to respect the new style.
Therefore, the old ancestors shouldn't be removed when they have only
non-editable content.

Unfortunately, I have no idea how to test all of the paths which are changed
by this patch. However, I believe the method should always treat non-editable
content as visible.

Differential Revision: https://phabricator.services.mozilla.com/D196817
2023-12-25 12:54:08 +00:00
Masayuki Nakano 897f6fc48e Bug 1870222 - part 1: Rename HTMLEditUtils::EmptyCheckOption::IgnoreEditableState with inverting the meaning r=m_kato
It means that "treat non-editable things as visible" when it's not set.
However, it's odd.  You must assume that if no option is set, `IsEmpty()` etc
should treat non-editable nodes as visible things.  Therefore, this renames it
to `TreatNonEditableContentAsVisible` and changing all callers of
`HTMLEditUtils::IsEmptyNode`, `HTMLEditUtils::IsEmptyInlineContainer`,
`HTMLEditUtils::IsEmptyBlockElement` and
`HTMLEditUtils::CollectEmptyInlineContainerDescendants`.  So, this does not
change any behavior.

Differential Revision: https://phabricator.services.mozilla.com/D196813
2023-12-25 12:54:06 +00:00
Masayuki Nakano aaf99290a9 Bug 1859245 - part 1: Make JoinNodesResult and SplitNodeResult handle only the new direction mode r=m_kato
Depends on D191604

Differential Revision: https://phabricator.services.mozilla.com/D191605
2023-10-27 01:57:28 +00:00
Masayuki Nakano b4f7a36895 Bug 1852849 - Make HTMLEditor::AutoInlineStyleSetter::ExtendOrShrinkRangeToApplyTheStyle recompute common ancestor of the range if it updates the range r=m_kato
In this case, `<font face="monospace">abc []<br></font>`, the range applying
new style will be extended as `<font face="monospace">abc [<br>}</font>` first.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#1944

Then, the start point should be shrunken and the range should become
`<font face="monospace">abc {<br>}</font>`.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#1977-1978

However, `commonAncestor` is still the text node because it's not updated
after extending the range to include the `<br>`.  Then,
`AutoInlineStyleSetter::GetNextEditableInlineContent` fails to get `<br>`
from the text node.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#1576-1578

Finally, the unexpected range computation will reach here with the text editor
and adjust the start of the range to start of the text node.
https://searchfox.org/mozilla-central/rev/29bdf6ff9965a647c6f64d63fed2b5bd094532c7/editor/libeditor/HTMLStyleEditor.cpp#420-423

Therefore, the new text which the new style should be applied is jumped to
start of the text node.

Differential Revision: https://phabricator.services.mozilla.com/D190028
2023-10-07 05:56:15 +00:00
Masayuki Nakano 6f1b3be29e Bug 1851951 - Make HTMLEditor refer computed display instead of the HTML default style at considering block or inline element r=m_kato
Blink [1] and WebKit [2] refers `display-outside` value when they consider whether an
element is a block or an inline.

However, our editor refers HTML default style instead.  Therefore, our editor
cannot handle the following cases:
* If a container block is a non-HTML element whose `display` style is `block`.
* If a container `<div>` etc is styled as `inline` and typing `Enter` in it.
* If a container `<span>` is styled as `block` and it ends with spaces.

For making users get better result, we should follow the other browsers.

However, this is too risky change.  Therefore, this patch enables new behavior
only in the Nightly channel and early beta builds to collect feedback from
testers.

The big rules of checking block vs. inline are:
* When we handle block level edit actions such as formatting block, indenting
or outdenting selection, making or removing list, we should keep referring
the HTML default style because the other browsers do so and the commands are
intended for modifying the HTML structure.
* Otherwise, we should refer the computed style of the block.  However, if
working with non-connected elements, we may need a special handling that is
falling back to refer the HTML default style because `HTMLEditorDataTransfer`
work with non-connected document fragments.
* Finally, if we check visibility of collapsible white-spaces and `<br>`s, we
should refer computed style.  However, in this case, we may need to treat
ancestor `inline-block`s as block too, but for siblings, we should refer only
`display-outside`.

1. https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/editing/editing_utilities.cc;l=779;drc=31fb07c05718d671d96c227855bfe97af9e3fb20
2. https://searchfox.org/wubkat/rev/b054636fffeffa0314914a11ce39725a3057131e/Source/WebCore/editing/Editing.cpp#317

Differential Revision: https://phabricator.services.mozilla.com/D188598
2023-09-27 03:01:26 +00:00
Masayuki Nakano 0c6fc61a73 Bug 1845208 - Make HTMLEditor::SplitAncestorStyledInlineElementsAtRangeEdges abort if splitting points are lost r=m_kato
Due to the `DOMNodeRemoved` event listener, splitting at range boundaries
may fail tracking the DOM tree due to unexpected container lost.  In the
cases, the method should abort its task.

Differential Revision: https://phabricator.services.mozilla.com/D184457
2023-07-27 03:21:31 +00:00
Masayuki Nakano 5a8db77199 Bug 1840500 - Make HTMLEditor::ClearStyleAt() remove <br> for reuse before removing its parent from the tree r=m_kato
Once a parent node is removed from the tree, the node may become not editable
because editable state "inherits" from ancestor nodes.
`HTMLEditor::ClearStyleAt` cleans up unnecessary parent inline elements first,
but if `<br>` element which should be reused in the block parent is contained
the inline elements, `HTMLEditUtils::IsRemovableNode()` will start returning
`false` for the `<br>` element because of in a document fragment which do not
contain an element whose `contenteditable` is `true`.  Then,
`MoveNodeWithTransaction` fails to move it because of unremovable.

Therefore, this patch makes the method move `<br>` element before removing
inline elements and use `InsertNodeWithTransaction` instead if `<br>` element
is an orphan node.

Differential Revision: https://phabricator.services.mozilla.com/D182640
2023-07-12 00:52:39 +00:00
Masayuki Nakano c6c4a18798 Bug 1839553 - Move EditorBase::IsInPlaintextMode() to HTMLEditor with renaming to IsPlaintextMailComposer() r=m_kato
Now, most users of `EditorBase::IsInPlaintextMode()` are `HTMLEditor` itself.

There are some exceptions:

`EditorBase::GetDesiredSpellCheckState()` uses it to consider whether the root
(`<body>` if `HTMLEditor`) element's `specllcheck` attribute should be referred
or document's editing state.  I think that this should just check
`IsHTMLEditor()`, but I think it must be okay to keep this as-is for now.

`EditorEventListener::KeyUp()` uses it to consider whether `Ctrl` + left/right
`Shift` switches the text direction of the editing host if and only if user
installed both LTR/RTL keyboard layouts and running in Windows.  I think that
this should keep working in plaintext mail composer because nobody can control
the direction in plaintext editor.  Therefore, this needs to check either
`IsTextEditor()` or `IsPlaintextMailComposer()` returning `true`.

`EditorEventListener::DragEventHasSupportingData()` uses it to consider
whether the editor accepts styled text and files.  Therefore, it needs to check
either `IsTextEditor()` or `IsPlaintextMailComposer()` returning `false`.

Finally, we can stop setting `nsIEditor::eEditorPlaintextMask` to `TextEditor`.

Differential Revision: https://phabricator.services.mozilla.com/D181866
2023-06-28 01:01:12 +00:00
Emilio Cobos Álvarez 529c9ee321 Bug 1839922 - Remove usage of {Has,Get}Attr(kNameSpaceID_None, ..). r=edgar
We have more readable and faster versions (that just omit the namespace
arg).

Mostly done via sed, with a couple helpers to use the faster lookups
where possible.

Differential Revision: https://phabricator.services.mozilla.com/D181795
2023-06-23 10:01:32 +00:00
Masayuki Nakano 6e37f110ea Bug 1835427 - Make HTMLEditor::ClearStyleAt track given point at calling SplitAncestorStyledInlineElementsAt() r=m_kato
It may be called with `AutoTransactionsConserveSelection` instance.
Therefore, it may return `aPoint` as-is even after modifying the DOM tree.
So it should track the point during a call of
`SplitAncestorStyledInlineElementsAt()`.

Depends on D179421

Differential Revision: https://phabricator.services.mozilla.com/D179422
2023-06-12 00:23:31 +00:00
Masayuki Nakano 0f5524eaaa Bug 1809129 - part 5: Make AutoListElementCreator copy attributes at replacing block elements r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D168871
2023-02-14 02:51:32 +00:00