Closed Bug 1712703 Opened 3 years ago Closed 2 years ago

`white-space:pre-wrap` does not interact correctly with `text-align:right` or `center`

Categories

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

defect

Tracking

()

RESOLVED FIXED
113 Branch
Tracking Status
firefox113 --- fixed

People

(Reporter: jfkthame, Assigned: jfkthame)

References

(Blocks 1 open bug, )

Details

Attachments

(3 files)

Testcase: https://codepen.io/jfkthame/pen/rNywVMB

When white-space:pre-wrap and text-align:right are in effect, we wrap lines after spaces (correctly), but then the space where the line was wrapped occupies space on the line instead of hanging, and means that the text is not properly flush-right.

This behavior would be correct for white-space:break-spaces, where it is explicitly called out in the spec as a difference from pre-wrap behavior; but for pre-wrap, the end-of-line space should hang.

FTR, Chrome also fails the example in this codepen, whereas Safari handles it correctly.

The same issue applies with text-align:center, where the preserved end-of-line spaces cause the wrapped lines to appear slightly off-center, though it's less obvious than the flush-right case. Example with centered text: https://codepen.io/jfkthame/pen/KKWqpbP

Again, this renders correctly in Safari but wrong in Chrome.

Summary: `white-space:pre-wrap` does not interact correctly with `text-align:right` → `white-space:pre-wrap` does not interact correctly with `text-align:right` or `center`
Blocks: 1253840
Depends on: 1825983

Of the 15 cases here (combinations of text-align and directionality), mozilla-central
currently fails 9 and passes only 6.

(FTR, a bunch of these tests also currently fail in Chrome, with similar errors to Firefox;
only Safari seems to handle them consistently/correctly.)

Assignee: nobody → jfkthame
Status: NEW → ASSIGNED

With the preceding patch, all the new testcases added here now pass, as do several
pre-existing WPT tests that were failing for similar reasons.

Depends on D174728

only Safari seems to handle them consistently/correctly.

I confirmed this -- though interestingly, WebKit-based Epiphany (aka gnome-web), which I tested before Safari here, doesn't seem to handle the preserved-spaces pieces of your codepens correctly. They render your right-aligned example https://codepen.io/jfkthame/pen/rNywVMB without any visible spaces at the right edge in the bottom section; and they render https://codepen.io/jfkthame/pen/KKWqpbP without the expected leftwards-offsetting at the bottom.

Not sure if this is due to platform-differences on Linux vs. Mac, or gnome-web lacking the WebKit code patch to do this properly, or something else.

Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/fa98b4c11d52 Add WPT reftests for white-space:pre interaction with text-align. r=dholbert https://hg.mozilla.org/integration/autoland/rev/e54195c66f87 Record the "hangable" advance of trailing whitespace in a textframe property, and use this in nsLineLayout to adjust inline positioning. r=dholbert https://hg.mozilla.org/integration/autoland/rev/18c753fda684 Remove annotations for failures related to pre-wrap and hanging spaces. r=dholbert
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/39399 for changes under testing/web-platform/tests
Upstream PR was closed without merging
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0c96eb4bdfd1 Add WPT reftests for white-space:pre interaction with text-align. r=dholbert https://hg.mozilla.org/integration/autoland/rev/d2bee1af043f Record the "hangable" advance of trailing whitespace in a textframe property, and use this in nsLineLayout to adjust inline positioning. r=dholbert https://hg.mozilla.org/integration/autoland/rev/5c2a1049afaa Remove annotations for failures related to pre-wrap and hanging spaces. r=dholbert
Status: ASSIGNED → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 113 Branch
Flags: needinfo?(jfkthame)
Upstream PR merged by moz-wptsync-bot
Regressions: 1827009
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: