<!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>[182704] trunk</title>
</head>
<body>

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

<h3>Log Message</h3>
<pre>[CSS Grid Layout] Support marking/unmarking tracks as infinitely growable
https://bugs.webkit.org/show_bug.cgi?id=141431

Reviewed by Darin Adler.

Source/WebCore:

As explained here
http://lists.w3.org/Archives/Public/www-style/2014Mar/0512.html we
sometimes need to consider that some tracks are infinitely
growable even when they are really not, in order to produce more
&quot;natural&quot; results.

For example the following case:
  grid-template-columns: auto auto;
  item 1 in column 1 with min-content = max-content = 10px;
  item 2 in columns 1-2 with min-content = 30, max-content = 100px;

will produce (45px, 55px) without this patch. But considering the
second column as infinitely growable the result is (10px, 90px), a
more &quot;natural&quot; result because column 1 just needs to be 10px to
accommodate item 1. From now on we can flag GridTracks so that
they can infinitely grow even when the growth limit is finite.

Apart from that distributeSpaceToTracks() is now unconditionally
called even though the extra space is 0. That's because it
computes the plannedSize value.

Test: fast/css-grid-layout/mark-as-infinitely-growable.html

* rendering/RenderGrid.cpp:
(WebCore::GridTrack::infiniteGrowthPotential):
(WebCore::GridTrack::infinitelyGrowable):
(WebCore::GridTrack::setInfinitelyGrowable):
(WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
(WebCore::RenderGrid::trackSizeForTrackSizeComputationPhase): Updated with new phase.
(WebCore::RenderGrid::shouldProcessTrackForTrackSizeComputationPhase): Ditto.
(WebCore::RenderGrid::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase): Ditto.
(WebCore::RenderGrid::updateTrackSizeForTrackSizeComputationPhase): Ditto.
(WebCore::RenderGrid::currentItemSizeForTrackSizeComputationPhase): Ditto.
(WebCore::RenderGrid::markAsInfinitelyGrowableForTrackSizeComputationPhase):
New helper method which does the mark/unmark just for growth limits.
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems):
(WebCore::sortByGridTrackGrowthPotential): Use
infiniteGrowthPotential() for sorting.
(WebCore::RenderGrid::distributeSpaceToTracks):
* rendering/RenderGrid.h:

LayoutTests:

New test that to check that tracks whose growth limit changes from
infinite to finite when evaluating &quot;intrinsic maximums&quot; are marked
as infinitely growable for the &quot;max-content maximums&quot; step.

