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..)
This commit is contained in:
parent
7b0dd98103
commit
9e39f51fd3
Notes:
sideshowbarker
2024-07-17 07:22:03 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9e39f51fd3
1 changed files with 11 additions and 2 deletions
|
@ -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<Box>(); sibling; sibling = sibling->previous_sibling_of_type<Box>()) {
|
||||
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<float> collapsible_margins;
|
||||
|
||||
auto* relevant_sibling = child_box.previous_sibling_of_type<Layout::BlockContainer>();
|
||||
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<Layout::BlockContainer>();
|
||||
relevant_sibling = previous_block_level_sibling(*relevant_sibling);
|
||||
}
|
||||
|
||||
if (relevant_sibling) {
|
||||
|
|
Loading…
Add table
Reference in a new issue