LibWeb: Avoid some redundant calls to Layout::Box::absolute_rect()

Computing the absolute rect of a box requires walking the chain of
containing blocks and apply any offsets encountered. This can be slow in
deeply nested box trees, so let's at least avoid doing it multiple times
when once is enough.
This commit is contained in:
Andreas Kling 2021-09-15 14:18:17 +02:00
commit eac31e21f2
Notes: sideshowbarker 2024-07-18 03:56:38 +09:00
2 changed files with 8 additions and 6 deletions

View file

@ -34,10 +34,11 @@ public:
Gfx::FloatRect padded_rect() const
{
auto absolute_rect = this->absolute_rect();
Gfx::FloatRect rect;
rect.set_x(absolute_x() - box_model().padding.left);
rect.set_x(absolute_rect.x() - box_model().padding.left);
rect.set_width(width() + box_model().padding.left + box_model().padding.right);
rect.set_y(absolute_y() - box_model().padding.top);
rect.set_y(absolute_rect.y() - box_model().padding.top);
rect.set_height(height() + box_model().padding.top + box_model().padding.bottom);
return rect;
}