зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1080029 - Support HTML template in XUL documents. r=smaug
Check if the current parent element is an HTML template element and if it is, append to the document fragment instead of it. Differential Revision: https://phabricator.services.mozilla.com/D26768 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
bed81008f7
Коммит
44fd876aaf
|
@ -439,6 +439,7 @@ nsresult PrototypeDocumentContentSink::ResumeWalk() {
|
|||
// inserted to the actual document.
|
||||
nsXULPrototypeElement* proto;
|
||||
nsCOMPtr<nsIContent> element;
|
||||
nsCOMPtr<nsIContent> nodeToPushTo;
|
||||
int32_t indx; // all children of proto before indx (not
|
||||
// inclusive) have already been constructed
|
||||
rv = mContextStack.Peek(&proto, getter_AddRefs(element), &indx);
|
||||
|
@ -467,6 +468,15 @@ nsresult PrototypeDocumentContentSink::ResumeWalk() {
|
|||
continue;
|
||||
}
|
||||
|
||||
nodeToPushTo = element;
|
||||
// For template elements append the content to the template's document
|
||||
// fragment.
|
||||
if (element->IsHTMLElement(nsGkAtoms::_template)) {
|
||||
HTMLTemplateElement* templateElement =
|
||||
static_cast<HTMLTemplateElement*>(element.get());
|
||||
nodeToPushTo = templateElement->Content();
|
||||
}
|
||||
|
||||
// Grab the next child, and advance the current context stack
|
||||
// to the next sibling to our right.
|
||||
nsXULPrototypeNode* childproto = proto->mChildren[indx];
|
||||
|
@ -487,7 +497,7 @@ nsresult PrototypeDocumentContentSink::ResumeWalk() {
|
|||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// ...and append it to the content model.
|
||||
rv = element->AppendChildTo(child, false);
|
||||
rv = nodeToPushTo->AppendChildTo(child, false);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// If it has children, push the element onto the context
|
||||
|
@ -532,7 +542,7 @@ nsresult PrototypeDocumentContentSink::ResumeWalk() {
|
|||
static_cast<nsXULPrototypeText*>(childproto);
|
||||
text->SetText(textproto->mValue, false);
|
||||
|
||||
rv = element->AppendChildTo(text, false);
|
||||
rv = nodeToPushTo->AppendChildTo(text, false);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
} break;
|
||||
|
||||
|
|
|
@ -19,5 +19,6 @@ support-files =
|
|||
[test_bug757137.xul]
|
||||
[test_bug775972.xul]
|
||||
[test_bug1070049_throw_from_script.xul]
|
||||
[test_html_template.xul]
|
||||
[test_import_xul_to_content.xul]
|
||||
[test_bug1290965.xul]
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
|
||||
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
|
||||
<window title="HTML template in XUL"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js" />
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/AddTask.js" />
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<template id="template">Content<span>Content</span></template>
|
||||
<script type="application/javascript"><![CDATA[
|
||||
add_task(async function test_template() {
|
||||
let template = document.getElementById("template");
|
||||
ok("content" in template, "Template has shadow root.");
|
||||
is(template.childNodes.length, 0, "Template should have no children.");
|
||||
is(template.content.childNodes.length, 2, "Template content should have two children.");
|
||||
});
|
||||
]]></script>
|
||||
</body>
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче