mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
LibWeb: Implement the (string) replace all operations for Node
This commit is contained in:
parent
67c73ddd59
commit
d36838d050
2 changed files with 30 additions and 0 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue