Closed Bug 1927709 Opened 1 year ago Closed 1 year ago

GetRenderedText with white-space:pre-line does not properly respect all newlines

Categories

(Core :: Layout: Text and Fonts, defect)

defect

Tracking

()

RESOLVED FIXED
134 Branch
Tracking Status
firefox134 --- fixed

People

(Reporter: jfkthame, Assigned: jfkthame)

References

Details

Attachments

(1 file)

(See https://github.com/web-platform-tests/wpt/pull/48678#issuecomment-2438706928.)

The recent fix for nsTextFrame::GetRenderedText in bug 1923829 (and the associated WPT test) was not quite correct, in that it fails to preserve blank lines in the white-space: pre-line content. The second assertion in https://wpt.live/html/dom/elements/the-innertext-and-outertext-properties/innertext-whitespace-pre-line.html is therefore currently wrong.

Given

<div id="c" style="white-space: pre-line">
 one
  two
    <!-- comment -->
   three
    four
</div>

we should expect c.innerText to return "\none\ntwo\n\nthree\nfour\n", preserving the initial newline and the blank line in the middle. This matches Chrome's result, and corresponds to

the element's text content "as rendered"

which is what the spec calls for.

The problem occurs because when the line is empty, we fail to set trimmedSignificantNewline here; and even if we had set that flag, we then return early from here so we'd fail to restore the required newline at the end of the method.

This makes innerText better reflect the actual rendered text, and matches the result
seen in Blink for the testcase.

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d9d099719789 Properly preserve newlines in GetRenderedText for textframes with white-space:pre-line. r=jwatt
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/48858 for changes under testing/web-platform/tests
Upstream PR was closed without merging

Ah, I see the issue -- accessibility code calls GetRenderedText with TrailingWhitespace::NoTrim, in which case we don't need the "fix" here because the trailing newline isn't getting trimmed. So we need to make the change conditional on the TrailingWhitespace option, otherwise we end up adding unwanted extra newlines to the a11y TextLeaf nodes.

I'll run the fixed version through tryserver again before re-landing...

Flags: needinfo?(jfkthame)
Attachment #9433868 - Attachment description: Bug 1927709 - Properly preserve newlines in GetRenderedText for textframes with white-space:pre-line. → WIP: Bug 1927709 - Properly preserve newlines in GetRenderedText for textframes with white-space:pre-line.
Attachment #9433868 - Attachment description: WIP: Bug 1927709 - Properly preserve newlines in GetRenderedText for textframes with white-space:pre-line. → Bug 1927709 - Properly preserve newlines in GetRenderedText for textframes with white-space:pre-line. r=#layout
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/3f4f1d264c3a Properly preserve newlines in GetRenderedText for textframes with white-space:pre-line. r=jwatt
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 134 Branch
Upstream PR merged by moz-wptsync-bot
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: