Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: b731ae0556bec576a391297ea4f90f1d0c8b5633
      
https://github.com/WebKit/WebKit/commit/b731ae0556bec576a391297ea4f90f1d0c8b5633
  Author: Sammy Gill <[email protected]>
  Date:   2026-10-05 (Mon, 05 Oct 2026)

  Changed paths:
    M Source/WebCore/layout/formattingContexts/grid/GridLayout.cpp
    M Source/WebCore/layout/formattingContexts/grid/GridLayoutUtils.cpp
    M Source/WebCore/layout/formattingContexts/grid/GridLayoutUtils.h

  Log Message:
  -----------
  [GFC] Add initial aspect-ratio sizing of grid items.
https://bugs.webkit.org/show_bug.cgi?id=325328
rdar://problem/188436006

Reviewed by Alan Baradlay.

This is the first step towards supporting grid items with a preferred aspect 
ratio in GFC.
It implements the logic needed to compute the automatic size of these
types of grid items as the final step of grid layout.

Most of the logic related to aspect-ratio comes from the following
portion of the spec which is what this code implements:
https://www.w3.org/TR/css-sizing-4/#ratios

Specifically what we implement is:

- Determining which axis is the ratio-determining axis
- Computing the automatic size for the item from the ratio-determining
  axis. For example, for an item with an aspect-ratio, fixed width, and auto
  height we detect that we need to compute the height from the width and
  aspect-ratio.
- For any min/max sizes that are not definite we will also consider
  any of the min/max sizes from the opposite axis (min/max size
  transfers)

One thing to note about this implementation is that since this occurs
after track sizing has completed this means that the grid area is known
and percentages/calc are considered definite. However, aspect-ratio will
also have an effect during track sizing (e.g. applying the automatic
minimum size) in which case the grid area is not known and
percentages/calc will be indefinite. We will implement this in a
separate patch as a follow up from this.

* Source/WebCore/layout/formattingContexts/grid/GridLayout.cpp:
(WebCore::Layout::GridLayout::layoutGridItems const):
When not considering the aspect ratio computing the used inline and
block sizes are fairly straightforward and we can do them independently.
aspect-ratio complicates this slightly, however, since computing a size
in one dimension is now dependent on the other. Instead of complicating
the existing code and trying to shoehorn the logic into the two
codepaths we will check to see if we are going to use the aspect-ratio
to compute the size of the grid item in which we then go through a new
dedicated path.

* Source/WebCore/layout/formattingContexts/grid/GridLayoutUtils.cpp:
(WebCore::Layout::GridLayoutUtils::blockSizeFromAspectRatio):
(WebCore::Layout::GridLayoutUtils::inlineSizeFromAspectRatio):
The very basic helper functions to compute the size from the aspect
ratio.

(WebCore::Layout::GridLayoutUtils::hasAutomaticSizeDuringItemSizing):
(WebCore::Layout::GridLayoutUtils::sizeDependsOnAspectRatio):
Figure out if we are going to need to use the aspect ratio to size an
item.

(WebCore::Layout::GridLayoutUtils::isDefiniteMinimumSizeDuringItemSizing):
(WebCore::Layout::GridLayoutUtils::isDefiniteMaximumSizeDuringItemSizing):
Used when applying the transfers. These are only for the final item
sizing, where the grid area is known so percentages and calc are
resolvable. When we extend this for track sizing we will add separate
functions that take in the grid area size in the relevant axis, since
it is only known for the axis that has already been sized.

(WebCore::Layout::GridLayoutUtils::needsTransferredBlockMinimumSize):
(WebCore::Layout::GridLayoutUtils::needsTransferredBlockMaximumSize):
(WebCore::Layout::GridLayoutUtils::needsTransferredInlineMinimumSize):
(WebCore::Layout::GridLayoutUtils::needsTransferredInlineMaximumSize):
(WebCore::Layout::GridLayoutUtils::transferredBlockMinimumSize):
(WebCore::Layout::GridLayoutUtils::transferredBlockMaximumSize):
(WebCore::Layout::GridLayoutUtils::transferredInlineMinimumSize):
(WebCore::Layout::GridLayoutUtils::transferredInlineMaximumSize):
(WebCore::Layout::GridLayoutUtils::blockMinimumSizeForAspectRatio):
(WebCore::Layout::GridLayoutUtils::blockMaximumSizeForAspectRatio):
(WebCore::Layout::GridLayoutUtils::inlineMinimumSizeForAspectRatio):
(WebCore::Layout::GridLayoutUtils::inlineMaximumSizeForAspectRatio):
(WebCore::Layout::GridLayoutUtils::ratioDeterminingAxis):
(WebCore::Layout::GridLayoutUtils::preferredSizesForAspectRatio):
All of the basic building block helper functions to implement each part
of the process described in the spec in some hopefully well contained
functions.

(WebCore::Layout::GridLayoutUtils::usedSizesForAspectRatioItem):
Aforementioned dedicated path that will be used to compute the used
inline and block sizes with the help of the aspect ratio.

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



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

Reply via email to