Title: [290096] trunk
Revision
290096
Author
commit-qu...@webkit.org
Date
2022-02-17 16:54:41 -0800 (Thu, 17 Feb 2022)

Log Message

Account for subgrid MBP when sizing
https://bugs.webkit.org/show_bug.cgi?id=236338

Patch by Matt Woodrow <mattwood...@apple.com> on 2022-02-17
Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

* web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html:
* web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html:
* web-platform-tests/css/css-grid/subgrid/line-names-008.html:
* web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html:
* web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html:

Source/WebCore:

Adds extra margin to subgrid items participating in the sizing of an outer
grid's tracks to account for the margin/border/padding of the intermediate
subgrid item itself.
Also contributes the subgrid's m/b/p to the edge tracks it cover, even
if no inner items occupy that track.

* rendering/GridLayoutFunctions.cpp:
(WebCore::GridLayoutFunctions::directionFromSide):
(WebCore::GridLayoutFunctions::hasRelativeOrIntrinsicSizeForChild):
(WebCore::GridLayoutFunctions::extraMarginForSubgridChild):
(WebCore::GridLayoutFunctions::gapDifferenceForSubgridChild):
(WebCore::GridLayoutFunctions::marginLogicalSizeForChild):
* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::setOverridingContainingBlockContentSizeForChild):
(WebCore::GridTrackSizingAlgorithmStrategy::logicalHeightForChild const):
(WebCore::GridTrackSizingAlgorithmStrategy::updateOverridingContainingBlockContentSizeForChild const):
(WebCore::DefiniteSizeStrategy::minLogicalSizeForChild const):
(WebCore::DefiniteSizeStrategy::minContentForChild const):
(WebCore::addSubgridMarginBorderPadding):
(WebCore::GridTrackSizingAlgorithm::accumulateIntrinsicSizesForTrack):
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::isSubgrid const):
(WebCore::RenderGrid::mayBeSubgridExcludingAbsPos const):
(WebCore::RenderGrid::gridSpanCoversRealTracks const):
(WebCore::RenderGrid::gridAreaBreadthForOutOfFlowChild):
(WebCore::RenderGrid::computeContentPositionAndDistributionOffset):
(WebCore::RenderGrid::gridSpanForChild const):
* rendering/RenderGrid.h:
* rendering/style/GridPositionsResolver.cpp:
(WebCore::adjustGridPositionsFromStyle):

LayoutTests:

Account for subgrid MBP when sizing

* TestExpectations:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (290095 => 290096)


--- trunk/LayoutTests/ChangeLog	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/ChangeLog	2022-02-18 00:54:41 UTC (rev 290096)
@@ -1,5 +1,16 @@
 2022-02-17  Matt Woodrow  <mattwood...@apple.com>
 
+        Account for subgrid MBP when sizing
+        https://bugs.webkit.org/show_bug.cgi?id=236338
+
+        Reviewed by Dean Jackson.
+
+        Account for subgrid MBP when sizing
+
+        * TestExpectations:
+
+2022-02-17  Matt Woodrow  <mattwood...@apple.com>
+
         Include sub grid items in the track sizing algorithm of the outer grid
         https://bugs.webkit.org/show_bug.cgi?id=236337
 

Modified: trunk/LayoutTests/TestExpectations (290095 => 290096)


--- trunk/LayoutTests/TestExpectations	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/TestExpectations	2022-02-18 00:54:41 UTC (rev 290096)
@@ -1395,29 +1395,14 @@
 imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-subgrid-002.html [ ImageOnlyFailure ]
 
 imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-002.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-003.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-004.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-002.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-003.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-004.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-007.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-larger-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-larger-002.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-smaller-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/item-percentage-height-001.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-007.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-008.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-001.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-002.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-003.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/orthogonal-writing-mode-004.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/repeat-auto-fill-003.html [ ImageOnlyFailure ]
-imported/w3c/web-platform-tests/css/css-grid/subgrid/repeat-auto-fill-004.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-mbp-overflow-001.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-mbp-overflow-002.html [ ImageOnlyFailure ]
 imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-mbp-overflow-003.html [ ImageOnlyFailure ]

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (290095 => 290096)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2022-02-18 00:54:41 UTC (rev 290096)
@@ -1,3 +1,16 @@
+2022-02-17  Matt Woodrow  <mattwood...@apple.com>
+
+        Account for subgrid MBP when sizing
+        https://bugs.webkit.org/show_bug.cgi?id=236338
+
+        Reviewed by Dean Jackson.
+
+        * web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html:
+        * web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html:
+        * web-platform-tests/css/css-grid/subgrid/line-names-008.html:
+        * web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html:
+        * web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html:
+
 2022-02-17  Noam Rosenthal  <n...@webkit.org>
 
         Resync web-platform-tests/paint-timing from upstream

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html (290095 => 290096)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-002-expected.html	2022-02-18 00:54:41 UTC (rev 290096)
@@ -61,7 +61,7 @@
 <div class="grid">
 <i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
 <div class="subgrid">
-  <x style="grid-column:3; right:27px">x</x>
+  <x style="grid-column:3; right:33px">x</x>
 </div>
 </div>
 
@@ -117,7 +117,7 @@
 <div class="grid">
 <i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i><i></i>
 <div class="subgrid hr">
-  <x style="grid-column:auto/1; left:-27px">x</x>
+  <x style="grid-column:auto/1; left:-33px">x</x>
 </div>
 </div>
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html (290095 => 290096)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/abs-pos-003-expected.html	2022-02-18 00:54:41 UTC (rev 290096)
@@ -40,15 +40,6 @@
   background: purple;
 }
 
-.a > .t1 > x {
-  margin: -10px 0 0 -10px;
-}
-.a > .t2 > x,
-.c > .t2 > x,
-.c > .t1 > x {
-  margin: 0 0 0 -10px;
-}
-
 </style>
 </head>
 <body>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-008.html (290095 => 290096)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-008.html	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-008.html	2022-02-18 00:54:41 UTC (rev 290096)
@@ -146,7 +146,7 @@
   </div>
 </div>
 
-<div class="grid" style="grid-template-columns: repeat(3,30px) [a] 30px repeat(7,30px)">
+<div class="grid" style="grid-template-columns: 30px [a] repeat(2,30px) [a] 30px repeat(7,30px)">
 <n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n>
   <div class="hr" style="grid-template-columns: subgrid [] [] [] [] [a]; grid-column:2/span 6">
     <x style="grid-column: a/span a">x</x>
@@ -153,7 +153,7 @@
   </div>
 </div>
 
-<div class="grid" style="grid-template-columns: repeat(3,30px) [a] 30px repeat(7,30px)">
+<div class="grid" style="grid-template-columns: 30px [a] repeat(2,30px) [a] 30px repeat(7,30px)">
 <n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n><n></n>
   <div class="hr" style="grid-template-columns: subgrid [] [] [] [] [a]; grid-column:2/span 6">
     <x style="grid-column: a/a 2">x</x>

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html (290095 => 290096)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-001.html	2022-02-18 00:54:41 UTC (rev 290096)
@@ -435,8 +435,8 @@
 
 <script>
   const expectedResults = [
-    "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z]",
-    "[x y] 0px [z] 1px [z] 1px [z] 1px [z]",
+    "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z] 46px",
+    "[x y] 0px [z] 1px [z] 1px [z] 1px [z] 23.5px 23.5px",
     "[x] 1px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
     "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px [z] 1px [z]",
     "[x] 2px [x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 0px [z]",
@@ -454,15 +454,15 @@
     "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px [z]",
     "[x] 2px [x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 0px",
     "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
-    "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
-    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z]",
+    "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
+    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 18px",
     "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px",
