From 52d6df5ee5834bb7edf0e0f533a5069c4ebeb348 Mon Sep 17 00:00:00 2001 From: Jonah Date: Wed, 5 Jul 2023 20:24:51 -0500 Subject: [PATCH] LibWeb: Add the MathML Element This patch introduces the MathML element, which provides the interface all MathML elements are built from. --- Userland/Libraries/LibWeb/CMakeLists.txt | 1 + Userland/Libraries/LibWeb/Forward.h | 4 +++ .../Libraries/LibWeb/MathML/MathMLElement.cpp | 27 ++++++++++++++ .../Libraries/LibWeb/MathML/MathMLElement.h | 36 +++++++++++++++++++ .../Libraries/LibWeb/MathML/MathMLElement.idl | 9 +++++ Userland/Libraries/LibWeb/idl_files.cmake | 1 + 6 files changed, 78 insertions(+) create mode 100644 Userland/Libraries/LibWeb/MathML/MathMLElement.cpp create mode 100644 Userland/Libraries/LibWeb/MathML/MathMLElement.h create mode 100644 Userland/Libraries/LibWeb/MathML/MathMLElement.idl diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index d9f62a2000e..26d13ad6729 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -450,6 +450,7 @@ set(SOURCES Loader/ProxyMappings.cpp Loader/Resource.cpp Loader/ResourceLoader.cpp + MathML/MathMLElement.cpp MimeSniff/MimeType.cpp Namespace.cpp NavigationTiming/EntryNames.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 6237a38cd9f..2bab4b6c8e4 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -497,6 +497,10 @@ enum class LayoutMode; struct LayoutState; } +namespace Web::MathML { +class MathMLElement; +} + namespace Web::MimeSniff { class MimeType; } diff --git a/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp b/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp new file mode 100644 index 00000000000..039341a0d75 --- /dev/null +++ b/Userland/Libraries/LibWeb/MathML/MathMLElement.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2023, Jonah Shafran + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::MathML { + +MathMLElement::~MathMLElement() = default; + +MathMLElement::MathMLElement(DOM::Document& document, DOM::QualifiedName qualified_name) + : DOM::Element(document, move(qualified_name)) +{ +} + +void MathMLElement::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "MathMLElement")); + + m_dataset = MUST(HTML::DOMStringMap::create(*this)); +} + +} diff --git a/Userland/Libraries/LibWeb/MathML/MathMLElement.h b/Userland/Libraries/LibWeb/MathML/MathMLElement.h new file mode 100644 index 00000000000..fb076f42eab --- /dev/null +++ b/Userland/Libraries/LibWeb/MathML/MathMLElement.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2023, Jonah Shafran + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::MathML { + +class MathMLElement : public DOM::Element + , public HTML::GlobalEventHandlers { + WEB_PLATFORM_OBJECT(MathMLElement, Element); + +public: + virtual ~MathMLElement() override; + + HTML::DOMStringMap* dataset() { return m_dataset.ptr(); } + HTML::DOMStringMap const* dataset() const { return m_dataset.ptr(); } + +protected: + virtual DOM::EventTarget& global_event_handlers_to_event_target(FlyString const&) override { return *this; } + +private: + MathMLElement(DOM::Document&, DOM::QualifiedName); + + virtual void initialize(JS::Realm&) override; + + JS::GCPtr m_dataset; +}; + +} diff --git a/Userland/Libraries/LibWeb/MathML/MathMLElement.idl b/Userland/Libraries/LibWeb/MathML/MathMLElement.idl new file mode 100644 index 00000000000..3e12dd72119 --- /dev/null +++ b/Userland/Libraries/LibWeb/MathML/MathMLElement.idl @@ -0,0 +1,9 @@ +#import +#import +#import + +// https://w3c.github.io/mathml-core/#dom-and-javascript +[Exposed=Window] +interface MathMLElement : Element { }; +MathMLElement includes GlobalEventHandlers; +MathMLElement includes HTMLOrSVGElement; // FIXME: We technically use HTMLOrForeignElement which is a rename of HTMLOrSVGElement, when that change is upstreamed we should update here diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 53295dbe21c..473fe9308ca 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -187,6 +187,7 @@ libweb_js_bindings(HighResolutionTime/Performance) libweb_js_bindings(Internals/Internals) libweb_js_bindings(IntersectionObserver/IntersectionObserver) libweb_js_bindings(IntersectionObserver/IntersectionObserverEntry) +libweb_js_bindings(MathML/MathMLElement) libweb_js_bindings(NavigationTiming/PerformanceTiming) libweb_js_bindings(PerformanceTimeline/PerformanceEntry) libweb_js_bindings(RequestIdleCallback/IdleDeadline)