From 9075f64cacabe7f548481cf63dbaa3e532d93574 Mon Sep 17 00:00:00 2001 From: Pavel Panchekha Date: Fri, 20 Sep 2024 12:53:45 -0600 Subject: [PATCH] LibWeb: Change inline float clearance to not reset margin collapsing When a block container has `clear` set and some clearance is applied, that clearance prevents margins from adjoining and therefore resets the margin state. But when a floating box has `clear` set, that clearance only goes between floating boxes so should not reset margin state. BlockFormattingContexts already do that correctly, and this PR changes InlineFormattingContext to do the same. Fixes #1462; adds reduced input from that issue as test. --- .../block-and-inline/inline-float-clear.txt | 26 +++++++++++++++++++ .../block-and-inline/inline-float-clear.html | 8 ++++++ .../LibWeb/Layout/InlineFormattingContext.cpp | 8 +++--- 3 files changed, 39 insertions(+), 3 deletions(-) create mode 100644 Tests/LibWeb/Layout/expected/block-and-inline/inline-float-clear.txt create mode 100644 Tests/LibWeb/Layout/input/block-and-inline/inline-float-clear.html diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-float-clear.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-float-clear.txt new file mode 100644 index 00000000000..612380b70e6 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-float-clear.txt @@ -0,0 +1,26 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x73 [BFC] children: not-inline + BlockContainer at (9,9) content-size 687.5x48 children: not-inline + BlockContainer <(anonymous)> at (9,9) content-size 687.5x0 children: inline + TextNode <#text> + BlockContainer at (9,9) content-size 687.5x16 children: not-inline + BlockContainer <(anonymous)> at (9,41) content-size 687.5x0 children: inline + TextNode <#text> + BlockContainer at (648.5,41) content-size 48x16 floating [BFC] children: not-inline + TextNode <#text> + BlockContainer at (648.5,57) content-size 48x16 floating [BFC] children: not-inline + TextNode <#text> + BlockContainer at (9,41) content-size 687.5x16 children: not-inline + BlockContainer <(anonymous)> at (9,57) content-size 687.5x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x73] + PaintableWithLines (BlockContainer) [8,8 689.5x50] + PaintableWithLines (BlockContainer(anonymous)) [9,9 687.5x0] + PaintableWithLines (BlockContainer
#A) [9,9 687.5x16] + PaintableWithLines (BlockContainer(anonymous)) [9,41 687.5x0] + PaintableWithLines (BlockContainer
#B) [648.5,41 48x16] + PaintableWithLines (BlockContainer
#C) [648.5,57 48x16] + PaintableWithLines (BlockContainer
#D) [9,41 687.5x16] + PaintableWithLines (BlockContainer(anonymous)) [9,57 687.5x0] diff --git a/Tests/LibWeb/Layout/input/block-and-inline/inline-float-clear.html b/Tests/LibWeb/Layout/input/block-and-inline/inline-float-clear.html new file mode 100644 index 00000000000..eeb49553ff3 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/inline-float-clear.html @@ -0,0 +1,8 @@ + + + + +
+
+
+
diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 2fcc4153d72..b4c25743ecf 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -314,9 +314,11 @@ void InlineFormattingContext::generate_line_boxes() case InlineLevelIterator::Item::Type::FloatingElement: if (is(*item.node)) { - auto introduce_clearance = parent().clear_floating_boxes(*item.node, *this); - if (introduce_clearance == BlockFormattingContext::DidIntroduceClearance::Yes) - parent().reset_margin_state(); + [[maybe_unused]] auto introduce_clearance = parent().clear_floating_boxes(*item.node, *this); + // Even if this introduces clearance, we do NOT reset + // the margin state, because that is clearance between + // floats and does not contribute to the height of the + // Inline Formatting Context. parent().layout_floating_box(static_cast(*item.node), containing_block(), *m_available_space, 0, &line_builder); } break;