Граф коммитов

8008 Коммитов

Автор SHA1 Сообщение Дата
Masayuki Nakano 46b5e78f5d Bug 1811161 - Make the style editor sets `color` attribute value of `<font>` to normalized color value r=m_kato
Currently, our editor sets `color` attribute of `<font>` to given value as-is.
However, the other browsers normalize it to `#[0-9a-z]{6}` before setting the
value, and some WTP expects the behavior.  Therefore, we need to follow it for
avoiding meaningless failures.

According to WPT, the parameter can be `"transparent"` even without
`styleWithCSS`.  Additionally, CSS color values are also allowed if
`styleWithCSS` is `true`.  Therefore, this patch includes some fixes for them
too to avoid new failures.

Differential Revision: https://phabricator.services.mozilla.com/D167500
2023-01-26 10:04:23 +00:00
Masayuki Nakano d0da820599 Bug 1810655 - Make `HTMLEditor` check readonly flag when its public methods are called r=m_kato
The readonly flag of `HTMLEditor` can be set by chrome script or
`Document.execCommand("contentReadOnly")`.  However, the XPCOM APIs should keep
working to update the editable content.  E.g., if focused editor is a single
line text field, the app may want to change the value even if it's not editable
by the users.

Note that this patch does not fix all cases of all APIs because this is not
important for Firefox even though the status can be created by web apps (but
Firefox does not use XPCOM APIs basically, instead using XUL commands and it
should not work with readonly state since it may be kicked by user
interactions, e.g., executing a menu item or a shortcut key).
Therefore, it's enough to work it in current Thunderbird for now.

Differential Revision: https://phabricator.services.mozilla.com/D167353
2023-01-24 07:12:19 +00:00
Masayuki Nakano c750faea02 Bug 1808886 - Make the style editor treat `<font>` related styles as exclusive styles r=m_kato
Currently, Gecko does not support updating `font-size` style even in the CSS
mode.  Therefore, `CSSEditUtils` claims that `<font size="...">` style is not
CSS editable.  Supporting it requires a lot of new code but currently we don't
have any reports about this poor support.  Therefore, we should only try to
make the style editor remove `font-size` properties around selection at setting
`<font size="...">` style for now.

Additionally, Blink and WebKit does not allow to nest multiple `<font>` elements
and `<span>` elements which specify `font-size`, `font-family` or `color`.  When
setting one of the styles, they split ancestors which are related to the style
at range boundaries.  Then, unwrap the unnecessary elements.  This makes the
DOM tree simpler, thus, the later handling will be simpler.  Therefore, it's
worthwhile to follow them.

Unfortunately, there are some logic differences when handling styles in elements
having `id` attribute.  Therefore, there are some new test failures, but I guess
that it does not cause any problems in web apps in the wild because it's hard to
manage editable identified elements in cross browsers and I have no idea of
motivations to do it.

Depends on D166617

Differential Revision: https://phabricator.services.mozilla.com/D167011
2023-01-20 03:45:58 +00:00
Masayuki Nakano c83d685fe9 Bug 1808906 - Make the style editor handle `<font>` at last when there are multiple preserved styles r=m_kato
Height of inline elements are considered with current `font-size` and
`line-height`.  Therefore, if content in inline elements are taller, the
`background-color` does not fill the bigger content background entirely.
For solving this issue, Chrome handles styles of `<font>` element as
outer-most style.  This is reasonable approach, let's follow this.

For solving this issue, we can change the order of `PreservedStyle`s at setting
the preserved styles.  Then, `SetInlinePropertiesAsSubAction` is called with
reversed order and apply later style first and applies newer styles to all
content in an element which is previously inserted.  Therefore, the `<font>`
element styles should be last elements of `PendingStyles::mPreservingStyles`.

When applying new style, our style editor does not reuse existing `<font>`
element, and this causes writing WPT harder.  Therefore, this patch also changes
the applying range of `<font>` style to wrapping existing `<font>` element if
and only if its content is entirely selected.

Unfortunately, this approach cannot get exactly same result as Chrome because we
insert outer-most `<font>` element first, then, try to apply `background-color`,
at this moment, our style editor applies the style to the previously inserted
`<font>` element instead of creating new `<span>` element.  This behavior is
required for compatibility in the other cases.  Additionally, changing only this
behavior requires a lot of method changes to specify how to handle it.  However,
this incompatible behavior may not cause any problems in web apps in the wild.
Therefore, this patch does not solve this incompatible issue.  I think that once
we get a bug report caused by this difference, we should redesign how to set
multiple inline styles once.

Differential Revision: https://phabricator.services.mozilla.com/D166617
2023-01-17 23:46:58 +00:00
Marian-Vasile Laza c1d3f54c8a Backed out changeset cb55480eb7ff (bug 1808906) for causing wpt failures on multitest.html. CLOSED TREE 2023-01-17 13:00:33 +02:00
Masayuki Nakano b916190dd0 Bug 1808906 - Make the style editor handle `<font>` at last when there are multiple preserved styles r=m_kato
Height of inline elements are considered with current `font-size` and
`line-height`.  Therefore, if content in inline elements are taller, the
`background-color` does not fill the bigger content background entirely.
For solving this issue, Chrome handles styles of `<font>` element as
outer-most style.  This is reasonable approach, let's follow this.

For solving this issue, we can change the order of `PreservedStyle`s at setting
the preserved styles.  Then, `SetInlinePropertiesAsSubAction` is called with
reversed order and apply later style first and applies newer styles to all
content in an element which is previously inserted.  Therefore, the `<font>`
element styles should be last elements of `PendingStyles::mPreservingStyles`.

When applying new style, our style editor does not reuse existing `<font>`
element, and this causes writing WPT harder.  Therefore, this patch also changes
the applying range of `<font>` style to wrapping existing `<font>` element if
and only if its content is entirely selected.

Unfortunately, this approach cannot get exactly same result as Chrome because we
insert outer-most `<font>` element first, then, try to apply `background-color`,
at this moment, our style editor applies the style to the previously inserted
`<font>` element instead of creating new `<span>` element.  This behavior is
required for compatibility in the other cases.  Additionally, changing only this
behavior requires a lot of method changes to specify how to handle it.  However,
this incompatible behavior may not cause any problems in web apps in the wild.
Therefore, this patch does not solve this incompatible issue.  I think that once
we get a bug report caused by this difference, we should redesign how to set
multiple inline styles once.

Differential Revision: https://phabricator.services.mozilla.com/D166617
2023-01-17 05:44:08 +00:00
Masayuki Nakano 4be6e924dc Bug 1807829 - Make `HTMLEditor::CreateStyleForInsertText` use same logic as `HTMLEditor::SetInlinePropertiesAsSubAction` to apply new style r=m_kato
The problem in Yahoo mail is, when you apply new font size to:
```
<div><font size="7">{}<br></font></div>
```

then, when you type text, you'll get:
```
<div><font size="7"><font size="4">abc<br></font></font></div>
```

because `HTMLEditor::CreateStyleForInsertText` does not check ancestors to
apply new style to empty text node which is created by the method for
placeholder.  Of course, the other browsers update the existing
`<font size="7">` instead and we should follow it.

However, there are 3 problems:
1. Our editor may adjust insertion point to nearest editable text node if caret
in empty inline elements.
2. Our editor supports increase/decrease font size which have been removed from
`Document.execCommand`, but Thunderbird keeps using it, and that's implemented
with an independent method.
3. Our style editor code does not support applying style to collapsed selection.

Therefore, this patch does:
1. keep create empty text node to apply new style at specific point.
2. give up to use new path if there is preserved font size increment/decrement.
3. separate `HTMLEditor::SetInlinePropertiesAsSubAction` and add new path for
applying style to collapsed range.

Then, `HTMLEditor::CreateStyleForInsertText` can use
`HTMLEditor::SetInlinePropertiesAsSubAction` which supports handling new styles
with existing ancestors.

Differential Revision: https://phabricator.services.mozilla.com/D166416
2023-01-17 05:26:14 +00:00
Cosmin Sabou 5be3068372 Backed out changeset dfd4ec691465 (bug 1807829) for causing bp-hybrid bustages on HTMLEditUtils.h. CLOSED TREE 2023-01-17 03:44:41 +02:00
Sandor Molnar 469df50089 Backed out changeset 649e12877126 (bug 1808906) for causing bp-hybrid bustages. 2023-01-17 03:18:05 +02:00
Masayuki Nakano d83e7a60f8 Bug 1808906 - Make the style editor handle `<font>` at last when there are multiple preserved styles r=m_kato
Height of inline elements are considered with current `font-size` and
`line-height`.  Therefore, if content in inline elements are taller, the
`background-color` does not fill the bigger content background entirely.
For solving this issue, Chrome handles styles of `<font>` element as
outer-most style.  This is reasonable approach, let's follow this.

For solving this issue, we can change the order of `PreservedStyle`s at setting
the preserved styles.  Then, `SetInlinePropertiesAsSubAction` is called with
reversed order and apply later style first and applies newer styles to all
content in an element which is previously inserted.  Therefore, the `<font>`
element styles should be last elements of `PendingStyles::mPreservingStyles`.

When applying new style, our style editor does not reuse existing `<font>`
element, and this causes writing WPT harder.  Therefore, this patch also changes
the applying range of `<font>` style to wrapping existing `<font>` element if
and only if its content is entirely selected.

Unfortunately, this approach cannot get exactly same result as Chrome because we
insert outer-most `<font>` element first, then, try to apply `background-color`,
at this moment, our style editor applies the style to the previously inserted
`<font>` element instead of creating new `<span>` element.  This behavior is
required for compatibility in the other cases.  Additionally, changing only this
behavior requires a lot of method changes to specify how to handle it.  However,
this incompatible behavior may not cause any problems in web apps in the wild.
Therefore, this patch does not solve this incompatible issue.  I think that once
we get a bug report caused by this difference, we should redesign how to set
multiple inline styles once.

Depends on D166416

Differential Revision: https://phabricator.services.mozilla.com/D166617
2023-01-16 23:59:45 +00:00
Masayuki Nakano 6d33379e63 Bug 1807829 - Make `HTMLEditor::CreateStyleForInsertText` use same logic as `HTMLEditor::SetInlinePropertiesAsSubAction` to apply new style r=m_kato
The problem in Yahoo mail is, when you apply new font size to:
```
<div><font size="7">{}<br></font></div>
```

then, when you type text, you'll get:
```
<div><font size="7"><font size="4">abc<br></font></font></div>
```

because `HTMLEditor::CreateStyleForInsertText` does not check ancestors to
apply new style to empty text node which is created by the method for
placeholder.  Of course, the other browsers update the existing
`<font size="7">` instead and we should follow it.

However, there are 3 problems:
1. Our editor may adjust insertion point to nearest editable text node if caret
in empty inline elements.
2. Our editor supports increase/decrease font size which have been removed from
`Document.execCommand`, but Thunderbird keeps using it, and that's implemented
with an independent method.
3. Our style editor code does not support applying style to collapsed selection.

Therefore, this patch does:
1. keep create empty text node to apply new style at specific point.
2. give up to use new path if there is preserved font size increment/decrement.
3. separate `HTMLEditor::SetInlinePropertiesAsSubAction` and add new path for
applying style to collapsed range.

Then, `HTMLEditor::CreateStyleForInsertText` can use
`HTMLEditor::SetInlinePropertiesAsSubAction` which supports handling new styles
with existing ancestors.

Differential Revision: https://phabricator.services.mozilla.com/D166416
2023-01-16 23:42:27 +00:00
Tom Schuster 9cf9360385 Bug 1808177 - mPointToInsert.GetContainer() in BlobReader::OnError could be nullptr. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D165858
2023-01-04 12:46:27 +00:00
Sandor Molnar 356a0e8699 Backed out changeset 78bd7cfde7b6 (bug 1793876) for causing wpt failures in /editing/other/editing-div-outside-body.html?designMode 2022-12-20 12:14:01 +02:00
Masayuki Nakano 5591cace33 Bug 1793876 - Make `HTMLEditor::ComputeEditingHostInternal` never return non-editable `<body>` r=m_kato
It returns the non-editable `<body>` causes the deletion handlers fail to
adjust range in the editing host and that caused hitting the assertion.

This patch also includes the wrong testcase with which the bug was reported.

Differential Revision: https://phabricator.services.mozilla.com/D164533
2022-12-20 07:28:24 +00:00
Masayuki Nakano e5e7abdba6 Bug 1805554 - Make `HTMLEditor::MaybeSplitAncestorsForInsertWithTransaction` return `NS_ERROR_EDITOR_UNEXPECTED_DOM_TREE` if it got lost the editing host r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D164771
2022-12-20 03:13:57 +00:00
Masayuki Nakano 3c28aeafd1 Bug 1792386 - part 6: Make `HTMLEditor::RemoveInlinePropertiesAsSubAction` shrink the selection range r=m_kato
If the start boundary is immediately before the next node or if the end boundary
is immediately after the previous node, it should be shrunken for consistency
with setting style behavior and the other browsers.

Depends on D164526

Differential Revision: https://phabricator.services.mozilla.com/D164527
2022-12-20 01:52:32 +00:00
Masayuki Nakano ef9d4c15b7 Bug 1792386 - part 5: Move some jobs in `HTMLEditor::RemoveInlinePropertiesAsSubAction` into `AutoInlineStyleSetter` r=m_kato
Depends on D164525

Differential Revision: https://phabricator.services.mozilla.com/D164526
2022-12-20 01:12:28 +00:00
Masayuki Nakano cf849ddc10 Bug 1792386 - part 4: Make `HTMLEditor::RemoveInlinePropertiesAsSubAction` handle deleting bold style coming from parent in its own loop r=m_kato
The remaining issue is, `RemoveInlinePropertiesAsSubAction` uses
`AutoInlineStyleSetter` for removing bold style coming from parent block or
its ancestors with new `<span style="font-weight: normal">`.  However,
in the normal removing code users `Selection` range restorer.  Therefore,
we cannot adjust the range simply without splitting the part of the normal
part and the special part for bold style.

This patch moves the part from an existing `for` loop which calls
`RemoveStyleInside` to a new `for` loop.

Depends on D164524

Differential Revision: https://phabricator.services.mozilla.com/D164525
2022-12-20 00:44:02 +00:00
Masayuki Nakano 0ddac48689 Bug 1792386 - part 3: Clean up `HTMLEditor::PromoteInlineRange` and `HTMLEditor::PromoteRangeIfStartsOrEndsInNamedAnchor` r=m_kato
They ignore non-editable nodes at scanning the DOM tree.  According to the
other browsers' behavior, at least `PromoteInlineRange` should not do it.
(Removing `<a name>` is not a feature of `execCommand` and the `unlink` behavior
is anyway incompatible.)

Additionally, we don't need to stop scanning the DOM tree when we meet `<body>`.
Scanning its parents also fine because typically it's wont be extended since
there should be `<head>` element before `<body>`.

Therefore, we can make them simpler.

Depends on D164523

Differential Revision: https://phabricator.services.mozilla.com/D164524
2022-12-20 00:35:06 +00:00
Masayuki Nakano 5081bd63e8 Bug 1792386 - part 2: Make `AutoInlineStyleSetter` store updated range to compute new `Selection` after applying the style r=m_kato
Chrome and Safari selects content nodes which are applied the new style.
E.g., when `abc[def]ghi` gets embolden, it should become `abc<b>[def]</b>ghi`,
but Gecko does `abc[<b>def]</b>ghi` because `RangeUpdater::SelAdjSplitNode`
does not update the split point (i.e., end of the new text node, "abc" in the
example) [1].

