dymokomi/luce-browser-engine
Source of release 0.6.0
0.6.0 / src / web / html / html_template_element.lucb
#==============================================================================================
#
# html_template_element - HTML::HTMLTemplateElement: <template> and its template contents
#
# DESCRIPTION:
# Port of LibWeb/HTML/HTMLTemplateElement.cpp (lines 1-94) and HTMLTemplateElement.h: the
# constructor (which moves the mixin tables to HTMLTemplateElement's, as C++'s vptrs
# move), initialize (which establishes the template contents), the adopting and cloning
# steps, and the content accessors.
#
#==============================================================================================
## Ported from HTMLTemplateElement.cpp:16 Web::HTML::HTMLTemplateElement::HTMLTemplateElement.
pub func html_template_element_construct(this: HtmlTemplateElement*, document: DomDocument*, qualified_name: DomQualifiedName):
html_element_construct(this.html_element(), document, qualified_name)
# The vptrs of the mixin bases move to HTMLTemplateElement's tables.
let element = this.html_element()
element.element.slottable_mixin.vtable = &html_template_element_slottable_mixin_vtable
element.element.aria_mixin.vtable = &html_template_element_aria_mixin_vtable
element.element.animatable.vtable = &html_template_element_animatable_vtable
element.global_event_handlers.vtable = &html_template_element_global_event_handlers_vtable
element.form_associated_element.vtable = &html_template_element_form_associated_element_vtable
## Ported from HTMLTemplateElement.cpp:23 Web::HTML::HTMLTemplateElement::initialize (override).
pub func html_template_element_initialize_impl(base: JsCell*, realm: Realm*):
let this = (HtmlTemplateElement*)base
web_set_prototype_for_interface(base, realm, BindInterfaceName.html_template_element)
html_element_initialize_impl(base, realm)
# https://html.spec.whatwg.org/multipage/scripting.html#template-contents
# When a template element is created, the user agent must run the following steps to establish the template contents:
# 1. Let document be the template element's node document's appropriate template contents owner document.
let document = dom_document_appropriate_template_contents_owner_document(dom_node_document(this.dom_node()))
# 2. Create a DocumentFragment object whose node document is document and host is the template element.
let document_fragment = realm_create_dom_document_fragment(realm, document)
dom_document_fragment_set_host(document_fragment, this.dom_element())
# 3. Set the template element's template contents to the newly created DocumentFragment object.
this.m_content = document_fragment
## Ported from HTMLTemplateElement.cpp:41 Web::HTML::HTMLTemplateElement::visit_edges (override).
pub func html_template_element_visit_edges_impl(base: gc.Cell*, visitor: gc.CellVisitor*):
let this = (HtmlTemplateElement*)base
html_element_visit_edges_impl(base, visitor)
gc.cell_visitor_visit_t(visitor, this.m_content)
## Ported from HTMLTemplateElement.cpp:48 Web::HTML::HTMLTemplateElement::adopted_from (override).
# https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-adopt-ext
pub func html_template_element_adopted_from_impl(base: DomNode*, arg0: DomDocument*):
let this = (HtmlTemplateElement*)base
# 1. Let document be node's node document's appropriate template contents owner document.
let document = dom_document_appropriate_template_contents_owner_document(dom_node_document(base))
# 2. Adopt node's template contents (a DocumentFragment object) into document.
dom_document_adopt_node(document, html_template_element_content(this).dom_node())
## Ported from HTMLTemplateElement.cpp:58 Web::HTML::HTMLTemplateElement::cloned (override).
# https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-clone-ext
pub func html_template_element_cloned_impl(base: DomNode*, copy: DomNode*, subtree: bool) -> !:
let this = (HtmlTemplateElement*)base
try html_element_cloned_impl(base, copy, subtree)
# The cloning steps for template elements given node, copy, and subtree are:
# 1. If subtree is false, then return.
if not subtree:
return
# 2. For each child of node's template contents's children, in tree order:
# clone a node given child with document set to copy's template contents's node document,
# subtree set to true, and parent set to copy's template contents.
let template_copy = as_html_template_element(copy)
let copy_content = html_template_element_content(template_copy)
for child in dom_node_children(html_template_element_content(this).dom_node()):
_ = try dom_node_clone_node(child, dom_node_document(copy_content.dom_node()), true, copy_content.dom_node())
## Ported from HTMLTemplateElement.cpp:80 Web::HTML::HTMLTemplateElement::content_for_bindings.
# https://html.spec.whatwg.org/multipage/scripting.html#dom-template-content
pub func html_template_element_content_for_bindings(this: HtmlTemplateElement*) -> DomDocumentFragment*:
let content = this.m_content else trap("a template element has template contents")
# 1. Assert: this's template contents is not a ShadowRoot node.
assert(not dom_node_is_shadow_root(content.dom_node()))
# 2. Return this's template contents.
return content
## Ported from HTMLTemplateElement.cpp:89 Web::HTML::HTMLTemplateElement::set_template_contents.
pub func html_template_element_set_template_contents(this: HtmlTemplateElement*, contents: DomDocumentFragment*):
this.m_content = contents
## Ported from HTMLTemplateElement.h:21 Web::HTML::HTMLTemplateElement::content.
pub func html_template_element_content(this: HtmlTemplateElement*) -> DomDocumentFragment*:
return this.m_content else trap("a template element has template contents")
## Ported from HTMLTemplateElement.h:22 Web::HTML::HTMLTemplateElement::content.
pub func html_template_element_content_const(this: HtmlTemplateElement*) -> DomDocumentFragment*:
return this.m_content else trap("a template element has template contents")
## Ported from HTMLTemplateElement.h:34 Web::HTML::HTMLTemplateElement::is_html_template_element (override).
pub func html_template_element_is_html_template_element_impl(base: DomNode*) -> bool:
return true