summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Wilde <lukew@serenityos.org>2021-09-06 01:25:58 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-06 02:36:04 +0200
commitd36838d05045e83da7c0cf27fabf525bc717584e (patch)
treec6bdafdd7dba03efd032ebead99d2c9e797acee2
parent67c73ddd59eb5b50684472b85546bc3f2156396b (diff)
downloadserenity-d36838d05045e83da7c0cf27fabf525bc717584e.zip
LibWeb: Implement the (string) replace all operations for Node
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.cpp27
-rw-r--r--Userland/Libraries/LibWeb/DOM/Node.h3
2 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp
index cd272ef13a..520da6d8d1 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.cpp
+++ b/Userland/Libraries/LibWeb/DOM/Node.cpp
@@ -718,4 +718,31 @@ bool Node::is_shadow_including_inclusive_ancestor_of(Node const& other) const
return other.is_shadow_including_inclusive_descendant_of(*this);
}
+// https://dom.spec.whatwg.org/#concept-node-replace-all
+void Node::replace_all(RefPtr<Node> node)
+{
+ // FIXME: Let removedNodes be parent’s children. (Current unused so not included)
+ // FIXME: Let addedNodes be the empty set. (Currently unused so not included)
+ // FIXME: If node is a DocumentFragment node, then set addedNodes to node’s children.
+ // FIXME: Otherwise, if node is non-null, set addedNodes to « node ».
+
+ remove_all_children(true);
+
+ if (node)
+ insert_before(*node, nullptr, true);
+
+ // FIXME: If either addedNodes or removedNodes is not empty, then queue a tree mutation record for parent with addedNodes, removedNodes, null, and null.
+}
+
+// https://dom.spec.whatwg.org/#string-replace-all
+void Node::string_replace_all(String const& string)
+{
+ RefPtr<Node> node;
+
+ if (!string.is_empty())
+ node = make_ref_counted<Text>(document(), string);
+
+ replace_all(node);
+}
+
}
diff --git a/Userland/Libraries/LibWeb/DOM/Node.h b/Userland/Libraries/LibWeb/DOM/Node.h
index d0e66209aa..22cca3cb00 100644
--- a/Userland/Libraries/LibWeb/DOM/Node.h
+++ b/Userland/Libraries/LibWeb/DOM/Node.h
@@ -182,6 +182,9 @@ public:
i32 id() const { return m_id; }
static Node* from_id(i32 node_id);
+ void replace_all(RefPtr<Node>);
+ void string_replace_all(String const&);
+
protected:
Node(Document&, NodeType);