mirror of
https://github.com/RGBCube/serenity
synced 2025-05-18 20:25:07 +00:00
LibWeb: Add barebones CanvasGradient object
Also add the CanvasRenderingContext2D APIs to go along with it. Note that it can't be used for anything yet.
This commit is contained in:
parent
545ec334f0
commit
dc3bf32307
10 changed files with 130 additions and 0 deletions
|
@ -3451,6 +3451,7 @@ void generate_prototype_implementation(IDL::Interface const& interface)
|
||||||
#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
|
#include <LibWeb/Bindings/CSSRuleWrapperFactory.h>
|
||||||
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
#include <LibWeb/Bindings/CSSStyleDeclarationWrapper.h>
|
||||||
#include <LibWeb/Bindings/CSSStyleSheetWrapper.h>
|
#include <LibWeb/Bindings/CSSStyleSheetWrapper.h>
|
||||||
|
#include <LibWeb/Bindings/CanvasGradientWrapper.h>
|
||||||
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
#include <LibWeb/Bindings/CanvasRenderingContext2DWrapper.h>
|
||||||
#include <LibWeb/Bindings/CommentWrapper.h>
|
#include <LibWeb/Bindings/CommentWrapper.h>
|
||||||
#include <LibWeb/Bindings/DOMImplementationWrapper.h>
|
#include <LibWeb/Bindings/DOMImplementationWrapper.h>
|
||||||
|
|
|
@ -22,6 +22,8 @@
|
||||||
#include <LibWeb/Bindings/CSSStyleRulePrototype.h>
|
#include <LibWeb/Bindings/CSSStyleRulePrototype.h>
|
||||||
#include <LibWeb/Bindings/CSSStyleSheetConstructor.h>
|
#include <LibWeb/Bindings/CSSStyleSheetConstructor.h>
|
||||||
#include <LibWeb/Bindings/CSSStyleSheetPrototype.h>
|
#include <LibWeb/Bindings/CSSStyleSheetPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/CanvasGradientConstructor.h>
|
||||||
|
#include <LibWeb/Bindings/CanvasGradientPrototype.h>
|
||||||
#include <LibWeb/Bindings/CanvasRenderingContext2DConstructor.h>
|
#include <LibWeb/Bindings/CanvasRenderingContext2DConstructor.h>
|
||||||
#include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h>
|
#include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h>
|
||||||
#include <LibWeb/Bindings/CharacterDataConstructor.h>
|
#include <LibWeb/Bindings/CharacterDataConstructor.h>
|
||||||
|
@ -303,6 +305,7 @@
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleDeclaration) \
|
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleDeclaration) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleRule) \
|
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleRule) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleSheet) \
|
ADD_WINDOW_OBJECT_INTERFACE(CSSStyleSheet) \
|
||||||
|
ADD_WINDOW_OBJECT_INTERFACE(CanvasGradient) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(CanvasRenderingContext2D) \
|
ADD_WINDOW_OBJECT_INTERFACE(CanvasRenderingContext2D) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(CharacterData) \
|
ADD_WINDOW_OBJECT_INTERFACE(CharacterData) \
|
||||||
ADD_WINDOW_OBJECT_INTERFACE(CloseEvent) \
|
ADD_WINDOW_OBJECT_INTERFACE(CloseEvent) \
|
||||||
|
|
|
@ -99,6 +99,7 @@ set(SOURCES
|
||||||
HTML/AttributeNames.cpp
|
HTML/AttributeNames.cpp
|
||||||
HTML/BrowsingContext.cpp
|
HTML/BrowsingContext.cpp
|
||||||
HTML/BrowsingContextContainer.cpp
|
HTML/BrowsingContextContainer.cpp
|
||||||
|
HTML/CanvasGradient.cpp
|
||||||
HTML/CanvasRenderingContext2D.cpp
|
HTML/CanvasRenderingContext2D.cpp
|
||||||
HTML/DOMParser.cpp
|
HTML/DOMParser.cpp
|
||||||
HTML/DOMStringMap.cpp
|
HTML/DOMStringMap.cpp
|
||||||
|
@ -406,6 +407,7 @@ libweb_js_wrapper(DOM/Text)
|
||||||
libweb_js_wrapper(Encoding/TextEncoder)
|
libweb_js_wrapper(Encoding/TextEncoder)
|
||||||
libweb_js_wrapper(Geometry/DOMRect)
|
libweb_js_wrapper(Geometry/DOMRect)
|
||||||
libweb_js_wrapper(Geometry/DOMRectReadOnly)
|
libweb_js_wrapper(Geometry/DOMRectReadOnly)
|
||||||
|
libweb_js_wrapper(HTML/CanvasGradient)
|
||||||
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
|
libweb_js_wrapper(HTML/CanvasRenderingContext2D)
|
||||||
libweb_js_wrapper(HTML/CloseEvent)
|
libweb_js_wrapper(HTML/CloseEvent)
|
||||||
libweb_js_wrapper(HTML/DOMParser)
|
libweb_js_wrapper(HTML/DOMParser)
|
||||||
|
|
|
@ -307,6 +307,7 @@ namespace Web::Bindings {
|
||||||
class AbortControllerWrapper;
|
class AbortControllerWrapper;
|
||||||
class AbortSignalWrapper;
|
class AbortSignalWrapper;
|
||||||
class AttributeWrapper;
|
class AttributeWrapper;
|
||||||
|
class CanvasGradientWrapper;
|
||||||
class CanvasRenderingContext2DWrapper;
|
class CanvasRenderingContext2DWrapper;
|
||||||
class CharacterDataWrapper;
|
class CharacterDataWrapper;
|
||||||
class CloseEventWrapper;
|
class CloseEventWrapper;
|
||||||
|
|
53
Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp
Normal file
53
Userland/Libraries/LibWeb/HTML/CanvasGradient.cpp
Normal file
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
Userland/Libraries/LibWeb/HTML/CanvasGradient.h
Normal file
40
Userland/Libraries/LibWeb/HTML/CanvasGradient.h
Normal file
|
@ -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 {};
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
5
Userland/Libraries/LibWeb/HTML/CanvasGradient.idl
Normal file
5
Userland/Libraries/LibWeb/HTML/CanvasGradient.idl
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
[Exposed=(Window,Worker)]
|
||||||
|
interface CanvasGradient {
|
||||||
|
// opaque object
|
||||||
|
undefined addColorStop(double offset, DOMString color);
|
||||||
|
};
|
|
@ -496,4 +496,19 @@ CanvasRenderingContext2D::PreparedText CanvasRenderingContext2D::prepare_text(St
|
||||||
return prepared_text;
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <LibGfx/Path.h>
|
#include <LibGfx/Path.h>
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
#include <LibWeb/Bindings/Wrappable.h>
|
||||||
#include <LibWeb/DOM/ExceptionOr.h>
|
#include <LibWeb/DOM/ExceptionOr.h>
|
||||||
|
#include <LibWeb/HTML/CanvasGradient.h>
|
||||||
#include <LibWeb/Layout/InlineNode.h>
|
#include <LibWeb/Layout/InlineNode.h>
|
||||||
#include <LibWeb/Layout/LineBox.h>
|
#include <LibWeb/Layout/LineBox.h>
|
||||||
|
|
||||||
|
@ -83,6 +84,10 @@ public:
|
||||||
|
|
||||||
RefPtr<TextMetrics> measure_text(String const& text);
|
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:
|
private:
|
||||||
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
|
explicit CanvasRenderingContext2D(HTMLCanvasElement&);
|
||||||
|
|
||||||
|
|
|
@ -40,4 +40,9 @@ interface CanvasRenderingContext2D {
|
||||||
readonly attribute HTMLCanvasElement canvas;
|
readonly attribute HTMLCanvasElement canvas;
|
||||||
|
|
||||||
TextMetrics measureText(DOMString text);
|
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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue