Title: [292465] trunk
Revision
292465
Author
za...@apple.com
Date
2022-04-06 08:02:01 -0700 (Wed, 06 Apr 2022)

Log Message

[CSS-Contain] Grid layout should take "contain: inline-size" into account when computing the grid item's logical width
https://bugs.webkit.org/show_bug.cgi?id=238850

Reviewed by Antti Koivisto.

Source/WebCore:

Ignore grid item's logical width when "contain: inline-size" is present (i.e. ignore descendant content in inline direction when sizing).

* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::GridTrackSizingAlgorithm::computeGridContainerIntrinsicSizes):
(WebCore::GridTrackSizingAlgorithmStrategy::minContentForChild const):
(WebCore::GridTrackSizingAlgorithmStrategy::maxContentForChild const):
(WebCore::GridTrackSizingAlgorithmStrategy::minSizeForChild const):
(WebCore::GridTrackSizingAlgorithmStrategy::minLogicalSizeForChild const):
(WebCore::GridTrackSizingAlgorithm::advanceNextState):
* rendering/GridTrackSizingAlgorithm.h:
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::computeEmptyTracksForAutoRepeat const):

LayoutTests:

* TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (292464 => 292465)


--- trunk/LayoutTests/ChangeLog	2022-04-06 14:33:22 UTC (rev 292464)
+++ trunk/LayoutTests/ChangeLog	2022-04-06 15:02:01 UTC (rev 292465)
@@ -1,3 +1,12 @@
+2022-04-06  Alan Bujtas  <za...@apple.com>
+
+        [CSS-Contain] Grid layout should take "contain: inline-size" into account when computing the grid item's logical width
+        https://bugs.webkit.org/show_bug.cgi?id=238850
+
+        Reviewed by Antti Koivisto.
+
+        * TestExpectations:
+
 2022-04-06  Oriol Brufau  <obru...@igalia.com>
 
         [css] Turn -webkit-text-orientation into a legacy shorthand

Modified: trunk/LayoutTests/TestExpectations (292464 => 292465)


--- trunk/LayoutTests/TestExpectations	2022-04-06 14:33:22 UTC (rev 292464)
+++ trunk/LayoutTests/TestExpectations	2022-04-06 15:02:01 UTC (rev 292465)
@@ -4640,7 +4640,6 @@
 
 # CSS containment tests that fail
 imported/w3c/web-platform-tests/css/css-contain/contain-inline-size-bfc-floats-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-contain/contain-inline-size-grid.html [ ImageOnlyFailure ]
 # webkit-ruby-text
 imported/w3c/web-platform-tests/css/css-contain/contain-layout-017.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-contain/contain-paint-021.html [ ImageOnlyFailure ]

Modified: trunk/Source/WebCore/ChangeLog (292464 => 292465)


--- trunk/Source/WebCore/ChangeLog	2022-04-06 14:33:22 UTC (rev 292464)
+++ trunk/Source/WebCore/ChangeLog	2022-04-06 15:02:01 UTC (rev 292465)
@@ -1,3 +1,24 @@
+2022-04-06  Alan Bujtas  <za...@apple.com>
+
+        [CSS-Contain] Grid layout should take "contain: inline-size" into account when computing the grid item's logical width
+        https://bugs.webkit.org/show_bug.cgi?id=238850
+
+        Reviewed by Antti Koivisto.
+
+        Ignore grid item's logical width when "contain: inline-size" is present (i.e. ignore descendant content in inline direction when sizing).
+
+        * rendering/GridTrackSizingAlgorithm.cpp:
+        (WebCore::GridTrackSizingAlgorithm::computeGridContainerIntrinsicSizes):
+        (WebCore::GridTrackSizingAlgorithmStrategy::minContentForChild const):
+        (WebCore::GridTrackSizingAlgorithmStrategy::maxContentForChild const):
+        (WebCore::GridTrackSizingAlgorithmStrategy::minSizeForChild const):
+        (WebCore::GridTrackSizingAlgorithmStrategy::minLogicalSizeForChild const):
+        (WebCore::GridTrackSizingAlgorithm::advanceNextState):
+        * rendering/GridTrackSizingAlgorithm.h:
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::layoutBlock):
+        (WebCore::RenderGrid::computeEmptyTracksForAutoRepeat const):
+
 2022-04-06  Oriol Brufau  <obru...@igalia.com>
 
         [css] Turn -webkit-text-orientation into a legacy shorthand

Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (292464 => 292465)


