1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 06:37:35 +00:00

LibWeb: Move box_type_agnostic_position() from layout node to paintable

For this method, there is no need to go through the layout node when we
can directly reach the paintable.
This commit is contained in:
Aliaksandr Kalenik 2024-01-14 11:14:20 +01:00 committed by Andreas Kling
parent 31e5b5f5de
commit 814bed33b4
8 changed files with 39 additions and 36 deletions

View file

@ -131,4 +131,28 @@ PaintableBox const* Paintable::nearest_scrollable_ancestor_within_stacking_conte
return nullptr;
}
CSSPixelPoint Paintable::box_type_agnostic_position() const
{
if (is_paintable_box())
return static_cast<PaintableBox const*>(this)->absolute_position();
VERIFY(is_inline());
if (is_inline_paintable()) {
auto const& inline_paintable = static_cast<Painting::InlinePaintable const&>(*this);
if (!inline_paintable.fragments().is_empty())
return inline_paintable.fragments().first().absolute_rect().location();
VERIFY_NOT_REACHED();
}
CSSPixelPoint position;
if (auto const* block = containing_block(); block && block->paintable() && is<Painting::PaintableWithLines>(*block->paintable())) {
static_cast<Painting::PaintableWithLines const&>(*block->paintable_box()).for_each_fragment([&](auto& fragment) {
position = fragment.absolute_rect().location();
return IterationDecision::Break;
});
}
return position;
}
}