LibWeb: Ensure floats are correctly placed under the preceding float

Previously floats would be placed next to the highest float that
fitted the new float on its line. However, this violates the rule
that floats should be placed under the preceding float if it does
not fit next to it.
This commit is contained in:
Ruben 2025-05-18 19:03:57 +02:00 committed by Jelle Raaijmakers
commit 09f5ce42f6
Notes: github-actions[bot] 2025-05-23 08:59:19 +00:00
5 changed files with 94 additions and 17 deletions

View file

@ -129,6 +129,14 @@ CSSPixels LineBuilder::y_for_float_to_be_inserted_here(Box const& box)
// Then, look for the next Y position where we can fit the new float.
auto box_in_root_rect = m_context.parent().content_box_rect_in_ancestor_coordinate_space(box_state, m_context.parent().root());
// New floats will always be placed vertically at or below the lowest float.
// This applies to all floats, so the last inserted float will always be the lowest.
auto last_float = m_context.parent().last_inserted_float();
if (last_float.has_value()) {
auto float_box_top = last_float->margin_box_rect_in_root_coordinate_space.top() - box_in_root_rect.y();
candidate_block_offset = max(candidate_block_offset, float_box_top);
}
HashMap<CSSPixels, AvailableSize> available_space_cache;
for (;;) {
Optional<CSSPixels> highest_intersection_bottom;