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.
display: contents wrappers and are left out.
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.
external/wpt/css/cssom-view + fast/dom/Range:
313 tests as expected.external/wpt/dom/ranges + fast/dom: 1434
tests as expected.fast/dom/Range, editing/selection,
cssom-view combined: 1690 as expected.*Range* blink unit tests pass.perf_tests/dom/range-get-client-rects-deep-tree.html:
getClientRects() over a 200 level deep tree with
display: contents in every other level, so the coverage
bookkeeping can be measured with pinpoint. Locally (debug build, 4001
rects) upstream, the ancestor-walk variant and the landed version all
measure 180-204ms, i.e. no difference outside noise.