summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@serenityos.org>2022-08-12 17:37:09 +0100
committerAndreas Kling <kling@serenityos.org>2022-08-14 11:30:40 +0200
commit53b9f364131192517d355e46d4d81b37f4868454 (patch)
tree7e00a983123bcb67585479eee235112e6aa18542 /Userland
parent270c60c5e8477730d09d36a767fbb55ffdacbbda (diff)
downloadserenity-53b9f364131192517d355e46d4d81b37f4868454.zip
LibWeb: Extract CanvasImageData class from CRC2D
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.h26
-rw-r--r--Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.idl14
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h10
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl7
4 files changed, 48 insertions, 9 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.h b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.h
new file mode 100644
index 0000000000..28c182f1f4
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2022, Sam Atkins <atkinssj@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <LibWeb/HTML/ImageData.h>
+
+namespace Web::HTML {
+
+// https://html.spec.whatwg.org/multipage/canvas.html#canvasdrawpath
+class CanvasImageData {
+public:
+ virtual ~CanvasImageData() = default;
+
+ virtual RefPtr<ImageData> create_image_data(int width, int height) const = 0;
+ virtual DOM::ExceptionOr<RefPtr<ImageData>> get_image_data(int x, int y, int width, int height) const = 0;
+ virtual void put_image_data(ImageData const&, float x, float y) = 0;
+
+protected:
+ CanvasImageData() = default;
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.idl b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.idl
new file mode 100644
index 0000000000..9be76e6325
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/Canvas/CanvasImageData.idl
@@ -0,0 +1,14 @@
+#import <HTML/ImageData.idl>
+
+// https://html.spec.whatwg.org/multipage/canvas.html#canvasimagedata
+interface mixin CanvasImageData {
+ // FIXME: Should be `ImageData createImageData([EnforceRange] long sw, [EnforceRange] long sh, optional ImageDataSettings settings = {});`
+ ImageData createImageData(long sw, long sh);
+ // FIXME: ImageData createImageData(ImageData imagedata);
+
+ // FIXME: Should be `ImageData getImageData([EnforceRange] long sx, [EnforceRange] long sy, [EnforceRange] long sw, [EnforceRange] long sh, optional ImageDataSettings settings = {});`
+ ImageData getImageData(long sx, long sy, long sw, long sh);
+
+ undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy);
+ // FIXME: undefined putImageData(ImageData imagedata, [EnforceRange] long dx, [EnforceRange] long dy, [EnforceRange] long dirtyX, [EnforceRange] long dirtyY, [EnforceRange] long dirtyWidth, [EnforceRange] long dirtyHeight);
+};
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
index 89c518a6cf..936a3182ba 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
@@ -19,6 +19,7 @@
#include <LibWeb/HTML/Canvas/CanvasDrawImage.h>
#include <LibWeb/HTML/Canvas/CanvasDrawPath.h>
#include <LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h>
+#include <LibWeb/HTML/Canvas/CanvasImageData.h>
#include <LibWeb/HTML/Canvas/CanvasPath.h>
#include <LibWeb/HTML/Canvas/CanvasRect.h>
#include <LibWeb/HTML/Canvas/CanvasState.h>
@@ -44,7 +45,8 @@ class CanvasRenderingContext2D
, public CanvasRect
, public CanvasDrawPath
, public CanvasText
- , public CanvasDrawImage {
+ , public CanvasDrawImage
+ , public CanvasImageData {
AK_MAKE_NONCOPYABLE(CanvasRenderingContext2D);
AK_MAKE_NONMOVABLE(CanvasRenderingContext2D);
@@ -74,9 +76,9 @@ public:
virtual void fill(String const& fill_rule) override;
virtual void fill(Path2D& path, String const& fill_rule) override;
- RefPtr<ImageData> create_image_data(int width, int height) const;
- DOM::ExceptionOr<RefPtr<ImageData>> get_image_data(int x, int y, int width, int height) const;
- void put_image_data(ImageData const&, float x, float y);
+ virtual RefPtr<ImageData> create_image_data(int width, int height) const override;
+ virtual DOM::ExceptionOr<RefPtr<ImageData>> get_image_data(int x, int y, int width, int height) const override;
+ virtual void put_image_data(ImageData const&, float x, float y) override;
virtual void reset_to_default_state() override;
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
index 35559c34b8..efcf607892 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
@@ -1,8 +1,8 @@
#import <HTML/HTMLCanvasElement.idl>
-#import <HTML/ImageData.idl>
#import <HTML/Canvas/CanvasDrawImage.idl>
#import <HTML/Canvas/CanvasDrawPath.idl>
#import <HTML/Canvas/CanvasFillStrokeStyles.idl>
+#import <HTML/Canvas/CanvasImageData.idl>
#import <HTML/Canvas/CanvasPath.idl>
#import <HTML/Canvas/CanvasRect.idl>
#import <HTML/Canvas/CanvasState.idl>
@@ -15,10 +15,6 @@ interface CanvasRenderingContext2D {
attribute double lineWidth;
- ImageData createImageData(long sw, long sh);
- ImageData getImageData(long sx, long sy, long sw, long sh);
- undefined putImageData(ImageData imagedata, double dx, double dy);
-
[ImplementedAs=canvas_for_binding] readonly attribute HTMLCanvasElement canvas;
};
@@ -30,4 +26,5 @@ CanvasRenderingContext2D includes CanvasRect;
CanvasRenderingContext2D includes CanvasDrawPath;
CanvasRenderingContext2D includes CanvasText;
CanvasRenderingContext2D includes CanvasDrawImage;
+CanvasRenderingContext2D includes CanvasImageData;
CanvasRenderingContext2D includes CanvasPath;