diff options
author | Andreas Kling <kling@serenityos.org> | 2020-06-12 15:23:59 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-06-12 15:24:33 +0200 |
commit | f3ea8d49a9ebe260ad727498a1a9aad1fe7bb5ba (patch) | |
tree | 5a6d5acd4a684fbc0a6e2860c39f405c3fcf295c | |
parent | 137f6d44ec43706c987eb5933b95458f407c3b42 (diff) | |
download | serenity-f3ea8d49a9ebe260ad727498a1a9aad1fe7bb5ba.zip |
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.
-rw-r--r-- | Libraries/LibWeb/Layout/LayoutReplaced.cpp | 14 |
1 files 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<LayoutBlock*>(containing_block())->add_absolutely_positioned_descendant(*this); + } else { + set_offset(calculate_position()); + } } void LayoutReplaced::split_into_lines(LayoutBlock& container, LayoutMode layout_mode) |