From 227b4c38b70412feb73aad57cfeeb0a817785ca1 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Sat, 15 Mar 2025 03:46:09 +0100 Subject: [PATCH] LibWeb: Use parent's available space for anonymous blocks in BFC Height resolution assumes that when available space is definite, it matches the size of non-anonymous containing block. With this change, we correctly maintain this assumption when box is wrapped in anonymous node. Fixes https://github.com/LadybirdBrowser/ladybird/issues/3422 --- .../LibWeb/Layout/BlockFormattingContext.cpp | 3 +- ...percentage-height-wrapped-in-anonymous.txt | 29 +++++++++++++++++++ ...ercentage-height-wrapped-in-anonymous.html | 16 ++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.html diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 1aa2a5597c2..4d1424a423c 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -803,7 +803,8 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain }); } - layout_block_level_children(as(box), box_state.available_inner_space_or_constraints_from(available_space)); + auto space_available_for_children = box.is_anonymous() ? available_space : box_state.available_inner_space_or_constraints_from(available_space); + layout_block_level_children(as(box), space_available_for_children); } } diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.txt b/Tests/LibWeb/Layout/expected/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.txt new file mode 100644 index 00000000000..b32cd8181d5 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.txt @@ -0,0 +1,29 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x116 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x100 children: not-inline + BlockContainer at (8,8) content-size 100x100 children: not-inline + BlockContainer <(anonymous)> at (8,8) content-size 100x17 children: inline + InlineNode + frag 0 from TextNode start: 0, length: 1, rect: [8,8 9.34375x17] baseline: 13.296875 + "a" + TextNode <#text> + BlockContainer <(anonymous)> at (8,25) content-size 100x100 children: not-inline continuation + BlockContainer at (8,25) content-size 100x100 children: not-inline + BlockContainer <(anonymous)> at (8,125) content-size 100x17 children: inline + InlineNode continuation + frag 0 from TextNode start: 0, length: 1, rect: [8,125 9.46875x17] baseline: 13.296875 + "b" + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x116] overflow: [0,0 800x142] + PaintableWithLines (BlockContainer) [8,8 784x100] overflow: [8,8 784x134] + PaintableWithLines (BlockContainer
.outer) [8,8 100x100] overflow: [8,8 100x134] + PaintableWithLines (BlockContainer(anonymous)) [8,8 100x17] + PaintableWithLines (InlineNode
.inline) + TextPaintable (TextNode<#text>) + PaintableWithLines (BlockContainer(anonymous)) [8,25 100x100] + PaintableWithLines (BlockContainer
.inner) [8,25 100x100] + PaintableWithLines (BlockContainer(anonymous)) [8,125 100x17] + PaintableWithLines (InlineNode
.inline) + TextPaintable (TextNode<#text>) diff --git a/Tests/LibWeb/Layout/input/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.html b/Tests/LibWeb/Layout/input/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.html new file mode 100644 index 00000000000..0a897217ac8 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/box-with-percentage-height-wrapped-in-anonymous.html @@ -0,0 +1,16 @@ +
a
b
\ No newline at end of file