summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h3
-rw-r--r--Userland/Libraries/LibWeb/CMakeLists.txt2
-rw-r--r--Userland/Libraries/LibWeb/Forward.h1
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp53
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasGradient.h40
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasGradient.idl5
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp15
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h5
-rw-r--r--Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl5
9 files changed, 129 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
index fa9deee190..d63c92023a 100644
--- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
+++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h
@@ -22,6 +22,8 @@
#include <LibWeb/Bindings/CSSStyleRulePrototype.h>
#include <LibWeb/Bindings/CSSStyleSheetConstructor.h>
#include <LibWeb/Bindings/CSSStyleSheetPrototype.h>
+#include <LibWeb/Bindings/CanvasGradientConstructor.h>
+#include <LibWeb/Bindings/CanvasGradientPrototype.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DConstructor.h>
#include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h>
#include <LibWeb/Bindings/CharacterDataConstructor.h>
@@ -303,6 +305,7 @@
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleDeclaration) \
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleRule) \
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleSheet) \
+ ADD_WINDOW_OBJECT_INTERFACE(CanvasGradient) \
ADD_WINDOW_OBJECT_INTERFACE(CanvasRenderingContext2D) \
ADD_WINDOW_OBJECT_INTERFACE(CharacterData) \
ADD_WINDOW_OBJECT_INTERFACE(CloseEvent) \
diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt
index 3204cc484f..1f62f6bccb 100644
--- a/Userland/Libraries/LibWeb/CMakeLists.txt
+++ b/Userland/Libraries/LibWeb/CMakeLists.txt
@@ -99,6 +99,7 @@ set(SOURCES
HTML/AttributeNames.cpp
HTML/BrowsingContext.cpp
HTML/BrowsingContextContainer.cpp
+ HTML/CanvasGradient.cpp
HTML/CanvasRenderingContext2D.cpp
HTML/DOMParser.cpp
HTML/DOMStringMap.cpp
@@ -406,6 +407,7 @@ libweb_js_wrapper(DOM/Text)
libweb_js_wrapper(Encoding/TextEncoder)
libweb_js_wrapper(Geometry/DOMRect)
libweb_js_wrapper(Geometry/DOMRectReadOnly)
+libweb_js_wrapper(HTML/CanvasGradient)
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
libweb_js_wrapper(HTML/CloseEvent)
libweb_js_wrapper(HTML/DOMParser)
diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h
index 48f72e22e6..e9b1786257 100644
--- a/Userland/Libraries/LibWeb/Forward.h
+++ b/Userland/Libraries/LibWeb/Forward.h
@@ -307,6 +307,7 @@ namespace Web::Bindings {
class AbortControllerWrapper;
class AbortSignalWrapper;
class AttributeWrapper;
+class CanvasGradientWrapper;
class CanvasRenderingContext2DWrapper;
class CharacterDataWrapper;
class CloseEventWrapper;
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp
new file mode 100644
index 0000000000..91673b6150
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/HTML/CanvasGradient.h>
+
+namespace Web::HTML {
+
+NonnullRefPtr<CanvasGradient> CanvasGradient::create_radial(double x0, double y0, double r0, double x1, double y1, double r1)
+{
+ (void)x0;
+ (void)y0;
+ (void)r0;
+ (void)x1;
+ (void)y1;
+ (void)r1;
+ return adopt_ref(*new CanvasGradient(Type::Radial));
+}
+
+NonnullRefPtr<CanvasGradient> CanvasGradient::create_linear(double x0, double y0, double x1, double y1)
+{
+ (void)x0;
+ (void)y0;
+ (void)x1;
+ (void)y1;
+ return adopt_ref(*new CanvasGradient(Type::Linear));
+}
+
+NonnullRefPtr<CanvasGradient> CanvasGradient::create_conic(double start_angle, double x, double y)
+{
+ (void)start_angle;
+ (void)x;
+ (void)y;
+ return adopt_ref(*new CanvasGradient(Type::Conic));
+}
+
+CanvasGradient::CanvasGradient(Type type)
+ : m_type(type)
+{
+}
+
+CanvasGradient::~CanvasGradient()
+{
+}
+
+void CanvasGradient::add_color_stop(double offset, String const& color)
+{
+ dbgln("CanvasGradient#addColorStop({}, '{}')", offset, color);
+}
+
+}
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.h b/Userland/Libraries/LibWeb/HTML/CanvasGradient.h
new file mode 100644
index 0000000000..03e1e529d7
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/RefCounted.h>
+#include <LibWeb/Bindings/Wrappable.h>
+
+namespace Web::HTML {
+
+class CanvasGradient final
+ : public RefCounted<CanvasGradient>
+ , public Bindings::Wrappable {
+public:
+ using WrapperType = Bindings::CanvasGradientWrapper;
+
+ enum class Type {
+ Linear,
+ Radial,
+ Conic,
+ };
+
+ static NonnullRefPtr<CanvasGradient> create_radial(double x0, double y0, double r0, double x1, double y1, double r1);
+ static NonnullRefPtr<CanvasGradient> create_linear(double x0, double y0, double x1, double y1);
+ static NonnullRefPtr<CanvasGradient> create_conic(double start_angle, double x, double y);
+
+ void add_color_stop(double offset, String const& color);
+
+ ~CanvasGradient();
+
+private:
+ explicit CanvasGradient(Type);
+
+ Type m_type {};
+};
+
+}
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasGradient.idl b/Userland/Libraries/LibWeb/HTML/CanvasGradient.idl
new file mode 100644
index 0000000000..c76ed30e01
--- /dev/null
+++ b/Userland/Libraries/LibWeb/HTML/CanvasGradient.idl
@@ -0,0 +1,5 @@
+[Exposed=(Window,Worker)]
+interface CanvasGradient {
+ // opaque object
+ undefined addColorStop(double offset, DOMString color);
+};
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
index 4a521bc1e4..2b3c44321d 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp
@@ -496,4 +496,19 @@ CanvasRenderingContext2D::PreparedText CanvasRenderingContext2D::prepare_text(St
return prepared_text;
}
+NonnullRefPtr<CanvasGradient> CanvasRenderingContext2D::create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1)
+{
+ return CanvasGradient::create_radial(x0, y0, r0, x1, y1, r1);
+}
+
+NonnullRefPtr<CanvasGradient> CanvasRenderingContext2D::create_linear_gradient(double x0, double y0, double x1, double y1)
+{
+ return CanvasGradient::create_linear(x0, y0, x1, y1);
+}
+
+NonnullRefPtr<CanvasGradient> CanvasRenderingContext2D::create_conic_gradient(double start_angle, double x, double y)
+{
+ return CanvasGradient::create_conic(start_angle, x, y);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
index f7713a0633..4e902bbd83 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.h
@@ -14,6 +14,7 @@
#include <LibGfx/Path.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/ExceptionOr.h>
+#include <LibWeb/HTML/CanvasGradient.h>
#include <LibWeb/Layout/InlineNode.h>
#include <LibWeb/Layout/LineBox.h>
@@ -83,6 +84,10 @@ public:
RefPtr<TextMetrics> measure_text(String const& text);
+ NonnullRefPtr<CanvasGradient> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1);
+ NonnullRefPtr<CanvasGradient> create_linear_gradient(double x0, double y0, double x1, double y1);
+ NonnullRefPtr<CanvasGradient> create_conic_gradient(double start_angle, double x, double y);
+
private:
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
index 6eaada5149..fabf573f41 100644
--- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
+++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.idl
@@ -40,4 +40,9 @@ interface CanvasRenderingContext2D {
readonly attribute HTMLCanvasElement canvas;
TextMetrics measureText(DOMString text);
+
+ CanvasGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1);
+ CanvasGradient createLinearGradient(double x0, double y0, double x1, double y1);
+ CanvasGradient createConicGradient(double startAngle, double x, double y);
+
};