From e2e4e6da52a228b0bdac28073622c78661328c2b Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 8 Jun 2023 11:46:44 -0400 Subject: [PATCH] LibWeb: Implement the SVG title element --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + .../Libraries/LibWeb/DOM/ElementFactory.cpp | 3 ++ Userland/Libraries/LibWeb/Forward.h | 1 + .../Libraries/LibWeb/SVG/SVGTitleElement.cpp | 47 +++++++++++++++++++ .../Libraries/LibWeb/SVG/SVGTitleElement.h | 25 ++++++++++ .../Libraries/LibWeb/SVG/SVGTitleElement.idl | 6 +++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 7 files changed, 84 insertions(+) create mode 100644 Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp create mode 100644 Userland/Libraries/LibWeb/SVG/SVGTitleElement.h create mode 100644 Userland/Libraries/LibWeb/SVG/SVGTitleElement.idl diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 395b5dd89b..5aaeedfa3e 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -524,6 +524,7 @@ set(SOURCES SVG/SVGStopElement.cpp SVG/SVGSymbolElement.cpp SVG/SVGTextContentElement.cpp + SVG/SVGTitleElement.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 c8bb809813..d63b9aeb9b 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 @@ -459,6 +460,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::text) 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::use) return MUST_OR_THROW_OOM(realm.heap().allocate(realm, document, move(qualified_name))); diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 6167d011f8..d15b6456fd 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -559,6 +559,7 @@ class SVGPolygonElement; class SVGPolylineElement; class SVGRectElement; class SVGSVGElement; +class SVGTitleElement; } namespace Web::UIEvents { diff --git a/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp new file mode 100644 index 0000000000..03590689f0 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include + +namespace Web::SVG { + +SVGTitleElement::SVGTitleElement(DOM::Document& document, DOM::QualifiedName qualified_name) + : SVGElement(document, move(qualified_name)) +{ +} + +JS::ThrowCompletionOr SVGTitleElement::initialize(JS::Realm& realm) +{ + MUST_OR_THROW_OOM(Base::initialize(realm)); + set_prototype(&Bindings::ensure_web_prototype(realm, "SVGTitleElement")); + + return {}; +} + +JS::GCPtr SVGTitleElement::create_layout_node(NonnullRefPtr) +{ + return nullptr; +} + +void SVGTitleElement::children_changed() +{ + Base::children_changed(); + + auto* page = document().page(); + if (!page) + return; + if (document().browsing_context() != &page->top_level_browsing_context()) + return; + + auto* document_element = document().document_element(); + + if (document_element == parent() && is(document_element)) + page->client().page_did_change_title(document().title()); +} + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTitleElement.h b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.h new file mode 100644 index 0000000000..f7fe41b085 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023, Tim Flynn + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include + +namespace Web::SVG { + +class SVGTitleElement final : public SVGElement { + WEB_PLATFORM_OBJECT(SVGTitleElement, SVGElement); + +private: + SVGTitleElement(DOM::Document&, DOM::QualifiedName); + + virtual JS::ThrowCompletionOr initialize(JS::Realm&) override; + + virtual JS::GCPtr create_layout_node(NonnullRefPtr) override; + virtual void children_changed() override; +}; + +} diff --git a/Userland/Libraries/LibWeb/SVG/SVGTitleElement.idl b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.idl new file mode 100644 index 0000000000..5b22ac3e03 --- /dev/null +++ b/Userland/Libraries/LibWeb/SVG/SVGTitleElement.idl @@ -0,0 +1,6 @@ +#import + +// https://svgwg.org/svg2-draft/struct.html#InterfaceSVGSVGElement +[Exposed=Window] +interface SVGTitleElement : SVGElement { +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index ad69a5a78a..4396976183 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -213,6 +213,7 @@ libweb_js_bindings(SVG/SVGSVGElement) libweb_js_bindings(SVG/SVGStopElement) libweb_js_bindings(SVG/SVGSymbolElement) libweb_js_bindings(SVG/SVGTextContentElement) +libweb_js_bindings(SVG/SVGTitleElement) libweb_js_bindings(SVG/SVGUseElement) libweb_js_bindings(Selection/Selection) libweb_js_bindings(UIEvents/FocusEvent)