Skip to content

Truly independent web browser

LibWeb: Keep the strut below the baseline of inline grids

Andreas Kling83f3ca4d943c
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
index d86dd9f6fc7..19e19d7bf16 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
@@ -1014,7 +1014,8 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
// line height properties.
should_align_strut_to_line_box_baseline |= has_line_relative_aligned_subtree
|| ((style.display().is_inline_block()
- || (style.display().is_inline_outside() && style.display().is_flex_inside()))
+ || (style.display().is_inline_outside()
+ && (style.display().is_flex_inside() || style.display().is_grid_inside())))
&& alignment_style.vertical_align_keyword() == vertical_align::BASELINE);
}
line_box_baseline = adjusted_baseline;
diff --git a/Tests/LibWeb/Layout/expected/grid/fit-content-3.txt b/Tests/LibWeb/Layout/expected/grid/fit-content-3.txt
index 8c1e6a4d988..1bf2c06c5e2 100644
--- a/Tests/LibWeb/Layout/expected/grid/fit-content-3.txt
+++ b/Tests/LibWeb/Layout/expected/grid/fit-content-3.txt
@@ -1,7 +1,7 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 122 0+0+0] [BFC] children: not-inline
- BlockContainer <body> at [8,10] [8+0+0 784 0+0+8] [8+0+0 104 0+0+8] children: not-inline
- BlockContainer <div.container> at [8,10] [0+0+0 200 0+0+584] [10+0+0 104 0+0+0] children: inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 125 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,10] [8+0+0 784 0+0+8] [8+0+0 107 0+0+8] children: not-inline
+ BlockContainer <div.container> at [8,10] [0+0+0 200 0+0+584] [10+0+0 107 0+0+0] children: inline
frag 0 from Box start: 0, length: 0, rect: [8,10 104x104] baseline: 104
Box <div.grid> at [8,10] [0+0+0 104 0+0+0] [0+0+0 104 0+0+0] [GFC] children: not-inline
BlockContainer <div.item> at [8,10] [0+0+0 78 0+0+0] [0+0+0 104 0+0+0] [BFC] children: not-inline
@@ -10,4 +10,4 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [0,0 800x122] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x125] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/inline-grid-line-height-includes-strut.txt b/Tests/LibWeb/Layout/expected/inline-grid-line-height-includes-strut.txt
new file mode 100644
index 00000000000..f2a9d543e63
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/inline-grid-line-height-includes-strut.txt
@@ -0,0 +1,13 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 206 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 206 0+0+0] children: not-inline
+ BlockContainer <div> at [0,0] [0+0+0 800 0+0+0] [0+0+0 103 0+0+0] children: inline
+ frag 0 from Box start: 0, length: 0, rect: [0,0 100x100] baseline: 100
+ Box <div.grid> at [0,0] [0+0+0 100 0+0+0] [0+0+0 100 0+0+0] [GFC] children: not-inline
+ BlockContainer <div> at [0,0] [0+0+0 100 0+0+0] [0+0+0 100 0+0+0] [BFC] children: not-inline
+ BlockContainer <div> at [0,103] [0+0+0 800 0+0+0] [0+0+0 103 0+0+0] children: inline
+ frag 0 from BlockContainer start: 0, length: 0, rect: [0,103 100x100] baseline: 100
+ BlockContainer <div.block> at [0,103] inline-block [0+0+0 100 0+0+0] [0+0+0 100 0+0+0] [BFC] children: not-inline
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x206] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/inline-grid-line-height-includes-strut.html b/Tests/LibWeb/Layout/input/inline-grid-line-height-includes-strut.html
new file mode 100644
index 00000000000..2680b512dd2
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/inline-grid-line-height-includes-strut.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<style>
+ body {
+ margin: 0;
+ }
+ .grid {
+ display: inline-grid;
+ grid: 100px / 100px;
+ background: blue;
+ }
+ .block {
+ display: inline-block;
+ width: 100px;
+ height: 100px;
+ background: blue;
+ }
+</style>
+<!-- An inline grid on its own on a line still has the strut of the line box below its baseline, as an inline block has. -->
+<div><div class="grid"><div></div></div></div>
+<div><div class="block"></div></div>