From 07b332e17c979cca05e6d5be42c65e7377257de2 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Sat, 23 Sep 2023 08:56:49 +1200 Subject: [PATCH] LibWeb: Add IDL definition for SVGScriptElement It does not currently handle any of the actual scripting, but this should at least allow us to create an instance of the element. The test being added here isn't actually testing much, but before the previous commit we used to crash parsing the page due to a TODO(). --- .../Text/expected/SVG/svg-script-element.txt | 1 + .../Text/input/SVG/svg-script-element.html | 7 ++++ Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/DOM/ElementFactory.cpp | 3 ++ Userland/Libraries/LibWeb/DOM/Node.h | 1 + .../Libraries/LibWeb/SVG/SVGScriptElement.cpp | 22 ++++++++++++ .../Libraries/LibWeb/SVG/SVGScriptElement.h | 34 +++++++++++++++++++ .../Libraries/LibWeb/SVG/SVGScriptElement.idl | 8 +++++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 9 files changed, 78 insertions(+) create mode 100644 Tests/LibWeb/Text/expected/SVG/svg-script-element.txt create mode 100644 Tests/LibWeb/Text/input/SVG/svg-script-element.html create mode 100644 Userland/Libraries/LibWeb/SVG/SVGScriptElement.cpp create mode 100644 Userland/Libraries/LibWeb/SVG/SVGScriptElement.h create mode 100644 Userland/Libraries/LibWeb/SVG/SVGScriptElement.idl diff --git a/Tests/LibWeb/Text/expected/SVG/svg-script-element.txt b/Tests/LibWeb/Text/expected/SVG/svg-script-element.txt new file mode 100644 index 0000000000..5cb0c6c0bc --- /dev/null +++ b/Tests/LibWeb/Text/expected/SVG/svg-script-element.txt @@ -0,0 +1 @@ + Name = SVGScriptElement diff --git a/Tests/LibWeb/Text/input/SVG/svg-script-element.html b/Tests/LibWeb/Text/input/SVG/svg-script-element.html new file mode 100644 index 0000000000..1fb734fdbe --- /dev/null +++ b/Tests/LibWeb/Text/input/SVG/svg-script-element.html @@ -0,0 +1,7 @@ + + + diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 926dca29ff..6e61c412c6 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -569,6 +569,7 @@ set(SOURCES SVG/SVGPolylineElement.cpp SVG/SVGRectElement.cpp SVG/SVGRadialGradientElement.cpp + SVG/SVGScriptElement.cpp SVG/SVGSVGElement.cpp SVG/SVGStopElement.cpp SVG/SVGStyleElement.cpp diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index 0646ce35c2..3514ce8cef 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -98,6 +98,7 @@ #include #include #include +#include #include #include #include @@ -472,6 +473,8 @@ static JS::GCPtr create_svg_element(JS::Realm& realm, Document& return realm.heap().allocate(realm, document, move(qualified_name)); if (local_name == SVG::TagNames::use) return realm.heap().allocate(realm, document, move(qualified_name)); + if (local_name == SVG::TagNames::script) + return realm.heap().allocate(realm, document, move(qualified_name)); return nullptr; } diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index 62aadf7834..5bd932328f 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -76,6 +76,7 @@ public: virtual bool is_svg_container() const { return false; } virtual bool is_svg_element() const { return false; } virtual bool is_svg_graphics_element() const { return false; } + virtual bool is_svg_script_element() const { return false; } virtual bool is_svg_svg_element() const { return false; } virtual bool is_svg_use_element() const { return false; } diff --git a/Userland/Libraries/LibWeb/SVG/SVGScriptElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGScriptElement.cpp new file mode 100644 index 0000000000..5a4c2b525e --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGScriptElement.cpp @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2023, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::SVG { + +SVGScriptElement::SVGScriptElement(DOM::Document& document, DOM::QualifiedName qualified_name) + : SVGElement(document, move(qualified_name)) +{ +} + +void SVGScriptElement::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "SVGScriptElement")); +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGScriptElement.h b/Userland/Libraries/LibWeb/SVG/SVGScriptElement.h new file mode 100644 index 0000000000..e215f6611e --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGScriptElement.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023, Shannon Booth + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::SVG { + +// https://www.w3.org/TR/SVG/interact.html#InterfaceSVGScriptElement +class SVGScriptElement : public SVGElement { + WEB_PLATFORM_OBJECT(SVGScriptElement, SVGElement); + +public: +protected: + SVGScriptElement(DOM::Document&, DOM::QualifiedName); + + virtual void initialize(JS::Realm&) override; + +private: + virtual bool is_svg_script_element() const final { return true; } +}; + +} + +namespace Web::DOM { + +template<> +inline bool Node::fast_is() const { return is_svg_script_element(); } + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGScriptElement.idl b/Userland/Libraries/LibWeb/SVG/SVGScriptElement.idl new file mode 100644 index 0000000000..86249d75cc --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGScriptElement.idl @@ -0,0 +1,8 @@ +// https://www.w3.org/TR/SVG/interact.html#InterfaceSVGScriptElement +[Exposed=Window] +interface SVGScriptElement : SVGElement { + [Reflect] attribute DOMString type; + [Reflect=crossorigin] attribute DOMString? crossOrigin; +}; + +// FIXME: SVGScriptElement includes SVGURIReference; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index ceee073820..b32e0d1d03 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -238,6 +238,7 @@ libweb_js_bindings(SVG/SVGPolygonElement) libweb_js_bindings(SVG/SVGPolylineElement) libweb_js_bindings(SVG/SVGRadialGradientElement) libweb_js_bindings(SVG/SVGRectElement) +libweb_js_bindings(SVG/SVGScriptElement) libweb_js_bindings(SVG/SVGSVGElement) libweb_js_bindings(SVG/SVGStopElement) libweb_js_bindings(SVG/SVGStyleElement)