LibWeb: Fix grid placement when using unresolved named grid lines

This patch fixes an issue where grid items using `grid-area: <name>`
with no matching named grid area or lines would be incorrectly placed
at position 0.

According to https://www.w3.org/TR/css-grid-1/#line-placement:
1. When a `<custom-ident>` doesn't match any named line, placement
   should fall back to the first implicit grid line
2. When the same `<custom-ident>` is given for both `grid-*-start` and
   `grid-*-end` (which happens with `grid-area: name`), and both fall
   back to the same implicit line, the resulting span is 1

Previously, the fallback values were hardcoded to 0 and 1, which placed
items in track 0. The fix changes the fallback to use
`m_explicit_line_count` (the first implicit line index) for both start
and end identifiers. When both reference the same line (start == end),
the existing "both positioned" logic now handles this by setting span=1
and adjusting end accordingly.
This commit is contained in:
Aliaksandr Kalenik
2026-01-02 20:55:28 +01:00
committed by Alexander Kalenik
parent 64010c78ab
commit f1253c7139
Notes: github-actions[bot] 2026-01-03 15:43:33 +00:00
4 changed files with 69 additions and 3 deletions

View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: Grid item placement with non-inherited grid-template-areas</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="../../../../../expected/wpt-import/css/css-grid/placement/../../reference/ref-filled-green-100px-square.xht">
<meta name="assert" content="Checks that inheriting grid-template-columns and grid-template-rows doesn't also inherit grid-template-areas.">
<style>
.wrapper {
grid-template-areas: "area";
}
.grid {
display: grid;
width: 100px;
height: 100px;
grid-auto-columns: 0px 100%;
grid-auto-rows: 0px 100%;
grid-template-columns: inherit;
grid-template-rows: inherit;
background: red;
}
.item {
grid-area: area;
background: green;
}
</style>
<p>Test passes if there is a filled green square and <strong>no red</strong>.</p>
<div class="wrapper">
<div class="grid">
<div class="item"></div>
</div>
</div>