Commit 92034a4d authored by Oriol Brufau's avatar Oriol Brufau Committed by Commit Bot

[css-grid] Fix grid placement with '<integer> && <custom-ident>'

The logic for placing a grid item with both an integer and an identifier
in a placement property was interacting wrong with auto repeat() tracks.

This patch uses the same proper logic that was already implemented in
OrderedNamedLinesCollectorInGridLayout::CollectLineNamesForIndex

BUG=966090

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

Change-Id: I042ce1fd77a79959240d272d96eac21f06e014ac
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082917Reviewed-by: default avatarJavier Fernandez <jfernandez@igalia.com>
Commit-Queue: Oriol Brufau <obrufau@igalia.com>
Cr-Commit-Position: refs/heads/master@{#747631}
parent 54c09d3f
...@@ -63,44 +63,42 @@ bool NamedLineCollection::HasNamedLines() { ...@@ -63,44 +63,42 @@ bool NamedLineCollection::HasNamedLines() {
return named_lines_indexes_ || auto_repeat_named_lines_indexes_; return named_lines_indexes_ || auto_repeat_named_lines_indexes_;
} }
size_t NamedLineCollection::Find(size_t line) { bool NamedLineCollection::Contains(size_t line) {
CHECK(HasNamedLines());
if (line > last_line_) if (line > last_line_)
return kNotFound; return false;
if (!auto_repeat_named_lines_indexes_ || line < insertion_point_) auto find = [](const Vector<size_t>* indexes, size_t line) {
return named_lines_indexes_ ? named_lines_indexes_->Find(line) : kNotFound; return indexes && indexes->Find(line) != kNotFound;
};
if (line <= (insertion_point_ + auto_repeat_total_tracks_)) {
size_t local_index = line - insertion_point_; if (auto_repeat_track_list_length_ == 0LU || line < insertion_point_)
return find(named_lines_indexes_, line);
size_t index_in_first_repetition =
local_index % auto_repeat_track_list_length_; DCHECK(auto_repeat_total_tracks_);
if (index_in_first_repetition)
return auto_repeat_named_lines_indexes_->Find(index_in_first_repetition); if (line > insertion_point_ + auto_repeat_total_tracks_)
return find(named_lines_indexes_, line - (auto_repeat_total_tracks_ - 1));
// The line names defined in the last line are also present in the first
// line of the next repetition (if any). Same for the line names defined in if (line == insertion_point_) {
// the first line. return find(named_lines_indexes_, line) ||
if (local_index == auto_repeat_total_tracks_) find(auto_repeat_named_lines_indexes_, 0);
return auto_repeat_named_lines_indexes_->Find(
auto_repeat_track_list_length_);
size_t position =
auto_repeat_named_lines_indexes_->Find(static_cast<size_t>(0));
if (position != kNotFound)
return position;
return local_index == 0 ? kNotFound
: auto_repeat_named_lines_indexes_->Find(
auto_repeat_track_list_length_);
} }
return named_lines_indexes_ ? named_lines_indexes_->Find( if (line == insertion_point_ + auto_repeat_total_tracks_) {
line - (auto_repeat_total_tracks_ - 1)) return find(auto_repeat_named_lines_indexes_,
: kNotFound; auto_repeat_track_list_length_) ||
} find(named_lines_indexes_, insertion_point_ + 1);
}
bool NamedLineCollection::Contains(size_t line) { size_t auto_repeat_index_in_first_repetition =
CHECK(HasNamedLines()); (line - insertion_point_) % auto_repeat_track_list_length_;
return Find(line) != kNotFound; if (!auto_repeat_index_in_first_repetition &&
find(auto_repeat_named_lines_indexes_, auto_repeat_track_list_length_))
return true;
return find(auto_repeat_named_lines_indexes_,
auto_repeat_index_in_first_repetition);
} }
size_t NamedLineCollection::FirstPosition() { size_t NamedLineCollection::FirstPosition() {
......
...@@ -38,7 +38,6 @@ class NamedLineCollection { ...@@ -38,7 +38,6 @@ class NamedLineCollection {
bool Contains(size_t line); bool Contains(size_t line);
private: private:
size_t Find(size_t line);
const Vector<size_t>* named_lines_indexes_ = nullptr; const Vector<size_t>* named_lines_indexes_ = nullptr;
const Vector<size_t>* auto_repeat_named_lines_indexes_ = nullptr; const Vector<size_t>* auto_repeat_named_lines_indexes_ = nullptr;
......
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Grid item placement with '&lt;integer&gt; && &lt;custom-ident&gt;' 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 using the '<integer> && <custom-ident>' syntax and there is an auto repeat().">
<style>
.grid {
display: grid;
width: 300px;
height: 300px;
grid-template-columns: [foo] repeat(auto-fill, 100px [foo]);
grid-template-rows: repeat(auto-fill, [foo] 100px);
}
.grid > div {
grid-area: 1 foo / 1 foo;
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