diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.h
index cefa427ec0e..39890d270bb 100644
--- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.h
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.h
@@ -27,6 +27,9 @@ public:
virtual void clip(StringView fill_rule) = 0;
virtual void clip(Path2D& path, StringView fill_rule) = 0;
+ virtual bool is_point_in_path(double x, double y, StringView fill_rule) = 0;
+ virtual bool is_point_in_path(Path2D const& path, double x, double y, StringView fill_rule) = 0;
+
protected:
CanvasDrawPath() = default;
};
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.idl b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.idl
index 75d7ada6e46..d893f86fadb 100644
--- a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.idl
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasDrawPath.idl
@@ -18,8 +18,10 @@ interface mixin CanvasDrawPath {
// FIXME: `DOMString` should be `CanvasFillRule`
undefined clip(Path2D path, optional DOMString fillRule = "nonzero");
- [FIXME] boolean isPointInPath(unrestricted double x, unrestricted double y, optional CanvasFillRule fillRule = "nonzero");
- [FIXME] boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional CanvasFillRule fillRule = "nonzero");
+ // FIXME: `DOMString` should be `CanvasFillRule`
+ boolean isPointInPath(unrestricted double x, unrestricted double y, optional DOMString fillRule = "nonzero");
+ // FIXME: `DOMString` should be `CanvasFillRule`
+ boolean isPointInPath(Path2D path, unrestricted double x, unrestricted double y, optional DOMString fillRule = "nonzero");
[FIXME] boolean isPointInStroke(unrestricted double x, unrestricted double y);
[FIXME] boolean isPointInStroke(Path2D path, unrestricted double x, unrestricted double y);
};
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index 282bec46f37..17470ee4c9f 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -542,6 +542,21 @@ void CanvasRenderingContext2D::clip(Path2D& path, StringView fill_rule)
clip_internal(path.path(), parse_fill_rule(fill_rule));
}
+static bool is_point_in_path_internal(Gfx::Path path, double x, double y, StringView fill_rule)
+{
+ return path.contains(Gfx::FloatPoint(x, y), parse_fill_rule(fill_rule));
+}
+
+bool CanvasRenderingContext2D::is_point_in_path(double x, double y, StringView fill_rule)
+{
+ return is_point_in_path_internal(path(), x, y, fill_rule);
+}
+
+bool CanvasRenderingContext2D::is_point_in_path(Path2D const& path, double x, double y, StringView fill_rule)
+{
+ return is_point_in_path_internal(path.path(), x, y, fill_rule);
+}
+
// https://html.spec.whatwg.org/multipage/canvas.html#check-the-usability-of-the-image-argument
WebIDL::ExceptionOr check_usability_of_image(CanvasImageSource const& image)
{
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
index 983e412d99d..2ce3223a274 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
@@ -87,6 +87,9 @@ public:
virtual void clip(StringView fill_rule) override;
virtual void clip(Path2D& path, StringView fill_rule) override;
+ virtual bool is_point_in_path(double x, double y, StringView fill_rule) override;
+ virtual bool is_point_in_path(Path2D const& path, double x, double y, StringView fill_rule) override;
+
virtual bool image_smoothing_enabled() const override;
virtual void set_image_smoothing_enabled(bool) override;
virtual Bindings::ImageSmoothingQuality image_smoothing_quality() const override;