[CSS Grid Layout] Layout is wrong for flex factor sum between 0 and 1
authorjfernandez@igalia.com <jfernandez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Sep 2015 15:04:08 +0000 (15:04 +0000)
committerjfernandez@igalia.com <jfernandez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 1 Sep 2015 15:04:08 +0000 (15:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148645

Reviewed by Darin Adler.

Source/WebCore:

This patch ensures that we don't normalize the individual tracks
to fill the space. More precisely, when we sum up the flexes, that
tells us how many "units" of flex need to fit into the free
space. We then figure out what size to assign to the flex unit
based on that, and send that back to the individual items, sizing
them appropriately to their flex value.

This way we get flex fraction values applied correctly so they fill
the available space in the indicated proportion. This approach has
an additional advantage of dealing with division by 0 when reducing
automatically the flex value.

Test: fast/css-grid-layout/flex-factor-sum-less-than-1.html

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::computeNormalizedFractionBreadth):

LayoutTests:

Ensure we don't normalize individual tracks to fill the space, so
at least, the sum of flex values must be 1. We also needed to
modify the grid-element-shrink-to-fit to adapt it to the new
behavior of flex fraction units.

* fast/css-grid-layout/flex-factor-sum-less-than-1-expected.txt: Added.
* fast/css-grid-layout/flex-factor-sum-less-than-1.html: Added.
* fast/css-grid-layout/grid-element-shrink-to-fit.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189208 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/css-grid-layout/flex-factor-sum-less-than-1-expected.txt [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/flex-factor-sum-less-than-1.html [new file with mode: 0644]
LayoutTests/fast/css-grid-layout/grid-element-shrink-to-fit.html
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderGrid.cpp

index b315410..5cf8785 100644 (file)
@@ -1,3 +1,19 @@
+2015-09-01  Javier Fernandez  <jfernandez@igalia.com>
+
+        [CSS Grid Layout] Layout is wrong for flex factor sum between 0 and 1
+        https://bugs.webkit.org/show_bug.cgi?id=148645
+
+        Reviewed by Darin Adler.
+
+        Ensure we don't normalize individual tracks to fill the space, so
+        at least, the sum of flex values must be 1. We also needed to
+        modify the grid-element-shrink-to-fit to adapt it to the new
+        behavior of flex fraction units.
+
+        * fast/css-grid-layout/flex-factor-sum-less-than-1-expected.txt: Added.
+        * fast/css-grid-layout/flex-factor-sum-less-than-1.html: Added.
+        * fast/css-grid-layout/grid-element-shrink-to-fit.html:
+
 2015-09-01  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
 
         Unreviewed EFL gardening. Skip new two tests which aren't supported by EFL port.
 2015-09-01  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
 
         Unreviewed EFL gardening. Skip new two tests which aren't supported by EFL port.
diff --git a/LayoutTests/fast/css-grid-layout/flex-factor-sum-less-than-1-expected.txt b/LayoutTests/fast/css-grid-layout/flex-factor-sum-less-than-1-expected.txt
new file mode 100644 (file)
index 0000000..bde5076
--- /dev/null
@@ -0,0 +1,5 @@
+Test that resolving auto tracks on grid items works properly.
+
+PASS
+PASS
+PASS
diff --git a/LayoutTests/fast/css-grid-layout/flex-factor-sum-less-than-1.html b/LayoutTests/fast/css-grid-layout/flex-factor-sum-less-than-1.html
new file mode 100644 (file)
index 0000000..e913a3b
--- /dev/null
@@ -0,0 +1,81 @@
+<!DOCTYPE html>
+<html>
+<link href="resources/grid.css" rel="stylesheet">
+<style>
+.onlyColumnFractionFlexFactors {
+    -webkit-grid-template-columns: minmax(0,0.1fr) minmax(0,0.2fr) minmax(0,0.3fr);
+    -webkit-grid-template-rows: 50px;
+    width: 100px;
+}
+.onlyRowFractionFlexFactors {
+    -webkit-grid-template-columns: 50px;
+    -webkit-grid-template-rows: minmax(0,0.1fr) minmax(0,0.2fr) minmax(0,0.3fr);
+    width: 50px;
+    height: 100px;
+}
+.fixedAndfractionFlexFactors {
+    -webkit-grid-template-columns: 50px minmax(0,0.2fr) 30px;
+    -webkit-grid-template-rows: minmax(0,0.1fr) 50px minmax(0,0.3fr);
+    width: 100px;
+    height: 100px;
+}
+.firstRowThirdColumn {
+    background-color: yellow;
+    -webkit-grid-column: 3;
+    -webkit-grid-row: 1;
+}
+.secondRowThirdColumn {
+    background-color: yellow;
+    -webkit-grid-column: 3;
+    -webkit-grid-row: 2;
+}
+.thirdRowFirstColumn {
+    background-color: brown;
+    -webkit-grid-column: 1;
+    -webkit-grid-row: 3;
+}
+.thirdRowThirdColumn {
+    background-color: magenta;
+    -webkit-grid-column: 3;
+    -webkit-grid-row: 3;
+}
+</style>
+<script src="../../resources/check-layout.js"></script>
+<body onload="checkLayout('.grid');">
+
+<p>Test that resolving auto tracks on grid items works properly.</p>
+
+<div style="position: relative;">
+    <div class="grid onlyColumnFractionFlexFactors">
+        <div class="firstRowFirstColumn" data-expected-width="10" data-expected-height="50"></div>
+        <div class="firstRowSecondColumn" data-expected-width="20" data-expected-height="50"></div>
+        <div class="firstRowThirdColumn" data-expected-width="30" data-expected-height="50"></div>
+    </div>
+</div>
+
+<div style="position: relative;">
+    <div class="grid onlyRowFractionFlexFactors">
+        <div class="firstRowFirstColumn" data-expected-width="50" data-expected-height="10"></div>
+        <div class="secondRowFirstColumn" data-expected-width="50" data-expected-height="20"></div>
+        <div class="thirdRowFirstColumn" data-expected-width="50" data-expected-height="30"></div>
+    </div>
+</div>
+
+<div style="position: relative;">
+    <div class="grid fixedAndfractionFlexFactors">
+        <div class="firstRowFirstColumn" data-expected-width="50" data-expected-height="5"></div>
+        <div class="firstRowSecondColumn" data-expected-width="4" data-expected-height="5"></div>
+        <div class="firstRowThirdColumn" data-expected-width="30" data-expected-height="5"></div>
+        <div class="secondRowFirstColumn" data-expected-width="50" data-expected-height="50"></div>
+        <div class="secondRowSecondColumn" data-expected-width="4" data-expected-height="50"></div>
+        <div class="secondRowThirdColumn" data-expected-width="30" data-expected-height="50"></div>
+        <div class="thirdRowFirstColumn" data-expected-width="50" data-expected-height="15"></div>
+        <div class="thirdRowSecondColumn" data-expected-width="4" data-expected-height="15"></div>
+        <div class="thirdRowThirdColumn" data-expected-width="30" data-expected-height="15"></div>
+    </div>
+</div>
+
+</body>
+</html>
+
+
index 4bdabf2..f2ed52d 100644 (file)
@@ -4,7 +4,7 @@
 <style>
 .grid {
     -webkit-grid-template-rows: 50px 50px;
 <style>
 .grid {
     -webkit-grid-template-rows: 50px 50px;
-    -webkit-grid-template-columns: 0.5fr 0.5fr;
+    -webkit-grid-template-columns: 1fr 1fr;
 }
 
 .floatPos {
 }
 
 .floatPos {
index 713d4b0..5217d14 100644 (file)
@@ -1,3 +1,27 @@
+2015-09-01  Javier Fernandez  <jfernandez@igalia.com>
+
+        [CSS Grid Layout] Layout is wrong for flex factor sum between 0 and 1
+        https://bugs.webkit.org/show_bug.cgi?id=148645
+
+        Reviewed by Darin Adler.
+
+        This patch ensures that we don't normalize the individual tracks
+        to fill the space. More precisely, when we sum up the flexes, that
+        tells us how many "units" of flex need to fit into the free
+        space. We then figure out what size to assign to the flex unit
+        based on that, and send that back to the individual items, sizing
+        them appropriately to their flex value.
+
+        This way we get flex fraction values applied correctly so they fill
+        the available space in the indicated proportion. This approach has
+        an additional advantage of dealing with division by 0 when reducing
+        automatically the flex value.
+
+        Test: fast/css-grid-layout/flex-factor-sum-less-than-1.html
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::computeNormalizedFractionBreadth):
+
 2015-08-31  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r189198.
 2015-08-31  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r189198.
index 4216d29..c7ab01e 100644 (file)
@@ -500,6 +500,11 @@ double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
         availableLogicalSpaceIgnoringFractionTracks += track.m_track->baseSize();
     }
 
         availableLogicalSpaceIgnoringFractionTracks += track.m_track->baseSize();
     }
 
+    // Let flex factor sum be the sum of the flex factors of the flexible tracks. If this value
+    // is less than 1, set it to 1 instead.
+    if (accumulatedFractions < 1)
+        return availableLogicalSpaceIgnoringFractionTracks;
+
     return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions;
 }
 
     return availableLogicalSpaceIgnoringFractionTracks / accumulatedFractions;
 }