mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibWeb: Make CanvasGradient GC-allocated
This commit is contained in:
parent
369dd42d67
commit
0d2fee351a
Notes:
sideshowbarker
2024-07-17 09:49:33 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/0d2fee351a Pull-request: https://github.com/SerenityOS/serenity/pull/14816 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/linusg ✅
5 changed files with 32 additions and 27 deletions
|
@ -449,7 +449,6 @@ class URLSearchParamsIterator;
|
|||
|
||||
namespace Web::Bindings {
|
||||
class BlobWrapper;
|
||||
class CanvasGradientWrapper;
|
||||
class CryptoWrapper;
|
||||
class DOMExceptionWrapper;
|
||||
class DOMPointWrapper;
|
||||
|
|
|
@ -42,19 +42,22 @@ public:
|
|||
return my_drawing_state().stroke_style.to_string();
|
||||
}
|
||||
|
||||
NonnullRefPtr<CanvasGradient> create_radial_gradient(double x0, double y0, double r0, double x1, double y1, double r1)
|
||||
JS::NonnullGCPtr<CanvasGradient> 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);
|
||||
auto& window = static_cast<IncludingClass&>(*this).global_object();
|
||||
return CanvasGradient::create_radial(window, x0, y0, r0, x1, y1, r1);
|
||||
}
|
||||
|
||||
NonnullRefPtr<CanvasGradient> create_linear_gradient(double x0, double y0, double x1, double y1)
|
||||
JS::NonnullGCPtr<CanvasGradient> create_linear_gradient(double x0, double y0, double x1, double y1)
|
||||
{
|
||||
return CanvasGradient::create_linear(x0, y0, x1, y1);
|
||||
auto& window = static_cast<IncludingClass&>(*this).global_object();
|
||||
return CanvasGradient::create_linear(window, x0, y0, x1, y1);
|
||||
}
|
||||
|
||||
NonnullRefPtr<CanvasGradient> create_conic_gradient(double start_angle, double x, double y)
|
||||
JS::NonnullGCPtr<CanvasGradient> create_conic_gradient(double start_angle, double x, double y)
|
||||
{
|
||||
return CanvasGradient::create_conic(start_angle, x, y);
|
||||
auto& window = static_cast<IncludingClass&>(*this).global_object();
|
||||
return CanvasGradient::create_conic(window, start_angle, x, y);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -5,12 +5,14 @@
|
|||
*/
|
||||
|
||||
#include <AK/QuickSort.h>
|
||||
#include <LibWeb/Bindings/CanvasGradientPrototype.h>
|
||||
#include <LibWeb/DOM/ExceptionOr.h>
|
||||
#include <LibWeb/HTML/CanvasGradient.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
NonnullRefPtr<CanvasGradient> CanvasGradient::create_radial(double x0, double y0, double r0, double x1, double y1, double r1)
|
||||
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_radial(HTML::Window& window, double x0, double y0, double r0, double x1, double y1, double r1)
|
||||
{
|
||||
(void)x0;
|
||||
(void)y0;
|
||||
|
@ -18,29 +20,31 @@ NonnullRefPtr<CanvasGradient> CanvasGradient::create_radial(double x0, double y0
|
|||
(void)x1;
|
||||
(void)y1;
|
||||
(void)r1;
|
||||
return adopt_ref(*new CanvasGradient(Type::Radial));
|
||||
return *window.heap().allocate<CanvasGradient>(window.realm(), window, Type::Radial);
|
||||
}
|
||||
|
||||
NonnullRefPtr<CanvasGradient> CanvasGradient::create_linear(double x0, double y0, double x1, double y1)
|
||||
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_linear(HTML::Window& window, double x0, double y0, double x1, double y1)
|
||||
{
|
||||
(void)x0;
|
||||
(void)y0;
|
||||
(void)x1;
|
||||
(void)y1;
|
||||
return adopt_ref(*new CanvasGradient(Type::Linear));
|
||||
return *window.heap().allocate<CanvasGradient>(window.realm(), window, Type::Linear);
|
||||
}
|
||||
|
||||
NonnullRefPtr<CanvasGradient> CanvasGradient::create_conic(double start_angle, double x, double y)
|
||||
JS::NonnullGCPtr<CanvasGradient> CanvasGradient::create_conic(HTML::Window& window, double start_angle, double x, double y)
|
||||
{
|
||||
(void)start_angle;
|
||||
(void)x;
|
||||
(void)y;
|
||||
return adopt_ref(*new CanvasGradient(Type::Conic));
|
||||
return *window.heap().allocate<CanvasGradient>(window.realm(), window, Type::Conic);
|
||||
}
|
||||
|
||||
CanvasGradient::CanvasGradient(Type type)
|
||||
: m_type(type)
|
||||
CanvasGradient::CanvasGradient(HTML::Window& window, Type type)
|
||||
: PlatformObject(window.realm())
|
||||
, m_type(type)
|
||||
{
|
||||
set_prototype(&window.ensure_web_prototype<Bindings::CanvasGradientPrototype>("CanvasGradient"));
|
||||
}
|
||||
|
||||
CanvasGradient::~CanvasGradient() = default;
|
||||
|
|
|
@ -6,15 +6,14 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefCounted.h>
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibWeb/Bindings/Wrappable.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
class CanvasGradient final
|
||||
: public RefCounted<CanvasGradient>
|
||||
, public Bindings::Wrappable {
|
||||
class CanvasGradient final : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(CanvasGradient, Bindings::PlatformObject);
|
||||
|
||||
public:
|
||||
enum class Type {
|
||||
Linear,
|
||||
|
@ -22,18 +21,16 @@ public:
|
|||
Conic,
|
||||
};
|
||||
|
||||
using WrapperType = Bindings::CanvasGradientWrapper;
|
||||
|
||||
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);
|
||||
static JS::NonnullGCPtr<CanvasGradient> create_radial(HTML::Window&, double x0, double y0, double r0, double x1, double y1, double r1);
|
||||
static JS::NonnullGCPtr<CanvasGradient> create_linear(HTML::Window&, double x0, double y0, double x1, double y1);
|
||||
static JS::NonnullGCPtr<CanvasGradient> create_conic(HTML::Window&, double start_angle, double x, double y);
|
||||
|
||||
DOM::ExceptionOr<void> add_color_stop(double offset, String const& color);
|
||||
|
||||
~CanvasGradient();
|
||||
|
||||
private:
|
||||
explicit CanvasGradient(Type);
|
||||
CanvasGradient(HTML::Window&, Type);
|
||||
|
||||
Type m_type {};
|
||||
|
||||
|
@ -46,3 +43,5 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
WRAPPER_HACK(CanvasGradient, Web::HTML)
|
||||
|
|
|
@ -61,7 +61,7 @@ libweb_js_wrapper(Geometry/DOMPointReadOnly)
|
|||
libweb_js_wrapper(Geometry/DOMRect)
|
||||
libweb_js_wrapper(Geometry/DOMRectList)
|
||||
libweb_js_wrapper(Geometry/DOMRectReadOnly)
|
||||
libweb_js_wrapper(HTML/CanvasGradient)
|
||||
libweb_js_wrapper(HTML/CanvasGradient NO_INSTANCE)
|
||||
libweb_js_wrapper(HTML/CanvasRenderingContext2D NO_INSTANCE)
|
||||
libweb_js_wrapper(HTML/CloseEvent NO_INSTANCE)
|
||||
libweb_js_wrapper(HTML/DOMParser NO_INSTANCE)
|
||||
|
|
Loading…
Reference in a new issue