mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 18:47:41 +00:00
LibWeb: Make Path2D GC-allocated
This commit is contained in:
parent
0d2fee351a
commit
2704bcdaaa
5 changed files with 28 additions and 17 deletions
|
@ -155,6 +155,8 @@ static bool impl_is_wrapper(Type const& type)
|
||||||
return true;
|
return true;
|
||||||
if (type.name == "WebGLRenderingContext"sv)
|
if (type.name == "WebGLRenderingContext"sv)
|
||||||
return true;
|
return true;
|
||||||
|
if (type.name == "Path2D"sv)
|
||||||
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -463,7 +463,6 @@ class IdleDeadlineWrapper;
|
||||||
class IntersectionObserverWrapper;
|
class IntersectionObserverWrapper;
|
||||||
class LocationObject;
|
class LocationObject;
|
||||||
class OptionConstructor;
|
class OptionConstructor;
|
||||||
class Path2DWrapper;
|
|
||||||
class RangePrototype;
|
class RangePrototype;
|
||||||
class ResizeObserverWrapper;
|
class ResizeObserverWrapper;
|
||||||
class SelectionWrapper;
|
class SelectionWrapper;
|
||||||
|
|
|
@ -4,13 +4,23 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/Path2DPrototype.h>
|
||||||
#include <LibWeb/HTML/Path2D.h>
|
#include <LibWeb/HTML/Path2D.h>
|
||||||
|
#include <LibWeb/HTML/Window.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d
|
JS::NonnullGCPtr<Path2D> Path2D::create_with_global_object(HTML::Window& window, Optional<Variant<JS::Handle<Path2D>, String>> const& path)
|
||||||
Path2D::Path2D(Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path)
|
|
||||||
{
|
{
|
||||||
|
return *window.heap().allocate<Path2D>(window.realm(), window, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d
|
||||||
|
Path2D::Path2D(HTML::Window& window, Optional<Variant<JS::Handle<Path2D>, String>> const& path)
|
||||||
|
: PlatformObject(window.realm())
|
||||||
|
{
|
||||||
|
set_prototype(&window.ensure_web_prototype<Bindings::Path2DPrototype>("Path2D"));
|
||||||
|
|
||||||
// 1. Let output be a new Path2D object.
|
// 1. Let output be a new Path2D object.
|
||||||
// 2. If path is not given, then return output.
|
// 2. If path is not given, then return output.
|
||||||
if (!path.has_value())
|
if (!path.has_value())
|
||||||
|
@ -18,8 +28,8 @@ Path2D::Path2D(Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path)
|
||||||
|
|
||||||
// 3. If path is a Path2D object, then add all subpaths of path to output and return output.
|
// 3. If path is a Path2D object, then add all subpaths of path to output and return output.
|
||||||
// (In other words, it returns a copy of the argument.)
|
// (In other words, it returns a copy of the argument.)
|
||||||
if (path->has<NonnullRefPtr<Path2D>>()) {
|
if (path->has<JS::Handle<Path2D>>()) {
|
||||||
this->path() = path->get<NonnullRefPtr<Path2D>>()->path();
|
this->path() = path->get<JS::Handle<Path2D>>()->path();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,4 +42,6 @@ Path2D::Path2D(Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path)
|
||||||
// FIXME: 8. Return output.
|
// FIXME: 8. Return output.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path2D::~Path2D() = default;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,29 +8,27 @@
|
||||||
|
|
||||||
#include <AK/RefCounted.h>
|
#include <AK/RefCounted.h>
|
||||||
#include <LibGfx/Path.h>
|
#include <LibGfx/Path.h>
|
||||||
#include <LibWeb/Bindings/Wrappable.h>
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
#include <LibWeb/HTML/Canvas/CanvasPath.h>
|
#include <LibWeb/HTML/Canvas/CanvasPath.h>
|
||||||
|
|
||||||
namespace Web::HTML {
|
namespace Web::HTML {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/canvas.html#path2d
|
// https://html.spec.whatwg.org/multipage/canvas.html#path2d
|
||||||
class Path2D
|
class Path2D final
|
||||||
: public RefCounted<Path2D>
|
: public Bindings::PlatformObject
|
||||||
, public Bindings::Wrappable
|
|
||||||
, public CanvasPath {
|
, public CanvasPath {
|
||||||
|
|
||||||
AK_MAKE_NONCOPYABLE(Path2D);
|
WEB_PLATFORM_OBJECT(Path2D, Bindings::PlatformObject);
|
||||||
AK_MAKE_NONMOVABLE(Path2D);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using WrapperType = Bindings::Path2DWrapper;
|
static JS::NonnullGCPtr<Path2D> create_with_global_object(HTML::Window&, Optional<Variant<JS::Handle<Path2D>, String>> const& path);
|
||||||
|
|
||||||
static NonnullRefPtr<Path2D> create_with_global_object(HTML::Window&, Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path) { return adopt_ref(*new Path2D(path)); }
|
virtual ~Path2D() override;
|
||||||
static NonnullRefPtr<Path2D> create(Optional<Variant<NonnullRefPtr<Path2D>, String>> const& path) { return adopt_ref(*new Path2D(path)); }
|
|
||||||
~Path2D() = default;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Path2D(Optional<Variant<NonnullRefPtr<Path2D>, String>> const&);
|
Path2D(HTML::Window&, Optional<Variant<JS::Handle<Path2D>, String>> const&);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WRAPPER_HACK(Path2D, Web::HTML)
|
||||||
|
|
|
@ -145,7 +145,7 @@ libweb_js_wrapper(HTML/MessageChannel NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/MessageEvent NO_INSTANCE)
|
libweb_js_wrapper(HTML/MessageEvent NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/MessagePort NO_INSTANCE)
|
libweb_js_wrapper(HTML/MessagePort NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/PageTransitionEvent NO_INSTANCE)
|
libweb_js_wrapper(HTML/PageTransitionEvent NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/Path2D)
|
libweb_js_wrapper(HTML/Path2D NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/PromiseRejectionEvent NO_INSTANCE)
|
libweb_js_wrapper(HTML/PromiseRejectionEvent NO_INSTANCE)
|
||||||
libweb_js_wrapper(HTML/Storage)
|
libweb_js_wrapper(HTML/Storage)
|
||||||
libweb_js_wrapper(HTML/SubmitEvent NO_INSTANCE)
|
libweb_js_wrapper(HTML/SubmitEvent NO_INSTANCE)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue