mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
LibWeb: Move rect-in-coordinate-space helper to Layout::Box
This commit is contained in:
parent
29589378ff
commit
83a6e698a0
Notes:
sideshowbarker
2024-07-17 20:21:02 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/83a6e698a03
2 changed files with 16 additions and 16 deletions
|
@ -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<Box>(*ancestor)) {
|
||||
auto offset = verify_cast<Box>(*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),
|
||||
|
|
|
@ -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<Box>(*current)) {
|
||||
auto offset = static_cast<Box const&>(*current).effective_offset();
|
||||
rect.translate_by(offset);
|
||||
}
|
||||
}
|
||||
return rect;
|
||||
}
|
||||
|
||||
protected:
|
||||
Box(DOM::Document& document, DOM::Node* node, NonnullRefPtr<CSS::StyleProperties> style)
|
||||
: NodeWithStyleAndBoxModelMetrics(document, node, move(style))
|
||||
|
|
Loading…
Reference in a new issue