diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index a11d60753b4..8930a91dbd8 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -933,7 +933,8 @@ BlockFormattingContext::DidIntroduceClearance BlockFormattingContext::clear_floa m_y_offset_of_current_block_container = clearance_y_in_containing_block; } - float_side.clear(); + if (!child_box.is_floating()) + float_side.clear(); } }; @@ -1053,7 +1054,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer } // Then we float it to the left or right. - auto float_box = [&](FloatSide side, FloatSideData& side_data, FloatSideData& other_side_data) { + auto float_box = [&](FloatSide side, FloatSideData& side_data) { CSSPixels offset_from_edge = 0; auto float_to_edge = [&] { if (side == FloatSide::Left) @@ -1165,18 +1166,13 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer // NOTE: We don't set the X position here, that happens later, once we know the root block width. // See parent_context_did_dimension_child_root_box() for that logic. box_state.set_content_y(y); - - // If the new box was inserted below the bottom of the opposite side, - // we reset the other side back to its edge. - if (top_margin_edge > other_side_data.y_offset) - other_side_data.clear(); }; // Next, float to the left and/or right if (box.computed_values().float_() == CSS::Float::Left) { - float_box(FloatSide::Left, m_left_floats, m_right_floats); + float_box(FloatSide::Left, m_left_floats); } else if (box.computed_values().float_() == CSS::Float::Right) { - float_box(FloatSide::Right, m_right_floats, m_left_floats); + float_box(FloatSide::Right, m_right_floats); } m_state.get_mutable(root()).add_floating_descendant(box); diff --git a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 50469a5d922..9b772f2ffe9 100644 --- a/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -314,11 +314,9 @@ void InlineFormattingContext::generate_line_boxes() case InlineLevelIterator::Item::Type::FloatingElement: if (is(*item.node)) { - [[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. + (void)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; diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-simultaneously.txt b/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-simultaneously.txt new file mode 100644 index 00000000000..5421adae1c3 --- /dev/null +++ b/Tests/LibWeb/Layout/expected/block-and-inline/float-clear-simultaneously.txt @@ -0,0 +1,23 @@ +Viewport <#document> at (0,0) content-size 800x600 children: not-inline + BlockContainer at (0,0) content-size 800x166 [BFC] children: not-inline + BlockContainer at (8,8) content-size 784x150 children: not-inline + BlockContainer at (8,8) content-size 784x50 children: not-inline + BlockContainer <(anonymous)> at (8,58) content-size 784x0 children: inline + TextNode <#text> + BlockContainer at (742,58) content-size 50x50 floating [BFC] children: not-inline + TextNode <#text> + BlockContainer at (8,108) content-size 0x0 floating [BFC] children: not-inline + TextNode <#text> + BlockContainer at (8,108) content-size 784x50 children: not-inline + BlockContainer <(anonymous)> at (8,158) content-size 784x0 children: inline + TextNode <#text> + +ViewportPaintable (Viewport<#document>) [0,0 800x600] + PaintableWithLines (BlockContainer) [0,0 800x166] + PaintableWithLines (BlockContainer) [8,8 784x150] + PaintableWithLines (BlockContainer
.a) [8,8 784x50] + PaintableWithLines (BlockContainer(anonymous)) [8,58 784x0] + PaintableWithLines (BlockContainer
.b) [742,58 50x50] + PaintableWithLines (BlockContainer
.c) [8,108 0x0] + PaintableWithLines (BlockContainer
.d) [8,108 784x50] + PaintableWithLines (BlockContainer(anonymous)) [8,158 784x0] diff --git a/Tests/LibWeb/Layout/input/block-and-inline/float-clear-simultaneously.html b/Tests/LibWeb/Layout/input/block-and-inline/float-clear-simultaneously.html new file mode 100644 index 00000000000..b8490347263 --- /dev/null +++ b/Tests/LibWeb/Layout/input/block-and-inline/float-clear-simultaneously.html @@ -0,0 +1,26 @@ + + +
+
+
+