Commit 0a900867 authored by Oriol Brufau's avatar Oriol Brufau Committed by Commit Bot

[css-grid] Fix referencing line both inside and after auto repeat()

When referencing a line name appearing both inside and after an auto
repeat(), the code used to just take the minim of:
 - The absolute index of the line inside the auto repeat(), i.e. the
   local index relative to the auto repeat() plus the insertion point of
   the auto repeat().
 - The index of the line outside the auto repeat(), without expanding
   repeated tracks.

This was correct if the line outside the auto repeat() preceded it.
Otherwise it was wrong due to not taking repeated tracks into account.

For example, with

  grid-template-columns: 1px repeat(auto-fill, 2px 3px [a]) [a];

the absolute index of the line inside the auto repeat() is 2 + 1 = 3.
And the absolute index of the line outside the auto repeat() is 1 + 2*n.
However, the used index wasn't including repeated tracks so it was 2.

Therefore, the minimum was 2 but should have been 3.

BUG=966090

TEST=external/wpt/css/css-grid/placement/grid-placement-using-named-grid-lines-003.html

Change-Id: I1777a64d7e7d39350a327185dcd13f82493adfdb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2071019
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Reviewed-by: default avatarJavier Fernandez <jfernandez@igalia.com>
Cr-Commit-Position: refs/heads/master@{#745925}
parent 012dc470
......@@ -108,19 +108,19 @@ size_t NamedLineCollection::FirstPosition() {
size_t first_line = 0;
if (!auto_repeat_named_lines_indexes_) {
if (insertion_point_ < named_lines_indexes_->at(first_line))
return named_lines_indexes_->at(first_line) +
(auto_repeat_total_tracks_ ? auto_repeat_total_tracks_ - 1 : 0);
// If there is no auto repeat(), there must be some named line outside, return
// the 1st one. Also return it if it precedes the auto-repeat().
if (auto_repeat_total_tracks_ == 0 ||
(named_lines_indexes_ &&
named_lines_indexes_->at(first_line) <= insertion_point_))
return named_lines_indexes_->at(first_line);
}
if (!named_lines_indexes_)
// Return the 1st named line inside the auto repeat(), if any.
if (auto_repeat_named_lines_indexes_)
return auto_repeat_named_lines_indexes_->at(first_line) + insertion_point_;
return std::min(
named_lines_indexes_->at(first_line),
auto_repeat_named_lines_indexes_->at(first_line) + insertion_point_);
// The 1st named line must be after the auto repeat().
return named_lines_indexes_->at(first_line) + auto_repeat_total_tracks_ - 1;
}
GridPositionSide GridPositionsResolver::InitialPositionSide(
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Grid item placement with named line and auto repeat()</title>
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">
<link rel="help" href="http://www.w3.org/TR/css-grid-1/#line-placement">
<link rel="match" href="../../reference/ref-filled-green-100px-square.xht">
<meta name="assert" content="Grid placement algorithm is able to select the right line when there is an auto repeat().">
<style>
.grid {
display: grid;
width: 300px;
height: 300px;
position: relative;
top: -200px;
left: -200px;
grid-template-columns: repeat(auto-fill, 100px 100px) [area-start] 100px [area-end];
grid-template-rows: repeat(auto-fill, 100px 100px [area-start]) [area-start] 100px [area-end];
}
.grid > div {
grid-area: area;
background: green;
}
</style>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div class="grid">
<div></div>
</div>
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