mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:57:45 +00:00
LibWeb: Use BFC root relative coordinates when flowing around floats
While IFC flows text into a block container, floating objects are anchored at the BFC root, not necessarily the local block container. Because of this, we have to use root-relative coordinates when checking how much space is available in between left and right floated objects.
This commit is contained in:
parent
54beb7433e
commit
9201f626c1
2 changed files with 7 additions and 3 deletions
|
@ -164,7 +164,7 @@ public:
|
||||||
virtual void before_children_paint(PaintContext&, PaintPhase) override;
|
virtual void before_children_paint(PaintContext&, PaintPhase) override;
|
||||||
virtual void after_children_paint(PaintContext&, PaintPhase) override;
|
virtual void after_children_paint(PaintContext&, PaintPhase) override;
|
||||||
|
|
||||||
Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& ancestor_box)
|
Gfx::FloatRect margin_box_rect_in_ancestor_coordinate_space(Box const& ancestor_box) const
|
||||||
{
|
{
|
||||||
auto rect = margin_box_as_relative_rect();
|
auto rect = margin_box_as_relative_rect();
|
||||||
for (auto const* current = parent(); current; current = current->parent()) {
|
for (auto const* current = parent(); current; current = current->parent()) {
|
||||||
|
|
|
@ -38,6 +38,10 @@ BlockFormattingContext const& InlineFormattingContext::parent() const
|
||||||
|
|
||||||
InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const
|
InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::available_space_for_line(float y) const
|
||||||
{
|
{
|
||||||
|
// NOTE: Floats are relative to the BFC root box, not necessarily the containing block of this IFC.
|
||||||
|
auto box_in_root_rect = containing_block().margin_box_rect_in_ancestor_coordinate_space(parent().root());
|
||||||
|
float y_in_root = box_in_root_rect.y() + y;
|
||||||
|
|
||||||
AvailableSpaceForLineInfo info;
|
AvailableSpaceForLineInfo info;
|
||||||
|
|
||||||
auto const& bfc = parent();
|
auto const& bfc = parent();
|
||||||
|
@ -45,7 +49,7 @@ InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::avai
|
||||||
for (ssize_t i = bfc.left_side_floats().boxes.size() - 1; i >= 0; --i) {
|
for (ssize_t i = bfc.left_side_floats().boxes.size() - 1; i >= 0; --i) {
|
||||||
auto const& floating_box = bfc.left_side_floats().boxes.at(i);
|
auto const& floating_box = bfc.left_side_floats().boxes.at(i);
|
||||||
auto rect = floating_box.margin_box_as_relative_rect();
|
auto rect = floating_box.margin_box_as_relative_rect();
|
||||||
if (rect.contains_vertically(y)) {
|
if (rect.contains_vertically(y_in_root)) {
|
||||||
info.left = rect.right() + 1;
|
info.left = rect.right() + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -56,7 +60,7 @@ InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::avai
|
||||||
for (ssize_t i = bfc.right_side_floats().boxes.size() - 1; i >= 0; --i) {
|
for (ssize_t i = bfc.right_side_floats().boxes.size() - 1; i >= 0; --i) {
|
||||||
auto const& floating_box = bfc.right_side_floats().boxes.at(i);
|
auto const& floating_box = bfc.right_side_floats().boxes.at(i);
|
||||||
auto rect = floating_box.margin_box_as_relative_rect();
|
auto rect = floating_box.margin_box_as_relative_rect();
|
||||||
if (rect.contains_vertically(y)) {
|
if (rect.contains_vertically(y_in_root)) {
|
||||||
info.right = rect.left() - 1;
|
info.right = rect.left() - 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue