diff options
author | Andreas Kling <kling@serenityos.org> | 2022-01-24 02:03:29 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-01-24 02:16:13 +0100 |
commit | 9201f626c133464580a4cf31517b3191d74626fd (patch) | |
tree | 6f892ccee0e9f9bd335267ccb78cd7990b18ff90 | |
parent | 54beb7433ee7fff89b1bdfae1e69fe6654147304 (diff) | |
download | serenity-9201f626c133464580a4cf31517b3191d74626fd.zip |
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.
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/Box.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp | 8 |
2 files changed, 7 insertions, 3 deletions
diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 231ac863e1..bd29c18aef 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -164,7 +164,7 @@ public: virtual void before_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(); for (auto const* current = parent(); current; current = current->parent()) { diff --git a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp index 9bad45c3cc..a672b44997 100644 --- a/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp @@ -38,6 +38,10 @@ BlockFormattingContext const& InlineFormattingContext::parent() 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; 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) { auto const& floating_box = bfc.left_side_floats().boxes.at(i); 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; break; } @@ -56,7 +60,7 @@ InlineFormattingContext::AvailableSpaceForLineInfo InlineFormattingContext::avai 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 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; break; } |