-    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
-    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
-    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px",
-    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
-    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
-    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
+    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
+    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
+    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px 18px",
+    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
+    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
+    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
   ];
   [...document.querySelectorAll('.grid')].forEach(function(grid, i) {
     let actual = window.getComputedStyle(grid)['grid-template-columns'];

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html (290095 => 290096)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/parent-repeat-auto-fit-002.html	2022-02-18 00:54:41 UTC (rev 290096)
@@ -439,8 +439,8 @@
 
 <script>
   const expectedResults = [
-    "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z]",
-    "[x y] 0px [z] 1px [z] 1px [z] 1px [z]",
+    "[y] 0px [z] 1px [z] 1px [z] 1px [z] 1px [z] 46px",
+    "[x y] 0px [z] 1px [z] 1px [z] 1px [z] 23.5px 23.5px",
     "[x] 1px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
     "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px [z] 1px [z]",
     "[x] 2px [x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 0px [z]",
@@ -458,15 +458,15 @@
     "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px [z]",
     "[x] 2px [x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 0px",
     "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 1px [z]",
-    "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
-    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z]",
+    "[x y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
+    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px [z] 18px",
     "[x] 2px [x] 2px [x y] 10px [y] 10px [y] 10px [y] 10px",
-    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z]",
-    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
-    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px",
-    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z]",
-    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
-    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px",
+    "[y] 0px [y] 0px [y] 10px [y] 10px [z] 1px [z] 29px",
+    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
+    "[x] 2px [x y] 0px [y] 10px [y] 10px [y] 10px 18px",
+    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px [z] 20px",
+    "[x y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
+    "[y] 0px [y] 0px [y] 10px [y] 10px [y] 10px 20px",
   ];
   [...document.querySelectorAll('.grid')].forEach(function(grid, i) {
     let actual = window.getComputedStyle(grid)['grid-template-rows'];

Modified: trunk/Source/WebCore/ChangeLog (290095 => 290096)


--- trunk/Source/WebCore/ChangeLog	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/Source/WebCore/ChangeLog	2022-02-18 00:54:41 UTC (rev 290096)
@@ -1,3 +1,41 @@
+2022-02-17  Matt Woodrow  <mattwood...@apple.com>
+
+        Account for subgrid MBP when sizing
+        https://bugs.webkit.org/show_bug.cgi?id=236338
+
+        Reviewed by Dean Jackson.
+
+        Adds extra margin to subgrid items participating in the sizing of an outer
+        grid's tracks to account for the margin/border/padding of the intermediate
+        subgrid item itself.
+        Also contributes the subgrid's m/b/p to the edge tracks it cover, even
+        if no inner items occupy that track.
+
+        * rendering/GridLayoutFunctions.cpp:
+        (WebCore::GridLayoutFunctions::directionFromSide):
+        (WebCore::GridLayoutFunctions::hasRelativeOrIntrinsicSizeForChild):
+        (WebCore::GridLayoutFunctions::extraMarginForSubgridChild):
+        (WebCore::GridLayoutFunctions::gapDifferenceForSubgridChild):
+        (WebCore::GridLayoutFunctions::marginLogicalSizeForChild):
+        * rendering/GridTrackSizingAlgorithm.cpp:
+        (WebCore::setOverridingContainingBlockContentSizeForChild):
+        (WebCore::GridTrackSizingAlgorithmStrategy::logicalHeightForChild const):
+        (WebCore::GridTrackSizingAlgorithmStrategy::updateOverridingContainingBlockContentSizeForChild const):
+        (WebCore::DefiniteSizeStrategy::minLogicalSizeForChild const):
+        (WebCore::DefiniteSizeStrategy::minContentForChild const):
+        (WebCore::addSubgridMarginBorderPadding):
+        (WebCore::GridTrackSizingAlgorithm::accumulateIntrinsicSizesForTrack):
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::isSubgrid const):
+        (WebCore::RenderGrid::mayBeSubgridExcludingAbsPos const):
+        (WebCore::RenderGrid::gridSpanCoversRealTracks const):
+        (WebCore::RenderGrid::gridAreaBreadthForOutOfFlowChild):
+        (WebCore::RenderGrid::computeContentPositionAndDistributionOffset):
+        (WebCore::RenderGrid::gridSpanForChild const):
+        * rendering/RenderGrid.h:
+        * rendering/style/GridPositionsResolver.cpp:
+        (WebCore::adjustGridPositionsFromStyle):
+
 2022-02-17  J Pascoe  <j_pas...@apple.com>
 
         PDF.js viewer should work for all kinds of URLs

Modified: trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp (290095 => 290096)


--- trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp	2022-02-18 00:54:41 UTC (rev 290096)
@@ -66,15 +66,83 @@
     return marginStartIsAuto(child, flowAwareDirection) ? marginEnd : marginEndIsAuto(child, flowAwareDirection) ? marginStart : marginStart + marginEnd;
 }
 
+static inline GridTrackSizingDirection directionFromSide(GridPositionSide side)
+{
+    return side == ColumnStartSide || side == ColumnEndSide ? ForColumns : ForRows;
+}
+
+static bool hasRelativeOrIntrinsicSizeForChild(const RenderBox& child, GridTrackSizingDirection direction)
+{
+    if (direction == ForColumns)
+        return child.hasRelativeLogicalWidth() || child.style().logicalWidth().isIntrinsicOrAuto();
+    return child.hasRelativeLogicalHeight() || child.style().logicalHeight().isIntrinsicOrAuto();
+}
+
+static LayoutUnit extraMarginForSubgrid(const RenderGrid& parent, unsigned startLine, unsigned endLine, GridTrackSizingDirection direction)
+{
+    unsigned numTracks = parent.numTracks(direction);
+    if (!numTracks || !parent.isSubgrid(direction))
+        return 0_lu;
+
+    std::optional<LayoutUnit> availableSpace;
+    if (!hasRelativeOrIntrinsicSizeForChild(parent, direction))
+        availableSpace = parent.availableSpaceForGutters(direction);
+
+    RenderGrid& grandParent = downcast<RenderGrid>(*parent.parent());
+    LayoutUnit mbp;
+    if (!startLine)
+        mbp += (direction == ForColumns) ? parent.marginAndBorderAndPaddingStart() : parent.marginAndBorderAndPaddingBefore();
+    else
+        mbp += (parent.gridGap(direction, availableSpace) - grandParent.gridGap(direction)) / 2;
+
+    if (endLine == numTracks)
+        mbp += (direction == ForColumns) ? parent.marginAndBorderAndPaddingEnd() : parent.marginAndBorderAndPaddingAfter();
+    else
+        mbp += (parent.gridGap(direction, availableSpace) - grandParent.gridGap(direction)) / 2;
+
+    return mbp;
+}
+
+static LayoutUnit extraMarginForSubgridAncestors(GridTrackSizingDirection direction, const RenderBox& child)
+{
+    const RenderGrid* grid = downcast<RenderGrid>(child.parent());
+    LayoutUnit mbp;
+
+    while (grid->isSubgrid(direction)) {
+        GridSpan span = grid->gridSpanForChild(child, direction);
+
+        mbp += extraMarginForSubgrid(*grid, span.startLine(), span.endLine(), direction);
+
+        const RenderElement* parent = grid->parent();
+        if (!parent || !is<RenderGrid>(parent))
+            break;
+
+        const RenderGrid* parentGrid = downcast<RenderGrid>(parent);
+        direction = flowAwareDirectionForParent(*grid, *parentGrid, direction);
+
+        grid = parentGrid;
+    }
+
+    return mbp;
+}
+
 LayoutUnit marginLogicalSizeForChild(const RenderGrid& grid, GridTrackSizingDirection direction, const RenderBox& child)
 {
+    LayoutUnit margin;
     if (child.needsLayout())
-        return computeMarginLogicalSizeForChild(grid, direction, child);
-    GridTrackSizingDirection flowAwareDirection = flowAwareDirectionForChild(grid, child, direction);
-    bool isRowAxis = flowAwareDirection == ForColumns;
-    LayoutUnit marginStart = marginStartIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginStart() : child.marginBefore();
-    LayoutUnit marginEnd = marginEndIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginEnd() : child.marginAfter();
-    return marginStart + marginEnd;
+        margin = computeMarginLogicalSizeForChild(grid, direction, child);
+    else {
+        GridTrackSizingDirection flowAwareDirection = flowAwareDirectionForChild(grid, child, direction);
+        bool isRowAxis = flowAwareDirection == ForColumns;
+        LayoutUnit marginStart = marginStartIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginStart() : child.marginBefore();
+        LayoutUnit marginEnd = marginEndIsAuto(child, flowAwareDirection) ? 0_lu : isRowAxis ? child.marginEnd() : child.marginAfter();
+        margin = marginStart + marginEnd;
+    }
+
+    if (&grid != child.parent())
+        margin += extraMarginForSubgridAncestors(direction, child);
+
+    return margin;
 }
 
 bool isOrthogonalChild(const RenderGrid& grid, const RenderBox& child)

Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (290095 => 290096)