Therefore, this patch makes `AutoInlineStyleSetter` record first and last points
trying to apply the style, then, `HTMLEditor::SetInlinePropertiesAsSubAction`
can set `Selection` to the applied range.

1. https://searchfox.org/mozilla-central/rev/dd216c1307a2bf1b0d2465b9749fa86dac44303a/editor/libeditor/SelectionState.cpp#329-334

Depends on D164522

Differential Revision: https://phabricator.services.mozilla.com/D164523
2022-12-20 00:25:45 +00:00
Masayuki Nakano 72b07d893e Bug 1792386 - part 1: Make `HTMLEditor::SetInlinePropertiesAsSubAction` extend and/or shrink range smarter r=m_kato
Blink's behavior is better than Gecko.  That is, when selected range crosses
an inline element boundary, Blink shrinks selected range to select only
children, but Gecko extends selected range to cover all inline parents around
the range.  E.g., when setting `abc[<i>def]</i>ghi` to `<b>`, Chrome changes it
to `abc<i><b>def</b></i>ghi`, but Gecko changes it to `abc<b><i>def</i></b>ghi`.
The Gecko's behavior is odd especially when `abc<i>[def]</i>ghi` since user
does not select the `<i>`, but Gecko wraps it in new `<b>`.

However, if the range contains an inline element entirely, e.g.,
`abc[<i>def</i>]ghi`, Chrome changes it to `abc<b><i>def</i></b>ghi` without
shrinking the range.  This is reasonable too.

On the other hand, there is a case that browsers need to extend the range.
That is an parent inline element has the style of what we're setting a range to.
E.g., `abc<span style="background-color: red"><b>[def]</b></span>ghi`, user
wants to update the style attribute of the `<span>` element rather than wrapping
the selected text node with new `<span>` element in the `<b>`.  Therefore,
if shrunken range starts from very beginning of a node or ends at very end of
a node and the inline parents have same style, we need extend the range to wrap
it.  (Note that Gecko deletes same styles in range with
`HTMLEditor::RemoveStyleInside`.  Therefore, wrapping most distant inline
element makes Gecko works as expected.)

Finally, if the containers of range boundaries are not same one, we should
extend the range to save the number of creating element.  E.g.,
`<span>[abc</span> <span>def]</span>` should become
`<b><span>abc</span> <span>def</span>` rather than
`<span><b>abc</b></span><b> </b><span><b>def</b></span>`.

Note that the new expected failures are caused by the difference of selection
range after applying the style.  That should be fixed by the following patch.

Depends on D164521

Differential Revision: https://phabricator.services.mozilla.com/D164522
2022-12-20 00:19:41 +00:00
Andrew McCreight ce28c41da0 Bug 1805931, part 2 - Automated removal of uses of ROOT and UNROOT CC macros. r=smaug
As of the prior patch, these are no longer needed. I removed
these with a script, then ran clang-format on the files, then
manually reverted a few unrelated changed from the formatter.

Differential Revision: https://phabricator.services.mozilla.com/D164829
2022-12-15 19:45:01 +00:00
Masayuki Nakano 2594ee7d9c Bug 1789574 - part 2: Make `HTMLEditor` preserve style of following text if deleting/replacing range starts around inline element boundary r=m_kato
Chrome preserves inline styles of first character in the deleting/replacing
if first visible thing is text.  Safari preserves inline style of the first
content of the range (i.e., styles of `<img>` etc is also respected).
For now, due to the market share and Safari's behavior is not obviously better
than Chrome, let's try to emulate the Chrome's behavior.  However, the rules are
complicated and probably depend on how it implements the deletion.  Therefore,
this patch makes Gecko only scan following text node if selection range starts
from end of a text node.

Depends on D164520

Differential Revision: https://phabricator.services.mozilla.com/D164521
2022-12-15 09:11:48 +00:00
Masayuki Nakano 4493e43e5d Bug 1789574 - part 1: Make `HTMLEditor` preserve order of inline style elements too r=m_kato
Currently, `HTMLEditor` preserves styled elements with the reversed order in
the loop.
https://searchfox.org/mozilla-central/rev/d7d5c89ee7bc70dec0fd846689ca030f94931393/editor/libeditor/HTMLEditSubActionHandler.cpp#8638-8658

I.e., if `<b><i></i></b>` is restored in the HTML styling mode, it will be
restored as `<i><b>...</b></i>`.  This blocks writing tests for bug 1789574.
Therefore, this should be fixed first.

(As I commented in the method, ideally we should store all inline elements and
restore all of them, but currently we don't need to do it.  It requires redesign
of the style cache, but it seems that we don't know web apps which is broken by
current behavior.  Therefore, I think that we should do it when we meet a
trouble with the behavior.)

Depends on D164519

Differential Revision: https://phabricator.services.mozilla.com/D164520
2022-12-15 09:11:47 +00:00
Masayuki Nakano 077fe4f24c Bug 1789574 - part 0: Add WPT to check which inline style should be preserved r=m_kato
This patch removes some traditional behavior check in the mochitest and
port it into expected results which match with the behavior of Chrome.

Almost all the new tests pass in Chrome, but some fails due to odd result in
Chrome. E.g., Chrome sometimes append `style` attribute with empty value.
Therefore, the expectations in this patch must be what Chrome developers
expected at implementing it.

Depends on D164004

Differential Revision: https://phabricator.services.mozilla.com/D164519
2022-12-15 09:11:47 +00:00
Jan-Niklas Jaeschke 3db9161d69 Bug 1803336: Simplified check if a range to delete is start/end of a text node. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D164360
2022-12-14 08:21:29 +00:00
Masayuki Nakano db70f10b72 Bug 1803044 - part 9: Make the style editor use existing inline element in the CSS mode as far as possible r=m_kato
The other browsers use any inline elements to set CSS property for applying
an inline style.  However, Gecko limits it to a `<span>` which does not have
any attributes.  The other browsers' design is better for saving number of
elements and runtime cost of inserting new element (moving all children to the
new element and inserting it to the original position).  Therefore, it's nicer
to follow the other browses.  Then, we can avoid new WPT failures at aligning
other behaviors to the other browsers.

With doing that, removing style code requires complicated changes because
`RemoveStyleInside` assumes that one element has one style, but after taking
the compatible behavior, one element can have multiple styles including the
style represented by the element itself.

Note that the new expected failures are caused by bug 1183844. Gecko returns
closest ancestor element's background color for
`queryCommandValue("backColor")`.  Therefore, it returns "transparent" of the
inner `<span>` element.

Differential Revision: https://phabricator.services.mozilla.com/D164004
2022-12-13 03:37:38 +00:00
Masayuki Nakano 35e5ee1094 Bug 1803044 - part 8: Refactor the bottom half of `HTMLEditor::RemoveStyleInside` r=m_kato
Now, we can make there simpler because the part does one of them:
* Replaces element with new `<span>`
* Removes element
* Removes attribute
* Does nothing

However, there are duplicated code.  We should consider what there does with
lambdas.

Depends on D164002

Differential Revision: https://phabricator.services.mozilla.com/D164003
2022-12-13 03:31:51 +00:00
Masayuki Nakano 3ed70dcc38 Bug 1803044 - part 7: Make `HTMLEditor::RemoveStyleInside` use `HTMLEditor::ReplaceContainerWithTransaction` r=m_kato
Depends on D164001

Differential Revision: https://phabricator.services.mozilla.com/D164002
2022-12-13 03:25:12 +00:00
Masayuki Nakano 45ccd3c8fe Bug 1803044 - part 6: Make `HTMLEditor::RemoveStyleInside` remove CSS style before touching the DOM tree structure r=m_kato
This change makes the following changes smaller.  Once we remove CSS style
first, then, it becomes easier to consider whether we should delete the element
since `style` attribute may be deleted by `ChangeStyleTransaction` if the
removing style is the last rule in it.

Depends on D164000

Differential Revision: https://phabricator.services.mozilla.com/D164001
2022-12-13 03:14:17 +00:00
Masayuki Nakano 13c3a0c6ec Bug 1803044 - part 5: Make `HTMLEditor::RemoveStyleInside` check whether aElement is editable first r=m_kato
Depends on D163999

Differential Revision: https://phabricator.services.mozilla.com/D164000
2022-12-13 03:06:12 +00:00
Masayuki Nakano 29bc09a466 Bug 1803044 - part 4: Make `HTMLEditor::SetAttributeOrEquivalent` insert a white-space only when old value is empty r=m_kato
This causes some new failures after applying the following patches.

Depends on D163998

Differential Revision: https://phabricator.services.mozilla.com/D163999
2022-12-13 01:48:51 +00:00
Masayuki Nakano 5255ec92fc Bug 1803044 - part 3: Make `EditorBase::RemoveAttributeWithTransaction` stop creating transaction if the element does not have the removing attribute r=m_kato
Depends on D163997

Differential Revision: https://phabricator.services.mozilla.com/D163998
2022-12-13 01:17:11 +00:00
Masayuki Nakano 512839adbf Bug 1803044 - part 2: Improve `HTMLEditUtils::ElementHasAttributeExcept` r=m_kato
In the following patches, the new variations are required.  Additionally,
`HTMLEditor` should ignore empty `class`, `id` and `style` attributes because
an older API does it.
https://searchfox.org/mozilla-central/rev/2ad13433da20a0749e1e9a10ec0ab49b987c2c8e/editor/libeditor/HTMLStyleEditor.cpp#3398-3402

Depends on D163996

Differential Revision: https://phabricator.services.mozilla.com/D163997
2022-12-13 01:09:43 +00:00
Masayuki Nakano 615cd98adf Bug 1803044 - part 1: Create a method of `EditorInlineStyle` to check whether an element represents the style r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D163996
2022-12-13 01:03:16 +00:00
Masayuki Nakano d9e5a56230 Bug 1803623 - Don't use `Result::unwrap` after ignoring the error state r=m_kato
Depends on D163767

Differential Revision: https://phabricator.services.mozilla.com/D163768
2022-12-06 07:33:15 +00:00
Masayuki Nakano 7ff1025425 Bug 1803626 - Make `HTMLEditor::AlignNodesAndDescendants` check whether insertion point stays valid r=m_kato
In the test case, `deleteFromDocument` call makes the point unset.  We should
make it check whether a legacy mutation event listener creates unexpected result
after calling `RemoveAlignFromDescendants`.

Differential Revision: https://phabricator.services.mozilla.com/D163767
2022-12-06 07:33:14 +00:00
Masayuki Nakano be355a79de Bug 1802831 - Make `AutoInlineStyleSetter` align setting `text-decoration` style behavior in the CSS mode to the other browsers r=m_kato
Gecko wraps selection (and parent elements if entirely selected in them) in
new `<span>` element and set `text-decoration`.  However, the other browsers
tries to reuse selected or parent element which already has `text-decoration`
style. The other browsers' behavior is more reasonable from point of view of:
* smaller footprint
* minimizing to update the DOM tree

And aligning the behavior makes it easier to check the compatibility between
browsers and us avoid from new test failures aligning other behaviors to the
other browsers.

If there is an element specifying `text-decoration`, its `text-decoration`
declaration should be updated first.

If found element is `<i>`, `<s>` or `<strike>`, it should be replaced with new
`<span>` because these elements just represents the visual style and we should
not use such elements in the CSS mode (bug 1802736).  At this time, unless
the element has `text-decoration` rules in its `style` attribute value, we
the new `text-decoration` style should have the value represented by the
removing element (i.e., `underline` for `<i>`, `line-through` for the others).

However, if found element is `<ins>` or `<del>`, we should set its
`text-decoration` and unless it already has `text-decoration` rules, we need
to append corresponding style (`underline` for `<ins>` and `line-through` for
`<del>`) too.

When setting the values or removing a value from `text-decoration` declaration,
the value should be normalized to represent only `text-decoration-line` for
compatibility with the other browsers and keeping the implementation simpler.
And also the value should be built as the following order:
1. underline
2. overline
3. line-though

rather than updating current value with complicated code. Then, the tests can
compare with one expectation.

Depends on D163188

Differential Revision: https://phabricator.services.mozilla.com/D163429
2022-12-02 22:50:56 +00:00
Masayuki Nakano 83c63f6aec Bug 1802736 - Make `AutoInlineStyleSetter` stop using different type of elements from the HTML/CSS mode point of view r=m_kato
The other browsers do not move styling nodes to existing element if the element
is never created in the mode. For example, `execCommand("bold")` in the CSS mode
for `[abc]<b>def</b>`, the other browsers make it
`<span style="font-weight: bold">abc</span><b>def</b>`, but Gecko does
`<b>abcdef</b>`.  Similarly, `execCommand("bold")` in the HTML mode for
`[abc]<span style="font-weight: bold">def</span>`, the other browsers make it
`<b>abc</b><span style="font-weight: bold">def</span>`, but Gecko does it
`<span style="font-weight: bold">abcdef</span>`.

This patch makes Gecko align the behavior to the other browsers.

Differential Revision: https://phabricator.services.mozilla.com/D163188
2022-12-01 07:58:14 +00:00
Masayuki Nakano 643cdfeed4 Bug 1802668 - part 3: Make `AutoInlineStyleSetter` remove similar element at setting style r=m_kato
Depends on D163186

Differential Revision: https://phabricator.services.mozilla.com/D163187
2022-12-01 00:16:57 +00:00
Masayuki Nakano 3b1fb3cea4 Bug 1802668 - part 2: Make `AutoInlineStyleSetter` stop using `<strong>`, `<em>` and `<strike>` as alternative container of `<b>`, `<i>` and `<strike>` r=m_kato
The other browsers do not do this. From semantics point of view, stop reusing
them is better.

Depends on D163185

Differential Revision: https://phabricator.services.mozilla.com/D163186
2022-12-01 00:16:56 +00:00
Masayuki Nakano de84b4f105 Bug 1802418 - Make the style editor remove potentially conflicting `vertical-align` styles at applying `<sup>` or `<sub>` style r=m_kato
`execCommand("superscript")` and `execCommand("subscript")` are handled
specially.

`<sup>` and `<sub>` are exclusive. Therefore, existing element is removed first.

However, they are not mapped to CSS due to bug 394304 comment 2 even though the
behavior is different from the other browsers.  Therefore, Gecko does not remove
`vertical-align` styles from selected ranges. On the other hand, the other
browsers do it. This makes sense and matches with the handling in HTML mode.

Therefore, we should remove `vertical-align` style around the selection ranges.

Note that this updates existing WPTs.

The first block of each command checks how the command work with similar
`<span>` having `vertical-align` style. The new expectation matches with the
other browsers (i.e., currently they fail in the other browsers).

The second block of each command checks how the command work with similar
situation but there is a sibling which has the applying style (i.e., `<sup>`
or `<sub>`).  These tests keep failing in the other browsers since they want
to update `vertical-align` style at the selected range in the `<span>` having
`vertical-align` style.

Anyway, this fix is for avoiding new WPT failures of fixing bug 1792386, and
these commands must not be used so widely especially in the CSS mode.
Therefore, I believe that this change is not so risky.

