- Revision
- 290577
- Author
- [email protected]
- Date
- 2022-02-27 19:03:39 -0800 (Sun, 27 Feb 2022)
Log Message
Compute correct containing block override size for items that are subgridden in one dimension only.
https://bugs.webkit.org/show_bug.cgi?id=236951
Reviewed by Dean Jackson.
LayoutTests/imported/w3c:
Added new WPT similar to auto-track-sizing-001 which adds new variations
with nested subgrids and varying whether the other axis is subgridded.
* web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002-expected.html: Added.
* web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html: Added.
Source/WebCore:
Items that are subgridded in one dimension will be included in the track sizing algorithm of the
outer grid for that dimension. When measuring their size in the subgridded dimension, we need to
set their containing block size in the other (non-subgridded) dimension, which is only available
from the subgrid's track sizing, not the outer track sizes.
This recurses up to set the override size on the subgrid element instead, and forces a layout
there, which should copy down subgrid track sizes and compute the other dimension, making it
available on the inner item we need.
Test: imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html
* rendering/GridLayoutFunctions.cpp:
(WebCore::GridLayoutFunctions::extraMarginForSubgridAncestors):
* rendering/GridLayoutFunctions.h:
* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::GridTrackSizingAlgorithmStrategy::updateOverridingContainingBlockContentSizeForChild const):
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::isSubgridOf):
* rendering/RenderGrid.h:
LayoutTests:
* TestExpectations:
Marked existing WPT as passing.
Modified Paths
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (290576 => 290577)
--- trunk/LayoutTests/ChangeLog 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/LayoutTests/ChangeLog 2022-02-28 03:03:39 UTC (rev 290577)
@@ -1,5 +1,16 @@
2022-02-27 Matt Woodrow <[email protected]>
+ Compute correct containing block override size for items that are subgridden in one dimension only.
+ https://bugs.webkit.org/show_bug.cgi?id=236951
+
+ Reviewed by Dean Jackson.
+
+ * TestExpectations:
+
+ Marked existing WPT as passing.
+
+2022-02-27 Matt Woodrow <[email protected]>
+
Convert grid direction to be relative to subgrid when accounting for extra margin.
https://bugs.webkit.org/show_bug.cgi?id=236954
Modified: trunk/LayoutTests/TestExpectations (290576 => 290577)
--- trunk/LayoutTests/TestExpectations 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/LayoutTests/TestExpectations 2022-02-28 03:03:39 UTC (rev 290577)
@@ -1394,7 +1394,6 @@
imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-subgrid-001.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-subgrid-002.html [ ImageOnlyFailure ]
-webkit.org/b/236951 imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-001.html [ ImageOnlyFailure ]
webkit.org/b/236959 imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-001.html [ ImageOnlyFailure ]
webkit.org/b/236956 imported/w3c/web-platform-tests/css/css-grid/subgrid/grid-gap-003.html [ ImageOnlyFailure ]
webkit.org/b/236957 imported/w3c/web-platform-tests/css/css-grid/subgrid/line-names-007.html [ ImageOnlyFailure ]
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (290576 => 290577)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-02-28 03:03:39 UTC (rev 290577)
@@ -1,3 +1,16 @@
+2022-02-27 Matt Woodrow <[email protected]>
+
+ Compute correct containing block override size for items that are subgridden in one dimension only.
+ https://bugs.webkit.org/show_bug.cgi?id=236951
+
+ Reviewed by Dean Jackson.
+
+ Added new WPT similar to auto-track-sizing-001 which adds new variations
+ with nested subgrids and varying whether the other axis is subgridded.
+
+ * web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002-expected.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html: Added.
+
2022-02-27 Antoine Quint <[email protected]>
[web-animations] web-animations/timing-model/animations/setting-the-timeline-of-an-animation.html is a unique failure
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002-expected.html (0 => 290577)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002-expected.html 2022-02-28 03:03:39 UTC (rev 290577)
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html><head>
+ <meta charset="utf-8">
+ <title>Reference: subgrid auto track sizing</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 monospace; padding:0; margin:0;
+}
+
+.grid {
+ display: inline-grid;
+ max-width: 260px;
+ padding: 1px 5px;
+ border: 1px solid;
+ grid-template-columns: 100px;
+}
+.subgrid {
+ display: grid;
+ grid-template-columns: 100%;
+ margin: 0px 10px 0px 10px;
+ background: grey;
+}
+
+ </style>
+</head>
+<body>
+
+<article class="grid">
+ <div class="subgrid">
+ The cat can not be separated from milk
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid">
+ The cat can not be separated from milk
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid">
+ The cat can not be separated from milk
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid">
+ The cat can not be separated from milk
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid">
+ The cat can not be separated from milk
+ </div>
+</article>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html (0 => 290577)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html 2022-02-28 03:03:39 UTC (rev 290577)
@@ -0,0 +1,80 @@
+<!DOCTYPE HTML>
+<!--
+ Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<html><head>
+ <meta charset="utf-8">
+ <title>Test: subgrid auto track sizing</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="match" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 monospace; padding:0; margin:0;
+}
+
+.grid {
+ display: inline-grid;
+ max-width: 260px;
+ padding: 1px 5px;
+ border: 1px solid;
+ grid-template-columns: 100px;
+}
+
+.subgrid {
+ display: grid;
+ grid-template-rows: subgrid;
+ grid-template-columns: 100%;
+ margin: 0px 5px 0px 10px;
+}
+
+.inner {
+ margin: 0px 5px 0px 0px;
+ background: grey;
+}
+ </style>
+</head>
+<body>
+
+<article class="grid">
+ <div class="subgrid" style="margin: 0px 10px 0px 10px; background: grey">
+ The cat can not be separated from milk
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid">
+ <div class="subgrid inner">
+ The cat can not be separated from milk
+ </div>
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid" style="grid-template-columns: subgrid">
+ <div class="subgrid inner">
+ The cat can not be separated from milk
+ </div>
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid">
+ <div class="subgrid inner" style="grid-template-columns: subgrid">
+ The cat can not be separated from milk
+ </div>
+ </div>
+</article>
+
+<article class="grid">
+ <div class="subgrid" style="grid-template-columns: subgrid">
+ <div class="subgrid inner" style="grid-template-columns: subgrid">
+ The cat can not be separated from milk
+ </div>
+ </div>
+</article>
+
+
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (290576 => 290577)
--- trunk/Source/WebCore/ChangeLog 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/Source/WebCore/ChangeLog 2022-02-28 03:03:39 UTC (rev 290577)
@@ -1,5 +1,32 @@
2022-02-27 Matt Woodrow <[email protected]>
+ Compute correct containing block override size for items that are subgridden in one dimension only.
+ https://bugs.webkit.org/show_bug.cgi?id=236951
+
+ Reviewed by Dean Jackson.
+
+ Items that are subgridded in one dimension will be included in the track sizing algorithm of the
+ outer grid for that dimension. When measuring their size in the subgridded dimension, we need to
+ set their containing block size in the other (non-subgridded) dimension, which is only available
+ from the subgrid's track sizing, not the outer track sizes.
+
+ This recurses up to set the override size on the subgrid element instead, and forces a layout
+ there, which should copy down subgrid track sizes and compute the other dimension, making it
+ available on the inner item we need.
+
+ Test: imported/w3c/web-platform-tests/css/css-grid/subgrid/auto-track-sizing-002.html
+
+ * rendering/GridLayoutFunctions.cpp:
+ (WebCore::GridLayoutFunctions::extraMarginForSubgridAncestors):
+ * rendering/GridLayoutFunctions.h:
+ * rendering/GridTrackSizingAlgorithm.cpp:
+ (WebCore::GridTrackSizingAlgorithmStrategy::updateOverridingContainingBlockContentSizeForChild const):
+ * rendering/RenderGrid.cpp:
+ (WebCore::RenderGrid::isSubgridOf):
+ * rendering/RenderGrid.h:
+
+2022-02-27 Matt Woodrow <[email protected]>
+
Convert grid direction to be relative to subgrid when accounting for extra margin.
https://bugs.webkit.org/show_bug.cgi?id=236954
Modified: trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp (290576 => 290577)
--- trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/Source/WebCore/rendering/GridLayoutFunctions.cpp 2022-02-28 03:03:39 UTC (rev 290577)
@@ -103,7 +103,7 @@
return mbp;
}
-static LayoutUnit extraMarginForSubgridAncestors(GridTrackSizingDirection direction, const RenderBox& child)
+LayoutUnit extraMarginForSubgridAncestors(GridTrackSizingDirection direction, const RenderBox& child)
{
const RenderGrid* grid = downcast<RenderGrid>(child.parent());
LayoutUnit mbp;
Modified: trunk/Source/WebCore/rendering/GridLayoutFunctions.h (290576 => 290577)
--- trunk/Source/WebCore/rendering/GridLayoutFunctions.h 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/Source/WebCore/rendering/GridLayoutFunctions.h 2022-02-28 03:03:39 UTC (rev 290577)
@@ -50,6 +50,7 @@
bool isFlippedDirection(const RenderGrid&, GridTrackSizingDirection);
bool isSubgridReversedDirection(const RenderGrid&, GridTrackSizingDirection outerDirection, const RenderGrid& subgrid);
+LayoutUnit extraMarginForSubgridAncestors(GridTrackSizingDirection, const RenderBox& child);
}
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (290576 => 290577)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2022-02-28 03:03:39 UTC (rev 290577)
@@ -965,6 +965,29 @@
if (!overrideSize)
overrideSize = m_algorithm.gridAreaBreadthForChild(child, direction);
+ if (renderGrid() != child.parent()) {
+ RenderGrid* grid = downcast<RenderGrid>(child.parent());
+
+ GridTrackSizingDirection subgridDirection = GridLayoutFunctions::flowAwareDirectionForChild(*renderGrid(), *grid, direction);
+
+ if (grid->isSubgridOf(subgridDirection, *renderGrid())) {
+ // If the item is subgridded in this direction (and thus the tracks it covers are tracks
+ // owned by this sizing algorithm), then we want to take the breadth of the tracks we occupy,
+ // and subtract any space occupied by the subgrid itself (and any ancestor subgrids).
+ *overrideSize -= GridLayoutFunctions::extraMarginForSubgridAncestors(subgridDirection, child);
+ } else {
+ // Otherwise the tracks that this item covers (in this non-subgridded axis) are owned
+ // by one of the intermediate RenderGrids (which are subgrids in the other axis). Recurse
+ // until we find an element this is directly part of this grid and set the override size
+ // for that, and then layout that item so that it computes the track sizes and sets the
+ // override size we need.
+ bool overrideSizeHasChanged =
+ updateOverridingContainingBlockContentSizeForChild(*grid, direction);
+ layoutGridItemForMinSizeComputation(*grid, overrideSizeHasChanged);
+ return overrideSizeHasChanged;
+ }
+ }
+
if (GridLayoutFunctions::hasOverridingContainingBlockContentSizeForChild(child, direction) && GridLayoutFunctions::overridingContainingBlockContentSizeForChild(child, direction) == overrideSize)
return false;
Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (290576 => 290577)
--- trunk/Source/WebCore/rendering/RenderGrid.cpp 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp 2022-02-28 03:03:39 UTC (rev 290577)
@@ -1628,6 +1628,18 @@
return isSubgrid(direction);
}
+bool RenderGrid::isSubgridOf(GridTrackSizingDirection direction, const RenderGrid& ancestor)
+{
+ if (!isSubgrid(direction))
+ return false;
+ if (parent() == &ancestor)
+ return true;
+
+ auto& parentGrid = *downcast<RenderGrid>(parent());
+ GridTrackSizingDirection parentDirection = GridLayoutFunctions::flowAwareDirectionForParent(parentGrid, *this, direction);
+ return parentGrid.isSubgridOf(parentDirection, ancestor);
+}
+
bool RenderGrid::mayBeSubgridExcludingAbsPos(GridTrackSizingDirection direction) const
{
// Should exclude cases where we establish an IFC, like contain layout.
Modified: trunk/Source/WebCore/rendering/RenderGrid.h (290576 => 290577)
--- trunk/Source/WebCore/rendering/RenderGrid.h 2022-02-28 02:14:28 UTC (rev 290576)
+++ trunk/Source/WebCore/rendering/RenderGrid.h 2022-02-28 03:03:39 UTC (rev 290577)
@@ -96,6 +96,12 @@
return isSubgrid(ForColumns);
}
bool isSubgridInParentDirection(GridTrackSizingDirection parentDirection) const;
+
+ // Returns true if this grid is inheriting subgridded tracks for
+ // the given direction from the specified ancestor. This handles
+ // nested subgrids, where ancestor may not be our direct parent.
+ bool isSubgridOf(GridTrackSizingDirection, const RenderGrid& ancestor);
+
bool mayBeSubgridExcludingAbsPos(GridTrackSizingDirection) const;
const Grid& currentGrid() const