diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.h b/Userland/Libraries/LibWeb/DOM/CharacterData.h index f80ff1ad8a..82967ccc0d 100644 --- a/Userland/Libraries/LibWeb/DOM/CharacterData.h +++ b/Userland/Libraries/LibWeb/DOM/CharacterData.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include #include @@ -14,6 +15,7 @@ namespace Web::DOM { class CharacterData : public Node + , public ChildNode , public NonDocumentTypeChildNode { public: using WrapperType = Bindings::CharacterDataWrapper; diff --git a/Userland/Libraries/LibWeb/DOM/CharacterData.idl b/Userland/Libraries/LibWeb/DOM/CharacterData.idl index 3e1d978ca0..4a67a12cd3 100644 --- a/Userland/Libraries/LibWeb/DOM/CharacterData.idl +++ b/Userland/Libraries/LibWeb/DOM/CharacterData.idl @@ -6,4 +6,7 @@ interface CharacterData : Node { readonly attribute Element? nextElementSibling; readonly attribute Element? previousElementSibling; + // FIXME: This should come from a ChildNode mixin + [CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove(); + }; diff --git a/Userland/Libraries/LibWeb/DOM/ChildNode.h b/Userland/Libraries/LibWeb/DOM/ChildNode.h new file mode 100644 index 0000000000..d038406b44 --- /dev/null +++ b/Userland/Libraries/LibWeb/DOM/ChildNode.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2021, Luke Wilde + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +namespace Web::DOM { + +// https://dom.spec.whatwg.org/#childnode +template +class ChildNode { +public: + // https://dom.spec.whatwg.org/#dom-childnode-remove + void remove_binding() + { + auto* node = static_cast(this); + + // 1. If this’s parent is null, then return. + if (!node->parent()) + return; + + // 2. Remove this. + node->remove(); + } + +protected: + ChildNode() = default; +}; + +} diff --git a/Userland/Libraries/LibWeb/DOM/DocumentType.h b/Userland/Libraries/LibWeb/DOM/DocumentType.h index e74494249e..b40389ab9f 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentType.h +++ b/Userland/Libraries/LibWeb/DOM/DocumentType.h @@ -7,11 +7,14 @@ #pragma once #include +#include #include namespace Web::DOM { -class DocumentType final : public Node { +class DocumentType final + : public Node + , public ChildNode { public: using WrapperType = Bindings::DocumentTypeWrapper; diff --git a/Userland/Libraries/LibWeb/DOM/DocumentType.idl b/Userland/Libraries/LibWeb/DOM/DocumentType.idl index 813b0e5b47..531cb3a259 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentType.idl +++ b/Userland/Libraries/LibWeb/DOM/DocumentType.idl @@ -4,4 +4,7 @@ interface DocumentType : Node { readonly attribute DOMString publicId; readonly attribute DOMString systemId; + // FIXME: This should come from a ChildNode mixin + [CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove(); + }; diff --git a/Userland/Libraries/LibWeb/DOM/Element.h b/Userland/Libraries/LibWeb/DOM/Element.h index b02d77b7c7..ca45079646 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.h +++ b/Userland/Libraries/LibWeb/DOM/Element.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +25,7 @@ namespace Web::DOM { class Element : public ParentNode + , public ChildNode , public NonDocumentTypeChildNode { public: diff --git a/Userland/Libraries/LibWeb/DOM/Element.idl b/Userland/Libraries/LibWeb/DOM/Element.idl index 6b3f04676b..8b99a0cc72 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.idl +++ b/Userland/Libraries/LibWeb/DOM/Element.idl @@ -37,4 +37,7 @@ interface Element : Node { DOMRect getBoundingClientRect(); + // FIXME: This should come from a ChildNode mixin + [CEReactions, Unscopable, ImplementedAs=remove_binding] undefined remove(); + };