mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 23:27:35 +00:00
LibWeb: Add the cloning steps in clone_node
This will be used in HTMLTemplateElement later to clone template contents. This makes the clone functions non-const in the process, as the cloning steps can have side effects.
This commit is contained in:
parent
e4ae1cdd1f
commit
f3f2170ac6
2 changed files with 8 additions and 5 deletions
|
@ -406,7 +406,7 @@ ExceptionOr<NonnullRefPtr<Node>> Node::replace_child(NonnullRefPtr<Node> node, N
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#concept-node-clone
|
// https://dom.spec.whatwg.org/#concept-node-clone
|
||||||
NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) const
|
NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children)
|
||||||
{
|
{
|
||||||
if (!document)
|
if (!document)
|
||||||
document = m_document;
|
document = m_document;
|
||||||
|
@ -454,7 +454,9 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co
|
||||||
TODO();
|
TODO();
|
||||||
}
|
}
|
||||||
// FIXME: 4. Set copy’s node document and document to copy, if copy is a document, and set copy’s node document to document otherwise.
|
// FIXME: 4. Set copy’s node document and document to copy, if copy is a document, and set copy’s node document to document otherwise.
|
||||||
// FIXME: 5. Run any cloning steps defined for node in other applicable specifications and pass copy, node, document and the clone children flag if set, as parameters.
|
|
||||||
|
cloned(*copy, clone_children);
|
||||||
|
|
||||||
if (clone_children) {
|
if (clone_children) {
|
||||||
for_each_child([&](auto& child) {
|
for_each_child([&](auto& child) {
|
||||||
copy->append_child(child.clone_node(document, true));
|
copy->append_child(child.clone_node(document, true));
|
||||||
|
@ -464,7 +466,7 @@ NonnullRefPtr<Node> Node::clone_node(Document* document, bool clone_children) co
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-node-clonenode
|
// https://dom.spec.whatwg.org/#dom-node-clonenode
|
||||||
ExceptionOr<NonnullRefPtr<Node>> Node::clone_node_binding(bool deep) const
|
ExceptionOr<NonnullRefPtr<Node>> Node::clone_node_binding(bool deep)
|
||||||
{
|
{
|
||||||
if (is<ShadowRoot>(*this))
|
if (is<ShadowRoot>(*this))
|
||||||
return NotSupportedError::create("Cannot clone shadow root");
|
return NotSupportedError::create("Cannot clone shadow root");
|
||||||
|
|
|
@ -85,8 +85,8 @@ public:
|
||||||
|
|
||||||
ExceptionOr<NonnullRefPtr<Node>> replace_child(NonnullRefPtr<Node> node, NonnullRefPtr<Node> child);
|
ExceptionOr<NonnullRefPtr<Node>> replace_child(NonnullRefPtr<Node> node, NonnullRefPtr<Node> child);
|
||||||
|
|
||||||
NonnullRefPtr<Node> clone_node(Document* document = nullptr, bool clone_children = false) const;
|
NonnullRefPtr<Node> clone_node(Document* document = nullptr, bool clone_children = false);
|
||||||
ExceptionOr<NonnullRefPtr<Node>> clone_node_binding(bool deep) const;
|
ExceptionOr<NonnullRefPtr<Node>> clone_node_binding(bool deep);
|
||||||
|
|
||||||
// NOTE: This is intended for the JS bindings.
|
// NOTE: This is intended for the JS bindings.
|
||||||
bool has_child_nodes() const { return has_children(); }
|
bool has_child_nodes() const { return has_children(); }
|
||||||
|
@ -134,6 +134,7 @@ public:
|
||||||
virtual void removed_from(Node*) { }
|
virtual void removed_from(Node*) { }
|
||||||
virtual void children_changed() { }
|
virtual void children_changed() { }
|
||||||
virtual void adopted_from(const Document&) { }
|
virtual void adopted_from(const Document&) { }
|
||||||
|
virtual void cloned(Node&, bool) {};
|
||||||
|
|
||||||
const Layout::Node* layout_node() const { return m_layout_node; }
|
const Layout::Node* layout_node() const { return m_layout_node; }
|
||||||
Layout::Node* layout_node() { return m_layout_node; }
|
Layout::Node* layout_node() { return m_layout_node; }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue