mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:27:45 +00:00
LibWeb: Use (transformed) path bounding quad for SVG path hit testing
This is needed for hit testing the directional arrows on the Street View office tour, and generally makes SVG hit testing more precise. Note: The rough bounding box is hit test first, so this should not be a load more overhead.
This commit is contained in:
parent
d0496ae9b8
commit
809c15d1ee
2 changed files with 15 additions and 0 deletions
|
@ -27,6 +27,19 @@ Layout::SVGGeometryBox const& SVGGeometryPaintable::layout_box() const
|
||||||
return static_cast<Layout::SVGGeometryBox const&>(layout_node());
|
return static_cast<Layout::SVGGeometryBox const&>(layout_node());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Optional<HitTestResult> SVGGeometryPaintable::hit_test(CSSPixelPoint position, HitTestType type) const
|
||||||
|
{
|
||||||
|
auto result = SVGGraphicsPaintable::hit_test(position, type);
|
||||||
|
if (!result.has_value())
|
||||||
|
return {};
|
||||||
|
auto& geometry_element = layout_box().dom_node();
|
||||||
|
auto transformed_bounding_box = layout_box().layout_transform().map_to_quad(
|
||||||
|
const_cast<SVG::SVGGeometryElement&>(geometry_element).get_path().bounding_box());
|
||||||
|
if (!transformed_bounding_box.contains(position.to_type<float>()))
|
||||||
|
return {};
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
|
void SVGGeometryPaintable::paint(PaintContext& context, PaintPhase phase) const
|
||||||
{
|
{
|
||||||
if (!is_visible())
|
if (!is_visible())
|
||||||
|
|
|
@ -17,6 +17,8 @@ class SVGGeometryPaintable final : public SVGGraphicsPaintable {
|
||||||
public:
|
public:
|
||||||
static JS::NonnullGCPtr<SVGGeometryPaintable> create(Layout::SVGGeometryBox const&);
|
static JS::NonnullGCPtr<SVGGeometryPaintable> create(Layout::SVGGeometryBox const&);
|
||||||
|
|
||||||
|
virtual Optional<HitTestResult> hit_test(CSSPixelPoint, HitTestType) const override;
|
||||||
|
|
||||||
virtual void paint(PaintContext&, PaintPhase) const override;
|
virtual void paint(PaintContext&, PaintPhase) const override;
|
||||||
|
|
||||||
Layout::SVGGeometryBox const& layout_box() const;
|
Layout::SVGGeometryBox const& layout_box() const;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue