<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[286148] trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/286148">286148</a></dd>
<dt>Author</dt> <dd>zsun@igalia.com</dd>
<dt>Date</dt> <dd>2021-11-24 07:04:31 -0800 (Wed, 24 Nov 2021)</dd>
</dl>

<h3>Log Message</h3>
<pre>[css-grid] Track sizing algorithm not repeated even if used flex fraction would change
https://bugs.webkit.org/show_bug.cgi?id=232617

Reviewed by Javier Fernandez.

Source/WebCore:

According to https://drafts.csswg.org/css-grid/#algo-flex-tracks, when row height is
indefinite, for each grid item that crosses a flexible track, we run the track sizing
algorithm under a max-content constraint to find the flex fraction. Then we work out
the grid container height as definite, which may cause the flex fraction change. At this
point, we need to repeat the track sizing algorithm for row and layout the grid for real.
The current implementation doesn't repeat the track sizing algorithm for row.

The complication with calling RenderGrid::repeatTracksSizingIfNeeded() for flex max-sizing
is that it might change a grid item's status of participating in Baseline Alignment for
a cyclic sizing dependncy case, which should be definitively excluded. See
https://github.com/w3c/csswg-drafts/issues/3046 for more details. This issue should be handled
in a seperate bug. This CL only handle test cases that don't have baseline alignment specified.

* rendering/GridTrackSizingAlgorithm.cpp:
(WebCore::GridTrackSizingAlgorithm::initializeTrackSizes):
(WebCore::GridTrackSizingAlgorithm::setup):
(WebCore::GridTrackSizingAlgorithm::reset):
* rendering/GridTrackSizingAlgorithm.h:
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::repeatTracksSizingIfNeeded):
(WebCore::RenderGrid::layoutBlock):
* rendering/RenderGrid.h:

LayoutTests:

Unskip two tests that are passing.

* TestExpectations:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkLayoutTestsTestExpectations">trunk/LayoutTests/TestExpectations</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCorerenderingGridTrackSizingAlgorithmcpp">trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingGridTrackSizingAlgorithmh">trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderGridcpp">trunk/Source/WebCore/rendering/RenderGrid.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderGridh">trunk/Source/WebCore/rendering/RenderGrid.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog      2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/LayoutTests/ChangeLog 2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -1,3 +1,14 @@
</span><ins>+2021-11-24  Ziran Sun  <zsun@igalia.com>
+
+        [css-grid] Track sizing algorithm not repeated even if used flex fraction would change
+        https://bugs.webkit.org/show_bug.cgi?id=232617
+
+        Reviewed by Javier Fernandez.
+
+        Unskip two tests that are passing.

