From 925c34cf436c13f1244f86d28286e08a7393b09e Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 26 Mar 2022 00:11:37 +0100 Subject: [PATCH] LibWeb: Include floats in height:auto for BFC root with inline children BFC roots with children_are_inline()==true can still have floating boxes as well. children_are_inline() is only concerned with in-flow children. For this reason, we have to always consider floats when calculating height:auto for BFC roots. --- .../LibWeb/Layout/FormattingContext.cpp | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index f839bb330c..2581d76b77 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -293,28 +293,30 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(F if (!top.has_value() || child_box_top < top.value()) top = child_box_top; - if (!bottom.has_value() || child_box_bottom > bottom.value()) - bottom = child_box_bottom; - - return IterationDecision::Continue; - }); - // In addition, if the element has any floating descendants - // whose bottom margin edge is below the element's bottom content edge, - // then the height is increased to include those edges. - root.for_each_child_of_type([&](Layout::Box& child_box) { - if (!child_box.is_floating()) - return IterationDecision::Continue; - - auto const& child_box_state = state.get(child_box); - // FIXME: We're ignoring negative margins here, figure out the correct thing to do. - float child_box_bottom = child_box_state.offset.y() + child_box_state.content_height + child_box_state.border_box_bottom() + max(0, child_box_state.margin_bottom); - if (!bottom.has_value() || child_box_bottom > bottom.value()) bottom = child_box_bottom; return IterationDecision::Continue; }); } + + // In addition, if the element has any floating descendants + // whose bottom margin edge is below the element's bottom content edge, + // then the height is increased to include those edges. + root.for_each_child_of_type([&](Layout::Box& child_box) { + if (!child_box.is_floating()) + return IterationDecision::Continue; + + auto const& child_box_state = state.get(child_box); + // FIXME: We're ignoring negative margins here, figure out the correct thing to do. + float child_box_bottom = child_box_state.offset.y() + child_box_state.content_height + child_box_state.border_box_bottom() + max(0, child_box_state.margin_bottom); + + if (!bottom.has_value() || child_box_bottom > bottom.value()) + bottom = child_box_bottom; + + return IterationDecision::Continue; + }); + return bottom.value_or(0) - top.value_or(0); }