Skip to content

Truly independent web browser

LibWeb: Clamp grid automatic minimums to the stretch fit of their area

Andreas Kling9c6ce29e8df2
diff --git a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
index cb4d5d1d7e6..0f571870e50 100644
--- a/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/grid_formatting_context.rs
@@ -3211,7 +3211,8 @@ impl<'pass> GridFormattingContext<'pass> {
fixed_track_limit += track.max_sizing.resolve(available);
}
if all_fixed {
- result = result.min(fixed_track_limit);
+ // NB: The stretch fit into that size leaves room for the item's margins, borders and padding.
+ result = result.min(CssPixels::default().max(fixed_track_limit - self.outer_edges(item, axis)));
}
// In all cases, the size suggestion is additionally clamped by the maximum size in the affected axis, if it’s definite.
diff --git a/Tests/LibWeb/Layout/expected/grid/automatic-minimum-size-fixed-track-outer-sizes.txt b/Tests/LibWeb/Layout/expected/grid/automatic-minimum-size-fixed-track-outer-sizes.txt
new file mode 100644
index 00000000000..a0aa12cca63
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/grid/automatic-minimum-size-fixed-track-outer-sizes.txt
@@ -0,0 +1,12 @@
+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 80 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 64 0+0+8] children: not-inline
+ Box <div.grid> at [8,8] [0+0+0 300 0+0+484] [0+0+0 30 0+0+0] [GFC] children: not-inline
+ BlockContainer <div.item> at [13,13] [5+0+0 40 0+0+5] [5+0+0 20 0+0+5] [BFC] children: not-inline
+ BlockContainer <div.box> at [13,13] [0+0+0 58 0+0+-18] [0+0+0 20 0+0+0] children: not-inline
+ Box <div.grid> at [8,38] [0+0+0 300 0+0+484] [0+0+0 34 0+0+0] [GFC] children: not-inline
+ BlockContainer <div.item> at [15,45] [0+0+7 36 7+0+0] [0+0+7 20 7+0+0] [BFC] children: not-inline
+ BlockContainer <div.box> at [15,45] [0+0+0 58 0+0+-22] [0+0+0 20 0+0+0] children: not-inline
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x80] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/grid/automatic-minimum-size-fixed-track-outer-sizes.html b/Tests/LibWeb/Layout/input/grid/automatic-minimum-size-fixed-track-outer-sizes.html
new file mode 100644
index 00000000000..52a248e900c
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/grid/automatic-minimum-size-fixed-track-outer-sizes.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<style>
+.grid {
+ display: grid;
+ grid-template-columns: minmax(auto, 50px);
+ width: 300px;
+}
+.item {
+ background: green;
+}
+.box {
+ width: 58px;
+ height: 20px;
+}
+</style>
+<div class="grid"><div class="item" style="margin: 5px"><div class="box"></div></div></div>
+<div class="grid"><div class="item" style="padding: 7px"><div class="box"></div></div></div>