From 5da7ebb806cd3be5b126ec22bfda926c7319e4f7 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 29 Mar 2022 18:46:14 +0200 Subject: [PATCH] LibWeb: Make height:auto for non-BFC-root blocks more correct Unlike BFC root blocks with height:auto, when the block *isn't* a BFC root, we don't have to look for the "bottommost" block-level child and determine the width from that. Instead, we should just look at the last in-flow block-level child. This was already indicated in the spec comment next to the code, but the code itself was wrong. This makes the body element on Acid3 have the correct height. It also introduces a small regression on Acid2 that we'll have to track down. --- .../LibWeb/Layout/FormattingContext.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index fbfb069412..9c2f77afd1 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -216,19 +216,14 @@ float FormattingContext::compute_auto_height_for_block_level_element(FormattingS // 2. the bottom edge of the bottom (possibly collapsed) margin of its last in-flow child, if the child's bottom margin does not collapse with the element's bottom margin // FIXME: 3. the bottom border edge of the last in-flow child whose top margin doesn't collapse with the element's bottom margin if (!box.children_are_inline()) { - Optional bottom; - box.for_each_child_of_type([&](Layout::Box& child_box) { - if (child_box.is_absolutely_positioned() || child_box.is_floating()) - return; + for (auto* child_box = box.last_child_of_type(); child_box; child_box = child_box->previous_sibling_of_type()) { + if (child_box->is_absolutely_positioned() || child_box->is_floating()) + continue; // FIXME: Handle margin collapsing. - auto const& child_box_state = state.get(child_box); - float child_box_bottom = child_box_state.offset.y() + child_box_state.content_height + child_box_state.margin_box_bottom(); - - if (!bottom.has_value() || child_box_bottom > bottom.value()) - bottom = child_box_bottom; - }); - return bottom.value_or(0); + auto const& child_box_state = state.get(*child_box); + return max(0, child_box_state.offset.y() + child_box_state.content_height + child_box_state.margin_box_bottom()); + } } // 4. zero, otherwise