Skip to content

Truly independent web browser

LibWeb: Treat a grid item's fit-content size as auto for contributions

Andreas Kling717b2a5ddfbf
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index da86e955028..cb4d5d1d7e6 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -2928,6 +2928,10 @@ impl<'pass> GridFormattingContext<'pass> {
if behaves_as_auto || (!self.item_facts(item).is_replaced_box() && preferred_size.contains_percentage()) {
return true;
}
+ // NB: A fit-content preferred size depends on the size of the item's containing block, its grid area.
+ if preferred_size.is_fit_content() {
+ return true;
+ }
// NB: A percentage block size that is treated as auto is reported as not auto when the item's inline size
// transfers through its aspect ratio, but it must not be resolved as a percentage here.
!axis.is_column()
diff --git a/Tests/LibWeb/Layout/expected/grid/fit-content-item-contributions.txt b/Tests/LibWeb/Layout/expected/grid/fit-content-item-contributions.txt
new file mode 100644
index 00000000000..209b7661aa3
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/grid/fit-content-item-contributions.txt
@@ -0,0 +1,16 @@
+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 145 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 129 0+0+8] children: not-inline
+ Box <div.grid> at [8,8] [0+0+0 200 0+0+584] [0+0+0 86 0+0+0] [GFC] children: not-inline
+ BlockContainer <div.item> at [8,8] [0+0+0 40 0+0+0] [0+0+0 86 0+0+0] [BFC] children: inline
+ frag 0 from BlockContainer start: 0, length: 0, rect: [8,8 40x40] baseline: 40
+ frag 1 from BlockContainer start: 0, length: 0, rect: [8,51 40x40] baseline: 40
+ BlockContainer <span.box> at [8,8] inline-block [0+0+0 40 0+0+0] [0+0+0 40 0+0+0] [BFC] children: not-inline
+ BlockContainer <span.box> at [8,51] inline-block [0+0+0 40 0+0+0] [0+0+0 40 0+0+0] [BFC] children: not-inline
+ Box <div.grid> at [8,94] [0+0+0 0 0+0+784] [0+0+0 43 0+0+0] [GFC] children: not-inline
+ BlockContainer <div.item> at [8,94] [0+0+0 40 0+0+0] [0+0+0 43 0+0+0] [BFC] children: inline
+ frag 0 from BlockContainer start: 0, length: 0, rect: [8,94 40x40] baseline: 40
+ BlockContainer <span.box> at [8,94] inline-block [0+0+0 40 0+0+0] [0+0+0 40 0+0+0] [BFC] children: not-inline
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x145] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/grid/fit-content-item-contributions.html b/Tests/LibWeb/Layout/input/grid/fit-content-item-contributions.html
new file mode 100644
index 00000000000..14df49a1394
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/fit-content-item-contributions.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<style>
+.grid {
+ display: grid;
+ width: 200px;
+}
+.item {
+ width: fit-content;
+ background: green;
+}
+.box {
+ display: inline-block;
+ width: 40px;
+ height: 40px;
+}
+</style>
+<!-- The item contributes its min-content size. -->
+<div class="grid" style="grid-template-columns: min-content"><div class="item"><span class="box"></span><span class="box"></span></div></div>
+<!-- The automatic minimum size is zero for an item spanning flexible tracks. -->
+<div class="grid" style="width: min-content; grid-template-columns: 1fr 1fr"><div class="item" style="grid-column: span 2"><span class="box"></span></div></div>