Depends on D163183

Differential Revision: https://phabricator.services.mozilla.com/D163184
2022-11-29 05:48:53 +00:00
Masayuki Nakano b1973c6d74 Bug 1802402 - Group the inline style setter methods into stack only class r=m_kato
* `SetInlinePropertyOnTextNode`
* `SetInlinePropertyOnNode`
* `SetInlinePropertyOnNodeImpl`
* `ElementIsGoodContainerForTheStyle`

These `HTMLEditor` methods run only when `SetInlinePropertyOnTextNode` or
`SetInlinePropertyOnNode` is called, they take common style information as 3
arguments and they run in a short period.  Therefore, they can be in a stack
only class.

Differential Revision: https://phabricator.services.mozilla.com/D163183
2022-11-28 11:13:02 +00:00
Masayuki Nakano 23f84e1ccb Bug 1777054 - part 2: Make `test_bug795785.html` synthesize key events in each event loop r=m_kato
When keyboard events are fired by auto repeat feature of OS, each event is fired
in each event loop.  However, `repeat` feature of the `synthesizeKey` and
typing multiple characters with `sendString` dispatch keyboard events in an
event loop.  Therefore, asynchronous scrolling is handled differently from
users' scenario.  So we should emulate the users' scenario better with
synthesizing each event with waiting a tick.

Depends on D162527

Differential Revision: https://phabricator.services.mozilla.com/D162528
2022-11-28 03:01:51 +00:00
Masayuki Nakano a8b90c9538 Bug 1777054 - part 1: Rewrite `test_bug795785.html` with `apz_test_utils.js` r=m_kato
It uses legacy `hitEventLoop` hack with `setTimeout`.  Now, we have better
utility methods and can avoid using callbacks with using async/await.

However, waiting only for `waitToClearOutAnyPotentialScrolls` does not fix
the intermittent failure.  Therefore, this patch checks whether the scroll
result in its wrapper to make sure that there is no pending scroll.

Differential Revision: https://phabricator.services.mozilla.com/D162527
2022-11-28 03:01:51 +00:00
Masayuki Nakano 410ddf5d67 Bug 1801028 - part 18: Make `CSSEditUtils::GenerateCSSDeclarationsFromHTMLStyle` take `EditorElementStyle` r=m_kato
And also making it and `BuildCSSDeclarations` return pairs of CSS property and
value with an array makes their callers simpler.

Depends on D162517

Differential Revision: https://phabricator.services.mozilla.com/D162518
2022-11-25 12:57:26 +00:00
Masayuki Nakano 753e7b2a04 Bug 1801028 - part 17: Make `CSSEditUtils::IsCSSEditableProperty` take `EditorElementStyle` r=m_kato
It can take `const Element&` instead of `nsINode*`, then most callers can be
simpler.

Depends on D162516

Differential Revision: https://phabricator.services.mozilla.com/D162517
2022-11-25 09:29:07 +00:00
Masayuki Nakano c2398f968f Bug 1801028 - part 16: Make `CSSEditUtils::GetComputedCSSEquivalentToHTMLInlineStyleSet` take `EditorElementStyle` r=m_kato
Depends on D162515

Differential Revision: https://phabricator.services.mozilla.com/D162516
2022-11-25 09:22:32 +00:00
Masayuki Nakano 715aea76d9 Bug 1801028 - part 15: Make `HTMLEditor::RemoveCSSEquivalentToHTMLStyle(With|Without)Transaction` take `EditorElementStyle` r=m_kato
Depends on D162514

Differential Revision: https://phabricator.services.mozilla.com/D162515
2022-11-25 09:14:38 +00:00
Masayuki Nakano 92b9c76726 Bug 1801028 - part 14: Make `CSSEditUtils::SetCSSEquivalentToHTMLStyle(With|Without)Transaction` take `EditorElementStyle` r=m_kato
This patch creates a base class of `EditorInlineStyle`, the name is
`EditorElementStyle`.  It requires only attribute of HTML.  However, it's
obviously different from `EditorInlineStyle`'s rule which is `mHTMLProperty`
cannot be `nullptr`.  Therefore, the methods which can treat only
`EditorInlineStyle` do not want the data only whose attribute is not `nullptr`.
For solving this issue at build time, this approach is better than renaming
`EditorInlineStyle` and make it have the new mode.

Depends on D162513

Differential Revision: https://phabricator.services.mozilla.com/D162514
2022-11-25 09:04:35 +00:00
Masayuki Nakano f95a663df7 Bug 1801028 - part 13: Make `HTMLEditUtils::IsInlineStyleSetByElement` take `EditorInlineStyle` r=m_kato
Depends on D162512

Differential Revision: https://phabricator.services.mozilla.com/D162513
2022-11-25 07:14:16 +00:00
Masayuki Nakano 6e6720944a Bug 1801028 - part 12: Make `CSSEditUtils::Have(Specified|Computed)CSSEquivalentStyles` take `EditorInlineStyle` r=m_kato
Depends on D162511

Differential Revision: https://phabricator.services.mozilla.com/D162512
2022-11-25 06:55:31 +00:00
Masayuki Nakano 26d6947e93 Bug 1801028 - part 11: Make `CSSEditUtils::Is(Computed|Specified)CSSEquivalentToHTMLInlineStyleSet` take `EditorInlineStyle` r=m_kato
Depends on D162510

Differential Revision: https://phabricator.services.mozilla.com/D162511
2022-11-25 06:43:51 +00:00
Masayuki Nakano 86439634a2 Bug 1801028 - part 10: Make `HTMLEditor::RemoveStyleInside` take `EditorInlineStyle` r=m_kato
Depends on D162509

Differential Revision: https://phabricator.services.mozilla.com/D162510
2022-11-25 06:26:04 +00:00
Masayuki Nakano 80c186fc72 Bug 1801028 - part 9: Make `HTMLEditor::ElementIsGoodContainerForTheStyle` take `EditorInlineStyleAndValue` r=m_kato
Depends on D162508

Differential Revision: https://phabricator.services.mozilla.com/D162509
2022-11-25 06:01:03 +00:00
Masayuki Nakano 1765ca764f Bug 1801028 - part 8: Make `HTMLEditor::SetInlinePropertyOnNode` and `HTMLEditor::SetInlinePropertyOnNodeImpl` take `EditorInlineStyleAndValue` r=m_kato
They are called each other. Therefore, this patch changes them once.

Depends on D162507

Differential Revision: https://phabricator.services.mozilla.com/D162508
2022-11-25 05:20:49 +00:00
Masayuki Nakano 14d073d0b7 Bug 1801028 - part 7: Make `HTMLEditor::SetInlinePropertyOnTextNode` take `EditorInlineStyleAndValue` r=m_kato
Depends on D162506

Differential Revision: https://phabricator.services.mozilla.com/D162507
2022-11-25 04:52:25 +00:00
Masayuki Nakano 40545cc05d Bug 1801028 - part 6: Make `HTMLEditor::SplitAncestorStyledInlineElementsAt` take `EditorInlineStyle` r=m_kato
Depends on D162505

Differential Revision: https://phabricator.services.mozilla.com/D162506
2022-11-25 04:17:46 +00:00
Masayuki Nakano 5b9f27a281 Bug 1801028 - part 5: Make `HTMLEditor::SplitAncestorStyledInlineElementsAtRangeEdges` take `EditorInlineStyle` r=m_kato
Depends on D162504

Differential Revision: https://phabricator.services.mozilla.com/D162505
2022-11-25 02:38:56 +00:00
Masayuki Nakano 9e35e5429b Bug 1801028 - part 4: Make `HTMLEditor::ClearStyleAt` take `EditorInlineStyle` r=m_kato
Depends on D162503

Differential Revision: https://phabricator.services.mozilla.com/D162504
2022-11-25 02:15:51 +00:00
Masayuki Nakano 57a03b7aaa Bug 1801028 - part 3: Make `HTMLEditor::GetInlinePropertyBase` take `EditorInlineStyle` r=m_kato
Depends on D162502

Differential Revision: https://phabricator.services.mozilla.com/D162503
2022-11-25 00:54:55 +00:00
Masayuki Nakano 9c32140caa Bug 1801028 - part 2: Move `CSSEditUtils::IsCSSInvertible` to `EditorInlineStyle` r=m_kato
It does not make sense to make the static method take only `EditorInlineStyle`.

Depends on D162501

Differential Revision: https://phabricator.services.mozilla.com/D162502
2022-11-25 00:22:32 +00:00
Masayuki Nakano 272cd8bc17 Bug 1801028 - part 1: Make `HTMLEditor::IsRemovableParentStyleWithNewSpanElement` take `EditorInlineStyle` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D162501
2022-11-25 00:12:58 +00:00
Mark Banner ec76a72706 Bug 1799314 - Convert consumers of testing modules to import ES modules direct (miscellaneous). r=mossop
Differential Revision: https://phabricator.services.mozilla.com/D161917
2022-11-17 12:00:32 +00:00
Masayuki Nakano bb73eac1f4 Bug 1800553 - part 1: Change most getter methods of `HTMLAnchorElement` to `const` methods r=smaug
Most of them are used only by the WebIDL bindings. Therefore, this fixes only
one caller in `HTMLEditUtils`.

`GetText` requires to change `nsContentUtils`, therefore it'll be done by the
following patch.

Differential Revision: https://phabricator.services.mozilla.com/D162065
2022-11-16 00:21:30 +00:00
Jan-Niklas Jaeschke c365257e21 Bug 1800043: Fixed condition to determine end of selected string. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D161881
2022-11-11 13:04:54 +00:00
Masayuki Nakano ae40061c72 Bug 1799231 - Make `WhiteSpaceVisibilityKeeper::MergeFirstLineOfRightBlockElementIntoAncestorLeftBlockElement` verify destination r=m_kato
Due to the preceding `DeleteInvisibleASCIIWhiteSpaces` call, the destination
may be lost since `aLeftContentInBlock` may have already been removed from the
DOM tree.  Therefore, it should stop handling the deletion when destination is
modified by the web app.

Depends on D161423

Differential Revision: https://phabricator.services.mozilla.com/D161424
2022-11-09 05:31:08 +00:00
Masayuki Nakano ab48ca181d Bug 1799226 - Make `HTMLEditor::AlignContentsAtRanges` stop referring `Selection` directly r=m_kato
It still refers `Selection` via `EditorBase::GetFirstRangeStartPoint`, however,
it should work with `aRanges` instead.

Depends on D161422

Differential Revision: https://phabricator.services.mozilla.com/D161423
2022-11-08 23:38:19 +00:00
Masayuki Nakano ba5d192b11 Bug 1798214 - Make `HTMLeditor::AdjustCaretPositionAndEnsurePaddingBRElement` invalidate child after inserting `<br>` element of the insertion point r=m_kato
It keeps using the insertion point after inserting `<br>` element for making
empty last line visible. Therefore, referring `IsStartOfContainer` in
`HTMLEditUtils::GetPreviousContent` causes the warning of mismating offset
and child node.

According to the old code [1], `HTMLEditRules` keeps scanning the DOM tree with
the offset of the insertion point.  Therefore, it should invalidate the child
after inserting `<br>` element.

1. https://searchfox.org/mozilla-central/rev/7b5f4b93ca3e96f9fb9b5793b58080c1e44bd4f6/editor/libeditor/HTMLEditRules.cpp#7606,7631

Differential Revision: https://phabricator.services.mozilla.com/D161246
2022-11-07 02:33:35 +00:00
Daniel Holbert 707a9a407d Bug 1797148: Simplify checkVisibility API (on nsISelectionController and nsIFrame) into a single nsTextFrame::HasVisibleText method. r=masayuki
Before this patch, we had two `checkVisibilty` methods on the
nsISelectionController interface, backed by several layers of implementation,
ultimately backed by a single function on nsTextFrame (which didn't actually
do anything meaningful with any of the parameters).

As it turns out, this API only had one caller, in HTMLEditUtils.cpp.

