From 83a2aa1832eb8dd1a70d5addce1ce82b45ff9d41 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 26 Mar 2022 22:45:51 +0100 Subject: [PATCH] LibWeb: Include negative margins in height:auto computation for BFC root ...but never allow the resulting height to become negative. This solves an issue seen on Acid3 where elements with negative vertical margins expanded the size of their height:auto container instead of shrinking it, which is the correct behavior. This now works :^) --- Userland/Libraries/LibWeb/Layout/FormattingContext.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 30292796f9..1bb8f7aeab 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -286,9 +286,8 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(F 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_top = child_box_state.offset.y() - child_box_state.border_box_top() - max(0, child_box_state.margin_top); - 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); + float child_box_top = child_box_state.offset.y() - child_box_state.margin_box_top(); + float child_box_bottom = child_box_state.offset.y() + child_box_state.content_height + child_box_state.margin_box_bottom(); if (!top.has_value() || child_box_top < top.value()) top = child_box_top; @@ -308,8 +307,7 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(F 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); + 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; @@ -317,7 +315,7 @@ float FormattingContext::compute_auto_height_for_block_formatting_context_root(F return IterationDecision::Continue; }); - return bottom.value_or(0) - top.value_or(0); + return max(0, bottom.value_or(0) - top.value_or(0)); } // 10.3.2 Inline, replaced elements, https://www.w3.org/TR/CSS22/visudet.html#inline-replaced-width