diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 49713280c6..4a31ff407e 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -553,6 +553,7 @@ set(SOURCES SVG/SVGTextElement.cpp SVG/SVGTextPositioningElement.cpp SVG/SVGTitleElement.cpp + SVG/SVGTSpanElement.cpp SVG/SVGUseElement.cpp SVG/TagNames.cpp SVG/ViewBox.cpp diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index 468b724cb9..e606e15880 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -99,6 +99,7 @@ #include #include #include +#include #include #include #include @@ -465,6 +466,8 @@ static WebIDL::ExceptionOr> create_svg_element(JS::Re return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); if (local_name == SVG::TagNames::title) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); + if (local_name == SVG::TagNames::tspan) + return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); if (local_name == SVG::TagNames::use) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); diff --git a/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.cpp new file mode 100644 index 0000000000..95ebf24a74 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.cpp @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::SVG { + +SVGTSpanElement::SVGTSpanElement(DOM::Document& document, DOM::QualifiedName qualified_name) + : SVGTextPositioningElement(document, move(qualified_name)) +{ +} + +JS::ThrowCompletionOr SVGTSpanElement::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "SVGTSpanElement")); + + return {}; +} + +JS::GCPtr SVGTSpanElement::create_layout_node(NonnullRefPtr style) +{ + // Text must be within an SVG element. + if (shadow_including_first_ancestor_of_type()) + return heap().allocate_without_realm(document(), *this, move(style)); + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.h b/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.h new file mode 100644 index 0000000000..e540434808 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::SVG { + +// https://svgwg.org/svg2-draft/text.html#InterfaceSVGTSpanElement +class SVGTSpanElement : public SVGTextPositioningElement { + WEB_PLATFORM_OBJECT(SVGTSpanElement, SVGTextPositioningElement); + +public: + virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; + +protected: + SVGTSpanElement(DOM::Document&, DOM::QualifiedName); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl b/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl new file mode 100644 index 0000000000..1712e166ec --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTSpanElement.idl @@ -0,0 +1,6 @@ +#import + +// https://svgwg.org/svg2-draft/text.html#InterfaceSVGTSpanElement +[Exposed=Window] +interface SVGTSpanElement : SVGTextPositioningElement { +}; diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.h b/Userland/Libraries/LibWeb/SVG/TagNames.h index 963a00db9e..7a37c5d760 100644 --- a/Userland/Libraries/LibWeb/SVG/TagNames.h +++ b/Userland/Libraries/LibWeb/SVG/TagNames.h @@ -21,7 +21,8 @@ namespace Web::SVG::TagNames { __ENUMERATE_SVG_TAG(polyline) \ __ENUMERATE_SVG_TAG(rect) \ __ENUMERATE_SVG_TAG(svg) \ - __ENUMERATE_SVG_TAG(text) + __ENUMERATE_SVG_TAG(text) \ + __ENUMERATE_SVG_TAG(tspan) #define ENUMERATE_SVG_TAGS \ ENUMERATE_SVG_GRAPHICS_TAGS \ diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 79373af21f..dad7ea04ba 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -228,6 +228,7 @@ libweb_js_bindings(SVG/SVGTextContentElement) libweb_js_bindings(SVG/SVGTextElement) libweb_js_bindings(SVG/SVGTextPositioningElement) libweb_js_bindings(SVG/SVGTitleElement) +libweb_js_bindings(SVG/SVGTSpanElement) libweb_js_bindings(SVG/SVGUseElement) libweb_js_bindings(Selection/Selection) libweb_js_bindings(UIEvents/FocusEvent)