Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (292972 => 292973)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-04-18 21:44:04 UTC (rev 292973)
@@ -1,3 +1,23 @@
+2022-04-18 Matt Woodrow <[email protected]>
+
+ Implement support for aligning baselines through subgrids
+ https://bugs.webkit.org/show_bug.cgi?id=238643
+
+ Reviewed by Javier Fernandez.
+
+ * web-platform-tests/css/css-grid/subgrid/baseline-002-expected.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-002.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-003-expected.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-003.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-004-expected.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-004.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-005-expected.html: Added.
+ * web-platform-tests/css/css-grid/subgrid/baseline-005.html: Added.
+
+ Added new WPT variants of the baseline tests, for the case where the introspected subgrid
+ has padding that affects the baseline position, and for the case where the subgrid uses an
+ orthogonal writing mode.
+
2022-04-18 Martin Robinson <[email protected]>
TestRunner testdriver does not properly focus elements before sending keys to them
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-001-expected.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-001-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-001-expected.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,55 @@
+<!DOCTYPE HTML>
+<html><head>
+ <meta charset="utf-8">
+ <title>Reference: baseline-aligned subgrid item with padding</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid: 20px repeat(4, auto) 30px / 30px repeat(4, auto) 20px;
+ place-content: start;
+ place-items: baseline start;
+ border: 1px solid;
+ text-decoration: underline blue;
+}
+
+.subgrid {
+ background: lightgrey;
+ grid-column: 2 / span 4;
+ grid-row: 3 / span 2;
+ min-width: 10px;
+ min-height: 0;
+ background: yellow;
+ padding-top: 20px;
+}
+
+x, z {
+ display: block;
+ min-width: 20px;
+ min-height: 10px;
+ font-size: 8em;
+ background: silver;
+}
+z {
+ width: 20px;
+ height: 10px;
+}
+
+ </style>
+</head>
+<body>
+
+<div class="grid">
+<y style="grid-area:3/1">A </y>
+<div class="subgrid">
+ <z></z><x> A</x>
+</div>
+</div>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-001.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-001.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-001.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html><head>
+ <meta charset="utf-8">
+ <title>CSS Grid Test: baseline-aligned subgrid item with padding</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <link rel="match" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid: 20px repeat(4, auto) 30px / 30px repeat(4, auto) 20px;
+ place-content: start;
+ place-items: baseline start;
+ border: 1px solid;
+ text-decoration: underline blue;
+}
+
+.subgrid {
+ display: grid;
+ grid: subgrid / auto;
+ background: lightgrey;
+ grid-column: 2 / span 4;
+ grid-row: 3 / span 2;
+ min-width: 10px;
+ min-height: 0;
+ background: yellow;
+ place-content: inherit;
+ place-items: inherit;
+ padding-top: 20px;
+}
+
+x {
+ min-width: 20px;
+ min-height: 10px;
+ font-size: 8em;
+ background: silver;
+}
+
+ </style>
+</head>
+<body>
+
+<div class="grid">
+<y style="grid-area:4/1">A </y>
+<div class="subgrid">
+ <x style="grid-row:2"> A</x><x></x>
+</div>
+</div>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-002-expected.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-002-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-002-expected.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html><head>
+ <meta charset="utf-8">
+ <title>Reference: baseline-aligned subgrid item with orthogonal writing-mode</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid: 20px repeat(4, auto) 30px / 30px repeat(4, auto) 20px;
+ place-content: start;
+ place-items: baseline start;
+ border: 1px solid;
+ text-decoration: underline blue;
+}
+
+.subgrid {
+ background: lightgrey;
+ grid-column: 2 / span 4;
+ grid-row: 3 / span 2;
+ min-width: 10px;
+ min-height: 0;
+ background: yellow;
+}
+
+x, z {
+ display: block;
+ min-width: 20px;
+ min-height: 10px;
+ font-size: 8em;
+ background: silver;
+}
+z {
+ width: 20px;
+ height: 10px;
+}
+
+ </style>
+</head>
+<body>
+
+<div class="grid">
+<y style="grid-area:3/1">A </y>
+<div class="subgrid">
+ <z></z><x style="margin-left: 20px"> A</x>
+</div>
+</div>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-002.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-002.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-002.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html><head>
+ <meta charset="utf-8">
+ <title>CSS Grid Test: baseline-aligned subgrid item with orthogonal writing-mode</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <link rel="match" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid: 20px repeat(4, auto) 30px / 30px repeat(4, auto) 20px;
+ place-content: start;
+ place-items: baseline start;
+ border: 1px solid;
+ text-decoration: underline blue;
+}
+
+.subgrid {
+ display: grid;
+ grid: auto / subgrid;
+ background: lightgrey;
+ grid-column: 2 / span 4;
+ grid-row: 3 / span 2;
+ min-width: 10px;
+ min-height: 0;
+ background: yellow;
+ place-content: inherit;
+ place-items: start baseline;
+ writing-mode: vertical-rl;
+}
+
+x {
+ min-width: 20px;
+ min-height: 10px;
+ font-size: 8em;
+ background: silver;
+ writing-mode: horizontal-tb;
+}
+
+ </style>
+</head>
+<body>
+
+<div class="grid">
+<y style="grid-area:4/1">A </y>
+<div class="subgrid">
+ <x style="grid-column:2"> A</x><x></x>
+</div>
+</div>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-003-expected.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-003-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-003-expected.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,37 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>CSS Grid Test: baseline-aligned subgrid item</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid-template-columns: auto auto;
+ max-width: 100px;
+ place-items: baseline start;
+}
+
+.first {
+ font-size: 3em;
+}
+
+.second {
+ font-size: 2em;
+}
+ </style>
+</head>
+<body>
+<div class="grid">
+ <div class="first">A</div>
+ <div class="second">A</div>
+</div>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-003.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-003.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-003.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,52 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>CSS Grid Test: baseline-aligned subgrid item</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <link rel="match" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid-template-columns: auto auto;
+ grid-template-rows: auto auto;
+ max-width: 100px;
+ place-items: baseline start;
+}
+
+.subgrid {
+ display: grid;
+ grid-template-rows: subgrid;
+ grid-row: 1 / 3;
+ grid-column: 2;
+
+ padding-bottom: 20px;
+ place-items: inherit;
+}
+
+.first {
+ font-size: 3em;
+ grid-row: 2;
+}
+
+.second {
+ font-size: 2em;
+ grid-row: 2;
+}
+ </style>
+</head>
+<body>
+<div class="grid">
+ <div class="first">A</div>
+ <div class="subgrid">
+ <div class="second">A</div>
+ </div>
+</div>
+
+</body></html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-004-expected.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-004-expected.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-004-expected.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>CSS Grid Test: baseline-aligned subgrid item</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid-template-columns: 50px 50px;
+ place-items: baseline start;
+}
+
+.first {
+ font-size: 3em;
+}
+
+.second {
+ font-size: 2em;
+}
+ </style>
+</head>
+<body>
+<div class="grid">
+ <div class="first">A</div>
+ <div class="second">A</div>
+</div>
+
+</body>
+</html>
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-004.html (0 => 292973)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-004.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-grid/subgrid/subgrid-baseline-004.html 2022-04-18 21:44:04 UTC (rev 292973)
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>CSS Grid Test: baseline-aligned subgrid item</title>
+ <link rel="author" title="Matt Woodrow" href=""
+ <link rel="help" href=""
+ <link rel="stylesheet" type="text/css" href=""
+ <link rel="match" href=""
+ <style>
+html,body {
+ color:black; background-color:white; font:16px/1 Ahem; padding:0; margin:0;
+}
+
+.grid {
+ display: grid;
+ grid-template-columns: 50px 50px;
+ grid-template-rows: auto auto;
+ place-items: baseline start;
+}
+
+.subgrid {
+ display: grid;
+ grid-template-columns: subgrid;
+ grid-row: 1 / 3;
+ grid-column: 2;
+
+ padding-bottom: 20px;
+ writing-mode: vertical-lr;
+ place-items: start baseline;
+}
+
+.first {
+ font-size: 3em;
+ grid-row: 2;
+}
+
+.second {
+ font-size: 2em;
+ grid-column: 2;
+ writing-mode: horizontal-tb;
+}
+ </style>
+</head>
+<body>
+<div class="grid">
+ <div class="first">A</div>
+ <div class="subgrid">
+ <div class="second">A</div>
+ </div>
+</div>
+
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (292972 => 292973)
--- trunk/Source/WebCore/ChangeLog 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/ChangeLog 2022-04-18 21:44:04 UTC (rev 292973)
@@ -1,3 +1,50 @@
+2022-04-18 Matt Woodrow <[email protected]>
+
+ Implement support for aligning baselines through subgrids
+ https://bugs.webkit.org/show_bug.cgi?id=238643
+
+ Reviewed by Javier Fernandez.
+
+ Implement baseline sharing recursion into subgrids
+
+ Tests: imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-002.html
+ imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-003.html
+ imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-004.html
+ imported/w3c/web-platform-tests/css/css-grid/subgrid/baseline-005.html
+
+ * rendering/GridBaselineAlignment.cpp:
+ (WebCore::GridBaselineAlignment::ascentForChild const):
+ (WebCore::GridBaselineAlignment::descentForChild const):
+ (WebCore::GridBaselineAlignment::updateBaselineAlignmentContext):
+ (WebCore::BaselineGroup::BaselineGroup):
+ (WebCore::BaselineGroup::update):
+ (WebCore::BaselineContext::BaselineContext):
+ (WebCore::BaselineContext::updateSharedGroup):
+ * rendering/GridBaselineAlignment.h:
+ (WebCore::BaselineGroup::maxAscent const):
+ (WebCore::BaselineGroup::maxDescent const): Deleted.
+ * rendering/GridLayoutFunctions.h:
+ * rendering/GridTrackSizingAlgorithm.cpp:
+ (WebCore::GridTrackSizingAlgorithm::canParticipateInBaselineAlignment const):
+ (WebCore::GridTrackSizingAlgorithm::updateBaselineAlignmentContext):
+ (WebCore::GridTrackSizingAlgorithm::baselineOffsetForChild const):
+ (WebCore::GridTrackSizingAlgorithm::cacheBaselineAlignedItem):
+ * rendering/GridTrackSizingAlgorithm.h:
+ * rendering/RenderGrid.cpp:
+ (WebCore::cacheBaselineAlignedChildren):
+ (WebCore::RenderGrid::computeIntrinsicLogicalWidths const):
+ (WebCore::RenderGrid::performGridItemsPreLayout const):
+ (WebCore::RenderGrid::alignSelfForChild const):
+ (WebCore::RenderGrid::justifySelfForChild const):
+ (WebCore::RenderGrid::columnAxisBaselineOffsetForChild const):
+ (WebCore::RenderGrid::rowAxisBaselineOffsetForChild const):
+
+ Moves the code for collecting baseline aligned children into a shared helper function, and adds
+ support for recursing into subgrid children (restricted to the axes that subgrid was applied).
+
+ Fixes align/justifySelfForChild to check if the child is a subgrid and overrides the result to 'stretch', so
+ that we're correctly stretching subgrids, not the children of subgrids (covered by new tests).
+
2022-04-18 Tyler Wilcock <[email protected]>
Node changes created by AXIsolatedTree::updateNode are overwritten when performed during AXIsolatedTree::collectNodeChangesForSubtree
Modified: trunk/Source/WebCore/rendering/GridBaselineAlignment.cpp (292972 => 292973)
--- trunk/Source/WebCore/rendering/GridBaselineAlignment.cpp 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/rendering/GridBaselineAlignment.cpp 2022-04-18 21:44:04 UTC (rev 292973)
@@ -68,6 +68,7 @@
LayoutUnit baseline(isParallelToBaselineAxisForChild(child, baselineAxis) ? child.firstLineBaseline().value_or(LayoutUnit(-1)) : LayoutUnit(-1));
// We take border-box's under edge if no valid baseline.
if (baseline == -1) {
+ ASSERT(!child.needsLayout());
if (isHorizontalBaselineAxis(baselineAxis))
return isFlippedWritingMode(m_blockFlow) ? child.size().width().toInt() + margin : margin;
return child.size().height() + margin;
@@ -77,6 +78,7 @@
LayoutUnit GridBaselineAlignment::descentForChild(const RenderBox& child, LayoutUnit ascent, GridAxis baselineAxis) const
{
+ ASSERT(!child.needsLayout());
if (isParallelToBaselineAxisForChild(child, baselineAxis))
return child.marginLogicalHeight() + child.logicalHeight() - ascent;
return child.marginLogicalWidth() + child.logicalWidth() - ascent;
@@ -122,9 +124,8 @@
// Determine Ascent and Descent values of this child with respect to
// its grid container.
LayoutUnit ascent = ascentForChild(child, baselineAxis);
- LayoutUnit descent = descentForChild(child, ascent, baselineAxis);
if (isDescentBaselineForChild(child, baselineAxis))
- std::swap(ascent, descent);
+ ascent = descentForChild(child, ascent, baselineAxis);
// Looking up for a shared alignment context perpendicular to the
// baseline axis.
@@ -134,10 +135,10 @@
// Looking for a compatible baseline-sharing group.
if (addResult.isNewEntry)
- addResult.iterator->value = makeUnique<BaselineContext>(child, preference, ascent, descent);
+ addResult.iterator->value = makeUnique<BaselineContext>(child, preference, ascent);
else {
auto* context = addResult.iterator->value.get();
- context->updateSharedGroup(child, preference, ascent, descent);
+ context->updateSharedGroup(child, preference, ascent);
}
}
@@ -159,17 +160,16 @@
}
BaselineGroup::BaselineGroup(WritingMode blockFlow, ItemPosition childPreference)
- : m_maxAscent(0), m_maxDescent(0), m_items()
+ : m_maxAscent(0), m_items()
{
m_blockFlow = blockFlow;
m_preference = childPreference;
}
-void BaselineGroup::update(const RenderBox& child, LayoutUnit ascent, LayoutUnit descent)
+void BaselineGroup::update(const RenderBox& child, LayoutUnit ascent)
{
if (m_items.add(&child).isNewEntry) {
m_maxAscent = std::max(m_maxAscent, ascent);
- m_maxDescent = std::max(m_maxDescent, descent);
}
}
@@ -209,10 +209,10 @@
return ((m_blockFlow == childBlockFlow || isOrthogonalBlockFlow(childBlockFlow)) && m_preference == childPreference) || (isOppositeBlockFlow(childBlockFlow) && m_preference != childPreference);
}
-BaselineContext::BaselineContext(const RenderBox& child, ItemPosition preference, LayoutUnit ascent, LayoutUnit descent)
+BaselineContext::BaselineContext(const RenderBox& child, ItemPosition preference, LayoutUnit ascent)
{
ASSERT(isBaselinePosition(preference));
- updateSharedGroup(child, preference, ascent, descent);
+ updateSharedGroup(child, preference, ascent);
}
const BaselineGroup& BaselineContext::sharedGroup(const RenderBox& child, ItemPosition preference) const
@@ -221,11 +221,11 @@
return const_cast<BaselineContext*>(this)->findCompatibleSharedGroup(child, preference);
}
-void BaselineContext::updateSharedGroup(const RenderBox& child, ItemPosition preference, LayoutUnit ascent, LayoutUnit descent)
+void BaselineContext::updateSharedGroup(const RenderBox& child, ItemPosition preference, LayoutUnit ascent)
{
ASSERT(isBaselinePosition(preference));
BaselineGroup& group = findCompatibleSharedGroup(child, preference);
- group.update(child, ascent, descent);
+ group.update(child, ascent);
}
// FIXME: Properly implement baseline-group compatibility.
Modified: trunk/Source/WebCore/rendering/GridBaselineAlignment.h (292972 => 292973)
--- trunk/Source/WebCore/rendering/GridBaselineAlignment.h 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/rendering/GridBaselineAlignment.h 2022-04-18 21:44:04 UTC (rev 292973)
@@ -49,11 +49,10 @@
//
class BaselineGroup {
public:
- // It stores an item (if not already present) and update the max_ascent and max_descent associated to this
+ // It stores an item (if not already present) and update the max_ascent associated to this
// baseline-sharing group.
- void update(const RenderBox&, LayoutUnit ascent, LayoutUnit descent);
+ void update(const RenderBox&, LayoutUnit ascent);
LayoutUnit maxAscent() const { return m_maxAscent; }
- LayoutUnit maxDescent() const { return m_maxDescent; }
int size() const { return m_items.size(); }
private:
@@ -75,7 +74,6 @@
WritingMode m_blockFlow;
ItemPosition m_preference;
LayoutUnit m_maxAscent;
- LayoutUnit m_maxDescent;
HashSet<const RenderBox*> m_items;
};
@@ -99,13 +97,13 @@
class BaselineContext {
WTF_MAKE_FAST_ALLOCATED;
public:
- BaselineContext(const RenderBox& child, ItemPosition preference, LayoutUnit ascent, LayoutUnit descent);
+ BaselineContext(const RenderBox& child, ItemPosition preference, LayoutUnit ascent);
const BaselineGroup& sharedGroup(const RenderBox& child, ItemPosition preference) const;
// Updates the baseline-sharing group compatible with the item.
// We pass the item's baseline-preference to avoid dependencies with the LayoutGrid class, which is the one
// managing the alignment behavior of the Grid Items.
- void updateSharedGroup(const RenderBox& child, ItemPosition preference, LayoutUnit ascent, LayoutUnit descent);
+ void updateSharedGroup(const RenderBox& child, ItemPosition preference, LayoutUnit ascent);
private:
// Returns the baseline-sharing group compatible with an item.
Modified: trunk/Source/WebCore/rendering/GridLayoutFunctions.h (292972 => 292973)
--- trunk/Source/WebCore/rendering/GridLayoutFunctions.h 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/rendering/GridLayoutFunctions.h 2022-04-18 21:44:04 UTC (rev 292973)
@@ -34,7 +34,10 @@
class RenderElement;
class RenderGrid;
-enum GridAxis { GridRowAxis, GridColumnAxis };
+enum GridAxis {
+ GridRowAxis = 1 << 0,
+ GridColumnAxis = 1 << 1
+};
namespace GridLayoutFunctions {
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (292972 => 292973)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2022-04-18 21:44:04 UTC (rev 292973)
@@ -909,6 +909,13 @@
if (isParallelToBaselineAxis && child.firstLineBaseline())
return true;
+ // FIXME: We don't currently allow items within subgrids that need to
+ // synthesize a baseline, since we need a layout to have been completed
+ // and performGridItemsPreLayout on the outer grid doesn't layout subgrid
+ // items.
+ if (child.parent() != renderGrid())
+ return false;
+
// Baseline cyclic dependencies only happen in grid areas with
// intrinsically-sized tracks.
if (!isIntrinsicSizedGridArea(child, baselineAxis))
@@ -926,7 +933,6 @@
{
ASSERT(wasSetup());
ASSERT(canParticipateInBaselineAlignment(child, baselineAxis));
- ASSERT(!child.needsLayout());
ItemPosition align = m_renderGrid->selfAlignmentForChild(baselineAxis, child).position();
const auto& span = m_renderGrid->gridSpanForChild(child, gridDirectionForAxis(baselineAxis));
@@ -935,6 +941,11 @@
LayoutUnit GridTrackSizingAlgorithm::baselineOffsetForChild(const RenderBox& child, GridAxis baselineAxis) const
{
+ // If we haven't yet initialized this axis (which can be the case if we're doing
+ // prelayout of a subgrid), then we can't know the baseline offset.
+ if (tracks(gridDirectionForAxis(baselineAxis)).isEmpty())
+ return LayoutUnit();
+
if (!participateInBaselineAlignment(child, baselineAxis))
return LayoutUnit();
@@ -951,7 +962,11 @@
void GridTrackSizingAlgorithm::cacheBaselineAlignedItem(const RenderBox& item, GridAxis axis)
{
- ASSERT(m_renderGrid->isBaselineAlignmentForChild(item, axis));
+ ASSERT(downcast<RenderGrid>(item.parent())->isBaselineAlignmentForChild(item, axis));
+
+ if (GridLayoutFunctions::isOrthogonalParent(*m_renderGrid, *item.parent()))
+ axis = axis == GridColumnAxis ? GridRowAxis : GridColumnAxis;
+
if (axis == GridColumnAxis)
m_columnBaselineItemsMap.add(&item, true);
else
Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h (292972 => 292973)
--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h 2022-04-18 21:44:04 UTC (rev 292973)
@@ -122,7 +122,7 @@
// and encapsulate any access in the algorithm class.
Grid& mutableGrid() const { return m_grid; }
- const RenderGrid* renderGrid() { return m_renderGrid; };
+ const RenderGrid* renderGrid() const { return m_renderGrid; };
LayoutUnit minContentSize() const { return m_minContentSize; };
LayoutUnit maxContentSize() const { return m_maxContentSize; };
Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (292972 => 292973)
--- trunk/Source/WebCore/rendering/RenderGrid.cpp 2022-04-18 21:37:35 UTC (rev 292972)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp 2022-04-18 21:44:04 UTC (rev 292973)
@@ -192,6 +192,40 @@
return RenderBlock::canPerformSimplifiedLayout();
}
+template<typename F>
+static void cacheBaselineAlignedChildren(const RenderGrid& grid, GridTrackSizingAlgorithm& algorithm, uint32_t axes, F& callback)
+{
+ for (auto* child = grid.firstChildBox(); child; child = child->nextSiblingBox()) {
+ if (child->isOutOfFlowPositioned() || child->isLegend())
+ continue;
+
+ callback(child);
+
+ // We keep a cache of items with baseline as alignment values so that we only compute the baseline shims for
+ // such items. This cache is needed for performance related reasons due to the cost of evaluating the item's
+ // participation in a baseline context during the track sizing algorithm.
+ uint32_t innerAxes = 0;
+ RenderGrid* inner = is<RenderGrid>(child) ? downcast<RenderGrid>(child) : nullptr;
+
+ if (axes & GridColumnAxis) {
+ if (inner && inner->isSubgridInParentDirection(ForRows))
+ innerAxes |= GridLayoutFunctions::isOrthogonalChild(grid, *child) ? GridRowAxis : GridColumnAxis;
+ else if (grid.isBaselineAlignmentForChild(*child, GridColumnAxis))
+ algorithm.cacheBaselineAlignedItem(*child, GridColumnAxis);
+ }
+
+ if (axes & GridRowAxis) {
+ if (inner && inner->isSubgridInParentDirection(ForColumns))
+ innerAxes |= GridLayoutFunctions::isOrthogonalChild(grid, *child) ? GridColumnAxis : GridRowAxis;
+ else if (grid.isBaselineAlignmentForChild(*child, GridRowAxis))
+ algorithm.cacheBaselineAlignedItem(*child, GridRowAxis);
+ }
+
+ if (innerAxes)
+ cacheBaselineAlignedChildren(*inner, algorithm, innerAxes, callback);
+ }
+}
+
Vector<RenderBox*> RenderGrid::computeAspectRatioDependentAndBaselineItems()
{
Vector<RenderBox*> dependentGridItems;
@@ -200,20 +234,12 @@
m_hasAnyOrthogonalItem = false;
m_hasAspectRatioBlockSizeDependentItem = false;
- for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
- if (child->isOutOfFlowPositioned() || child->isLegend())
- continue;
-
+ auto computeOrthogonalAndDependentItems = [&](RenderBox* child) {
// Grid's layout logic controls the grid item's override height, hence we need to
// clear any override height set previously, so it doesn't interfere in current layout
// execution. Grid never uses the override width, that's why we don't need to clear it.
child->clearOverridingLogicalHeight();
- // Grid's layout logic controls the grid item's override height, hence we need to
- // clear any override height set previously, so it doesn't interfere in current layout
- // execution. Grid never uses the override width, that's why we don't need to clear it.
- child->clearOverridingLogicalHeight();
-
// We may need to repeat the track sizing in case of any grid item was orthogonal.
if (GridLayoutFunctions::isOrthogonalChild(*this, *child))
m_hasAnyOrthogonalItem = true;
@@ -224,16 +250,9 @@
dependentGridItems.append(child);
m_hasAspectRatioBlockSizeDependentItem = true;
}
+ };
- // We keep a cache of items with baseline as aligcnment values so that we only compute the baseline shims for
- // such items. This cache is needed for performance related reasons due to the cost of evaluating the item's
- // participation in a baseline context during the track sizing algorithm.
- if (isBaselineAlignmentForChild(*child, GridColumnAxis))
- m_trackSizingAlgorithm.cacheBaselineAlignedItem(*child, GridColumnAxis);
- if (isBaselineAlignmentForChild(*child, GridRowAxis))
- m_trackSizingAlgorithm.cacheBaselineAlignedItem(*child, GridRowAxis);
- }
-
+ cacheBaselineAlignedChildren(*this, m_trackSizingAlgorithm, GridRowAxis | GridColumnAxis, computeOrthogonalAndDependentItems);
return dependentGridItems;
}
@@ -477,12 +496,8 @@
if (m_baselineItemsCached)
algorithm.copyBaselineItemsCache(m_trackSizingAlgorithm, GridRowAxis);
else {
- for (auto* child = firstChildBox(); child; child = child->nextSiblingBox()) {
- if (child->isOutOfFlowPositioned())
- continue;
- if (isBaselineAlignmentForChild(*child, GridRowAxis))
- algorithm.cacheBaselineAlignedItem(*child, GridRowAxis);
- }
+ auto emptyCallback = [](RenderBox*) { };
+ cacheBaselineAlignedChildren(*this, algorithm, GridRowAxis, emptyCallback);
}
computeTrackSizesForIndefiniteSize(algorithm, ForColumns, &minLogicalWidth, &maxLogicalWidth);
@@ -783,6 +798,8 @@
// We need to layout the item to know whether it must synthesize its
// baseline or not, which may imply a cyclic sizing dependency.
// FIXME: Can we avoid it ?
+ // FIXME: We also want to layout baseline aligned items within subgrids, but
+ // we don't currently have a way to do that here.
if (isBaselineAlignmentForChild(*child)) {
updateGridAreaLogicalSize(*child, algorithm.estimatedGridAreaBreadthForChild(*child, ForColumns), algorithm.estimatedGridAreaBreadthForChild(*child, ForRows));
child->layoutIfNeeded();
@@ -1226,7 +1243,7 @@
StyleSelfAlignmentData RenderGrid::alignSelfForChild(const RenderBox& child, StretchingMode stretchingMode, const RenderStyle* gridStyle) const
{
- if (isSubgridInParentDirection(ForRows))
+ if (is<RenderGrid>(child) && downcast<RenderGrid>(child).isSubgridInParentDirection(ForRows))
return { ItemPosition::Stretch, OverflowAlignment::Default };
if (!gridStyle)
gridStyle = &style();
@@ -1236,7 +1253,7 @@
StyleSelfAlignmentData RenderGrid::justifySelfForChild(const RenderBox& child, StretchingMode stretchingMode, const RenderStyle* gridStyle) const
{
- if (isSubgridInParentDirection(ForColumns))
+ if (is<RenderGrid>(child) && downcast<RenderGrid>(child).isSubgridInParentDirection(ForColumns))
return { ItemPosition::Stretch, OverflowAlignment::Default };
if (!gridStyle)
gridStyle = &style();
@@ -1457,11 +1474,23 @@
LayoutUnit RenderGrid::columnAxisBaselineOffsetForChild(const RenderBox& child) const
{
+ if (isSubgridRows()) {
+ RenderGrid* outer = downcast<RenderGrid>(parent());
+ if (GridLayoutFunctions::isOrthogonalChild(*outer, *this))
+ return outer->rowAxisBaselineOffsetForChild(child);
+ return outer->columnAxisBaselineOffsetForChild(child);
+ }
return m_trackSizingAlgorithm.baselineOffsetForChild(child, GridColumnAxis);
}
LayoutUnit RenderGrid::rowAxisBaselineOffsetForChild(const RenderBox& child) const
{
+ if (isSubgridColumns()) {
+ RenderGrid* outer = downcast<RenderGrid>(parent());
+ if (GridLayoutFunctions::isOrthogonalChild(*outer, *this))
+ return outer->columnAxisBaselineOffsetForChild(child);
+ return outer->rowAxisBaselineOffsetForChild(child);
+ }
return m_trackSizingAlgorithm.baselineOffsetForChild(child, GridRowAxis);
}