Range.getBoundingClientRect() is wrong with display: contents inside the range

#40837457 Area: Blink>DOM / CSSOM View CL 8644629 In Review

What happens

Range::GetBorderAndTextQuads() collects the border box of every fully selected element and then skips that element's children, since the parent box already covers them. A display: contents element is fully selected like any other, but generates no box -- so its children were skipped while nothing was reported in their place, and the range came out too short.

The fix stops a subtree only once a selected ancestor actually generates a box. The existing WPT cssom-view/range-bounding-client-rect-with-display-contents.html was failing on every desktop platform and passes now; three stale mac/win/ios baselines go away.

Range between two spacers, with display: contents blocks in between

Your browser: unpatched Chrome reports 46px for a 60px gap.
Before: 46px, mismatch
Without the patch: the two 30px blocks live inside display: contents wrappers and are left out.
After: 60px, match
With the patch: the range covers the full 60px.
Diff mask over the readout
852 px differ -- the readout rows.

The subtle part

The first version of this fix simply left box-less elements out of the "selected elements" set. That fixes the bug, but it also breaks the chain the skip logic walks: for <div><span style="display:contents"><b> with the whole div selected, <b> no longer had a selected parent, so its box was emitted in addition to the div box that already covers it -- getClientRects() went from 2 rects to 3.

The landed version keeps every fully selected element in the set and tracks coverage in a second set, filled in the same tree-order pass: an element is covered when its parent is selected and either generates a box or is itself covered. That is one hash lookup per node, so the fix stays O(1) per node like the original code -- an earlier variant walked the ancestor chain per element instead, which is O(depth). A new internal test, fast/dom/Range/client-rects-with-display-contents.html, pins both directions: children of a display: contents element are reported, and boxes already covered by a selected ancestor are not repeated. That second assertion fails with the first version of the fix.

Verification

Links

Issue 40837457 CL 8644629 standalone sampler.html capture_screenshots.py