Skip to content

Truly independent web browser

LibWeb: Resolve grid line placement as the spec describes

Andreas Klingc07449bd0588
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index d412c380539..b437f67e4cf 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -414,111 +414,178 @@ fn is_span(placement: ComputedGridPlacement) -> bool {
}
fn clamped_line_number(placement: ComputedGridPlacement) -> Option<i32> {
- placement
- .has_line_number
- .then(|| placement.line_number.clamp(-MAX_GRID_LINE_NUMBER, MAX_GRID_LINE_NUMBER))
+ placement.has_line_number.then(|| match placement.line_number {
+ // AD-HOC: A calc() that resolves to 0 is not rejected at parse time as a literal 0 is, but no grid line has the
+ // number 0. Treat it as 1.
+ 0 => 1,
+ number => number.clamp(-MAX_GRID_LINE_NUMBER, MAX_GRID_LINE_NUMBER),
+ })
}
fn clamped_span(placement: ComputedGridPlacement) -> usize {
placement.line_number.clamp(1, MAX_GRID_LINE_NUMBER) as usize
}
-/// Resolves one axis exactly as `GridFormattingContext::resolve_grid_position`.
-/// Names are pre-interned in F1, including the area `-start`/`-end` aliases.
-pub(crate) fn resolve_placement_position(
- placement_start: ComputedGridPlacement,
- placement_end: ComputedGridPlacement,
- placement_names: &[usize],
- lines: &[Vec<LineName>],
- explicit_line_count: usize,
- occupation_track_count: usize,
-) -> ResolvedPlacementPosition {
- let start_line_number = clamped_line_number(placement_start);
- let end_line_number = clamped_line_number(placement_end);
- let mut result = ResolvedPlacementPosition {
- start: 0,
- end: 0,
- span: 1,
- };
+/// The lines of one axis that carry names a placement can refer to: the explicit grid's lines, the first of which is
+/// line 0. Every implicit line, before or after them, is assumed to have every name.
+#[derive(Clone, Copy)]
+pub(crate) struct ExplicitGridLines<'a> {
+ lines: &'a [Vec<LineName>],
+}
- if let Some(number) = start_line_number {
- result.start = if number > 0 {
- number - 1
- } else {
- explicit_line_count as i32 + number
- };
- }
- if let Some(number) = end_line_number {
- result.end = number - 1;
- }
- if result.end < 0 {
- result.end = occupation_track_count as i32 + result.end + 2;
+impl<'a> ExplicitGridLines<'a> {
+ pub(crate) fn new(lines: &'a [Vec<LineName>]) -> Self {
+ Self { lines }
}
- // FIXME: If a name is given as a <custom-ident>, only lines with that name are counted. If not enough lines with
- // that name exist, all implicit grid lines on the side of the explicit grid corresponding to the search
- // direction are assumed to have that name for the purpose of counting this span.
- if is_span(placement_end) {
- result.span = clamped_span(placement_end);
- }
- if is_span(placement_start) {
- result.span = clamped_span(placement_start);
- result.start = result.end - result.span as i32;
- // FIXME: Remove me once have implemented spans overflowing into negative indexes, e.g., grid-row: span 2 / 1
- result.start = result.start.max(0);
+ fn last_line(self) -> i32 {
+ self.lines.len() as i32 - 1
}
- if placement_end.has_name {
- let number = end_line_number.unwrap_or(1);
- result.end = placement_names
- .get(placement_end.implicit_end_name_index as usize)
- .and_then(|name| nth_named_line(lines, *name, number))
- .or_else(|| {
- placement_names
- .get(placement_end.name_index as usize)
- .and_then(|name| nth_named_line(lines, *name, number))
- })
- .unwrap_or(explicit_line_count as i32);
- if !placement_start.has_line_number {
- result.start = result.end - 1;
+ fn lines_named(self, name_raw: usize) -> impl DoubleEndedIterator<Item = i32> + 'a {
+ self.lines
+ .iter()
+ .enumerate()
+ .filter(move |(_, names)| names.iter().any(|name| name.raw == name_raw))
+ .map(|(index, _)| index as i32)
+ }
+
+ // https://drafts.csswg.org/css-grid-2/#grid-placement-int
+ // Contributes the Nth grid line to the grid item’s placement. If a negative integer is given, it instead counts in
+ // reverse, starting from the end edge of the explicit grid. If a name is given as a <custom-ident>, only lines
+ // with that name are counted. If not enough lines with that name exist, all implicit grid lines are assumed to
+ // have that name for the purpose of finding this position.
+ fn nth_line(self, n: i32, name_raw: Option<usize>) -> i32 {
+ let Some(name_raw) = name_raw else {
+ return if n > 0 { n - 1 } else { self.last_line() + 1 + n };
+ };
+ let wanted = n.unsigned_abs() as usize;
+ let named: Vec<i32> = self.lines_named(name_raw).collect();
+ if n > 0 {
+ named
+ .get(wanted - 1)
+ .copied()
+ .unwrap_or_else(|| self.last_line().saturating_add((wanted - named.len()) as i32))
+ } else {
+ named
+ .len()
+ .checked_sub(wanted)
+ .map(|index| named[index])
+ .unwrap_or_else(|| -((wanted - named.len()) as i32))
+ }
+ }
+
+ // https://drafts.csswg.org/css-grid-2/#grid-placement-span-int
+ // Contributes a grid span to the grid item’s placement such that the corresponding edge of the grid item’s grid
+ // area is N lines from its opposite edge in the corresponding direction. [...] If a name is given as a
+ // <custom-ident>, only lines with that name are counted. If not enough lines with that name exist, all implicit
+ // grid lines on the side of the explicit grid corresponding to the search direction are assumed to have that name
+ // for the purpose of counting this span.
+ fn line_spanned_from(self, from: i32, n: usize, name_raw: Option<usize>, endward: bool) -> i32 {
+ let n = n.min(MAX_GRID_LINE_NUMBER as usize) as i32;
+ let Some(name_raw) = name_raw else {
+ return if endward {
+ from.saturating_add(n)
+ } else {
+ from.saturating_sub(n)
+ };
+ };
+ let candidates: Vec<i32> = if endward {
+ self.lines_named(name_raw).filter(|&line| line > from).collect()
+ } else {
+ self.lines_named(name_raw).rev().filter(|&line| line < from).collect()
+ };
+ if let Some(&line) = candidates.get(n as usize - 1) {
+ return line;
+ }
+ let missing = n - candidates.len() as i32;
+ if endward {
+ from.max(self.last_line()).saturating_add(missing)
+ } else {
+ from.min(0).saturating_sub(missing)
}
}
- if placement_start.has_name {
- let number = start_line_number.unwrap_or(1);
- result.start = placement_names
- .get(placement_start.implicit_start_name_index as usize)
- .and_then(|name| nth_named_line(lines, *name, number))
- .or_else(|| {
- placement_names
- .get(placement_start.name_index as usize)
- .and_then(|name| nth_named_line(lines, *name, number))
- })
- .unwrap_or(explicit_line_count as i32);
- }
-
- if !is_positioned(placement_start) && is_positioned(placement_end) && !is_span(placement_end) {
- result.start = result.end - result.span as i32;
+ fn resolve_line(self, placement: ComputedGridPlacement, placement_names: &[usize], is_start: bool) -> i32 {
+ let name = placement
+ .has_name
+ .then(|| placement_names.get(placement.name_index as usize).copied())
+ .flatten();
+ let Some(n) = clamped_line_number(placement) else {
+ // https://drafts.csswg.org/css-grid-2/#grid-placement-slot
+ // First attempt to match the grid area’s edge to a named grid area: if there is a grid line whose line name
+ // is <custom-ident>-start (for grid-*-start) / <custom-ident>-end (for grid-*-end), contributes the first
+ // such line to the grid item’s placement.
+ let area_edge_name = placement_names
+ .get(if is_start {
+ placement.implicit_start_name_index
+ } else {
+ placement.implicit_end_name_index
+ } as usize)
+ .copied();
+ if let Some(line) = area_edge_name.and_then(|name| self.lines_named(name).next()) {
+ return line;
+ }
+ // Otherwise, treat this as if the integer 1 had been specified along with the <custom-ident>.
+ return self.nth_line(1, name);
+ };
+ self.nth_line(n, name)
}
+}
- if is_positioned(placement_start) && is_positioned(placement_end) {
- if result.start > result.end {
- std::mem::swap(&mut result.start, &mut result.end);
- }
- if result.start != result.end {
- result.span = (result.end - result.start) as usize;
+/// Resolves the placement of one axis in which at least one of the placement properties is a line, to lines
+/// numbered from the explicit grid's first line, which is line 0. `automatic_span` is the automatic grid span used when
+/// only one of the placement properties is a line, which is 1 unless the item is subgridded in this axis.
+pub(crate) fn resolve_placement_position(
+ placement_start: ComputedGridPlacement,
+ placement_end: ComputedGridPlacement,
+ placement_names: &[usize],
+ lines: ExplicitGridLines<'_>,
+ automatic_span: Option<usize>,
+) -> ResolvedPlacementPosition {
+ let automatic_span = automatic_span.unwrap_or(1).max(1) as i32;
+ let span_name = |placement: ComputedGridPlacement| {
+ placement
+ .has_name
+ .then(|| placement_names.get(placement.name_index as usize).copied())
+ .flatten()
+ };
+ let (mut start, mut end) = if is_positioned(placement_start) {
+ let start = lines.resolve_line(placement_start, placement_names, true);
+ let end = if is_positioned(placement_end) {
+ lines.resolve_line(placement_end, placement_names, false)
+ } else if is_span(placement_end) {
+ lines.line_spanned_from(start, clamped_span(placement_end), span_name(placement_end), true)
} else {
- result.span = 1;
- result.end = result.start + 1;
- }
- }
-
- // If the placement contains two spans, remove the one contributed by the end grid-placement
- // property.
- if is_span(placement_start) && is_span(placement_end) {
- result.span = clamped_span(placement_start);
+ start.saturating_add(automatic_span)
+ };
+ (start, end)
+ } else {
+ let end = lines.resolve_line(placement_end, placement_names, false);
+ let start = if is_span(placement_start) {
+ lines.line_spanned_from(end, clamped_span(placement_start), span_name(placement_start), false)
+ } else {
+ end.saturating_sub(automatic_span)
+ };
+ (start, end)
+ };
+ // https://drafts.csswg.org/css-grid-2/#grid-placement-errors
+ // If the placement for a grid item contains two lines, and the start line is further end-ward than the end line,
+ // swap the two lines. If the start line is equal to the end line, remove the end line.
+ if start > end {
+ std::mem::swap(&mut start, &mut end);
+ }
+ if start == end {
+ end = start.saturating_add(1);
+ }
+ // https://drafts.csswg.org/css-grid/#overlarge-grids
+ start = start.clamp(-MAX_GRID_LINE_NUMBER, MAX_GRID_LINE_NUMBER - 1);
+ end = end.clamp(start + 1, MAX_GRID_LINE_NUMBER);
+ ResolvedPlacementPosition {
+ start,
+ end,
+ span: (end - start) as usize,
}
- result
}
pub(crate) fn resolve_placement_span(
@@ -526,11 +593,18 @@ pub(crate) fn resolve_placement_span(
placement_end: ComputedGridPlacement,
automatic_subgrid_span: Option<usize>,
) -> usize {
- if is_span(placement_start) {
- return clamped_span(placement_start);
- }
- if is_span(placement_end) {
- return clamped_span(placement_end);
+ // https://drafts.csswg.org/css-grid-2/#grid-placement-errors
+ // If the placement contains two spans, remove the one contributed by the end grid-placement property.
+ // If the placement contains only a span for a named line, replace it with a span of 1.
+ let span = if is_span(placement_start) {
+ Some(placement_start)
+ } else if is_span(placement_end) {
+ Some(placement_end)
+ } else {
+ None
+ };
+ if let Some(span) = span {
+ return if span.has_name { 1 } else { clamped_span(span) };
}
if !(is_positioned(placement_start) && is_positioned(placement_end))
&& let Some(span) = automatic_subgrid_span
@@ -1537,16 +1611,19 @@ impl<'pass> GridFormattingContext<'pass> {
) -> ResolvedAxisPlacement {
let start_is_auto = start.kind != crate::layout::ComputedGridPlacementKind::Line as u8;
let end_is_auto = end.kind != crate::layout::ComputedGridPlacementKind::Line as u8;
- let lines = self.axis_lines(axis);
- let explicit_lines = self.explicit_line_count(axis);
- let explicit_tracks = lines.len().saturating_sub(1);
if start_is_auto && end_is_auto {
return ResolvedAxisPlacement {
start: None,
span: resolve_placement_span(start, end, automatic_subgrid_span_value),
};
}
- let resolved = resolve_placement_position(start, end, placement_names, lines, explicit_lines, explicit_tracks);
+ let resolved = resolve_placement_position(
+ start,
+ end,
+ placement_names,
+ self.explicit_grid_lines(axis),
+ automatic_subgrid_span_value,
+ );
ResolvedAxisPlacement {
start: Some(resolved.start),
span: resolved.span,
@@ -1872,6 +1949,18 @@ impl<'pass> GridFormattingContext<'pass> {
axis.select(self.explicit_column_line_count, self.explicit_row_line_count)
}
+ fn explicit_start(&self, axis: Axis) -> usize {
+ axis.select(self.explicit_column_start, self.explicit_row_start)
+ }
+
+ /// The explicit grid's lines, which come after the implicit lines that items placed before it add.
+ fn explicit_grid_lines(&self, axis: Axis) -> ExplicitGridLines<'_> {
+ let lines = self.axis_lines(axis);
+ let start = self.explicit_start(axis).min(lines.len());
+ let end = start.saturating_add(self.explicit_line_count(axis)).min(lines.len());
+ ExplicitGridLines::new(&lines[start..end])
+ }
+
fn content_alignment(&self, axis: Axis) -> Alignment {
let style = self.style(self.run.box_);
let alignment = axis.select(
@@ -3631,29 +3720,34 @@ impl<'pass> GridFormattingContext<'pass> {
end: ComputedGridPlacement,
placement_names: &[usize],
) -> (CssPixels, CssPixels) {
- let lines = self.axis_lines(axis);
- let explicit_lines = self.explicit_line_count(axis);
- let resolved = resolve_placement_position(
- start,
- end,
- placement_names,
- lines,
- explicit_lines,
- lines.len().saturating_sub(1),
- );
- let is_auto_positioned =
- |placement: ComputedGridPlacement| placement.kind != crate::layout::ComputedGridPlacementKind::Line as u8;
- let mut rect = self.axis_grid_area(
- axis,
- (!(is_auto_positioned(start) && is_auto_positioned(end))).then_some((resolved.start, resolved.span)),
- );
-
- let start_is_augmented =
- is_auto_positioned(start) && end.kind == crate::layout::ComputedGridPlacementKind::Line as u8;
- let end_is_augmented =
- is_auto_positioned(end) && start.kind == crate::layout::ComputedGridPlacementKind::Line as u8;
- if !start_is_augmented && !end_is_augmented {
- return rect;
+ let is_line = |placement: ComputedGridPlacement| is_positioned(placement);
+ if !is_line(start) && !is_line(end) {
+ return self.axis_grid_area(axis, None);
+ }
+ let resolved = resolve_placement_position(start, end, placement_names, self.explicit_grid_lines(axis), None);
+ // https://drafts.csswg.org/css-grid-2/#abspos-items
+ // If a grid-placement property refers to a non-existent line either by explicitly specifying such a line or by
+ // spanning outside of the existing implicit grid, it is instead treated as specifying auto (instead of
+ // creating new implicit grid lines).
+ let line_count = self.axis_lines(axis).len() as i32;
+ let existing_line = |line: i32| {
+ let line = line.saturating_add(self.explicit_start(axis) as i32);
+ (0..line_count).contains(&line).then_some(line)
+ };
+ let start_line = if is_line(start) || is_line(end) && is_span(start) {
+ existing_line(resolved.start)
+ } else {
+ None
+ };
+ let end_line = if is_line(end) || is_line(start) && is_span(end) {
+ existing_line(resolved.end)
+ } else {
+ None
+ };
+ if let (Some(start_line), Some(end_line)) = (start_line, end_line)
+ && start_line < self.axis_tracks(axis).len() as i32
+ {
+ return self.axis_grid_area(axis, Some((start_line, (end_line - start_line) as usize)));
}
// Instead of auto-placement, an auto value for a grid-placement property contributes a special line to the placement whose position
@@ -3691,18 +3785,9 @@ impl<'pass> GridFormattingContext<'pass> {
offset
}
};
- let start_offset = if start_is_augmented {
- augmented_edge(true)
- } else {
- explicit_line_position(resolved.start, false)
- };
- let end_offset = if end_is_augmented {
- augmented_edge(false)
- } else {
- explicit_line_position(resolved.end, true)
- };
- rect = (start_offset, end_offset - start_offset);
- rect
+ let start_offset = start_line.map_or_else(|| augmented_edge(true), |line| explicit_line_position(line, false));
+ let end_offset = end_line.map_or_else(|| augmented_edge(false), |line| explicit_line_position(line, true));
+ (start_offset, end_offset - start_offset)
}
fn layout_items(&mut self, run: &FormattingContextRun<'pass>) {
@@ -5286,31 +5371,6 @@ pub(crate) fn add_template_area_lines(
}
}
-pub(crate) fn nth_named_line(lines: &[Vec<LineName>], name_raw: usize, nth_line: i32) -> Option<i32> {
- // FIXME: If not enough lines with the name exist, all implicit grid lines on the side
- // of the explicit grid corresponding to the search direction are assumed to have that name for the purpose of counting this span.
- // Source: https://drafts.csswg.org/css-grid/#line-placement
- let mut remaining = if nth_line < 0 {
- lines.len().wrapping_add_signed(nth_line as isize)
- } else {
- nth_line.saturating_sub(1) as usize
- };
- for (line_index, names) in lines.iter().enumerate() {
- for name in names {
- if name.raw != name_raw {
- continue;
- }
- if remaining == 0 {
- // https://drafts.csswg.org/css-grid/#line-placement
- // Contributes the nth grid line to the grid item’s placement.
- return Some(line_index as i32);
- }
- remaining = remaining.wrapping_sub(1);
- }
- }
- None
-}
-
#[derive(Clone, Copy, Debug)]
pub(crate) enum TrackSizingFunction<'pass> {
Auto,
diff --git a/Tests/LibWeb/Crash/Layout/grid-line-number-calc-zero.html b/Tests/LibWeb/Crash/Layout/grid-line-number-calc-zero.html
new file mode 100644
index 00000000000..84851b4a2da
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/grid-line-number-calc-zero.html
@@ -0,0 +1,9 @@
+<!DOCTYPE html>
+<div style="display: grid; grid-template-columns: [a] 10px [a] 10px [a];">
+ <div style="grid-column: calc(1 - 1) a;"></div>
+ <div style="grid-row: calc(1 - 1) a / calc(2 - 2) b;"></div>
+ <div style="grid-column: calc(1 - 1);"></div>
+</div>
+<div style="display: grid; position: relative;">
+ <div style="position: absolute; grid-column: calc(1 - 1) a;"></div>
+</div>
diff --git a/Tests/LibWeb/Text/expected/css/subgrid-automatic-span-with-one-definite-line.txt b/Tests/LibWeb/Text/expected/css/subgrid-automatic-span-with-one-definite-line.txt
new file mode 100644
index 00000000000..2cd7faff56e
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/subgrid-automatic-span-with-one-definite-line.txt
@@ -0,0 +1,4 @@
+start: x=50 width=100
+start-auto: x=50 width=100
+end: x=100 width=100
+explicit-span: x=50 width=100
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/absolute-positioning-grid-container-containing-block-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/absolute-positioning-grid-container-containing-block-001.txt
index 771dfb7973f..2142b403e3b 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/absolute-positioning-grid-container-containing-block-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/absolute-positioning-grid-container-containing-block-001.txt
@@ -2,15 +2,15 @@ Harness status: OK
Found 10 tests
-2 Pass
-8 Fail
-Fail .grid 1
-Fail .grid 2
+8 Pass
+2 Fail
+Pass .grid 1
+Pass .grid 2
Pass .grid 3
-Fail .grid 4
-Fail .grid 5
-Fail .grid 6
-Fail .grid 7
+Pass .grid 4
+Pass .grid 5
+Pass .grid 6
+Pass .grid 7
Pass .grid 8
Fail .grid 9
Fail .grid 10
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-001.txt
index ed228f48932..e5a4fd18460 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-001.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 44 tests
-20 Pass
-24 Fail
+44 Pass
Pass .grid 1
Pass .grid 2
Pass .grid 3
@@ -12,39 +11,39 @@ Pass .grid 5
Pass .grid 6
Pass .grid 7
Pass .grid 8
-Fail .grid 9
-Fail .grid 10
-Fail .grid 11
-Fail .grid 12
-Fail .grid 13
-Fail .grid 14
+Pass .grid 9
+Pass .grid 10
+Pass .grid 11
+Pass .grid 12
+Pass .grid 13
+Pass .grid 14
Pass .grid 15
Pass .grid 16
Pass .grid 17
Pass .grid 18
-Fail .grid 19
-Fail .grid 20
-Fail .grid 21
-Fail .grid 22
-Fail .grid 23
-Fail .grid 24
+Pass .grid 19
+Pass .grid 20
+Pass .grid 21
+Pass .grid 22
+Pass .grid 23
+Pass .grid 24
Pass .grid 25
Pass .grid 26
-Fail .grid 27
-Fail .grid 28
-Fail .grid 29
-Fail .grid 30
-Fail .grid 31
-Fail .grid 32
+Pass .grid 27
+Pass .grid 28
+Pass .grid 29
+Pass .grid 30
+Pass .grid 31
+Pass .grid 32
Pass .grid 33
Pass .grid 34
Pass .grid 35
Pass .grid 36
Pass .grid 37
Pass .grid 38
-Fail .grid 39
-Fail .grid 40
-Fail .grid 41
-Fail .grid 42
-Fail .grid 43
-Fail .grid 44
\ No newline at end of file
+Pass .grid 39
+Pass .grid 40
+Pass .grid 41
+Pass .grid 42
+Pass .grid 43
+Pass .grid 44
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-rtl-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-rtl-001.txt
index ed228f48932..e5a4fd18460 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-rtl-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-gaps-rtl-001.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 44 tests
-20 Pass
-24 Fail
+44 Pass
Pass .grid 1
Pass .grid 2
Pass .grid 3
@@ -12,39 +11,39 @@ Pass .grid 5
Pass .grid 6
Pass .grid 7
Pass .grid 8
-Fail .grid 9
-Fail .grid 10
-Fail .grid 11
-Fail .grid 12
-Fail .grid 13
-Fail .grid 14
+Pass .grid 9
+Pass .grid 10
+Pass .grid 11
+Pass .grid 12
+Pass .grid 13
+Pass .grid 14
Pass .grid 15
Pass .grid 16
Pass .grid 17
Pass .grid 18
-Fail .grid 19
-Fail .grid 20
-Fail .grid 21
-Fail .grid 22
-Fail .grid 23
-Fail .grid 24
+Pass .grid 19
+Pass .grid 20
+Pass .grid 21
+Pass .grid 22
+Pass .grid 23
+Pass .grid 24
Pass .grid 25
Pass .grid 26
-Fail .grid 27
-Fail .grid 28
-Fail .grid 29
-Fail .grid 30
-Fail .grid 31
-Fail .grid 32
+Pass .grid 27
+Pass .grid 28
+Pass .grid 29
+Pass .grid 30
+Pass .grid 31
+Pass .grid 32
Pass .grid 33
Pass .grid 34
Pass .grid 35
Pass .grid 36
Pass .grid 37
Pass .grid 38
-Fail .grid 39
-Fail .grid 40
-Fail .grid 41
-Fail .grid 42
-Fail .grid 43
-Fail .grid 44
\ No newline at end of file
+Pass .grid 39
+Pass .grid 40
+Pass .grid 41
+Pass .grid 42
+Pass .grid 43
+Pass .grid 44
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-padding-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-padding-001.txt
index d368de84432..5f0a1974d84 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-padding-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-padding-001.txt
@@ -2,16 +2,15 @@ Harness status: OK
Found 12 tests
-8 Pass
-4 Fail
+12 Pass
Pass .grid 1
-Fail .grid 2
+Pass .grid 2
Pass .grid 3
-Fail .grid 4
+Pass .grid 4
Pass .grid 5
-Fail .grid 6
+Pass .grid 6
Pass .grid 7
-Fail .grid 8
+Pass .grid 8
Pass .grid 9
Pass .grid 10
Pass .grid 11
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-within-grid-implicit-track-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-within-grid-implicit-track-001.txt
index 52a99216035..c6739d3d5d5 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-within-grid-implicit-track-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/abspos/grid-positioned-items-within-grid-implicit-track-001.txt
@@ -2,20 +2,20 @@ Harness status: OK
Found 16 tests
-16 Fail
-Fail .grid 1
-Fail .grid 2
-Fail .grid 3
-Fail .grid 4
-Fail .grid 5
-Fail .grid 6
-Fail .grid 7
-Fail .grid 8
-Fail .grid 9
-Fail .grid 10
-Fail .grid 11
-Fail .grid 12
-Fail .grid 13
-Fail .grid 14
-Fail .grid 15
-Fail .grid 16
\ No newline at end of file
+16 Pass
+Pass .grid 1
+Pass .grid 2
+Pass .grid 3
+Pass .grid 4
+Pass .grid 5
+Pass .grid 6
+Pass .grid 7
+Pass .grid 8
+Pass .grid 9
+Pass .grid 10
+Pass .grid 11
+Pass .grid 12
+Pass .grid 13
+Pass .grid 14
+Pass .grid 15
+Pass .grid 16
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-auto-placement-automatic-span-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-auto-placement-automatic-span-001.txt
index 48fc4d7c82b..6b72c1369bf 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-auto-placement-automatic-span-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-auto-placement-automatic-span-001.txt
@@ -2,16 +2,16 @@ Harness status: OK
Found 16 tests
-10 Pass
-6 Fail
+12 Pass
+4 Fail
Pass .grid 1
Pass .grid 2
Pass .grid 3
Pass .grid 4
Pass .grid 5
Pass .grid 6
-Fail .grid 7
-Fail .grid 8
+Pass .grid 7
+Pass .grid 8
Pass .grid 9
Pass .grid 10
Fail .grid 11
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-dynamic-change-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-dynamic-change-001.txt
index c73b15f76f0..370657afa01 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-dynamic-change-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-dynamic-change-001.txt
@@ -2,8 +2,7 @@ Harness status: OK
Found 88 tests
-69 Pass
-19 Fail
+88 Pass
Pass .grid 1
Pass .grid 2
Pass .grid 3
@@ -29,13 +28,13 @@ Pass .grid 22
Pass .grid 23
Pass .grid 24
Pass .grid 25
-Fail .grid 26
-Fail .grid 27
+Pass .grid 26
+Pass .grid 27
Pass .grid 28
-Fail .grid 29
+Pass .grid 29
Pass .grid 30
Pass .grid 31
-Fail .grid 32
+Pass .grid 32
Pass .grid 33
Pass .grid 34
Pass .grid 35
@@ -67,28 +66,28 @@ Pass .grid 60
Pass .grid 61
Pass .grid 62
Pass .grid 63
-Fail .grid 64
-Fail .grid 65
+Pass .grid 64
+Pass .grid 65
Pass .grid 66
-Fail .grid 67
-Fail .grid 68
+Pass .grid 67
+Pass .grid 68
Pass .grid 69
Pass .grid 70
Pass .grid 71
Pass .grid 72
-Fail .grid 73
+Pass .grid 73
Pass .grid 74
-Fail .grid 75
-Fail .grid 76
+Pass .grid 75
+Pass .grid 76
Pass .grid 77
-Fail .grid 78
+Pass .grid 78
Pass .grid 79
-Fail .grid 80
+Pass .grid 80
Pass .grid 81
-Fail .grid 82
-Fail .grid 83
+Pass .grid 82
+Pass .grid 83
Pass .grid 84
-Fail .grid 85
-Fail .grid 86
-Fail .grid 87
-Fail .grid 88
\ No newline at end of file
+Pass .grid 85
+Pass .grid 86
+Pass .grid 87
+Pass .grid 88
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-unknown-named-grid-line-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-unknown-named-grid-line-001.txt
index 790d75c2300..dddef28aeb0 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-unknown-named-grid-line-001.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-grid/placement/grid-placement-unknown-named-grid-line-001.txt
@@ -2,22 +2,21 @@ Harness status: OK
Found 17 tests
-2 Pass
-15 Fail
+17 Pass
Pass .grid 1
Pass .grid 2
-Fail .grid 3
-Fail .grid 4
-Fail .grid 5
-Fail .grid 6
-Fail .grid 7
-Fail .grid 8
-Fail .grid 9
-Fail .grid 10
-Fail .grid 11
-Fail .grid 12
-Fail .grid 13
-Fail .grid 14
-Fail .grid 15
-Fail .grid 16
-Fail .grid 17
\ No newline at end of file
+Pass .grid 3
+Pass .grid 4
+Pass .grid 5
+Pass .grid 6
+Pass .grid 7
+Pass .grid 8
+Pass .grid 9
+Pass .grid 10
+Pass .grid 11
+Pass .grid 12
+Pass .grid 13
+Pass .grid 14
+Pass .grid 15
+Pass .grid 16
+Pass .grid 17
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/css/subgrid-automatic-span-with-one-definite-line.html b/Tests/LibWeb/Text/input/css/subgrid-automatic-span-with-one-definite-line.html
new file mode 100644
index 00000000000..88e9dddf1c5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/subgrid-automatic-span-with-one-definite-line.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<style>
+ body {
+ margin: 0;
+ }
+
+ .grid {
+ display: grid;
+ grid-template-columns: repeat(4, 50px);
+ }
+
+ .subgrid {
+ display: grid;
+ grid-template-columns: subgrid [a] [b] [c];
+ height: 10px;
+ }
+</style>
+<div class="grid"><div class="subgrid" id="start" style="grid-column-start: 2"></div></div>
+<div class="grid"><div class="subgrid" id="start-auto" style="grid-column: 2 / auto"></div></div>
+<div class="grid"><div class="subgrid" id="end" style="grid-column-end: 5"></div></div>
+<div class="grid"><div class="subgrid" id="explicit-span" style="grid-column: 2 / span 2"></div></div>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ for (const id of ["start", "start-auto", "end", "explicit-span"]) {
+ const rect = document.getElementById(id).getBoundingClientRect();
+ println(`${id}: x=${rect.x} width=${rect.width}`);
+ }
+ });
+</script>