1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 18:37:35 +00:00

LibWeb: Change StackingContext::hit_test() to accept callback

This change modifies hit_test() to no longer return the first paintable
encountered at a specified position. Instead, this function accepts a
callback that is invoked for each paintable located at a position, in
hit-testing order.

This modification will allow us to reuse this call for
`Document.elementsFromPoint()` in upcoming changes.
This commit is contained in:
Aliaksandr Kalenik 2024-02-13 21:34:07 +01:00 committed by Andreas Kling
parent 15d151ee66
commit 9c99182b1e
11 changed files with 120 additions and 104 deletions

View file

@ -26,15 +26,14 @@ Layout::SVGGraphicsBox const& SVGPathPaintable::layout_box() const
return static_cast<Layout::SVGGraphicsBox const&>(layout_node());
}
Optional<HitTestResult> SVGPathPaintable::hit_test(CSSPixelPoint position, HitTestType type) const
TraversalDecision SVGPathPaintable::hit_test(CSSPixelPoint position, HitTestType type, Function<TraversalDecision(HitTestResult)> const& callback) const
{
auto result = SVGGraphicsPaintable::hit_test(position, type);
if (!result.has_value() || !computed_path().has_value())
return {};
if (!computed_path().has_value())
return TraversalDecision::Continue;
auto transformed_bounding_box = computed_transforms().svg_to_css_pixels_transform().map_to_quad(computed_path()->bounding_box());
if (!transformed_bounding_box.contains(position.to_type<float>()))
return {};
return result;
return TraversalDecision::Continue;
return SVGGraphicsPaintable::hit_test(position, type, callback);
}
static Gfx::Painter::WindingRule to_gfx_winding_rule(SVG::FillRule fill_rule)