From bf3772362a79984fa9226a12a147fb5a94a4e648 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 2 Jan 2021 03:46:26 +0100 Subject: [PATCH] LibWeb: When collapsing margins, consider border box heights Empty boxes should be fully collapsed, but a box with border and/or padding is not empty. This fixes an issue where
elements were getting weirdly collapsed since they have zero content height (but some border height.) --- Libraries/LibWeb/Layout/BlockFormattingContext.cpp | 2 +- Libraries/LibWeb/Layout/Box.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 402a86f127..e7d1281b81 100644 --- a/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -548,7 +548,7 @@ void BlockFormattingContext::place_block_level_non_replaced_element_in_normal_fl while (relevant_sibling != nullptr) { if (!relevant_sibling->is_absolutely_positioned() && !relevant_sibling->is_floating()) { collapsed_bottom_margin_of_preceding_siblings = max(collapsed_bottom_margin_of_preceding_siblings, relevant_sibling->box_model().margin.bottom); - if (relevant_sibling->height() > 0) + if (relevant_sibling->border_box_height() > 0) break; } relevant_sibling = relevant_sibling->previous_sibling(); diff --git a/Libraries/LibWeb/Layout/Box.h b/Libraries/LibWeb/Layout/Box.h index a836761087..a9517b6437 100644 --- a/Libraries/LibWeb/Layout/Box.h +++ b/Libraries/LibWeb/Layout/Box.h @@ -58,6 +58,12 @@ public: return width() + border_box.left + border_box.right; } + float border_box_height() const + { + auto border_box = box_model().border_box(); + return height() + border_box.top + border_box.bottom; + } + Gfx::FloatRect content_box_as_relative_rect() const { return { m_offset, m_size };