1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:57:35 +00:00

LibWeb: Add support for SVG <tspan> elements

This commit is contained in:
MacDue 2023-07-22 19:34:51 +01:00 committed by Andreas Kling
parent 0e12503586
commit b30a1b957d
7 changed files with 74 additions and 1 deletions

View file

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

View file

@ -99,6 +99,7 @@
#include <LibWeb/SVG/SVGStopElement.h>
#include <LibWeb/SVG/SVGStyleElement.h>
#include <LibWeb/SVG/SVGSymbolElement.h>
#include <LibWeb/SVG/SVGTSpanElement.h>
#include <LibWeb/SVG/SVGTextElement.h>
#include <LibWeb/SVG/SVGTitleElement.h>
#include <LibWeb/SVG/SVGUseElement.h>
@ -465,6 +466,8 @@ static WebIDL::ExceptionOr<JS::GCPtr<SVG::SVGElement>> create_svg_element(JS::Re
return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGTextElement>(realm, document, move(qualified_name)));
if (local_name == SVG::TagNames::title)
return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGTitleElement>(realm, document, move(qualified_name)));
if (local_name == SVG::TagNames::tspan)
return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGTSpanElement>(realm, document, move(qualified_name)));
if (local_name == SVG::TagNames::use)
return MUST_OR_THROW_OOM(realm.heap().allocate<SVG::SVGUseElement>(realm, document, move(qualified_name)));

View file

@ -0,0 +1,34 @@
/*
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Layout/SVGTextBox.h>
#include <LibWeb/SVG/SVGTSpanElement.h>
#include <LibWeb/SVG/SVGTextElement.h>
namespace Web::SVG {
SVGTSpanElement::SVGTSpanElement(DOM::Document& document, DOM::QualifiedName qualified_name)
: SVGTextPositioningElement(document, move(qualified_name))
{
}
JS::ThrowCompletionOr<void> SVGTSpanElement::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGTSpanElementPrototype>(realm, "SVGTSpanElement"));
return {};
}
JS::GCPtr<Layout::Node> SVGTSpanElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{
// Text must be within an SVG <text> element.
if (shadow_including_first_ancestor_of_type<SVGTextElement>())
return heap().allocate_without_realm<Layout::SVGTextBox>(document(), *this, move(style));
return {};
}
}

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/SVG/SVGTextPositioningElement.h>
#include <LibWeb/WebIDL/ExceptionOr.h>
namespace Web::SVG {
// https://svgwg.org/svg2-draft/text.html#InterfaceSVGTSpanElement
class SVGTSpanElement : public SVGTextPositioningElement {
WEB_PLATFORM_OBJECT(SVGTSpanElement, SVGTextPositioningElement);
public:
virtual JS::GCPtr<Layout::Node> create_layout_node(NonnullRefPtr<CSS::StyleProperties>) override;
protected:
SVGTSpanElement(DOM::Document&, DOM::QualifiedName);
virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override;
};
}

View file

@ -0,0 +1,6 @@
#import <SVG/SVGTextPositioningElement.idl>
// https://svgwg.org/svg2-draft/text.html#InterfaceSVGTSpanElement
[Exposed=Window]
interface SVGTSpanElement : SVGTextPositioningElement {
};

View file

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

View file

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