From 83a6e698a0308b9cb57cd211784438a26860af83 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 23 Jan 2022 12:54:20 +0100 Subject: [PATCH] LibWeb: Move rect-in-coordinate-space helper to Layout::Box --- .../LibWeb/Layout/BlockFormattingContext.cpp | 18 ++---------------- Userland/Libraries/LibWeb/Layout/Box.h | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp index 256da30e69..463c4b6519 100644 --- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp +++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp @@ -569,20 +569,6 @@ void BlockFormattingContext::layout_initial_containing_block(LayoutMode layout_m } } -static Gfx::FloatRect rect_in_coordinate_space(const Box& box, const Box& context_box) -{ - Gfx::FloatRect rect = box.margin_box_as_relative_rect(); - for (auto* ancestor = box.parent(); ancestor; ancestor = ancestor->parent()) { - if (is(*ancestor)) { - auto offset = verify_cast(*ancestor).effective_offset(); - rect.translate_by(offset); - } - if (ancestor == &context_box) - break; - } - return rect; -} - void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer const& containing_block) { VERIFY(box.is_floating()); @@ -601,7 +587,7 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons // Then we float it to the left or right. float x = box.effective_offset().x(); - auto box_in_root_rect = rect_in_coordinate_space(box, root()); + auto box_in_root_rect = box.margin_box_rect_in_ancestor_coordinate_space(root()); float y_in_root = box_in_root_rect.y(); float y = box.effective_offset().y(); @@ -615,7 +601,7 @@ void BlockFormattingContext::layout_floating_child(Box& box, BlockContainer cons side_data.y_offset = 0; } else { auto& previous_box = side_data.boxes.last(); - auto previous_rect = rect_in_coordinate_space(previous_box, root()); + auto previous_rect = previous_box.margin_box_rect_in_ancestor_coordinate_space(root()); auto margin_collapsed_with_previous = max( second_edge(previous_box.box_model().margin), diff --git a/Userland/Libraries/LibWeb/Layout/Box.h b/Userland/Libraries/LibWeb/Layout/Box.h index 71f2e65d85..231ac863e1 100644 --- a/Userland/Libraries/LibWeb/Layout/Box.h +++ b/Userland/Libraries/LibWeb/Layout/Box.h @@ -164,6 +164,20 @@ 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) + { + auto rect = margin_box_as_relative_rect(); + for (auto const* current = parent(); current; current = current->parent()) { + if (current == &ancestor_box) + break; + if (is(*current)) { + auto offset = static_cast(*current).effective_offset(); + rect.translate_by(offset); + } + } + return rect; + } + protected: Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr style) : NodeWithStyleAndBoxModelMetrics(document, node, move(style))