mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibWeb/HTML: Update spec text related to template's content
Corresponds to:
aa52274b5a
This commit is contained in:
parent
39ad7833f0
commit
a25cb679fb
Notes:
github-actions[bot]
2025-11-27 10:27:18 +00:00
Author: https://github.com/AtkinsSJ
Commit: a25cb679fb
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6951
3 changed files with 24 additions and 14 deletions
|
|
@ -4499,15 +4499,16 @@ void Document::decrement_throw_on_dynamic_markup_insertion_counter(Badge<HTML::H
|
|||
// https://html.spec.whatwg.org/multipage/scripting.html#appropriate-template-contents-owner-document
|
||||
GC::Ref<DOM::Document> Document::appropriate_template_contents_owner_document()
|
||||
{
|
||||
// 1. If doc is not a Document created by this algorithm, then:
|
||||
// 1. If document is not a Document created by this algorithm:
|
||||
if (!created_for_appropriate_template_contents()) {
|
||||
// 1. If doc does not yet have an associated inert template document, then:
|
||||
// 1. If document does not yet have an associated inert template document:
|
||||
if (!m_associated_inert_template_document) {
|
||||
// 1. Let new doc be a new Document (whose browsing context is null). This is "a Document created by this algorithm" for the purposes of the step above.
|
||||
// 1. Let newDocument be a new Document (whose browsing context is null). This is "a Document created by
|
||||
// this algorithm" for the purposes of the step above.
|
||||
auto new_document = HTML::HTMLDocument::create(realm());
|
||||
new_document->m_created_for_appropriate_template_contents = true;
|
||||
|
||||
// 2. If doc is an HTML document, mark new doc as an HTML document also.
|
||||
// 2. If document is an HTML document, then mark newDocument as an HTML document also.
|
||||
if (document_type() == Type::HTML)
|
||||
new_document->set_document_type(Type::HTML);
|
||||
|
||||
|
|
@ -4516,13 +4517,13 @@ GC::Ref<DOM::Document> Document::appropriate_template_contents_owner_document()
|
|||
// Spec issue: https://github.com/whatwg/html/issues/11955
|
||||
new_document->set_allow_declarative_shadow_roots(allow_declarative_shadow_roots());
|
||||
|
||||
// 3. Set doc's associated inert template document to new doc.
|
||||
// 3. Set document's associated inert template document to newDocument.
|
||||
m_associated_inert_template_document = new_document;
|
||||
}
|
||||
// 2. Set doc to doc's associated inert template document.
|
||||
// 2. Set document to document's associated inert template document.
|
||||
return *m_associated_inert_template_document;
|
||||
}
|
||||
// 2. Return doc.
|
||||
// 2. Return document.
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,17 @@ void HTMLTemplateElement::initialize(JS::Realm& realm)
|
|||
WEB_SET_PROTOTYPE_FOR_INTERFACE(HTMLTemplateElement);
|
||||
Base::initialize(realm);
|
||||
|
||||
m_content = realm.create<DOM::DocumentFragment>(m_document->appropriate_template_contents_owner_document());
|
||||
m_content->set_host(this);
|
||||
// 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.
|
||||
auto document = m_document->appropriate_template_contents_owner_document();
|
||||
|
||||
// 2. Create a DocumentFragment object whose node document is document and host is the template element.
|
||||
auto document_fragment = realm.create<DOM::DocumentFragment>(document);
|
||||
document_fragment->set_host(this);
|
||||
|
||||
// 3. Set the template element's template contents to the newly created DocumentFragment object.
|
||||
m_content = document_fragment;
|
||||
}
|
||||
|
||||
void HTMLTemplateElement::visit_edges(Cell::Visitor& visitor)
|
||||
|
|
@ -38,11 +47,11 @@ void HTMLTemplateElement::visit_edges(Cell::Visitor& visitor)
|
|||
// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-adopt-ext
|
||||
void HTMLTemplateElement::adopted_from(DOM::Document&)
|
||||
{
|
||||
// 1. Let doc be node's node document's appropriate template contents owner document.
|
||||
auto doc = document().appropriate_template_contents_owner_document();
|
||||
// 1. Let document be node's node document's appropriate template contents owner document.
|
||||
auto document = this->document().appropriate_template_contents_owner_document();
|
||||
|
||||
// 2. Adopt node's template contents (a DocumentFragment object) into doc.
|
||||
doc->adopt_node(content());
|
||||
// 2. Adopt node's template contents (a DocumentFragment object) into document.
|
||||
document->adopt_node(content());
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/scripting.html#the-template-element:concept-node-clone-ext
|
||||
|
|
|
|||
|
|
@ -1263,7 +1263,7 @@ void HTMLParser::handle_in_head(HTMLToken& token)
|
|||
// 4. Set shadow's declarative to true.
|
||||
shadow.set_declarative(true);
|
||||
|
||||
// 5. Set template's template contents property to shadow.
|
||||
// 5. Set template's template contents to shadow.
|
||||
as<HTMLTemplateElement>(*template_).set_template_contents(shadow);
|
||||
|
||||
// 6. Set shadow's available to element internals to true.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue