Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 6412a2d665afff31ee9fba2b6f233736798db288
https://github.com/WebKit/WebKit/commit/6412a2d665afff31ee9fba2b6f233736798db288
Author: Karl Dubost <[email protected]>
Date: 2026-08-06 (Thu, 06 Aug 2026)
Changed paths:
A
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-geometry-apis-in-non-rendered-elements-expected.txt
A
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-geometry-apis-in-non-rendered-elements.html
M
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-get-bounding-client-rect-in-non-rendered-elements-expected.txt
M Source/WebCore/dom/Element.cpp
M Source/WebCore/rendering/RenderObject.h
Log Message:
-----------
getBoundingClientRect() returns a non-zero rect for SVG elements inside
hidden containers
https://bugs.webkit.org/show_bug.cgi?id=320456
rdar://183425103
Reviewed by Nikolas Zimmermann.
<g display="none"><rect id="r" width="10" height="10"/></g>
r.getBoundingClientRect().width // 10, should be 0
r.getClientRects().length // 1, should be 0
Nothing paints there, and the same happens in `<defs>`, `<mask>`, `<pattern>`,
`<marker>`, gradients and `<symbol>`. Those containers keep renderers for their
descendants so that resources stay referenceable, and `display` does not
inherit, so the `<rect>` is laid out with a real bounding box.
The SVG branch of `Element::getClientRects` asks that renderer for its
`objectBoundingBox()` directly, so CSSOM View step 1[1]
return an empty list when the element has no associated box
is never evaluated for SVG.
Fix by adding `isInNonRenderedSVGSubtree` and returning early from
* `getClientRects`,
* `boundingAbsoluteRectWithoutLayout`
* and `boundsInRootViewSpace`.
It has to run before the branch on renderer type, which is why `<text>`
was wrong too (it is a `RenderBlockFlow` and reports through a
different path than shapes).
The ancestor walk stops at the SVG root. `SVGForeignObjectElement`
suppresses the renderer for a `<foreignObject>` under a hidden container,
so nothing below a root can have one above it. `<foreignObject>` was the
one element getting this right.
A `ResizeObserver` on the same element still reports 10x10, so it now
answers 0x0 to `getBoundingClientRect` and 10x10 to `ResizeObserver`.
Chrome does the same, so `ResizeObservation::computeObservedSizes` is
left alone.
[1] https://drafts.csswg.org/cssom-view-1/#dom-element-getclientrects
Test:
imported/w3c/web-platform-tests/svg/geometry/svg-geometry-apis-in-non-rendered-elements.html
*
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-geometry-apis-in-non-rendered-elements-expected.txt:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-geometry-apis-in-non-rendered-elements.html:
Added.
*
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-get-bounding-client-rect-in-non-rendered-elements-expected.txt:
* Source/WebCore/dom/Element.cpp:
(WebCore::isInNonRenderedSVGSubtree):
(WebCore::Element::boundsInRootViewSpace):
(WebCore::Element::getClientRects):
(WebCore::Element::boundingAbsoluteRectWithoutLayout const):
* Source/WebCore/rendering/RenderObject.h:
(WebCore::RenderObject::isRenderOrLegacyRenderSVGHiddenContainer const):
Canonical link: https://commits.webkit.org/318744@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications