Skip to content

elementFromPoint() hits the outermost <svg> in corners cut by border-radius - #78233

Open
karlcow wants to merge 1 commit into
WebKit:mainfrom
karlcow:328841-svg-root-border-radius-hittest
Open

karlcow wants to merge 1 commit into
WebKit:mainfrom
karlcow:328841-svg-root-border-radius-hittest

Conversation

@karlcow

@karlcow karlcow commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

b9e049c

elementFromPoint() hits the outermost <svg> in corners cut by border-radius
https://bugs.webkit.org/show_bug.cgi?id=328841
rdar://190954429

An outermost <svg> with border-radius is painted with rounded corners,
but elementFromPoint() returns the <svg> for points in the cut-off
corners. A <div> with the same size and border-radius returns its
parent there. Chrome and Firefox return the parent for both.

CSS Backgrounds says event handling follows the curves:

    other effects that clip painting or event handling to the border,
    padding, or content edge must clip to their respective curves. For
    example, [...] pointer events to the curved border edge, etc.

https://drafts.csswg.org/css-backgrounds-3/#corner-clipping

RenderBox::nodeAtPoint() and RenderBlock::nodeAtPoint() both call
hitTestBorderRadius() before they record a hit on their own background.
Both SVG root renderers replace nodeAtPoint() and only checked that the
point is inside the border box rectangle.

Add the same hitTestBorderRadius() check to the step that reports a hit
on the <svg> element itself, in LegacyRenderSVGRoot and in
RenderSVGRoot. SVG children are still tested first and are not affected
by the root's border-radius, which matches what a <div> does.

Test: imported/w3c/web-platform-tests/svg/interact/scripted/svg-root-border-radius.html

* LayoutTests/imported/w3c/web-platform-tests/svg/interact/scripted/svg-root-border-radius-expected.txt:
* Source/WebCore/rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::nodeAtPoint):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGRoot.cpp:
(WebCore::LegacyRenderSVGRoot::nodeAtPoint):

b9e049c

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-cmake-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ⏳ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 api-mac-cmake-debug
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 ios-safer-cpp ✅ 🧪 mac-cmake-debug-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 loading 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim
✅ 🛠 watch
✅ 🛠 watch-sim

…radius

https://bugs.webkit.org/show_bug.cgi?id=328841
rdar://190954429

An outermost <svg> with border-radius is painted with rounded corners,
but elementFromPoint() returns the <svg> for points in the cut-off
corners. A <div> with the same size and border-radius returns its
parent there. Chrome and Firefox return the parent for both.

CSS Backgrounds says event handling follows the curves:

    other effects that clip painting or event handling to the border,
    padding, or content edge must clip to their respective curves. For
    example, [...] pointer events to the curved border edge, etc.

https://drafts.csswg.org/css-backgrounds-3/#corner-clipping

RenderBox::nodeAtPoint() and RenderBlock::nodeAtPoint() both call
hitTestBorderRadius() before they record a hit on their own background.
Both SVG root renderers replace nodeAtPoint() and only checked that the
point is inside the border box rectangle.

Add the same hitTestBorderRadius() check to the step that reports a hit
on the <svg> element itself, in LegacyRenderSVGRoot and in
RenderSVGRoot. SVG children are still tested first and are not affected
by the root's border-radius, which matches what a <div> does.

Test: imported/w3c/web-platform-tests/svg/interact/scripted/svg-root-border-radius.html

* LayoutTests/imported/w3c/web-platform-tests/svg/interact/scripted/svg-root-border-radius-expected.txt:
* Source/WebCore/rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::nodeAtPoint):
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGRoot.cpp:
(WebCore::LegacyRenderSVGRoot::nodeAtPoint):
@karlcow karlcow self-assigned this Oct 25, 2026
@karlcow karlcow added the SVG For bugs in the SVG implementation. label Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SVG For bugs in the SVG implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants