Skip to content
Permalink
Browse files
[css-grid] Improve grid container sizing with size constraints and in…
…trinsic sizes

https://bugs.webkit.org/show_bug.cgi?id=150679

Reviewed by Darin Adler.

Source/WebCore:

The grid container stores from now on its min-content and
max-content block sizes in order to be able to properly
compute its intrinsic size. It has to redefine
computeIntrinsicLogicalContentHeightUsing() because the
behavior of grid is different to "normal" blocks:

- the min-content size is the sum of the grid container's
track sizes in the appropiate axis when the grid is sized
under a min-content constraint.
- the max-content size is the sum of the grid container's
track sizes in the appropiate axis when the grid is sized
under a max-content constraint.
- the auto block size is the max-content size.

A nice side effect is that we can now properly detect whether
the grid has a definite size on a given axis or not.

Tests: fast/css-grid-layout/absolute-positioning-definite-sizes.html
       fast/css-grid-layout/flex-and-intrinsic-sizes.html
       fast/css-grid-layout/maximize-tracks-definite-indefinite-height.html
       fast/css-grid-layout/maximize-tracks-definite-indefinite-width.html

* rendering/RenderBox.h: made
computeIntrinsicLogicalContentHeightUsing() virtual.
* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::GridSizingData::GridSizingData):
(WebCore::RenderGrid::GridSizingData::freeSpaceForDirection):
(WebCore::RenderGrid::GridSizingData::setFreeSpaceForDirection):
(WebCore::RenderGrid::computeTrackBasedLogicalHeight):
(WebCore::RenderGrid::computeTrackSizesForDirection):
(WebCore::RenderGrid::layoutBlock):
(WebCore::RenderGrid::computeIntrinsicLogicalWidths):
(WebCore::RenderGrid::computeIntrinsicLogicalHeight):
(WebCore::RenderGrid::computeIntrinsicLogicalContentHeightUsing):
(WebCore::RenderGrid::computeUsedBreadthOfGridTracks):
(WebCore::RenderGrid::distributeSpaceToTracks):
(WebCore::RenderGrid::tracksAreWiderThanMinTrackBreadth):
(WebCore::RenderGrid::applyStretchAlignmentToTracksIfNeeded):
(WebCore::RenderGrid::layoutGridItems):
(WebCore::RenderGrid::populateGridPositions):
(WebCore::RenderGrid::gridElementIsShrinkToFit): Deleted.
* rendering/RenderGrid.h:

LayoutTests:

* fast/css-grid-layout/absolute-positioning-definite-sizes-expected.txt: Added.
* fast/css-grid-layout/absolute-positioning-definite-sizes.html: Added.
* fast/css-grid-layout/flex-and-intrinsic-sizes-expected.txt: Added.
* fast/css-grid-layout/flex-and-intrinsic-sizes.html: Added.
* fast/css-grid-layout/grid-element-change-columns-repaint.html:
* fast/css-grid-layout/grid-item-change-column-repaint.html:
* fast/css-grid-layout/grid-preferred-logical-widths.html:
* fast/css-grid-layout/maximize-tracks-definite-indefinite-height-expected.txt: Added.
* fast/css-grid-layout/maximize-tracks-definite-indefinite-height.html: Added.
* fast/css-grid-layout/maximize-tracks-definite-indefinite-width-expected.txt: Added.
* fast/css-grid-layout/maximize-tracks-definite-indefinite-width.html: Added.
* fast/css-grid-layout/percent-of-indefinite-track-size.html:
* fast/events/key-events-in-editable-gridbox-expected.txt:
* fast/events/key-events-in-editable-gridbox.html: Added more test
cases for intrinsic and fixed sized heights.

Canonical link: https://commits.webkit.org/169231@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192154 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
svillar committed Nov 9, 2015
1 parent 113c803 commit 25ed4a9f00e633f67a7b1caa1d8b1f6fa1e18311
Showing 19 changed files with 1,198 additions and 279 deletions.
@@ -1,3 +1,26 @@
2015-11-02 Sergio Villar Senin <svillar@igalia.com>

[css-grid] Improve grid container sizing with size constraints and intrinsic sizes
https://bugs.webkit.org/show_bug.cgi?id=150679

Reviewed by Darin Adler.

