diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasRect.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasRect.h
new file mode 100644
index 0000000000..4ff12891c8
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasRect.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2022, Sam Atkins
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+namespace Web::HTML {
+
+// https://html.spec.whatwg.org/multipage/canvas.html#canvasrect
+class CanvasRect {
+public:
+ virtual ~CanvasRect() = default;
+
+ virtual void fill_rect(float x, float y, float width, float height) = 0;
+ virtual void stroke_rect(float x, float y, float width, float height) = 0;
+ virtual void clear_rect(float x, float y, float width, float height) = 0;
+
+protected:
+ CanvasRect() = default;
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasRect.idl b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasRect.idl
new file mode 100644
index 0000000000..3ac61cf1d4
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasRect.idl
@@ -0,0 +1,6 @@
+// https://html.spec.whatwg.org/multipage/canvas.html#canvasrect
+interface mixin CanvasRect {
+ undefined clearRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
+ undefined fillRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
+ undefined strokeRect(unrestricted double x, unrestricted double y, unrestricted double w, unrestricted double h);
+};
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
index 9aa60b1efe..ef11f68dcd 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
@@ -18,6 +18,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -36,7 +37,8 @@ class CanvasRenderingContext2D
, public CanvasPath
, public CanvasState
, public CanvasTransform
- , public CanvasFillStrokeStyles {
+ , public CanvasFillStrokeStyles
+ , public CanvasRect {
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
@@ -47,9 +49,9 @@ public:
static NonnullRefPtr create(HTMLCanvasElement& element) { return adopt_ref(*new CanvasRenderingContext2D(element)); }
~CanvasRenderingContext2D();
- void fill_rect(float x, float y, float width, float height);
- void stroke_rect(float x, float y, float width, float height);
- void clear_rect(float x, float y, float width, float height);
+ virtual void fill_rect(float x, float y, float width, float height) override;
+ virtual void stroke_rect(float x, float y, float width, float height) override;
+ virtual void clear_rect(float x, float y, float width, float height) override;
DOM::ExceptionOr draw_image(CanvasImageSource const&, float destination_x, float destination_y);
DOM::ExceptionOr draw_image(CanvasImageSource const&, float destination_x, float destination_y, float destination_width, float destination_height);
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
index 2a7de9dffd..cbb2e90138 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
@@ -4,6 +4,7 @@
#import
#import
#import
+#import
#import
#import
#import
@@ -12,10 +13,6 @@
[Exposed=Window]
interface CanvasRenderingContext2D {
- undefined fillRect(double x, double y, double w, double h);
- undefined strokeRect(double x, double y, double w, double h);
- undefined clearRect(double x, double y, double w, double h);
-
undefined beginPath();
// FIXME: `DOMString` should be `CanvasFillRule`
undefined fill(optional DOMString fillRule = "nonzero");
@@ -51,4 +48,5 @@ interface CanvasRenderingContext2D {
CanvasRenderingContext2D includes CanvasState;
CanvasRenderingContext2D includes CanvasTransform;
CanvasRenderingContext2D includes CanvasFillStrokeStyles;
+CanvasRenderingContext2D includes CanvasRect;
CanvasRenderingContext2D includes CanvasPath;