--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp	2022-04-06 14:33:22 UTC (rev 292464)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp	2022-04-06 15:02:01 UTC (rev 292465)
@@ -783,7 +783,7 @@
 
     Vector<GridTrack>& allTracks = tracks(m_direction);
     for (auto& track : allTracks) {
-        ASSERT(m_strategy->isComputingSizeContainment() || !track.infiniteGrowthPotential());
+        ASSERT(m_strategy->isComputingSizeContainment() || m_strategy->isComputingInlineSizeContainment() || !track.infiniteGrowthPotential());
         m_minContentSize += track.baseSize();
         m_maxContentSize += track.growthLimitIsInfinite() ? track.baseSize() : track.growthLimit();
         // The growth limit caps must be cleared now in order to properly sort
@@ -815,6 +815,8 @@
 {
     GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
     if (direction() == childInlineDirection) {
+        if (isComputingInlineSizeContainment())
+            return { };
         // FIXME: It's unclear if we should return the intrinsic width or the preferred width.
         // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
         if (child.needsPreferredWidthsRecalculation())
@@ -838,6 +840,8 @@
 {
     GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
     if (direction() == childInlineDirection) {
+        if (isComputingInlineSizeContainment())
+            return { };
         // FIXME: It's unclear if we should return the intrinsic width or the preferred width.
         // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
         if (child.needsPreferredWidthsRecalculation())
@@ -854,6 +858,8 @@
 {
     GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
     bool isRowAxis = direction() == childInlineDirection;
+    if (isRowAxis && isComputingInlineSizeContainment())
+        return { };
     const Length& childSize = isRowAxis ? child.style().logicalWidth() : child.style().logicalHeight();
     if (!childSize.isAuto() && !childSize.isPercentOrCalculated())
         return minContentForChild(child);
@@ -1006,7 +1012,7 @@
     GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
     bool isRowAxis = direction() == childInlineDirection;
     if (isRowAxis)
-        return child.computeLogicalWidthInFragmentUsing(MinSize, childMinSize, availableSize.value_or(0), *renderGrid(), nullptr) + GridLayoutFunctions::marginLogicalSizeForChild(*renderGrid(), childInlineDirection, child);
+        return isComputingInlineSizeContainment() ? 0_lu : child.computeLogicalWidthInFragmentUsing(MinSize, childMinSize, availableSize.value_or(0), *renderGrid(), nullptr) + GridLayoutFunctions::marginLogicalSizeForChild(*renderGrid(), childInlineDirection, child);
     bool overrideSizeHasChanged = updateOverridingContainingBlockContentSizeForChild(child, childInlineDirection, availableSize);
     layoutGridItemForMinSizeComputation(child, overrideSizeHasChanged);
     GridTrackSizingDirection childBlockDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForRows);
@@ -1025,6 +1031,7 @@
     bool recomputeUsedFlexFractionIfNeeded(double& flexFraction, LayoutUnit& totalGrowth) const override;
     LayoutUnit freeSpaceForStretchAutoTracksStep() const override;
     bool isComputingSizeContainment() const override { return shouldApplySizeContainment(*renderGrid()); }
+    bool isComputingInlineSizeContainment() const override { return shouldApplyInlineSizeContainment(*renderGrid()); }
     void accumulateFlexFraction(double& flexFraction, GridIterator&, GridTrackSizingDirection outermostDirection, HashSet<RenderBox*>& itemsSet) const;
 };
 
@@ -1137,6 +1144,7 @@
     LayoutUnit minContentForChild(RenderBox&) const override;
     LayoutUnit minLogicalSizeForChild(RenderBox&, const Length& childMinSize, std::optional<LayoutUnit> availableSize) const override;
     bool isComputingSizeContainment() const override { return false; }
+    bool isComputingInlineSizeContainment() const override { return false; }
 };
 
 LayoutUnit IndefiniteSizeStrategy::freeSpaceForStretchAutoTracksStep() const
@@ -1410,7 +1418,7 @@
 {
     switch (m_sizingState) {
     case ColumnSizingFirstIteration:
-        m_sizingState = m_strategy->isComputingSizeContainment() ? ColumnSizingExtraIterationForSizeContainment : RowSizingFirstIteration;
+        m_sizingState = m_strategy->isComputingSizeContainment() || m_strategy->isComputingInlineSizeContainment() ? ColumnSizingExtraIterationForSizeContainment : RowSizingFirstIteration;
         return;
     case ColumnSizingExtraIterationForSizeContainment:
         m_sizingState = RowSizingFirstIteration;

Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h (292464 => 292465)


--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h	2022-04-06 14:33:22 UTC (rev 292464)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h	2022-04-06 15:02:01 UTC (rev 292465)
@@ -282,6 +282,7 @@
     virtual bool recomputeUsedFlexFractionIfNeeded(double& flexFraction, LayoutUnit& totalGrowth) const = 0;
     virtual LayoutUnit freeSpaceForStretchAutoTracksStep() const = 0;
     virtual bool isComputingSizeContainment() const = 0;
+    virtual bool isComputingInlineSizeContainment() const = 0;
 
 protected:
     GridTrackSizingAlgorithmStrategy(GridTrackSizingAlgorithm& algorithm)

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (292464 => 292465)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2022-04-06 14:33:22 UTC (rev 292464)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2022-04-06 15:02:01 UTC (rev 292465)
@@ -280,7 +280,8 @@
         // logical width is always definite as the above call to updateLogicalWidth() properly resolves intrinsic 
         // sizes. We cannot do the same for heights though because many code paths inside updateLogicalHeight() require 
         // a previous call to setLogicalHeight() to resolve heights properly (like for positioned items for example).
-        if (shouldApplySizeContainment(*this))
+        auto shouldIgnoreGridItemContentForLogicalWidth = shouldApplySizeContainment(*this) || shouldApplyInlineSizeContainment(*this);
+        if (shouldIgnoreGridItemContentForLogicalWidth)
             computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForColumns);
         else
             computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
@@ -287,7 +288,7 @@
 
         m_minContentSize = m_trackSizingAlgorithm.minContentSize();
         m_maxContentSize = m_trackSizingAlgorithm.maxContentSize();
-        if (shouldApplySizeContainment(*this))
+        if (shouldIgnoreGridItemContentForLogicalWidth)
             computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
 
         // 1.5- Compute Content Distribution offsets for column tracks
@@ -627,7 +628,7 @@
     unsigned firstAutoRepeatTrack = insertionPoint + grid.explicitGridStart(direction);
     unsigned lastAutoRepeatTrack = firstAutoRepeatTrack + grid.autoRepeatTracks(direction);
 
-    if (!grid.hasGridItems() || shouldApplySizeContainment(*this)) {
+    if (!grid.hasGridItems() || shouldApplySizeContainment(*this) || shouldApplyInlineSizeContainment(*this)) {
         emptyTrackIndexes = makeUnique<OrderedTrackIndexSet>();
         for (unsigned trackIndex = firstAutoRepeatTrack; trackIndex < lastAutoRepeatTrack; ++trackIndex)
             emptyTrackIndexes->add(trackIndex);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to