* fast/css-grid-layout/absolute-positioning-definite-sizes-expected.txt: Added.
* fast/css-grid-layout/absolute-positioning-definite-sizes.html: Added.
* fast/css-grid-layout/flex-and-intrinsic-sizes-expected.txt: Added.
* fast/css-grid-layout/flex-and-intrinsic-sizes.html: Added.
* fast/css-grid-layout/grid-element-change-columns-repaint.html:
* fast/css-grid-layout/grid-item-change-column-repaint.html:
* fast/css-grid-layout/grid-preferred-logical-widths.html:
* fast/css-grid-layout/maximize-tracks-definite-indefinite-height-expected.txt: Added.
* fast/css-grid-layout/maximize-tracks-definite-indefinite-height.html: Added.
* fast/css-grid-layout/maximize-tracks-definite-indefinite-width-expected.txt: Added.
* fast/css-grid-layout/maximize-tracks-definite-indefinite-width.html: Added.
* fast/css-grid-layout/percent-of-indefinite-track-size.html:
* fast/events/key-events-in-editable-gridbox-expected.txt:
* fast/events/key-events-in-editable-gridbox.html: Added more test
cases for intrinsic and fixed sized heights.

2015-11-05 Sergio Villar Senin <svillar@igalia.com>

[css-grid] Grid placement conflict handling
@@ -0,0 +1,5 @@
Items should extend to fill the width of the absolutely positioned grid container.

XXX X
XX XXX XX
PASS
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<link href="resources/grid.css" rel="stylesheet">
<style>
.grid {
-webkit-grid-template: 1fr / 50px 1fr;

position: absolute;
left: 50px;
top: 50px;

width: 200px;
height: 200px;

border: 7px solid #ccc;
font: 10px/1 Ahem;
}

.row1 {
grid-row-start: 1;
background-color: yellow;
}

.row2 {
grid-row-start: 2;
background-color: cyan;
}
</style>

<p>Items should extend to fill the width of the absolutely positioned grid container.</p>
<script src="../../resources/check-layout.js"></script>
<body onload="checkLayout('.grid')">

<div class="grid">
<div class="row1" data-expected-height="50" data-expected-width="200">XXX X</div>
<div class="row2" data-expected-height="150" data-expected-width="200">XX XXX XX</div>
</div>

</body>
@@ -0,0 +1,19 @@
This test checks that fr tracks are properly sized whenever grid have intrinsic sizes.

XXX XXX
PASS
XXX XXX
FAIL:
Expected 30 for width, but got 70.

<div class="container">
<div class="grid minContent" data-expected-width="30" data-expected-height="10">
<div>XXX XXX</div>
</div>
</div>
XXX XXX
PASS
XXX XXX
PASS
XXX XXX
PASS
@@ -0,0 +1,77 @@
<!DOCTYPE html>

<link href="resources/grid.css" rel="stylesheet">

<style>
.container {
width: 100px;
height: 100px;
}

.grid {
-webkit-grid-template-columns: 1fr;
-webkit-grid-template-rows: 1fr;
}

div { font: 10px/1 Ahem; }

.minContent {
width: -webkit-min-content;
height: -webkit-min-content;
}

.maxContent {
width: -webkit-max-content;
height: -webkit-max-content;
}

.fitContent {
width: -webkit-fit-content;
height: -webkit-fit-content;
}

.fillAvailable {
width: -webkit-fill-available;
height: -webkit-fill-available;
}

</style>

<script src="../../resources/check-layout.js"></script>

<body onload="checkLayout('.grid')">

<p>This test checks that fr tracks are properly sized whenever grid have intrinsic sizes.</p>

<div class="container">
<div class="grid" data-expected-width="100" data-expected-height="10">
<div>XXX XXX</div>
</div>
</div>

<!-- This fails due to https://bugs.webkit.org/show_bug.cgi?id=150674 -->
<div class="container">
<div class="grid minContent" data-expected-width="30" data-expected-height="10">
<div>XXX XXX</div>
</div>
</div>

<div class="container">
<div class="grid maxContent" data-expected-width="70" data-expected-height="10">
<div>XXX XXX</div>
</div>
</div>

<div class="container">
<div class="grid fitContent" data-expected-width="70" data-expected-height="10">
<div>XXX XXX</div>
</div>
</div>

<div class="container">
<div class="grid fillAvailable" data-expected-width="100" data-expected-height="100">
<div>XXX XXX</div>
</div>
</div>

</body>
@@ -16,7 +16,7 @@
}

.grid {
width: -webkit-fit-content;
width: -webkit-min-content;
-webkit-grid-template-rows: 50px;
-webkit-grid-template-columns: minmax(100px, 180px) 100px minmax(50px, 100px);
}
@@ -16,7 +16,7 @@
}

.grid {
width: -webkit-fit-content;
width: -webkit-min-content;
-webkit-grid-template-rows: 50px;
-webkit-grid-template-columns: minmax(100px, 180px) 100px minmax(50px, 100px);
}

0 comments on commit 25ed4a9

Please sign in to comment.