diff options
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp index 3f9cff0184..bfa714f7ed 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.cpp @@ -38,4 +38,20 @@ DOM::Document& HTMLTemplateElement::appropriate_template_contents_owner_document return document; } +// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-clone-ext +void HTMLTemplateElement::cloned(Node& copy, bool clone_children) +{ + if (!clone_children) + return; + + auto& template_clone = verify_cast<HTMLTemplateElement>(copy); + + content()->for_each_child([&](auto& child) { + auto cloned_child = child.clone_node(&template_clone.content()->document(), true); + + // FIXME: Should this use TreeNode::append_child instead? + template_clone.content()->append_child(cloned_child); + }); +} + } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.h index b6d53874c1..6c5c3bd759 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTemplateElement.h @@ -21,6 +21,8 @@ public: NonnullRefPtr<DOM::DocumentFragment> content() { return *m_content; } const NonnullRefPtr<DOM::DocumentFragment> content() const { return *m_content; } + virtual void cloned(Node& copy, bool clone_children) override; + private: DOM::Document& appropriate_template_contents_owner_document(DOM::Document&); |