--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp	2022-02-18 00:54:41 UTC (rev 290096)
@@ -125,8 +125,13 @@
     return hasRelativeOrIntrinsicSizeForChild(child, direction) || hasRelativeMarginOrPaddingForChild(child, direction);
 }
 
-static void setOverridingContainingBlockContentSizeForChild(RenderBox& child, GridTrackSizingDirection direction, std::optional<LayoutUnit> size)
+static void setOverridingContainingBlockContentSizeForChild(const RenderGrid& grid, RenderBox& child, GridTrackSizingDirection direction, std::optional<LayoutUnit> size)
 {
+    // This function sets the dimension based on the writing mode of the containing block.
+    // For subgrids, this might not be the outermost grid, but could be a subgrid. If the
+    // writing mode of the CB and the grid for which we're doing sizing don't match, swap
+    // the directions.
+    direction = GridLayoutFunctions::flowAwareDirectionForChild(grid, *child.containingBlock(), direction);
     if (direction == ForColumns)
         child.setOverridingContainingBlockContentLogicalWidth(size);
     else
@@ -794,7 +799,7 @@
     // If |child| has a relative logical height, we shouldn't let it override its intrinsic height, which is
     // what we are interested in here. Thus we need to set the block-axis override size to nullopt (no possible resolution).
     if (shouldClearOverridingContainingBlockContentSizeForChild(child, ForRows)) {
-        setOverridingContainingBlockContentSizeForChild(child, childBlockDirection, std::nullopt);
+        setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, childBlockDirection, std::nullopt);
         child.setNeedsLayout(MarkOnlyThis);
     }
 
@@ -959,10 +964,11 @@
 {
     if (!overrideSize)
         overrideSize = m_algorithm.gridAreaBreadthForChild(child, direction);
+
     if (GridLayoutFunctions::hasOverridingContainingBlockContentSizeForChild(child, direction) && GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, direction) == overrideSize)
         return false;
 
-    setOverridingContainingBlockContentSizeForChild(child, direction, overrideSize);
+    setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, direction, overrideSize);
     return true;
 }
 
@@ -1122,7 +1128,7 @@
     GridTrackSizingDirection flowAwareDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, direction());
     if (hasRelativeMarginOrPaddingForChild(child, flowAwareDirection) || (direction() != childInlineDirection && hasRelativeOrIntrinsicSizeForChild(child, flowAwareDirection))) {
         auto indefiniteSize = direction() == childInlineDirection ? std::make_optional(0_lu) : std::nullopt;
-        setOverridingContainingBlockContentSizeForChild(child, direction(), indefiniteSize);
+        setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, direction(), indefiniteSize);
     }
     return GridTrackSizingAlgorithmStrategy::minLogicalSizeForChild(child, childMinSize, availableSize);
 }
