Page MenuHomePhabricator

Bug 1979915 Part 1 - Apply text-decoration-trim during decoration rect calculation and decoration painting.
ClosedPublic

Authored by AlaskanEmily on Sep 22 2025, 9:59 PM.
Referenced Files
Unknown Object (File)
Tue, Apr 7, 4:51 AM
Unknown Object (File)
Sun, Apr 5, 6:04 PM
Unknown Object (File)
Sun, Apr 5, 6:04 PM
Unknown Object (File)
Sun, Apr 5, 6:04 PM
Unknown Object (File)
Sat, Apr 4, 11:36 PM
Unknown Object (File)
Sat, Apr 4, 3:43 AM
Unknown Object (File)
Sat, Apr 4, 2:09 AM
Unknown Object (File)
Fri, Apr 3, 9:09 PM

Details

Summary

This is still pref'ed off, even though we don't directly check the pref in
this code.
Without the pref layout.css.text-decoration-trim.enabled set, this should do
nothing as the intial value of zero will result in no text decoration trim.

This change still leaves a few situations with incorrect painting:

The current implementation will always have zero trim on a line break, but it
is possible that a very large trim value and the leftover trim from the next
line should then overflow to the previous line.

No distinction is made between BIDI continuations and line breaks.
Combined with the previous limitation, this means that in the case of a BIDI
continuation at the start or end of a line which is smaller than the text
trim, the decoration will begin where the inline frames meet.

This also causes incorrect painting when the box-decoration-break value is
clone in a line with BIDI continuations, as the trim will now be applied
where the continuations meet.

Diff Detail

Event Timeline

phab-bot changed the visibility from "Custom Policy" to "Public (No Login Required)".
phab-bot changed the edit policy from "Custom Policy" to "Restricted Project (Project)".
phab-bot removed a project: secure-revision.
AlaskanEmily retitled this revision from Bug 1979915 WIP to Bug 1979915 - Apply text-decoration-trim during decoration rect calculation and decoration painting..
AlaskanEmily edited the summary of this revision. (Show Details)
jfkthame requested changes to this revision.Oct 6 2025, 6:04 PM
jfkthame added a subscriber: jfkthame.

Looking good! "Request Changes" for a couple of issues with CSS vs device pixels, as noted inline, but with those fixed up it'd be great to get this landed.

We can have a followup to figure out the issue with text-decoration-trim-011.html, plus whatever additional testcases you make for other tricky examples.

Presumably you can remove most of the existing text-decoration-trim-*.ini files under the wpt/meta directory, as they should now be passing.

layout/generic/nsTextFrame.cpp
5794–5797

There's some mixing of units here, which can be observed by zooming in on the text-decoration-trim-010.html testcase: the amount of trim (relative to the text size) varies with the zoom level (or, equivalently, with the devicePixelRatio of the screen).

I think the issue is that gfxFont::Metrics is in device pixels already, so the multiplication by scale is unnecessary and effectively means that the devicePixelRatio has been doubly applied.

I'd suggest something like max(aMetrics.emHeight * 0.125, scale) which should give a trim of 1/8th of an em, clamped to a minimum of one CSS px (rather than one device pixel, which could be excessively narrow on a high-res screen).

5808–5809

I think this gives the right result but is confusing, because trimLeft and trimRight want to be device pixels (see comment at struct DecorationRectParams), so getting them via ToCSSPixels() feels wrong.

It's actually working out because of the prior application of scale, but would be better done as something like

trimLeft = NSAppUnitsToDoublePixels(length.start.ToAppUnits(), app);

so that it doesn't look like we're putting a CSS px value in there.

5818

These can be nscoord, can't they? AFAICS they're just used for (integer) appUnit values.

6007–6008

Can we skip computing and unioning the rect if this returns false? It seems like that should be OK -- if the decoration is going to be entirely trimmed away, we don't need to consider it part of the ink overflow area. (Or am I missing something?)

This revision now requires changes to proceed.Oct 6 2025, 6:04 PM
AlaskanEmily marked 3 inline comments as done.

I wasn't going to adjust the meta for the tests until the pref is enabled, and I was going to wait for next nightly to enable it to get a longer test cycle before it rolls into beta.

layout/generic/nsTextFrame.cpp
5808–5809

Yeah, I noticed that it was a little misleading. I considered using the typed coordinate values, but I also then saw I would really want to convert the entire params struct, and that should be its own change later.
I can rephrase it as suggested.

jfkthame added a project: testing-approved.

I wasn't going to adjust the meta for the tests until the pref is enabled, and I was going to wait for next nightly to enable it to get a longer test cycle before it rolls into beta.

It's already enabled for the text-decoration directory, though, via the __dir__.ini file. :)

Flipping the pref at the start of the next cycle makes sense, but this can land ahead of that; it'll be preffed-off for users but already getting tests run in CI.

(Tagging "testing-approved" on the assumption that it passes on tryserver. Though do you need to tweak text-decoration-trim-007.html as previously discussed, to make it more reliable if the Arabic font has larger descenders?)

This revision is now accepted and ready to land.Oct 6 2025, 9:17 PM

I wasn't going to adjust the meta for the tests until the pref is enabled, and I was going to wait for next nightly to enable it to get a longer test cycle before it rolls into beta.

It's already enabled for the text-decoration directory, though, via the __dir__.ini file. :)

Ah, OK. I'll add a part 2 to update the test metadata.

I do think we should tweak some of the tests based on the descender issue at some point (I could do that in the followup that has the extra testcases), but it's only an issue locally for me and not on the try-server.

AlaskanEmily retitled this revision from Bug 1979915 - Apply text-decoration-trim during decoration rect calculation and decoration painting. to Bug 1979915 Part 1 - Apply text-decoration-trim during decoration rect calculation and decoration painting..

I do think we should tweak some of the tests based on the descender issue at some point (I could do that in the followup that has the extra testcases), but it's only an issue locally for me and not on the try-server.

SGTM, thanks.

This revision is now accepted and ready to land.Oct 7 2025, 6:28 AM
This revision is now accepted and ready to land.Oct 7 2025, 9:41 PM