diff options
author | Luke <luke.wilde@live.co.uk> | 2021-07-05 05:55:02 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-05 12:39:46 +0200 |
commit | 9cae827f0797a48e916d697664b1e3323e5f9966 (patch) | |
tree | 2bd3519b00aacfd3993a5d33081db658a00f716b /Userland | |
parent | a826df773eff63ee0584d7a8a9bf100e23cc6344 (diff) | |
download | serenity-9cae827f0797a48e916d697664b1e3323e5f9966.zip |
LibWeb: Implement Node.contains
Used by Web Components Polyfills.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.h | 2 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOM/Node.idl | 1 |
3 files changed, 9 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 29cf612567..4bfe4dadad 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -649,4 +649,10 @@ bool Node::is_scripting_disabled() const return !document().browsing_context(); } +// https://dom.spec.whatwg.org/#dom-node-contains +bool Node::contains(RefPtr<Node> other) const +{ + return other && other->is_inclusive_descendant_of(*this); +} + } diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h index a4845b5a94..6d8614a717 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.h +++ b/Userland/Libraries/LibWeb/DOM/Node.h @@ -166,6 +166,8 @@ public: bool is_scripting_disabled() const; + bool contains(RefPtr<Node>) const; + // Used for dumping the DOM Tree void serialize_tree_as_json(JsonObjectSerializer<StringBuilder>&) const; diff --git a/Userland/Libraries/LibWeb/DOM/Node.idl b/Userland/Libraries/LibWeb/DOM/Node.idl index 00fb334369..edd50ca84f 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.idl +++ b/Userland/Libraries/LibWeb/DOM/Node.idl @@ -21,6 +21,7 @@ interface Node : EventTarget { Node replaceChild(Node node, Node child); [ImplementedAs=pre_remove] Node removeChild(Node child); [ImplementedAs=clone_node_binding] Node cloneNode(optional boolean deep = false); + boolean contains(Node? other); const unsigned short ELEMENT_NODE = 1; const unsigned short ATTRIBUTE_NODE = 2; |