Closed Bug 1653534 Opened 4 years ago Closed 4 years ago

`WSRunScanner` and `TextFragmentData` should not refer style of scan start container for checking whether specific node is preformatted or not

Categories

(Core :: DOM: Editor, defect, P2)

defect

Tracking

()

RESOLVED FIXED
81 Branch
Tracking Status
firefox80 --- wontfix
firefox81 --- fixed

People

(Reporter: masayuki, Assigned: masayuki)

References

Details

Attachments

(5 files)

I don't like to change traditional behavior before shipping beforeinput event. However, this bug causes odd failure in some WPT, and this must not affect actual web apps because web apps must not put preformatted inline elements into contenteditable.

Currently, TextFragmentData (formally, WSRunScanner and its derived class, WSRunObject) check whether a point is preformatted text or not with "scan start point". Therefore, if white-space sequence across multiple inline elements and some of them have different white-space style value, its behavior is broken. So, we need to fix this bug 1644313, unfortunately.

Currently, TextFragmentData stores whether the scan start point is
preformatted or not. However, it does not make sense because the class
may contain other text nodes which may have different style in its range.
The main job of TextFragmentData is managing white-spaces as visible
sequence or invisible sequence. So, preformatted white-space should be
treated as visible character because of not collapsible with adjacent
formatted ASCII white-spaces.

First of all, this patch its initializer stop scanning white-spaces if
it meets non-empty preformatted text node.

Note that the new failures are caused by the difference whether which
white-space sequence should be normalized when modifying text at text node
or inline element boundary. This difference should be fixed in another
bug because our new normalizer does not handle this same as Blink for now.

Simply, if a white-space is in a preformatted text node, we shouldn't modify
it for normalizing. This patch adds such checks to various points in
WSRunObject.cpp.

Depends on D84317

The check does not make sense because TextFragmentData's range may contain
multiple text nodes which may have different style.

With the previous patch, the range won't cross characters in preformatted
text nodes. Therefore, their result won't contain preformatted characters
right now. So, we can just drop the unnecessary check from them.

Depends on D84319

Traditionally, WSRunScanner (and formerly WSRunObject) treats all text
nodes in its range when scan start container node has preformatted style.
This means that when starting start from start or end of preformatted text node
or inline element, it treats adjacent white-spaces which is not preformatted
as preformatted.

This patch fixes this issue. Because of the fix of preceding patches,
BoundaryData stops scanning if it meets preformatted text node so that
this patch makes the scanners mark whether the boundary crossed or not a
preformatted character from scan start point to reason content.

Note that the above change causes new failures with <listing> element which
should be treated as <pre> element, but HTMLEditUtils treats it as
non-container inline element.
https://html.spec.whatwg.org/multipage/dom.html#elements-in-the-dom:listing

Therefore, this patch changes the definition of <listing> element and
<xmp> element which is also mentioned in the above link to container
element etc. <listing> element is treated exactly same as <pre>,
therefore, the new definition is same as <pre>, but <xmp> does not
allow any tags after opens it (i.e., even if its close tag). Therefore,
<xmp> definition is different from <listing> and <pre> elements'
definition.

Depends on D84320

The patches will fix about a thousand known test failures (mostly in fontname.html) in the traditional path. And also they will fix about 10 test failures in new white-space normalizer path.

Attachment #9164982 - Attachment description: Bug 1653534 - part 4: Make `TextFragmentData` set its `mIsPreformatted` only when its range contains preformatted character r=m_kato! → Bug 1653534 - part 4: Make `TextFragmentData` set its `mIsPreformatted` more carefully r=m_kato!

With the previous patch, 2 bugs become visible.

One is a MOZ_ASSERT in
WhiteSpaceVisibilityKeeper::MakeSureToKeepVisibleStateOfWhiteSpacesAroundDeletingRange()
is wrong. When TextFragmentData::GetReplaceRangeDataAtEndOfDeletionRange()
returns a replace range, it may set the start to inclusive next character of
end to delete. So, start of replace range may start after end to delete when
container of end to delete is not a text node and its next editable char point
is an ASCII white-space. Therefore, this patch rewrite it with
MOZ_ASSERT_IF and EditorDOMPoint::IsInTextNode().

The other is TextFragmentData::GetReplaceRangeDataAtEndOfDeletionRange()
and TextFragmentData::GetReplaceRangeDataAtStartOfDeletionRange() may call
TextFragmentData::GetFirstASCIIWhiteSpacePointCollapsedTo() and
TextFragmentData::GetEndOfCollapsibleASCIIWhiteSpaces() with a point in
preformatted text node. Therefore, this patch adds the check into them.

Depends on D84323

Pushed by masayuki@d-toybox.com:
https://hg.mozilla.org/integration/autoland/rev/70f2b09f0b57
part 1: Make `TextFragmentData` treat only collapsible white-spaces as its non-collapsed range r=m_kato
https://hg.mozilla.org/integration/autoland/rev/64991750fbdb
part 2: Add text node style check in `WSRunObject.cpp` r=m_kato
https://hg.mozilla.org/integration/autoland/rev/b17cfb4cf764
part 3: Make `TextFragmentData::InvisibleLeadingWhiteSpaceRangeRef()` and `TextFragmentData::InvisibleTrailingWhiteSpaceRangeRef()` stop checking whether scanning start point is preformatted or not r=m_kato
https://hg.mozilla.org/integration/autoland/rev/d418b81621a9
part 4: Make `TextFragmentData` set its `mIsPreformatted` more carefully r=m_kato
https://hg.mozilla.org/integration/autoland/rev/724aa6e8cdc6
part 5: Fix new intermittent orange of editor/libeditor/crashtests/1424450.html r=m_kato

The patch landed in nightly and beta is affected.
:masayuki, is this bug important enough to require an uplift?
If not please set status_beta to wontfix.

For more information, please visit auto_nag documentation.

Flags: needinfo?(masayuki)

No, this is too risky change for beta, and this is long standing bug.

Flags: needinfo?(masayuki)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: