Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2025cb32576ca2b653e30d66744c3861cab4bc19
      
https://github.com/WebKit/WebKit/commit/2025cb32576ca2b653e30d66744c3861cab4bc19
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-08-04 (Tue, 04 Aug 2026)

  Changed paths:
    M 
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-image-intrinsic-size-with-cssstyle-auto-expected.txt
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/rendering/svg/RenderSVGImage.cpp
    A Source/WebCore/rendering/svg/SVGImageIntrinsicSizing.cpp
    A Source/WebCore/rendering/svg/SVGImageIntrinsicSizing.h
    M Source/WebCore/rendering/svg/legacy/LegacyRenderSVGImage.cpp

  Log Message:
  -----------
  <svg:image> 'auto' sizing should follow the CSS default sizing algorithm
https://bugs.webkit.org/show_bug.cgi?id=194815
rdar://122586485

Reviewed by Nikolas Zimmermann.

This patch aligns WebKit with Gecko / Firefox and Blink / Chromium.

Per SVG 2 §12.2 "Placement of the embedded content"
(https://w3c.github.io/svgwg/svg2-draft/embedded.html#Placement):

    "The 'auto' value for width or height is used to size the
     corresponding element automatically based on the intrinsic
     dimensions or intrinsic aspect ratio of the referenced
     resource. Computation of automatically-sized values follows
     the Default Sizing Algorithm defined for replaced elements in
     CSS layout [css-images-3]. In particular, when the referenced
     resource does not have an intrinsic size (such as image types
     with no defined dimensions), it is assumed to have a width of
     300px and a height of 150px."

The default sizing algorithm itself is defined in CSS Images Level 3 §4.3.1
(https://www.w3.org/TR/css-images-3/#default-sizing-algorithm).

calculateObjectBoundingBox() previously used the value returned by
CachedImage::imageSizeForRenderer() as both the intrinsic size and
the intrinsic ratio. For SVG sources this conflated three distinct
cases:

    * An SVG with only a viewBox (no intrinsic width/height) reported
      the viewBox size as if it were intrinsic, so 'width:auto;
      height:auto' returned the viewBox dimensions instead of fitting
      the intrinsic ratio into the 300x150 default object size.
    * An SVG with one intrinsic dimension plus a viewBox returned the
      viewBox size, ignoring the intrinsic dimension that should have
      been preserved while the missing dimension is derived from the
      ratio.
    * An empty SVG (no intrinsic dimensions and no viewBox) fell back
      to 300x150 inside imageSizeForRenderer, but the surrounding
      logic then treated that fallback as a real 2:1 intrinsic ratio
      when one CSS axis was 'auto'.

Add SVGImageIntrinsicSizing.h, a helper shared by the LBSE and legacy
SVG image renderers, which both previously carried identical copies of
this computation. resolveSVGImageIntrinsicSizing() queries
CachedImage::computeIntrinsicDimensions() for SVG sources and applies
the CSS Images Level 3 §4.3.1 default sizing algorithm with a 300x150
default object size, returning an SVGImageIntrinsicSizing struct: a
concrete intrinsic size, the intrinsic ratio, and a HasRatio enum.
HasRatio distinguishes a real aspect ratio from the 300x150 fallback,
which callers need because resolving 'auto' against a fallback ratio
yields the wrong size. When both intrinsic dimensions exist, the
intrinsic ratio is taken from those dimensions (per spec), so the
viewBox-derived ratio cannot override the intrinsic w/h ratio for SVGs
that declare width, height, and viewBox.

calculateSVGImageObjectBoundingBox() resolves the concrete width and
height from the CSS 'width' / 'height' computed values against that
sizing, keying its ratio branches off HasRatio rather than an emptiness
check, so the 300x150 default-object-size fallback no longer poses as an
aspect ratio. Both RenderSVGImage::calculateObjectBoundingBox() and
LegacyRenderSVGImage::calculateObjectBoundingBox() now just delegate to
it.

Non-SVG (raster) sources are unaffected: the helper returns
imageSizeForRenderer() for them, matching the previous behavior.

* 
LayoutTests/imported/w3c/web-platform-tests/svg/geometry/svg-image-intrinsic-size-with-cssstyle-auto-expected.txt:
 Progressions
* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:
* Source/WebCore/rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::calculateObjectBoundingBox const):
* Source/WebCore/rendering/svg/SVGImageIntrinsicSizing.cpp: Added.
(WebCore::resolveSVGImageIntrinsicSizing):
(WebCore::calculateSVGImageObjectBoundingBox):
* Source/WebCore/rendering/svg/SVGImageIntrinsicSizing.h: Added.
* Source/WebCore/rendering/svg/legacy/LegacyRenderSVGImage.cpp:
(WebCore::LegacyRenderSVGImage::calculateObjectBoundingBox const):

Canonical link: https://commits.webkit.org/318548@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to