<!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>[212823] trunk/Source/WebCore</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/212823">212823</a></dd>
<dt>Author</dt> <dd>svillar@igalia.com</dd>
<dt>Date</dt> <dd>2017-02-22 03:44:15 -0800 (Wed, 22 Feb 2017)</dd>
</dl>

<h3>Log Message</h3>
<pre>[css-grid] Move the track sizing algorithm to its own class
https://bugs.webkit.org/show_bug.cgi?id=167988

Reviewed by Manuel Rego Casasnovas.

This is about moving the track sizing algorithm code out of RenderGrid to a new class
GridTrackSizingAlgorithm, making RenderGrid more compact and easy to maintain. A nice side
effect of this patch is the removal of the GridSizingData structure as it is no longer
needed. All the data structures in that class were transferred to GridTrackSizingAlgorithm
as private attribute members. The GridTrack class was also moved to the new file.

The algorithm execution starts with the call to run(). It's mandatory to call setup() before
any call to run() in order to properly configure the behaviour of the algorithm. You can
call setup() &amp; run() multiple times for a single layout operation (normally twice, one for
columns and another one for rows). The algorithm uses a state machine to verify that the
client issues the calls in the proper order (i.e. first columns and then rows). After
finishing the layout, the client should call reset() to allow the algorithm to perform
cleanups and to prepare itself for another round of calls.

In order to implement the different behaviours of the algorithm depending on whether the
available size is definite or not, a strategy pattern was implemented in the
GridTrackSizingAlgorithmStrategy class. It has two subclasses, one for definite sizes and
another one for indefinite ones.

We took advantage of this change to perform some renames of the track sizing algorithm
methods that were still using the names from the first versions of the specs. Not only that,
the original track sizing algorithm method (computeUsedBreadthOfGridTracks) was split in 4
different parts representing the 4 steps of the algorithm.

