Skip to content
Permalink
Browse files
[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.

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:


Canonical link: https://commits.webkit.org/166786@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189208 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
javifernandez committed Sep 1, 2015
1 parent 290f0f2 commit 686a17aa3ca424ea07ce48f5cd5e44b677bff453
Showing 6 changed files with 132 additions and 1 deletion.
@@ -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.
@@ -0,0 +1,5 @@
Test that resolving auto tracks on grid items works properly.

PASS
PASS
PASS
@@ -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>


@@ -4,7 +4,7 @@
<style>
.grid {
-webkit-grid-template-rows: 50px 50px;
-webkit-grid-template-columns: 0.5fr 0.5fr;
-webkit-grid-template-columns: 1fr 1fr;
}

.floatPos {
@@ -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.
@@ -500,6 +500,11 @@ double RenderGrid::computeNormalizedFractionBreadth(Vector<GridTrack>& tracks, c
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;
}

0 comments on commit 686a17a

Please sign in to comment.