From 87c7fb1d633676201c96bb3c5c09a81719691990 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 30 Aug 2025 15:32:43 +0200 Subject: [PATCH] LibWeb: Use 0 as min-content size for items with `overflow:hidden` [GFC] This behavior is not specified but required to match other browsers. Fixes https://github.com/LadybirdBrowser/ladybird/issues/5907 --- .../LibWeb/Layout/GridFormattingContext.cpp | 9 ++++++++- .../grid/inline-item-with-overflow-hidden.txt | 20 +++++++++++++++++++ .../inline-item-with-overflow-hidden.html | 16 +++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/grid/inline-item-with-overflow-hidden.txt create mode 100644 Tests/LibWeb/Layout/input/grid/inline-item-with-overflow-hidden.html diff --git a/Libraries/LibWeb/Layout/GridFormattingContext.cpp b/Libraries/LibWeb/Layout/GridFormattingContext.cpp index dd7c38c2154..687b2c55da2 100644 --- a/Libraries/LibWeb/Layout/GridFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/GridFormattingContext.cpp @@ -2460,7 +2460,14 @@ CSSPixels GridFormattingContext::calculate_min_content_contribution(GridItem con } if (should_treat_preferred_size_as_auto) { - auto result = item.add_margin_box_sizes(calculate_min_content_size(item, dimension), dimension); + CSSPixels min_content_size; + // NOTE: This behavior is not defined in the spec, but seems required to match other browsers. + if (item.box->is_scroll_container()) { + min_content_size = 0; + } else { + min_content_size = calculate_min_content_size(item, dimension); + } + auto result = item.add_margin_box_sizes(min_content_size, dimension); return min(result, maximum_size); } diff --git a/Tests/LibWeb/Layout/expected/grid/inline-item-with-overflow-hidden.txt b/Tests/LibWeb/Layout/expected/grid/inline-item-with-overflow-hidden.txt new file mode 100644 index 00000000000..b7746ebe7cc --- /dev/null +++ b/Tests/LibWeb/Layout/expected/grid/inline-item-with-overflow-hidden.txt @@ -0,0 +1,20 @@ +Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] children: not-inline + BlockContainer at [0,0] [0+0+0 800 0+0+0] [0+0+0 34 0+0+0] [BFC] children: not-inline + BlockContainer at [8,8] [8+0+0 784 0+0+8] [8+0+0 18 0+0+8] children: not-inline + Box at [8,8] [0+0+0 784 0+0+0] [0+0+0 18 0+0+0] [GFC] children: not-inline + Box at [8,8] [0+0+0 196 0+0+0] [0+0+0 18 0+0+0] [GFC] children: not-inline + BlockContainer at [8,8] [0+0+0 196 0+0+0] [0+0+0 18 0+0+0] [BFC] children: inline + frag 0 from TextNode start: 0, length: 115, rect: [8,8 970.5625x18] baseline: 13.796875 + "Very very very long sentence lorem ipsum too long to fit what will happen with this sentence? Nobody knows for sure" + TextNode <#text> (not painted) + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x34] + PaintableWithLines (BlockContainer) [8,8 784x18] + PaintableBox (Box
.a) [8,8 784x18] + PaintableBox (Box
.b) [8,8 196x18] + PaintableWithLines (BlockContainer) [8,8 196x18] overflow: [8,8 970.5625x18] + TextPaintable (TextNode<#text>) + +SC for Viewport<#document> [0,0 800x600] [children: 1] (z-index: auto) + SC for BlockContainer [0,0 800x34] [children: 0] (z-index: auto) diff --git a/Tests/LibWeb/Layout/input/grid/inline-item-with-overflow-hidden.html b/Tests/LibWeb/Layout/input/grid/inline-item-with-overflow-hidden.html new file mode 100644 index 00000000000..3a8894e4201 --- /dev/null +++ b/Tests/LibWeb/Layout/input/grid/inline-item-with-overflow-hidden.html @@ -0,0 +1,16 @@ + + +
Very very very long sentence lorem ipsum too long to fit what will happen with this sentence? Nobody knows for sure \ No newline at end of file