No new tests as this is about moving code and refactoring.

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* rendering/GridTrackSizingAlgorithm.cpp: Added.
(WebCore::GridTrack::baseSize):
(WebCore::GridTrack::growthLimit):
(WebCore::GridTrack::setBaseSize):
(WebCore::GridTrack::setGrowthLimit):
(WebCore::GridTrack::growthLimitIfNotInfinite):
(WebCore::GridTrack::setTempSize):
(WebCore::GridTrack::growTempSize):
(WebCore::GridTrack::setGrowthLimitCap):
(WebCore::GridTrack::ensureGrowthLimitIsBiggerThanBaseSize):
(WebCore::shouldClearOverrideContainingBlockContentSizeForChild):
(WebCore::hasOverrideContainingBlockContentSizeForChild):
(WebCore::setOverrideContainingBlockContentSizeForChild):
(WebCore::flowAwareDirectionForChild):
(WebCore::overrideContainingBlockContentSizeForChild):
(WebCore::computeMarginLogicalSizeForChild):
(WebCore::marginIntrinsicLogicalWidthForChild):
(WebCore::GridTrackSizingAlgorithm::setFreeSpace):
(WebCore::GridTrackSizingAlgorithm::rawGridTrackSize):
(WebCore::GridTrackSizingAlgorithm::computeTrackBasedSize):
(WebCore::GridTrackSizingAlgorithm::initialBaseSize):
(WebCore::GridTrackSizingAlgorithm::initialGrowthLimit):
(WebCore::GridTrackSizingAlgorithm::sizeTrackToFitNonSpanningItem):
(WebCore::GridTrackSizingAlgorithm::spanningItemCrossesFlexibleSizedTracks):
(WebCore::GridItemWithSpan::GridItemWithSpan):
(WebCore::GridItemWithSpan::gridItem):
(WebCore::GridItemWithSpan::span):
(WebCore::GridItemWithSpan::operator&lt;):
(WebCore::GridTrackSizingAlgorithm::itemSizeForTrackSizeComputationPhase):
(WebCore::shouldProcessTrackForTrackSizeComputationPhase):
(WebCore::trackSizeForTrackSizeComputationPhase):
(WebCore::updateTrackSizeForTrackSizeComputationPhase):
(WebCore::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase):
(WebCore::markAsInfinitelyGrowableForTrackSizeComputationPhase):
(WebCore::GridTrackSizingAlgorithm::increaseSizesToAccommodateSpanningItems):
(WebCore::sortByGridTrackGrowthPotential):
(WebCore::clampGrowthShareIfNeeded):
(WebCore::GridTrackSizingAlgorithm::distributeSpaceToTracks):
(WebCore::GridTrackSizingAlgorithm::assumedRowsSizeForOrthogonalChild):
(WebCore::GridTrackSizingAlgorithm::gridAreaBreadthForChild):
(WebCore::GridTrackSizingAlgorithm::gridTrackSize):
(WebCore::GridTrackSizingAlgorithm::computeFlexFactorUnitSize):
(WebCore::GridTrackSizingAlgorithm::computeFlexSizedTracksGrowth):
(WebCore::GridTrackSizingAlgorithm::findFrUnitSize):
(WebCore::GridTrackSizingAlgorithm::computeGridContainerIntrinsicSizes):
(WebCore::GridTrackSizingAlgorithmStrategy::logicalHeightForChild):
(WebCore::GridTrackSizingAlgorithmStrategy::minContentForChild):
(WebCore::GridTrackSizingAlgorithmStrategy::maxContentForChild):
(WebCore::GridTrackSizingAlgorithmStrategy::minSizeForChild):
(WebCore::GridTrackSizingAlgorithmStrategy::updateOverrideContainingBlockContentSizeForChild):
(WebCore::IndefiniteSizeStrategy::minLogicalWidthForChild):
(WebCore::IndefiniteSizeStrategy::layoutGridItemForMinSizeComputation):
(WebCore::IndefiniteSizeStrategy::maximizeTracks):
(WebCore::normalizedFlexFraction):
(WebCore::IndefiniteSizeStrategy::findUsedFlexFraction):
(WebCore::IndefiniteSizeStrategy::recomputeUsedFlexFractionIfNeeded):
(WebCore::DefiniteSizeStrategy::minLogicalWidthForChild):
(WebCore::DefiniteSizeStrategy::maximizeTracks):
(WebCore::DefiniteSizeStrategy::layoutGridItemForMinSizeComputation):
(WebCore::DefiniteSizeStrategy::findUsedFlexFraction):
(WebCore::DefiniteSizeStrategy::recomputeUsedFlexFractionIfNeeded):
(WebCore::GridTrackSizingAlgorithm::initializeTrackSizes):
(WebCore::GridTrackSizingAlgorithm::resolveIntrinsicTrackSizes):
(WebCore::GridTrackSizingAlgorithm::stretchFlexibleTracks):
(WebCore::GridTrackSizingAlgorithm::advanceNextState):
(WebCore::GridTrackSizingAlgorithm::isValidTransition):
(WebCore::GridTrackSizingAlgorithm::setup):
(WebCore::GridTrackSizingAlgorithm::run):
(WebCore::GridTrackSizingAlgorithm::reset):
(WebCore::GridTrackSizingAlgorithm::tracksAreWiderThanMinTrackBreadth):
(WebCore::GridTrackSizingAlgorithm::StateMachine::StateMachine):
(WebCore::GridTrackSizingAlgorithm::StateMachine::~StateMachine):
* rendering/GridTrackSizingAlgorithm.h: Added.
(WebCore::GridTrack::GridTrack):
(WebCore::GridTrack::infiniteGrowthPotential):
(WebCore::GridTrack::plannedSize):
(WebCore::GridTrack::setPlannedSize):
(WebCore::GridTrack::tempSize):
(WebCore::GridTrack::infinitelyGrowable):
(WebCore::GridTrack::setInfinitelyGrowable):
(WebCore::GridTrack::growthLimitCap):
(WebCore::GridTrack::growthLimitIsInfinite):
(WebCore::GridTrack::isGrowthLimitBiggerThanBaseSize):
(WebCore::GridTrackSizingAlgorithmStrategy::GridTrackSizingAlgorithmStrategy):
(WebCore::GridTrackSizingAlgorithmStrategy::computeTrackBasedSize):
(WebCore::GridTrackSizingAlgorithmStrategy::direction):
(WebCore::GridTrackSizingAlgorithmStrategy::findFrUnitSize):
(WebCore::GridTrackSizingAlgorithmStrategy::distributeSpaceToTracks):
(WebCore::GridTrackSizingAlgorithmStrategy::renderGrid):
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::RenderGrid):
(WebCore::RenderGrid::computeTrackBasedLogicalHeight):
(WebCore::RenderGrid::computeTrackSizesForDefiniteSize):
(WebCore::RenderGrid::repeatTracksSizingIfNeeded):
(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::computeIntrinsicLogicalWidths):
(WebCore::RenderGrid::computeTrackSizesForIndefiniteSize):
(WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
(WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded):
(WebCore::RenderGrid::layoutGridItems):
(WebCore::RenderGrid::gridAreaBreadthForChildIncludingAlignmentOffsets):
(WebCore::RenderGrid::populateGridPositionsForDirection):
(WebCore::RenderGrid::columnAxisOffsetForChild):
(WebCore::RenderGrid::rowAxisOffsetForChild):
(WebCore::RenderGrid::findChildLogicalPosition):
(WebCore::GridTrack::GridTrack): Deleted.
(WebCore::GridTrack::baseSize): Deleted.
(WebCore::GridTrack::growthLimit): Deleted.
(WebCore::GridTrack::setBaseSize): Deleted.
(WebCore::GridTrack::setGrowthLimit): Deleted.
(WebCore::GridTrack::infiniteGrowthPotential): Deleted.
(WebCore::GridTrack::growthLimitIfNotInfinite): Deleted.
(WebCore::GridTrack::plannedSize): Deleted.
(WebCore::GridTrack::setPlannedSize): Deleted.
(WebCore::GridTrack::tempSize): Deleted.
(WebCore::GridTrack::setTempSize): Deleted.
(WebCore::GridTrack::growTempSize): Deleted.
(WebCore::GridTrack::infinitelyGrowable): Deleted.
(WebCore::GridTrack::setInfinitelyGrowable): Deleted.
(WebCore::GridTrack::setGrowthLimitCap): Deleted.
(WebCore::GridTrack::growthLimitCap): Deleted.
(WebCore::GridTrack::growthLimitIsInfinite): Deleted.
(WebCore::GridTrack::isGrowthLimitBiggerThanBaseSize): Deleted.
(WebCore::GridTrack::ensureGrowthLimitIsBiggerThanBaseSize): Deleted.
(WebCore::RenderGrid::GridSizingData::GridSizingData): Deleted.
(WebCore::RenderGrid::GridSizingData::freeSpace): Deleted.
(WebCore::RenderGrid::GridSizingData::availableSpace): Deleted.
(WebCore::RenderGrid::GridSizingData::setAvailableSpace): Deleted.
(WebCore::RenderGrid::GridSizingData::advanceNextState): Deleted.
(WebCore::RenderGrid::GridSizingData::isValidTransition): Deleted.
(WebCore::RenderGrid::GridSizingData::grid): Deleted.
(WebCore::RenderGrid::GridSizingData::setFreeSpace): Deleted.
(WebCore::RenderGrid::computeTrackSizesForDirection): Deleted.
(WebCore::RenderGrid::computeIntrinsicLogicalHeight): Deleted.
(WebCore::normalizedFlexFraction): Deleted.
(WebCore::RenderGrid::computeUsedBreadthOfGridTracks): Deleted.
(WebCore::RenderGrid::computeFlexSizedTracksGrowth): Deleted.
(WebCore::RenderGrid::computeUsedBreadthOfMinLength): Deleted.
(WebCore::RenderGrid::computeUsedBreadthOfMaxLength): Deleted.
(WebCore::RenderGrid::computeFlexFactorUnitSize): Deleted.
(WebCore::RenderGrid::findFlexFactorUnitSize): Deleted.
(WebCore::hasOverrideContainingBlockContentSizeForChild): Deleted.
(WebCore::setOverrideContainingBlockContentSizeForChild): Deleted.
(WebCore::shouldClearOverrideContainingBlockContentSizeForChild): Deleted.
(WebCore::RenderGrid::rawGridTrackSize): Deleted.
(WebCore::RenderGrid::gridTrackSize): Deleted.
(WebCore::RenderGrid::logicalHeightForChild): Deleted.
(WebCore::RenderGrid::minSizeForChild): Deleted.
(WebCore::RenderGrid::updateOverrideContainingBlockContentSizeForChild): Deleted.
(WebCore::RenderGrid::minContentForChild): Deleted.
(WebCore::RenderGrid::maxContentForChild): Deleted.
(WebCore::GridItemWithSpan::GridItemWithSpan): Deleted.
(WebCore::GridItemWithSpan::gridItem): Deleted.
(WebCore::GridItemWithSpan::span): Deleted.
(WebCore::GridItemWithSpan::operator&lt;): Deleted.
(WebCore::RenderGrid::spanningItemCrossesFlexibleSizedTracks): Deleted.
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions): Deleted.
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems): Deleted.
(WebCore::trackSizeForTrackSizeComputationPhase): Deleted.
(WebCore::RenderGrid::shouldProcessTrackForTrackSizeComputationPhase): Deleted.
(WebCore::RenderGrid::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase): Deleted.
(WebCore::RenderGrid::markAsInfinitelyGrowableForTrackSizeComputationPhase): Deleted.
(WebCore::RenderGrid::updateTrackSizeForTrackSizeComputationPhase): Deleted.
(WebCore::RenderGrid::currentItemSizeForTrackSizeComputationPhase): Deleted.
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems): Deleted.
(WebCore::sortByGridTrackGrowthPotential): Deleted.
(WebCore::clampGrowthShareIfNeeded): Deleted.
(WebCore::RenderGrid::distributeSpaceToTracks): Deleted.
(WebCore::RenderGrid::tracksAreWiderThanMinTrackBreadth): Deleted.
(WebCore::RenderGrid::assumedRowsSizeForOrthogonalChild): Deleted.
(WebCore::RenderGrid::gridAreaBreadthForChild): Deleted.
* rendering/RenderGrid.h:</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreCMakeListstxt">trunk/Source/WebCore/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</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>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorerenderingGridTrackSizingAlgorithmcpp">trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingGridTrackSizingAlgorithmh">trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/CMakeLists.txt (212822 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/CMakeLists.txt        2017-02-22 11:34:46 UTC (rev 212822)
+++ trunk/Source/WebCore/CMakeLists.txt        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -2375,6 +2375,7 @@
</span><span class="cx">     rendering/FloatingObjects.cpp
</span><span class="cx">     rendering/FlowThreadController.cpp
</span><span class="cx">     rendering/Grid.cpp
</span><ins>+    rendering/GridTrackSizingAlgorithm.cpp
</ins><span class="cx">     rendering/HitTestLocation.cpp
</span><span class="cx">     rendering/HitTestResult.cpp
</span><span class="cx">     rendering/HitTestingTransformState.cpp
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (212822 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2017-02-22 11:34:46 UTC (rev 212822)
+++ trunk/Source/WebCore/ChangeLog        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -1,3 +1,211 @@
</span><ins>+2017-02-08  Sergio Villar Senin  &lt;svillar@igalia.com&gt;
+
+        [css-grid] Move the track sizing algorithm to its own class
+        https://bugs.webkit.org/show_bug.cgi?id=167988
+
+        Reviewed by Manuel Rego Casasnovas.
+
+        This is about moving the track sizing algorithm code out of RenderGrid to a new class
+        GridTrackSizingAlgorithm, making RenderGrid more compact and easy to maintain. A nice side
+        effect of this patch is the removal of the GridSizingData structure as it is no longer
+        needed. All the data structures in that class were transferred to GridTrackSizingAlgorithm
+        as private attribute members. The GridTrack class was also moved to the new file.
+
+        The algorithm execution starts with the call to run(). It's mandatory to call setup() before
+        any call to run() in order to properly configure the behaviour of the algorithm. You can
+        call setup() &amp; run() multiple times for a single layout operation (normally twice, one for
+        columns and another one for rows). The algorithm uses a state machine to verify that the
+        client issues the calls in the proper order (i.e. first columns and then rows). After
+        finishing the layout, the client should call reset() to allow the algorithm to perform
+        cleanups and to prepare itself for another round of calls.
+
+        In order to implement the different behaviours of the algorithm depending on whether the
+        available size is definite or not, a strategy pattern was implemented in the
+        GridTrackSizingAlgorithmStrategy class. It has two subclasses, one for definite sizes and
+        another one for indefinite ones.
+
+        We took advantage of this change to perform some renames of the track sizing algorithm
+        methods that were still using the names from the first versions of the specs. Not only that,
+        the original track sizing algorithm method (computeUsedBreadthOfGridTracks) was split in 4
+        different parts representing the 4 steps of the algorithm.
+
+        No new tests as this is about moving code and refactoring.
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * rendering/GridTrackSizingAlgorithm.cpp: Added.
+        (WebCore::GridTrack::baseSize):
+        (WebCore::GridTrack::growthLimit):
+        (WebCore::GridTrack::setBaseSize):
+        (WebCore::GridTrack::setGrowthLimit):
+        (WebCore::GridTrack::growthLimitIfNotInfinite):
+        (WebCore::GridTrack::setTempSize):
+        (WebCore::GridTrack::growTempSize):
+        (WebCore::GridTrack::setGrowthLimitCap):
+        (WebCore::GridTrack::ensureGrowthLimitIsBiggerThanBaseSize):
+        (WebCore::shouldClearOverrideContainingBlockContentSizeForChild):
+        (WebCore::hasOverrideContainingBlockContentSizeForChild):
+        (WebCore::setOverrideContainingBlockContentSizeForChild):
+        (WebCore::flowAwareDirectionForChild):
+        (WebCore::overrideContainingBlockContentSizeForChild):
+        (WebCore::computeMarginLogicalSizeForChild):
+        (WebCore::marginIntrinsicLogicalWidthForChild):
+        (WebCore::GridTrackSizingAlgorithm::setFreeSpace):
+        (WebCore::GridTrackSizingAlgorithm::rawGridTrackSize):
+        (WebCore::GridTrackSizingAlgorithm::computeTrackBasedSize):
+        (WebCore::GridTrackSizingAlgorithm::initialBaseSize):
+        (WebCore::GridTrackSizingAlgorithm::initialGrowthLimit):
+        (WebCore::GridTrackSizingAlgorithm::sizeTrackToFitNonSpanningItem):
+        (WebCore::GridTrackSizingAlgorithm::spanningItemCrossesFlexibleSizedTracks):
+        (WebCore::GridItemWithSpan::GridItemWithSpan):
+        (WebCore::GridItemWithSpan::gridItem):
+        (WebCore::GridItemWithSpan::span):
+        (WebCore::GridItemWithSpan::operator&lt;):
+        (WebCore::GridTrackSizingAlgorithm::itemSizeForTrackSizeComputationPhase):
+        (WebCore::shouldProcessTrackForTrackSizeComputationPhase):
+        (WebCore::trackSizeForTrackSizeComputationPhase):
+        (WebCore::updateTrackSizeForTrackSizeComputationPhase):
+        (WebCore::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase):
+        (WebCore::markAsInfinitelyGrowableForTrackSizeComputationPhase):
+        (WebCore::GridTrackSizingAlgorithm::increaseSizesToAccommodateSpanningItems):
+        (WebCore::sortByGridTrackGrowthPotential):
+        (WebCore::clampGrowthShareIfNeeded):
+        (WebCore::GridTrackSizingAlgorithm::distributeSpaceToTracks):
+        (WebCore::GridTrackSizingAlgorithm::assumedRowsSizeForOrthogonalChild):
+        (WebCore::GridTrackSizingAlgorithm::gridAreaBreadthForChild):
+        (WebCore::GridTrackSizingAlgorithm::gridTrackSize):
+        (WebCore::GridTrackSizingAlgorithm::computeFlexFactorUnitSize):
+        (WebCore::GridTrackSizingAlgorithm::computeFlexSizedTracksGrowth):
+        (WebCore::GridTrackSizingAlgorithm::findFrUnitSize):
+        (WebCore::GridTrackSizingAlgorithm::computeGridContainerIntrinsicSizes):
+        (WebCore::GridTrackSizingAlgorithmStrategy::logicalHeightForChild):
+        (WebCore::GridTrackSizingAlgorithmStrategy::minContentForChild):
+        (WebCore::GridTrackSizingAlgorithmStrategy::maxContentForChild):
+        (WebCore::GridTrackSizingAlgorithmStrategy::minSizeForChild):
+        (WebCore::GridTrackSizingAlgorithmStrategy::updateOverrideContainingBlockContentSizeForChild):
+        (WebCore::IndefiniteSizeStrategy::minLogicalWidthForChild):
+        (WebCore::IndefiniteSizeStrategy::layoutGridItemForMinSizeComputation):
+        (WebCore::IndefiniteSizeStrategy::maximizeTracks):
+        (WebCore::normalizedFlexFraction):
+        (WebCore::IndefiniteSizeStrategy::findUsedFlexFraction):
+        (WebCore::IndefiniteSizeStrategy::recomputeUsedFlexFractionIfNeeded):
+        (WebCore::DefiniteSizeStrategy::minLogicalWidthForChild):
+        (WebCore::DefiniteSizeStrategy::maximizeTracks):
+        (WebCore::DefiniteSizeStrategy::layoutGridItemForMinSizeComputation):
+        (WebCore::DefiniteSizeStrategy::findUsedFlexFraction):
+        (WebCore::DefiniteSizeStrategy::recomputeUsedFlexFractionIfNeeded):
+        (WebCore::GridTrackSizingAlgorithm::initializeTrackSizes):
+        (WebCore::GridTrackSizingAlgorithm::resolveIntrinsicTrackSizes):
+        (WebCore::GridTrackSizingAlgorithm::stretchFlexibleTracks):
+        (WebCore::GridTrackSizingAlgorithm::advanceNextState):
+        (WebCore::GridTrackSizingAlgorithm::isValidTransition):
+        (WebCore::GridTrackSizingAlgorithm::setup):
+        (WebCore::GridTrackSizingAlgorithm::run):
+        (WebCore::GridTrackSizingAlgorithm::reset):
+        (WebCore::GridTrackSizingAlgorithm::tracksAreWiderThanMinTrackBreadth):
+        (WebCore::GridTrackSizingAlgorithm::StateMachine::StateMachine):
+        (WebCore::GridTrackSizingAlgorithm::StateMachine::~StateMachine):
+        * rendering/GridTrackSizingAlgorithm.h: Added.
+        (WebCore::GridTrack::GridTrack):
+        (WebCore::GridTrack::infiniteGrowthPotential):
+        (WebCore::GridTrack::plannedSize):
+        (WebCore::GridTrack::setPlannedSize):
+        (WebCore::GridTrack::tempSize):
+        (WebCore::GridTrack::infinitelyGrowable):
+        (WebCore::GridTrack::setInfinitelyGrowable):
+        (WebCore::GridTrack::growthLimitCap):
+        (WebCore::GridTrack::growthLimitIsInfinite):
+        (WebCore::GridTrack::isGrowthLimitBiggerThanBaseSize):
+        (WebCore::GridTrackSizingAlgorithmStrategy::GridTrackSizingAlgorithmStrategy):
+        (WebCore::GridTrackSizingAlgorithmStrategy::computeTrackBasedSize):
+        (WebCore::GridTrackSizingAlgorithmStrategy::direction):
+        (WebCore::GridTrackSizingAlgorithmStrategy::findFrUnitSize):
+        (WebCore::GridTrackSizingAlgorithmStrategy::distributeSpaceToTracks):
+        (WebCore::GridTrackSizingAlgorithmStrategy::renderGrid):
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::RenderGrid):
+        (WebCore::RenderGrid::computeTrackBasedLogicalHeight):
+        (WebCore::RenderGrid::computeTrackSizesForDefiniteSize):
+        (WebCore::RenderGrid::repeatTracksSizingIfNeeded):
+        (WebCore::RenderGrid::layoutBlock):
+        (WebCore::RenderGrid::computeIntrinsicLogicalWidths):
+        (WebCore::RenderGrid::computeTrackSizesForIndefiniteSize):
+        (WebCore::RenderGrid::placeSpecifiedMajorAxisItemsOnGrid):
+        (WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded):
+        (WebCore::RenderGrid::layoutGridItems):
+        (WebCore::RenderGrid::gridAreaBreadthForChildIncludingAlignmentOffsets):
+        (WebCore::RenderGrid::populateGridPositionsForDirection):
+        (WebCore::RenderGrid::columnAxisOffsetForChild):
+        (WebCore::RenderGrid::rowAxisOffsetForChild):
+        (WebCore::RenderGrid::findChildLogicalPosition):
+        (WebCore::GridTrack::GridTrack): Deleted.
+        (WebCore::GridTrack::baseSize): Deleted.
+        (WebCore::GridTrack::growthLimit): Deleted.
+        (WebCore::GridTrack::setBaseSize): Deleted.
+        (WebCore::GridTrack::setGrowthLimit): Deleted.
+        (WebCore::GridTrack::infiniteGrowthPotential): Deleted.
+        (WebCore::GridTrack::growthLimitIfNotInfinite): Deleted.
+        (WebCore::GridTrack::plannedSize): Deleted.
+        (WebCore::GridTrack::setPlannedSize): Deleted.
+        (WebCore::GridTrack::tempSize): Deleted.
+        (WebCore::GridTrack::setTempSize): Deleted.
+        (WebCore::GridTrack::growTempSize): Deleted.
+        (WebCore::GridTrack::infinitelyGrowable): Deleted.
+        (WebCore::GridTrack::setInfinitelyGrowable): Deleted.
+        (WebCore::GridTrack::setGrowthLimitCap): Deleted.
+        (WebCore::GridTrack::growthLimitCap): Deleted.
+        (WebCore::GridTrack::growthLimitIsInfinite): Deleted.
+        (WebCore::GridTrack::isGrowthLimitBiggerThanBaseSize): Deleted.
+        (WebCore::GridTrack::ensureGrowthLimitIsBiggerThanBaseSize): Deleted.
+        (WebCore::RenderGrid::GridSizingData::GridSizingData): Deleted.
+        (WebCore::RenderGrid::GridSizingData::freeSpace): Deleted.
+        (WebCore::RenderGrid::GridSizingData::availableSpace): Deleted.
+        (WebCore::RenderGrid::GridSizingData::setAvailableSpace): Deleted.
+        (WebCore::RenderGrid::GridSizingData::advanceNextState): Deleted.
+        (WebCore::RenderGrid::GridSizingData::isValidTransition): Deleted.
+        (WebCore::RenderGrid::GridSizingData::grid): Deleted.
+        (WebCore::RenderGrid::GridSizingData::setFreeSpace): Deleted.
+        (WebCore::RenderGrid::computeTrackSizesForDirection): Deleted.
+        (WebCore::RenderGrid::computeIntrinsicLogicalHeight): Deleted.
+        (WebCore::normalizedFlexFraction): Deleted.
+        (WebCore::RenderGrid::computeUsedBreadthOfGridTracks): Deleted.
+        (WebCore::RenderGrid::computeFlexSizedTracksGrowth): Deleted.
+        (WebCore::RenderGrid::computeUsedBreadthOfMinLength): Deleted.
+        (WebCore::RenderGrid::computeUsedBreadthOfMaxLength): Deleted.
+        (WebCore::RenderGrid::computeFlexFactorUnitSize): Deleted.
+        (WebCore::RenderGrid::findFlexFactorUnitSize): Deleted.
+        (WebCore::hasOverrideContainingBlockContentSizeForChild): Deleted.
+        (WebCore::setOverrideContainingBlockContentSizeForChild): Deleted.
+        (WebCore::shouldClearOverrideContainingBlockContentSizeForChild): Deleted.
+        (WebCore::RenderGrid::rawGridTrackSize): Deleted.
+        (WebCore::RenderGrid::gridTrackSize): Deleted.
+        (WebCore::RenderGrid::logicalHeightForChild): Deleted.
+        (WebCore::RenderGrid::minSizeForChild): Deleted.
+        (WebCore::RenderGrid::updateOverrideContainingBlockContentSizeForChild): Deleted.
+        (WebCore::RenderGrid::minContentForChild): Deleted.
+        (WebCore::RenderGrid::maxContentForChild): Deleted.
+        (WebCore::GridItemWithSpan::GridItemWithSpan): Deleted.
+        (WebCore::GridItemWithSpan::gridItem): Deleted.
+        (WebCore::GridItemWithSpan::span): Deleted.
+        (WebCore::GridItemWithSpan::operator&lt;): Deleted.
+        (WebCore::RenderGrid::spanningItemCrossesFlexibleSizedTracks): Deleted.
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctions): Deleted.
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems): Deleted.
+        (WebCore::trackSizeForTrackSizeComputationPhase): Deleted.
+        (WebCore::RenderGrid::shouldProcessTrackForTrackSizeComputationPhase): Deleted.
+        (WebCore::RenderGrid::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase): Deleted.
+        (WebCore::RenderGrid::markAsInfinitelyGrowableForTrackSizeComputationPhase): Deleted.
+        (WebCore::RenderGrid::updateTrackSizeForTrackSizeComputationPhase): Deleted.
+        (WebCore::RenderGrid::currentItemSizeForTrackSizeComputationPhase): Deleted.
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems): Deleted.
+        (WebCore::sortByGridTrackGrowthPotential): Deleted.
+        (WebCore::clampGrowthShareIfNeeded): Deleted.
+        (WebCore::RenderGrid::distributeSpaceToTracks): Deleted.
+        (WebCore::RenderGrid::tracksAreWiderThanMinTrackBreadth): Deleted.
+        (WebCore::RenderGrid::assumedRowsSizeForOrthogonalChild): Deleted.
+        (WebCore::RenderGrid::gridAreaBreadthForChild): Deleted.
+        * rendering/RenderGrid.h:
+
</ins><span class="cx"> 2017-02-22  Per Arne Vollan  &lt;pvollan@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         [Win] Crash under CACFLayerTreeHost::acceleratedCompositingAvailable().
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (212822 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-02-22 11:34:46 UTC (rev 212822)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -6218,6 +6218,8 @@
</span><span class="cx">                 E1284AEA10447DEE00EAEB52 /* PageTransitionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1284AE910447DEE00EAEB52 /* PageTransitionEvent.cpp */; };
</span><span class="cx">                 E1284BB110449FFA00EAEB52 /* JSPageTransitionEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E1284BAF10449FFA00EAEB52 /* JSPageTransitionEvent.h */; };
</span><span class="cx">                 E1284BB210449FFA00EAEB52 /* JSPageTransitionEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1284BB010449FFA00EAEB52 /* JSPageTransitionEvent.cpp */; };
</span><ins>+                E12DE7171E4B749C00F9ACCF /* GridTrackSizingAlgorithm.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E12DE7151E4B748700F9ACCF /* GridTrackSizingAlgorithm.cpp */; };
+                E12DE7181E4B74A600F9ACCF /* GridTrackSizingAlgorithm.h in Headers */ = {isa = PBXBuildFile; fileRef = E12DE7161E4B748700F9ACCF /* GridTrackSizingAlgorithm.h */; };
</ins><span class="cx">                 E12EDB7B0B308A78002704B6 /* EventTarget.h in Headers */ = {isa = PBXBuildFile; fileRef = E12EDB7A0B308A78002704B6 /* EventTarget.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 E12EDBEA0B308E0B002704B6 /* EventTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E12EDBE90B308E0B002704B6 /* EventTarget.cpp */; };
</span><span class="cx">                 E134F5AB12EE343F004EC58D /* IntRectHash.h in Headers */ = {isa = PBXBuildFile; fileRef = E134F5AA12EE343F004EC58D /* IntRectHash.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="lines">@@ -14361,6 +14363,8 @@
</span><span class="cx">                 E1284AE910447DEE00EAEB52 /* PageTransitionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageTransitionEvent.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E1284BAF10449FFA00EAEB52 /* JSPageTransitionEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSPageTransitionEvent.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E1284BB010449FFA00EAEB52 /* JSPageTransitionEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSPageTransitionEvent.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><ins>+                E12DE7151E4B748700F9ACCF /* GridTrackSizingAlgorithm.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GridTrackSizingAlgorithm.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
+                E12DE7161E4B748700F9ACCF /* GridTrackSizingAlgorithm.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridTrackSizingAlgorithm.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</ins><span class="cx">                 E12EDB7A0B308A78002704B6 /* EventTarget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventTarget.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E12EDBE90B308E0B002704B6 /* EventTarget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventTarget.cpp; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="cx">                 E134F5AA12EE343F004EC58D /* IntRectHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IntRectHash.h; sourceTree = &quot;&lt;group&gt;&quot;; };
</span><span class="lines">@@ -24100,6 +24104,8 @@
</span><span class="cx">                                 935C477409AC4D8D00A6AAB4 /* GapRects.h */,
</span><span class="cx">                                 E112F4701E3A85F200D6CDFD /* Grid.cpp */,
</span><span class="cx">                                 E112F46F1E3A85D800D6CDFD /* Grid.h */,
</span><ins>+                                E12DE7151E4B748700F9ACCF /* GridTrackSizingAlgorithm.cpp */,
+                                E12DE7161E4B748700F9ACCF /* GridTrackSizingAlgorithm.h */,
</ins><span class="cx">                                 4969B0F013D0B33F00DF3521 /* HitTestingTransformState.cpp */,
</span><span class="cx">                                 4969B0F113D0B33F00DF3521 /* HitTestingTransformState.h */,
</span><span class="cx">                                 2D8287F416E4A0380086BD00 /* HitTestLocation.cpp */,
</span><span class="lines">@@ -26168,6 +26174,7 @@
</span><span class="cx">                                 A12705C31656BD6500C2E27C /* GridPosition.h in Headers */,
</span><span class="cx">                                 CDF7483F18FEBCEC0006ECC0 /* GridPositionsResolver.h in Headers */,
</span><span class="cx">                                 A12A1050166444FD008FA311 /* GridTrackSize.h in Headers */,
</span><ins>+                                E12DE7181E4B74A600F9ACCF /* GridTrackSizingAlgorithm.h in Headers */,
</ins><span class="cx">                                 26EA89A71B4F2B75008C5FD2 /* HashableActionList.h in Headers */,
</span><span class="cx">                                 8482B7461198C35400BFB005 /* HashChangeEvent.h in Headers */,
</span><span class="cx">                                 A8748BE012CBF2DC001FBA41 /* HashTools.h in Headers */,
</span><span class="lines">@@ -30003,6 +30010,7 @@
</span><span class="cx">                                 B2A015AA0AF6CD53006BCE0E /* GraphicsTypes.cpp in Sources */,
</span><span class="cx">                                 E112F4711E3A861200D6CDFD /* Grid.cpp in Sources */,
</span><span class="cx">                                 CDF7483E18FEBCEC0006ECC0 /* GridPositionsResolver.cpp in Sources */,
</span><ins>+                                E12DE7171E4B749C00F9ACCF /* GridTrackSizingAlgorithm.cpp in Sources */,
</ins><span class="cx">                                 F55B3DBF1251F12D003EF269 /* HiddenInputType.cpp in Sources */,
</span><span class="cx">                                 515BE19B1D54F6C100DD7C68 /* HIDGamepad.cpp in Sources */,
</span><span class="cx">                                 515BE19D1D54F6C100DD7C68 /* HIDGamepadProvider.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingGridTrackSizingAlgorithmcpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp (0 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp                                (rev 0)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -0,0 +1,1202 @@
</span><ins>+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include &quot;config.h&quot;
+#include &quot;GridTrackSizingAlgorithm.h&quot;
+
+#include &quot;Grid.h&quot;
+#include &quot;GridArea.h&quot;
+#include &quot;RenderGrid.h&quot;
+
+namespace WebCore {
+
+const LayoutUnit&amp; GridTrack::baseSize() const
+{
+    ASSERT(isGrowthLimitBiggerThanBaseSize());
+    return m_baseSize;
+}
+
+const LayoutUnit&amp; GridTrack::growthLimit() const
+{
+    ASSERT(isGrowthLimitBiggerThanBaseSize());
+    ASSERT(!m_growthLimitCap || m_growthLimitCap.value() &gt;= m_growthLimit || m_baseSize &gt;= m_growthLimitCap.value());
+    return m_growthLimit;
+}
+
+void GridTrack::setBaseSize(LayoutUnit baseSize)
+{
+    m_baseSize = baseSize;
+    ensureGrowthLimitIsBiggerThanBaseSize();
+}
+
+void GridTrack::setGrowthLimit(LayoutUnit growthLimit)
+{
+    m_growthLimit = growthLimit == infinity ? growthLimit : std::min(growthLimit, m_growthLimitCap.value_or(growthLimit));
+    ensureGrowthLimitIsBiggerThanBaseSize();
+}
+
+const LayoutUnit&amp; GridTrack::growthLimitIfNotInfinite() const
+{
+    ASSERT(isGrowthLimitBiggerThanBaseSize());
+    return m_growthLimit == infinity ? m_baseSize : m_growthLimit;
+}
+
+void GridTrack::setTempSize(const LayoutUnit&amp; tempSize)
+{
+    ASSERT(tempSize &gt;= 0);
+    ASSERT(growthLimitIsInfinite() || growthLimit() &gt;= tempSize);
+    m_tempSize = tempSize;
+}
+
+void GridTrack::growTempSize(const LayoutUnit&amp; tempSize)
+{
+    ASSERT(tempSize &gt;= 0);
+    m_tempSize += tempSize;
+}
+
+void GridTrack::setGrowthLimitCap(std::optional&lt;LayoutUnit&gt; growthLimitCap)
+{
+    ASSERT(!growthLimitCap || growthLimitCap.value() &gt;= 0);
+    m_growthLimitCap = growthLimitCap;
+}
+
+void GridTrack::ensureGrowthLimitIsBiggerThanBaseSize()
+{
+    if (m_growthLimit != infinity &amp;&amp; m_growthLimit &lt; m_baseSize)
+        m_growthLimit = m_baseSize;
+}
+
+// Static helper methods.
+
+static bool shouldClearOverrideContainingBlockContentSizeForChild(const RenderBox&amp; child, GridTrackSizingDirection direction)
+{
+    if (direction == ForColumns)
+        return child.hasRelativeLogicalWidth() || child.style().logicalWidth().isIntrinsicOrAuto();
+    return child.hasRelativeLogicalHeight() || child.style().logicalHeight().isIntrinsicOrAuto();
+}
+
+static bool hasOverrideContainingBlockContentSizeForChild(const RenderBox&amp; child, GridTrackSizingDirection direction)
+{
+    return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidth() : child.hasOverrideContainingBlockLogicalHeight();
+}
+
+static void setOverrideContainingBlockContentSizeForChild(RenderBox&amp; child, GridTrackSizingDirection direction, std::optional&lt;LayoutUnit&gt; size)
+{
+    if (direction == ForColumns)
+        child.setOverrideContainingBlockContentLogicalWidth(size);
+    else
+        child.setOverrideContainingBlockContentLogicalHeight(size);
+}
+
+static GridTrackSizingDirection flowAwareDirectionForChild(const RenderGrid* grid, const RenderBox&amp; child, GridTrackSizingDirection direction)
+{
+    ASSERT(grid);
+    return !grid-&gt;isOrthogonalChild(child) ? direction : (direction == ForColumns ? ForRows : ForColumns);
+}
+
+static std::optional&lt;LayoutUnit&gt; overrideContainingBlockContentSizeForChild(const RenderBox&amp; child, GridTrackSizingDirection direction)
+{
+    return direction == ForColumns ? child.overrideContainingBlockContentLogicalWidth() : child.overrideContainingBlockContentLogicalHeight();
+}
+
+static LayoutUnit computeMarginLogicalSizeForChild(GridTrackSizingDirection direction, const RenderGrid&amp; renderGrid, const RenderBox&amp; child)
+{
+    if (!child.style().hasMargin())
+        return 0;
+
+    LayoutUnit marginStart;
+    LayoutUnit marginEnd;
+    if (direction == ForColumns)
+        child.computeInlineDirectionMargins(renderGrid, child.containingBlockLogicalWidthForContentInRegion(nullptr), child.logicalWidth(), marginStart, marginEnd);
+    else
+        child.computeBlockDirectionMargins(renderGrid, marginStart, marginEnd);
+
+    return marginStart + marginEnd;
+}
+
+// FIXME: we borrowed this from RenderBlock. We cannot call it from here because it's protected for RenderObjects.
+static LayoutUnit marginIntrinsicLogicalWidthForChild(const RenderGrid* renderGrid, RenderBox&amp; child)
+{
+    // A margin has three types: fixed, percentage, and auto (variable).
+    // Auto and percentage margins become 0 when computing min/max width.
+    // Fixed margins can be added in as is.
+    Length marginLeft = child.style().marginStartUsing(&amp;renderGrid-&gt;style());
+    Length marginRight = child.style().marginEndUsing(&amp;renderGrid-&gt;style());
+    LayoutUnit margin = 0;
+    if (marginLeft.isFixed())
+        margin += marginLeft.value();
+    if (marginRight.isFixed())
+        margin += marginRight.value();
+    return margin;
+}
+
+// GridTrackSizingAlgorithm private.
+
+void GridTrackSizingAlgorithm::setFreeSpace(GridTrackSizingDirection direction, std::optional&lt;LayoutUnit&gt; freeSpace)
+{
+    if (direction == ForColumns)
+        m_freeSpaceColumns = freeSpace;
+    else
+        m_freeSpaceRows = freeSpace;
+}
+
+const GridTrackSize&amp; GridTrackSizingAlgorithm::rawGridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex) const
+{
+    bool isRowAxis = direction == ForColumns;
+    auto&amp; renderStyle = m_renderGrid-&gt;style();
+    auto&amp; trackStyles = isRowAxis ? renderStyle.gridColumns() : renderStyle.gridRows();
+    auto&amp; autoRepeatTrackStyles = isRowAxis ? renderStyle.gridAutoRepeatColumns() : renderStyle.gridAutoRepeatRows();
+    auto&amp; autoTrackStyles = isRowAxis ? renderStyle.gridAutoColumns() : renderStyle.gridAutoRows();
+    unsigned insertionPoint = isRowAxis ? renderStyle.gridAutoRepeatColumnsInsertionPoint() : renderStyle.gridAutoRepeatRowsInsertionPoint();
+    unsigned autoRepeatTracksCount = m_grid.autoRepeatTracks(direction);
+
+    // We should not use GridPositionsResolver::explicitGridXXXCount() for this because the
+    // explicit grid might be larger than the number of tracks in grid-template-rows|columns (if
+    // grid-template-areas is specified for example).
+    unsigned explicitTracksCount = trackStyles.size() + autoRepeatTracksCount;
+
+    int untranslatedIndexAsInt = translatedIndex + m_grid.smallestTrackStart(direction);
+    unsigned autoTrackStylesSize = autoTrackStyles.size();
+    if (untranslatedIndexAsInt &lt; 0) {
+        int index = untranslatedIndexAsInt % static_cast&lt;int&gt;(autoTrackStylesSize);
+        // We need to traspose the index because the first negative implicit line will get the last defined auto track and so on.
+        index += index ? autoTrackStylesSize : 0;
+        ASSERT(index &gt;= 0);
+        return autoTrackStyles[index];
+    }
+
+    unsigned untranslatedIndex = static_cast&lt;unsigned&gt;(untranslatedIndexAsInt);
+    if (untranslatedIndex &gt;= explicitTracksCount)
+        return autoTrackStyles[(untranslatedIndex - explicitTracksCount) % autoTrackStylesSize];
+
+    if (!autoRepeatTracksCount || untranslatedIndex &lt; insertionPoint)
+        return trackStyles[untranslatedIndex];
+
+    if (untranslatedIndex &lt; (insertionPoint + autoRepeatTracksCount)) {
+        unsigned autoRepeatLocalIndex = untranslatedIndexAsInt - insertionPoint;
+        return autoRepeatTrackStyles[autoRepeatLocalIndex % autoRepeatTrackStyles.size()];
+    }
+
+    return trackStyles[untranslatedIndex - autoRepeatTracksCount];
+}
+
+LayoutUnit GridTrackSizingAlgorithm::computeTrackBasedSize() const
+{
+    LayoutUnit size;
+    auto&amp; allTracks = tracks(m_direction);
+    for (auto&amp; track : allTracks)
+        size += track.baseSize();
+
+    size += m_renderGrid-&gt;guttersSize(m_grid, m_direction, 0, allTracks.size());
+
+    return size;
+}
+
+LayoutUnit GridTrackSizingAlgorithm::initialBaseSize(const GridTrackSize&amp; trackSize) const
+{
+    const GridLength&amp; gridLength = trackSize.minTrackBreadth();
+    if (gridLength.isFlex())
+        return 0;
+
+    const Length&amp; trackLength = gridLength.length();
+    if (trackLength.isSpecified())
+        return valueForLength(trackLength, std::max&lt;LayoutUnit&gt;(m_availableSpace.value_or(0), 0));
+
+    ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isMaxContent());
+    return 0;
+}
+
+LayoutUnit GridTrackSizingAlgorithm::initialGrowthLimit(const GridTrackSize&amp; trackSize, LayoutUnit baseSize) const
+{
+    const GridLength&amp; gridLength = trackSize.maxTrackBreadth();
+    if (gridLength.isFlex())
+        return baseSize;
+
+    const Length&amp; trackLength = gridLength.length();
+    if (trackLength.isSpecified())
+        return valueForLength(trackLength, std::max&lt;LayoutUnit&gt;(m_availableSpace.value_or(0), 0));
+
+    ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isMaxContent());
+    return infinity;
+}
+
+void GridTrackSizingAlgorithm::sizeTrackToFitNonSpanningItem(const GridSpan&amp; span, RenderBox&amp; gridItem, GridTrack&amp; track)
+{
+    unsigned trackPosition = span.startLine();
+    GridTrackSize trackSize = gridTrackSize(m_direction, trackPosition);
+
+    if (trackSize.hasMinContentMinTrackBreadth())
+        track.setBaseSize(std::max(track.baseSize(), m_strategy-&gt;minContentForChild(gridItem)));
+    else if (trackSize.hasMaxContentMinTrackBreadth())
+        track.setBaseSize(std::max(track.baseSize(), m_strategy-&gt;maxContentForChild(gridItem)));
+    else if (trackSize.hasAutoMinTrackBreadth())
+        track.setBaseSize(std::max(track.baseSize(), m_strategy-&gt;minSizeForChild(gridItem)));
+
+    if (trackSize.hasMinContentMaxTrackBreadth()) {
+        track.setGrowthLimit(std::max(track.growthLimit(), m_strategy-&gt;minContentForChild(gridItem)));
+    } else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) {
+        LayoutUnit growthLimit = m_strategy-&gt;maxContentForChild(gridItem);
+        if (trackSize.isFitContent())
+            growthLimit = std::min(growthLimit, valueForLength(trackSize.fitContentTrackBreadth().length(), m_availableSpace.value_or(0)));
+        track.setGrowthLimit(std::max(track.growthLimit(), growthLimit));
+    }
+}
+
+bool GridTrackSizingAlgorithm::spanningItemCrossesFlexibleSizedTracks(const GridSpan&amp; itemSpan) const
+{
+    for (auto trackPosition : itemSpan) {
+        const GridTrackSize&amp; trackSize = gridTrackSize(m_direction, trackPosition);
+        if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth().isFlex())
+            return true;
+    }
+
+    return false;
+}
+
+class GridItemWithSpan {
+public:
+    GridItemWithSpan(RenderBox&amp; gridItem, GridSpan span)
+        : m_gridItem(gridItem)
+        , m_span(span)
+    {
+    }
+
+    RenderBox&amp; gridItem() const { return m_gridItem; }
+    GridSpan span() const { return m_span; }
+
+    bool operator&lt;(const GridItemWithSpan other) const { return m_span.integerSpan() &lt; other.m_span.integerSpan(); }
+
+private:
+    std::reference_wrapper&lt;RenderBox&gt; m_gridItem;
+    GridSpan m_span;
+};
+
+struct GridItemsSpanGroupRange {
+    Vector&lt;GridItemWithSpan&gt;::iterator rangeStart;
+    Vector&lt;GridItemWithSpan&gt;::iterator rangeEnd;
+};
+
+enum TrackSizeRestriction {
+    AllowInfinity,
+    ForbidInfinity,
+};
+
+LayoutUnit GridTrackSizingAlgorithm::itemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, RenderBox&amp; gridItem) const
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+    case ResolveIntrinsicMaximums:
+        return m_strategy-&gt;minSizeForChild(gridItem);
+    case ResolveContentBasedMinimums:
+        return m_strategy-&gt;minContentForChild(gridItem);
+    case ResolveMaxContentMinimums:
+    case ResolveMaxContentMaximums:
+        return m_strategy-&gt;maxContentForChild(gridItem);
+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return 0;
+    }
+
+    ASSERT_NOT_REACHED();
+    return 0;
+}
+
+static bool shouldProcessTrackForTrackSizeComputationPhase(TrackSizeComputationPhase phase, const GridTrackSize&amp; trackSize)
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+        return trackSize.hasIntrinsicMinTrackBreadth();
+    case ResolveContentBasedMinimums:
+        return trackSize.hasMinOrMaxContentMinTrackBreadth();
+    case ResolveMaxContentMinimums:
+        return trackSize.hasMaxContentMinTrackBreadth();
+    case ResolveIntrinsicMaximums:
+        return trackSize.hasIntrinsicMaxTrackBreadth();
+    case ResolveMaxContentMaximums:
+        return trackSize.hasMaxContentOrAutoMaxTrackBreadth();
+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return false;
+    }
+
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+static LayoutUnit trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track, TrackSizeRestriction restriction)
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+    case ResolveContentBasedMinimums:
+    case ResolveMaxContentMinimums:
+    case MaximizeTracks:
+        return track.baseSize();
+    case ResolveIntrinsicMaximums:
+    case ResolveMaxContentMaximums:
+        return restriction == AllowInfinity ? track.growthLimit() : track.growthLimitIfNotInfinite();
+    }
+
+    ASSERT_NOT_REACHED();
+    return track.baseSize();
+}
+
+static void updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track)
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+    case ResolveContentBasedMinimums:
+    case ResolveMaxContentMinimums:
+        track.setBaseSize(track.plannedSize());
+        return;
+    case ResolveIntrinsicMaximums:
+    case ResolveMaxContentMaximums:
+        track.setGrowthLimit(track.plannedSize());
+        return;
+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+static bool trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(TrackSizeComputationPhase phase, const GridTrackSize&amp; trackSize)
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+    case ResolveContentBasedMinimums:
+        return trackSize.hasAutoOrMinContentMinTrackBreadthAndIntrinsicMaxTrackBreadth();
+    case ResolveMaxContentMinimums:
+        return trackSize.hasMaxContentMinTrackBreadthAndMaxContentMaxTrackBreadth();
+    case ResolveIntrinsicMaximums:
+    case ResolveMaxContentMaximums:
+        return true;
+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return false;
+    }
+
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+static void markAsInfinitelyGrowableForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track)
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+    case ResolveContentBasedMinimums:
+    case ResolveMaxContentMinimums:
+        return;
+    case ResolveIntrinsicMaximums:
+        if (trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity) == infinity  &amp;&amp; track.plannedSize() != infinity)
+            track.setInfinitelyGrowable(true);
+        return;
+    case ResolveMaxContentMaximums:
+        if (track.infinitelyGrowable())
+            track.setInfinitelyGrowable(false);
+        return;
+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return;
+    }
+
+    ASSERT_NOT_REACHED();
+}
+
+template &lt;TrackSizeComputationPhase phase&gt;
+void GridTrackSizingAlgorithm::increaseSizesToAccommodateSpanningItems(const GridItemsSpanGroupRange&amp; gridItemsWithSpan)
+{
+    Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    for (const auto&amp; trackIndex : m_contentSizedTracksIndex) {
+        GridTrack&amp; track = allTracks[trackIndex];
+        track.setPlannedSize(trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity));
+    }
+
+    Vector&lt;GridTrack*&gt; growBeyondGrowthLimitsTracks;
+    Vector&lt;GridTrack*&gt; filteredTracks;
+    for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEnd; ++it) {
+        GridItemWithSpan&amp; gridItemWithSpan = *it;
+        ASSERT(gridItemWithSpan.span().integerSpan() &gt; 1);
+        const GridSpan&amp; itemSpan = gridItemWithSpan.span();
+
+        filteredTracks.shrink(0);
+        growBeyondGrowthLimitsTracks.shrink(0);
+        LayoutUnit spanningTracksSize;
+        for (auto trackPosition : itemSpan) {
+            const GridTrackSize&amp; trackSize = gridTrackSize(m_direction, trackPosition);
+            GridTrack&amp; track = tracks(m_direction)[trackPosition];
+            spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, track, ForbidInfinity);
+            if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize))
+                continue;
+
+            filteredTracks.append(&amp;track);
+
+            if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(phase, trackSize))
+                growBeyondGrowthLimitsTracks.append(&amp;track);
+        }
+
+        if (filteredTracks.isEmpty())
+            continue;
+
+        spanningTracksSize += m_renderGrid-&gt;guttersSize(m_grid, m_direction, itemSpan.startLine(), itemSpan.integerSpan());
+
+        LayoutUnit extraSpace = itemSizeForTrackSizeComputationPhase(phase, gridItemWithSpan.gridItem()) - spanningTracksSize;
+        extraSpace = std::max&lt;LayoutUnit&gt;(extraSpace, 0);
+        auto&amp; tracksToGrowBeyondGrowthLimits = growBeyondGrowthLimitsTracks.isEmpty() ? filteredTracks : growBeyondGrowthLimitsTracks;
+        distributeSpaceToTracks&lt;phase&gt;(filteredTracks, &amp;tracksToGrowBeyondGrowthLimits, extraSpace);
+    }
+
+    for (const auto&amp; trackIndex : m_contentSizedTracksIndex) {
+        GridTrack&amp; track = allTracks[trackIndex];
+        markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track);
+        updateTrackSizeForTrackSizeComputationPhase(phase, track);
+    }
+}
+
+static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTrack* track2)
+{
+    // This check ensures that we respect the irreflexivity property of the strict weak ordering required by std::sort
+    // (forall x: NOT x &lt; x).
+    bool track1HasInfiniteGrowthPotentialWithoutCap = track1-&gt;infiniteGrowthPotential() &amp;&amp; !track1-&gt;growthLimitCap();
+    bool track2HasInfiniteGrowthPotentialWithoutCap = track2-&gt;infiniteGrowthPotential() &amp;&amp; !track2-&gt;growthLimitCap();
+
+    if (track1HasInfiniteGrowthPotentialWithoutCap &amp;&amp; track2HasInfiniteGrowthPotentialWithoutCap)
+        return false;
+
+    if (track1HasInfiniteGrowthPotentialWithoutCap || track2HasInfiniteGrowthPotentialWithoutCap)
+        return track2HasInfiniteGrowthPotentialWithoutCap;
+
+    LayoutUnit track1Limit = track1-&gt;growthLimitCap().value_or(track1-&gt;growthLimit());
+    LayoutUnit track2Limit = track2-&gt;growthLimitCap().value_or(track2-&gt;growthLimit());
+    return (track1Limit - track1-&gt;baseSize()) &lt; (track2Limit - track2-&gt;baseSize());
+}
+
+static void clampGrowthShareIfNeeded(TrackSizeComputationPhase phase, const GridTrack&amp; track, LayoutUnit&amp; growthShare)
+{
+    if (phase != ResolveMaxContentMaximums || !track.growthLimitCap())
+        return;
+
+    LayoutUnit distanceToCap = track.growthLimitCap().value() - track.tempSize();
+    if (distanceToCap &lt;= 0)
+        return;
+
+    growthShare = std::min(growthShare, distanceToCap);
+}
+
+template &lt;TrackSizeComputationPhase phase&gt;
+void GridTrackSizingAlgorithm::distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp; tracks, Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; freeSpace) const
+{
+    ASSERT(freeSpace &gt;= 0);
+
+    for (auto* track : tracks)
+        track-&gt;setTempSize(trackSizeForTrackSizeComputationPhase(phase, *track, ForbidInfinity));
+
+    if (freeSpace &gt; 0) {
+        std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential);
+
+        unsigned tracksSize = tracks.size();
+        for (unsigned i = 0; i &lt; tracksSize; ++i) {
+            GridTrack&amp; track = *tracks[i];
+            const LayoutUnit&amp; trackBreadth = trackSizeForTrackSizeComputationPhase(phase, track, ForbidInfinity);
+            bool infiniteGrowthPotential = track.infiniteGrowthPotential();
+            LayoutUnit trackGrowthPotential = infiniteGrowthPotential ? track.growthLimit() : track.growthLimit() - trackBreadth;
+            // Let's avoid computing availableLogicalSpaceShare as much as possible as it's a hot spot in performance tests.
+            if (trackGrowthPotential &gt; 0 || infiniteGrowthPotential) {
+                LayoutUnit availableLogicalSpaceShare = freeSpace / (tracksSize - i);
+                LayoutUnit growthShare = infiniteGrowthPotential ? availableLogicalSpaceShare : std::min(availableLogicalSpaceShare, trackGrowthPotential);
+                clampGrowthShareIfNeeded(phase, track, growthShare);
+                ASSERT_WITH_MESSAGE(growthShare &gt;= 0, &quot;We should never shrink any grid track or else we can't guarantee we abide by our min-sizing function. We can still have 0 as growthShare if the amount of tracks greatly exceeds the freeSpace.&quot;);
+                track.growTempSize(growthShare);
+                freeSpace -= growthShare;
+            }
+        }
+    }
+
+    if (freeSpace &gt; 0 &amp;&amp; growBeyondGrowthLimitsTracks) {
+        // We need to sort them because there might be tracks with growth limit caps (like the ones
+        // with fit-content()) which cannot indefinitely grow over the limits.
+        if (phase == ResolveMaxContentMaximums)
+            std::sort(growBeyondGrowthLimitsTracks-&gt;begin(), growBeyondGrowthLimitsTracks-&gt;end(), sortByGridTrackGrowthPotential);
+
+        unsigned tracksGrowingBeyondGrowthLimitsSize = growBeyondGrowthLimitsTracks-&gt;size();
+        for (unsigned i = 0; i &lt; tracksGrowingBeyondGrowthLimitsSize; ++i) {
+            GridTrack* track = growBeyondGrowthLimitsTracks-&gt;at(i);
+            LayoutUnit growthShare = freeSpace / (tracksGrowingBeyondGrowthLimitsSize - i);
+            clampGrowthShareIfNeeded(phase, *track, growthShare);
+            track-&gt;growTempSize(growthShare);
+            freeSpace -= growthShare;
+        }
+    }
+
+    for (auto* track : tracks)
+        track-&gt;setPlannedSize(track-&gt;plannedSize() == infinity ? track-&gt;tempSize() : std::max(track-&gt;plannedSize(), track-&gt;tempSize()));
+}
+
+LayoutUnit GridTrackSizingAlgorithm::assumedRowsSizeForOrthogonalChild(const RenderBox&amp; child) const
+{
+    ASSERT(m_renderGrid-&gt;isOrthogonalChild(child));
+    const GridSpan&amp; span = m_grid.gridItemSpan(child, ForRows);
+    LayoutUnit gridAreaSize;
+    bool gridAreaIsIndefinite = false;
+    LayoutUnit containingBlockAvailableSize = m_renderGrid-&gt;containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding);
+    for (auto trackPosition : span) {
+        GridLength maxTrackSize = gridTrackSize(ForRows, trackPosition).maxTrackBreadth();
+        if (maxTrackSize.isContentSized() || maxTrackSize.isFlex())
+            gridAreaIsIndefinite = true;
+        else
+            gridAreaSize += valueForLength(maxTrackSize.length(), containingBlockAvailableSize);
+    }
+
+    gridAreaSize += m_renderGrid-&gt;guttersSize(m_grid, ForRows, span.startLine(), span.integerSpan());
+
+    return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gridAreaSize) : gridAreaSize;
+}
+
+LayoutUnit GridTrackSizingAlgorithm::gridAreaBreadthForChild(const RenderBox&amp; child, GridTrackSizingDirection direction) const
+{
+    // To determine the column track's size based on an orthogonal grid item we need it's logical
+    // height, which may depend on the row track's size. It's possible that the row tracks sizing
+    // logic has not been performed yet, so we will need to do an estimation.
+    if (direction == ForRows &amp;&amp; m_sizingState == ColumnSizingFirstIteration)
+        return assumedRowsSizeForOrthogonalChild(child);
+
+    const Vector&lt;GridTrack&gt;&amp; allTracks = tracks(direction);
+    const GridSpan&amp; span = m_grid.gridItemSpan(child, direction);
+    LayoutUnit gridAreaBreadth = 0;
+    for (auto trackPosition : span)
+        gridAreaBreadth += allTracks[trackPosition].baseSize();
+
+    gridAreaBreadth += m_renderGrid-&gt;guttersSize(m_grid, direction, span.startLine(), span.integerSpan());
+
+    return gridAreaBreadth;
+}
+
+GridTrackSize GridTrackSizingAlgorithm::gridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex, SizingOperation sizingOperation) const
+{
+    // Collapse empty auto repeat tracks if auto-fit.
+    if (m_grid.hasAutoRepeatEmptyTracks(direction) &amp;&amp; m_grid.isEmptyAutoRepeatTrack(direction, translatedIndex))
+        return { Length(Fixed), LengthTrackSizing };
+
+    auto&amp; trackSize = rawGridTrackSize(direction, translatedIndex);
+    if (trackSize.isFitContent())
+        return trackSize;
+
+    GridLength minTrackBreadth = trackSize.minTrackBreadth();
+    GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
+
+    // FIXME: Ensure this condition for determining whether a size is indefinite or not is working
+    // correctly for orthogonal flows.
+    if (minTrackBreadth.isPercentage() || maxTrackBreadth.isPercentage()) {
+        // If the logical width/height of the grid container is indefinite, percentage values are
+        // treated as &lt;auto&gt;. For the inline axis this only happens when we're computing the
+        // intrinsic sizes (IntrinsicSizeComputation).
+        if (sizingOperation == IntrinsicSizeComputation || (direction == ForRows &amp;&amp; !m_renderGrid-&gt;hasDefiniteLogicalHeight())) {
+            if (minTrackBreadth.isPercentage())
+                minTrackBreadth = Length(Auto);
+            if (maxTrackBreadth.isPercentage())
+                maxTrackBreadth = Length(Auto);
+        }
+    }
+
+    // Flex sizes are invalid as a min sizing function. However we still can have a flexible |minTrackBreadth|
+    // if the track size is just a flex size (e.g. &quot;1fr&quot;), the spec says that in this case it implies an automatic minimum.
+    if (minTrackBreadth.isFlex())
+        minTrackBreadth = Length(Auto);
+
+    return GridTrackSize(minTrackBreadth, maxTrackBreadth);
+}
+
+double GridTrackSizingAlgorithm::computeFlexFactorUnitSize(const Vector&lt;GridTrack&gt;&amp; tracks, double flexFactorSum, LayoutUnit&amp; leftOverSpace, const Vector&lt;unsigned, 8&gt;&amp; flexibleTracksIndexes, std::unique_ptr&lt;TrackIndexSet&gt; tracksToTreatAsInflexible) const
+{
+    // We want to avoid the effect of flex factors sum below 1 making the factor unit size to grow exponentially.
+    double hypotheticalFactorUnitSize = leftOverSpace / std::max&lt;double&gt;(1, flexFactorSum);
+
+    // product of the hypothetical &quot;flex factor unit&quot; and any flexible track's &quot;flex factor&quot; must be grater than such track's &quot;base size&quot;.
+    bool validFlexFactorUnit = true;
+    for (auto index : flexibleTracksIndexes) {
+        if (tracksToTreatAsInflexible &amp;&amp; tracksToTreatAsInflexible-&gt;contains(index))
+            continue;
+        LayoutUnit baseSize = tracks[index].baseSize();
+        double flexFactor = gridTrackSize(m_direction, index).maxTrackBreadth().flex();
+        // treating all such tracks as inflexible.
+        if (baseSize &gt; hypotheticalFactorUnitSize * flexFactor) {
+            leftOverSpace -= baseSize;
+            flexFactorSum -= flexFactor;
+            if (!tracksToTreatAsInflexible)
+                tracksToTreatAsInflexible = std::unique_ptr&lt;TrackIndexSet&gt;(new TrackIndexSet());
+            tracksToTreatAsInflexible-&gt;add(index);
+            validFlexFactorUnit = false;
+        }
+    }
+    if (!validFlexFactorUnit)
+        return computeFlexFactorUnitSize(tracks, flexFactorSum, leftOverSpace, flexibleTracksIndexes, WTFMove(tracksToTreatAsInflexible));
+    return hypotheticalFactorUnitSize;
+}
+
+void GridTrackSizingAlgorithm::computeFlexSizedTracksGrowth(double flexFraction, Vector&lt;LayoutUnit&gt;&amp; increments, LayoutUnit&amp; totalGrowth) const
+{
+    size_t numFlexTracks = m_flexibleSizedTracksIndex.size();
+    ASSERT(increments.size() == numFlexTracks);
+    const Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    for (size_t i = 0; i &lt; numFlexTracks; ++i) {
+        unsigned trackIndex = m_flexibleSizedTracksIndex[i];
+        auto trackSize = gridTrackSize(m_direction, trackIndex);
+        ASSERT(trackSize.maxTrackBreadth().isFlex());
+        LayoutUnit oldBaseSize = allTracks[trackIndex].baseSize();
+        LayoutUnit newBaseSize = std::max(oldBaseSize, LayoutUnit(flexFraction * trackSize.maxTrackBreadth().flex()));
+        increments[i] = newBaseSize - oldBaseSize;
+        totalGrowth += increments[i];
+    }
+}
+
+double GridTrackSizingAlgorithm::findFrUnitSize(const GridSpan&amp; tracksSpan, LayoutUnit leftOverSpace) const
+{
+    if (leftOverSpace &lt;= 0)
+        return 0;
+
+    const Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    double flexFactorSum = 0;
+    Vector&lt;unsigned, 8&gt; flexibleTracksIndexes;
+    for (auto trackIndex : tracksSpan) {
+        GridTrackSize trackSize = gridTrackSize(m_direction, trackIndex);
+        if (!trackSize.maxTrackBreadth().isFlex())
+            leftOverSpace -= allTracks[trackIndex].baseSize();
+        else {
+            double flexFactor = trackSize.maxTrackBreadth().flex();
+            flexibleTracksIndexes.append(trackIndex);
+            flexFactorSum += flexFactor;
+        }
+    }
+
+    // The function is not called if we don't have &lt;flex&gt; grid tracks.
+    ASSERT(!flexibleTracksIndexes.isEmpty());
+
+    return computeFlexFactorUnitSize(allTracks, flexFactorSum, leftOverSpace, flexibleTracksIndexes);
+}
+
+void GridTrackSizingAlgorithm::computeGridContainerIntrinsicSizes()
+{
+    m_minContentSize = m_maxContentSize = LayoutUnit();
+
+    Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    for (auto&amp; track : allTracks) {
+        ASSERT(!track.infiniteGrowthPotential());
+        m_minContentSize += track.baseSize();
+        m_maxContentSize += track.growthLimit();
+        // The growth limit caps must be cleared now in order to properly sort
+        // tracks by growth potential on an eventual &quot;Maximize Tracks&quot;.
+        track.setGrowthLimitCap(std::nullopt);
+    }
+}
+
+// GridTrackSizingAlgorithmStrategy.
+LayoutUnit GridTrackSizingAlgorithmStrategy::logicalHeightForChild(RenderBox&amp; child) const
+{
+    GridTrackSizingDirection childBlockDirection = flowAwareDirectionForChild(renderGrid(), child, ForRows);
+    // 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 -1 (no possible resolution).
+    if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForRows)) {
+        setOverrideContainingBlockContentSizeForChild(child, childBlockDirection, std::nullopt);
+        child.setNeedsLayout(MarkOnlyThis);
+    }
+
+    // We need to clear the stretched height to properly compute logical height during layout.
+    if (child.needsLayout())
+        child.clearOverrideLogicalContentHeight();
+
+    child.layoutIfNeeded();
+    return child.logicalHeight() + child.marginLogicalHeight();
+}
+
+LayoutUnit GridTrackSizingAlgorithmStrategy::minContentForChild(RenderBox&amp; child) const
+{
+    GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(renderGrid(), child, ForColumns);
+    if (direction() == childInlineDirection) {
+        // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is
+        // what we are interested in here. Thus we need to set the override logical width to std::nullopt (no possible resolution).
+        if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColumns))
+            setOverrideContainingBlockContentSizeForChild(child, childInlineDirection, std::nullopt);
+
+        // FIXME: It's unclear if we should return the intrinsic width or the preferred width.
+        // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
+        return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(renderGrid(), child);
+    }
+
+    // All orthogonal flow boxes were already laid out during an early layout phase performed in FrameView::performLayout.
+    // It's true that grid track sizing was not completed at that time and it may afffect the final height of a
+    // grid item, but since it's forbidden to perform a layout during intrinsic width computation, we have to use
+    // that computed height for now.
+    if (direction() == ForColumns &amp;&amp; m_algorithm.m_sizingOperation == IntrinsicSizeComputation) {
+        ASSERT(renderGrid()-&gt;isOrthogonalChild(child));
+        return child.logicalHeight() + child.marginLogicalHeight();
+    }
+
+    if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirection))
+        child.setNeedsLayout(MarkOnlyThis);
+    return logicalHeightForChild(child);
+}
+
+LayoutUnit GridTrackSizingAlgorithmStrategy::maxContentForChild(RenderBox&amp; child) const
+{
+    GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(renderGrid(), child, ForColumns);
+    if (direction() == childInlineDirection) {
+        // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is
+        // what we are interested in here. Thus we need to set the inline-axis override size to -1 (no possible resolution).
+        if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColumns))
+            setOverrideContainingBlockContentSizeForChild(child, childInlineDirection, std::nullopt);
+
+        // FIXME: It's unclear if we should return the intrinsic width or the preferred width.
+        // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
+        return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(renderGrid(), child);
+        return child.maxPreferredLogicalWidth();
+    }
+
+    // All orthogonal flow boxes were already laid out during an early layout phase performed in
+    // FrameView::performLayout. It's true that grid track sizing was not completed at that time
+    // and it may afffect the final height of a grid item, but since it's forbidden to perform a
+    // layout during intrinsic width computation, we have to use that computed height for now.
+    if (direction() == ForColumns &amp;&amp; m_algorithm.m_sizingOperation == IntrinsicSizeComputation) {
+        ASSERT(renderGrid()-&gt;isOrthogonalChild(child));
+        return child.logicalHeight() + child.marginLogicalHeight();
+    }
+
+    if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirection))
+        child.setNeedsLayout(MarkOnlyThis);
+    return logicalHeightForChild(child);
+}
+
+LayoutUnit GridTrackSizingAlgorithmStrategy::minSizeForChild(RenderBox&amp; child) const
+{
+    GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(renderGrid(), child, ForColumns);
+    bool isRowAxis = direction() == childInlineDirection;
+    const Length&amp; childMinSize = isRowAxis ? child.style().logicalMinWidth() : child.style().logicalMinHeight();
+    const Length&amp; childSize = isRowAxis ? child.style().logicalWidth() : child.style().logicalHeight();
+    if (!childSize.isAuto() || childMinSize.isAuto())
+        return minContentForChild(child);
+
+    bool overrideSizeHasChanged = updateOverrideContainingBlockContentSizeForChild(child, childInlineDirection);
+
+    if (isRowAxis)
+        return minLogicalWidthForChild(child, childMinSize, childInlineDirection);
+
+    layoutGridItemForMinSizeComputation(child, overrideSizeHasChanged);
+
+    return child.computeLogicalHeightUsing(MinSize, childMinSize, std::nullopt).value_or(0) + child.marginLogicalHeight() + child.scrollbarLogicalHeight();
+}
+
+bool GridTrackSizingAlgorithmStrategy::updateOverrideContainingBlockContentSizeForChild(RenderBox&amp; child, GridTrackSizingDirection direction) const
+{
+    LayoutUnit overrideSize = m_algorithm.gridAreaBreadthForChild(child, direction);
+    if (hasOverrideContainingBlockContentSizeForChild(child, direction) &amp;&amp; overrideContainingBlockContentSizeForChild(child, direction) == overrideSize)
+        return false;
+
+    setOverrideContainingBlockContentSizeForChild(child, direction, overrideSize);
+    return true;
+}
+
+class IndefiniteSizeStrategy final : public GridTrackSizingAlgorithmStrategy {
+public:
+    IndefiniteSizeStrategy(GridTrackSizingAlgorithm&amp; algorithm)
+        : GridTrackSizingAlgorithmStrategy(algorithm) { }
+
+private:
+    LayoutUnit minLogicalWidthForChild(RenderBox&amp;, Length childMinSize, GridTrackSizingDirection) const override;
+    void layoutGridItemForMinSizeComputation(RenderBox&amp;, bool overrideSizeHasChanged) const override;
+    void maximizeTracks(Vector&lt;GridTrack&gt;&amp;, std::optional&lt;LayoutUnit&gt;&amp; freeSpace) override;
+    double findUsedFlexFraction(Vector&lt;unsigned&gt;&amp; flexibleSizedTracksIndex, GridTrackSizingDirection, std::optional&lt;LayoutUnit&gt; freeSpace) const override;
+    bool recomputeUsedFlexFractionIfNeeded(double&amp; flexFraction, LayoutUnit&amp; totalGrowth) const override;
+};
+
+LayoutUnit IndefiniteSizeStrategy::minLogicalWidthForChild(RenderBox&amp; child, Length childMinSize, GridTrackSizingDirection childInlineDirection) const
+{
+    return child.computeLogicalWidthInRegionUsing(MinSize, childMinSize, overrideContainingBlockContentSizeForChild(child, childInlineDirection).value_or(0), *renderGrid(), nullptr) + marginIntrinsicLogicalWidthForChild(renderGrid(), child);
+}
+
+void IndefiniteSizeStrategy::layoutGridItemForMinSizeComputation(RenderBox&amp; child, bool overrideSizeHasChanged) const
+{
+    if (overrideSizeHasChanged &amp;&amp; direction() != ForColumns)
+        child.setNeedsLayout(MarkOnlyThis);
+    child.layoutIfNeeded();
+}
+
+void IndefiniteSizeStrategy::maximizeTracks(Vector&lt;GridTrack&gt;&amp; tracks, std::optional&lt;LayoutUnit&gt;&amp; freeSpace)
+{
+    UNUSED_PARAM(freeSpace);
+    for (auto&amp; track : tracks)
+        track.setBaseSize(track.growthLimit());
+}
+
+
+static inline double normalizedFlexFraction(const GridTrack&amp; track, double flexFactor)
+{
+    return track.baseSize() / std::max&lt;double&gt;(1, flexFactor);
+}
+
+double IndefiniteSizeStrategy::findUsedFlexFraction(Vector&lt;unsigned&gt;&amp; flexibleSizedTracksIndex, GridTrackSizingDirection direction, std::optional&lt;LayoutUnit&gt; freeSpace) const
+{
+    UNUSED_PARAM(freeSpace);
+    auto allTracks = m_algorithm.tracks(direction);
+
+    double flexFraction = 0;
+    for (const auto&amp; trackIndex : flexibleSizedTracksIndex) {
+        // FIXME: we pass TrackSizing to gridTrackSize() because it does not really matter
+        // as we know the track is a flex sized track. It'd be nice not to have to do that.
+        flexFraction = std::max(flexFraction, normalizedFlexFraction(allTracks[trackIndex], m_algorithm.gridTrackSize(direction, trackIndex, TrackSizing).maxTrackBreadth().flex()));
+    }
+
+    const Grid&amp; grid = m_algorithm.grid();
+    if (!grid.hasGridItems())
+        return flexFraction;
+
+    for (unsigned i = 0; i &lt; flexibleSizedTracksIndex.size(); ++i) {
+        GridIterator iterator(grid, direction, flexibleSizedTracksIndex[i]);
+        while (auto* gridItem = iterator.nextGridItem()) {
+            const GridSpan&amp; span = grid.gridItemSpan(*gridItem, direction);
+
+            // Do not include already processed items.
+            if (i &gt; 0 &amp;&amp; span.startLine() &lt;= flexibleSizedTracksIndex[i - 1])
+                continue;
+
+            flexFraction = std::max(flexFraction, findFrUnitSize(span, maxContentForChild(*gridItem)));
+        }
+    }
+
+    return flexFraction;
+}
+
+bool IndefiniteSizeStrategy::recomputeUsedFlexFractionIfNeeded(double&amp; flexFraction, LayoutUnit&amp; totalGrowth) const
+{
+    if (direction() == ForColumns)
+        return false;
+
+    const RenderGrid* renderGrid = this-&gt;renderGrid();
+
+    auto minSize = renderGrid-&gt;computeContentLogicalHeight(MinSize, renderGrid-&gt;style().logicalMinHeight(), std::nullopt);
+    auto maxSize = renderGrid-&gt;computeContentLogicalHeight(MaxSize, renderGrid-&gt;style().logicalMaxHeight(), std::nullopt);
+
+    // Redo the flex fraction computation using min|max-height as definite available space in case
+    // the total height is smaller than min-height or larger than max-height.
+    LayoutUnit rowsSize = totalGrowth + computeTrackBasedSize();
+    bool checkMinSize = minSize &amp;&amp; rowsSize &lt; minSize.value();
+    bool checkMaxSize = maxSize &amp;&amp; rowsSize &gt; maxSize.value();
+    if (!checkMinSize &amp;&amp; !checkMaxSize)
+        return false;
+
+    LayoutUnit freeSpace = checkMaxSize ? maxSize.value() : LayoutUnit(-1);
+    const Grid&amp; grid = m_algorithm.grid();
+    freeSpace = std::max(freeSpace, minSize.value()) - renderGrid-&gt;guttersSize(grid, ForRows, 0, grid.numTracks(ForRows));
+
+    size_t numberOfTracks = m_algorithm.tracks(ForRows).size();
+    flexFraction = findFrUnitSize(GridSpan::translatedDefiniteGridSpan(0, numberOfTracks), freeSpace);
+    return true;
+}
+
+class DefiniteSizeStrategy final : public GridTrackSizingAlgorithmStrategy {
+public:
+    DefiniteSizeStrategy(GridTrackSizingAlgorithm&amp; algorithm)
+        : GridTrackSizingAlgorithmStrategy(algorithm) { }
+
+private:
+    LayoutUnit minLogicalWidthForChild(RenderBox&amp;, Length childMinSize, GridTrackSizingDirection) const override;
+    void layoutGridItemForMinSizeComputation(RenderBox&amp;, bool overrideSizeHasChanged) const override;
+    void maximizeTracks(Vector&lt;GridTrack&gt;&amp;, std::optional&lt;LayoutUnit&gt;&amp; freeSpace) override;
+    double findUsedFlexFraction(Vector&lt;unsigned&gt;&amp; flexibleSizedTracksIndex, GridTrackSizingDirection, std::optional&lt;LayoutUnit&gt; freeSpace) const override;
+    bool recomputeUsedFlexFractionIfNeeded(double&amp; flexFraction, LayoutUnit&amp; totalGrowth) const override;
+};
+
+LayoutUnit DefiniteSizeStrategy::minLogicalWidthForChild(RenderBox&amp; child, Length childMinSize, GridTrackSizingDirection childInlineDirection) const
+{
+    LayoutUnit marginLogicalWidth =
+        computeMarginLogicalSizeForChild(childInlineDirection, *renderGrid(), child);
+    return child.computeLogicalWidthInRegionUsing(MinSize, childMinSize, overrideContainingBlockContentSizeForChild(child, childInlineDirection).value_or(0), *renderGrid(), nullptr) + marginLogicalWidth;
+}
+
+void DefiniteSizeStrategy::maximizeTracks(Vector&lt;GridTrack&gt;&amp; tracks, std::optional&lt;LayoutUnit&gt;&amp; freeSpace)
+{
+    size_t tracksSize = tracks.size();
+    Vector&lt;GridTrack*&gt; tracksForDistribution(tracksSize);
+    for (size_t i = 0; i &lt; tracksSize; ++i) {
+        tracksForDistribution[i] = tracks.data() + i;
+        tracksForDistribution[i]-&gt;setPlannedSize(tracksForDistribution[i]-&gt;baseSize());
+    }
+
+    ASSERT(freeSpace);
+    distributeSpaceToTracks(tracksForDistribution, freeSpace.value());
+
+    for (auto* track : tracksForDistribution)
+        track-&gt;setBaseSize(track-&gt;plannedSize());
+}
+
+
+void DefiniteSizeStrategy::layoutGridItemForMinSizeComputation(RenderBox&amp; child, bool overrideSizeHasChanged) const
+{
+    if (overrideSizeHasChanged)
+        child.setNeedsLayout(MarkOnlyThis);
+    child.layoutIfNeeded();
+}
+
+double DefiniteSizeStrategy::findUsedFlexFraction(Vector&lt;unsigned&gt;&amp;, GridTrackSizingDirection direction, std::optional&lt;LayoutUnit&gt; freeSpace) const
+{
+    GridSpan allTracksSpan = GridSpan::translatedDefiniteGridSpan(0, m_algorithm.tracks(direction).size());
+    ASSERT(freeSpace);
+    return findFrUnitSize(allTracksSpan, freeSpace.value());
+}
+
+bool DefiniteSizeStrategy::recomputeUsedFlexFractionIfNeeded(double&amp; flexFraction, LayoutUnit&amp; totalGrowth) const
+{
+    UNUSED_PARAM(flexFraction);
+    UNUSED_PARAM(totalGrowth);
+    return false;
+}
+
+// GridTrackSizingAlgorithm steps.
+
+void GridTrackSizingAlgorithm::initializeTrackSizes()
+{
+    ASSERT(m_contentSizedTracksIndex.isEmpty());
+    ASSERT(m_flexibleSizedTracksIndex.isEmpty());
+
+    Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    const bool hasDefiniteFreeSpace = !!m_availableSpace;
+    LayoutUnit maxSize = std::max(LayoutUnit(), m_availableSpace.value_or(LayoutUnit()));
+    // 1. Initialize per Grid track variables.
+    for (unsigned i = 0; i &lt; allTracks.size(); ++i) {
+        GridTrack&amp; track = allTracks[i];
+        const GridTrackSize&amp; trackSize = gridTrackSize(m_direction, i);
+
+        track.setBaseSize(initialBaseSize(trackSize));
+        track.setGrowthLimit(initialGrowthLimit(trackSize, track.baseSize()));
+        track.setInfinitelyGrowable(false);
+
+        if (trackSize.isFitContent()) {
+            GridLength gridLength = trackSize.fitContentTrackBreadth();
+            if (!gridLength.isPercentage() || hasDefiniteFreeSpace)
+                track.setGrowthLimitCap(valueForLength(gridLength.length(), maxSize));
+        }
+        if (trackSize.isContentSized())
+            m_contentSizedTracksIndex.append(i);
+        if (trackSize.maxTrackBreadth().isFlex())
+            m_flexibleSizedTracksIndex.append(i);
+    }
+}
+
+void GridTrackSizingAlgorithm::resolveIntrinsicTrackSizes()
+{
+    Vector&lt;GridItemWithSpan&gt; itemsSortedByIncreasingSpan;
+    HashSet&lt;RenderBox*&gt; itemsSet;
+    Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    if (m_grid.hasGridItems()) {
+        for (auto trackIndex : m_contentSizedTracksIndex) {
+            GridIterator iterator(m_grid, m_direction, trackIndex);
+            GridTrack&amp; track = allTracks[trackIndex];
+
+            while (auto* gridItem = iterator.nextGridItem()) {
+                if (itemsSet.add(gridItem).isNewEntry) {
+                    const GridSpan&amp; span = m_grid.gridItemSpan(*gridItem, m_direction);
+                    if (span.integerSpan() == 1)
+                        sizeTrackToFitNonSpanningItem(span, *gridItem, track);
+                    else if (!spanningItemCrossesFlexibleSizedTracks(span))
+                        itemsSortedByIncreasingSpan.append(GridItemWithSpan(*gridItem, span));
+                }
+            }
+        }
+        std::sort(itemsSortedByIncreasingSpan.begin(), itemsSortedByIncreasingSpan.end());
+    }
+
+    auto it = itemsSortedByIncreasingSpan.begin();
+    auto end = itemsSortedByIncreasingSpan.end();
+    while (it != end) {
+        GridItemsSpanGroupRange spanGroupRange = { it, std::upper_bound(it, end, *it) };
+        increaseSizesToAccommodateSpanningItems&lt;ResolveIntrinsicMinimums&gt;(spanGroupRange);
+        increaseSizesToAccommodateSpanningItems&lt;ResolveContentBasedMinimums&gt;(spanGroupRange);
+        increaseSizesToAccommodateSpanningItems&lt;ResolveMaxContentMinimums&gt;(spanGroupRange);
+        increaseSizesToAccommodateSpanningItems&lt;ResolveIntrinsicMaximums&gt;(spanGroupRange);
+        increaseSizesToAccommodateSpanningItems&lt;ResolveMaxContentMaximums&gt;(spanGroupRange);
+        it = spanGroupRange.rangeEnd;
+    }
+
+    for (auto trackIndex : m_contentSizedTracksIndex) {
+        GridTrack&amp; track = allTracks[trackIndex];
+        if (track.growthLimit() == infinity)
+            track.setGrowthLimit(track.baseSize());
+    }
+}
+
+void GridTrackSizingAlgorithm::stretchFlexibleTracks(std::optional&lt;LayoutUnit&gt; freeSpace)
+{
+    double flexFraction = m_strategy-&gt;findUsedFlexFraction(m_flexibleSizedTracksIndex, m_direction, freeSpace);
+
+    LayoutUnit totalGrowth;
+    Vector&lt;LayoutUnit&gt; increments;
+    increments.grow(m_flexibleSizedTracksIndex.size());
+    computeFlexSizedTracksGrowth(flexFraction, increments, totalGrowth);
+
+    if (m_strategy-&gt;recomputeUsedFlexFractionIfNeeded(flexFraction, totalGrowth)) {
+        totalGrowth = LayoutUnit();
+        computeFlexSizedTracksGrowth(flexFraction, increments, totalGrowth);
+    }
+
+    size_t i = 0;
+    Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    for (auto trackIndex : m_flexibleSizedTracksIndex) {
+        auto&amp; track = allTracks[trackIndex];
+        if (LayoutUnit increment = increments[i++])
+            track.setBaseSize(track.baseSize() + increment);
+    }
+    if (this-&gt;freeSpace(m_direction))
+        setFreeSpace(m_direction, this-&gt;freeSpace(m_direction).value() - totalGrowth);
+    m_maxContentSize += totalGrowth;
+}
+
+void GridTrackSizingAlgorithm::advanceNextState()
+{
+    switch (m_sizingState) {
+    case ColumnSizingFirstIteration:
+        m_sizingState = RowSizingFirstIteration;
+        return;
+    case RowSizingFirstIteration:
+        m_sizingState = ColumnSizingSecondIteration;
+        return;
+    case ColumnSizingSecondIteration:
+        m_sizingState = RowSizingSecondIteration;
+        return;
+    case RowSizingSecondIteration:
+        m_sizingState = ColumnSizingFirstIteration;
+        return;
+    }
+    ASSERT_NOT_REACHED();
+    m_sizingState = ColumnSizingFirstIteration;
+}
+
+bool GridTrackSizingAlgorithm::isValidTransition() const
+{
+    switch (m_sizingState) {
+    case ColumnSizingFirstIteration:
+    case ColumnSizingSecondIteration:
+        return m_direction == ForColumns;
+    case RowSizingFirstIteration:
+    case RowSizingSecondIteration:
+        return m_direction == ForRows;
+    }
+    ASSERT_NOT_REACHED();
+    return false;
+}
+
+// GridTrackSizingAlgorithm API.
+
+void GridTrackSizingAlgorithm::setup(GridTrackSizingDirection direction, unsigned numTracks, SizingOperation sizingOperation, std::optional&lt;LayoutUnit&gt; availableSpace, std::optional&lt;LayoutUnit&gt; freeSpace)
+{
+    ASSERT(m_needsSetup);
+    m_direction = direction;
+    m_availableSpace = availableSpace;
+
+    m_sizingOperation = sizingOperation;
+    switch (m_sizingOperation) {
+    case IntrinsicSizeComputation:
+        m_strategy = std::make_unique&lt;IndefiniteSizeStrategy&gt;(*this);
+        break;
+    case TrackSizing:
+        m_strategy = std::make_unique&lt;DefiniteSizeStrategy&gt;(*this);
+        break;
+    }
+
+    m_contentSizedTracksIndex.shrink(0);
+    m_flexibleSizedTracksIndex.shrink(0);
+
+    setFreeSpace(direction, freeSpace);
+    tracks(direction).resize(numTracks);
+
+    m_needsSetup = false;
+}
+
+void GridTrackSizingAlgorithm::run()
+{
+    StateMachine stateMachine(*this);
+
+    // Step 1.
+    const std::optional&lt;LayoutUnit&gt; initialFreeSpace = freeSpace(m_direction);
+    initializeTrackSizes();
+
+    // Step 2.
+    if (!m_contentSizedTracksIndex.isEmpty())
+        resolveIntrinsicTrackSizes();
+
+    // This is not exactly a step of the track sizing algorithm, but we use the track sizes computed
+    // up to this moment (before maximization) to calculate the grid container intrinsic sizes.
+    computeGridContainerIntrinsicSizes();
+
+    if (freeSpace(m_direction)) {
+        LayoutUnit updatedFreeSpace = freeSpace(m_direction).value() - m_minContentSize;
+        setFreeSpace(m_direction, updatedFreeSpace);
+        if (updatedFreeSpace &lt;= 0)
+            return;
+    }
+
+    // Step 3.
+    m_strategy-&gt;maximizeTracks(tracks(m_direction), m_direction == ForColumns ? m_freeSpaceColumns : m_freeSpaceRows);
+
+    if (m_flexibleSizedTracksIndex.isEmpty())
+        return;
+
+    // Step 4.
+    stretchFlexibleTracks(initialFreeSpace);
+}
+
+void GridTrackSizingAlgorithm::reset()
+{
+    m_sizingState = ColumnSizingFirstIteration;
+    m_columns.shrink(0);
+    m_rows.shrink(0);
+    m_contentSizedTracksIndex.shrink(0);
+    m_flexibleSizedTracksIndex.shrink(0);
+}
+
+#ifndef NDEBUG
+bool GridTrackSizingAlgorithm::tracksAreWiderThanMinTrackBreadth() const
+{
+    const Vector&lt;GridTrack&gt;&amp; allTracks = tracks(m_direction);
+    for (size_t i = 0; i &lt; allTracks.size(); ++i) {
+        GridTrackSize trackSize = gridTrackSize(m_direction, i);
+        if (initialBaseSize(trackSize) &gt; allTracks[i].baseSize())
+            return false;
+    }
+    return true;
+}
+#endif
+
+GridTrackSizingAlgorithm::StateMachine::StateMachine(GridTrackSizingAlgorithm&amp; algorithm)
+    : m_algorithm(algorithm)
+{
+    ASSERT(m_algorithm.isValidTransition());
+    ASSERT(!m_algorithm.m_needsSetup);
+}
+
+GridTrackSizingAlgorithm::StateMachine::~StateMachine()
+{
+    m_algorithm.advanceNextState();
+    m_algorithm.m_needsSetup = true;
+}
+
+} // namespace WebCore
</ins><span class="cx">Property changes on: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.cpp
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<ins>+LF
</ins><span class="cx">\ No newline at end of property
</span><a id="trunkSourceWebCorerenderingGridTrackSizingAlgorithmh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h (0 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h                                (rev 0)
+++ trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -0,0 +1,241 @@
</span><ins>+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#pragma once
+
+#include &quot;Grid.h&quot;
+#include &quot;GridTrackSize.h&quot;
+#include &quot;LayoutUnit.h&quot;
+
+namespace WebCore {
+
+static const int infinity = -1;
+
+enum SizingOperation { TrackSizing, IntrinsicSizeComputation };
+
+enum TrackSizeComputationPhase {
+    ResolveIntrinsicMinimums,
+    ResolveContentBasedMinimums,
+    ResolveMaxContentMinimums,
+    ResolveIntrinsicMaximums,
+    ResolveMaxContentMaximums,
+    MaximizeTracks,
+};
+
+class GridTrackSizingAlgorithmStrategy;
+
+class GridTrack {
+public:
+    GridTrack() { }
+
+    const LayoutUnit&amp; baseSize() const;
+    void setBaseSize(LayoutUnit);
+
+    const LayoutUnit&amp; growthLimit() const;
+    void setGrowthLimit(LayoutUnit);
+
+    bool infiniteGrowthPotential() const { return growthLimitIsInfinite() || m_infinitelyGrowable; }
+    const LayoutUnit&amp; growthLimitIfNotInfinite() const;
+
+    const LayoutUnit&amp; plannedSize() const { return m_plannedSize; }
+    void setPlannedSize(LayoutUnit plannedSize) { m_plannedSize = plannedSize; }
+
+    const LayoutUnit&amp; tempSize() const { return m_tempSize; }
+    void setTempSize(const LayoutUnit&amp;);
+    void growTempSize(const LayoutUnit&amp;);
+
+    bool infinitelyGrowable() const { return m_infinitelyGrowable; }
+    void setInfinitelyGrowable(bool infinitelyGrowable) { m_infinitelyGrowable = infinitelyGrowable; }
+
+    void setGrowthLimitCap(std::optional&lt;LayoutUnit&gt;);
+    std::optional&lt;LayoutUnit&gt; growthLimitCap() const { return m_growthLimitCap; }
+
+private:
+    bool growthLimitIsInfinite() const { return m_growthLimit == infinity; }
+    bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite() || m_growthLimit &gt;= m_baseSize; }
+
+    void ensureGrowthLimitIsBiggerThanBaseSize();
+
+    LayoutUnit m_baseSize { 0 };
+    LayoutUnit m_growthLimit { 0 };
+    LayoutUnit m_plannedSize { 0 };
+    LayoutUnit m_tempSize { 0 };
+    std::optional&lt;LayoutUnit&gt; m_growthLimitCap;
+    bool m_infinitelyGrowable { false };
+};
+
+class GridTrackSizingAlgorithm final {
+    friend class GridTrackSizingAlgorithmStrategy;
+
+public:
+    GridTrackSizingAlgorithm(const RenderGrid* renderGrid, Grid&amp; grid)
+        : m_grid(grid)
+        , m_renderGrid(renderGrid)
+        , m_sizingState(ColumnSizingFirstIteration)
+    {
+    }
+
+    void setup(GridTrackSizingDirection, unsigned numTracks, SizingOperation, std::optional&lt;LayoutUnit&gt; availableSpace, std::optional&lt;LayoutUnit&gt; freeSpace);
+    void run();
+    void reset();
+
+    // Required by RenderGrid. Try to minimize the exposed surface.
+    const Grid&amp; grid() const { return m_grid; }
+    GridTrackSize gridTrackSize(GridTrackSizingDirection, unsigned translatedIndex, SizingOperation) const;
+
+    LayoutUnit minContentSize() const { return m_minContentSize; };
+    LayoutUnit maxContentSize() const { return m_maxContentSize; };
+
+    Vector&lt;GridTrack&gt;&amp; tracks(GridTrackSizingDirection direction) { return direction == ForColumns ? m_columns : m_rows; }
+    const Vector&lt;GridTrack&gt;&amp; tracks(GridTrackSizingDirection direction) const { return direction == ForColumns ? m_columns : m_rows; }
+
+    std::optional&lt;LayoutUnit&gt; freeSpace(GridTrackSizingDirection direction) const { return direction == ForColumns ? m_freeSpaceColumns : m_freeSpaceRows; }
+    void setFreeSpace(GridTrackSizingDirection, std::optional&lt;LayoutUnit&gt;);
+
+#ifndef NDEBUG
+    bool tracksAreWiderThanMinTrackBreadth() const;
+#endif
+
+private:
+    GridTrackSize gridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex) const { return gridTrackSize(direction, translatedIndex, m_sizingOperation); }
+    const GridTrackSize&amp; rawGridTrackSize(GridTrackSizingDirection, unsigned translatedIndex) const;
+    LayoutUnit assumedRowsSizeForOrthogonalChild(const RenderBox&amp;) const;
+    LayoutUnit computeTrackBasedSize() const;
+
+    // Helper methods for step 1. initializeTrackSizes().
+    LayoutUnit initialBaseSize(const GridTrackSize&amp;) const;
+    LayoutUnit initialGrowthLimit(const GridTrackSize&amp;, LayoutUnit baseSize) const;
+
+    // Helper methods for step 2. resolveIntrinsicTrackSizes().
+    void sizeTrackToFitNonSpanningItem(const GridSpan&amp;, RenderBox&amp; gridItem, GridTrack&amp;);
+    bool spanningItemCrossesFlexibleSizedTracks(const GridSpan&amp;) const;
+    typedef struct GridItemsSpanGroupRange GridItemsSpanGroupRange;
+    template &lt;TrackSizeComputationPhase phase&gt; void increaseSizesToAccommodateSpanningItems(const GridItemsSpanGroupRange&amp; gridItemsWithSpan);
+    LayoutUnit itemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, RenderBox&amp;) const;
+    template &lt;TrackSizeComputationPhase phase&gt; void distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp; tracks, Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; availableLogicalSpace) const;
+    LayoutUnit gridAreaBreadthForChild(const RenderBox&amp;, GridTrackSizingDirection) const;
+
+    void computeGridContainerIntrinsicSizes();
+
+    // Helper methods for step 4. Strech flexible tracks.
+    typedef HashSet&lt;unsigned, DefaultHash&lt;unsigned&gt;::Hash, WTF::UnsignedWithZeroKeyHashTraits&lt;unsigned&gt;&gt; TrackIndexSet;
+    double computeFlexFactorUnitSize(const Vector&lt;GridTrack&gt;&amp; tracks, double flexFactorSum, LayoutUnit&amp; leftOverSpace, const Vector&lt;unsigned, 8&gt;&amp; flexibleTracksIndexes, std::unique_ptr&lt;TrackIndexSet&gt; tracksToTreatAsInflexible = nullptr) const;
+    void computeFlexSizedTracksGrowth(double flexFraction, Vector&lt;LayoutUnit&gt;&amp; increments, LayoutUnit&amp; totalGrowth) const;
+    double findFrUnitSize(const GridSpan&amp; tracksSpan, LayoutUnit leftOverSpace) const;
+
+    // Track sizing algorithm steps. Note that the &quot;Maximize Tracks&quot; step is done
+    // entirely inside the strategies, that's why we don't need an additional
+    // method at thise level.
+    void initializeTrackSizes();
+    void resolveIntrinsicTrackSizes();
+    void stretchFlexibleTracks(std::optional&lt;LayoutUnit&gt; freeSpace);
+
+    // State machine.
+    void advanceNextState();
+    bool isValidTransition() const;
+
+    bool m_needsSetup { true };
+    std::optional&lt;LayoutUnit&gt; m_availableSpace;
+
+    std::optional&lt;LayoutUnit&gt; m_freeSpaceColumns;
+    std::optional&lt;LayoutUnit&gt; m_freeSpaceRows;
+
+    // We need to keep both alive in order to properly size grids with orthogonal
+    // writing modes.
+    Vector&lt;GridTrack&gt; m_columns;
+    Vector&lt;GridTrack&gt; m_rows;
+    Vector&lt;unsigned&gt; m_contentSizedTracksIndex;
+    Vector&lt;unsigned&gt; m_flexibleSizedTracksIndex;
+
+    GridTrackSizingDirection m_direction;
+    SizingOperation m_sizingOperation;
+
+    Grid&amp; m_grid;
+
+    const RenderGrid* m_renderGrid;
+    std::unique_ptr&lt;GridTrackSizingAlgorithmStrategy&gt; m_strategy;
+
+    // The track sizing algorithm is used for both layout and intrinsic size
+    // computation. We're normally just interested in intrinsic inline sizes
+    // (a.k.a widths in most of the cases) for the computeIntrinsicLogicalWidths()
+    // computations. That's why we don't need to keep around different values for
+    // rows/columns.
+    LayoutUnit m_minContentSize;
+    LayoutUnit m_maxContentSize;
+
+    enum SizingState {
+        ColumnSizingFirstIteration,
+        RowSizingFirstIteration,
+        ColumnSizingSecondIteration,
+        RowSizingSecondIteration
+    };
+    SizingState m_sizingState;
+
+    // This is a RAII class used to ensure that the track sizing algorithm is
+    // executed as it is suppossed to be, i.e., first resolve columns and then
+    // rows. Only if required a second iteration is run following the same order,
+    // first columns and then rows.
+    class StateMachine {
+    public:
+        StateMachine(GridTrackSizingAlgorithm&amp;);
+        ~StateMachine();
+
+    private:
+        GridTrackSizingAlgorithm&amp; m_algorithm;
+    };
+};
+
+class GridTrackSizingAlgorithmStrategy {
+public:
+    LayoutUnit minContentForChild(RenderBox&amp;) const;
+    LayoutUnit maxContentForChild(RenderBox&amp;) const;
+    LayoutUnit minSizeForChild(RenderBox&amp;) const;
+
+    virtual ~GridTrackSizingAlgorithmStrategy() { }
+
+    virtual void maximizeTracks(Vector&lt;GridTrack&gt;&amp;, std::optional&lt;LayoutUnit&gt;&amp; freeSpace) = 0;
+    virtual double findUsedFlexFraction(Vector&lt;unsigned&gt;&amp; flexibleSizedTracksIndex, GridTrackSizingDirection, std::optional&lt;LayoutUnit&gt; initialFreeSpace) const = 0;
+    virtual bool recomputeUsedFlexFractionIfNeeded(double&amp; flexFraction, LayoutUnit&amp; totalGrowth) const = 0;
+
+protected:
+    GridTrackSizingAlgorithmStrategy(GridTrackSizingAlgorithm&amp; algorithm)
+        : m_algorithm(algorithm) { }
+
+    virtual LayoutUnit minLogicalWidthForChild(RenderBox&amp;, Length childMinSize, GridTrackSizingDirection) const = 0;
+    virtual void layoutGridItemForMinSizeComputation(RenderBox&amp;, bool overrideSizeHasChanged) const = 0;
+
+    LayoutUnit logicalHeightForChild(RenderBox&amp;) const;
+    bool updateOverrideContainingBlockContentSizeForChild(RenderBox&amp;, GridTrackSizingDirection) const;
+
+    // GridTrackSizingAlgorithm accessors for subclasses.
+    LayoutUnit computeTrackBasedSize() const { return m_algorithm.computeTrackBasedSize(); }
+    GridTrackSizingDirection direction() const { return m_algorithm.m_direction; }
+    double findFrUnitSize(const GridSpan&amp; tracksSpan, LayoutUnit leftOverSpace) const { return m_algorithm.findFrUnitSize(tracksSpan, leftOverSpace); }
+    void distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp; tracks, LayoutUnit&amp; availableLogicalSpace) const { m_algorithm.distributeSpaceToTracks&lt;MaximizeTracks&gt;(tracks, nullptr, availableLogicalSpace); }
+    const RenderGrid* renderGrid() const { return m_algorithm.m_renderGrid; }
+
+    GridTrackSizingAlgorithm&amp; m_algorithm;
+};
+
+} // namespace WebCore
</ins><span class="cx">Property changes on: trunk/Source/WebCore/rendering/GridTrackSizingAlgorithm.h
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<ins>+LF
</ins><span class="cx">\ No newline at end of property
</span><a id="trunkSourceWebCorerenderingRenderGridcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (212822 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderGrid.cpp        2017-02-22 11:34:46 UTC (rev 212822)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -1,6 +1,6 @@
</span><span class="cx"> /*
</span><span class="cx">  * Copyright (C) 2011 Apple Inc. All rights reserved.
</span><del>- * Copyright (C) 2013, 2014 Igalia S.L.
</del><ins>+ * Copyright (C) 2013-2017 Igalia S.L.
</ins><span class="cx">  *
</span><span class="cx">  * Redistribution and use in source and binary forms, with or without
</span><span class="cx">  * modification, are permitted provided that the following conditions
</span><span class="lines">@@ -29,6 +29,7 @@
</span><span class="cx"> 
</span><span class="cx"> #include &quot;GridArea.h&quot;
</span><span class="cx"> #include &quot;GridPositionsResolver.h&quot;
</span><ins>+#include &quot;GridTrackSizingAlgorithm.h&quot;
</ins><span class="cx"> #include &quot;LayoutRepainter.h&quot;
</span><span class="cx"> #include &quot;RenderLayer.h&quot;
</span><span class="cx"> #include &quot;RenderView.h&quot;
</span><span class="lines">@@ -36,7 +37,6 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><del>-static const int infinity = -1;
</del><span class="cx"> static constexpr ItemPosition selfAlignmentNormalBehavior = ItemPositionStretch;
</span><span class="cx"> 
</span><span class="cx"> enum TrackSizeRestriction {
</span><span class="lines">@@ -44,94 +44,6 @@
</span><span class="cx">     ForbidInfinity,
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-class GridTrack {
-public:
-    GridTrack() {}
-
-    const LayoutUnit&amp; baseSize() const
-    {
-        ASSERT(isGrowthLimitBiggerThanBaseSize());
-        return m_baseSize;
-    }
-
-    const LayoutUnit&amp; growthLimit() const
-    {
-        ASSERT(isGrowthLimitBiggerThanBaseSize());
-        ASSERT(!m_growthLimitCap || m_growthLimitCap.value() &gt;= m_growthLimit || m_baseSize &gt;= m_growthLimitCap.value());
-        return m_growthLimit;
-    }
-
-    void setBaseSize(LayoutUnit baseSize)
-    {
-        m_baseSize = baseSize;
-        ensureGrowthLimitIsBiggerThanBaseSize();
-    }
-
-    void setGrowthLimit(LayoutUnit growthLimit)
-    {
-        m_growthLimit = growthLimit == infinity ? growthLimit : std::min(growthLimit, m_growthLimitCap.value_or(growthLimit));
-        ensureGrowthLimitIsBiggerThanBaseSize();
-    }
-
-    bool infiniteGrowthPotential() const { return growthLimitIsInfinite() || m_infinitelyGrowable; }
-
-    const LayoutUnit&amp; growthLimitIfNotInfinite() const
-    {
-        ASSERT(isGrowthLimitBiggerThanBaseSize());
-        return (m_growthLimit == infinity) ? m_baseSize : m_growthLimit;
-    }
-
-    const LayoutUnit&amp; plannedSize() const { return m_plannedSize; }
-
-    void setPlannedSize(LayoutUnit plannedSize)
-    {
-        m_plannedSize = plannedSize;
-    }
-
-    const LayoutUnit&amp; tempSize() const { return m_tempSize; }
-
-    void setTempSize(const LayoutUnit&amp; tempSize)
-    {
-        ASSERT(tempSize &gt;= 0);
-        ASSERT(growthLimitIsInfinite() || growthLimit() &gt;= tempSize);
-        m_tempSize = tempSize;
-    }
-
-    void growTempSize(const LayoutUnit&amp; tempSize)
-    {
-        ASSERT(tempSize &gt;= 0);
-        m_tempSize += tempSize;
-    }
-
-    bool infinitelyGrowable() const { return m_infinitelyGrowable; }
-    void setInfinitelyGrowable(bool infinitelyGrowable) { m_infinitelyGrowable = infinitelyGrowable; }
-
-    void setGrowthLimitCap(std::optional&lt;LayoutUnit&gt; growthLimitCap)
-    {
-        ASSERT(!growthLimitCap || growthLimitCap.value() &gt;= 0);
-        m_growthLimitCap = growthLimitCap;
-    }
-
-    std::optional&lt;LayoutUnit&gt; growthLimitCap() const { return m_growthLimitCap; }
-
-private:
-    bool growthLimitIsInfinite() const { return m_growthLimit == infinity; }
-    bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite() || m_growthLimit &gt;= m_baseSize; }
-
-    void ensureGrowthLimitIsBiggerThanBaseSize()
-    {
-        if (m_growthLimit != infinity &amp;&amp; m_growthLimit &lt; m_baseSize)
-            m_growthLimit = m_baseSize;
-    }
-
-    LayoutUnit m_baseSize { 0 };
-    LayoutUnit m_growthLimit { 0 };
-    LayoutUnit m_plannedSize { 0 };
-    LayoutUnit m_tempSize { 0 };
-    std::optional&lt;LayoutUnit&gt; m_growthLimitCap;
-    bool m_infinitelyGrowable { false };
-};
-
</del><span class="cx"> struct ContentAlignmentData {
</span><span class="cx">     WTF_MAKE_FAST_ALLOCATED;
</span><span class="cx"> public:
</span><span class="lines">@@ -142,91 +54,10 @@
</span><span class="cx">     LayoutUnit distributionOffset;
</span><span class="cx"> };
</span><span class="cx"> 
</span><del>-class RenderGrid::GridSizingData {
-    WTF_MAKE_NONCOPYABLE(GridSizingData);
-public:
-    GridSizingData(unsigned gridColumnCount, unsigned gridRowCount, Grid&amp; grid)
-        : columnTracks(gridColumnCount)
-        , rowTracks(gridRowCount)
-        , m_grid(grid)
-    {
-    }
-
-    Vector&lt;GridTrack&gt; columnTracks;
-    Vector&lt;GridTrack&gt; rowTracks;
-    Vector&lt;unsigned&gt; contentSizedTracksIndex;
-
-    // Performance optimization: hold onto these Vectors until the end of Layout to avoid repeated malloc / free.
-    Vector&lt;GridTrack*&gt; filteredTracks;
-    Vector&lt;GridTrack*&gt; growBeyondGrowthLimitsTracks;
-    Vector&lt;GridItemWithSpan&gt; itemsSortedByIncreasingSpan;
-
-    std::optional&lt;LayoutUnit&gt; freeSpace(GridTrackSizingDirection direction) { return direction == ForColumns ? freeSpaceForColumns : freeSpaceForRows; }
-    void setFreeSpace(GridTrackSizingDirection, std::optional&lt;LayoutUnit&gt; freeSpace);
-
-    std::optional&lt;LayoutUnit&gt; availableSpace() const { return m_availableSpace; }
-    void setAvailableSpace(std::optional&lt;LayoutUnit&gt; availableSpace) { m_availableSpace = availableSpace; }
-
-    SizingOperation sizingOperation { TrackSizing };
-
-    enum SizingState { ColumnSizingFirstIteration, RowSizingFirstIteration, ColumnSizingSecondIteration, RowSizingSecondIteration};
-    SizingState sizingState { ColumnSizingFirstIteration };
-    void advanceNextState()
-    {
-        switch (sizingState) {
-        case ColumnSizingFirstIteration:
-            sizingState = RowSizingFirstIteration;
-            return;
-        case RowSizingFirstIteration:
-            sizingState = ColumnSizingSecondIteration;
-            return;
-        case ColumnSizingSecondIteration:
-            sizingState = RowSizingSecondIteration;
-            return;
-        case RowSizingSecondIteration:
-            sizingState = ColumnSizingFirstIteration;
-            return;
-        }
-        ASSERT_NOT_REACHED();
-        sizingState = ColumnSizingFirstIteration;
-    }
-    bool isValidTransition(GridTrackSizingDirection direction) const
-    {
-        switch (sizingState) {
-        case ColumnSizingFirstIteration:
-        case ColumnSizingSecondIteration:
-            return direction == ForColumns;
-        case RowSizingFirstIteration:
-        case RowSizingSecondIteration:
-            return direction == ForRows;
-        }
-        ASSERT_NOT_REACHED();
-        return false;
-    }
-
-    Grid&amp; grid() const { return m_grid; }
-
-private:
-    std::optional&lt;LayoutUnit&gt; freeSpaceForColumns;
-    std::optional&lt;LayoutUnit&gt; freeSpaceForRows;
-    // No need to store one per direction as it will be only used for computations during each axis
-    // track sizing. It's cached here because we need it to compute relative sizes.
-    std::optional&lt;LayoutUnit&gt; m_availableSpace;
-
-    Grid&amp; m_grid;
-};
-
-void RenderGrid::GridSizingData::setFreeSpace(GridTrackSizingDirection direction, std::optional&lt;LayoutUnit&gt; freeSpace)
-{
-    if (direction == ForColumns)
-        freeSpaceForColumns = freeSpace;
-    else
-        freeSpaceForRows = freeSpace;
-}
-
</del><span class="cx"> RenderGrid::RenderGrid(Element&amp; element, RenderStyle&amp;&amp; style)
</span><span class="cx">     : RenderBlock(element, WTFMove(style), 0)
</span><span class="cx">     , m_grid(*this)
</span><ins>+    , m_trackSizingAlgorithm(this, m_grid)
</ins><span class="cx"> {
</span><span class="cx">     // All of our children must be block level.
</span><span class="cx">     setChildrenInline(false);
</span><span class="lines">@@ -335,37 +166,32 @@
</span><span class="cx">         || oldStyle.namedGridColumnLines() != style().namedGridColumnLines();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-LayoutUnit RenderGrid::computeTrackBasedLogicalHeight(const GridSizingData&amp; sizingData) const
</del><ins>+LayoutUnit RenderGrid::computeTrackBasedLogicalHeight() const
</ins><span class="cx"> {
</span><span class="cx">     LayoutUnit logicalHeight;
</span><span class="cx"> 
</span><del>-    for (const auto&amp; row : sizingData.rowTracks)
</del><ins>+    auto&amp; allRows = m_trackSizingAlgorithm.tracks(ForRows);
+    for (const auto&amp; row : allRows)
</ins><span class="cx">         logicalHeight += row.baseSize();
</span><span class="cx"> 
</span><del>-    logicalHeight += guttersSize(sizingData.grid(), ForRows, 0, sizingData.rowTracks.size());
</del><ins>+    logicalHeight += guttersSize(m_grid, ForRows, 0, allRows.size());
</ins><span class="cx"> 
</span><span class="cx">     return logicalHeight;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderGrid::computeTrackSizesForDirection(GridTrackSizingDirection direction, GridSizingData&amp; sizingData, LayoutUnit availableSpace)
</del><ins>+void RenderGrid::computeTrackSizesForDefiniteSize(GridTrackSizingDirection direction, LayoutUnit availableSpace)
</ins><span class="cx"> {
</span><del>-    ASSERT(sizingData.isValidTransition(direction));
-    LayoutUnit totalGuttersSize = guttersSize(sizingData.grid(), direction, 0, m_grid.numTracks(direction));
-    sizingData.setAvailableSpace(availableSpace);
-    sizingData.setFreeSpace(direction, availableSpace - totalGuttersSize);
-    sizingData.sizingOperation = TrackSizing;
</del><ins>+    LayoutUnit totalGuttersSize = guttersSize(m_grid, direction, 0, m_grid.numTracks(direction));
+    LayoutUnit freeSpace = availableSpace - totalGuttersSize;
</ins><span class="cx"> 
</span><del>-    LayoutUnit baseSizes, growthLimits;
-    computeUsedBreadthOfGridTracks(direction, sizingData, baseSizes, growthLimits);
-    ASSERT(tracksAreWiderThanMinTrackBreadth(direction, sizingData));
-    sizingData.advanceNextState();
</del><ins>+    m_trackSizingAlgorithm.setup(direction, numTracks(direction, m_grid), TrackSizing, availableSpace, freeSpace);
+    m_trackSizingAlgorithm.run();
+
+    ASSERT(m_trackSizingAlgorithm.tracksAreWiderThanMinTrackBreadth());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderGrid::repeatTracksSizingIfNeeded(GridSizingData&amp; sizingData, LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows)
</del><ins>+void RenderGrid::repeatTracksSizingIfNeeded(LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows)
</ins><span class="cx"> {
</span><del>-    ASSERT(!sizingData.grid().needsItemsPlacement());
-    ASSERT(sizingData.sizingState &gt; GridSizingData::RowSizingFirstIteration);
-
</del><span class="cx">     // In orthogonal flow cases column track's size is determined by using the computed
</span><span class="cx">     // row track's size, which it was estimated during the first cycle of the sizing
</span><span class="cx">     // algorithm. Hence we need to repeat computeUsedBreadthOfGridTracks for both,
</span><span class="lines">@@ -374,9 +200,9 @@
</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 (sizingData.grid().hasAnyOrthogonalGridItem()) {
-        computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForColumns);
-        computeTrackSizesForDirection(ForRows, sizingData, availableSpaceForRows);
</del><ins>+    if (m_grid.hasAnyOrthogonalGridItem()) {
+        computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
+        computeTrackSizesForDefiniteSize(ForRows, availableSpaceForRows);
</ins><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -422,23 +248,30 @@
</span><span class="cx"> 
</span><span class="cx">     placeItemsOnGrid(m_grid, TrackSizing);
</span><span class="cx"> 
</span><del>-    GridSizingData sizingData(numTracks(ForColumns, m_grid), numTracks(ForRows, m_grid), m_grid);
-
</del><span class="cx">     // At this point the logical width is always definite as the above call to updateLogicalWidth()
</span><span class="cx">     // properly resolves intrinsic sizes. We cannot do the same for heights though because many code
</span><span class="cx">     // paths inside updateLogicalHeight() require a previous call to setLogicalHeight() to resolve
</span><span class="cx">     // heights properly (like for positioned items for example).
</span><span class="cx">     LayoutUnit availableSpaceForColumns = availableLogicalWidth();
</span><del>-    computeTrackSizesForDirection(ForColumns, sizingData, availableSpaceForColumns);
</del><ins>+    computeTrackSizesForDefiniteSize(ForColumns, availableSpaceForColumns);
</ins><span class="cx"> 
</span><span class="cx">     // FIXME: We should use RenderBlock::hasDefiniteLogicalHeight() but it does not work for positioned stuff.
</span><span class="cx">     // FIXME: Consider caching the hasDefiniteLogicalHeight value throughout the layout.
</span><span class="cx">     bool hasDefiniteLogicalHeight = hasOverrideLogicalContentHeight() || computeContentLogicalHeight(MainOrPreferredSize, style().logicalHeight(), std::nullopt);
</span><del>-    if (!hasDefiniteLogicalHeight)
-        computeIntrinsicLogicalHeight(sizingData);
-    else
-        computeTrackSizesForDirection(ForRows, sizingData, availableLogicalHeight(ExcludeMarginBorderPadding));
-    LayoutUnit trackBasedLogicalHeight = computeTrackBasedLogicalHeight(sizingData) + borderAndPaddingLogicalHeight() + scrollbarLogicalHeight();
</del><ins>+    if (!hasDefiniteLogicalHeight) {
+        m_minContentHeight = LayoutUnit();
+        m_maxContentHeight = LayoutUnit();
+        computeTrackSizesForIndefiniteSize(m_trackSizingAlgorithm, ForRows, m_grid, *m_minContentHeight, *m_maxContentHeight);
+        // FIXME: This should be really added to the intrinsic height in RenderBox::computeContentAndScrollbarLogicalHeightUsing().
+        // Remove this when that is fixed.
+        ASSERT(m_minContentHeight);
+        ASSERT(m_maxContentHeight);
+        LayoutUnit scrollbarHeight = scrollbarLogicalHeight();
+        *m_minContentHeight += scrollbarHeight;
+        *m_maxContentHeight += scrollbarHeight;
+    } else
+        computeTrackSizesForDefiniteSize(ForRows, availableLogicalHeight(ExcludeMarginBorderPadding));
+    LayoutUnit trackBasedLogicalHeight = computeTrackBasedLogicalHeight() + borderAndPaddingLogicalHeight() + scrollbarLogicalHeight();
</ins><span class="cx">     setLogicalHeight(trackBasedLogicalHeight);
</span><span class="cx"> 
</span><span class="cx">     LayoutUnit oldClientAfterEdge = clientLogicalBottom();
</span><span class="lines">@@ -447,12 +280,12 @@
</span><span class="cx">     // Once grid's indefinite height is resolved, we can compute the
</span><span class="cx">     // available free space for Content Alignment.
</span><span class="cx">     if (!hasDefiniteLogicalHeight)
</span><del>-        sizingData.setFreeSpace(ForRows, logicalHeight() - trackBasedLogicalHeight);
</del><ins>+        m_trackSizingAlgorithm.setFreeSpace(ForRows, logicalHeight() - trackBasedLogicalHeight);
</ins><span class="cx"> 
</span><span class="cx">     // 3- If the min-content contribution of any grid items have changed based on the row
</span><span class="cx">     // sizes calculated in step 2, steps 1 and 2 are repeated with the new min-content
</span><span class="cx">     // contribution (once only).
</span><del>-    repeatTracksSizingIfNeeded(sizingData, availableSpaceForColumns, contentLogicalHeight());
</del><ins>+    repeatTracksSizingIfNeeded(availableSpaceForColumns, contentLogicalHeight());
</ins><span class="cx"> 
</span><span class="cx">     // Grid container should have the minimum height of a line if it's editable. That does not affect track sizing though.
</span><span class="cx">     if (hasLineIfEmpty()) {
</span><span class="lines">@@ -462,10 +295,11 @@
</span><span class="cx">         setLogicalHeight(std::max(logicalHeight(), minHeightForEmptyLine));
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-    applyStretchAlignmentToTracksIfNeeded(ForColumns, sizingData);
-    applyStretchAlignmentToTracksIfNeeded(ForRows, sizingData);
</del><ins>+    applyStretchAlignmentToTracksIfNeeded(ForColumns);
+    applyStretchAlignmentToTracksIfNeeded(ForRows);
</ins><span class="cx"> 
</span><del>-    layoutGridItems(sizingData);
</del><ins>+    layoutGridItems();
+    m_trackSizingAlgorithm.reset();
</ins><span class="cx"> 
</span><span class="cx">     if (size() != previousSize)
</span><span class="cx">         relayoutChildren = true;
</span><span class="lines">@@ -557,46 +391,26 @@
</span><span class="cx">     Grid grid(const_cast&lt;RenderGrid&amp;&gt;(*this));
</span><span class="cx">     placeItemsOnGrid(grid, IntrinsicSizeComputation);
</span><span class="cx"> 
</span><del>-    GridSizingData sizingData(numTracks(ForColumns, grid), numTracks(ForRows, grid), grid);
-    sizingData.setAvailableSpace(std::nullopt);
-    sizingData.setFreeSpace(ForColumns, std::nullopt);
-    sizingData.sizingOperation = IntrinsicSizeComputation;
-    computeUsedBreadthOfGridTracks(ForColumns, sizingData, minLogicalWidth, maxLogicalWidth);
</del><ins>+    GridTrackSizingAlgorithm algorithm(this, grid);
+    computeTrackSizesForIndefiniteSize(algorithm, ForColumns, grid, minLogicalWidth, maxLogicalWidth);
</ins><span class="cx"> 
</span><del>-    LayoutUnit totalGuttersSize = guttersSize(sizingData.grid(), ForColumns, 0, sizingData.columnTracks.size());
-    minLogicalWidth += totalGuttersSize;
-    maxLogicalWidth += totalGuttersSize;
-
</del><span class="cx">     LayoutUnit scrollbarWidth = intrinsicScrollbarLogicalWidth();
</span><span class="cx">     minLogicalWidth += scrollbarWidth;
</span><span class="cx">     maxLogicalWidth += scrollbarWidth;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderGrid::computeIntrinsicLogicalHeight(GridSizingData&amp; sizingData)
</del><ins>+void RenderGrid::computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&amp; algorithm, GridTrackSizingDirection direction, Grid&amp; grid, LayoutUnit&amp; minIntrinsicSize, LayoutUnit&amp; maxIntrinsicSize) const
</ins><span class="cx"> {
</span><del>-    ASSERT(sizingData.isValidTransition(ForRows));
-    sizingData.setAvailableSpace(std::nullopt);
-    sizingData.setFreeSpace(ForRows, std::nullopt);
-    sizingData.sizingOperation = IntrinsicSizeComputation;
-    LayoutUnit minHeight, maxHeight;
-    computeUsedBreadthOfGridTracks(ForRows, sizingData, minHeight, maxHeight);
</del><ins>+    algorithm.setup(direction, numTracks(direction, grid), IntrinsicSizeComputation, std::nullopt, std::nullopt);
+    algorithm.run();
</ins><span class="cx"> 
</span><del>-    // FIXME: This should be really added to the intrinsic height in RenderBox::computeContentAndScrollbarLogicalHeightUsing().
-    // Remove this when that is fixed.
-    LayoutUnit scrollbarHeight = scrollbarLogicalHeight();
-    minHeight += scrollbarHeight;
-    maxHeight += scrollbarHeight;
</del><ins>+    size_t numberOfTracks = algorithm.tracks(direction).size();
+    LayoutUnit totalGuttersSize = guttersSize(grid, direction, 0, numberOfTracks);
</ins><span class="cx"> 
</span><del>-    LayoutUnit totalGuttersSize = guttersSize(sizingData.grid(), ForRows, 0, m_grid.numTracks(ForRows));
-    minHeight += totalGuttersSize;
-    maxHeight += totalGuttersSize;
</del><ins>+    minIntrinsicSize = algorithm.minContentSize() + totalGuttersSize;
+    maxIntrinsicSize = algorithm.maxContentSize() + totalGuttersSize;
</ins><span class="cx"> 
</span><del>-    m_minContentHeight = minHeight;
-    m_maxContentHeight = maxHeight;
-
-    ASSERT(tracksAreWiderThanMinTrackBreadth(ForRows, sizingData));
-    sizingData.advanceNextState();
-    sizingData.sizingOperation = TrackSizing;
</del><ins>+    ASSERT(algorithm.tracksAreWiderThanMinTrackBreadth());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> std::optional&lt;LayoutUnit&gt; RenderGrid::computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional&lt;LayoutUnit&gt; intrinsicLogicalHeight, LayoutUnit borderAndPadding) const
</span><span class="lines">@@ -621,339 +435,11 @@
</span><span class="cx">     return std::nullopt;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static inline double normalizedFlexFraction(const GridTrack&amp; track, double flexFactor)
-{
-    return track.baseSize() / std::max&lt;double&gt;(1, flexFactor);
-}
-
-void RenderGrid::computeUsedBreadthOfGridTracks(GridTrackSizingDirection direction, GridSizingData&amp; sizingData, LayoutUnit&amp; baseSizesWithoutMaximization, LayoutUnit&amp; growthLimitsWithoutMaximization) const
-{
-    const std::optional&lt;LayoutUnit&gt; initialFreeSpace = sizingData.freeSpace(direction);
-    Vector&lt;GridTrack&gt;&amp; tracks = (direction == ForColumns) ? sizingData.columnTracks : sizingData.rowTracks;
-    Vector&lt;unsigned&gt; flexibleSizedTracksIndex;
-    sizingData.contentSizedTracksIndex.shrink(0);
-
-    // Grid gutters were removed from freeSpace by the caller (if freeSpace is definite),
-    // but we must use them to compute relative (i.e. percentages) sizes.
-    LayoutUnit maxSize = std::max(LayoutUnit(), sizingData.availableSpace().value_or(LayoutUnit()));
-    const bool hasDefiniteFreeSpace = sizingData.sizingOperation == TrackSizing;
-
-    // 1. Initialize per Grid track variables.
-    for (unsigned i = 0; i &lt; tracks.size(); ++i) {
-        GridTrack&amp; track = tracks[i];
-        const GridTrackSize&amp; trackSize = gridTrackSize(direction, i, sizingData);
-
-        track.setBaseSize(computeUsedBreadthOfMinLength(trackSize, maxSize));
-        track.setGrowthLimit(computeUsedBreadthOfMaxLength(trackSize, track.baseSize(), maxSize));
-        track.setInfinitelyGrowable(false);
-
-        if (trackSize.isFitContent()) {
-            GridLength gridLength = trackSize.fitContentTrackBreadth();
-            if (!gridLength.isPercentage() || hasDefiniteFreeSpace)
-                track.setGrowthLimitCap(valueForLength(gridLength.length(), maxSize));
-        }
-        if (trackSize.isContentSized())
-            sizingData.contentSizedTracksIndex.append(i);
-        if (trackSize.maxTrackBreadth().isFlex())
-            flexibleSizedTracksIndex.append(i);
-    }
-
-    // 2. Resolve content-based TrackSizingFunctions.
-    if (!sizingData.contentSizedTracksIndex.isEmpty())
-        resolveContentBasedTrackSizingFunctions(direction, sizingData);
-
-    baseSizesWithoutMaximization = growthLimitsWithoutMaximization = 0;
-
-    for (auto&amp; track : tracks) {
-        ASSERT(!track.infiniteGrowthPotential());
-        baseSizesWithoutMaximization += track.baseSize();
-        growthLimitsWithoutMaximization += track.growthLimit();
-        // The growth limit caps must be cleared now in order to properly sort tracks by growth
-        // potential on an eventual &quot;Maximize Tracks&quot;.
-        track.setGrowthLimitCap(std::nullopt);
-    }
-    LayoutUnit freeSpace = initialFreeSpace ? initialFreeSpace.value() - baseSizesWithoutMaximization : LayoutUnit(0);
-
-    if (hasDefiniteFreeSpace &amp;&amp; freeSpace &lt;= 0) {
-        sizingData.setFreeSpace(direction, freeSpace);
-        return;
-    }
-
-    // 3. Grow all Grid tracks in GridTracks from their UsedBreadth up to their MaxBreadth value until freeSpace is exhausted.
-    if (hasDefiniteFreeSpace) {
-        const unsigned tracksSize = tracks.size();
-        Vector&lt;GridTrack*&gt; tracksForDistribution(tracksSize);
-        for (unsigned i = 0; i &lt; tracksSize; ++i) {
-            tracksForDistribution[i] = tracks.data() + i;
-            tracksForDistribution[i]-&gt;setPlannedSize(tracksForDistribution[i]-&gt;baseSize());
-        }
-
-        distributeSpaceToTracks&lt;MaximizeTracks&gt;(tracksForDistribution, nullptr, freeSpace);
-
-        for (auto* track : tracksForDistribution)
-            track-&gt;setBaseSize(track-&gt;plannedSize());
-    } else {
-        for (auto&amp; track : tracks)
-            track.setBaseSize(track.growthLimit());
-    }
-
-    if (flexibleSizedTracksIndex.isEmpty()) {
-        sizingData.setFreeSpace(direction, freeSpace);
-        return;
-    }
-
-    // 4. Grow all Grid tracks having a fraction as the MaxTrackSizingFunction.
-    double flexFraction = 0;
-    if (hasDefiniteFreeSpace)
-        flexFraction = findFlexFactorUnitSize(tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()), direction, initialFreeSpace.value(), sizingData);
-    else {
-        for (const auto&amp; trackIndex : flexibleSizedTracksIndex)
-            flexFraction = std::max(flexFraction, normalizedFlexFraction(tracks[trackIndex], gridTrackSize(direction, trackIndex, sizingData).maxTrackBreadth().flex()));
-
-        Grid&amp; grid = sizingData.grid();
-        if (grid.hasGridItems()) {
-            for (unsigned i = 0; i &lt; flexibleSizedTracksIndex.size(); ++i) {
-                GridIterator iterator(grid, direction, flexibleSizedTracksIndex[i]);
-                while (auto* gridItem = iterator.nextGridItem()) {
-                    const GridSpan&amp; span = grid.gridItemSpan(*gridItem, direction);
-
-                    // Do not include already processed items.
-                    if (i &gt; 0 &amp;&amp; span.startLine() &lt;= flexibleSizedTracksIndex[i - 1])
-                        continue;
-
-                    flexFraction = std::max(flexFraction, findFlexFactorUnitSize(tracks, span, direction, maxContentForChild(*gridItem, direction, sizingData), sizingData));
-                }
-            }
-        }
-    }
-    LayoutUnit totalGrowth;
-    Vector&lt;LayoutUnit&gt; increments;
-    increments.grow(flexibleSizedTracksIndex.size());
-    computeFlexSizedTracksGrowth(direction, sizingData, tracks, flexibleSizedTracksIndex, flexFraction, increments, totalGrowth);
-
-    // We only need to redo the flex fraction computation for indefinite heights (definite sizes are
-    // already constrained by min/max sizes). Regarding widths, they are always definite at layout
-    // time so we shouldn't ever have to do this.
-    if (!hasDefiniteFreeSpace &amp;&amp; direction == ForRows) {
-        auto minSize = computeContentLogicalHeight(MinSize, style().logicalMinHeight(), LayoutUnit(-1));
-        auto maxSize = computeContentLogicalHeight(MaxSize, style().logicalMaxHeight(), LayoutUnit(-1));
-
-        // Redo the flex fraction computation using min|max-height as definite available space in
-        // case the total height is smaller than min-height or larger than max-height.
-        LayoutUnit rowsSize = totalGrowth + computeTrackBasedLogicalHeight(sizingData);
-        bool checkMinSize = minSize &amp;&amp; rowsSize &lt; minSize.value();
-        bool checkMaxSize = maxSize &amp;&amp; rowsSize &gt; maxSize.value();
-        if (checkMinSize || checkMaxSize) {
-            LayoutUnit constrainedFreeSpace = checkMaxSize ? maxSize.value() : LayoutUnit(-1);
-            constrainedFreeSpace = std::max(constrainedFreeSpace, minSize.value()) - guttersSize(sizingData.grid(), ForRows, 0, sizingData.grid().numTracks(ForRows));
-            flexFraction = findFlexFactorUnitSize(tracks, GridSpan::translatedDefiniteGridSpan(0, tracks.size()), ForRows, constrainedFreeSpace, sizingData);
-
-            totalGrowth = LayoutUnit(0);
-            computeFlexSizedTracksGrowth(ForRows, sizingData, tracks, flexibleSizedTracksIndex, flexFraction, increments, totalGrowth);
-        }
-    }
-
-    for (size_t i = 0; i &lt; flexibleSizedTracksIndex.size(); ++i) {
-        if (LayoutUnit increment = increments[i]) {
-            auto&amp; track = tracks[flexibleSizedTracksIndex[i]];
-            track.setBaseSize(track.baseSize() + increment);
-        }
-    }
-    freeSpace -= totalGrowth;
-    growthLimitsWithoutMaximization += totalGrowth;
-    sizingData.setFreeSpace(direction, freeSpace);
-}
-
-void RenderGrid::computeFlexSizedTracksGrowth(GridTrackSizingDirection direction, const GridSizingData&amp; sizingData, Vector&lt;GridTrack&gt;&amp; tracks, const Vector&lt;unsigned&gt;&amp; flexibleSizedTracksIndex, double flexFraction, Vector&lt;LayoutUnit&gt;&amp; increments, LayoutUnit&amp; totalGrowth) const
-{
-    size_t numFlexTracks = flexibleSizedTracksIndex.size();
-    ASSERT(increments.size() == numFlexTracks);
-    for (size_t i = 0; i &lt; numFlexTracks; ++i) {
-        unsigned trackIndex = flexibleSizedTracksIndex[i];
-        auto trackSize = gridTrackSize(direction, trackIndex, sizingData);
-        ASSERT(trackSize.maxTrackBreadth().isFlex());
-        LayoutUnit oldBaseSize = tracks[trackIndex].baseSize();
-        LayoutUnit newBaseSize = std::max(oldBaseSize, LayoutUnit(flexFraction * trackSize.maxTrackBreadth().flex()));
-        increments[i] = newBaseSize - oldBaseSize;
-        totalGrowth += increments[i];
-    }
-}
-
-LayoutUnit RenderGrid::computeUsedBreadthOfMinLength(const GridTrackSize&amp; trackSize, LayoutUnit maxSize) const
-{
-    const GridLength&amp; gridLength = trackSize.minTrackBreadth();
-    if (gridLength.isFlex())
-        return 0;
-
-    const Length&amp; trackLength = gridLength.length();
-    if (trackLength.isSpecified())
-        return valueForLength(trackLength, maxSize);
-
-    ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isMaxContent());
-    return 0;
-}
-
-LayoutUnit RenderGrid::computeUsedBreadthOfMaxLength(const GridTrackSize&amp; trackSize, LayoutUnit usedBreadth, LayoutUnit maxSize) const
-{
-    const GridLength&amp; gridLength = trackSize.maxTrackBreadth();
-    if (gridLength.isFlex())
-        return usedBreadth;
-
-    const Length&amp; trackLength = gridLength.length();
-    if (trackLength.isSpecified())
-        return valueForLength(trackLength, maxSize);
-
-    ASSERT(trackLength.isMinContent() || trackLength.isAuto() || trackLength.isMaxContent());
-    return infinity;
-}
-
-double RenderGrid::computeFlexFactorUnitSize(const Vector&lt;GridTrack&gt;&amp; tracks, GridTrackSizingDirection direction, const GridSizingData&amp; sizingData, double flexFactorSum, LayoutUnit leftOverSpace, const Vector&lt;unsigned, 8&gt;&amp; flexibleTracksIndexes, std::unique_ptr&lt;TrackIndexSet&gt; tracksToTreatAsInflexible) const
-{
-    // We want to avoid the effect of flex factors sum below 1 making the factor unit size to grow exponentially.
-    double hypotheticalFactorUnitSize = leftOverSpace / std::max&lt;double&gt;(1, flexFactorSum);
-
-    // product of the hypothetical &quot;flex factor unit&quot; and any flexible track's &quot;flex factor&quot; must be grater than such track's &quot;base size&quot;.
-    bool validFlexFactorUnit = true;
-    for (auto index : flexibleTracksIndexes) {
-        if (tracksToTreatAsInflexible &amp;&amp; tracksToTreatAsInflexible-&gt;contains(index))
-            continue;
-        LayoutUnit baseSize = tracks[index].baseSize();
-        double flexFactor = gridTrackSize(direction, index, sizingData).maxTrackBreadth().flex();
-        // treating all such tracks as inflexible.
-        if (baseSize &gt; hypotheticalFactorUnitSize * flexFactor) {
-            leftOverSpace -= baseSize;
-            flexFactorSum -= flexFactor;
-            if (!tracksToTreatAsInflexible)
-                tracksToTreatAsInflexible = std::unique_ptr&lt;TrackIndexSet&gt;(new TrackIndexSet());
-            tracksToTreatAsInflexible-&gt;add(index);
-            validFlexFactorUnit = false;
-        }
-    }
-    if (!validFlexFactorUnit)
-        return computeFlexFactorUnitSize(tracks, direction, sizingData, flexFactorSum, leftOverSpace, flexibleTracksIndexes, WTFMove(tracksToTreatAsInflexible));
-    return hypotheticalFactorUnitSize;
-}
-
-double RenderGrid::findFlexFactorUnitSize(const Vector&lt;GridTrack&gt;&amp; tracks, const GridSpan&amp; tracksSpan, GridTrackSizingDirection direction, LayoutUnit leftOverSpace, const GridSizingData&amp; sizingData) const
-{
-    if (leftOverSpace &lt;= 0)
-        return 0;
-
-    double flexFactorSum = 0;
-    Vector&lt;unsigned, 8&gt; flexibleTracksIndexes;
-    for (auto trackIndex : tracksSpan) {
-        GridTrackSize trackSize = gridTrackSize(direction, trackIndex, sizingData);
-        if (!trackSize.maxTrackBreadth().isFlex())
-            leftOverSpace -= tracks[trackIndex].baseSize();
-        else {
-            double flexFactor = trackSize.maxTrackBreadth().flex();
-            flexibleTracksIndexes.append(trackIndex);
-            flexFactorSum += flexFactor;
-        }
-    }
-
-    // The function is not called if we don't have &lt;flex&gt; grid tracks
-    ASSERT(!flexibleTracksIndexes.isEmpty());
-
-    return computeFlexFactorUnitSize(tracks, direction, sizingData, flexFactorSum, leftOverSpace, flexibleTracksIndexes);
-}
-
-static bool hasOverrideContainingBlockContentSizeForChild(const RenderBox&amp; child, GridTrackSizingDirection direction)
-{
-    return direction == ForColumns ? child.hasOverrideContainingBlockLogicalWidth() : child.hasOverrideContainingBlockLogicalHeight();
-}
-
</del><span class="cx"> static std::optional&lt;LayoutUnit&gt; overrideContainingBlockContentSizeForChild(const RenderBox&amp; child, GridTrackSizingDirection direction)
</span><span class="cx"> {
</span><span class="cx">     return direction == ForColumns ? child.overrideContainingBlockContentLogicalWidth() : child.overrideContainingBlockContentLogicalHeight();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-static void setOverrideContainingBlockContentSizeForChild(RenderBox&amp; child, GridTrackSizingDirection direction, std::optional&lt;LayoutUnit&gt; size)
-{
-    if (direction == ForColumns)
-        child.setOverrideContainingBlockContentLogicalWidth(size);
-    else
-        child.setOverrideContainingBlockContentLogicalHeight(size);
-}
-
-static bool shouldClearOverrideContainingBlockContentSizeForChild(const RenderBox&amp; child, GridTrackSizingDirection direction)
-{
-    if (direction == ForColumns)
-        return child.hasRelativeLogicalWidth() || child.style().logicalWidth().isIntrinsicOrAuto();
-    return child.hasRelativeLogicalHeight() || child.style().logicalHeight().isIntrinsicOrAuto();
-}
-
-const GridTrackSize&amp; RenderGrid::rawGridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex, const GridSizingData&amp; sizingData) const
-{
-    bool isRowAxis = direction == ForColumns;
-    auto&amp; trackStyles = isRowAxis ? style().gridColumns() : style().gridRows();
-    auto&amp; autoRepeatTrackStyles = isRowAxis ? style().gridAutoRepeatColumns() : style().gridAutoRepeatRows();
-    auto&amp; autoTrackStyles = isRowAxis ? style().gridAutoColumns() : style().gridAutoRows();
-    unsigned insertionPoint = isRowAxis ? style().gridAutoRepeatColumnsInsertionPoint() : style().gridAutoRepeatRowsInsertionPoint();
-    unsigned autoRepeatTracksCount = sizingData.grid().autoRepeatTracks(direction);
-
-    // We should not use GridPositionsResolver::explicitGridXXXCount() for this because the
-    // explicit grid might be larger than the number of tracks in grid-template-rows|columns (if
-    // grid-template-areas is specified for example).
-    unsigned explicitTracksCount = trackStyles.size() + autoRepeatTracksCount;
-
-    int untranslatedIndexAsInt = translatedIndex + sizingData.grid().smallestTrackStart(direction);
-    unsigned autoTrackStylesSize = autoTrackStyles.size();
-    if (untranslatedIndexAsInt &lt; 0) {
-        int index = untranslatedIndexAsInt % static_cast&lt;int&gt;(autoTrackStylesSize);
-        // We need to traspose the index because the first negative implicit line will get the last defined auto track and so on.
-        index += index ? autoTrackStylesSize : 0;
-        return autoTrackStyles[index];
-    }
-
-    unsigned untranslatedIndex = static_cast&lt;unsigned&gt;(untranslatedIndexAsInt);
-    if (untranslatedIndex &gt;= explicitTracksCount)
-        return autoTrackStyles[(untranslatedIndex - explicitTracksCount) % autoTrackStylesSize];
-
-    if (!autoRepeatTracksCount || untranslatedIndex &lt; insertionPoint)
-        return trackStyles[untranslatedIndex];
-
-    if (untranslatedIndex &lt; (insertionPoint + autoRepeatTracksCount)) {
-        unsigned autoRepeatLocalIndex = untranslatedIndexAsInt - insertionPoint;
-        return autoRepeatTrackStyles[autoRepeatLocalIndex % autoRepeatTrackStyles.size()];
-    }
-
-    return trackStyles[untranslatedIndex - autoRepeatTracksCount];
-}
-
-GridTrackSize RenderGrid::gridTrackSize(GridTrackSizingDirection direction, unsigned translatedIndex, const GridSizingData&amp; sizingData) const
-{
-    // Collapse empty auto repeat tracks if auto-fit.
-    if (sizingData.grid().hasAutoRepeatEmptyTracks(direction) &amp;&amp; sizingData.grid().isEmptyAutoRepeatTrack(direction, translatedIndex))
-        return { Length(Fixed), LengthTrackSizing };
-
-    auto&amp; trackSize = rawGridTrackSize(direction, translatedIndex, sizingData);
-    if (trackSize.isFitContent())
-        return trackSize;
-
-    GridLength minTrackBreadth = trackSize.minTrackBreadth();
-    GridLength maxTrackBreadth = trackSize.maxTrackBreadth();
-
-    // FIXME: Ensure this condition for determining whether a size is indefinite or not is working correctly for orthogonal flows.
-    if (minTrackBreadth.isPercentage() || maxTrackBreadth.isPercentage()) {
-        // If the logical width/height of the grid container is indefinite, percentage values are treated as &lt;auto&gt;.
-        // For the inline axis this only happens when we're computing the intrinsic sizes (IntrinsicSizeComputation).
-        if (sizingData.sizingOperation == IntrinsicSizeComputation || (direction == ForRows &amp;&amp; !hasDefiniteLogicalHeight())) {
-            if (minTrackBreadth.isPercentage())
-                minTrackBreadth = Length(Auto);
-            if (maxTrackBreadth.isPercentage())
-                maxTrackBreadth = Length(Auto);
-        }
-    }
-
-    // Flex sizes are invalid as a min sizing function. However we still can have a flexible |minTrackBreadth|
-    // if the track size is just a flex size (e.g. &quot;1fr&quot;), the spec says that in this case it implies an automatic minimum.
-    if (minTrackBreadth.isFlex())
-        minTrackBreadth = Length(Auto);
-
-    return GridTrackSize(minTrackBreadth, maxTrackBreadth);
-}
-
</del><span class="cx"> bool RenderGrid::isOrthogonalChild(const RenderBox&amp; child) const
</span><span class="cx"> {
</span><span class="cx">     return child.isHorizontalWritingMode() != isHorizontalWritingMode();
</span><span class="lines">@@ -964,475 +450,6 @@
</span><span class="cx">     return !isOrthogonalChild(child) ? direction : (direction == ForColumns ? ForRows : ForColumns);
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-LayoutUnit RenderGrid::logicalHeightForChild(RenderBox&amp; child) const
-{
-    GridTrackSizingDirection childBlockDirection = flowAwareDirectionForChild(child, ForRows);
-    // 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 -1 (no possible resolution).
-    if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForRows)) {
-        setOverrideContainingBlockContentSizeForChild(child, childBlockDirection, std::nullopt);
-        child.setNeedsLayout(MarkOnlyThis);
-    }
-
-    // We need to clear the stretched height to properly compute logical height during layout.
-    if (child.needsLayout())
-        child.clearOverrideLogicalContentHeight();
-
-    child.layoutIfNeeded();
-    return child.logicalHeight() + child.marginLogicalHeight();
-}
-
-LayoutUnit RenderGrid::minSizeForChild(RenderBox&amp; child, GridTrackSizingDirection direction, GridSizingData&amp; sizingData) const
-{
-    GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(child, ForColumns);
-    bool isRowAxis = direction == childInlineDirection;
-    const Length&amp; childMinSize = isRowAxis ? child.style().logicalMinWidth() : child.style().logicalMinHeight();
-    const Length&amp; childSize = isRowAxis ? child.style().logicalWidth() : child.style().logicalHeight();
-    if (!childSize.isAuto() || childMinSize.isAuto())
-        return minContentForChild(child, direction, sizingData);
-
-    bool overrideSizeHasChanged = updateOverrideContainingBlockContentSizeForChild(child, childInlineDirection, sizingData);
-    if (isRowAxis) {
-        LayoutUnit marginLogicalWidth = sizingData.sizingOperation == TrackSizing ? computeMarginLogicalSizeForChild(childInlineDirection, child) : marginIntrinsicLogicalWidthForChild(child);
-        return child.computeLogicalWidthInRegionUsing(MinSize, childMinSize, overrideContainingBlockContentSizeForChild(child, childInlineDirection).value_or(0), *this, nullptr) + marginLogicalWidth;
-    }
-
-    if (overrideSizeHasChanged &amp;&amp; (direction != ForColumns || sizingData.sizingOperation != IntrinsicSizeComputation))
-        child.setNeedsLayout(MarkOnlyThis);
-    child.layoutIfNeeded();
-    return child.computeLogicalHeightUsing(MinSize, childMinSize, std::nullopt).value_or(0) + child.marginLogicalHeight() + child.scrollbarLogicalHeight();
-}
-
-bool RenderGrid::updateOverrideContainingBlockContentSizeForChild(RenderBox&amp; child, GridTrackSizingDirection direction, GridSizingData&amp; sizingData) const
-{
-    LayoutUnit overrideSize = gridAreaBreadthForChild(child, direction, sizingData);
-    if (hasOverrideContainingBlockContentSizeForChild(child, direction) &amp;&amp; overrideContainingBlockContentSizeForChild(child, direction) == overrideSize)
-        return false;
-
-    setOverrideContainingBlockContentSizeForChild(child, direction, overrideSize);
-    return true;
-}
-
-LayoutUnit RenderGrid::minContentForChild(RenderBox&amp; child, GridTrackSizingDirection direction, GridSizingData&amp; sizingData) const
-{
-    GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(child, ForColumns);
-    if (direction == childInlineDirection) {
-        // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is
-        // what we are interested in here. Thus we need to set the override logical width to std::nullopt (no possible resolution).
-        if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColumns))
-            setOverrideContainingBlockContentSizeForChild(child, childInlineDirection, std::nullopt);
-
-        // FIXME: It's unclear if we should return the intrinsic width or the preferred width.
-        // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
-        return child.minPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(child);
-    }
-
-    // All orthogonal flow boxes were already laid out during an early layout phase performed in FrameView::performLayout.
-    // It's true that grid track sizing was not completed at that time and it may afffect the final height of a
-    // grid item, but since it's forbidden to perform a layout during intrinsic width computation, we have to use
-    // that computed height for now.
-    if (direction == ForColumns &amp;&amp; sizingData.sizingOperation == IntrinsicSizeComputation) {
-        ASSERT(isOrthogonalChild(child));
-        return child.logicalHeight() + child.marginLogicalHeight();
-    }
-
-    if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirection, sizingData))
-        child.setNeedsLayout(MarkOnlyThis);
-    return logicalHeightForChild(child);
-}
-
-LayoutUnit RenderGrid::maxContentForChild(RenderBox&amp; child, GridTrackSizingDirection direction, GridSizingData&amp; sizingData) const
-{
-    GridTrackSizingDirection childInlineDirection = flowAwareDirectionForChild(child, ForColumns);
-    if (direction == childInlineDirection) {
-        // If |child| has a relative logical width, we shouldn't let it override its intrinsic width, which is
-        // what we are interested in here. Thus we need to set the inline-axis override size to -1 (no possible resolution).
-        if (shouldClearOverrideContainingBlockContentSizeForChild(child, ForColumns))
-            setOverrideContainingBlockContentSizeForChild(child, childInlineDirection, std::nullopt);
-
-        // FIXME: It's unclear if we should return the intrinsic width or the preferred width.
-        // See http://lists.w3.org/Archives/Public/www-style/2013Jan/0245.html
-        return child.maxPreferredLogicalWidth() + marginIntrinsicLogicalWidthForChild(child);
-    }
-
-    // All orthogonal flow boxes were already laid out during an early layout phase performed in FrameView::performLayout.
-    // It's true that grid track sizing was not completed at that time and it may afffect the final height of a
-    // grid item, but since it's forbidden to perform a layout during intrinsic width computation, we have to use
-    // that computed height for now.
-    if (direction == ForColumns &amp;&amp; sizingData.sizingOperation == IntrinsicSizeComputation) {
-        ASSERT(isOrthogonalChild(child));
-        return child.logicalHeight() + child.marginLogicalHeight();
-    }
-
-    if (updateOverrideContainingBlockContentSizeForChild(child, childInlineDirection, sizingData))
-        child.setNeedsLayout(MarkOnlyThis);
-    return logicalHeightForChild(child);
-}
-
-class GridItemWithSpan {
-public:
-    GridItemWithSpan(RenderBox&amp; gridItem, GridSpan span)
-        : m_gridItem(gridItem)
-        , m_span(span)
-    {
-    }
-
-    RenderBox&amp; gridItem() const { return m_gridItem; }
-    GridSpan span() const { return m_span; }
-
-    bool operator&lt;(const GridItemWithSpan other) const
-    {
-        return m_span.integerSpan() &lt; other.m_span.integerSpan();
-    }
-
-private:
-    std::reference_wrapper&lt;RenderBox&gt; m_gridItem;
-    GridSpan m_span;
-};
-
-bool RenderGrid::spanningItemCrossesFlexibleSizedTracks(const GridSpan&amp; itemSpan, GridTrackSizingDirection direction, const GridSizingData&amp; sizingData) const
-{
-    for (auto trackPosition : itemSpan) {
-        const GridTrackSize&amp; trackSize = gridTrackSize(direction, trackPosition, sizingData);
-        if (trackSize.minTrackBreadth().isFlex() || trackSize.maxTrackBreadth().isFlex())
-            return true;
-    }
-
-    return false;
-}
-
-struct GridItemsSpanGroupRange {
-    Vector&lt;GridItemWithSpan&gt;::iterator rangeStart;
-    Vector&lt;GridItemWithSpan&gt;::iterator rangeEnd;
-};
-
-void RenderGrid::resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection direction, GridSizingData&amp; sizingData) const
-{
-    sizingData.itemsSortedByIncreasingSpan.shrink(0);
-    HashSet&lt;RenderBox*&gt; itemsSet;
-    Grid&amp; grid = sizingData.grid();
-    if (grid.hasGridItems()) {
-        for (auto trackIndex : sizingData.contentSizedTracksIndex) {
-            GridIterator iterator(grid, direction, trackIndex);
-            GridTrack&amp; track = (direction == ForColumns) ? sizingData.columnTracks[trackIndex] : sizingData.rowTracks[trackIndex];
-
-            while (auto* gridItem = iterator.nextGridItem()) {
-                if (itemsSet.add(gridItem).isNewEntry) {
-                    const GridSpan&amp; span = grid.gridItemSpan(*gridItem, direction);
-                    if (span.integerSpan() == 1)
-                        resolveContentBasedTrackSizingFunctionsForNonSpanningItems(direction, span, *gridItem, track, sizingData);
-                    else if (!spanningItemCrossesFlexibleSizedTracks(span, direction, sizingData))
-                        sizingData.itemsSortedByIncreasingSpan.append(GridItemWithSpan(*gridItem, span));
-                }
-            }
-        }
-        std::sort(sizingData.itemsSortedByIncreasingSpan.begin(), sizingData.itemsSortedByIncreasingSpan.end());
-    }
-
-    auto it = sizingData.itemsSortedByIncreasingSpan.begin();
-    auto end = sizingData.itemsSortedByIncreasingSpan.end();
-    while (it != end) {
-        GridItemsSpanGroupRange spanGroupRange = { it, std::upper_bound(it, end, *it) };
-        resolveContentBasedTrackSizingFunctionsForItems&lt;ResolveIntrinsicMinimums&gt;(direction, sizingData, spanGroupRange);
-        resolveContentBasedTrackSizingFunctionsForItems&lt;ResolveContentBasedMinimums&gt;(direction, sizingData, spanGroupRange);
-        resolveContentBasedTrackSizingFunctionsForItems&lt;ResolveMaxContentMinimums&gt;(direction, sizingData, spanGroupRange);
-        resolveContentBasedTrackSizingFunctionsForItems&lt;ResolveIntrinsicMaximums&gt;(direction, sizingData, spanGroupRange);
-        resolveContentBasedTrackSizingFunctionsForItems&lt;ResolveMaxContentMaximums&gt;(direction, sizingData, spanGroupRange);
-        it = spanGroupRange.rangeEnd;
-    }
-
-    for (auto trackIndex : sizingData.contentSizedTracksIndex) {
-        GridTrack&amp; track = (direction == ForColumns) ? sizingData.columnTracks[trackIndex] : sizingData.rowTracks[trackIndex];
-        if (track.growthLimit() == infinity)
-            track.setGrowthLimit(track.baseSize());
-    }
-}
-
-void RenderGrid::resolveContentBasedTrackSizingFunctionsForNonSpanningItems(GridTrackSizingDirection direction, const GridSpan&amp; span, RenderBox&amp; gridItem, GridTrack&amp; track, GridSizingData&amp; sizingData) const
-{
-    unsigned trackPosition = span.startLine();
-    GridTrackSize trackSize = gridTrackSize(direction, trackPosition, sizingData);
-
-    if (trackSize.hasMinContentMinTrackBreadth())
-        track.setBaseSize(std::max(track.baseSize(), minContentForChild(gridItem, direction, sizingData)));
-    else if (trackSize.hasMaxContentMinTrackBreadth())
-        track.setBaseSize(std::max(track.baseSize(), maxContentForChild(gridItem, direction, sizingData)));
-    else if (trackSize.hasAutoMinTrackBreadth())
-        track.setBaseSize(std::max(track.baseSize(), minSizeForChild(gridItem, direction, sizingData)));
-
-    if (trackSize.hasMinContentMaxTrackBreadth()) {
-        track.setGrowthLimit(std::max(track.growthLimit(), minContentForChild(gridItem, direction, sizingData)));
-    } else if (trackSize.hasMaxContentOrAutoMaxTrackBreadth()) {
-        LayoutUnit growthLimit = maxContentForChild(gridItem, direction, sizingData);
-        if (trackSize.isFitContent())
-            growthLimit = std::min(growthLimit, valueForLength(trackSize.fitContentTrackBreadth().length(), sizingData.availableSpace().value_or(0)));
-        track.setGrowthLimit(std::max(track.growthLimit(), growthLimit));
-    }
-}
-
-static LayoutUnit trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track, TrackSizeRestriction restriction)
-{
-    switch (phase) {
-    case ResolveIntrinsicMinimums:
-    case ResolveContentBasedMinimums:
-    case ResolveMaxContentMinimums:
-    case MaximizeTracks:
-        return track.baseSize();
-    case ResolveIntrinsicMaximums:
-    case ResolveMaxContentMaximums:
-        return restriction == AllowInfinity ? track.growthLimit() : track.growthLimitIfNotInfinite();
-    }
-
-    ASSERT_NOT_REACHED();
-    return track.baseSize();
-}
-
-bool RenderGrid::shouldProcessTrackForTrackSizeComputationPhase(TrackSizeComputationPhase phase, const GridTrackSize&amp; trackSize)
-{
-    switch (phase) {
-    case ResolveIntrinsicMinimums:
-        return trackSize.hasIntrinsicMinTrackBreadth();
-    case ResolveContentBasedMinimums:
-        return trackSize.hasMinOrMaxContentMinTrackBreadth();
-    case ResolveMaxContentMinimums:
-        return trackSize.hasMaxContentMinTrackBreadth();
-    case ResolveIntrinsicMaximums:
-        return trackSize.hasIntrinsicMaxTrackBreadth();
-    case ResolveMaxContentMaximums:
-        return trackSize.hasMaxContentOrAutoMaxTrackBreadth();
-    case MaximizeTracks:
-        ASSERT_NOT_REACHED();
-        return false;
-    }
-
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-bool RenderGrid::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(TrackSizeComputationPhase phase, const GridTrackSize&amp; trackSize)
-{
-    switch (phase) {
-    case ResolveIntrinsicMinimums:
-    case ResolveContentBasedMinimums:
-        return trackSize.hasAutoOrMinContentMinTrackBreadthAndIntrinsicMaxTrackBreadth();
-    case ResolveMaxContentMinimums:
-        return trackSize.hasMaxContentMinTrackBreadthAndMaxContentMaxTrackBreadth();
-    case ResolveIntrinsicMaximums:
-    case ResolveMaxContentMaximums:
-        return true;
-    case MaximizeTracks:
-        ASSERT_NOT_REACHED();
-        return false;
-    }
-
-    ASSERT_NOT_REACHED();
-    return false;
-}
-
-void RenderGrid::markAsInfinitelyGrowableForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track)
-{
-    switch (phase) {
-    case ResolveIntrinsicMinimums:
-    case ResolveContentBasedMinimums:
-    case ResolveMaxContentMinimums:
-        return;
-    case ResolveIntrinsicMaximums:
-        if (trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity) == infinity  &amp;&amp; track.plannedSize() != infinity)
-            track.setInfinitelyGrowable(true);
-        return;
-    case ResolveMaxContentMaximums:
-        if (track.infinitelyGrowable())
-            track.setInfinitelyGrowable(false);
-        return;
-    case MaximizeTracks:
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    ASSERT_NOT_REACHED();
-}
-
-void RenderGrid::updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track)
-{
-    switch (phase) {
-    case ResolveIntrinsicMinimums:
-    case ResolveContentBasedMinimums:
-    case ResolveMaxContentMinimums:
-        track.setBaseSize(track.plannedSize());
-        return;
-    case ResolveIntrinsicMaximums:
-    case ResolveMaxContentMaximums:
-        track.setGrowthLimit(track.plannedSize());
-        return;
-    case MaximizeTracks:
-        ASSERT_NOT_REACHED();
-        return;
-    }
-
-    ASSERT_NOT_REACHED();
-}
-
-LayoutUnit RenderGrid::currentItemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, RenderBox&amp; gridItem, GridTrackSizingDirection direction, GridSizingData&amp; sizingData) const
-{
-    switch (phase) {
-    case ResolveIntrinsicMinimums:
-    case ResolveIntrinsicMaximums:
-        return minSizeForChild(gridItem, direction, sizingData);
-    case ResolveContentBasedMinimums:
-        return minContentForChild(gridItem, direction, sizingData);
-    case ResolveMaxContentMinimums:
-    case ResolveMaxContentMaximums:
-        return maxContentForChild(gridItem, direction, sizingData);
-    case MaximizeTracks:
-        ASSERT_NOT_REACHED();
-        return 0;
-    }
-
-    ASSERT_NOT_REACHED();
-    return 0;
-}
-
-template &lt;TrackSizeComputationPhase phase&gt;
-void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirection direction, GridSizingData&amp; sizingData, const GridItemsSpanGroupRange&amp; gridItemsWithSpan) const
-{
-    Vector&lt;GridTrack&gt;&amp; tracks = (direction == ForColumns) ? sizingData.columnTracks : sizingData.rowTracks;
-    for (const auto&amp; trackIndex : sizingData.contentSizedTracksIndex) {
-        GridTrack&amp; track = tracks[trackIndex];
-        track.setPlannedSize(trackSizeForTrackSizeComputationPhase(phase, track, AllowInfinity));
-    }
-
-    for (auto it = gridItemsWithSpan.rangeStart; it != gridItemsWithSpan.rangeEnd; ++it) {
-        GridItemWithSpan&amp; gridItemWithSpan = *it;
-        ASSERT(gridItemWithSpan.span().integerSpan() &gt; 1);
-        const GridSpan&amp; itemSpan = gridItemWithSpan.span();
-
-        sizingData.filteredTracks.shrink(0);
-        sizingData.growBeyondGrowthLimitsTracks.shrink(0);
-        LayoutUnit spanningTracksSize;
-        for (auto trackPosition : itemSpan) {
-            const GridTrackSize&amp; trackSize = gridTrackSize(direction, trackPosition, sizingData);
-            GridTrack&amp; track = (direction == ForColumns) ? sizingData.columnTracks[trackPosition] : sizingData.rowTracks[trackPosition];
-            spanningTracksSize += trackSizeForTrackSizeComputationPhase(phase, track, ForbidInfinity);
-            if (!shouldProcessTrackForTrackSizeComputationPhase(phase, trackSize))
-                continue;
-
-            sizingData.filteredTracks.append(&amp;track);
-
-            if (trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(phase, trackSize))
-                sizingData.growBeyondGrowthLimitsTracks.append(&amp;track);
-        }
-
-        if (sizingData.filteredTracks.isEmpty())
-            continue;
-
-        spanningTracksSize += guttersSize(sizingData.grid(), direction, itemSpan.startLine(), itemSpan.integerSpan());
-
-        LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phase, gridItemWithSpan.gridItem(), direction, sizingData) - spanningTracksSize;
-        extraSpace = std::max&lt;LayoutUnit&gt;(extraSpace, 0);
-        auto&amp; tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimitsTracks.isEmpty() ? sizingData.filteredTracks : sizingData.growBeyondGrowthLimitsTracks;
-        distributeSpaceToTracks&lt;phase&gt;(sizingData.filteredTracks, &amp;tracksToGrowBeyondGrowthLimits, extraSpace);
-    }
-
-    for (const auto&amp; trackIndex : sizingData.contentSizedTracksIndex) {
-        GridTrack&amp; track = tracks[trackIndex];
-        markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track);
-        updateTrackSizeForTrackSizeComputationPhase(phase, track);
-    }
-}
-
-static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTrack* track2)
-{
-    // This check ensures that we respect the irreflexivity property of the strict weak ordering required by std::sort
-    // (forall x: NOT x &lt; x).
-    bool track1HasInfiniteGrowthPotentialWithoutCap = track1-&gt;infiniteGrowthPotential() &amp;&amp; !track1-&gt;growthLimitCap();
-    bool track2HasInfiniteGrowthPotentialWithoutCap = track2-&gt;infiniteGrowthPotential() &amp;&amp; !track2-&gt;growthLimitCap();
-
-    if (track1HasInfiniteGrowthPotentialWithoutCap &amp;&amp; track2HasInfiniteGrowthPotentialWithoutCap)
-        return false;
-
-    if (track1HasInfiniteGrowthPotentialWithoutCap || track2HasInfiniteGrowthPotentialWithoutCap)
-        return track2HasInfiniteGrowthPotentialWithoutCap;
-
-    LayoutUnit track1Limit = track1-&gt;growthLimitCap().value_or(track1-&gt;growthLimit());
-    LayoutUnit track2Limit = track2-&gt;growthLimitCap().value_or(track2-&gt;growthLimit());
-    return (track1Limit - track1-&gt;baseSize()) &lt; (track2Limit - track2-&gt;baseSize());
-}
-
-static void clampGrowthShareIfNeeded(TrackSizeComputationPhase phase, const GridTrack&amp; track, LayoutUnit&amp; growthShare)
-{
-    if (phase != ResolveMaxContentMaximums || !track.growthLimitCap())
-        return;
-
-    LayoutUnit distanceToCap = track.growthLimitCap().value() - track.tempSize();
-    if (distanceToCap &lt;= 0)
-        return;
-
-    growthShare = std::min(growthShare, distanceToCap);
-}
-
-template &lt;TrackSizeComputationPhase phase&gt;
-void RenderGrid::distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp; tracks, Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; freeSpace) const
-{
-    ASSERT(freeSpace &gt;= 0);
-
-    for (auto* track : tracks)
-        track-&gt;setTempSize(trackSizeForTrackSizeComputationPhase(phase, *track, ForbidInfinity));
-
-    if (freeSpace &gt; 0) {
-        std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential);
-
-        unsigned tracksSize = tracks.size();
-        for (unsigned i = 0; i &lt; tracksSize; ++i) {
-            GridTrack&amp; track = *tracks[i];
-            const LayoutUnit&amp; trackBreadth = trackSizeForTrackSizeComputationPhase(phase, track, ForbidInfinity);
-            bool infiniteGrowthPotential = track.infiniteGrowthPotential();
-            LayoutUnit trackGrowthPotential = infiniteGrowthPotential ? track.growthLimit() : track.growthLimit() - trackBreadth;
-            // Let's avoid computing availableLogicalSpaceShare as much as possible as it's a hot spot in performance tests.
-            if (trackGrowthPotential &gt; 0 || infiniteGrowthPotential) {
-                LayoutUnit availableLogicalSpaceShare = freeSpace / (tracksSize - i);
-                LayoutUnit growthShare = infiniteGrowthPotential ? availableLogicalSpaceShare : std::min(availableLogicalSpaceShare, trackGrowthPotential);
-                clampGrowthShareIfNeeded(phase, track, growthShare);
-                ASSERT_WITH_MESSAGE(growthShare &gt;= 0, &quot;We should never shrink any grid track or else we can't guarantee we abide by our min-sizing function. We can still have 0 as growthShare if the amount of tracks greatly exceeds the freeSpace.&quot;);
-                track.growTempSize(growthShare);
-                freeSpace -= growthShare;
-            }
-        }
-    }
-
-    if (freeSpace &gt; 0 &amp;&amp; growBeyondGrowthLimitsTracks) {
-        // We need to sort them because there might be tracks with growth limit caps (like the ones
-        // with fit-content()) which cannot indefinitely grow over the limits.
-        if (phase == ResolveMaxContentMaximums)
-            std::sort(growBeyondGrowthLimitsTracks-&gt;begin(), growBeyondGrowthLimitsTracks-&gt;end(), sortByGridTrackGrowthPotential);
-
-        unsigned tracksGrowingBeyondGrowthLimitsSize = growBeyondGrowthLimitsTracks-&gt;size();
-        for (unsigned i = 0; i &lt; tracksGrowingBeyondGrowthLimitsSize; ++i) {
-            GridTrack* track = growBeyondGrowthLimitsTracks-&gt;at(i);
-            LayoutUnit growthShare = freeSpace / (tracksGrowingBeyondGrowthLimitsSize - i);
-            clampGrowthShareIfNeeded(phase, *track, growthShare);
-            track-&gt;growTempSize(growthShare);
-            freeSpace -= growthShare;
-        }
-    }
-
-    for (auto* track : tracks)
-        track-&gt;setPlannedSize(track-&gt;plannedSize() == infinity ? track-&gt;tempSize() : std::max(track-&gt;plannedSize(), track-&gt;tempSize()));
-}
-
-#ifndef NDEBUG
-bool RenderGrid::tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection direction, GridSizingData&amp; sizingData)
-{
-    const Vector&lt;GridTrack&gt;&amp; tracks = (direction == ForColumns) ? sizingData.columnTracks : sizingData.rowTracks;
-    const LayoutUnit maxSize = sizingData.availableSpace().value_or(0);
-    for (unsigned i = 0; i &lt; tracks.size(); ++i) {
-        const GridTrackSize&amp; trackSize = gridTrackSize(direction, i, sizingData);
-        if (computeUsedBreadthOfMinLength(trackSize, maxSize) &gt; tracks[i].baseSize())
-            return false;
-    }
-    return true;
-}
-#endif
-
</del><span class="cx"> unsigned RenderGrid::computeAutoRepeatTracksCount(GridTrackSizingDirection direction, SizingOperation sizingOperation) const
</span><span class="cx"> {
</span><span class="cx">     bool isRowAxis = direction == ForColumns;
</span><span class="lines">@@ -1670,7 +687,7 @@
</span><span class="cx"> 
</span><span class="cx">     // Mapping between the major axis tracks (rows or columns) and the last auto-placed item's position inserted on
</span><span class="cx">     // that track. This is needed to implement &quot;sparse&quot; packing for items locked to a given track.
</span><del>-    // See http://dev.w3.org/csswg/css-grid/#auto-placement-algo
</del><ins>+    // See http://dev.w3.org/csswg/css-grid/#auto-placement-algorithm
</ins><span class="cx">     HashMap&lt;unsigned, unsigned, DefaultHash&lt;unsigned&gt;::Hash, WTF::UnsignedWithZeroKeyHashTraits&lt;unsigned&gt;&gt; minorAxisCursors;
</span><span class="cx"> 
</span><span class="cx">     for (auto&amp; autoGridItem : autoGridItems) {
</span><span class="lines">@@ -1826,9 +843,9 @@
</span><span class="cx">     return normalBehavior;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction, GridSizingData&amp; sizingData)
</del><ins>+void RenderGrid::applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection direction)
</ins><span class="cx"> {
</span><del>-    std::optional&lt;LayoutUnit&gt; freeSpace = sizingData.freeSpace(direction);
</del><ins>+    std::optional&lt;LayoutUnit&gt; freeSpace = m_trackSizingAlgorithm.freeSpace(direction);
</ins><span class="cx">     if (!freeSpace
</span><span class="cx">         || freeSpace.value() &lt;= 0
</span><span class="cx">         || (direction == ForColumns &amp;&amp; style().resolvedJustifyContentDistribution(contentAlignmentNormalBehaviorGrid()) != ContentDistributionStretch)
</span><span class="lines">@@ -1836,10 +853,10 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     // Spec defines auto-sized tracks as the ones with an 'auto' max-sizing function.
</span><del>-    Vector&lt;GridTrack&gt;&amp; tracks = (direction == ForColumns) ? sizingData.columnTracks : sizingData.rowTracks;
</del><ins>+    Vector&lt;GridTrack&gt;&amp; allTracks = m_trackSizingAlgorithm.tracks(direction);
</ins><span class="cx">     Vector&lt;unsigned&gt; autoSizedTracksIndex;
</span><del>-    for (unsigned i = 0; i &lt; tracks.size(); ++i) {
-        const GridTrackSize&amp; trackSize = gridTrackSize(direction, i, sizingData);
</del><ins>+    for (unsigned i = 0; i &lt; allTracks.size(); ++i) {
+        const GridTrackSize&amp; trackSize = m_trackSizingAlgorithm.gridTrackSize(direction, i, TrackSizing);
</ins><span class="cx">         if (trackSize.hasAutoMaxTrackBreadth())
</span><span class="cx">             autoSizedTracksIndex.append(i);
</span><span class="cx">     }
</span><span class="lines">@@ -1850,17 +867,16 @@
</span><span class="cx"> 
</span><span class="cx">     LayoutUnit sizeToIncrease = freeSpace.value() / numberOfAutoSizedTracks;
</span><span class="cx">     for (const auto&amp; trackIndex : autoSizedTracksIndex) {
</span><del>-        auto&amp; track = tracks[trackIndex];
</del><ins>+        auto&amp; track = allTracks[trackIndex];
</ins><span class="cx">         track.setBaseSize(track.baseSize() + sizeToIncrease);
</span><span class="cx">     }
</span><del>-    sizingData.setFreeSpace(direction, std::optional&lt;LayoutUnit&gt;(0));
</del><ins>+    m_trackSizingAlgorithm.setFreeSpace(direction, LayoutUnit());
</ins><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderGrid::layoutGridItems(GridSizingData&amp; sizingData)
</del><ins>+void RenderGrid::layoutGridItems()
</ins><span class="cx"> {
</span><del>-    ASSERT(sizingData.sizingOperation == TrackSizing);
-    populateGridPositionsForDirection(sizingData, ForColumns);
-    populateGridPositionsForDirection(sizingData, ForRows);
</del><ins>+    populateGridPositionsForDirection(ForColumns);
+    populateGridPositionsForDirection(ForRows);
</ins><span class="cx"> 
</span><span class="cx">     for (RenderBox* child = firstChildBox(); child; child = child-&gt;nextSiblingBox()) {
</span><span class="cx">         if (child-&gt;isOutOfFlowPositioned()) {
</span><span class="lines">@@ -1873,8 +889,8 @@
</span><span class="cx">         std::optional&lt;LayoutUnit&gt; oldOverrideContainingBlockContentLogicalWidth = child-&gt;hasOverrideContainingBlockLogicalWidth() ? child-&gt;overrideContainingBlockContentLogicalWidth() : LayoutUnit();
</span><span class="cx">         std::optional&lt;LayoutUnit&gt; oldOverrideContainingBlockContentLogicalHeight = child-&gt;hasOverrideContainingBlockLogicalHeight() ? child-&gt;overrideContainingBlockContentLogicalHeight() : LayoutUnit();
</span><span class="cx"> 
</span><del>-        LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForColumns, sizingData);
-        LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows, sizingData);
</del><ins>+        LayoutUnit overrideContainingBlockContentLogicalWidth = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForColumns);
+        LayoutUnit overrideContainingBlockContentLogicalHeight = gridAreaBreadthForChildIncludingAlignmentOffsets(*child, ForRows);
</ins><span class="cx">         if (!oldOverrideContainingBlockContentLogicalWidth || oldOverrideContainingBlockContentLogicalWidth.value() != overrideContainingBlockContentLogicalWidth
</span><span class="cx">             || ((!oldOverrideContainingBlockContentLogicalHeight || oldOverrideContainingBlockContentLogicalHeight.value() != overrideContainingBlockContentLogicalHeight)
</span><span class="cx">                 &amp;&amp; child-&gt;hasRelativeLogicalHeight()))
</span><span class="lines">@@ -1896,7 +912,7 @@
</span><span class="cx">         updateAutoMarginsInColumnAxisIfNeeded(*child);
</span><span class="cx">         updateAutoMarginsInRowAxisIfNeeded(*child);
</span><span class="cx"> 
</span><del>-        child-&gt;setLogicalLocation(findChildLogicalPosition(*child, sizingData));
</del><ins>+        child-&gt;setLogicalLocation(findChildLogicalPosition(*child));
</ins><span class="cx"> 
</span><span class="cx">         // If the child moved, we have to repaint it as well as any floating/positioned
</span><span class="cx">         // descendants. An exception is if we need a layout. In this case, we know we're going to
</span><span class="lines">@@ -2023,51 +1039,12 @@
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-LayoutUnit RenderGrid::assumedRowsSizeForOrthogonalChild(const RenderBox&amp; child, const GridSizingData&amp; sizingData) const
</del><ins>+LayoutUnit RenderGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&amp; child, GridTrackSizingDirection direction) const
</ins><span class="cx"> {
</span><del>-    ASSERT(isOrthogonalChild(child));
-    const GridSpan&amp; span = sizingData.grid().gridItemSpan(child, ForRows);
-    LayoutUnit gridAreaSize;
-    bool gridAreaIsIndefinite = false;
-    LayoutUnit containingBlockAvailableSize = containingBlockLogicalHeightForContent(ExcludeMarginBorderPadding);
-    for (auto trackPosition : span) {
-        GridLength maxTrackSize = gridTrackSize(ForRows, trackPosition, sizingData).maxTrackBreadth();
-        if (maxTrackSize.isContentSized() || maxTrackSize.isFlex())
-            gridAreaIsIndefinite = true;
-        else
-            gridAreaSize += valueForLength(maxTrackSize.length(), containingBlockAvailableSize);
-    }
-
-    gridAreaSize += guttersSize(sizingData.grid(), ForRows, span.startLine(), span.integerSpan());
-
-    return gridAreaIsIndefinite ? std::max(child.maxPreferredLogicalWidth(), gridAreaSize) : gridAreaSize;
-}
-
-LayoutUnit RenderGrid::gridAreaBreadthForChild(const RenderBox&amp; child, GridTrackSizingDirection direction, const GridSizingData&amp; sizingData) const
-{
-    // To determine the column track's size based on an orthogonal grid item we need it's logical height, which
-    // may depend on the row track's size. It's possible that the row tracks sizing logic has not been performed yet,
-    // so we will need to do an estimation.
-    if (direction == ForRows &amp;&amp; sizingData.sizingState == GridSizingData::ColumnSizingFirstIteration)
-        return assumedRowsSizeForOrthogonalChild(child, sizingData);
-
-    const Vector&lt;GridTrack&gt;&amp; tracks = direction == ForColumns ? sizingData.columnTracks : sizingData.rowTracks;
-    const GridSpan&amp; span = sizingData.grid().gridItemSpan(child, direction);
-    LayoutUnit gridAreaBreadth = 0;
-    for (auto trackPosition : span)
-        gridAreaBreadth += tracks[trackPosition].baseSize();
-
-    gridAreaBreadth += guttersSize(sizingData.grid(), direction, span.startLine(), span.integerSpan());
-
-    return gridAreaBreadth;
-}
-
-LayoutUnit RenderGrid::gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&amp; child, GridTrackSizingDirection direction, const GridSizingData&amp; sizingData) const
-{
</del><span class="cx">     // We need the cached value when available because Content Distribution alignment properties
</span><span class="cx">     // may have some influence in the final grid area breadth.
</span><del>-    const auto&amp; tracks = (direction == ForColumns) ? sizingData.columnTracks : sizingData.rowTracks;
-    const auto&amp; span = sizingData.grid().gridItemSpan(child, direction);
</del><ins>+    const auto&amp; tracks = m_trackSizingAlgorithm.tracks(direction);
+    const auto&amp; span = m_grid.gridItemSpan(child, direction);
</ins><span class="cx">     const auto&amp; linePositions = (direction == ForColumns) ? m_columnPositions : m_rowPositions;
</span><span class="cx"> 
</span><span class="cx">     LayoutUnit initialTrackPosition = linePositions[span.startLine()];
</span><span class="lines">@@ -2077,7 +1054,7 @@
</span><span class="cx">     return finalTrackPosition - initialTrackPosition + tracks[span.endLine() - 1].baseSize();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void RenderGrid::populateGridPositionsForDirection(GridSizingData&amp; sizingData, GridTrackSizingDirection direction)
</del><ins>+void RenderGrid::populateGridPositionsForDirection(GridTrackSizingDirection direction)
</ins><span class="cx"> {
</span><span class="cx">     // Since we add alignment offsets and track gutters, grid lines are not always adjacent. Hence we will have to
</span><span class="cx">     // assume from now on that we just store positions of the initial grid lines of each track,
</span><span class="lines">@@ -2087,21 +1064,20 @@
</span><span class="cx">     // inline-axis flow direction. However, column lines positions are 'direction' unaware. This simplification
</span><span class="cx">     // allows us to use the same indexes to identify the columns independently on the inline-axis direction.
</span><span class="cx">     bool isRowAxis = direction == ForColumns;
</span><del>-    auto&amp; tracks = isRowAxis ? sizingData.columnTracks : sizingData.rowTracks;
</del><ins>+    auto&amp; tracks = m_trackSizingAlgorithm.tracks(direction);
</ins><span class="cx">     unsigned numberOfTracks = tracks.size();
</span><span class="cx">     unsigned numberOfLines = numberOfTracks + 1;
</span><span class="cx">     unsigned lastLine = numberOfLines - 1;
</span><span class="cx"> 
</span><del>-    ContentAlignmentData offset = computeContentPositionAndDistributionOffset(direction, sizingData.freeSpace(direction).value(), numberOfTracks);
</del><ins>+    ContentAlignmentData offset = computeContentPositionAndDistributionOffset(direction, m_trackSizingAlgorithm.freeSpace(direction).value(), numberOfTracks);
</ins><span class="cx">     auto&amp; positions = isRowAxis ? m_columnPositions : m_rowPositions;
</span><span class="cx">     positions.resize(numberOfLines);
</span><span class="cx">     auto borderAndPadding = isRowAxis ? borderAndPaddingLogicalLeft() : borderAndPaddingBefore();
</span><span class="cx">     positions[0] = borderAndPadding + offset.positionOffset;
</span><del>-    Grid&amp; grid = sizingData.grid();
</del><span class="cx">     if (numberOfLines &gt; 1) {
</span><span class="cx">         // If we have collapsed tracks we just ignore gaps here and add them later as we might not
</span><span class="cx">         // compute the gap between two consecutive tracks without examining the surrounding ones.
</span><del>-        bool hasCollapsedTracks = grid.hasAutoRepeatEmptyTracks(direction);
</del><ins>+        bool hasCollapsedTracks = m_grid.hasAutoRepeatEmptyTracks(direction);
</ins><span class="cx">         LayoutUnit gap = !hasCollapsedTracks ? gridGapForDirection(direction) : LayoutUnit();
</span><span class="cx">         unsigned nextToLastLine = numberOfLines - 2;
</span><span class="cx">         for (unsigned i = 0; i &lt; nextToLastLine; ++i)
</span><span class="lines">@@ -2112,16 +1088,16 @@
</span><span class="cx">         // coincide exactly) except on the edges of the grid where they become 0.
</span><span class="cx">         if (hasCollapsedTracks) {
</span><span class="cx">             gap = gridGapForDirection(direction);
</span><del>-            unsigned remainingEmptyTracks = grid.autoRepeatEmptyTracks(direction)-&gt;size();
</del><ins>+            unsigned remainingEmptyTracks = m_grid.autoRepeatEmptyTracks(direction)-&gt;size();
</ins><span class="cx">             LayoutUnit gapAccumulator;
</span><span class="cx">             for (unsigned i = 1; i &lt; lastLine; ++i) {
</span><del>-                if (grid.isEmptyAutoRepeatTrack(direction, i - 1))
</del><ins>+                if (m_grid.isEmptyAutoRepeatTrack(direction, i - 1))
</ins><span class="cx">                     --remainingEmptyTracks;
</span><span class="cx">                 else {
</span><span class="cx">                     // Add gap between consecutive non empty tracks. Add it also just once for an
</span><span class="cx">                     // arbitrary number of empty tracks between two non empty ones.
</span><span class="cx">                     bool allRemainingTracksAreEmpty = remainingEmptyTracks == (lastLine - i);
</span><del>-                    if (!allRemainingTracksAreEmpty || !grid.isEmptyAutoRepeatTrack(direction, i))
</del><ins>+                    if (!allRemainingTracksAreEmpty || !m_grid.isEmptyAutoRepeatTrack(direction, i))
</ins><span class="cx">                         gapAccumulator += gap;
</span><span class="cx">                 }
</span><span class="cx">                 positions[i] += gapAccumulator;
</span><span class="lines">@@ -2484,9 +1460,9 @@
</span><span class="cx">     return GridAxisStart;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-LayoutUnit RenderGrid::columnAxisOffsetForChild(const RenderBox&amp; child, const GridSizingData&amp; sizingData) const
</del><ins>+LayoutUnit RenderGrid::columnAxisOffsetForChild(const RenderBox&amp; child) const
</ins><span class="cx"> {
</span><del>-    const GridSpan&amp; rowsSpan = sizingData.grid().gridItemSpan(child, ForRows);
</del><ins>+    const GridSpan&amp; rowsSpan = m_grid.gridItemSpan(child, ForRows);
</ins><span class="cx">     unsigned childStartLine = rowsSpan.startLine();
</span><span class="cx">     LayoutUnit startOfRow = m_rowPositions[childStartLine];
</span><span class="cx">     LayoutUnit startPosition = startOfRow + marginBeforeForChild(child);
</span><span class="lines">@@ -2517,9 +1493,9 @@
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-LayoutUnit RenderGrid::rowAxisOffsetForChild(const RenderBox&amp; child, const GridSizingData&amp; sizingData) const
</del><ins>+LayoutUnit RenderGrid::rowAxisOffsetForChild(const RenderBox&amp; child) const
</ins><span class="cx"> {
</span><del>-    const GridSpan&amp; columnsSpan = sizingData.grid().gridItemSpan(child, ForColumns);
</del><ins>+    const GridSpan&amp; columnsSpan = m_grid.gridItemSpan(child, ForColumns);
</ins><span class="cx">     unsigned childStartLine = columnsSpan.startLine();
</span><span class="cx">     LayoutUnit startOfColumn = m_columnPositions[childStartLine];
</span><span class="cx">     LayoutUnit startPosition = startOfColumn + marginStartForChild(child);
</span><span class="lines">@@ -2659,10 +1635,11 @@
</span><span class="cx">     return rightGridEdgePosition + alignmentOffset - coordinate;
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox&amp; child, const GridSizingData&amp; sizingData) const
</del><ins>+LayoutPoint RenderGrid::findChildLogicalPosition(const RenderBox&amp; child) const
</ins><span class="cx"> {
</span><del>-    LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child, sizingData);
-    LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child, sizingData);
</del><ins>+    LayoutUnit columnAxisOffset = columnAxisOffsetForChild(child);
+    LayoutUnit rowAxisOffset = rowAxisOffsetForChild(child);
+
</ins><span class="cx">     // We stored m_columnPositions's data ignoring the direction, hence we might need now
</span><span class="cx">     // to translate positions from RTL to LTR, as it's more convenient for painting.
</span><span class="cx">     if (!style().isLeftToRightDirection())
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderGridh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderGrid.h (212822 => 212823)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderGrid.h        2017-02-22 11:34:46 UTC (rev 212822)
+++ trunk/Source/WebCore/rendering/RenderGrid.h        2017-02-22 11:44:15 UTC (rev 212823)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx"> #pragma once
</span><span class="cx"> 
</span><span class="cx"> #include &quot;Grid.h&quot;
</span><ins>+#include &quot;GridTrackSizingAlgorithm.h&quot;
</ins><span class="cx"> #include &quot;RenderBlock.h&quot;
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -33,22 +34,11 @@
</span><span class="cx"> 
</span><span class="cx"> class GridArea;
</span><span class="cx"> class GridSpan;
</span><del>-class GridTrack;
-class GridItemWithSpan;
</del><span class="cx"> 
</span><span class="cx"> struct ContentAlignmentData;
</span><span class="cx"> 
</span><span class="cx"> enum GridAxisPosition {GridAxisStart, GridAxisEnd, GridAxisCenter};
</span><span class="cx"> 
</span><del>-enum TrackSizeComputationPhase {
-    ResolveIntrinsicMinimums,
-    ResolveContentBasedMinimums,
-    ResolveMaxContentMinimums,
-    ResolveIntrinsicMaximums,
-    ResolveMaxContentMaximums,
-    MaximizeTracks,
-};
-
</del><span class="cx"> class RenderGrid final : public RenderBlock {
</span><span class="cx"> public:
</span><span class="cx">     RenderGrid(Element&amp;, RenderStyle&amp;&amp;);
</span><span class="lines">@@ -70,6 +60,9 @@
</span><span class="cx"> 
</span><span class="cx">     unsigned autoRepeatCountForDirection(GridTrackSizingDirection direction) const { return m_grid.autoRepeatTracks(direction); }
</span><span class="cx"> 
</span><ins>+    // Required by GridTrackSizingAlgorithm. Keep them under control.
+    bool isOrthogonalChild(const RenderBox&amp;) const;
+    LayoutUnit guttersSize(const Grid&amp;, GridTrackSizingDirection, unsigned startLine, unsigned span) const;
</ins><span class="cx"> private:
</span><span class="cx">     const char* renderName() const override;
</span><span class="cx">     bool isRenderGrid() const override { return true; }
</span><span class="lines">@@ -83,14 +76,6 @@
</span><span class="cx"> 
</span><span class="cx">     std::optional&lt;LayoutUnit&gt; computeIntrinsicLogicalContentHeightUsing(Length logicalHeightLength, std::optional&lt;LayoutUnit&gt; intrinsicContentHeight, LayoutUnit borderAndPadding) const override;
</span><span class="cx"> 
</span><del>-    class GridSizingData;
-    enum SizingOperation { TrackSizing, IntrinsicSizeComputation };
-    void computeUsedBreadthOfGridTracks(GridTrackSizingDirection, GridSizingData&amp;, LayoutUnit&amp; baseSizesWithoutMaximization, LayoutUnit&amp; growthLimitsWithoutMaximization) const;
-    void computeFlexSizedTracksGrowth(GridTrackSizingDirection, const GridSizingData&amp;, Vector&lt;GridTrack&gt;&amp;, const Vector&lt;unsigned&gt;&amp; flexibleSizedTracksIndex, double flexFraction, Vector&lt;LayoutUnit&gt;&amp; increments, LayoutUnit&amp; totalGrowth) const;
-    LayoutUnit computeUsedBreadthOfMinLength(const GridTrackSize&amp;, LayoutUnit maxSize) const;
-    LayoutUnit computeUsedBreadthOfMaxLength(const GridTrackSize&amp;, LayoutUnit usedBreadth, LayoutUnit maxSize) const;
-    void resolveContentBasedTrackSizingFunctions(GridTrackSizingDirection, GridSizingData&amp;) const;
-
</del><span class="cx">     unsigned computeAutoRepeatTracksCount(GridTrackSizingDirection, SizingOperation) const;
</span><span class="cx"> 
</span><span class="cx">     std::unique_ptr&lt;OrderedTrackIndexSet&gt; computeEmptyTracksForAutoRepeat(Grid&amp;, GridTrackSizingDirection) const;
</span><span class="lines">@@ -110,54 +95,28 @@
</span><span class="cx">     void layoutPositionedObject(RenderBox&amp;, bool relayoutChildren, bool fixedPositionObjectsOnly) override;
</span><span class="cx">     void offsetAndBreadthForPositionedChild(const RenderBox&amp;, GridTrackSizingDirection, LayoutUnit&amp; offset, LayoutUnit&amp; breadth);
</span><span class="cx"> 
</span><del>-    void computeIntrinsicLogicalHeight(GridSizingData&amp;);
-    LayoutUnit computeTrackBasedLogicalHeight(const GridSizingData&amp;) const;
-    void computeTrackSizesForDirection(GridTrackSizingDirection, GridSizingData&amp;, LayoutUnit freeSpace);
</del><ins>+    void computeTrackSizesForDefiniteSize(GridTrackSizingDirection, LayoutUnit availableSpace);
+    void computeTrackSizesForIndefiniteSize(GridTrackSizingAlgorithm&amp;, GridTrackSizingDirection, Grid&amp;, LayoutUnit&amp; minIntrinsicSize, LayoutUnit&amp; maxIntrinsicSize) const;
+    LayoutUnit computeTrackBasedLogicalHeight() const;
</ins><span class="cx"> 
</span><del>-    void repeatTracksSizingIfNeeded(GridSizingData&amp;, LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows);
</del><ins>+    void repeatTracksSizingIfNeeded(LayoutUnit availableSpaceForColumns, LayoutUnit availableSpaceForRows);
</ins><span class="cx"> 
</span><del>-    void layoutGridItems(GridSizingData&amp;);
-    void populateGridPositionsForDirection(GridSizingData&amp;, GridTrackSizingDirection);
</del><ins>+    void layoutGridItems();
+    void populateGridPositionsForDirection(GridTrackSizingDirection);
</ins><span class="cx"> 
</span><del>-    static bool shouldProcessTrackForTrackSizeComputationPhase(TrackSizeComputationPhase, const GridTrackSize&amp;);
-    static bool trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(TrackSizeComputationPhase, const GridTrackSize&amp;);
-    static void markAsInfinitelyGrowableForTrackSizeComputationPhase(TrackSizeComputationPhase, GridTrack&amp;);
-    static void updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, GridTrack&amp;);
-    LayoutUnit currentItemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, RenderBox&amp;, GridTrackSizingDirection, GridSizingData&amp;) const;
-
-    typedef struct GridItemsSpanGroupRange GridItemsSpanGroupRange;
-    void resolveContentBasedTrackSizingFunctionsForNonSpanningItems(GridTrackSizingDirection, const GridSpan&amp;, RenderBox&amp; gridItem, GridTrack&amp;, GridSizingData&amp;) const;
-    template &lt;TrackSizeComputationPhase&gt; void resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirection, GridSizingData&amp;, const GridItemsSpanGroupRange&amp;) const;
-    template &lt;TrackSizeComputationPhase&gt; void distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp;, Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; availableLogicalSpace) const;
-
-    typedef HashSet&lt;unsigned, DefaultHash&lt;unsigned&gt;::Hash, WTF::UnsignedWithZeroKeyHashTraits&lt;unsigned&gt;&gt; TrackIndexSet;
-    double computeFlexFactorUnitSize(const Vector&lt;GridTrack&gt;&amp;, GridTrackSizingDirection, const GridSizingData&amp;, double flexFactorSum, LayoutUnit leftOverSpace, const Vector&lt;unsigned, 8&gt;&amp; flexibleTracksIndexes, std::unique_ptr&lt;TrackIndexSet&gt; tracksToTreatAsInflexible = nullptr) const;
-    double findFlexFactorUnitSize(const Vector&lt;GridTrack&gt;&amp;, const GridSpan&amp;, GridTrackSizingDirection, LayoutUnit spaceToFill, const GridSizingData&amp;) const;
-
-    const GridTrackSize&amp; rawGridTrackSize(GridTrackSizingDirection, unsigned, const GridSizingData&amp;) const;
-    GridTrackSize gridTrackSize(GridTrackSizingDirection, unsigned, const GridSizingData&amp;) const;
-
-    bool updateOverrideContainingBlockContentSizeForChild(RenderBox&amp;, GridTrackSizingDirection, GridSizingData&amp;) const;
-    LayoutUnit logicalHeightForChild(RenderBox&amp;) const;
-    LayoutUnit minSizeForChild(RenderBox&amp;, GridTrackSizingDirection, GridSizingData&amp;) const;
-    LayoutUnit minContentForChild(RenderBox&amp;, GridTrackSizingDirection, GridSizingData&amp;) const;
-    LayoutUnit maxContentForChild(RenderBox&amp;, GridTrackSizingDirection, GridSizingData&amp;) const;
</del><span class="cx">     GridAxisPosition columnAxisPositionForChild(const RenderBox&amp;) const;
</span><span class="cx">     GridAxisPosition rowAxisPositionForChild(const RenderBox&amp;) const;
</span><del>-    LayoutUnit columnAxisOffsetForChild(const RenderBox&amp;, const GridSizingData&amp;) const;
-    LayoutUnit rowAxisOffsetForChild(const RenderBox&amp;, const GridSizingData&amp;) const;
</del><ins>+    LayoutUnit columnAxisOffsetForChild(const RenderBox&amp;) const;
+    LayoutUnit rowAxisOffsetForChild(const RenderBox&amp;) const;
</ins><span class="cx">     ContentAlignmentData computeContentPositionAndDistributionOffset(GridTrackSizingDirection, const LayoutUnit&amp; availableFreeSpace, unsigned numberOfGridTracks) const;
</span><del>-    LayoutPoint findChildLogicalPosition(const RenderBox&amp;, const GridSizingData&amp;) const;
</del><ins>+    LayoutPoint findChildLogicalPosition(const RenderBox&amp;) const;
</ins><span class="cx">     GridArea cachedGridArea(const RenderBox&amp;) const;
</span><span class="cx">     GridSpan cachedGridSpan(const RenderBox&amp;, GridTrackSizingDirection) const;
</span><span class="cx"> 
</span><ins>+    LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&amp;, GridTrackSizingDirection) const;
</ins><span class="cx"> 
</span><del>-    LayoutUnit gridAreaBreadthForChild(const RenderBox&amp; child, GridTrackSizingDirection, const GridSizingData&amp;) const;
-    LayoutUnit gridAreaBreadthForChildIncludingAlignmentOffsets(const RenderBox&amp;, GridTrackSizingDirection, const GridSizingData&amp;) const;
-    LayoutUnit assumedRowsSizeForOrthogonalChild(const RenderBox&amp;, const GridSizingData&amp;) const;
</del><ins>+    void applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection);
</ins><span class="cx"> 
</span><del>-    void applyStretchAlignmentToTracksIfNeeded(GridTrackSizingDirection, GridSizingData&amp;);
-
</del><span class="cx">     void paintChildren(PaintInfo&amp; forSelf, const LayoutPoint&amp; paintOffset, PaintInfo&amp; forChild, bool usePrintRect) override;
</span><span class="cx">     bool needToStretchChildLogicalHeight(const RenderBox&amp;) const;
</span><span class="cx">     LayoutUnit marginLogicalHeightForChild(const RenderBox&amp;) const;
</span><span class="lines">@@ -181,24 +140,18 @@
</span><span class="cx">     std::optional&lt;int&gt; inlineBlockBaseline(LineDirectionMode) const final;
</span><span class="cx">     bool isInlineBaselineAlignedChild(const RenderBox&amp;) const;
</span><span class="cx"> 
</span><del>-#ifndef NDEBUG
-    bool tracksAreWiderThanMinTrackBreadth(GridTrackSizingDirection, GridSizingData&amp;);
-#endif
-
</del><span class="cx">     LayoutUnit gridGapForDirection(GridTrackSizingDirection) const;
</span><del>-    LayoutUnit guttersSize(const Grid&amp;, GridTrackSizingDirection, unsigned startLine, unsigned span) const;
</del><span class="cx"> 
</span><del>-    bool spanningItemCrossesFlexibleSizedTracks(const GridSpan&amp;, GridTrackSizingDirection, const GridSizingData&amp;) const;
-
</del><span class="cx">     unsigned numTracks(GridTrackSizingDirection, const Grid&amp;) const;
</span><span class="cx"> 
</span><span class="cx">     LayoutUnit translateRTLCoordinate(LayoutUnit) const;
</span><span class="cx"> 
</span><del>-    bool isOrthogonalChild(const RenderBox&amp;) const;
</del><span class="cx">     GridTrackSizingDirection flowAwareDirectionForChild(const RenderBox&amp;, GridTrackSizingDirection) const;
</span><span class="cx"> 
</span><span class="cx">     Grid m_grid;
</span><span class="cx"> 
</span><ins>+    GridTrackSizingAlgorithm m_trackSizingAlgorithm;
+
</ins><span class="cx">     Vector&lt;LayoutUnit&gt; m_columnPositions;
</span><span class="cx">     Vector&lt;LayoutUnit&gt; m_rowPositions;
</span><span class="cx">     LayoutUnit m_offsetBetweenColumns;
</span></span></pre>
</div>
</div>

</body>
</html>