Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 2f7f2a11688698603f8ef12421efd6e3ace72685
https://github.com/WebKit/WebKit/commit/2f7f2a11688698603f8ef12421efd6e3ace72685
Author: Ahmad Saleem <[email protected]>
Date: 2026-01-01 (Thu, 01 Jan 2026)
Changed paths:
A LayoutTests/svg/as-image/svg-image-aspect-ration-par-none-expected.html
A LayoutTests/svg/as-image/svg-image-aspect-ration-par-none.html
M Source/WebCore/svg/SVGSVGElement.cpp
Log Message:
-----------
Synthesize preserveAspectRatio='none' for SVGs embedded in <img> without
viewBox
https://bugs.webkit.org/show_bug.cgi?id=304669
rdar://167121931
Reviewed by Nikolas Zimmermann.
When an SVG is embedded through SVGImage (e.g., in an <img> tag) and has
fixed width/height attributes but no explicit viewBox, WebKit synthesizes
a viewBox matching the SVG's intrinsic dimensions. However, this alone
causes the SVG to preserve its aspect ratio and center within the <img>
container, which differs from Chrome and Firefox behavior.
Chrome and Firefox stretch the SVG to fill the container dimensions in
these cases, matching the behavior of raster images. To align with this
behavior and meet author expectations, we now also synthesize
preserveAspectRatio='none' when a viewBox is synthesized for an embedded
SVG. This allows the SVG content to stretch to fill the <img> container,
consistent with other browsers and the expected behavior for replaced
elements.
* Source/WebCore/svg/SVGSVGElement.cpp:
(WebCore::isEmbeddedThroughSVGImage):
(WebCore::SVGSVGElement::currentViewBoxRect const):
(WebCore::SVGSVGElement::viewBoxToViewTransform const):
* LayoutTests/svg/as-image/svg-image-aspect-ration-par-none.html: Added.
* LayoutTests/svg/as-image/svg-image-aspect-ration-par-none-expected.html:
Added.
Canonical link: https://commits.webkit.org/305043@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications