Kaynağa Gözat

LibWeb: Implement Node.contains

Used by Web Components Polyfills.
Luke 4 yıl önce
ebeveyn
işleme
9cae827f07

+ 6 - 0
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);
+}
+
 }

+ 2 - 0
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;
 

+ 1 - 0
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;