1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 08:18:11 +00:00

LibWeb: Do paint-order traversal in Document::elements_from_point()

Elements are now collected according to paint order as spec says,
replacing the depth-first traversal of the paint tree with hit-testing
on each box.

This change resolves a FIXME in an existing test and adds a new
previously non-working test.
This commit is contained in:
Aliaksandr Kalenik 2024-02-13 21:34:46 +01:00 committed by Andreas Kling
parent 9c99182b1e
commit 9d2809146f
7 changed files with 68 additions and 20 deletions

View file

@ -3829,16 +3829,12 @@ Vector<JS::NonnullGCPtr<Element>> Document::elements_from_point(double x, double
// 3. For each box in the viewport, in paint order, starting with the topmost box, that would be a target for
// hit testing at coordinates x,y even if nothing would be overlapping it, when applying the transforms that
// apply to the descendants of the viewport, append the associated element to sequence.
// FIXME: Paintable box tree order is not the same as paint order. We need a helper to traverse the paint tree in
// paint order with a custom callback.
if (auto const* paintable_box = this->paintable_box(); paintable_box) {
paintable_box->for_each_in_inclusive_subtree_of_type<Painting::PaintableBox>([&](auto& paintable_box) {
if (auto result = paintable_box.hit_test(position, Painting::HitTestType::Exact); result.has_value()) {
if (auto* dom_node = result->dom_node(); dom_node && dom_node->is_element())
sequence.append(*static_cast<Element*>(dom_node));
return Painting::TraversalDecision::Continue;
}
return Painting::TraversalDecision::SkipChildrenAndContinue;
(void)paintable_box->hit_test(position, Painting::HitTestType::Exact, [&](Painting::HitTestResult result) {
auto* dom_node = result.dom_node();
if (dom_node && dom_node->is_element())
sequence.append(*static_cast<Element*>(dom_node));
return Painting::TraversalDecision::Continue;
});
}