1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:04:57 +00:00

LibWeb: Use a precalculated list of positioned descendants for painting

This allows us to avoid the need for costly traversals to gather
boxes that have been saved during the construction of the stacking
context tree.

No behavior change intended.
This commit is contained in:
Aliaksandr Kalenik 2024-03-02 18:36:52 +01:00 committed by Andreas Kling
parent cd0302426f
commit d5e74b1bdc

View file

@ -206,32 +206,23 @@ void StackingContext::paint_internal(PaintContext& context) const
// Draw positioned descendants with z-index `0` or `auto` in tree order. (step 8)
// FIXME: There's more to this step that we have yet to understand and implement.
paintable().for_each_in_subtree([&context](Paintable const& paintable) {
auto const& z_index = paintable.computed_values().z_index();
if (!paintable.is_positioned() || (z_index.has_value() && z_index.value() != 0)) {
return paintable.stacking_context()
? TraversalDecision::SkipChildrenAndContinue
: TraversalDecision::Continue;
}
for (auto const& paintable : m_positioned_descendants_with_stack_level_0_and_stacking_contexts) {
if (!paintable.is_positioned())
continue;
// At this point, `paintable_box` is a positioned descendant with z-index: auto.
// FIXME: This is basically duplicating logic found elsewhere in this same function. Find a way to make this more elegant.
auto exit_decision = TraversalDecision::Continue;
auto* parent_paintable = paintable.parent();
if (parent_paintable)
parent_paintable->before_children_paint(context, PaintPhase::Foreground);
if (auto* child = paintable.stacking_context()) {
paint_child(context, *child);
exit_decision = TraversalDecision::SkipChildrenAndContinue;
} else {
paint_node_as_stacking_context(paintable, context);
}
if (parent_paintable)
parent_paintable->after_children_paint(context, PaintPhase::Foreground);
return exit_decision;
});
};
// Stacking contexts formed by positioned descendants with z-indices greater than or equal to 1 in z-index order
// (smallest first) then tree order. (Step 9)