From fa876320ebb3a32a06dece87a17efd11117fcf76 Mon Sep 17 00:00:00 2001 From: Sergey Bugaev Date: Wed, 25 Sep 2019 12:28:35 +0300 Subject: [PATCH] LibHTML: Fix LayoutBlock vertical position & height computations --- Libraries/LibHTML/Layout/LayoutBlock.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Libraries/LibHTML/Layout/LayoutBlock.cpp b/Libraries/LibHTML/Layout/LayoutBlock.cpp index eed6101479..a910875f72 100644 --- a/Libraries/LibHTML/Layout/LayoutBlock.cpp +++ b/Libraries/LibHTML/Layout/LayoutBlock.cpp @@ -26,13 +26,7 @@ void LayoutBlock::layout() int content_height = 0; for_each_child([&](auto& child) { child.layout(); - content_height += child.rect().height() - + child.style().margin().top.to_px() - + child.style().border().top.to_px() - + child.style().padding().top.to_px() - + child.style().margin().bottom.to_px() - + child.style().border().bottom.to_px() - + child.style().padding().bottom.to_px(); + content_height = child.rect().bottom() + child.style().full_margin().bottom - rect().top(); }); rect().set_height(content_height); @@ -117,6 +111,7 @@ void LayoutBlock::compute_position() auto zero_value = Length(0, Length::Type::Absolute); auto width = style_properties.length_or_fallback("width", auto_value); + style().margin().top = style_properties.length_or_fallback("margin-top", zero_value); style().margin().bottom = style_properties.length_or_fallback("margin-bottom", zero_value); style().border().top = style_properties.length_or_fallback("border-top", zero_value); @@ -124,7 +119,17 @@ void LayoutBlock::compute_position() style().padding().top = style_properties.length_or_fallback("padding-top", zero_value); style().padding().bottom = style_properties.length_or_fallback("padding-bottom", zero_value); rect().set_x(containing_block()->rect().x() + style().margin().left.to_px() + style().border().left.to_px() + style().padding().left.to_px()); - rect().set_y(containing_block()->rect().y() + style().margin().top.to_px() + style().border().top.to_px() + style().padding().top.to_px()); + + int top_border = -1; + if (previous_sibling() != nullptr) { + auto& previous_sibling_rect = previous_sibling()->rect(); + auto& previous_sibling_style = previous_sibling()->style(); + top_border = previous_sibling_rect.y() + previous_sibling_rect.height(); + top_border += previous_sibling_style.full_margin().bottom; + } else { + top_border = containing_block()->rect().y(); + } + rect().set_y(top_border + style().full_margin().top); } void LayoutBlock::compute_height()