From f3ea8d49a9ebe260ad727498a1a9aad1fe7bb5ba Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Fri, 12 Jun 2020 15:23:59 +0200 Subject: [PATCH] LibWeb: Remove absolute positioning logic from LayoutReplaced Absolutely positioned elements are placed by their containing block. Instead of trying to compute its own position, LayoutReplaced will now simply add itself as an absolutely positioned descendant of its containing block. --- Libraries/LibWeb/Layout/LayoutReplaced.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/Libraries/LibWeb/Layout/LayoutReplaced.cpp b/Libraries/LibWeb/Layout/LayoutReplaced.cpp index 1d911e8461..dccb63aa97 100644 --- a/Libraries/LibWeb/Layout/LayoutReplaced.cpp +++ b/Libraries/LibWeb/Layout/LayoutReplaced.cpp @@ -123,17 +123,11 @@ float LayoutReplaced::calculate_height() const Gfx::FloatPoint LayoutReplaced::calculate_position() { + ASSERT(!is_absolutely_positioned()); auto& style = this->style(); auto zero_value = Length(0, Length::Type::Px); auto& containing_block = *this->containing_block(); - if (style.position() == CSS::Position::Absolute) { - box_model().offset().top = style.length_or_fallback(CSS::PropertyID::Top, zero_value, containing_block.height()); - box_model().offset().right = style.length_or_fallback(CSS::PropertyID::Right, zero_value, containing_block.width()); - box_model().offset().bottom = style.length_or_fallback(CSS::PropertyID::Bottom, zero_value, containing_block.height()); - box_model().offset().left = style.length_or_fallback(CSS::PropertyID::Left, zero_value, containing_block.width()); - } - box_model().margin().top = style.length_or_fallback(CSS::PropertyID::MarginTop, zero_value, containing_block.width()); box_model().margin().bottom = style.length_or_fallback(CSS::PropertyID::MarginBottom, zero_value, containing_block.width()); box_model().border().top = style.length_or_fallback(CSS::PropertyID::BorderTopWidth, zero_value); @@ -158,7 +152,11 @@ void LayoutReplaced::layout(LayoutMode layout_mode) LayoutBox::layout(layout_mode); - set_offset(calculate_position()); + if (is_absolutely_positioned()) { + const_cast(containing_block())->add_absolutely_positioned_descendant(*this); + } else { + set_offset(calculate_position()); + } } void LayoutReplaced::split_into_lines(LayoutBlock& container, LayoutMode layout_mode)