From 34025442ffd3f933f5eb0c384dea72cd70d67cd1 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 14 Sep 2022 15:39:19 +0200 Subject: [PATCH] LibWeb: Account for float's container offsets in BFC root auto height When calculating the automatic height of a BFC root, we stretch it to contain the bottommost margin edge of floating boxes. Before this change, we assumed that floating boxes had coordinates relative to the BFC root, when they're actually relative to the floating box's containing block. This may or may not be the BFC root, so we have to use margin_box_in_ancestor_coordinate_space() to apply offsets from all boxes in the containing block chain (up to the BFC root). --- .../Libraries/LibWeb/Layout/FormattingContext.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 554d331e7c..205aeb7734 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -345,11 +345,12 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(L // whose bottom margin edge is below the element's bottom content edge, // then the height is increased to include those edges. for (auto* floating_box : state.get(root).floating_descendants()) { - auto const& floating_box_state = state.get(*floating_box); - float floating_box_bottom = floating_box_state.offset.y() + floating_box_state.content_height() + floating_box_state.margin_box_bottom(); - - if (!bottom.has_value() || floating_box_bottom > bottom.value()) - bottom = floating_box_bottom; + // NOTE: Floating box coordinates are relative to their own containing block, + // which may or may not be the BFC root. + auto margin_box = margin_box_rect_in_ancestor_coordinate_space(*floating_box, root, state); + float floating_box_bottom_margin_edge = margin_box.bottom() + 1; + if (!bottom.has_value() || floating_box_bottom_margin_edge > bottom.value()) + bottom = floating_box_bottom_margin_edge; } return max(0.0f, bottom.value_or(0) - top.value_or(0));