This patch converts that caller to directly query nsTextFrame (if the given
node's primary frame is indeed a nsTextFrame).  The direct function-call is
renamed to HasVisibleText(), to be a bit clearer about it being text-specific
and also to avoid confusion with the (unrelated) recently-specified HTML
checkVisibility() API.

With these changes, we can remove the API from the nsISelectionController
interface and its implementations.

This patch also updates the HTMLEditUtils::IsInVisibleTextFrames documentation
(with s/all/any/) to reflect the reality of what the nsTextFrame impl actually
does.

Differential Revision: https://phabricator.services.mozilla.com/D160563
2022-10-28 17:56:04 +00:00
Masayuki Nakano 173881e7e3 Bug 1797026 - Make `DeleteRangeTransaction::DoTransaction` extend the range to delete to contain parent nodes which will be empty r=m_kato
If the range ends at a node, its parents are never iterated by
`ContentSubtreeIterator` because it collects the nodes end in the given range.
However, if the range starts from a new empty parent node, e.g.,

```
abc[<b>def]</b>
```

Then, the `<b>` element should be deleted rather than alive as `abc<b></b>`.
Therefore, unless the end container does not match with start container, it
should extend the range to contain empty parents while the range ends at end
of a node.

Differential Revision: https://phabricator.services.mozilla.com/D160165
2022-10-28 11:07:37 +00:00
Noemi Erli b6f45020ab Backed out changeset 95939c987c9f (bug 1797026) for causing failures in input-events-get-target-ranges-forwarddelete.tentative.html CLOSED TREE 2022-10-28 07:52:49 +03:00
Masayuki Nakano 30033d5abb Bug 1797026 - Make `DeleteRangeTransaction::DoTransaction` extend the range to delete to contain parent nodes which will be empty r=m_kato
If the range ends at a node, its parents are never iterated by
`ContentSubtreeIterator` because it collects the nodes end in the given range.
However, if the range starts from a new empty parent node, e.g.,

```
abc[<b>def]</b>
```

Then, the `<b>` element should be deleted rather than alive as `abc<b></b>`.
Therefore, unless the end container does not match with start container, it
should extend the range to contain empty parents while the range ends at end
of a node.

Differential Revision: https://phabricator.services.mozilla.com/D160165
2022-10-28 00:50:21 +00:00
Masayuki Nakano ab06299299 Bug 1768315 - Get rid of `nsIEditor.transactionManager` due to unused r=m_kato
`nsITransactionManager` provides too low level things and editor may want to
stop using it in the future if Undo Manager spec is implemented in another
browser.  Therefore, I'd like to stop exposing `nsITransactionManager` instance
for editor.

Note that `mozilla::TransactionManager` is still created and used by the
UI of mailer of SeaMonkey (i.e., under `mailnews`), once we move
`nsITransactionManager` instance moved into SeaMonkey, we can make
`mozilla::TransactionManager` stop inheriting `nsITransactionManager`.

Differential Revision: https://phabricator.services.mozilla.com/D160008
2022-10-27 22:50:07 +00:00
Jan-Niklas Jaeschke 67840fe563 Bug 1783641: Deleting a selected word deletes surrounding whitespace on MacOS. r=masayuki
Native behaviour on MacOS dictates one whitespace being removed after double-clicking a word and pressing delete.
This behaviour is achieved by saving the information that the selection is created by doubleclick to the `nsFrameSelection`
and using it in the `DeleteRangeTransaction`, where the range is extended by one whitespace character before or after the range.

Differential Revision: https://phabricator.services.mozilla.com/D159613
2022-10-25 07:00:26 +00:00
Masayuki Nakano c9466187eb Bug 1699256 - Make `AutoEmptyBlockAncestorDeleter::GetNewCaretPosition` always return a valid point if succeeded r=m_kato
The testcase is tricky.  It creates 2 `Selection` ranges, one is collapsed at
end of the `<html>`, the other is collapsed in the new `<h3>` element.  The
first one is ignored by delete handler since Gecko does not allow to edit
outside `<body>` for now.

Then, deleting non-collapsed selection ranges tries to delete empty parent
blocks at the remaining collapsed selection range in the `<h3>`.  At this time,
it works with `nsIEditor::eNone`.  Then, its `GetNewCaretPosition` does not
return a valid point.  Then, the `Run` does not remove the `Selection` range
outside the `<body>`.

Therefore, `HTMLEditor::DeleteSelectionAndPrepareToCreateNode()` will see
2 ranges, then, hit the assertion.

Although there are some other cases which meet 2 or more `Selection` ranges
after deletion in `DeleteSelectionAndPrepareToCreateNode`, but for now, we
should make `AutoEmptyBlockAncestorDeleter::Run` collapse `Selection` when
it deletes empty ancestors.

Differential Revision: https://phabricator.services.mozilla.com/D159581
2022-10-21 05:59:34 +00:00
Tom Schuster 4918f62d16 Bug 1778565 - Editor: Handle nsIFile transferable as blob. r=nika,masayuki
Differential Revision: https://phabricator.services.mozilla.com/D155753
2022-10-20 11:11:59 +00:00
Masayuki Nakano fb0bf2eac0 Bug 1777060 - Make the test initialize selection after waiting some ticks r=m_kato
The failure on Android is caused by async initialization of `<textarea>` runs
after initializing selection in it.  Therefore, `ArrowUp` is synthesized when
all text is selected and collapses it to start.

Then, I see another failure on Linux and macOS in `contenteditable` case at
running TV and TV-nonfis.  It seems that it's caused by remaining `Selection`
of the preceding test (`vertical-rl` case) does something wrong.  Once
removing all ranges at `blur`ring, the failures in `vertical-lr` case has
gone.

Differential Revision: https://phabricator.services.mozilla.com/D159566
2022-10-19 23:18:48 +00:00
Masayuki Nakano a2e038d71f Bug 1795061 - Stop exposing `JoinSplitNodeDirection.h` r=m_kato
Including it in `HTMLEditor.h` causes creating static constructors for
the modules which include `HTMLEditor.h`.  And the public methods are used
only in the `libeditor`.  Therefore, we can make `HTMLEditor.h` stop including
it and stop exposing `JoinSplitNodeDirection.h`.

Differential Revision: https://phabricator.services.mozilla.com/D159363
2022-10-19 06:40:30 +00:00
Masayuki Nakano 4a64b9ab3f Bug 1795179 - Make some elements non-splittable r=m_kato
One of the reason of bug 1793873 is, `HTMLEditUtils::IsSplittableNode` returns
`false` for `<textarea>`.  Then, `insertParagraph` etc command with `Selection`
collapsed in `<textarea>` causes splitting the `<textarea>` and it's not split
at same parent.

Then, I found that we need to take care `<button>` specially.  It creates a
block formatting context, and it's a form control so that it should never be
split.  Therefore, `HTMLEditor::GetAncestorElement` requires to take care of
`<button>` element with additional scan option for minimizing the risk.

Differential Revision: https://phabricator.services.mozilla.com/D159229
2022-10-18 22:58:10 +00:00
Masayuki Nakano 6e573a8e54 Bug 1794804 - Make `HTMLEditor::MergeFirstLineOfRightBlockElementIntoLeftBlockElement` stop referring ok type of `Result` when it's error r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D159234
2022-10-18 22:42:54 +00:00
Masayuki Nakano 5f62438afd Bug 1794800 - Make `HTMLEditor::MoveOneHardLineContentsWithTransaction` notify last move node result of ignoring caret point suggestion if new move node fails r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D159233
2022-10-18 22:37:01 +00:00
Masayuki Nakano 2da57e45a2 Bug 1794800 - Make `HTMLEditor::MoveChildrenWithTransaction` notify last move node result of ignoring caret point suggestion if new move node fails r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D159232
2022-10-18 22:37:01 +00:00
Sandor Molnar 8cd82824c1 Backed out 2 changesets (bug 1778565) for causing mochitest plain failures in editor/libeditor/tests/test_bug490879.html CLOSED TREE
Backed out changeset 5f6350cfab61 (bug 1778565)
Backed out changeset 420e02d37505 (bug 1778565)
2022-10-18 22:18:00 +03:00
Tom Schuster 50f59ff179 Bug 1778565 - Editor: Handle nsIFile transferable as blob. r=nika,masayuki
Differential Revision: https://phabricator.services.mozilla.com/D155753
2022-10-18 17:35:33 +00:00
Masayuki Nakano 7b5c93295e Bug 1793865 - Make `HTMLEditor::HandleOutdentAtSelectionInternal` not return caret point suggestion r=m_kato
It restores `Selection` with `AutoSelectionRestorer` instance created first.
Therefore it does not want the callers (currently, only
`HTMLEditor::HandleOutdentAtSelection` only) change `Selection` after doing it
without special reasons.  Therefore, it shouldn't return last caret point
suggestion which is not a good point to put caret actually.  Then, callers
do not need to handle it as they've never done.

Differential Revision: https://phabricator.services.mozilla.com/D159231
2022-10-18 06:48:45 +00:00
Andrew McCreight b1fa3e3b36 Bug 1794811, part 1 - Include nsISupports.h instead of nsISupportsBase.h. r=necko-reviewers,nika,valentin
nsISupports.h includes nsISupportsBase.h, so it should be equivalent.

In the next patch, I'm changing things so that nsISupports is defined in
nsISupports.h instead of nsISupportsBase.h, and deleting the latter, so
this change will be needed anyways. I'm guessing people were using IWYU
or something like that.

Differential Revision: https://phabricator.services.mozilla.com/D159169
2022-10-17 16:09:22 +00:00
Masayuki Nakano 555eef31f3 Bug 1793873 - Make `HTMLEditor::DoSplitNode` stop assuming that joining nodes are in same parent r=m_kato
Between splitting a node and undoing it, web apps can move split nodes anywhere.
Therefore, it shouldn't assume they are always in same parent node, and
`RangeUpdater::SelAdjJoinNodes` needs to handle it correctly.

Unfortunately, `RangeUpdater::SelAdjJoinNodes` cannot handle nested cases
correctly, e.g., right node was in `aRemovedContent` or right node was in
the container of `aStartOfRightContent.GetContainer()`.  However, it's not
a new regression, and such complicated situation breaks undoing anyway.
Therefore, I think that we don't need to care about it for now.

Differential Revision: https://phabricator.services.mozilla.com/D159230
2022-10-14 02:49:13 +00:00
Jan-Niklas Jaeschke 311f68ad19 Bug 1793485: Fixed memory issue in `NodeWillBeDestroyed()` for `MultiMutationObserver` classes. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D158671
2022-10-13 14:26:07 +00:00
Cristian Tuns 67ff6520de Backed out changeset 928edafe970f (bug 1793485) for causing leaks CLOSED TREE 2022-10-12 17:09:32 -04:00
Jan-Niklas Jaeschke e71ca074c5 Bug 1793485: Fixed memory issue in `NodeWillBeDestroyed()` for `MultiMutationObserver` classes. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D158671
2022-10-12 19:36:46 +00:00
Masayuki Nakano ff05850ef8 Bug 1793694 - part 7: Stop exposting `CSSEditUtils.h` and `ChangeStyleTransaction.h` r=m_kato
Depends on D158636

Differential Revision: https://phabricator.services.mozilla.com/D158637
2022-10-12 02:44:20 +00:00
Masayuki Nakano d54f646831 Bug 1793694 - part 6: Stop exposting `EditorUtils.h` r=m_kato
Depends on D158635

Differential Revision: https://phabricator.services.mozilla.com/D158636
2022-10-12 02:44:20 +00:00
Masayuki Nakano 994759243f Bug 1793694 - part 5: Move `EditorUtils::MaskString` to `TextEditor` r=m_kato
It's the only method which is used outside of the editor module.  Therefore,
we can stop exposing `EditorUtils.h` later.

Depends on D158634

Differential Revision: https://phabricator.services.mozilla.com/D158635
2022-10-12 02:44:19 +00:00
Masayuki Nakano e2b2e03fb4 Bug 1793694 - part 4: Stop exposing `HTMLEditUtils.h` r=m_kato
It's currently referred from outside only by `TextServicesDocument.cpp`.
It's not under `libeditor` but in the editor module.  Therefore, let's allow
it to refer the header files under `libeditor` directly.  Then, we can stop
exposing `HTMLEditUtils.h`.

Depends on D158633

Differential Revision: https://phabricator.services.mozilla.com/D158634
2022-10-12 02:44:19 +00:00
Masayuki Nakano d2b4935d19 Bug 1793694 - part 3: Move definitions of `JoinNodesDirection` and `SplitNodeDirection` into a new exposed header file r=m_kato
They are used in public inline methods of `HTMLEditor`.  Therefore, they should
be defined in an exposed header file without other internal use things for the
editor module.  Then, we can stop exposing `HTMLEditHelpers.h`.

Depends on D158632

Differential Revision: https://phabricator.services.mozilla.com/D158633
2022-10-12 02:44:18 +00:00
Masayuki Nakano 020393179b Bug 1793694 - part 2: Move some protected inline method definitions of `HTMLEditor` to non-exposed header r=m_kato
Depends on D158631

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

Differential Revision: https://phabricator.services.mozilla.com/D158631
2022-10-12 02:44:17 +00:00
Chengyu Sun d4e767473d Bug 1790224 - Convert browser/actors/ClickHandler* JSM modules to ESMs. r=mconley
Differential Revision: https://phabricator.services.mozilla.com/D158853
2022-10-11 14:12:33 +00:00
Masayuki Nakano 52fa7d578c Bug 1793381 - part 3: Drop `DeleteSelectedContent` argument from `HTMLEditor::InsertFromTransferable` r=m_kato
It's always called with `DeleteSelectedContent::Yes`.  Therefore, the argument
is not required.  Then, its name can be `InsertFromTransferableAtSelection`.

Differential Revision: https://phabricator.services.mozilla.com/D158483
2022-10-09 01:27:35 +00:00
Masayuki Nakano df28abd410 Bug 1793381 - part 2: Make `HTMLEditor::DoInsertHTMLWithContext` as a sub action handler r=m_kato
It just creates `HTMLWithContextInserter` and calls its `Run()`.  Then, `Run()`
works as a sub action handler.  Therefore, we can make `DoInsertHTMLWithContext`
(which sounds like a helper class of a handler method) a sub action handler.

Then, it can handle the optional insertion point in it and
`HTMLWithContextInserter::Run` does not need to handle it.

Differential Revision: https://phabricator.services.mozilla.com/D158482
2022-10-09 01:27:35 +00:00
Masayuki Nakano f9fd02e705 Bug 1793381 - part 1: Make `HTMLEditor::InsertObject` and related methods use `enum class` instead of `bool` r=m_kato
They use `bool` arguments a lot.  Therefore, some call-sites are hard to read.
They should be replaced with `enum class`es.  Note that this patch does not
make the raw value of new `enum class`es to `bool` unless they are used in the
heap.

Differential Revision: https://phabricator.services.mozilla.com/D158481
2022-10-09 01:27:34 +00:00
Masayuki Nakano 6f006e854a Bug 1792759 - part 4: Make all tests in mozilla-central stop using `nsIEditor.transactionManager` r=m_kato
Now, `nsIEditor` has all alternatives of remaining `nsITransactionManager`
usage in mozilla-central.

Differential Revision: https://phabricator.services.mozilla.com/D158339
2022-10-09 01:13:50 +00:00
Masayuki Nakano 221e6fe540 Bug 1792759 - part 3: Add `nsIEditor.undoAll` r=m_kato,Standard8
`nsIEditor.undo` and `nsIEditor.redo` are called with `1` except by the search
bar, and search bar wants to undo everything to reset the value.  Therefore,
search bar needs an API to undo all, and the others do not need the number of
undoing/redoing transactions.  Therefore, this patch adds `nsIEditor.undoAll`
for search bar, and remove the arguments from `nsIEditor.undo` and
`nsIEditor.redo`.

Differential Revision: https://phabricator.services.mozilla.com/D158338
2022-10-09 01:13:50 +00:00
Masayuki Nakano 85a314b8fd Bug 1792759 - part 2: Redesign `nsIEditor.canUndo` and `nsIEditor.canRedo` r=m_kato,NeilDeakin
They are methods to take 2 out params, and it's not convenient for light use.
I think that there should be 3 attributes, `undoRedoEnabled`, `canUndo` and
`canRedo`.  Then, the findbar does not need to check number of transactions
with `nsITransactionManager`.

Differential Revision: https://phabricator.services.mozilla.com/D158337
2022-10-09 01:13:49 +00:00
Masayuki Nakano 4ba9b4dd1c Bug 1792759 - part 1: Add `nsIEditor.clearUndoRedo()` to get rid of `nsIEditor.transactionManager` r=m_kato,NeilDeakin,Standard8
`nsIEditor.transactionManager` is used only for some simple purposes, however,
`nsIEditor` exposes the rich API.  That makes it harder to maintain internal
code around transactions.  Instead, `nsIEditor` exposes only simple and
necessary APIs.

This patch creates a new API to clear undo/redo history and make the users in
mozilla-central use it instead of using `nsITransactionManager.clear()`.

Differential Revision: https://phabricator.services.mozilla.com/D158336
2022-10-09 01:13:49 +00:00
Masayuki Nakano 4789a16aab Bug 1792654 - Make `CreateNodeResultBase`, `MoveNodeResult`, `SplitNodeResult` and `SplitRangeOffResult` handle caret point with a common base class r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158335
2022-10-04 21:36:57 +00:00
Masayuki Nakano 86bd7e3f58 Bug 1792642 - Make `SplitNodeResult` treated as ok type of `Result` r=m_kato
Depends on D158333

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

Differential Revision: https://phabricator.services.mozilla.com/D158333
2022-10-03 23:17:02 +00:00
Masayuki Nakano e93bfe5b05 Bug 1792639 - Make `SplitRangeOffFromNodeResult` treated as ok type of `Result` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158332
2022-10-03 07:52:45 +00:00
Masayuki Nakano fa59d785e9 Bug 1792624 - Make `SplitRangeOffResult` treated as ok type of `Result` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158243
2022-10-03 01:19:59 +00:00
Masayuki Nakano b56174de6b Bug 1792502 - Correct the emulation in crashtests for bug 1789967 r=m_kato
I misunderstood the traditional behavior before bug 1789967, that is,
`HTMLEditor` collapsed `Selection` to end of the deepest last child container
element **or text node** of the `<body>`, rather than to end of **only** the
deepest last child container element. This misunderstanding caused the backout
of the first landing, but I didn't realize this mistake.

Therefore, this patch makes the crashtests which are touched in bug 1789967 and
the collapsed point is at a text node (or failed to consider the collapsed
point) collapse `Selection` to end of the deepest last text node of their
`<body>` elements.

Differential Revision: https://phabricator.services.mozilla.com/D158177
2022-10-02 00:03:36 +00:00
Masayuki Nakano b671926fa5 Bug 1792387 - part 10: Make `editor/libeditor/tests/test_inline_style_cache.html` be aware of both split node directions r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158108
2022-09-30 22:20:23 +00:00
Masayuki Nakano 405786efd0 Bug 1792387 - part 8: Make `HTMLEditor::InsertParagraphSeparatorAsSubAction` put caret into right paragraph r=m_kato
If splitting element is a list item element,
`HandleInsertParagraphInListItemElement` may just move it into a list element
if it's followed by the list element, or may create new paragraph element if
the list item element is empty and last list item element.

If splitting element is a heading element,
`HandleInsertParagraphInHeadingElement` may create new paragraph element if
splitting at end of the heading element and not followed by `<br>`.

Therefore, neither `SplitNodeResult` nor `CreateElementResult` is proper for
their result type, and the caller `InsertParagraphSeparatorAsSubAction`, just
wants to know the right handle element which should contain caret and a caret
point suggestion.

For solving these issues, this gives an alias to `CreateElementResult`, makes
them return the right paragraph even if it's not newly created nor split
element, and replaces `blockElementToPutCaret` with the returned element.

Differential Revision: https://phabricator.services.mozilla.com/D158106
2022-09-30 22:20:22 +00:00
Masayuki Nakano 6b4bdd204e Bug 1792387 - part 7: Make `editor/libeditor/test_bug449243.html` be aware of both split node directions r=m_kato
The test compares the node name of the split element and its previous sibling
element, so it should switch the scanning direction with the pref to switch
split node direction.

Note that the behavior is different from the other browsers in some cases.
Therefore, we cannot port this to WPT.

Differential Revision: https://phabricator.services.mozilla.com/D158105
2022-09-30 22:20:22 +00:00
Masayuki Nakano 5e5b106cf0 Bug 1792387 - part 6: Make `HTMLEditor::InsertElementWithSplittingAncestorsWithTransaction` check edge case with next node of the split point r=m_kato
The check assumes that the container of `aPointToInsert` is always right node.
However, its child is moved to new node if we switch the direction, so we should
make it check the edge case with `SplitNodeResult::GetNextContent()`.

Differential Revision: https://phabricator.services.mozilla.com/D158104
2022-09-30 22:20:22 +00:00
Masayuki Nakano 5cf34cef27 Bug 1792387 - part 5: Make `HTMLEditor::SplitRangeOffFromBlock` and its caller refer `SplitNodeResult` at their post-processing r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158103
2022-09-30 22:20:21 +00:00
Masayuki Nakano 9301bc763b Bug 1792387 - part 4: Make `JoinNodesTransaction` and `SplitNodeTransaction` support both join/split node directions r=m_kato
The reason why the changes of `SplitNodeTransaction` is smaller than
`JoinNodesTransaction` is, `HTMLEditor::DoSplitNode` does almost all things
instead.

Differential Revision: https://phabricator.services.mozilla.com/D158102
2022-09-30 22:20:21 +00:00
Masayuki Nakano 6ba25b471e Bug 1792387 - part 3-2: Make `HTMLEditor::DoSplitNode()` handle both split node directions r=m_kato
This does not change the existing path's behavior.

Differential Revision: https://phabricator.services.mozilla.com/D158101
2022-09-30 22:20:20 +00:00
Masayuki Nakano 8fd837d307 Bug 1792387 - part 3-1: Make `HTMLEditor::DoSplitNode()` adjust selection for both split node directions r=m_kato
This patch adds new path to adjust selection for the new split node direction.
So this does not change any behavior of the existing path.

Differential Revision: https://phabricator.services.mozilla.com/D158100
2022-09-30 22:20:20 +00:00
Masayuki Nakano 68073f0bbf Bug 1792387 - part 2-2: Make `HTMLEditor::DoJoinNodes()` handle both join nodes directions r=m_kato
This changes the existing path's behavior a bit.  However, it should not affect
to web apps in the wild because it must be really rare case that web apps
inserting new nodes into the removing node while moving its children.

Differential Revision: https://phabricator.services.mozilla.com/D158099
2022-09-30 22:20:20 +00:00
Masayuki Nakano 53757982b2 Bug 1792387 - part 2-1: Make `HTMLEditor::DoJoinNodes()` adjust selection for both join nodes directions r=m_kato
This patch add new path to adjust selection for the new join nodes direction.
So this does not change any behavior of the existing path.

Differential Revision: https://phabricator.services.mozilla.com/D158098
2022-09-30 22:20:19 +00:00
Masayuki Nakano 656bb3ee88 Bug 1792387 - part 1: Make `HTMLEditor` join/split node direction switchable by a pref r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D158097
2022-09-30 22:20:19 +00:00
Andrew McCreight 2da84b8ac4 Bug 1792574, part 3 - Don't include nsMemory where it isn't needed. r=xpcom-reviewers,necko-reviewers,valentin,nika
There are only 3 places where nsMemory.h is still needed (image/RasterImage.cpp,
gfx/thebes/gfxFT2FontList.cpp, and nsMemory.cpp). Remove the rest.

Differential Revision: https://phabricator.services.mozilla.com/D158213
2022-09-28 15:17:46 +00:00
Masayuki Nakano bd1059c951 Bug 1791501 - Use `EditActionResult` as ok type of `mozilla::Result` r=m_kato
Any callers do not refer "ignored", "handled" and "cancel" state without
checking whether the method returns error or not.  Therefore, error state
can be (and should be) managed by `mozilla::Result`'s error state.

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

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

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

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

Differential Revision: https://phabricator.services.mozilla.com/D157574
2022-09-26 00:56:46 +00:00
Masayuki Nakano c82ba52224 Bug 1782911 - part 10: Make `HTMLEditor::MoveOneHardLineContentsWithTransaction` delete trailing linefeed if it becomes not preformatted r=m_kato
This is a hack for compatibility with the other browsers.  When we move first
line of `<pre>` to left paragraph whose `white-space` style does not make it
preformatted, they drop the last linefeed because of unnecessary.

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

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

Differential Revision: https://phabricator.services.mozilla.com/D157418
2022-09-25 12:49:46 +00:00
Masayuki Nakano 351819c1cc Bug 1782911 - part 8: Make `HTMLEditor::MoveOneHardLineContentsWithTransaction` clean up line break before right block if its first line is moved there r=m_kato
When the first line of right block element is moved before the block element,
unnecessary line break may be moved to immediately before the right block
element.  In the case, it needs to clean it up instead of trying to find
unnecessary line break at end of the left block which is a container of the
right block element.

Differential Revision: https://phabricator.services.mozilla.com/D157417
2022-09-25 12:49:46 +00:00
Masayuki Nakano 4854c49121 Bug 1782911 - part 7: Make `HTMLEditor::MoveOneHardLineContentsWithTransaction` stop moving empty inline nodes r=m_kato
Empty inline nodes except non-container nodes are not required in the
destination paragraph.  Therefore, it should just remove the node from the
DOM tree.

Differential Revision: https://phabricator.services.mozilla.com/D157416
2022-09-25 12:49:45 +00:00
Masayuki Nakano 94fbe6ab47 Bug 1782911 - part 6: Make `HTMLEditor::MoveOneHardLineContentsWithTransaction` delete new empty inline parents if deleting unnecessary line break creates them r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D157415
2022-09-25 12:49:45 +00:00
Masayuki Nakano a7c1b47e8b Bug 1782911 - part 5: Make `HTMLEditor::AutoBlockElementsJoiner` scan previous (or next) paragraph with ignoring invisible data nodes r=m_kato
We don't ignore invisible data node at joining 2 paragraphs and this is
a different behavior from the other browsers.  When looking for a content
from current block boundary, `AutoBlockElementsJoiner` should keep scanning
visible things with ignoring invisible data nodes.  Then, it should delete
all invisible things after joining the paragraphs.

Differential Revision: https://phabricator.services.mozilla.com/D157414
2022-09-25 12:49:44 +00:00
Masayuki Nakano 7e788541b1 Bug 1782911 - part 4: Make `HTMLEditor::MoveNodeOrChildrenWithTransaction` preserve `white-space` style at moving different style node r=m_kato
Chrome and Safari preserve `white-space` with `style` attribute to keep
collapsible or preserved white-spaces as-is.  If an HTML element is moved,
`style` attribute should be set to it.  Otherwise, create `<span>` element
whose `style` attribute has the declaration for `white-space` and move
content into it.

Differential Revision: https://phabricator.services.mozilla.com/D157413
2022-09-25 12:49:44 +00:00
Masayuki Nakano bb2a35d9d7 Bug 1782911 - part 3: Make `HTMLEditor` always move first line of right block only when the blocks have different `white-space` style r=m_kato
Gecko just joins 2 blocks when editable block parents are same element, e.g.,
both are `<div>`.  However, Chrome and Safari moves only first line of the
right block into the left block, and Gecko does it when both blocks are
different elements.

Ideally, we should take same behavior as Chrome and Safari because it's
reasonable for both compatibility with the other browsers and consistency
when both blocks are different but has same style, then we don't need to
maintain different behavior paths.

However, doing it for all elements are too risky because right block will be
merged into left block if right block has no line break.  On the other hand,
without doing it, preserving `white-space` is really hard because we need to
maintain the both paths.

Therefore, I'd like to change the behavior only when both blocks have different
`white-space` styles.  Usually, web apps do not change `white-space` for each
block, so I think that this is safer than doing this in all elements,
additionally, we can revert the behavior easy since this patch is really small.

Differential Revision: https://phabricator.services.mozilla.com/D157412
2022-09-25 12:49:43 +00:00
Masayuki Nakano d1b5e4a973 Bug 1782911 - part 2: Clean up unnecessary line break at block boundary while moving first line of right paragraph to left paragraph r=m_kato
This fixes bug 503838 partially.  The new utility method scans unnecessary
`<br>` with strict check as far as possible.  Then, we can delete the node or
the preformatted line break at end of the last text node.

Differential Revision: https://phabricator.services.mozilla.com/D157411
2022-09-25 12:49:43 +00:00
Masayuki Nakano 222a330cb6 Bug 1782911 - part 1: Port most tests of test_bug772796.html to WPT r=m_kato
This patch ports most part of `editor/libeditor/tests/test_bug772796.html` to
WPT because this kind of behaviors are not tested by `editing/run/delete.html`
nor `editing/run/forwarddelete.html`. (Not ported tests are invalid HTML
structure cases and list item cases, the reason why not doing this for the
latter is, it needs a lot of cases and not important for most web apps.)

The most expectations are based on Chrome and Safari (they both behave almost
same), but they fail a lot in `join-pre-and-other-block.html` and
`white-space: pre-line` cases in the other tests.

Even though this ports a lot of cases, for making easier to compare the
behavior change in the following patches, we should keep the tests.

Differential Revision: https://phabricator.services.mozilla.com/D157410
2022-09-25 12:49:42 +00:00
Masayuki Nakano c2cfa6c82a Bug 1791136 - Make `HTMLEditor::FormatBlockContainerWithTransaction` return error state correctly r=m_kato
The line never runs in automated tests, and
`RemoveBlockContainerElementsWithTransaction` does not check whether the DOM
tree gets as expected or not.  Therefore, I have no idea how to test this.

Differential Revision: https://phabricator.services.mozilla.com/D157573
2022-09-22 22:14:35 +00:00
Andreea Pavel c538244252 Bug 1777060 - disable test_caret_move_in_vertical_content.html on android debug r=intermittent-reviewers,MasterWayZ DONTBUILD
Differential Revision: https://phabricator.services.mozilla.com/D157917
2022-09-22 11:38:35 +00:00
Masayuki Nakano fc89971ea6 Bug 1789967 - part 4: Make `HTMLEditor::SelectAllInternal` work without selection range r=m_kato
It may be called even when there is no selection range and focused element.
However, it assumes that there is a selection range, and an editable element
has focus.  Therefore, now, if there is an editing host and user tries to
do "Select All" without clicking somewhere before doing it, "Select All" does
nothing.

Differential Revision: https://phabricator.services.mozilla.com/D157409
2022-09-22 06:27:38 +00:00
Masayuki Nakano a353ab7e90 Bug 1789967 - part 3: Make `HTMLEditor::CollapseSelectionToEndOfLastLeafNodeOfDocument` and `HTMLEditor::InitEditorContentAndSelection` do nothing if the document is partially editable r=m_kato
They and their callees work with the result of `GetRoot()` which is the document
element or the body element.  If the body is not editable, `Selection` should
not be updated in non-editable region nor `<br>` elements should not be
inserted in both non-focused editable elements and non-editable elements.
Therefore, they should run only when the document element or the `<body>`
element is editable.

To keep testing crashtests as reported, this patch makes tests which have
`contenteditable` except `<html>` and `<body>` initialize `Selection` as
what we've done.  And clean up the tests for helping to port them to WPT
in the future (bug 1725850).

Differential Revision: https://phabricator.services.mozilla.com/D157408
2022-09-22 06:27:37 +00:00
Masayuki Nakano 2f0ed118ae Bug 1789967 - part 2: Make `TextEditor` and `HTMLEditor` implement `EditorBase::CollapseSelectionToEndOfLastLeafNode` by themselves r=m_kato
It does different thing for `TextEditor` and `HTMLEditor`, and used almost
internally.  Therefore, it should be implemented in the sub classes and
we should name them better.

Differential Revision: https://phabricator.services.mozilla.com/D157407
2022-09-22 06:17:36 +00:00
Masayuki Nakano f1dd8bf3b5 Bug 1789967 - part 1: Make `TextEditor` and `HTMLEditor` implement `EditorBase::InitEditorContentAndSelection` by themselves r=m_kato
The method is enough simple, and uses bad cast from point of view of OOP.
Therefore, this patch make the sub classes implement the method only for each.

Differential Revision: https://phabricator.services.mozilla.com/D157406
2022-09-22 06:06:54 +00:00
Jan-Niklas Jaeschke 4265f72859 Bug 1777925: Replaced MutationObserver array container type with linked list. r=smaug
Deletion of mutation observers from a list resulted in O(n^2) behavior and could lead to massive freezes.
This is resolved by using a LinkedList instead, reducing complexity to O(n).

A safely iterable doubly linked list was implemented based on `mozilla::DoublyLinkedList`,
allowing to insert and remove elements while iterating the list.

Due to the nature of `mozilla::DoublyLinkedList`, every Mutation Observer now inherits `mozilla::DoublyLinkedListElement<T>`.
This implies that a Mutation Observer can only be part of one DoublyLinkedList.
This conflicts with some Mutation Observers, which are being added to multiple `nsINode`s.
To continue supporting this, new MutationObserver base classes `nsMultiMutationObserver` and `nsStubMultiMutationObserver` are introduced,
which create `MutationObserverWrapper` objects each time they are added to a `nsINode`.
The wrapper objects forward every call to the actual observer.

Differential Revision: https://phabricator.services.mozilla.com/D157031
2022-09-21 11:31:44 +00:00
Iulian Moraru 6af4d42518 Backed out changeset 555d2ca16477 (bug 1789967) as per dev request. CLOSED TREE 2022-09-21 06:48:30 +03:00
Masayuki Nakano f3ce7840c7 Bug 1789967 - part 1: Make `TextEditor` and `HTMLEditor` implement `EditorBase::InitEditorContentAndSelection` by themselves r=m_kato CLOSED TREE
The method is enough simple, and uses bad cast from point of view of OOP.
Therefore, this patch make the sub classes implement the method only for each.

Differential Revision: https://phabricator.services.mozilla.com/D157406
2022-09-21 00:20:26 +00:00
Iulian Moraru 52da19beca Backed out 2 changesets (bug 1789967) for causing wd failures on content_editable.py. CLOSED TREE
Backed out changeset f2f431ee78a3 (bug 1789967)
Backed out changeset edac234f1eba (bug 1789967)
2022-09-21 04:40:46 +03:00
Masayuki Nakano 7f5b2e7242 Bug 1789967 - part 2: Make `TextEditor` and `HTMLEditor` implement `EditorBase::CollapseSelectionToEndOfLastLeafNode` by themselves r=m_kato
It does different thing for `TextEditor` and `HTMLEditor`, and used almost
internally.  Therefore, it should be implemented in the sub classes and
we should name them better.

Differential Revision: https://phabricator.services.mozilla.com/D157407
2022-09-21 00:38:23 +00:00
Masayuki Nakano 7f5a748878 Bug 1789967 - part 1: Make `TextEditor` and `HTMLEditor` implement `EditorBase::InitEditorContentAndSelection` by themselves r=m_kato
The method is enough simple, and uses bad cast from point of view of OOP.
Therefore, this patch make the sub classes implement the method only for each.

Differential Revision: https://phabricator.services.mozilla.com/D157406
2022-09-21 00:20:26 +00:00
Masayuki Nakano 5a7f7ccb64 Bug 1788840 - Make `HTMLEditor::HandleCSSIndentAroundRanges` stop referring moved `EditorDOMPoint` r=m_kato
Unfortunately, the result is really different from the other browsers.
E.g., when `execCommand("indent")` at `<div>abc<br>{}<br></div>`, Gecko inserts
a `<div>` and set its `margin-left`.  However, Chrome splits parent `<div>`
element and wrap the `<div>` which contains the caret in new `<blockquote>`.
Therefore, this does not contain new WPT.

Depends on D157404

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

Differential Revision: https://phabricator.services.mozilla.com/D157276
2022-09-14 10:27:39 +00:00
Masayuki Nakano b6c7be1c68 Bug 1789344 - Make `SelectionState::DidMoveNode` track DOM points having pointed the moved content correctly r=m_kato
When selection is `abc<b>[def</b>]ghi`, `insertParagraph` command will delete
the `<b>` element first, then, `Selection` becomes `abc{}ghi`.  Then,
`HTMLEditor::InsertParagraphSeparatorAsSubAction` wraps all of the line in
the default paragraph, `<div>`, with
`HTMLEditor::FormatBlockContainerWithTransaction` (although this is incompatible
behavior with the other browsers).  At this time, new `<div>` is inserted before
the first text node and then, move the text nodes into the new `<div>`.

However, `RangeUpdater::DidMoveNode` just slides the offsets if containers of
registered DOM points are the ex-parent of the moving nodes.  Therefore, the
tracked selection range in `HTMLEditor::FormatBlockContainerWithTransaction`
become `<div></div>abc{}def`, then, `<div>abcdef</div>{}`, but the expected
behavior is of course, `<div>abc{}def</div>`, then, split the new `<div>`.

So the problem is, `DidMoveNode` assumes that DOM points won't point the moving
content node.  If the node is pointed, it should keep pointing in the new
parent.

Note that the expectations of new tests are based on Chrome, therefore, the
new known failures are incompatible with Chrome.

Differential Revision: https://phabricator.services.mozilla.com/D156798
2022-09-12 23:53:37 +00:00
Masayuki Nakano 2d65dbd85c Bug 1789345 - Make `editor/libeditor/test_bug1318312.html` easier to read r=m_kato
It's hard to know how some tests failed in test_bug1318312.html.  Therefore,
this patch makes the selection range comparison easier to read, and add
description to explain what was doing at the failure.

Differential Revision: https://phabricator.services.mozilla.com/D156526
2022-09-07 01:06:47 +00:00
Makoto Kato fa04356be7 Bug 1787680 - Part 2. Don't create CSSEditUtils instance. r=masayuki
We can change all methods in `CSSEditUtils` to static method if we add
`HTMLEditor` parameter.

Differential Revision: https://phabricator.services.mozilla.com/D155976
2022-09-01 04:33:36 +00:00
Makoto Kato 4d903283b4 Bug 1787680 - Part 1. Move mIsCSSPrefChecked to HTMLEditor. r=masayuki
`CSSEditUtils::IsCSSPrefChecked` is used in HTMLEditor only, so we can move
`mIsCSSPrefChecked` to HTMLEditor.

Differential Revision: https://phabricator.services.mozilla.com/D155975
2022-09-01 04:33:36 +00:00
Mark Banner 4f95e6b415 Bug 1786197 - Turn on ESLint rule for prefer-boolean-length-check for editor. r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D155169
2022-08-26 13:39:36 +00:00
Masayuki Nakano 64fe7ed79d Bug 1784192 - part 10: Make `PendingStyles::GetTypeInState()` return an `enum class` instead of taking 2 bool out parameters r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D155319
2022-08-26 03:31:26 +00:00
Masayuki Nakano 8bbdf5e967 Bug 1784192 - part 9: Rename `TypeInState` to `PendingStyles` r=m_kato
Additionally,
* `PropItem` -> `PendingStyle`
* `StyleCache` -> `PendingStyleCache`
* `AutoStyleCacheArray` -> `AutoPendingStyleCacheArray`

And finally, `PendingStyle` (formally `PropItem`) is changed to `class` and
its members are encapsuled.

Differential Revision: https://phabricator.services.mozilla.com/D155318
2022-08-26 03:31:26 +00:00
Masayuki Nakano ef559e105f Bug 1784192 - part 8: Make scanner methods of `TypeInState` return `Maybe<size_t>` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D155317
2022-08-26 03:25:19 +00:00
Masayuki Nakano bfb3d1f8c6 Bug 1784192 - part 7: Rename `TypeInState::ClearProp` and related methods r=m_kato
For consistency with the previous patch, we should rename them too.  Then, we're
getting rid of unclear word "Prop" from the public methods.

Differential Revision: https://phabricator.services.mozilla.com/D155316
2022-08-26 03:25:19 +00:00
Masayuki Nakano 165e90f341 Bug 1784192 - part 6: Rename `TypeInState::SetProp` and `TypeInState::TakeSetProperty` r=m_kato
I usually retry to understand what they mean.  Therefore, I'd like to give new
names for them (and rename `TypeInState` class in a following patch).

Differential Revision: https://phabricator.services.mozilla.com/D155315
2022-08-26 03:20:14 +00:00
Masayuki Nakano a94d4ffd46 Bug 1784192 - part 5: Make `TypeInState` manage `PropItem` instances with `UniquePtr` r=m_kato
It's ugly to manage them as raw pointer especially when deleting the instances.
We should make it use `UniquePtr`.

Differential Revision: https://phabricator.services.mozilla.com/D155314
2022-08-26 03:20:14 +00:00
Masayuki Nakano cf8abe2061 Bug 1784192 - part 4: Change `PropItem::mSpecifiedStyle` to a constant r=m_kato
Only the value member needs to be updated when setting the prop multiple times.
Therefore, we cannot change all members to constants.

Differential Revision: https://phabricator.services.mozilla.com/D155313
2022-08-26 03:10:32 +00:00
Masayuki Nakano 100af2494d Bug 1784192 - part 3: Change other members of `PropItem` r=m_kato
According to the debug, its value can be CSS property value if in the CSS mode.
For making the value meaning easier to understand, this renames it to
mAttributeValueOrCSSValue.

Differential Revision: https://phabricator.services.mozilla.com/D155312
2022-08-26 03:10:31 +00:00
Masayuki Nakano 491bc57b81 Bug 1784192 - part 2: Change `PropItem::attr` to a strong pointer r=m_kato
It's currently no problem to manage it with a raw pointer because it may be
set to a dynamic atom only when `nsIHTMLEditor.insertLinkAroundSelection` is
called with unknown attribute, but comm-central uses it only with `href`
attribute.

I think that we should change the API just to take `href` value in the future,
but for now, it should be `RefPtr<nsAtom>`.

Differential Revision: https://phabricator.services.mozilla.com/D155311
2022-08-26 03:10:31 +00:00
Masayuki Nakano 66c9f821f0 Bug 1784192 - part 1: Change `PropItem::tag` to `nsStaticAtom*` r=m_kato
It's always a pointer to `nsStaticAtom` instance or `nullptr`.  Therefore,
it can be `nsStaticAtom*` and we can make its users treat `nsStaticAtom`
instead of `nsAtom`.

Additionally, this patch changes some pointer parameters to references if
they are never `nullptr`.

Differential Revision: https://phabricator.services.mozilla.com/D155310
2022-08-26 03:10:30 +00:00
Masayuki Nakano 76c16ceefc Bug 1785801 - Make `RangeUpdater::SelAdjJoinNodes` take the ex-offset of right node r=m_kato
In bug 1739524, I misunderstood the meaning of `aOffset` of `SelAdjJoinNodes`.

After joining 2 nodes, and a point points right node which will have ex-left
node content, the point needs to point ex-start of the right node to keep
next insertion point as-is.  Therefore, it's not useful with new join nodes
direction, it needs to know the ex-offset of the right node.

Differential Revision: https://phabricator.services.mozilla.com/D155438
2022-08-26 01:50:07 +00:00
Masayuki Nakano 94b817dc98 Bug 1785311 - Make `EditorBase::InsertTextIntoTextNodeWithTransaction` update insertion point after executing the transaction r=m_kato
Before the fix of bug 1758420, `TextComposition`'s text node and offset in it
are updated at creating `CompositionTransaction`.  However, it's now put off
until getting the mutations.  Therefore, it always unsets `pointToInsert` at
first time of the composition and fails to notify the listeners.

This patch makes it retrieve the result after calling `DoTransactionInternal`
and handle the post processing with the new point.

Differential Revision: https://phabricator.services.mozilla.com/D155052
2022-08-22 23:56:36 +00:00
Masayuki Nakano ff67736d1c Bug 1781994 - part 12: Make `HTMLEditor::SetCSSBackgroundColorWithTransaction` use similar approach as `SetInlinePropertiesAsSubAction` etc r=m_kato
It's a Gecko specific feature, and it sets background color of parent block
elements of selection ranges.  This does similar things to
`SetInlinePropertiesAsSubAction`, but still refers `Selection` directly and
uses `AutoSelectionRestorer`.  For consistency between similar methods, this
patch makes it use `AutoRangeArray`.

Depends on D154353

Differential Revision: https://phabricator.services.mozilla.com/D154354
2022-08-16 01:17:46 +00:00
Masayuki Nakano 0f6bbf324c Bug 1781994 - part 11: Clean up `HTMLEditor::RelativeFontChange` r=m_kato
It should use `AutoRangeArray` to stop using `AutoSelectionRestorer`.

Depends on D154352

Differential Revision: https://phabricator.services.mozilla.com/D154353
2022-08-16 01:17:45 +00:00
Masayuki Nakano d1c4c5d8e2 Bug 1781994 - part 10: Make `HTMLEditor::RelativeFontChangeOnNode` and `HTMLEditor::RelativeFontChangeHelper` stop touching `Selection` directly r=m_kato
They are renamed to `SetFontSizeWithBigOrSmallElement` and
`SetFontSizeOfFontElementChildren`.

Depends on D154351

Differential Revision: https://phabricator.services.mozilla.com/D154352
2022-08-16 01:09:31 +00:00
Masayuki Nakano 3327432a6a Bug 1781994 - part 9: Make `HTMLEditor::RelativeFontChangeOnNode` and `HTMLEditor::RelativeFontChangeHelper` use `FontSize` r=m_kato
`HTMLEditor::RelativeFontChange()` and its helpers are based on
`SetInlinePropertiesAsSubAction()` and its helpers.  Therefore, they may have
similar problem to switch join/split direction.  Therefore, this and the
following patches clean them up too.

Depends on D154350

Differential Revision: https://phabricator.services.mozilla.com/D154351
2022-08-16 01:01:06 +00:00
Masayuki Nakano 648f892bde Bug 1781994 - part 8: Make `HTMLEditor::SetInlinePropertyAsSubAction` handle multiple styles once r=m_kato
Depends on D154349

Differential Revision: https://phabricator.services.mozilla.com/D154350
2022-08-16 01:01:05 +00:00
Masayuki Nakano d6991deecb Bug 1781994 - part 7: Make `HTMLEditor::RemoveInlinePropertyAsSubAction` handle multiple styles once r=m_kato
I think that `HTMLEditor::SetInlinePropertyAsSubAction` and
`HTMLEditor::RemoveInlinePropertyAsSubAction` should not be called multiple
times in one edit action.  Therefore, I'd like to make them take multiple
styles once.  Then, we could collect all targets before touching the DOM tree
in the future.

Depends on D154348

Differential Revision: https://phabricator.services.mozilla.com/D154349
2022-08-16 00:55:06 +00:00
Masayuki Nakano da11385641 Bug 1781994 - part 6: Make `HTMLEditor::SetInlinePropertyInternal` use `AutoRangeArray` r=m_kato
Depends on D154347

Differential Revision: https://phabricator.services.mozilla.com/D154348
2022-08-16 00:38:30 +00:00
Masayuki Nakano 9d26dd1005 Bug 1781994 - part 5: Make `HTMLEditor::RemoveInlinePropertyAsSubAction` handle correct text node after splitting a text to any direction r=m_kato
This is a pre-fix for bug 1735608.  Currently, the loop assumes that collected
nodes are always right node, but it'll be changed, therefore, it creates
new array for the follow up loops handle expected nodes.

Depends on D154346

Differential Revision: https://phabricator.services.mozilla.com/D154347
2022-08-16 00:31:45 +00:00
Masayuki Nakano 181da530ee Bug 1781994 - part 4: Make `HTMLEditor::RemoveInlinePropertyInternal` use `AutoRangeArray` r=m_kato
I'd like to get rid of `AutoSelectionRangeArray` and `AutoRestoreSelection`,
and I'd like to make it stop touching `Selection` while it is removing style
of each content nodes in the range.  Therefore, this patch rewrites it with
`AutoRangeArray`.  Then, we can reduce the indent level of the nested `for`
loops.

Note that it creates `AutoEditSubActionNotifier`, so it's a sub-edit action
handler.  Therefore, this patch renames it.

Depends on D154345

Differential Revision: https://phabricator.services.mozilla.com/D154346
2022-08-16 00:26:05 +00:00
Masayuki Nakano 55250ca5e0 Bug 1781994 - part 3: Make `HTMLEditor::SetInlinePropertyOnTextNode` stop touching `Selection` directly r=m_kato
Depends on D154344

Differential Revision: https://phabricator.services.mozilla.com/D154345
2022-08-16 00:13:40 +00:00
Masayuki Nakano fcecac970b Bug 1781994 - part 2: Make `HTMLEditor::SplitAncestorStyledInlineElementsAtRangeEdges` stop touching `Selection` directly r=m_kato
Depends on D154343

Differential Revision: https://phabricator.services.mozilla.com/D154344
2022-08-16 00:08:07 +00:00
Masayuki Nakano 9f9cd9e318 Bug 1781994 - part 1: Make `HTMLEditor::SplitAncestorStyledInlineElementsAt` and `HTMLEditor::ClearStyleAt` stop touching `Selection` directly r=m_kato
I've already made a caller of `HTMLEditor::ClearStyleAt`,
`HTMLEditor::CreateStyleForInsertText`, in bug 1770877, so this fixes a bug of
the patch.

`HTMLEditor::ClearStyleAt` is still updates `Selection` only in some cases.
And one of the caller has not handle the `Selection` update.  Therefore, once
it completely stop touching `Selection`, `ComputeEditingHost` will fail and
the other paths update `Selection`, so it should do it too.  (Without the
change, `test_dragdrop.html` fails.)

Finally, we don't need `EditResult` anymore because we have
`Result<EditorDOMPoint, nsresult>`.

Differential Revision: https://phabricator.services.mozilla.com/D154343
2022-08-16 00:02:25 +00:00
Masayuki Nakano 64e700332c Bug 1783402 - part 3: Make result of unsafe getter methods of `EditorDOMPointBase` templated r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D153842
2022-08-09 01:43:24 +00:00
Masayuki Nakano fe4e77e324 Bug 1783402 - part 2: Make result of safe getter methods of `EditorDOMPointBase` templated r=m_kato
Similar to the previous patch, and for consistency between editor helper
classes, we should make result of getter methods of `EditorDOMPointBase` too.

Differential Revision: https://phabricator.services.mozilla.com/D153841
2022-08-09 01:43:24 +00:00
Masayuki Nakano 2c1d4805a6 Bug 1783402 - part 1: Make result of the getter methods of `SplitRangeOffFromNodeResult` templated r=m_kato
We'll need the version to return `dom::Text*` in coming patches for bug 1735608.
For avoiding the class to have a lot of getters, we should make result of the
getters templated.

Differential Revision: https://phabricator.services.mozilla.com/D153840
2022-08-09 01:43:23 +00:00
Masayuki Nakano d636f57443 Bug 1783393 - Get rid of the constructor of `SplitRangeOffFromNodeResult` which takes 2 `SplitNodeResult`s r=m_kato
`GetLeftContent()` etc is explained as:
> This may return nullptr if the method didn't split at start edge of the node.

On the other hand, `SplitNodeResult::GetPreviousContent()` and
`SplitNodeResult::GetNextContent()` returns previous or next content node
of split point when the split is not performed, but not in error.

Therefore, it should check `SplitNodeResult::DidSplit()` instead of
`SplitNodeResult::isOk()`.

However, there is another problem.  The constructor cannot specify the order
of the 2 splits.  Therefore, it's hard to maintain the constructor.
Fortunately, there is only one user, so we can make the user create the
result with another constructor.

Differential Revision: https://phabricator.services.mozilla.com/D153838
2022-08-08 09:06:24 +00:00
Masayuki Nakano 982149f4f1 Bug 1782874 - part 2: Make `HTMLEditor::RemoveEmptyNodesIn` remove end container of the range if empty r=m_kato
If splitting node creates new right node instead of new left node,
`TopLevelEditSubActionData::mChangedRange` ends by start of the right node.
However, `RemoveEmptyNodesIn` uses `PostContentIterator` which collects DOM
nodes whose "end tag" appear in the range.  Therefore, for cleaning up new
empty right nodes correctly, we need to extend the range to contain the node.

Additionally, it removes unexpected element which is editable but shouldn't be
removed from the DOM tree.  Therefore, this patch adds new check such as
`HTMLEditUtils::IsRemovalNode()`.

Finally, this patch adds a check whether the editor is a mail editor or not
at considering whether a node is a "mail-cite" because `contenteditable` in
web apps do not need special handling for such Gecko-specific element.

Differential Revision: https://phabricator.services.mozilla.com/D153834
2022-08-08 08:22:44 +00:00
Masayuki Nakano 8b7fb928d3 Bug 1782628 - Make `HTMLEditor::HandleInsertBRElement` create caret position before moving its container r=m_kato
The test oddly passes without the fix in `HandleInsertBRElement`.  I guess that
post-processing in `HTMLEditor::OnEndHandlingTopLevelEditSubActionInternal()`
handles `Selection`, and anyway the insertion point of the following
`insertText` is wrong.  It seems that we don't need to uplift this.

Differential Revision: https://phabricator.services.mozilla.com/D153832
2022-08-08 01:54:47 +00:00
Masayuki Nakano bea9bf4233 Bug 1782852 - part 1: Get rid of unused editor commands in the wild r=smaug
`increaseFontSize`, `decreaseFontSize`, `gethtml`, `heading` and `readonly`
commands were disabled for a year in all channels, but no regression reports
have been filed.  Therefore, we can delete the commands and the telemetry
probes.

Note that `cmd_getContents` command which is the internal command of `gethtml`
is not used in comm-central too.  Therefore, this patch deletes the command
handler, `nsClipboardGetContentsCommand`, and `Command::GetHTML` too.

Differential Revision: https://phabricator.services.mozilla.com/D153720
2022-08-05 02:55:22 +00:00
Masayuki Nakano eddeebefce Bug 1775381 - Move `AutoRangeArray` from `EditorUtils.h` to its own header and cpp file r=m_kato
Depends on D152982

Differential Revision: https://phabricator.services.mozilla.com/D153063
2022-08-04 05:39:16 +00:00
Masayuki Nakano b938b9b105 Bug 1774704 - part 9: Get rid of `EditorBase::TopLevelEditSubActionData::mNewBlockElement` due to unused r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152982
2022-08-04 05:39:15 +00:00
Masayuki Nakano aaa97aa9d5 Bug 1774704 - part 8: Make `HTMLEditor::SetSelectionToAbsoluteAsSubAction` stop setting `TopLevelEditSubActionData::mNewBlockElement` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152981
2022-08-04 05:31:12 +00:00
Masayuki Nakano 0196645809 Bug 1774704 - part 7-7: Make `HTMLEditor::AlignNodesAndDescendants` stop touching `Selection` directly and setting `mNewBlockElement` r=m_kato
For doing that, this patch also making `HTMLEditor::AlignContentsAtSelection`
which the only caller of `HTMLEditor::AlignNodesAndDescendants` handle
`Selection` with `AutoRangeArray` because it uses `AutoSelectionRestorer` and
we need to adjust `Selection` after restored.

Differential Revision: https://phabricator.services.mozilla.com/D152980
2022-08-04 05:07:32 +00:00
Masayuki Nakano 3a9a1e4035 Bug 1774704 - part 7-6: Make `HTMLEditor::AlignContentsInAllTableCellsAndListItems` and `HTMLEditor::AlignBlockContentsWithDivElement` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152979
2022-08-04 05:00:38 +00:00
Masayuki Nakano 1da47692c5 Bug 1774704 - part 7-5: Make `HTMLEditor::AlignContentsAtSelectionWithEmptyDivElement` stop touching `Selection` directly and setting `mNewBlockElement` r=m_kato
It's only caller is `HTMLEditor::AlignContentsAtSelection` which is called only
by `HTMLEditor::AlignAsSubAction` at almost last of it.  Therefore, it's safe
to handle `mNewBlockElement` at the caller of
`AlignContentsAtSelectionWithEmptyDivElement` is safe.

Differential Revision: https://phabricator.services.mozilla.com/D152978
2022-08-04 04:53:54 +00:00
Masayuki Nakano 3f4655f24a Bug 1774704 - part 7-4: Make `HTMLEditor::SetBlockElementAlign` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152977
2022-08-04 04:40:14 +00:00
Masayuki Nakano fd641593ca Bug 1774704 - part 7-3: Make `HTMLEditor::RemoveAlignFromDescendants` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152976
2022-08-04 04:33:56 +00:00
Masayuki Nakano efd0248a4c Bug 1774704 - part 7-2: Make `CSSEditUtils::RemoveCSSInlineStyleWithTransaction` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152975
2022-08-04 04:28:13 +00:00
Masayuki Nakano 68caf865dc Bug 1774704 - part 7-1: Make `HTMLEditor::EnsureHardLineBeginsWithFirstChildOf` and `HTMLEditor::EnsureHardLineEndsWithLastChildOf` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152974
2022-08-04 04:19:46 +00:00
Masayuki Nakano b653b11028 Bug 1774704 - part 6: Make `HTMLEditor::HandleHTMLIndentAtSelectionInternal` stop touching `Selection` directly and stop setting `mNewBlockElement` r=m_kato
The change of expected assertion count in the crash test is caused by that the
test calls `execCommand` recursively from the legacy mutation event listeners.
Therefore, stopping updating `Selection` for each DOM tree change causes that
the target range in the nested edit action is changed.  However, the nested
handling has already been disabled by default, so this should not be a problem
for the users.

Differential Revision: https://phabricator.services.mozilla.com/D152973
2022-08-04 04:07:46 +00:00
Masayuki Nakano c18ae2e047 Bug 1774704 - part 5-3: Make `HTMLEditor::HandleCSSIndentAtSelectionInternal` stop touching `Selection` directly and setting `mNewBlockElement` r=m_kato
It's called only by `HTMLEditor::HandleCSSIndentAtSelection` which is called
only by `HTMLEditor::HandleIndentAtSelection`.  They don't touch `Selection`
after calling it.  Therefore, we can make it adjust collapsing selection point
by itself.

Differential Revision: https://phabricator.services.mozilla.com/D152972
2022-08-04 03:16:28 +00:00
Masayuki Nakano 2296d580e7 Bug 1774704 - part 5-2: Make `HTMLEditor::IndentListChild` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152971
2022-08-04 03:00:31 +00:00
Masayuki Nakano 49869c2825 Bug 1774704 - part 5-1: Make `HTMLEditor::ChangeMarginStart` stop touching `Selection` directly r=m_kato
And also this patch makes it and an its caller stop computing editing host
with the latest `Selection`.

Differential Revision: https://phabricator.services.mozilla.com/D152970
2022-08-04 02:40:57 +00:00
Masayuki Nakano 6a5e4e03e3 Bug 1774704 - part 4-4: Make `HTMLEditor::ChangeSelectedHardLinesToList` stop setting `TopLevelEditSubActionData::mNewBlockElement` r=m_kato
With taking an `AutoRangeArray` which is initialized with `Selection`, it can
restore selection and check if it's collapsed and if collapsed in the expected
list element.  Then, its caller can apply the returned range to `Selection`
because it's an edit sub-action handler.

Differential Revision: https://phabricator.services.mozilla.com/D152969
2022-08-04 02:28:11 +00:00
Masayuki Nakano cc6f01f78c Bug 1774704 - part 4-3: Make `HTMLEditor::MaybeSplitAncestorsForInsertWithTransaction` stop computing editing host with current selection r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152968
2022-08-04 02:12:03 +00:00
Masayuki Nakano 87542555d4 Bug 1774704 - part 4-2: Make `HTMLEditor::ChangeListElementType` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152967
2022-08-04 02:02:46 +00:00
Masayuki Nakano 7b53a68cd6 Bug 1774704 - part 4-1: Move `HTMLEditor::GetParentListElementAtSelection` into `AutoRangeArray` r=m_kato
It oddly retrieve an ancestor list element which contains one range in the
selection ranges.  So, working it with `AutoRangeArray` which is initialized
with `Selection` makes `HTMLEditor` smaller...

Differential Revision: https://phabricator.services.mozilla.com/D152966
2022-08-04 01:50:28 +00:00
Masayuki Nakano 8b65b0bbf3 Bug 1774704 - part 3: Make `HTMLEditor::InsertParagraphSeparatorAsSubAction` stop setting `TopLevelEditSubActionData::mNewBlockElement` r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152965
2022-08-04 01:00:25 +00:00
Masayuki Nakano 49774332d1 Bug 1774704 - part 2: Make `CreateOrChangeBlockContainerElement`, `FormatBlockContainerWithTransaction` and `WrapContentsInBlockquoteElementsWithTransaction` stop setting `TopLevelEditSubActionData::mNewBlockElement` r=m_kato
They set `TopLevelEditSubActionData::mNewBlockElement` and their root callers
in edit sub-action level are only `InsertParagraphSeparatorAsSubAction` and
`FormatBlockContainerAsSubAction`, and they are called each other.  Therefore,
this patch changes these 3 methods once.

Differential Revision: https://phabricator.services.mozilla.com/D152964
2022-08-04 00:39:13 +00:00
Masayuki Nakano 14dd35ea1d Bug 1774704 - part 1: Make `HTMLEditor::EnsureCaretInBlockElement` only computes new caret point in the given element r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D152963
2022-08-04 00:21:53 +00:00
Masayuki Nakano 7f6f9cf71c Bug 1774704 - part 0: Add automated tests of preserving selection while handling some commands r=m_kato
The following patches touch the logic to restore selection after handling
commands.  However, it seems that they are not tested because I found some
regressions by manual testing, but didn't cause orange on tryserver.

`outdent-preserving-selection.tentative.html` causes a crash due to the
`MOZ_ASSERTION` in `HTMLEditor::HandleOutdentAtSelectionInternal`.  It means
that I misunderstand the logic and had put the assertion.  I should fix it
later with reading the complicated code again.  For now, I just change it
to `NS_WARNING_ASSERTION` instead.

And also `test_cmd_absPos.html` is the first test to check toggling `position`
between `static` and `absolute`.  Therefore, it detects wrong `MOZ_ASSERT`s
which test whether `EditActionData` or `TopLevelEditSubActionData` is created
or not **before** they create them by themselves.  So, this patch removes the
wrong assertions.

Differential Revision: https://phabricator.services.mozilla.com/D152962
2022-08-04 00:21:53 +00:00
Mark Banner 1c23a90c8e Bug 1782008 - Remove now unnecessary ESLint test definitions from other .eslintrc.js files. r=mossop,media-playback-reviewers,alwu
Differential Revision: https://phabricator.services.mozilla.com/D153216
2022-08-03 11:16:20 +00:00
Nika Layzell c15823d075 Bug 1772006 - Part 5: Simplify and move the string searching APIs from ns[T]StringObsolete, r=xpcom-reviewers,necko-reviewers,eeejay,dragana,barret
The biggest set of APIs from ns[T]StringObsolete which are still heavily used
are the string searching APIs. It appears the intention was for these to be
replaced by the `FindInReadable` APIs, however that doesn't appear to have
happened.

In addition, the APIs have some quirks around their handling of mixed character
widths. These APIs generally supported both narrow strings and the native
string type, probably because char16_t string literals weren't available until
c++11. Finally they also used easy-to-confuse unlabeled boolean and integer
optional arguments to control behaviour.

These patches do the following major changes to the searching APIs:

1. The ASCII case-insensitive search method was split out as
   LowerCaseFindASCII, rather than using a boolean. This should be less
   error-prone and more explicit, and allows the method to continue to use
   narrow string literals for all string types (as only ASCII is supported).
2. The other [R]Find methods were restricted to only support arguments with
   matching character types. I considered adding a FindASCII method which would
   use narrow string literals for both wide and narrow strings but it would've
   been the same amount of work as changing all of the literals to unicode
   literals.
   This ends up being the bulk of the changes in the patch.
3. All find methods were re-implemented using std::basic_string_view's find
   algorithm or stl algorithms to reduce code complexity, and avoid the need to
   carry around the logic from nsStringObsolete.cpp.
4. The implementations were moved to nsTStringRepr.cpp.
5. An overload of Find was added to try to catch callers which previously
   called `Find(..., false)` or `Find(..., true)` to set case-sensitivity, due
   to booleans normally implicitly coercing to `index_type`. This should
   probably be removed at some point, but may be useful during the transition.

Differential Revision: https://phabricator.services.mozilla.com/D148300
2022-07-30 00:12:48 +00:00
Masayuki Nakano bf2ccc8872 Bug 1780140 - Make `HTMLEditor::ClearStyleAt` clean up new empty inline elements which are not contain new text r=m_kato
Currently, `HTMLEditor` assumes that padding `<br>` element for empty last line
is outside of inline elements, but it may happen because of both:
* starting from bug 1778091, `HTMLEditor` move `<br>` element into new empty
inline elements at inserting new paragraph.
* web apps can put it into inline elements.

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

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

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

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

Differential Revision: https://phabricator.services.mozilla.com/D152616
2022-07-27 22:51:18 +00:00
Tooru Fujisawa a032f53a63 Bug 1780543 - Part 5: Add mozilla/chrome-script environment. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D152430
2022-07-26 02:46:30 +00:00
Masayuki Nakano a45b6d1e16 Bug 1773848 - Make the for-loop in the lambda in `HTMLEditor::InsertTableRowsWithTransaction` refer only `cellDataInLastRow` r=m_kato
It's renamed from `CellData`, but `cellData` still exists in the wider scope.
https://searchfox.org/mozilla-central/rev/f6a2ef2f028b8f1eb82fa5dc5cb1e39a3baa8feb/editor/libeditor/HTMLTableEditor.cpp#923-924

Therefore, these lines are wrong:
https://searchfox.org/mozilla-central/rev/f6a2ef2f028b8f1eb82fa5dc5cb1e39a3baa8feb/editor/libeditor/HTMLTableEditor.cpp#1049,1053

because `cellData` was in the for-loop:
https://searchfox.org/mozilla-central/rev/bc4493c72442ad55aecf6b575edb0df4ed18b113/editor/libeditor/HTMLTableEditor.cpp#1008-1009,1020,1022,1026

Differential Revision: https://phabricator.services.mozilla.com/D152144
2022-07-20 04:24:52 +00:00
Magnus Melin 2fec2a1929 Bug 1779343 - Don't crash rewrapping "> ". r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D151682
2022-07-14 13:12:29 +00:00
Neil Deakin ef2a63d6b6 Bug 1779042, fix test_paste_no_formatting.html to handle headless clipboard, r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D151548
2022-07-14 12:53:06 +00:00
Tooru Fujisawa 52c95734e7 Bug 1667455 - Part 9: Stop importing Services.jsm from chrome-priv HTML code, single-line cases. r=kmag,necko-reviewers,geckoview-reviewers,extension-reviewers,m_kato,dragana
Differential Revision: https://phabricator.services.mozilla.com/D150898
2022-07-11 12:41:52 +00:00
Neil Deakin 00acc7206b Bug 968104, paste unformatted shortcut (shift+ctrl/cmd+v) should work in plain text contexts, such as input and textarea, r=masayuki
Differential Revision: https://phabricator.services.mozilla.com/D150806
2022-07-11 08:58:35 +00:00
Masayuki Nakano 92c1ac04ef Bug 1778091 - Make `HTMLEditor` move invisible `<br>` element into the empty inline element after splitting a paragraph at end r=m_kato
In Yahoo! Mail, the paragraph has `<br>` after `<span>` element which has
`background-color`.  In this case, Gecko creates the following DOM tree after
splitting the paragraph:
```
<div><span>foo</span></div><div><span></span><br></div>
```
Then, the empty `<span>` in the right paragraph will be removed by the
post-processing.  However, in this case, the inline element is required for
preserving the style continued from the previous paragraph.

In this case, we should move the `<br>` element into the `<span>` to make
it non-empty and avoid it to be removed.  This is compatible with Chrome.

Differential Revision: https://phabricator.services.mozilla.com/D151345
2022-07-11 05:36:29 +00:00
Joel Maher 537a5a0dc8 Bug 1777549 - remove remaining e10s conditions in manifest files. r=gbrown,extension-reviewers,zombie
Differential Revision: https://phabricator.services.mozilla.com/D150820
2022-07-01 13:49:42 +00:00
Masayuki Nakano 80fbd3825b Bug 1774114 - Make `HTMLEditor` and its helper classes get split/join node direction dynamically r=m_kato
Currently I'm think that the split/join node direction should be managed per
`HTMLEditor` instance because per transaction makes undo/redo handling
complicated and may require additional space to save it in each transaction
instance.  However, the direction should be changeable with new Gecko specific
`execCommand` to support both direction until creating first split/join node
transaction or anytime with clearing the transactions.

Differential Revision: https://phabricator.services.mozilla.com/D149192
2022-07-01 02:02:03 +00:00
Masayuki Nakano b08b799b15 Bug 1770877 - part 38: Make `HTMLEditor::InsertParagraphSeparatorAsSubAction` stop updating `Selection` while handling its job r=m_kato
Finally, this patch makes it update `Selection` once after finishing its
preparation.

Differential Revision: https://phabricator.services.mozilla.com/D149109
2022-06-23 01:09:12 +00:00
Emilio Cobos Álvarez bd09497378 Bug 1372276 - Remove HTML menuitem. r=smaug,mconley,agi
This removes HTMLMenuItemElement and all the code and tests preffed off
by dom.menuitem.enabled.

The HTML parser changes are the result of applying the previous patch.

Differential Revision: https://phabricator.services.mozilla.com/D149979
2022-06-22 22:31:42 +00:00
Norisz Fay cfa3a53e0d Backed out changeset e9b6a7f08dc9 (bug 1770877) for causing wpt failures on editing-div-outside-body.html 2022-06-22 20:11:34 +03:00
Masayuki Nakano c2a64d2ada Bug 1770877 - part 38: Make `HTMLEditor::InsertParagraphSeparatorAsSubAction` stop updating `Selection` while handling its job r=m_kato
Finally, this patch makes it update `Selection` once after finishing its
preparation.

Differential Revision: https://phabricator.services.mozilla.com/D149109
2022-06-22 13:57:07 +00:00
Masayuki Nakano d292b994f8 Bug 1770877 - part 37: Make `HTMLEditor::HandleInsertLinefeed` stop touching `Selection` directly r=m_kato
Note that the odd path which always returns `NS_ERROR_FAILURE` is not covered by
the tests.  Therefore, this patch adds `MOZ_ASSERT` to make somebody hit it and
report a bug.

Differential Revision: https://phabricator.services.mozilla.com/D149108
2022-06-22 13:14:17 +00:00
Masayuki Nakano 4f7e0e9717 Bug 1770877 - part 36: Make `HTMLEditor::CreateStyleForInsertText` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149107
2022-06-22 13:07:05 +00:00
Masayuki Nakano d97c255cf8 Bug 1770877 - part 35: Make `HTMLEditor::SetInlinePropertyOnNode` and `HTMLEditor::SetInlinePropertyOnNodeImpl` stop touching `Selection` directly r=m_kato
Note that `CSSEditUtils` does not change `Selection` except
`RemoveCSSInlineStyleWithTransaction` which is used only by aligning in a block.
Therefore, this patch does not touch `CSSEditUtils`.

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

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

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

Differential Revision: https://phabricator.services.mozilla.com/D149103
2022-06-22 08:04:26 +00:00
Masayuki Nakano 9c2145a90d Bug 1770877 - part 31-3: Replace `insertLineBreak` variable in `HTMLEditor::InsertParagraphSeparatorAsSubAction` with a lambda r=m_kato
This can encapsule the long if-elseif-else blocks into the lambda.

Differential Revision: https://phabricator.services.mozilla.com/D149102
2022-06-22 02:54:34 +00:00
Masayuki Nakano 5af4b5cb8d Bug 1770877 - part 31-2: Make `HTMLEditor::InsertParagraphSeparatorAsSubAction` call `HandleInsertParagraphInParagraph` without `Selection` r=m_kato
The preceding call of `InsertBRElement` may collapse selection at the inserted
padding `<br>` element.  Only when calling `HandleInsertParagraphInParagraph`,
`InsertParagraphSeparatorAsSubAction` uses `Selection`.  So, only in this case,
we need to recompute the point to split for keeping current (odd) behavior.

Note that in normal cases, using `atStartOfSelection` gets same result.
However, if there are some invisible nodes such as comment nodes, doing it
may change the behavior.  For now, we should keep the current behavior.  It
should be sorted out when we make it stop inserting `<br>` elements for the
preparation of split without checking whether it's actually necessary.

Differential Revision: https://phabricator.services.mozilla.com/D149101
2022-06-22 01:52:32 +00:00
Masayuki Nakano 47a4dbc560 Bug 1770877 - part 30: Make `HTMLEditor::HandleInsertParagraphInListItemElement` stop touching `Selection` directly r=m_kato
It touches `Selection` redundantly (i.e., immediately after that, it or its
caller collapse `Selection`).  So we can just stop it because we can ignore
the cases when the handling fails after the redundant `Selection` update and
it can be caused by tricky things with the mutation event listeners.

Note that without changing `SplitNodeResult` a lot, we cannot make it return
`SplitNodeResult`, and currently there is no motivation to do it because the
only caller does not need the detail of the split.  Therefore, I give up doing
it.

Differential Revision: https://phabricator.services.mozilla.com/D149099
2022-06-22 01:34:03 +00:00
Masayuki Nakano c76d7f7b67 Bug 1770877 - part 29: Make `HTMLEditor::HandleInsertParagraphInHeadingElement` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149098
2022-06-22 01:25:04 +00:00
Masayuki Nakano 9b86130934 Bug 1770877 - part 28-6: Make `HTMLEditor::HandleInsertParagraphInParagraph` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149097
2022-06-22 01:18:35 +00:00
Masayuki Nakano a8fbc40014 Bug 1770877 - part 28-5: Get rid of unnecessary duplication of `EditorDOMPoint` in `HTMLEditor::HandleInsertParagraphInParagraph` r=m_kato
I tried to make the latter half preparation to call
`HTMLEditor::SplitParagraphWithTransaction`, but I cannot make it cleaner
because it needs to return `HTMLBRElement*` and `EditorDOMPoint` with maybe
modifying the DOM tree.  So, I keep it as-is, but I make replace the unnecessary
duplicated `EditorDOMPoint` with the original one which is adjusted to avoid
to create new empty link in the right paragraph.

Differential Revision: https://phabricator.services.mozilla.com/D149096
2022-06-22 01:05:47 +00:00
Masayuki Nakano fc4610f7d0 Bug 1770877 - part 28-4: Make `HTMLEditor::HandlerInsertParagraphInParagraph` take a split point and editing host r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149095
2022-06-22 01:00:42 +00:00
Masayuki Nakano a1ce604b80 Bug 1770877 - part 28-3: Make `HTMLEditor::HandleInsertParagraphInParagraph` insert `<br>` element immediately after considering so r=m_kato
Using the wide scope `EditorDOMPoint pointToInsertBR` makes it harder to read.
Although this duplicates a call of `HTMLEditor::InsertBRElement` and a couple of
post processing, but I think that it's easier to read/understand.

Differential Revision: https://phabricator.services.mozilla.com/D149094
2022-06-22 00:40:20 +00:00
Masayuki Nakano c0a2068334 Bug 1770877 - part 28-2: Make `HTMLEditor::HandleInsertParagraphInParagraph` return earlier if should be default to insert `<br>` instead r=m_kato
If it needs to insert a `<br>` but the editor does not want to create new
paragraph, its caller should be default to insert a `<br>` element.  Rather
than checking this at inserting `<br>` element, it should do it at considering
the place to insert the new `<br>`.

Differential Revision: https://phabricator.services.mozilla.com/D149093
2022-06-21 23:50:42 +00:00
Masayuki Nakano b97aca0073 Bug 1770877 - part 28-1: Isolate the part of adjusting split point for avoiding to create new empty link in `HTMLEditor::HandleInsertParagraphInParagraph` r=m_kato
The method does several different things.  For making each part isolated,
this patch wraps the first part with a lambda.

Differential Revision: https://phabricator.services.mozilla.com/D149092
2022-06-21 23:38:06 +00:00
Masayuki Nakano c77d8d358f Bug 1770877 - part 27: Make `HTMLEditor::SplitParagraph` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149091
2022-06-21 08:49:51 +00:00
Masayuki Nakano 6f93e32018 Bug 1770877 - part 26: Make `HTMLEditor::InsertBRElementIfEmptyBlockElement` a lambda since it's used only by one method r=m_kato
And its selection update are not used except the legacy mutation event
listeners so that we can drop them.

Differential Revision: https://phabricator.services.mozilla.com/D149090
2022-06-21 08:19:37 +00:00
Masayuki Nakano f9d31a6638 Bug 1770877 - part 25: Make `HTMLEditor::FormatBlockContainerWithTransaction` stop touching `Selection` directly r=m_kato
This patch makes it take `AutoRangeArray` and it can save a snapshot of the
ranges and restore it like `AutoSelectionRestorer`.

For accessing `HTMLEditor::RangeUpdaterRef` for clearing the saved ranges,
`AutoRangeArray` needs to store `HTMLEditor`.  Therefore, its constructors
and the destructor cannot be inlined in the header due to the include-hell.

Differential Revision: https://phabricator.services.mozilla.com/D149089
2022-06-21 05:58:45 +00:00
Masayuki Nakano f89b9d6eb1 Bug 1770877 - part 24: Make `HTMLEditor::MaybeExtendSelectionToHardLineEdgesForBlockEditAction` stop touching `Selection` directly r=m_kato
Differential Revision: https://phabricator.services.mozilla.com/D149088
2022-06-21 03:11:42 +00:00
Masayuki Nakano 5c2c671dec Bug 1770877 - part 23: Clean up callers of `AutoRangeArray::SplitTextNodesAtEndBoundariesAndParentInlineElementsAtBoundaries` r=m_kato
They at most twice updates the `Selection` right now.  We can make them update
`Selection` once.  And this patch makes the scope of `AutoRangeArray` clearer.

Differential Revision: https://phabricator.services.mozilla.com/D149087
2022-06-21 01:26:20 +00:00
Masayuki Nakano f1476f699b Bug 1770877 - part 22: Move `HTMLEditor::CollectEditTargetNodes` into `AutoRangeArray` r=m_kato
And also this moves `HTMLEditor::CollectChildren` to `HTMLEditUtils`.

Differential Revision: https://phabricator.services.mozilla.com/D149086
2022-06-21 01:19:25 +00:00
Masayuki Nakano 84a30bf21e Bug 1770877 - part 21: Get rid of `HTMLEditor::SplitInlinesAndCollectEditTargetNodes` r=m_kato
It's callers become messy with this patch.  The following patches try to make
them smaller.

Differential Revision: https://phabricator.services.mozilla.com/D149085
2022-06-21 01:07:10 +00:00