@@ -1167,7 +1173,7 @@
 {
     GridTrackSizingDirection childInlineDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), child, ForColumns);
     if (direction() == childInlineDirection && child.needsLayout() && shouldClearOverridingContainingBlockContentSizeForChild(child, ForColumns))
-        setOverridingContainingBlockContentSizeForChild(child, childInlineDirection, LayoutUnit());
+        setOverridingContainingBlockContentSizeForChild(*renderGrid(), child, childInlineDirection, LayoutUnit());
     return GridTrackSizingAlgorithmStrategy::minContentForChild(child);
 }
 
@@ -1222,12 +1228,49 @@
     }
 }
 
+static LayoutUnit marginAndBorderAndPaddingForEdge(const RenderGrid& grid, GridTrackSizingDirection direction, bool startEdge)
+{
+    if (direction == ForColumns)
+        return startEdge ? grid.marginAndBorderAndPaddingStart() : grid.marginAndBorderAndPaddingEnd();
+    return startEdge ? grid.marginAndBorderAndPaddingBefore() : grid.marginAndBorderAndPaddingAfter();
+}
+
+// https://drafts.csswg.org/css-grid-2/#subgrid-edge-placeholders
+// FIXME: This is a simplification of the specified behaviour, where we add the hypothetical
+// items directly to the edge tracks as if they had a span of 1. This matches the current Gecko
+// behavior.
+static void addSubgridMarginBorderPadding(const RenderGrid* outermost, GridTrackSizingDirection outermostDirection, Vector<GridTrack>& allTracks, GridSpan& span, RenderGrid* subgrid)
+{
+    // Convert the direction into the coordinate space of subgrid (which may not be a direct child
+    // of the outermost grid for which we're running the track sizing algorithm).
+    GridTrackSizingDirection direction = GridLayoutFunctions::flowAwareDirectionForChild(*outermost, *subgrid, outermostDirection);
+    bool reversed = GridLayoutFunctions::isSubgridReversedDirection(*outermost, outermostDirection, *subgrid);
+
+    if (allTracks[span.startLine()].cachedTrackSize().hasIntrinsicMinTrackBreadth()) {
+        // If the subgrid has a reversed flow direction relative to the outermost grid, then
+        // we want the MBP from the end edge in its local coordinate space.
+        LayoutUnit mbpStart = marginAndBorderAndPaddingForEdge(*subgrid, direction, !reversed);
+        allTracks[span.startLine()].setBaseSize(std::max(allTracks[span.startLine()].baseSize(), mbpStart));
+    }
+    if (allTracks[span.endLine() - 1].cachedTrackSize().hasIntrinsicMinTrackBreadth()) {
+        LayoutUnit mbpEnd = marginAndBorderAndPaddingForEdge(*subgrid, direction, reversed);
+        allTracks[span.endLine() - 1].setBaseSize(std::max(allTracks[span.endLine() - 1].baseSize(), mbpEnd));
+    }
+}
+
 void GridTrackSizingAlgorithm::accumulateIntrinsicSizesForTrack(GridTrack& track, GridIterator& iterator, Vector<GridItemWithSpan>& itemsSortedByIncreasingSpan, Vector<GridItemWithSpan>& itemsCrossingFlexibleTracks, HashSet<RenderBox*>& itemsSet)
 {
+    Vector<GridTrack>& allTracks = tracks(m_direction);
+
     while (auto* gridItem = iterator.nextGridItem()) {
         bool isNewEntry = itemsSet.add(gridItem).isNewEntry;
         if (is<RenderGrid>(gridItem) && downcast<RenderGrid>(gridItem)->isSubgridInParentDirection(iterator.direction())) {
+            // Contribute the mbp of wrapper to the first and last tracks that we span.
             RenderGrid* inner = downcast<RenderGrid>(gridItem);
+            if (isNewEntry) {
+                GridSpan span = m_renderGrid->gridSpanForChild(*gridItem, m_direction);
+                addSubgridMarginBorderPadding(m_renderGrid, m_direction, allTracks, span, inner);
+            }
 
             GridIterator childIterator = GridIterator::createForSubgrid(*inner, iterator);
             accumulateIntrinsicSizesForTrack(track, childIterator, itemsSortedByIncreasingSpan, itemsCrossingFlexibleTracks, itemsSet);

Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (290095 => 290096)


--- trunk/Source/WebCore/rendering/RenderGrid.cpp	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp	2022-02-18 00:54:41 UTC (rev 290096)
@@ -1653,11 +1653,9 @@
 
 bool RenderGrid::isSubgrid(GridTrackSizingDirection direction) const
 {
-    if (isOutOfFlowPositioned() || isExcludedFromNormalLayout())
+    if (!mayBeSubgridExcludingAbsPos(direction))
         return false;
-    if ((direction == ForColumns) ? !style().gridSubgridColumns() : !style().gridSubgridRows())
-        return false;
-    return is<RenderGrid>(parent());
+    return downcast<RenderGrid>(parent())->gridSpanCoversRealTracks(*this, direction);
 }
 
 bool RenderGrid::isSubgridInParentDirection(GridTrackSizingDirection parentDirection) const
@@ -1668,6 +1666,18 @@
     return isSubgrid(direction);
 }
 
+bool RenderGrid::mayBeSubgridExcludingAbsPos(GridTrackSizingDirection direction) const
+{
+    // Should exclude cases where we establish an IFC, like contain layout.
+    if (isExcludedFromNormalLayout())
+        return false;
+    if (direction == ForColumns ? !style().gridSubgridColumns() : !style().gridSubgridRows())
+        return false;
+    if (!is<RenderGrid>(parent()))
+        return false;
+    return true;
+}
+
 LayoutUnit RenderGrid::gridAreaBreadthForOutOfFlowChild(const RenderBox& child, GridTrackSizingDirection direction)
 {
     ASSERT(child.isOutOfFlowPositioned());
@@ -1852,6 +1862,11 @@
     bool isRowAxis = direction == ForColumns;
     auto& offset =
         isRowAxis ? m_offsetBetweenColumns : m_offsetBetweenRows;
+    if (isRowAxis ? isSubgridColumns() : isSubgridRows()) {
+        offset.positionOffset = 0_lu;
+        offset.distributionOffset = 0_lu;
+        return;
+    }
     auto contentAlignmentData = contentAlignment(direction);
     auto position = contentAlignmentData.position();
     // If <content-distribution> value can't be applied, 'position' will become the associated
@@ -2095,4 +2110,26 @@
     return span;
 }
 
+bool RenderGrid::gridSpanCoversRealTracks(const RenderBox& child, GridTrackSizingDirection direction) const
+{
+    // Only out of flow positioned items can span to the special line that covers
+    // the padding area.
+    if (!child.isOutOfFlowPositioned())
+        return true;
+
+    int lastLine = numTracks(direction, m_grid);
+    int startLine, endLine;
+    bool startIsAuto, endIsAuto;
+    if (!computeGridPositionsForOutOfFlowChild(child, direction, startLine, startIsAuto, endLine, endIsAuto))
+        return lastLine > 0;
+
+    // If the resulting span covers only the padding area, then it's not a real
+    // track that could be used for a subgrid.
+    if (startIsAuto && !endLine)
+        return false;
+    if (endIsAuto && startLine == lastLine)
+        return false;
+    return true;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderGrid.h (290095 => 290096)


--- trunk/Source/WebCore/rendering/RenderGrid.h	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/Source/WebCore/rendering/RenderGrid.h	2022-02-18 00:54:41 UTC (rev 290096)
@@ -96,6 +96,7 @@
         return isSubgrid(ForColumns);
     }
     bool isSubgridInParentDirection(GridTrackSizingDirection parentDirection) const;
+    bool mayBeSubgridExcludingAbsPos(GridTrackSizingDirection) const;
 
     const Grid& currentGrid() const
     {
@@ -109,6 +110,10 @@
 
     void placeItems();
 
+    std::optional<LayoutUnit> availableSpaceForGutters(GridTrackSizingDirection) const;
+    LayoutUnit gridGap(GridTrackSizingDirection) const;
+    LayoutUnit gridGap(GridTrackSizingDirection, std::optional<LayoutUnit> availableSize) const;
+
 private:
     friend class GridTrackSizingAlgorithm;
 
@@ -125,8 +130,6 @@
     bool selfAlignmentChangedToStretch(GridAxis, const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderBox&) const;
     bool selfAlignmentChangedFromStretch(GridAxis, const RenderStyle& oldStyle, const RenderStyle& newStyle, const RenderBox&) const;
 
-    std::optional<LayoutUnit> availableSpaceForGutters(GridTrackSizingDirection) const;
-
     bool explicitGridDidResize(const RenderStyle&) const;
     bool namedGridLinesDefinitionDidChange(const RenderStyle&) const;
     bool implicitGridLinesDefinitionDidChange(const RenderStyle&) const;
@@ -206,9 +209,6 @@
     LayoutUnit columnAxisBaselineOffsetForChild(const RenderBox&) const;
     LayoutUnit rowAxisBaselineOffsetForChild(const RenderBox&) const;
 
-    LayoutUnit gridGap(GridTrackSizingDirection) const;
-    LayoutUnit gridGap(GridTrackSizingDirection, std::optional<LayoutUnit> availableSize) const;
-
     unsigned nonCollapsedTracks(GridTrackSizingDirection) const;
     unsigned numTracks(GridTrackSizingDirection, const Grid&) const;
 
@@ -222,7 +222,9 @@
     Vector<RenderBox*> computeAspectRatioDependentAndBaselineItems();
 
     GridSpan gridSpanForOutOfFlowChild(const RenderBox&, GridTrackSizingDirection) const;
+
     bool computeGridPositionsForOutOfFlowChild(const RenderBox&, GridTrackSizingDirection, int&, bool&, int&, bool&) const;
+    bool gridSpanCoversRealTracks(const RenderBox&, GridTrackSizingDirection) const;
 
     Grid m_grid;
 

Modified: trunk/Source/WebCore/rendering/style/GridPositionsResolver.cpp (290095 => 290096)


--- trunk/Source/WebCore/rendering/style/GridPositionsResolver.cpp	2022-02-18 00:53:20 UTC (rev 290095)
+++ trunk/Source/WebCore/rendering/style/GridPositionsResolver.cpp	2022-02-18 00:54:41 UTC (rev 290096)
@@ -380,7 +380,10 @@
     if (finalPosition.isAuto() && initialPosition.isSpan() && !initialPosition.namedGridLine().isNull())
         initialPosition.setSpanPosition(1, String());
 
-    if (isIndefiniteSpan(initialPosition, finalPosition) && is<RenderGrid>(gridItem) && downcast<RenderGrid>(gridItem).isSubgrid(direction)) {
+    // Absolutely positioned items specifying subgrid might not actually be a subgrid if their grid
+    // span doesn't cover any tracks and only the padding area. We don't know if that is the case until
+    // we've figured out their grid position though, which is what we're trying to do now.
+    if (isIndefiniteSpan(initialPosition, finalPosition) && is<RenderGrid>(gridItem) && downcast<RenderGrid>(gridItem).mayBeSubgridExcludingAbsPos(direction)) {
         // Indefinite span for an item that is subgridded in this axis.
         int lineCount = (isForColumns ? gridItem.style().orderedNamedGridColumnLines() : gridItem.style().orderedNamedGridRowLines()).size();
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to