Skip to content

LibWeb: Respect CSS values for more SVG elements - #11067

Merged
gmta merged 6 commits into
LadybirdBrowser:masterfrom
Calme1709:respect-css-properties-for-svg
Aug 10, 2026
Merged

LibWeb: Respect CSS values for more SVG elements#11067
gmta merged 6 commits into
LadybirdBrowser:masterfrom
Calme1709:respect-css-properties-for-svg

Conversation

@Calme1709

Copy link
Copy Markdown
Member

This fixes a few cases where previously we used attribute values directly, ignoring values set via CSS. We now use the values produced by the CSS cascade (which includes the attribute values as presentational hints).

See individual commits for details.

Previously we used attribute values directly, ignoring values set via
CSS.

We now use the values produced by the CSS cascade (which includes the
attribute values as presentational hints).
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 93056753-df5f-4d8b-bdba-71d4e8e0a906

📥 Commits

Reviewing files that changed from the base of the PR and between f3b48ae and cbf8934.

📒 Files selected for processing (2)
  • Libraries/LibWeb/SVG/SVGRectElement.cpp
  • Libraries/LibWeb/SVG/SVGRectElement.h
🚧 Files skipped from review as they are similar to previous changes (2)
  • Libraries/LibWeb/SVG/SVGRectElement.h
  • Libraries/LibWeb/SVG/SVGRectElement.cpp

📝 Walkthrough

Walkthrough

SVG ellipse and rectangle geometry now uses computed CSS values. The implementation resolves viewport-relative lengths, auto radii, percentages, and radius clamping. SVG images use computed positions and CSS default sizing with intrinsic image data. SVG <use> elements resolve computed x and y values before translation. Tests cover dynamic ellipse geometry, image intrinsic sizing, computed geometry, bounding boxes, and <use> positioning.

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description directly explains the SVG changes to use CSS-cascaded values instead of reading presentation attributes directly.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Libraries/LibWeb/SVG/SVGRectElement.cpp`:
- Around line 114-134: Update the rx/ry percentage conversions in the
SVGRectElement radius calculation to resolve rx against used_width and ry
against used_height in all three auto/non-auto branches before clamping. Add a
regression test using percentage radii where the used rectangle dimensions
differ from the viewport, verifying the radii use the rectangle dimensions
rather than viewport-relative values.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b2e229f6-e457-4f51-9ee7-21056c391fcb

📥 Commits

Reviewing files that changed from the base of the PR and between efb6f45 and f3b48ae.

⛔ Files ignored due to path filters (5)
  • Tests/LibWeb/Ref/expected/wpt-import/svg/geometry/reftests/ellipse-ref.svg is excluded by !**/*.svg
  • Tests/LibWeb/Ref/input/wpt-import/css/css-images/support/colors-16x8.svg is excluded by !**/*.svg
  • Tests/LibWeb/Ref/input/wpt-import/svg/geometry/reftests/ellipse-001.svg is excluded by !**/*.svg
  • Tests/LibWeb/Text/input/wpt-import/svg/geometry/parsing/height-computed.svg is excluded by !**/*.svg
  • Tests/LibWeb/Text/input/wpt-import/svg/geometry/parsing/width-computed.svg is excluded by !**/*.svg
📒 Files selected for processing (23)
  • Libraries/LibWeb/SVG/SVGEllipseElement.cpp
  • Libraries/LibWeb/SVG/SVGEllipseElement.h
  • Libraries/LibWeb/SVG/SVGImageElement.cpp
  • Libraries/LibWeb/SVG/SVGImageElement.h
  • Libraries/LibWeb/SVG/SVGRectElement.cpp
  • Libraries/LibWeb/SVG/SVGRectElement.h
  • Libraries/LibWeb/SVG/SVGUseElement.cpp
  • Libraries/LibWeb/SVG/SVGUseElement.h
  • Tests/LibWeb/Layout/expected/svg/rect-percentages.txt
  • Tests/LibWeb/Ref/expected/wpt-import/css/css-images/object-position-svg-001-ref.html
  • Tests/LibWeb/Ref/expected/wpt-import/svg/geometry/reftests/ellipse-calc-dynamic-viewport-ref.html
  • Tests/LibWeb/Ref/expected/wpt-import/svg/shapes/reftests/ellipse-auto-rx-textpath-ref.html
  • Tests/LibWeb/Ref/input/wpt-import/css/css-images/object-position-svg-001o.html
  • Tests/LibWeb/Ref/input/wpt-import/svg/geometry/reftests/ellipse-calc-dynamic-viewport.html
  • Tests/LibWeb/Ref/input/wpt-import/svg/shapes/reftests/ellipse-auto-rx-textpath.html
  • Tests/LibWeb/Text/expected/SVG/use-element-css-x-y.txt
  • Tests/LibWeb/Text/expected/wpt-import/svg/geometry/parsing/height-computed.txt
  • Tests/LibWeb/Text/expected/wpt-import/svg/geometry/parsing/width-computed.txt
  • Tests/LibWeb/Text/expected/wpt-import/svg/geometry/svg-image-intrinsic-size-with-cssstyle-auto.txt
  • Tests/LibWeb/Text/expected/wpt-import/svg/types/scripted/SVGGraphicsElement.getBBox-08.txt
  • Tests/LibWeb/Text/input/SVG/use-element-css-x-y.html
  • Tests/LibWeb/Text/input/wpt-import/svg/geometry/svg-image-intrinsic-size-with-cssstyle-auto.html
  • Tests/LibWeb/Text/input/wpt-import/svg/types/scripted/SVGGraphicsElement.getBBox-08.html
💤 Files with no reviewable changes (5)
  • Tests/LibWeb/Ref/expected/wpt-import/css/css-images/object-position-svg-001-ref.html
  • Libraries/LibWeb/SVG/SVGUseElement.h
  • Libraries/LibWeb/SVG/SVGEllipseElement.h
  • Tests/LibWeb/Ref/input/wpt-import/css/css-images/object-position-svg-001o.html
  • Libraries/LibWeb/SVG/SVGImageElement.h

Comment thread Libraries/LibWeb/SVG/SVGRectElement.cpp Outdated
Previously we used attribute values directly, ignoring values set via
CSS.

We now use the values produced by the CSS cascade (which includes the
attribute values as presentational hints) and implement the updated
algorithm to determine used corner radii values.

This change revealed a false positive SVG object-position test which has
been removed from tree.

This change causes a regression in `rect-percentages.html` since we now
round to CSSPixels prematurely (i.e. while still in SVG user space),
this is covered by a FIXME for now since it's a larger issue than just
this element.
This matches the behavior described by the spec - we also now use the
correct 300x150 size when we have an image without a natural size.
Previously we used attribute values directly, ignoring values set via
CSS.

We now use the values produced by the CSS cascade (which includes the
attribute values as presentational hints).
Previously we used attribute values directly, ignoring values set via
CSS.

We now use the values produced by the CSS cascade (which includes the
attribute values as presentational hints).
@Calme1709
Calme1709 force-pushed the respect-css-properties-for-svg branch from f3b48ae to cbf8934 Compare August 10, 2026 05:20
@gmta
gmta enabled auto-merge (rebase) August 10, 2026 06:50
@gmta
gmta merged commit 7ed6f96 into LadybirdBrowser:master Aug 10, 2026
25 of 29 checks passed
@Calme1709
Calme1709 deleted the respect-css-properties-for-svg branch August 10, 2026 09:52
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.

2 participants