Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 348ac9f493b2119efabc54d7f02eefbb6fc6b4c8
      
https://github.com/WebKit/WebKit/commit/348ac9f493b2119efabc54d7f02eefbb6fc6b4c8
  Author: Sammy Gill <[email protected]>
  Date:   2025-05-16 (Fri, 16 May 2025)

  Changed paths:
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-contain/contain-inline-size-grid-auto-fit-expected.html
    A 
LayoutTests/imported/w3c/web-platform-tests/css/css-contain/contain-inline-size-grid-auto-fit.html
    M Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp
    M Source/WebCore/rendering/RenderGrid.cpp
    M Source/WebCore/rendering/RenderGrid.h

  Log Message:
  -----------
  [Grid][Containment] Grid with inline-size containment and auto-fit columns is 
incorrectly sized.
https://bugs.webkit.org/show_bug.cgi?id=256047
rdar://problem/108897961

Reviewed by Alan Baradlay.

css-contain states that laying out a size containment box and its
contents is done in two phases:
Accorind to the css-contain spec, laying out a size containment box and
its contents is done in two phases:
1.) Sizing the size containment box as if it was empty
2.) Laying out its contents using the fixed size computed from 1
https://www.w3.org/TR/css-contain-2/#containment-size

In grid this seems to be currently implemented by interleaving size
containment logic with the rest of normal flow grid layout. In other
words, we will check to see if size containment is applied at various
points during grid layout and slightly switch up or add some new logic
if it is.

This seems like it can be a bit problematic with certain types of
content such as a grid with inline-size containment and auto-fit
columns. This is because in that case we will create and hold onto an
empty set of tracks during grid item placement. In normal circumstances,
one reason these would be created is for auto-fit tracks without any
grid items in them as they are supposed to get collapsed to 0. We seem
to do this in order to trick grid layout to collapse any auto-fit tracks
in order to achieve the "sizing as if empty," effect but fail to recover
for normal flow grid layout.

Consider the following test case:
<style>
.grid {
  contain: inline-size;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  border: 1px solid blue;
}
.grid-item {
  border: 3px solid red;
}
</style>
<div class="grid">
  <div class="grid-item">
    This box should fill the container column width
  </div>
</div>

Currently what will happen is that we collapse all of the tracks since
they are auto-fit tracks and inline-size containment is being applied on
the box. This results in a grid size of 0 which for "sizing as if empty," is ok
since that is the indicated behavior. However, since we tricked grid
layout into this state by creating an empty track list we fail to
recover during normal flow grid layout code.

In this patch I change our behavior to help us compute the correct
geometry in these cases in two ways:

1.) Stop creating and setting empty tracks during item placement in the
presence of size containment.
  - Doing this has implications for the rest of grid layout and is
    hard/error prone to recover from.
2.) Instead check for size containment when sizes of the grid that are
based off the track sizes (computeGridContainerIntrinsicSizes and
computeTrackBasedSizes) and filter out the auto-fit tracks.
  - The former is used during intrinsic logical width computation and
    the latter is used when computing the content/track based logical
    height of the grid. It seems like these are the places instead we
    should be checking if size containment is applied and computing a
    slightly different value.

In the context of the test case above this would mean we perform grid
layout as normal, but when we get to computeGridContainerIntrinsicSizes
we slightly adjust our logic to return the correct intrinsic sizes for
size containment. Instead of triggering the track collapsing logic as
before we will simply filter out the auto-fit tracks when computing the
sum of the track sizes which has the same effect.

(WebCore::GridTrackSizingAlgorithm::computeTrackBasedSize const):
Here we simply filter out the auto-fit tracks and provide the
potentially modified vector of tracks to accumulate over. This
is needed in order to properly consider the correct number of gaps
as the gaps associated with collapsed auto-fit tracks also collapse to
0.

(WebCore::GridTrackSizingAlgorithm::computeGridContainerIntrinsicSizes):
Instead of filtering out the auto-fit tracks like above we need to just
skip over them. This is so that we properly call setGrowthLimitCap on
the track that is held onto by GridTrackSizingAlgorithm.

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



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to