1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:27:42 +00:00

LibWeb: Layout floating children per block instead of whole BFC at once

Instead of plowing through all the floating boxes within a BFC and
doing all the layout up front, do the children of each block as we go.
This will allow us to know the vertical position of the containing
block when placing floats.
This commit is contained in:
Andreas Kling 2020-12-06 16:15:35 +01:00
parent 5eb1f752ab
commit d582828040
2 changed files with 9 additions and 10 deletions

View file

@ -65,7 +65,7 @@ void BlockFormattingContext::run(LayoutMode layout_mode)
if (layout_mode == LayoutMode::Default) if (layout_mode == LayoutMode::Default)
compute_width(context_box()); compute_width(context_box());
layout_floating_descendants(); layout_floating_children();
if (context_box().children_are_inline()) { if (context_box().children_are_inline()) {
layout_inline_children(layout_mode); layout_inline_children(layout_mode);
@ -615,7 +615,7 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m
icb.set_width(viewport_rect.width()); icb.set_width(viewport_rect.width());
layout_floating_descendants(); layout_floating_children();
layout_block_level_children(layout_mode); layout_block_level_children(layout_mode);
@ -651,17 +651,16 @@ void BlockFormattingContext::layout_absolutely_positioned_descendants()
}); });
} }
void BlockFormattingContext::layout_floating_descendants() void BlockFormattingContext::layout_floating_children()
{ {
context_box().for_each_in_subtree_of_type<Box>([&](auto& box) { context_box().for_each_child_of_type<Box>([&](auto& box) {
if (box.is_floating() && box.containing_block() == &context_box()) { if (box.is_floating())
layout_floating_descendant(box); layout_floating_child(box);
}
return IterationDecision::Continue; return IterationDecision::Continue;
}); });
} }
void BlockFormattingContext::layout_floating_descendant(Box& box) void BlockFormattingContext::layout_floating_child(Box& box)
{ {
ASSERT(box.is_floating()); ASSERT(box.is_floating());

View file

@ -58,13 +58,13 @@ private:
void layout_block_level_children(LayoutMode); void layout_block_level_children(LayoutMode);
void layout_inline_children(LayoutMode); void layout_inline_children(LayoutMode);
void layout_absolutely_positioned_descendants(); void layout_absolutely_positioned_descendants();
void layout_floating_descendants(); void layout_floating_children();
void place_block_level_replaced_element_in_normal_flow(Box&); void place_block_level_replaced_element_in_normal_flow(Box&);
void place_block_level_non_replaced_element_in_normal_flow(Box&); void place_block_level_non_replaced_element_in_normal_flow(Box&);
void layout_absolutely_positioned_descendant(Box&); void layout_absolutely_positioned_descendant(Box&);
void layout_floating_descendant(Box&); void layout_floating_child(Box&);
Vector<Box*> m_left_floating_boxes; Vector<Box*> m_left_floating_boxes;
Vector<Box*> m_right_floating_boxes; Vector<Box*> m_right_floating_boxes;