+        * TestExpectations:
+
</ins><span class="cx"> 2021-11-24  Manuel Rego Casasnovas  <rego@igalia.com>
</span><span class="cx"> 
</span><span class="cx">         [selectors] Import 2 new :focus-visible tests from WPT
</span></span></pre></div>
<a id="trunkLayoutTestsTestExpectations"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/TestExpectations (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/TestExpectations       2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/LayoutTests/TestExpectations  2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -1396,8 +1396,6 @@
</span><span class="cx"> webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/grid-items/replaced-element-015.html [ ImageOnlyFailure ]
</span><span class="cx"> 
</span><span class="cx"> imported/w3c/web-platform-tests/css/css-grid/grid-model/grid-areas-overflowing-grid-container-009.html [ ImageOnlyFailure ]
</span><del>-imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/flex-sizing-rows-indefinite-height.html [ ImageOnlyFailure ]
-webkit.org/b/231021 imported/w3c/web-platform-tests/css/css-grid/layout-algorithm/grid-template-flexible-rerun-track-sizing.html [ ImageOnlyFailure ]
</del><span class="cx"> imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-align-content-001.html [ ImageOnlyFailure ]
</span><span class="cx"> imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-align-content-002.html [ ImageOnlyFailure ]
</span><span class="cx"> imported/w3c/web-platform-tests/css/css-grid/masonry/tentative/masonry-align-content-003.html [ ImageOnlyFailure ]
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog   2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/Source/WebCore/ChangeLog      2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -1,3 +1,33 @@
</span><ins>+2021-11-24  Ziran Sun  <zsun@igalia.com>
+
+        [css-grid] Track sizing algorithm not repeated even if used flex fraction would change
+        https://bugs.webkit.org/show_bug.cgi?id=232617
+
+        Reviewed by Javier Fernandez.
+
+        According to https://drafts.csswg.org/css-grid/#algo-flex-tracks, when row height is
+        indefinite, for each grid item that crosses a flexible track, we run the track sizing
+        algorithm under a max-content constraint to find the flex fraction. Then we work out
+        the grid container height as definite, which may cause the flex fraction change. At this
+        point, we need to repeat the track sizing algorithm for row and layout the grid for real.
+        The current implementation doesn't repeat the track sizing algorithm for row.
+
+        The complication with calling RenderGrid::repeatTracksSizingIfNeeded() for flex max-sizing
+        is that it might change a grid item's status of participating in Baseline Alignment for
+        a cyclic sizing dependncy case, which should be definitively excluded. See
+        https://github.com/w3c/csswg-drafts/issues/3046 for more details. This issue should be handled
+        in a seperate bug. This CL only handle test cases that don't have baseline alignment specified. 
+        
+        * rendering/GridTrackSizingAlgorithm.cpp:
+        (WebCore::GridTrackSizingAlgorithm::initializeTrackSizes):
+        (WebCore::GridTrackSizingAlgorithm::setup):
+        (WebCore::GridTrackSizingAlgorithm::reset):
+        * rendering/GridTrackSizingAlgorithm.h:
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::repeatTracksSizingIfNeeded):
+        (WebCore::RenderGrid::layoutBlock):
+        * rendering/RenderGrid.h:
+
</ins><span class="cx"> 2021-11-24  Alan Bujtas  <zalan@apple.com>
</span><span class="cx"> 
</span><span class="cx">         [IFC][Integration] RenderQuote is not a RenderText
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingGridTrackSizingAlgorithmcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp      2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp 2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -1165,6 +1165,7 @@
</span><span class="cx">     ASSERT(m_flexibleSizedTracksIndex.isEmpty());
</span><span class="cx">     ASSERT(m_autoSizedTracksForStretchIndex.isEmpty());
</span><span class="cx">     ASSERT(!m_hasPercentSizedRowsIndefiniteHeight);
</span><ins>+    ASSERT(!m_hasFlexibleMaxTrackBreadth);
</ins><span class="cx"> 
</span><span class="cx">     Vector<GridTrack>& allTracks = tracks(m_direction);
</span><span class="cx">     const bool indefiniteHeight = m_direction == ForRows && !m_renderGrid->hasDefiniteLogicalHeight();
</span><span class="lines">@@ -1187,9 +1188,14 @@
</span><span class="cx">         if (trackSize.hasAutoMaxTrackBreadth() && !trackSize.isFitContent())
</span><span class="cx">             m_autoSizedTracksForStretchIndex.append(i);
</span><span class="cx"> 
</span><del>-        if (!m_hasPercentSizedRowsIndefiniteHeight && indefiniteHeight) {
</del><ins>+        if (indefiniteHeight) {
</ins><span class="cx">             auto& rawTrackSize = rawGridTrackSize(m_direction, i);
</span><del>-            if (rawTrackSize.minTrackBreadth().isPercentage() || rawTrackSize.maxTrackBreadth().isPercentage())
</del><ins>+            // Set the flag for repeating the track sizing algorithm. For flexible tracks, as per spec https://drafts.csswg.org/css-grid/#algo-flex-tracks,
+            // in clause "if the free space is an indefinite length:", it states that "If using this flex fraction would cause the grid to be smaller than
+            // the grid container’s min-width/height (or larger than the grid container’s max-width/height), then redo this step".
+            if (!m_hasFlexibleMaxTrackBreadth && rawTrackSize.maxTrackBreadth().isFlex())
+                m_hasFlexibleMaxTrackBreadth = true;
+            if (!m_hasPercentSizedRowsIndefiniteHeight && (rawTrackSize.minTrackBreadth().isPercentage() || rawTrackSize.maxTrackBreadth().isPercentage()))
</ins><span class="cx">                 m_hasPercentSizedRowsIndefiniteHeight = true;
</span><span class="cx">         }
</span><span class="cx">     }
</span><span class="lines">@@ -1361,6 +1367,7 @@
</span><span class="cx"> 
</span><span class="cx">     m_needsSetup = false;
</span><span class="cx">     m_hasPercentSizedRowsIndefiniteHeight = false;
</span><ins>+    m_hasFlexibleMaxTrackBreadth = false;
</ins><span class="cx"> 
</span><span class="cx">     computeBaselineAlignmentContext();
</span><span class="cx"> }
</span><span class="lines">@@ -1432,6 +1439,7 @@
</span><span class="cx">     setAvailableSpace(ForRows, std::nullopt);
</span><span class="cx">     setAvailableSpace(ForColumns, std::nullopt);
</span><span class="cx">     m_hasPercentSizedRowsIndefiniteHeight = false;
</span><ins>+    m_hasFlexibleMaxTrackBreadth = false;
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #if ASSERT_ENABLED
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingGridTrackSizingAlgorithmh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h        2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h   2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -143,6 +143,8 @@
</span><span class="cx">     LayoutUnit computeTrackBasedSize() const;
</span><span class="cx"> 
</span><span class="cx">     bool hasAnyPercentSizedRowsIndefiniteHeight() const { return m_hasPercentSizedRowsIndefiniteHeight; }
</span><ins>+    bool hasAnyFlexibleMaxTrackBreadth() const { return m_hasFlexibleMaxTrackBreadth; }
+    bool hasAnyBaselineAlignmentItem() const { return !m_columnBaselineItemsMap.isEmpty() || !m_rowBaselineItemsMap.isEmpty(); }
</ins><span class="cx"> 
</span><span class="cx"> #if ASSERT_ENABLED
</span><span class="cx">     bool tracksAreWiderThanMinTrackBreadth() const;
</span><span class="lines">@@ -199,6 +201,7 @@
</span><span class="cx">     bool wasSetup() const { return !!m_strategy; }
</span><span class="cx">     bool m_needsSetup { true };
</span><span class="cx">     bool m_hasPercentSizedRowsIndefiniteHeight { false };
</span><ins>+    bool m_hasFlexibleMaxTrackBreadth { false };
</ins><span class="cx">     std::optional<LayoutUnit> m_availableSpaceRows;
</span><span class="cx">     std::optional<LayoutUnit> m_availableSpaceColumns;
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderGridcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderGrid.cpp    2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp       2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -161,7 +161,14 @@
</span><span class="cx">     // a new cycle of the sizing algorithm; there may be more. In addition, not all the
</span><span class="cx">     // cases with orthogonal flows require this extra cycle; we need a more specific
</span><span class="cx">     // condition to detect whether child's min-content contribution has changed or not.
</span><del>-    if (m_hasAnyOrthogonalItem || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight() || m_hasAspectRatioBlockSizeDependentItem) {
</del><ins>+    // The complication with repeating the track sizing algorithm for flex max-sizing is that
+    // it might change a grid item's status of participating in Baseline Alignment for
+    // a cyclic sizing dependncy case, which should be definitively excluded. See
+    // https://github.com/w3c/csswg-drafts/issues/3046 for details.
+    // FIXME: we are avoiding repeating the track sizing algorithm for grid item with baseline alignment
+    // here in the case of using flex max-sizing functions. We probably also need to investigate whether
+    // it is applicable for the case of percent-sized rows with indefinite height as well.
+    if (m_hasAnyOrthogonalItem || m_trackSizingAlgorithm.hasAnyPercentSizedRowsIndefiniteHeight() || (m_trackSizingAlgorithm.hasAnyFlexibleMaxTrackBreadth() && !m_trackSizingAlgorithm.hasAnyBaselineAlignmentItem()) || m_hasAspectRatioBlockSizeDependentItem) {
</ins><span class="cx">         computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
</span><span class="cx">         computeContentPositionAndDistributionOffset(ForColumns, m_trackSizingAlgorithm.freeSpace(ForColumns).value(), nonCollapsedTracks(ForColumns));
</span><span class="cx">         computeTrackSizesForDefiniteSize(ForRows, availableSpaceForRows);
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderGridh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderGrid.h (286147 => 286148)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderGrid.h      2021-11-24 14:14:28 UTC (rev 286147)
+++ trunk/Source/WebCore/rendering/RenderGrid.h 2021-11-24 15:04:31 UTC (rev 286148)
</span><span class="lines">@@ -207,6 +207,7 @@
</span><span class="cx">     bool m_hasAnyOrthogonalItem {false};
</span><span class="cx">     bool m_hasAspectRatioBlockSizeDependentItem { false };
</span><span class="cx">     bool m_baselineItemsCached {false};
</span><ins>+    bool m_hasAnyBaselineAlignmentItem { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> } // namespace WebCore
</span></span></pre>
</div>
</div>

</body>
</html>