Skip to content

LibWeb: Apply ::first-letter pseudo-element styles#8885

Open
tcl3 wants to merge 5 commits intoLadybirdBrowser:masterfrom
tcl3:libweb_first_letter
Open

LibWeb: Apply ::first-letter pseudo-element styles#8885
tcl3 wants to merge 5 commits intoLadybirdBrowser:masterfrom
tcl3:libweb_first_letter

Conversation

@tcl3
Copy link
Copy Markdown
Member

@tcl3 tcl3 commented Apr 12, 2026

We now apply first letter styles by splitting text with a first-letter style applied into 2 TextSliceNode objects. The
DOM::Text layout node always points at the non first-letter slice and the first-letter slice is reachable via
TextSliceNode::first_letter_slice().

First letter splitting works by TreeBuilder walking a block container's inline descendants to find the first typographic letter unit per the pattern given in css-pseudo level 4, which is then wrapped in an anonymous inline box styled with the ::first-letter computed properties.

Consumers that map between DOM offsets and layout geometry are updated to visit all slices of a DOM::Text through TextOffsetMapping.

With this change we pass 359 of the first-letter-punctuation-* WPT tests because we are following the css-pseudo-4 spec, which has stricter rules for trailing punctuation.

@tcl3 tcl3 requested a review from AtkinsSJ as a code owner April 12, 2026 21:25
@tcl3 tcl3 force-pushed the libweb_first_letter branch from bf89115 to bf28e74 Compare April 12, 2026 21:41
tcl3 added 4 commits April 12, 2026 23:42
Add an `AttachToDOMNode` parameter to the Layout::Node constructor that
controls whether the newly-constructed node calls `set_layout_node()`
on its backing DOM node.
We now apply first letter styles by splitting text with a first-letter
style applied into 2 `TextSliceNode` objects.  The
`DOM::Text` layout  node always points at the non first-letter slice
and the first-letter slice is  reachable via
`TextSliceNode::first_letter_slice()`.

First letter splitting works by `TreeBuilder` walking a block
container's inline descendants to find the first typographic letter
unit per the pattern given in  css-pseudo level 4, which is then
wrapped in an anonymous inline box styled with the `::first-letter`
computed properties.

Consumers that map between DOM offsets and layout geometry
are updated to visit all slices of a `DOM::Text` through
`TextOffsetMapping`.
@tcl3 tcl3 force-pushed the libweb_first_letter branch from bf28e74 to 139fa52 Compare April 12, 2026 22:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant