1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 14:17:36 +00:00

LibWeb: Build stacking context tree lazily

There's no actual need to build the stacking context tree before
performing layout. Instead, make it lazy and build the tree when it's
actually needed for something.

This avoids a bunch of work in situations where multiple synchronous
layouts are forced (typically by JavaScript) without painting or hit
testing taking place in between.

It also opens up for style invalidations that only target the stacking
context tree.
This commit is contained in:
Andreas Kling 2022-03-21 10:56:02 +01:00
parent 89086c337c
commit 59afdb959f
5 changed files with 23 additions and 8 deletions

View file

@ -18,13 +18,19 @@ InitialContainingBlock::InitialContainingBlock(DOM::Document& document, NonnullR
InitialContainingBlock::~InitialContainingBlock() = default;
void InitialContainingBlock::build_stacking_context_tree_if_needed()
{
if (paint_box()->stacking_context())
return;
build_stacking_context_tree();
}
void InitialContainingBlock::build_stacking_context_tree()
{
const_cast<Painting::PaintableWithLines*>(paint_box())->set_stacking_context(make<Painting::StackingContext>(*this, nullptr));
for_each_in_inclusive_subtree_of_type<Box>([&](Box& box) {
if (&box == this)
return IterationDecision::Continue;
for_each_in_subtree_of_type<Box>([&](Box& box) {
const_cast<Painting::PaintableBox*>(box.paint_box())->invalidate_stacking_context();
if (!box.establishes_stacking_context()) {
VERIFY(!box.paint_box()->stacking_context());
return IterationDecision::Continue;
@ -40,6 +46,7 @@ void InitialContainingBlock::build_stacking_context_tree()
void InitialContainingBlock::paint_all_phases(PaintContext& context)
{
build_stacking_context_tree_if_needed();
context.painter().fill_rect(enclosing_int_rect(paint_box()->absolute_rect()), context.palette().base());
context.painter().translate(-context.viewport_rect().location());
paint_box()->stacking_context()->paint(context);