Auto merge of #7531 - nox:template, r=Ms2ger

Implement <template>

All tests using iframes can't currently pass, same for innerHTML-related tests with <template> elements. The latter contradicts the spec, see the links below.

Apart from this, they work, AFAICT.

https://github.com/servo/html5ever/issues/164
https://www.w3.org/Bugs/Public/show_bug.cgi?id=27314

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7531)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-09-08 02:29:00 -06:00
commit 5a0be12e43
28 changed files with 268 additions and 57 deletions

View file

@ -155,6 +155,9 @@ pub struct Document {
reflow_timeout: Cell<Option<u64>>,
/// The cached first `base` element with an `href` attribute.
base_element: MutNullableHeap<JS<HTMLBaseElement>>,
/// This field is set to the document itself for inert documents.
/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
appropriate_template_contents_owner_document: MutNullableHeap<JS<Document>>,
}
impl PartialEq for Document {
@ -1058,6 +1061,7 @@ impl Document {
current_parser: Default::default(),
reflow_timeout: Cell::new(None),
base_element: Default::default(),
appropriate_template_contents_owner_document: Default::default(),
}
}
@ -1106,6 +1110,23 @@ impl Document {
.and_then(HTMLHtmlElementCast::to_ref)
.map(Root::from_ref)
}
/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
pub fn appropriate_template_contents_owner_document(&self) -> Root<Document> {
self.appropriate_template_contents_owner_document.or_init(|| {
let doctype = if self.is_html_document {
IsHTMLDocument::HTMLDocument
} else {
IsHTMLDocument::NonHTMLDocument
};
let new_doc = Document::new(
&*self.window(), None, doctype, None, None,
DocumentSource::NotFromParser, DocumentLoader::new(&self.loader()));
new_doc.appropriate_template_contents_owner_document.set(
Some(JS::from_ref(&*new_doc)));
new_doc
})
}
}