LibWeb: Simplify reverse child traversal in StackingContext::hit_test()

No need for manual index fiddling, use Vector::in_reverse().
This commit is contained in:
Jelle Raaijmakers 2025-08-29 00:43:29 +02:00 committed by Andreas Kling
commit 8bbb3429b4
Notes: github-actions[bot] 2025-08-28 23:26:09 +00:00

View file

@ -398,11 +398,10 @@ TraversalDecision StackingContext::hit_test(CSSPixelPoint position, HitTestType
// 7. the child stacking contexts with positive stack levels (least positive first).
// NOTE: Hit testing follows reverse painting order, that's why the conditions here are reversed.
for (ssize_t i = m_children.size() - 1; i >= 0; --i) {
auto const& child = *m_children[i];
if (child.paintable_box().computed_values().z_index().value_or(0) <= 0)
for (auto const* child : m_children.in_reverse()) {
if (child->paintable_box().computed_values().z_index().value_or(0) <= 0)
break;
if (child.hit_test(transformed_position, type, callback) == TraversalDecision::Break)
if (child->hit_test(transformed_position, type, callback) == TraversalDecision::Break)
return TraversalDecision::Break;
}
@ -449,11 +448,10 @@ TraversalDecision StackingContext::hit_test(CSSPixelPoint position, HitTestType
// 2. the child stacking contexts with negative stack levels (most negative first).
// NOTE: Hit testing follows reverse painting order, that's why the conditions here are reversed.
for (ssize_t i = m_children.size() - 1; i >= 0; --i) {
auto const& child = *m_children[i];
if (child.paintable_box().computed_values().z_index().value_or(0) >= 0)
for (auto const* child : m_children.in_reverse()) {
if (child->paintable_box().computed_values().z_index().value_or(0) >= 0)
break;
if (child.hit_test(transformed_position, type, callback) == TraversalDecision::Break)
if (child->hit_test(transformed_position, type, callback) == TraversalDecision::Break)
return TraversalDecision::Break;
}