From e3d01c5e10e18e8bf5239b49ecf0b198121a8189 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 6 Apr 2021 17:58:20 +0100 Subject: [PATCH] LibWeb: Make the node mutation event functions spec compliant This particularly affects the insertion steps and the removed steps. The insertion steps no longer take into the parent that the node was inserted to, as per the spec. Due to this, I have renamed the function from "inserted_into" to simply "inserted". None of the users of the insertion steps was using it anyway. The removed steps now take a pointer to the old parent instead of a reference. This is because it is optional according to the spec and old parent is null when running the removal steps for the descendants of a node that just got removed. This commit does not affect HTMLScriptElement as there is a bit more to that, which is better suited for a separate commit. Also adds in the adopted steps as they will be used later. --- Userland/Libraries/LibWeb/DOM/Node.h | 5 +++-- Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/FrameHostElement.h | 2 +- Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h | 2 +- Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h | 2 +- Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp | 2 +- Userland/Libraries/LibWeb/HTML/HTMLStyleElement.h | 2 +- 9 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index ecdf0c42e7..d1a71bc768 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -136,9 +136,10 @@ public: Element* parent_element(); const Element* parent_element() const; - virtual void inserted_into(Node&); - virtual void removed_from(Node&) { } + virtual void inserted(); + virtual void removed_from(Node*) { } virtual void children_changed() { } + virtual void adopted_from(const Document&) { } const Layout::Node* layout_node() const { return m_layout_node; } Layout::Node* layout_node() { return m_layout_node; } diff --git a/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp b/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp index 8215fbd61b..5364774250 100644 --- a/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/FrameHostElement.cpp @@ -41,9 +41,9 @@ FrameHostElement::~FrameHostElement() { } -void FrameHostElement::inserted_into(Node& parent) +void FrameHostElement::inserted() { - HTMLElement::inserted_into(parent); + HTMLElement::inserted(); if (!is_connected()) return; if (auto* frame = document().frame()) diff --git a/Userland/Libraries/LibWeb/HTML/FrameHostElement.h b/Userland/Libraries/LibWeb/HTML/FrameHostElement.h index f23868fb5d..c8d6aa819c 100644 --- a/Userland/Libraries/LibWeb/HTML/FrameHostElement.h +++ b/Userland/Libraries/LibWeb/HTML/FrameHostElement.h @@ -45,7 +45,7 @@ public: void content_frame_did_load(Badge); - virtual void inserted_into(Node&) override; + virtual void inserted() override; protected: RefPtr m_content_frame; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp index 7d8cce2ef6..95efd33ca6 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.cpp @@ -54,9 +54,9 @@ void HTMLIFrameElement::parse_attribute(const FlyString& name, const String& val load_src(value); } -void HTMLIFrameElement::inserted_into(Node& parent) +void HTMLIFrameElement::inserted() { - FrameHostElement::inserted_into(parent); + FrameHostElement::inserted(); if (is_connected()) load_src(attribute(HTML::AttributeNames::src)); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h index 75e6b424bc..bc92e1a839 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLIFrameElement.h @@ -40,7 +40,7 @@ public: virtual RefPtr create_layout_node() override; private: - virtual void inserted_into(Node&) override; + virtual void inserted() override; virtual void parse_attribute(const FlyString& name, const String& value) override; void load_src(const String&); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 88ea62c331..692515335d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -47,9 +47,9 @@ HTMLLinkElement::~HTMLLinkElement() { } -void HTMLLinkElement::inserted_into(Node& node) +void HTMLLinkElement::inserted() { - HTMLElement::inserted_into(node); + HTMLElement::inserted(); if (m_relationship & Relationship::Stylesheet && !(m_relationship & Relationship::Alternate)) { m_css_loader.load_from_url(document().complete_url(href())); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h index fc0df34bad..84a59d853e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h @@ -39,7 +39,7 @@ public: HTMLLinkElement(DOM::Document&, QualifiedName); virtual ~HTMLLinkElement() override; - virtual void inserted_into(Node&) override; + virtual void inserted() override; String rel() const { return attribute(HTML::AttributeNames::rel); } String type() const { return attribute(HTML::AttributeNames::type); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp index 9dece219dc..7dd3d51fcb 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.cpp @@ -60,7 +60,7 @@ void HTMLStyleElement::children_changed() HTMLElement::children_changed(); } -void HTMLStyleElement::removed_from(Node& old_parent) +void HTMLStyleElement::removed_from(Node* old_parent) { if (m_css_loader.style_sheet()) { // FIXME: Remove the sheet from the document diff --git a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.h b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.h index 93e59720d5..1a4545ccf3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLStyleElement.h @@ -40,7 +40,7 @@ public: virtual ~HTMLStyleElement() override; virtual void children_changed() override; - virtual void removed_from(Node&) override; + virtual void removed_from(Node*) override; private: CSSLoader m_css_loader;