Commit Graph
330 Commits
Author SHA1 Message Date
Masayuki Nakano 1c1025a6e6 Bug 1814337 - Fix bugs at applying multiple styles to collapsed Selection r=m_kato
There are 3 bugs.

One is, `PendingStyles::TakeAllPreservedStyles` returns styles in reversed order
of setting styles, this unexpected order causes that `<font>` element is placed
innermost instead of outermost, thus, background color may be applied to shorter
area than text.  Unfortunately, Chrome applies the style in fixed order, but
using same order as setting the styles is reasonable for us because we use
same code to apply multiple styles once.

Another is, `AutoInlineStyleSetter` extends the range to apply new style to
parents even if the given point is not in start or end of the first container.
Current code works fine if there is only one text node in an inline element,
but after un-setting a style, text nodes may be keep split.  And also when we
apply new style, we create an empty text node for a placeholder of new text,
therefore, the range may be extended from the empty text node to before/after
its previous/next text node.  Note that the latter case needs to work with
invisible things more, but this bug needs to be fixed ASAP due to the dead line,
and invisible things not so appear in inline elements.  Therefore, it's okay
to leave it.

The other is, the delete handlers do not clear the cached styles (cached when
`HTMLEditor` starts handling it).  If it's caused by a `Backspace` key press
in start of a block, `HTMLEditor` caches the style at caret (right paragraph),
then, collapse `Selection` to end of the ex-left block where may have different
style, then, when user types new text there, the cached style is applied into
to the new text **too**.  Therefore, if `Selection` was collapsed and handling
a `Backspace` key press, the cached styles should be forgotten.

Depends on D168640

Differential Revision: https://phabricator.services.mozilla.com/D168865
2023-02-07 14:52:02 +00:00
Masayuki Nakano 21a652d4b5 Bug 1814345 - Make the style setter re-normalize color value when setting <font color="..."> r=m_kato
Gmail sets `styleWithCSS` to `true` before setting `foreColor`, then, sets
`styleWithCSS` to `false` before user typing text.  Currently, we normalize
given color value to a proper value for current styling mode, and we have not
assumed that the mode is changed during preserving the style.

For solving this issue, `HTMLEditor::AutoInlineStyleSetter::ApplyStyle` should
normalize the given value again if the value is not proper for
`<font color="...">` (at this moment, the color value is normalized to `#XXXXXX`
style or `rgb(n, n, n)` or `rgba(n, n, n, n)`, therefore the check is simple in
this patch).

Then, I realized that according to `editing/run/forecolor.html` result [1],
the other browsers accept CSS color value as the parameter of `foreColor`
command.  Therefore, this patch also allows it, thus, this patch fixes a lot of
WPT failures.

1. https://wpt.fyi/results/editing/run/forecolor.html%3F1-1000?sha=95f9b15d9a&label=master&max-count=1&view=subtest

Depends on D168179

Differential Revision: https://phabricator.services.mozilla.com/D168639
2023-02-02 08:45:39 +00:00
Masayuki Nakano b3911926e1 Bug 1812170 - Make HTMLEditor::ClearStyleAt should return pointToPutCaret if next node of first split is not split r=m_kato
The new path added in bug 1807829 hits the odd result case of `ClearStyleAt`.
`pointToPutCaret` may be updated if the preceding split occurs.  Therefore,
it should be returned if it does not split next nodes after the first split
instead of returning unset point (because of not splitting the point,
`unwrappedSplitNodeResult.AtSplitPoint` may return unset point, therefore,
it may return unset point in the case).

Additionally, I forgot to split delete `SplitNodeResult::mCaretPoint` in
bug 1792654, and it causes `SplitNodeDeepWithTransaction` returns unset caret
point.  This patch fixes this bug too.

Differential Revision: https://phabricator.services.mozilla.com/D168179
2023-02-02 05:09:15 +00:00
Masayuki Nakano a2c96e81e2 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 307c2dae78 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 b785efe281 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 30127aeb18 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 f18e2bfef5 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 d75253ccaa 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 874a4583b0 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 2454027ce5 Backed out changeset 649e12877126 (bug 1808906) for causing bp-hybrid bustages. 2023-01-17 03:18:05 +02:00
Masayuki Nakano 06a160716d 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 11d6e9bc6d 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
Masayuki Nakano 733d45f1e8 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 687b8ed601 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 87fc0d16f8 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 432b75ccff 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 67be0a498d 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 292a13ec19 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
Masayuki Nakano 95a9fbe5c3 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 bab37e2979 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 4c86bfd83b 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 348c77d058 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 479c34e4a7 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 ff62247ba3 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 c4c0392a25 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 9fc03531ae 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 889518c142 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 17e909acad 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 4b58271700 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 8a3f2db260 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 aab055ae21 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 ea0a1148d0 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 fd8da25d31 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 88aa660625 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 a9570014cf 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 660a55f386 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 91d4c3ff9b 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 cd1ecc6e69 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 80dd5a8116 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 ff0dced7c9 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 7fd9c5ea2a 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 28026f23ec 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 2c93609e80 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 ab6e29169b 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 a04806dcfe 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 bf8361d3fe 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 a52e6adf9a 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 a8f6e15d50 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 175fe247b2 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