diff --git a/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp b/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp index 77a3600956..db09082939 100644 --- a/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp +++ b/Userland/Libraries/LibWeb/Bindings/NodeWrapperFactory.cpp @@ -90,6 +90,7 @@ #include #include #include +#include #include #include #include @@ -335,6 +336,8 @@ NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node) return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) return static_cast(wrap_impl(global_object, verify_cast(node))); + if (is(node)) + return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) return static_cast(wrap_impl(global_object, verify_cast(node))); if (is(node)) diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h index cdb1566b73..805a6f6663 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h +++ b/Userland/Libraries/LibWeb/Bindings/WindowObjectHelper.h @@ -278,6 +278,8 @@ #include #include #include +#include +#include #include #include #include @@ -476,6 +478,7 @@ ADD_WINDOW_OBJECT_INTERFACE(SVGPolylineElement) \ ADD_WINDOW_OBJECT_INTERFACE(SVGRectElement) \ ADD_WINDOW_OBJECT_INTERFACE(SVGSVGElement) \ + ADD_WINDOW_OBJECT_INTERFACE(SVGTextContentElement) \ ADD_WINDOW_OBJECT_INTERFACE(Text) \ ADD_WINDOW_OBJECT_INTERFACE(TextDecoder) \ ADD_WINDOW_OBJECT_INTERFACE(TextEncoder) \ diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 232c313415..e5895b71ac 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -322,6 +322,7 @@ set(SOURCES SVG/SVGPolylineElement.cpp SVG/SVGRectElement.cpp SVG/SVGSVGElement.cpp + SVG/SVGTextContentElement.cpp SVG/TagNames.cpp SVG/ViewBox.cpp Selection/Selection.cpp @@ -580,6 +581,7 @@ libweb_js_wrapper(SVG/SVGPolygonElement) libweb_js_wrapper(SVG/SVGPolylineElement) libweb_js_wrapper(SVG/SVGRectElement) libweb_js_wrapper(SVG/SVGSVGElement) +libweb_js_wrapper(SVG/SVGTextContentElement) libweb_js_wrapper(Selection/Selection) libweb_js_wrapper(UIEvents/FocusEvent) libweb_js_wrapper(UIEvents/KeyboardEvent) diff --git a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp index b5e0234eed..1e7cc2f1d5 100644 --- a/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp +++ b/Userland/Libraries/LibWeb/DOM/ElementFactory.cpp @@ -85,6 +85,7 @@ #include #include #include +#include #include namespace Web::DOM { @@ -275,6 +276,8 @@ NonnullRefPtr create_element(Document& document, FlyString local_name, return adopt_ref(*new SVG::SVGRectElement(document, move(qualified_name))); if (lowercase_tag_name == SVG::TagNames::g) return adopt_ref(*new SVG::SVGGElement(document, move(qualified_name))); + if (lowercase_tag_name == SVG::TagNames::text) + return adopt_ref(*new SVG::SVGTextContentElement(document, move(qualified_name))); // FIXME: If name is a valid custom element name, then return HTMLElement. diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 3dcbffa507..42de3509cc 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -520,6 +520,7 @@ class SVGPolygonElementWrapper; class SVGPolylineElementWrapper; class SVGRectElementWrapper; class SVGSVGElementWrapper; +class SVGTextContentElementWrapper; class TextDecoderWrapper; class TextEncoderWrapper; class TextMetricsWrapper; diff --git a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp new file mode 100644 index 0000000000..b71329c634 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::SVG { + +SVGTextContentElement::SVGTextContentElement(DOM::Document& document, DOM::QualifiedName qualified_name) + : SVGGraphicsElement(document, move(qualified_name)) +{ +} + +// https://svgwg.org/svg2-draft/text.html#__svg__SVGTextContentElement__getNumberOfChars +int SVGTextContentElement::get_number_of_chars() const +{ + return AK::utf8_to_utf16(child_text_content()).size(); +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h new file mode 100644 index 0000000000..e80708bbf5 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022, Andreas Kling + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::SVG { + +// https://svgwg.org/svg2-draft/text.html#InterfaceSVGTextContentElement +class SVGTextContentElement : public SVGGraphicsElement { +public: + using WrapperType = Bindings::SVGTextContentElementWrapper; + + SVGTextContentElement(DOM::Document&, DOM::QualifiedName); + + int get_number_of_chars() const; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.idl b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.idl new file mode 100644 index 0000000000..a063b628c7 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTextContentElement.idl @@ -0,0 +1,8 @@ +#import + +[Exposed=Window] +interface SVGTextContentElement : SVGGraphicsElement { + + long getNumberOfChars(); + +}; diff --git a/Userland/Libraries/LibWeb/SVG/TagNames.h b/Userland/Libraries/LibWeb/SVG/TagNames.h index d1b4150a73..8593a204ce 100644 --- a/Userland/Libraries/LibWeb/SVG/TagNames.h +++ b/Userland/Libraries/LibWeb/SVG/TagNames.h @@ -19,7 +19,8 @@ namespace Web::SVG::TagNames { __ENUMERATE_SVG_TAG(polygon) \ __ENUMERATE_SVG_TAG(polyline) \ __ENUMERATE_SVG_TAG(rect) \ - __ENUMERATE_SVG_TAG(svg) + __ENUMERATE_SVG_TAG(svg) \ + __ENUMERATE_SVG_TAG(text) #define ENUMERATE_SVG_TAGS \ ENUMERATE_SVG_GRAPHICS_TAGS \