mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-20 01:37:39 +03:00
LibWeb: Add a barebones SVGTextContentElement with getNumberOfChars()
This commit is contained in:
parent
e212514bbf
commit
5d672717aa
Notes:
sideshowbarker
2024-07-17 17:03:44 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5d672717aa
@ -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))
|
||||
|
@ -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) \
|
||||
|
@ -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)
|
||||
|
@ -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.
|
||||
|
||||
|
@ -520,6 +520,7 @@ class SVGPolygonElementWrapper;
|
||||
class SVGPolylineElementWrapper;
|
||||
class SVGRectElementWrapper;
|
||||
class SVGSVGElementWrapper;
|
||||
class SVGTextContentElementWrapper;
|
||||
class TextDecoderWrapper;
|
||||
class TextEncoderWrapper;
|
||||
class TextMetricsWrapper;
|
||||
|
24
Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp
Normal file
24
Userland/Libraries/LibWeb/SVG/SVGTextContentElement.cpp
Normal 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();
|
||||
}
|
||||
|
||||
}
|
23
Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h
Normal file
23
Userland/Libraries/LibWeb/SVG/SVGTextContentElement.h
Normal 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;
|
||||
};
|
||||
|
||||
}
|
8
Userland/Libraries/LibWeb/SVG/SVGTextContentElement.idl
Normal file
8
Userland/Libraries/LibWeb/SVG/SVGTextContentElement.idl
Normal file
@ -0,0 +1,8 @@
|
||||
#import <SVG/SVGGraphicsElement.idl>
|
||||
|
||||
[Exposed=Window]
|
||||
interface SVGTextContentElement : SVGGraphicsElement {
|
||||
|
||||
long getNumberOfChars();
|
||||
|
||||
};
|
@ -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 \
|
||||
|
Loading…
Reference in New Issue
Block a user