diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp index 8d267a4254..667683a75e 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/WrapperGenerator/IDLGenerators.cpp @@ -56,6 +56,8 @@ static bool is_wrappable_type(Type const& type) return true; if (type.name == "Blob") return true; + if (type.name == "Path2D") + return true; return false; } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index 515c8dbbb1..ae967d4d12 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -279,6 +279,8 @@ #include #include #include +#include +#include #include #include #include @@ -518,6 +520,7 @@ ADD_WINDOW_OBJECT_INTERFACE(NodeIterator) \ ADD_WINDOW_OBJECT_INTERFACE(NodeList) \ ADD_WINDOW_OBJECT_INTERFACE(PageTransitionEvent) \ + ADD_WINDOW_OBJECT_INTERFACE(Path2D) \ ADD_WINDOW_OBJECT_INTERFACE(Performance) \ ADD_WINDOW_OBJECT_INTERFACE(PerformanceTiming) \ ADD_WINDOW_OBJECT_INTERFACE(ProcessingInstruction) \ diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 4ee4d3af27..ed47ff7b0c 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -232,6 +232,7 @@ set(SOURCES HTML/Parser/HTMLTokenizer.cpp HTML/Parser/ListOfActiveFormattingElements.cpp HTML/Parser/StackOfOpenElements.cpp + HTML/Path2D.cpp HTML/Scripting/ClassicScript.cpp HTML/Scripting/Environments.cpp HTML/Scripting/ExceptionReporter.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 9f3923903e..a3739e5109 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -295,6 +295,7 @@ class MessagePort; struct NavigationParams; class Origin; class PageTransitionEvent; +class Path2D; struct PolicyContainer; class PromiseRejectionEvent; class WorkerDebugConsoleClient; @@ -582,6 +583,7 @@ class NodeListWrapper; class NodeWrapper; class OptionConstructor; class PageTransitionEventWrapper; +class Path2DWrapper; class PerformanceTimingWrapper; class PerformanceWrapper; class ProcessingInstructionWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index a8bc6478dd..732ace1ebf 100644 --- a/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Userland/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.cpp b/Userland/Libraries/LibWeb/HTML/Path2D.cpp new file mode 100644 index 0000000000..5d28efdb88 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Path2D.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2022, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d +Path2D::Path2D(Optional, String>> const& path) +{ + // 1. Let output be a new Path2D object. + // 2. If path is not given, then return output. + if (!path.has_value()) + return; + + // 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.) + if (path->has>()) { + this->path() = path->get>()->path(); + return; + } + + dbgln("TODO: Implement constructing Path2D object with an SVG path string"); + + // FIXME: 4. Let svgPath be the result of parsing and interpreting path according to SVG 2's rules for path data. [SVG] + // FIXME: 5. Let (x, y) be the last point in svgPath. + // FIXME: 6. Add all the subpaths, if any, from svgPath to output. + // FIXME: 7. Create a new subpath in output with (x, y) as the only point in the subpath. + // FIXME: 8. Return output. +} + +} diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.h b/Userland/Libraries/LibWeb/HTML/Path2D.h new file mode 100644 index 0000000000..8f58a4589a --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Path2D.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include +#include + +namespace Web::HTML { + +// https://html.spec.whatwg.org/multipage/canvas.html#path2d +class Path2D + : public RefCounted + , public Bindings::Wrappable + , public CanvasPath { + + AK_MAKE_NONCOPYABLE(Path2D); + AK_MAKE_NONMOVABLE(Path2D); + +public: + using WrapperType = Bindings::Path2DWrapper; + + static NonnullRefPtr create_with_global_object(Bindings::WindowObject&, Optional, String>> const& path) { return adopt_ref(*new Path2D(path)); } + static NonnullRefPtr create(Optional, String>> const& path) { return adopt_ref(*new Path2D(path)); } + ~Path2D() = default; + +private: + Path2D(Optional, String>> const&); +}; + +} diff --git a/Userland/Libraries/LibWeb/HTML/Path2D.idl b/Userland/Libraries/LibWeb/HTML/Path2D.idl new file mode 100644 index 0000000000..64264dd2c9 --- /dev/null +++ b/Userland/Libraries/LibWeb/HTML/Path2D.idl @@ -0,0 +1,11 @@ +#import + +// https://html.spec.whatwg.org/multipage/canvas.html#path2d +[Exposed=(Window,Worker)] +interface Path2D { + constructor(optional (Path2D or DOMString) path); + + // FIXME: undefined addPath(Path2D path, optional DOMMatrix2DInit transform = {}); +}; + +Path2D includes CanvasPath; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 4a5b25691b..9e91f119fd 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -145,6 +145,7 @@ libweb_js_wrapper(HTML/MessageChannel) libweb_js_wrapper(HTML/MessageEvent) libweb_js_wrapper(HTML/MessagePort) libweb_js_wrapper(HTML/PageTransitionEvent) +libweb_js_wrapper(HTML/Path2D) libweb_js_wrapper(HTML/PromiseRejectionEvent) libweb_js_wrapper(HTML/Storage) libweb_js_wrapper(HTML/SubmitEvent)