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.
This commit is contained in:
Luke 2021-04-06 17:58:20 +01:00 committed by Andreas Kling
parent 9e338a2be2
commit e3d01c5e10
Notes: sideshowbarker 2024-07-18 20:43:09 +09:00
9 changed files with 14 additions and 13 deletions

View File

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

View File

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

View File

@ -45,7 +45,7 @@ public:
void content_frame_did_load(Badge<FrameLoader>);
virtual void inserted_into(Node&) override;
virtual void inserted() override;
protected:
RefPtr<Frame> m_content_frame;

View File

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

View File

@ -40,7 +40,7 @@ public:
virtual RefPtr<Layout::Node> 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&);

View File

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

View File

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

View File

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

View File

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