LibWeb: Add a barebones SVGTextContentElement with getNumberOfChars()

This commit is contained in:
Andreas Kling 2022-03-20 11:20:06 +01:00
parent e212514bbf
commit 5d672717aa
Notes: sideshowbarker 2024-07-17 17:03:44 +09:00
9 changed files with 69 additions and 1 deletions

View File

@ -90,6 +90,7 @@
#include <LibWeb/Bindings/SVGPolylineElementWrapper.h>
#include <LibWeb/Bindings/SVGRectElementWrapper.h>
#include <LibWeb/Bindings/SVGSVGElementWrapper.h>
#include <LibWeb/Bindings/SVGTextContentElementWrapper.h>
#include <LibWeb/Bindings/TextWrapper.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Node.h>
@ -335,6 +336,8 @@ NodeWrapper* wrap(JS::GlobalObject& global_object, DOM::Node& node)
return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<SVG::SVGPathElement>(node)));
if (is<SVG::SVGRectElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<SVG::SVGRectElement>(node)));
if (is<SVG::SVGTextContentElement>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<SVG::SVGTextContentElement>(node)));
if (is<DOM::Element>(node))
return static_cast<NodeWrapper*>(wrap_impl(global_object, verify_cast<DOM::Element>(node)));
if (is<DOM::DocumentFragment>(node))

View File

@ -278,6 +278,8 @@
#include <LibWeb/Bindings/SVGRectElementPrototype.h>
#include <LibWeb/Bindings/SVGSVGElementConstructor.h>
#include <LibWeb/Bindings/SVGSVGElementPrototype.h>
#include <LibWeb/Bindings/SVGTextContentElementConstructor.h>
#include <LibWeb/Bindings/SVGTextContentElementPrototype.h>
#include <LibWeb/Bindings/ScreenConstructor.h>
#include <LibWeb/Bindings/ScreenPrototype.h>
#include <LibWeb/Bindings/SelectionConstructor.h>
@ -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) \

View File

@ -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)

View File

@ -85,6 +85,7 @@
#include <LibWeb/SVG/SVGPolylineElement.h>
#include <LibWeb/SVG/SVGRectElement.h>
#include <LibWeb/SVG/SVGSVGElement.h>
#include <LibWeb/SVG/SVGTextContentElement.h>
#include <LibWeb/SVG/TagNames.h>
namespace Web::DOM {
@ -275,6 +276,8 @@ NonnullRefPtr<Element> 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.

View File

@ -520,6 +520,7 @@ class SVGPolygonElementWrapper;
class SVGPolylineElementWrapper;
class SVGRectElementWrapper;
class SVGSVGElementWrapper;
class SVGTextContentElementWrapper;
class TextDecoderWrapper;
class TextEncoderWrapper;
class TextMetricsWrapper;

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Utf16View.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/SVG/SVGTextContentElement.h>
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();
}
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/SVG/SVGGraphicsElement.h>
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;
};
}

View File

@ -0,0 +1,8 @@
#import <SVG/SVGGraphicsElement.idl>
[Exposed=Window]
interface SVGTextContentElement : SVGGraphicsElement {
long getNumberOfChars();
};

View File

@ -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 \