* fast/css-grid-layout/mark-as-infinitely-growable-expected.txt: Added.
* fast/css-grid-layout/mark-as-infinitely-growable.html: Added.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkLayoutTestsChangeLog">trunk/LayoutTests/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</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="#trunkLayoutTestsfastcssgridlayoutmarkasinfinitelygrowableexpectedtxt">trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable-expected.txt</a></li>
<li><a href="#trunkLayoutTestsfastcssgridlayoutmarkasinfinitelygrowablehtml">trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable.html</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkLayoutTestsChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/LayoutTests/ChangeLog (182703 => 182704)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/ChangeLog        2015-04-13 10:41:51 UTC (rev 182703)
+++ trunk/LayoutTests/ChangeLog        2015-04-13 10:49:43 UTC (rev 182704)
</span><span class="lines">@@ -1,3 +1,17 @@
</span><ins>+2015-04-10  Sergio Villar Senin  &lt;svillar@igalia.com&gt;
+
+        [CSS Grid Layout] Support marking/unmarking tracks as infinitely growable
+        https://bugs.webkit.org/show_bug.cgi?id=141431
+
+        Reviewed by Darin Adler.
+
+        New test that to check that tracks whose growth limit changes from
+        infinite to finite when evaluating &quot;intrinsic maximums&quot; are marked
+        as infinitely growable for the &quot;max-content maximums&quot; step.
+
+        * fast/css-grid-layout/mark-as-infinitely-growable-expected.txt: Added.
+        * fast/css-grid-layout/mark-as-infinitely-growable.html: Added.
+
</ins><span class="cx"> 2015-04-13  Csaba Osztrogonác  &lt;ossy@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         [EFL] Unreviewed gardening, update platform specifix expected files after r181889.
</span></span></pre></div>
<a id="trunkLayoutTestsfastcssgridlayoutmarkasinfinitelygrowableexpectedtxt"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable-expected.txt (0 => 182704)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable-expected.txt                                (rev 0)
+++ trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable-expected.txt        2015-04-13 10:49:43 UTC (rev 182704)
</span><span class="lines">@@ -0,0 +1,11 @@
</span><ins>+PASS window.getComputedStyle(gridAutoAndAuto, '').getPropertyValue('-webkit-grid-template-columns') is &quot;30px 70px&quot;
+PASS window.getComputedStyle(gridAutoAndAuto, '').getPropertyValue('-webkit-grid-template-rows') is &quot;10px&quot;
+PASS window.getComputedStyle(gridFixedMaxContentAndFixedMaxContent, '').getPropertyValue('-webkit-grid-template-columns') is &quot;20px 80px&quot;
+PASS window.getComputedStyle(gridFixedMaxContentAndFixedMaxContent, '').getPropertyValue('-webkit-grid-template-rows') is &quot;10px&quot;
+PASS successfullyParsed is true
+
+TEST COMPLETE
+X X
+XXXXXX XXX
+XX
+XXXX X XXX
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable-expected.txt
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkLayoutTestsfastcssgridlayoutmarkasinfinitelygrowablehtml"></a>
<div class="addfile"><h4>Added: trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable.html (0 => 182704)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable.html                                (rev 0)
+++ trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable.html        2015-04-13 10:49:43 UTC (rev 182704)
</span><span class="lines">@@ -0,0 +1,36 @@
</span><ins>+&lt;!DOCTYPE html&gt;
+&lt;head&gt;
+&lt;link href=&quot;resources/grid.css&quot; rel=&quot;stylesheet&quot;/&gt;
+&lt;style&gt;
+.grid {
+    font: 10px/1 Ahem;
+}
+.gridAutoAndAuto {
+    -webkit-grid-template-columns: auto auto;
+}
+
+.gridFixedMaxContentAndFixedMaxContent {
+    -webkit-grid-template-columns: minmax(20px, -webkit-max-content) minmax(10px, -webkit-max-content);
+}
+&lt;/style&gt;
+&lt;script src=&quot;../../resources/js-test.js&quot;&gt;&lt;/script&gt;
+&lt;/head&gt;
+&lt;body&gt;
+&lt;script src=&quot;resources/grid-definitions-parsing-utils.js&quot;&gt;&lt;/script&gt;
+
+&lt;div class=&quot;grid gridAutoAndAuto&quot; id=&quot;gridAutoAndAuto&quot;&gt;
+    &lt;div class=&quot;firstRowFirstColumn&quot;&gt;X X&lt;/div&gt;
+    &lt;div class=&quot;firstRowBothColumn&quot;&gt;XXXXXX XXX&lt;/div&gt;
+&lt;/div&gt;
+
+&lt;div class=&quot;grid gridFixedMaxContentAndFixedMaxContent&quot; id=&quot;gridFixedMaxContentAndFixedMaxContent&quot;&gt;
+    &lt;div class=&quot;firstRowFirstColumn&quot;&gt;XX&lt;/div&gt;
+    &lt;div class=&quot;firstRowBothColumn&quot;&gt;XXXX X XXX&lt;/div&gt;
+&lt;/div&gt;
+
+&lt;script&gt;
+testGridTemplatesValues(gridAutoAndAuto, &quot;30px 70px&quot;, &quot;10px&quot;);
+testGridTemplatesValues(gridFixedMaxContentAndFixedMaxContent, &quot;20px 80px&quot;, &quot;10px&quot;);
+&lt;/script&gt;
+
+&lt;/body&gt;
</ins><span class="cx">Property changes on: trunk/LayoutTests/fast/css-grid-layout/mark-as-infinitely-growable.html
</span><span class="cx">___________________________________________________________________
</span></span></pre></div>
<a id="svnmimetype"></a>
<div class="addfile"><h4>Added: svn:mime-type</h4></div>
<a id="svneolstyle"></a>
<div class="addfile"><h4>Added: svn:eol-style</h4></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (182703 => 182704)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2015-04-13 10:41:51 UTC (rev 182703)
+++ trunk/Source/WebCore/ChangeLog        2015-04-13 10:49:43 UTC (rev 182704)
</span><span class="lines">@@ -1,3 +1,51 @@
</span><ins>+2015-04-10  Sergio Villar Senin  &lt;svillar@igalia.com&gt;
+
+        [CSS Grid Layout] Support marking/unmarking tracks as infinitely growable
+        https://bugs.webkit.org/show_bug.cgi?id=141431
+
+        Reviewed by Darin Adler.
+
+        As explained here
+        http://lists.w3.org/Archives/Public/www-style/2014Mar/0512.html we
+        sometimes need to consider that some tracks are infinitely
+        growable even when they are really not, in order to produce more
+        &quot;natural&quot; results.
+
+        For example the following case:
+          grid-template-columns: auto auto;
+          item 1 in column 1 with min-content = max-content = 10px;
+          item 2 in columns 1-2 with min-content = 30, max-content = 100px;
+
+        will produce (45px, 55px) without this patch. But considering the
+        second column as infinitely growable the result is (10px, 90px), a
+        more &quot;natural&quot; result because column 1 just needs to be 10px to
+        accommodate item 1. From now on we can flag GridTracks so that
+        they can infinitely grow even when the growth limit is finite.
+
+        Apart from that distributeSpaceToTracks() is now unconditionally
+        called even though the extra space is 0. That's because it
+        computes the plannedSize value.
+
+        Test: fast/css-grid-layout/mark-as-infinitely-growable.html
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::GridTrack::infiniteGrowthPotential):
+        (WebCore::GridTrack::infinitelyGrowable):
+        (WebCore::GridTrack::setInfinitelyGrowable):
+        (WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
+        (WebCore::RenderGrid::trackSizeForTrackSizeComputationPhase): Updated with new phase.
+        (WebCore::RenderGrid::shouldProcessTrackForTrackSizeComputationPhase): Ditto.
+        (WebCore::RenderGrid::trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase): Ditto.
+        (WebCore::RenderGrid::updateTrackSizeForTrackSizeComputationPhase): Ditto.
+        (WebCore::RenderGrid::currentItemSizeForTrackSizeComputationPhase): Ditto.
+        (WebCore::RenderGrid::markAsInfinitelyGrowableForTrackSizeComputationPhase):
+        New helper method which does the mark/unmark just for growth limits.
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems):
+        (WebCore::sortByGridTrackGrowthPotential): Use
+        infiniteGrowthPotential() for sorting.
+        (WebCore::RenderGrid::distributeSpaceToTracks):
+        * rendering/RenderGrid.h:
+
</ins><span class="cx"> 2015-04-12  Benjamin Poulain  &lt;benjamin@webkit.org&gt;
</span><span class="cx"> 
</span><span class="cx">         Legacy scroll behavior on HTMLBodyElement should only apply to the first body element of a document
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderGridcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderGrid.cpp (182703 => 182704)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderGrid.cpp        2015-04-13 10:41:51 UTC (rev 182703)
+++ trunk/Source/WebCore/rendering/RenderGrid.cpp        2015-04-13 10:49:43 UTC (rev 182704)
</span><span class="lines">@@ -73,6 +73,11 @@
</span><span class="cx">         return m_growthLimit == infinity;
</span><span class="cx">     }
</span><span class="cx"> 
</span><ins>+    bool infiniteGrowthPotential() const
+    {
+        return growthLimitIsInfinite() || m_infinitelyGrowable;
+    }
+
</ins><span class="cx">     const LayoutUnit&amp; growthLimitIfNotInfinite() const
</span><span class="cx">     {
</span><span class="cx">         ASSERT(isGrowthLimitBiggerThanBaseSize());
</span><span class="lines">@@ -88,6 +93,13 @@
</span><span class="cx"> 
</span><span class="cx">     LayoutUnit&amp; tempSize() { return m_tempSize; }
</span><span class="cx"> 
</span><ins>+    bool infinitelyGrowable() const { return m_infinitelyGrowable; }
+
+    void setInfinitelyGrowable(bool infinitelyGrowable)
+    {
+        m_infinitelyGrowable = infinitelyGrowable;
+    }
+
</ins><span class="cx"> private:
</span><span class="cx">     bool isGrowthLimitBiggerThanBaseSize() const { return growthLimitIsInfinite() || m_growthLimit &gt;= m_baseSize; }
</span><span class="cx"> 
</span><span class="lines">@@ -101,6 +113,7 @@
</span><span class="cx">     LayoutUnit m_growthLimit { 0 };
</span><span class="cx">     LayoutUnit m_plannedSize { 0 };
</span><span class="cx">     LayoutUnit m_tempSize { 0 };
</span><ins>+    bool m_infinitelyGrowable { false };
</ins><span class="cx"> };
</span><span class="cx"> 
</span><span class="cx"> struct GridTrackForNormalization {
</span><span class="lines">@@ -342,6 +355,7 @@
</span><span class="cx"> 
</span><span class="cx">         track.setBaseSize(computeUsedBreadthOfMinLength(direction, minTrackBreadth));
</span><span class="cx">         track.setGrowthLimit(computeUsedBreadthOfMaxLength(direction, maxTrackBreadth, track.baseSize()));
</span><ins>+        track.setInfinitelyGrowable(false);
</ins><span class="cx"> 
</span><span class="cx">         if (trackSize.isContentSized())
</span><span class="cx">             sizingData.contentSizedTracksIndex.append(i);
</span><span class="lines">@@ -372,7 +386,7 @@
</span><span class="cx">             tracksForDistribution[i]-&gt;setPlannedSize(tracksForDistribution[i]-&gt;baseSize());
</span><span class="cx">         }
</span><span class="cx"> 
</span><del>-        distributeSpaceToTracks&lt;DistributeSpaceToBaseSizes&gt;(tracksForDistribution, nullptr, availableLogicalSpace);
</del><ins>+        distributeSpaceToTracks&lt;MaximizeTracks&gt;(tracksForDistribution, nullptr, availableLogicalSpace);
</ins><span class="cx"> 
</span><span class="cx">         for (auto* track : tracksForDistribution)
</span><span class="cx">             track-&gt;setBaseSize(track-&gt;plannedSize());
</span><span class="lines">@@ -677,12 +691,11 @@
</span><span class="cx">     switch (phase) {
</span><span class="cx">     case ResolveIntrinsicMinimums:
</span><span class="cx">     case ResolveMaxContentMinimums:
</span><ins>+    case MaximizeTracks:
</ins><span class="cx">         return track.baseSize();
</span><del>-        break;
</del><span class="cx">     case ResolveIntrinsicMaximums:
</span><span class="cx">     case ResolveMaxContentMaximums:
</span><span class="cx">         return restriction == AllowInfinity ? track.growthLimit() : track.growthLimitIfNotInfinite();
</span><del>-        break;
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="lines">@@ -700,6 +713,9 @@
</span><span class="cx">         return trackSize.hasMinOrMaxContentMaxTrackBreadth();
</span><span class="cx">     case ResolveMaxContentMaximums:
</span><span class="cx">         return trackSize.hasMaxContentMaxTrackBreadth();
</span><ins>+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return false;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="lines">@@ -716,12 +732,37 @@
</span><span class="cx">     case ResolveIntrinsicMaximums:
</span><span class="cx">     case ResolveMaxContentMaximums:
</span><span class="cx">         return true;
</span><ins>+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return false;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="cx">     return false;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void RenderGrid::markAsInfinitelyGrowableForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track)
+{
+    switch (phase) {
+    case ResolveIntrinsicMinimums:
+    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();
+}
+
</ins><span class="cx"> void RenderGrid::updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase phase, GridTrack&amp; track)
</span><span class="cx"> {
</span><span class="cx">     switch (phase) {
</span><span class="lines">@@ -733,6 +774,9 @@
</span><span class="cx">     case ResolveMaxContentMaximums:
</span><span class="cx">         track.setGrowthLimit(track.plannedSize());
</span><span class="cx">         return;
</span><ins>+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="lines">@@ -747,6 +791,9 @@
</span><span class="cx">     case ResolveMaxContentMinimums:
</span><span class="cx">     case ResolveMaxContentMaximums:
</span><span class="cx">         return maxContentForChild(gridItem, direction, columnTracks);
</span><ins>+    case MaximizeTracks:
+        ASSERT_NOT_REACHED();
+        return 0;
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     ASSERT_NOT_REACHED();
</span><span class="lines">@@ -788,25 +835,14 @@
</span><span class="cx">             continue;
</span><span class="cx"> 
</span><span class="cx">         LayoutUnit extraSpace = currentItemSizeForTrackSizeComputationPhase(phase, gridItemWithSpan.gridItem(), direction, sizingData.columnTracks) - spanningTracksSize;
</span><del>-        // Specs mandate to floor extraSpace to 0. Instead we directly avoid the function call in those cases as it will be
-        // a noop in terms of track sizing.
-        if (extraSpace &gt; 0) {
-            auto* tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimitsTracks.isEmpty() ? &amp;sizingData.filteredTracks : &amp;sizingData.growBeyondGrowthLimitsTracks;
-            switch (phase) {
-            case ResolveIntrinsicMinimums:
-            case ResolveMaxContentMinimums:
-                distributeSpaceToTracks&lt;DistributeSpaceToBaseSizes&gt;(sizingData.filteredTracks, tracksToGrowBeyondGrowthLimits, extraSpace);
-                break;
-            case ResolveIntrinsicMaximums:
-            case ResolveMaxContentMaximums:
-                distributeSpaceToTracks&lt;DistributeSpaceToGrowthLimits&gt;(sizingData.filteredTracks, tracksToGrowBeyondGrowthLimits, extraSpace);
-                break;
-            }
-        }
</del><ins>+        extraSpace = std::max&lt;LayoutUnit&gt;(extraSpace, 0);
+        auto&amp; tracksToGrowBeyondGrowthLimits = sizingData.growBeyondGrowthLimitsTracks.isEmpty() ? &amp;sizingData.filteredTracks : &amp;sizingData.growBeyondGrowthLimitsTracks;
+        distributeSpaceToTracks&lt;phase&gt;(sizingData.filteredTracks, &amp;tracksToGrowBeyondGrowthLimits, extraSpace);
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (const auto&amp; trackIndex : sizingData.contentSizedTracksIndex) {
</span><span class="cx">         GridTrack&amp; track = tracks[trackIndex];
</span><ins>+        markAsInfinitelyGrowableForTrackSizeComputationPhase(phase, track);
</ins><span class="cx">         updateTrackSizeForTrackSizeComputationPhase(phase, track);
</span><span class="cx">     }
</span><span class="cx"> }
</span><span class="lines">@@ -815,45 +851,41 @@
</span><span class="cx"> {
</span><span class="cx">     // This check ensures that we respect the irreflexivity property of the strict weak ordering required by std::sort
</span><span class="cx">     // (forall x: NOT x &lt; x).
</span><del>-    if (track1-&gt;growthLimitIsInfinite() &amp;&amp; track2-&gt;growthLimitIsInfinite())
</del><ins>+    if (track1-&gt;infiniteGrowthPotential() &amp;&amp; track2-&gt;infiniteGrowthPotential())
</ins><span class="cx">         return false;
</span><span class="cx"> 
</span><del>-    if (track1-&gt;growthLimitIsInfinite() || track2-&gt;growthLimitIsInfinite())
-        return track2-&gt;growthLimitIsInfinite();
</del><ins>+    if (track1-&gt;infiniteGrowthPotential() || track2-&gt;infiniteGrowthPotential())
+        return track2-&gt;infiniteGrowthPotential();
</ins><span class="cx"> 
</span><span class="cx">     return (track1-&gt;growthLimit() - track1-&gt;baseSize()) &lt; (track2-&gt;growthLimit() - track2-&gt;baseSize());
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-template &lt;RenderGrid::DistributeSpacePhase phase&gt;
</del><ins>+template &lt;RenderGrid::TrackSizeComputationPhase phase&gt;
</ins><span class="cx"> void RenderGrid::distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp; tracks, const Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; availableLogicalSpace)
</span><span class="cx"> {
</span><del>-    ASSERT(availableLogicalSpace &gt; 0);
-    std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential);
</del><ins>+    ASSERT(availableLogicalSpace &gt;= 0);
</ins><span class="cx"> 
</span><del>-    unsigned tracksSize = tracks.size();
</del><ins>+    for (auto* track : tracks)
+        track-&gt;tempSize() = trackSizeForTrackSizeComputationPhase(phase, *track, ForbidInfinity);
</ins><span class="cx"> 
</span><del>-    for (unsigned i = 0; i &lt; tracksSize; ++i) {
-        GridTrack&amp; track = *tracks[i];
-        LayoutUnit trackBreadth;
-        switch (phase) {
-        case DistributeSpaceToBaseSizes:
-            trackBreadth = track.baseSize();
-            break;
-        case DistributeSpaceToGrowthLimits:
-            trackBreadth = track.growthLimitIfNotInfinite();
-            break;
</del><ins>+    if (availableLogicalSpace &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 = availableLogicalSpace / (tracksSize - i);
+                LayoutUnit growthShare = infiniteGrowthPotential ? availableLogicalSpaceShare : std::min(availableLogicalSpaceShare, trackGrowthPotential);
+                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 availableLogicalSpace.&quot;);
+                track.tempSize() += growthShare;
+                availableLogicalSpace -= growthShare;
+            }
</ins><span class="cx">         }
</span><del>-        bool infiniteGrowthPotential = track.growthLimitIsInfinite();
-        LayoutUnit trackGrowthPotential = infiniteGrowthPotential ? track.growthLimit() : track.growthLimit() - trackBreadth;
-        track.tempSize() = 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 = availableLogicalSpace / (tracksSize - i);
-            LayoutUnit growthShare = infiniteGrowthPotential ? availableLogicalSpaceShare : std::min(availableLogicalSpaceShare, trackGrowthPotential);
-            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 availableLogicalSpace.&quot;);
-            track.tempSize() += growthShare;
-            availableLogicalSpace -= growthShare;
-        }
</del><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (availableLogicalSpace &gt; 0 &amp;&amp; growBeyondGrowthLimitsTracks) {
</span><span class="lines">@@ -867,7 +899,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     for (auto* track : tracks)
</span><del>-        track-&gt;setPlannedSize(std::max(track-&gt;plannedSize(), track-&gt;tempSize()));
</del><ins>+        track-&gt;setPlannedSize(track-&gt;plannedSize() == infinity ? track-&gt;tempSize() : std::max(track-&gt;plannedSize(), track-&gt;tempSize()));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> #ifndef NDEBUG
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderGridh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderGrid.h (182703 => 182704)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderGrid.h        2015-04-13 10:41:51 UTC (rev 182703)
+++ trunk/Source/WebCore/rendering/RenderGrid.h        2015-04-13 10:49:43 UTC (rev 182704)
</span><span class="lines">@@ -96,21 +96,19 @@
</span><span class="cx">         ResolveMaxContentMinimums,
</span><span class="cx">         ResolveIntrinsicMaximums,
</span><span class="cx">         ResolveMaxContentMaximums,
</span><ins>+        MaximizeTracks,
</ins><span class="cx">     };
</span><del>-    enum DistributeSpacePhase {
-        DistributeSpaceToBaseSizes,
-        DistributeSpaceToGrowthLimits,
-    };
</del><span class="cx">     static const LayoutUnit&amp; trackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, GridTrack&amp;, TrackSizeRestriction);
</span><span class="cx">     static bool shouldProcessTrackForTrackSizeComputationPhase(TrackSizeComputationPhase, const GridTrackSize&amp;);
</span><span class="cx">     static bool trackShouldGrowBeyondGrowthLimitsForTrackSizeComputationPhase(TrackSizeComputationPhase, const GridTrackSize&amp;);
</span><ins>+    static void markAsInfinitelyGrowableForTrackSizeComputationPhase(TrackSizeComputationPhase, GridTrack&amp;);
</ins><span class="cx">     static void updateTrackSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, GridTrack&amp;);
</span><span class="cx">     LayoutUnit currentItemSizeForTrackSizeComputationPhase(TrackSizeComputationPhase, RenderBox&amp;, GridTrackSizingDirection, Vector&lt;GridTrack&gt;&amp; columnTracks);
</span><span class="cx"> 
</span><span class="cx">     typedef struct GridItemsSpanGroupRange GridItemsSpanGroupRange;
</span><span class="cx">     void resolveContentBasedTrackSizingFunctionsForNonSpanningItems(GridTrackSizingDirection, const GridCoordinate&amp;, RenderBox&amp; gridItem, GridTrack&amp;, Vector&lt;GridTrack&gt;&amp; columnTracks);
</span><span class="cx">     template &lt;TrackSizeComputationPhase&gt; void resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizingDirection, GridSizingData&amp;, const GridItemsSpanGroupRange&amp;);
</span><del>-    template &lt;DistributeSpacePhase&gt; void distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp;, const Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; availableLogicalSpace);
</del><ins>+    template &lt;TrackSizeComputationPhase&gt; void distributeSpaceToTracks(Vector&lt;GridTrack*&gt;&amp;, const Vector&lt;GridTrack*&gt;* growBeyondGrowthLimitsTracks, LayoutUnit&amp; availableLogicalSpace);
</ins><span class="cx"> 
</span><span class="cx">     double computeNormalizedFractionBreadth(Vector&lt;GridTrack&gt;&amp;, const GridSpan&amp; tracksSpan, GridTrackSizingDirection, LayoutUnit availableLogicalSpace) const;
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>