\ No newline at end of file
diff --git a/Tests/LibWeb/Layout/input/grid/template-areas-2.html b/Tests/LibWeb/Layout/input/grid/template-areas-2.html
new file mode 100644
index 0000000000..dcc0aafbb8
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/template-areas-2.html
@@ -0,0 +1,22 @@
+
a
b
\ No newline at end of file
diff --git a/Tests/LibWeb/Layout/input/grid/template-areas-3.html b/Tests/LibWeb/Layout/input/grid/template-areas-3.html
new file mode 100644
index 0000000000..8d1e81e6e3
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/template-areas-3.html
@@ -0,0 +1,33 @@
+
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
index 9da529b99c..bd8d940c49 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
@@ -1323,33 +1323,35 @@ void GridFormattingContext::build_grid_areas()
// https://www.w3.org/TR/css-grid-2/#grid-template-areas-property
// If a named grid area spans multiple grid cells, but those cells do not form a single
// filled-in rectangle, the declaration is invalid.
- for (size_t y = 0; y < grid_container().computed_values().grid_template_areas().size(); y++) {
- for (size_t x = 0; x < grid_container().computed_values().grid_template_areas()[y].size(); x++) {
- auto grid_area_name = grid_container().computed_values().grid_template_areas()[y][x];
- auto maybe_grid_area = m_grid_areas.get(grid_area_name);
- if (!maybe_grid_area.has_value()) {
- m_grid_areas.set(grid_area_name, { grid_area_name, y, y + 1, x, x + 1 });
- } else {
- auto& grid_area = maybe_grid_area.value();
- if (grid_area.row_start == y) {
- if (grid_area.column_end == x)
- grid_area.column_end = grid_area.column_end + 1;
- else
- return;
- } else {
- if (grid_area.row_end == y) {
- if (grid_area.column_start != x)
- return;
- grid_area.row_end = grid_area.row_end + 1;
- } else if (grid_area.row_end == y + 1) {
- if (grid_area.column_end < x || grid_area.column_end > x + 1)
- return;
- } else {
- return;
- }
+ auto const& rows = grid_container().computed_values().grid_template_areas();
+
+ auto find_area_rectangle = [&](size_t x_start, size_t y_start, String const& name) {
+ bool invalid = false;
+ size_t x_end = x_start;
+ size_t y_end = y_start;
+ while (x_end < rows[y_start].size() && rows[y_start][x_end] == name)
+ x_end++;
+ while (y_end < rows.size() && rows[y_end][x_start] == name)
+ y_end++;
+ for (size_t y = y_start; y < y_end; y++) {
+ for (size_t x = x_start; x < x_end; x++) {
+ if (rows[y][x] != name) {
+ // If a named grid area spans multiple grid cells, but those cells do not form a single filled-in rectangle, the declaration is invalid.
+ invalid = true;
+ break;
}
}
}
+ m_grid_areas.set(name, { name, y_start, y_end, x_start, x_end, invalid });
+ };
+
+ for (size_t y = 0; y < rows.size(); y++) {
+ for (size_t x = 0; x < rows[y].size(); x++) {
+ auto name = rows[y][x];
+ if (auto grid_area = m_grid_areas.get(name); grid_area.has_value())
+ continue;
+ find_area_rectangle(x, y, name);
+ }
}
}
diff --git a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
index bf57e4ca03..3b67325e3d 100644
--- a/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/GridFormattingContext.h
@@ -142,6 +142,7 @@ private:
size_t row_end { 1 };
size_t column_start { 0 };
size_t column_end { 1 };
+ bool invalid { false }; /* FIXME: Ignore ignore invalid areas during layout */
};
HashMap
m_grid_areas;