Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 854eb722df0f08bb9414096e480860dca2c8d77b
      
https://github.com/WebKit/WebKit/commit/854eb722df0f08bb9414096e480860dca2c8d77b
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-08-27 (Thu, 27 Aug 2026)

  Changed paths:
    M LayoutTests/TestExpectations
    M Source/WebCore/rendering/BackgroundPainter.cpp

  Log Message:
  -----------
  background-size: contain/cover and auto sizing ignore SVG images with one 
intrinsic dimension and no aspect ratio
https://bugs.webkit.org/show_bug.cgi?id=322705
rdar://185970333

Reviewed by Simon Fraser.

BackgroundPainter::calculateFillTileSize() did not correctly implement the
CSS default sizing algorithm for images that have exactly one intrinsic
dimension and no intrinsic aspect ratio, such as an SVG with a single
non-percent width/height and no viewBox.

Two problems:

1. contain/cover scaled the image by a single uniform factor, which is only
   correct when the image has a natural aspect ratio. The spec resolves both
   keywords against the constraint rectangle using the object's aspect ratio,
   but:

     "In both cases, if the object doesn't have a natural aspect ratio, the
      concrete object size is the specified constraint rectangle." [1]

   For a background the constraint rectangle is the background positioning
   area, so a ratio-less image fills the whole area. Because the missing
   dimension had already been substituted with the positioning-area size, the
   limiting scale factor collapsed to 1 and the tile kept its intrinsic (e.g.
   8px) width instead of filling the area.

2. When one background-size axis was auto and the other a definite length, the
   auto axis was only resolved through the aspect ratio. With no ratio it was
   left at the positioning-area size, ignoring the image's intrinsic length on
   that axis. The spec resolves the missing dimension as:

     "If the object has a natural aspect ratio, the missing dimension [...] is
      calculated using that aspect ratio and the present dimension.
      Otherwise, if the missing dimension is present in the object's natural
      dimensions, the missing dimension is taken from the object's natural
      dimensions.
      Otherwise, the missing dimension [...] is taken from the default object
      size." [2]

   The auto axis now falls back to the image's intrinsic dimension.
   calculateImageIntrinsicDimensions() already returns the natural dimension
   when present and otherwise substitutes the default object size (the
   positioning area), so the single fallback covers both "otherwise" clauses
   and preserves existing behavior for images with no natural length on that
   axis.

Covers the no-viewBox contain/cover and auto/length cases in the
css-backgrounds/background-size/vector WPT suite. The extreme-viewBox cover
cases remain a separate degenerate-ratio precision issue.

[1] https://drafts.csswg.org/css-images-3/#cover-contain
[2] https://drafts.csswg.org/css-images-3/#default-sizing

* LayoutTests/TestExpectations: Unskip now passing tests
* Source/WebCore/rendering/BackgroundPainter.cpp:
(WebCore::BackgroundPainter::calculateFillTileSize):

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



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

Reply via email to