From 9e39f51fd3ab7e59b4099ec89fa97653b69fb344 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 8 Sep 2022 01:42:25 +0200 Subject: [PATCH] LibWeb: Position blocks after previous block-level box, ignoring type Before this change, block-level boxes were laid out vertically by placing them after the nearest previous BlockContainer sibling. This only worked if the preceding block-level box happened to be a BlockContainer. This fixes an issue where the screenshot on netsurf-browser.org was not being laid out properly (it was `img { display: block }` which creates a block-level ImageBox, and ImageBox is not a BlockContainer but a ReplacedBox, so the following block-level box was skipping over the ImageBox and being placed next to whatever was before the ImageBox..) --- .../Libraries/LibWeb/Layout/FormattingContext.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp index 2a08e9f126..8da09790a7 100644 --- a/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/FormattingContext.cpp @@ -1111,13 +1111,22 @@ float FormattingContext::containing_block_height_for(Box const& box, LayoutState VERIFY_NOT_REACHED(); } +static Box const* previous_block_level_sibling(Box const& box) +{ + for (auto* sibling = box.previous_sibling_of_type(); sibling; sibling = sibling->previous_sibling_of_type()) { + if (sibling->computed_values().display().is_block_outside()) + return sibling; + } + return nullptr; +} + float FormattingContext::compute_box_y_position_with_respect_to_siblings(Box const& child_box, LayoutState::UsedValues const& box_state) { float y = box_state.border_box_top(); Vector collapsible_margins; - auto* relevant_sibling = child_box.previous_sibling_of_type(); + auto* relevant_sibling = previous_block_level_sibling(child_box); while (relevant_sibling != nullptr) { if (!relevant_sibling->is_absolutely_positioned() && !relevant_sibling->is_floating()) { auto const& relevant_sibling_state = m_state.get(*relevant_sibling); @@ -1127,7 +1136,7 @@ float FormattingContext::compute_box_y_position_with_respect_to_siblings(Box con break; collapsible_margins.append(relevant_sibling_state.margin_top); } - relevant_sibling = relevant_sibling->previous_sibling_of_type(); + relevant_sibling = previous_block_level_sibling(*relevant_sibling); } if (relevant_sibling) {