1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

LibWeb: Make Paintable::containing_block() return a PaintableBox*

Every single client of this function was immediately calling paintable()
on the result anyway, so there was no need to return a layout node!

This automatically leverages the cached containing block pointer we
already have in Paintable, which melts away a bunch of unnecessary
traversal in hit testing and painting. :^)
This commit is contained in:
Andreas Kling 2024-03-01 15:30:44 +01:00
parent c3980eda9e
commit d1b5f55f91
9 changed files with 32 additions and 36 deletions

View file

@ -128,8 +128,6 @@ void Paintable::set_needs_display() const
auto* containing_block = this->containing_block();
if (!containing_block)
return;
if (!containing_block->paintable_box())
return;
auto navigable = this->navigable();
if (!navigable)
return;
@ -140,9 +138,9 @@ void Paintable::set_needs_display() const
navigable->set_needs_display(fragment.absolute_rect());
}
if (!is<Painting::PaintableWithLines>(*containing_block->paintable_box()))
if (!is<Painting::PaintableWithLines>(*containing_block))
return;
static_cast<Painting::PaintableWithLines const&>(*containing_block->paintable_box()).for_each_fragment([&](auto& fragment) {
static_cast<Painting::PaintableWithLines const&>(*containing_block).for_each_fragment([&](auto& fragment) {
navigable->set_needs_display(fragment.absolute_rect());
return IterationDecision::Continue;
});
@ -162,8 +160,8 @@ CSSPixelPoint Paintable::box_type_agnostic_position() const
}
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) {
if (auto const* block = containing_block(); block && is<Painting::PaintableWithLines>(*block)) {
static_cast<Painting::PaintableWithLines const&>(*block).for_each_fragment([&](auto& fragment) {
position = fragment.absolute_rect().location();
return IterationDecision::Break;
});