1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00

LibWeb: Improve float: right behavior

- Use the border box of the floated element when testing if something
  needs to flow around it.
- Take the floated element's containing block size into account (instead
  of the BFC root) when calculating available space on a line where a
  right-side float intrudes.
This commit is contained in:
Andreas Kling 2022-09-07 13:29:58 +02:00
parent a42506c8b9
commit 514fa83708
5 changed files with 64 additions and 9 deletions

View file

@ -107,6 +107,31 @@ Gfx::FloatRect margin_box_rect(Box const& box, LayoutState const& state)
return rect;
}
Gfx::FloatRect border_box_rect(Box const& box, LayoutState const& state)
{
auto const& box_state = state.get(box);
auto rect = Gfx::FloatRect { box_state.offset, { box_state.content_width(), box_state.content_height() } };
rect.set_x(rect.x() - box_state.border_box_left());
rect.set_width(rect.width() + box_state.border_box_left() + box_state.border_box_right());
rect.set_y(rect.y() - box_state.border_box_top());
rect.set_height(rect.height() + box_state.border_box_top() + box_state.border_box_bottom());
return rect;
}
Gfx::FloatRect border_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const& state)
{
auto rect = border_box_rect(box, state);
for (auto const* current = box.parent(); current; current = current->parent()) {
if (current == &ancestor_box)
break;
if (is<Box>(*current)) {
auto const& current_state = state.get(static_cast<Box const&>(*current));
rect.translate_by(current_state.offset);
}
}
return rect;
}
Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& box, Box const& ancestor_box, LayoutState const& state)
{
auto rect = margin_box_rect(box, state);