Commit be21183b authored by Oriol Brufau's avatar Oriol Brufau Committed by Commit Bot

[css-grid] Properly align items next to collapsed tracks with gutters

GridAreaPositionForInFlowChild could return a wrong end position for
grid items adjacent to a collapsed track, because it didn't take into
account that gutters collapse in that case. Therefore, "center" or
"end" alignments displayed the item at the wrong position.

BUG=801881

TEST=external/wpt/css/css-grid/alignment/grid-gutters-013.html

Change-Id: I8223f102e3fd581ab0a2d6f23d18c188e23807c7
Reviewed-on: https://chromium-review.googlesource.com/1245727Reviewed-by: default avatarJavier Fernandez <jfernandez@igalia.com>
Reviewed-by: default avatarSergio Villar <svillar@igalia.com>
Reviewed-by: default avatarManuel Rego <rego@igalia.com>
Commit-Queue: Javier Fernandez <jfernandez@igalia.com>
Cr-Commit-Position: refs/heads/master@{#595045}
parent 87ed0acb
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Gutters adjacent to collapsed tracks also collapse</title>
<link rel="help" href="https://www.w3.org/TR/css-grid-1/#gutters">
<link rel="help" href="https://www.w3.org/TR/css-align-3/#gap-shorthand">
<link rel="help" href="https://www.w3.org/TR/css-align-3/#gap-legacy">
<link rel="help" href="https://www.w3.org/TR/css-grid-1/#repeat-notation">
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<meta name="assert" content="This test checks that gutters adjacent to collapsed tracks don't reduce the space available for aligning adjacent grid items." />
<style>
#grid {
display: grid;
margin-top: -50px;
margin-left: -50px;
width: 500px;
height: 500px;
grid-gap: 100px;
grid-template-rows: repeat(auto-fit, 200px);
grid-template-columns: repeat(auto-fit, 200px);
align-items: center;
justify-items: center;
background: linear-gradient(red, red) no-repeat 50px 50px / 100px 100px;
}
#grid > div {
background-color: green;
width: 50%;
height: 50%;
}
</style>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div id="grid">
<div></div>
</div>
...@@ -2109,8 +2109,8 @@ void LayoutGrid::GridAreaPositionForInFlowChild( ...@@ -2109,8 +2109,8 @@ void LayoutGrid::GridAreaPositionForInFlowChild(
LayoutUnit& start, LayoutUnit& start,
LayoutUnit& end) const { LayoutUnit& end) const {
DCHECK(!child.IsOutOfFlowPositioned()); DCHECK(!child.IsOutOfFlowPositioned());
const GridSpan& span = const Grid& grid = track_sizing_algorithm_.GetGrid();
track_sizing_algorithm_.GetGrid().GridItemSpan(child, direction); const GridSpan& span = grid.GridItemSpan(child, direction);
// TODO (lajava): This is a common pattern, why not defining a function like // TODO (lajava): This is a common pattern, why not defining a function like
// positions(direction) ? // positions(direction) ?
auto& positions = auto& positions =
...@@ -2120,8 +2120,11 @@ void LayoutGrid::GridAreaPositionForInFlowChild( ...@@ -2120,8 +2120,11 @@ void LayoutGrid::GridAreaPositionForInFlowChild(
// The 'positions' vector includes distribution offset (because of content // The 'positions' vector includes distribution offset (because of content
// alignment) and gutters so we need to subtract them to get the actual // alignment) and gutters so we need to subtract them to get the actual
// end position for a given track (this does not have to be done for the // end position for a given track (this does not have to be done for the
// last track as there are no more positions's elements after it). // last track as there are no more positions's elements after it, nor for
if (span.EndLine() < positions.size() - 1) // collapsed tracks).
if (span.EndLine() < positions.size() - 1 &&
!(grid.HasAutoRepeatEmptyTracks(direction) &&
grid.IsEmptyAutoRepeatTrack(direction, span.EndLine())))
end -= GridGap(direction) + GridItemOffset(direction); end -= GridGap(direction) + GridItemOffset(direction);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment