Bug 932086 - Hoist <template> to head when found between </head> and <body>. r=hsivonen

This commit is contained in:
William Chen 2013-11-04 17:19:22 -08:00
parent bc94caa0ae
commit b5a15360d3
2 changed files with 35 additions and 17 deletions

View File

@ -834,9 +834,17 @@ public abstract class TreeBuilder<T> implements TokenHandler,
if (!"http://www.w3.org/TR/html4/strict.dtd".equals(systemIdentifier)) {
warn("The doctype did not contain the system identifier prescribed by the HTML 4.01 specification. Expected \u201C<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\u201D.");
}
} else if ("-//W3C//DTD XHTML 1.0 Strict//EN".equals(publicIdentifier)) {
if (!"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd".equals(systemIdentifier)) {
warn("The doctype did not contain the system identifier prescribed by the XHTML 1.0 specification. Expected \u201C<!DOCTYPE HTML PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\u201D.");
}
} else if ("//W3C//DTD XHTML 1.1//EN".equals(publicIdentifier)) {
if (!"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd".equals(systemIdentifier)) {
warn("The doctype did not contain the system identifier prescribed by the XHTML 1.1 specification. Expected \u201C<!DOCTYPE HTML PUBLIC \"//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\u201D.");
}
} else if (!((systemIdentifier == null || Portability.literalEqualsString(
"about:legacy-compat", systemIdentifier)) && publicIdentifier == null)) {
err("Legacy doctype. Expected e.g. \u201C<!DOCTYPE html>\u201D.");
err("Unexpected doctype. Expected, e.g., \u201C<!DOCTYPE html>\u201D.");
}
documentModeInternal(DocumentMode.STANDARDS_MODE,
publicIdentifier, systemIdentifier, html4);
@ -2901,16 +2909,15 @@ public abstract class TreeBuilder<T> implements TokenHandler,
mode = IN_FRAMESET;
attributes = null; // CPP
break starttagloop;
case BASE:
case TEMPLATE:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
appendVoidElementToCurrentMayFoster(
elementName,
attributes);
selfClosing = false;
pop(); // head
StackNode<T> headOnStack = stack[currentPtr];
startTagTemplateInHead(elementName, attributes);
removeFromStack(headOnStack);
attributes = null; // CPP
break starttagloop;
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND:
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
@ -3991,6 +3998,9 @@ public abstract class TreeBuilder<T> implements TokenHandler,
}
case AFTER_HEAD:
switch (group) {
case TEMPLATE:
endTagTemplateInHead();
break endtagloop;
case HTML:
case BODY:
case BR:
@ -4317,8 +4327,11 @@ public abstract class TreeBuilder<T> implements TokenHandler,
ns = node.ns;
if (i == 0) {
if (!(contextNamespace == "http://www.w3.org/1999/xhtml" && (contextName == "td" || contextName == "th"))) {
name = contextName;
ns = contextNamespace;
if (fragment) {
// Make sure we are parsing a fragment otherwise the context element doesn't make sense.
name = contextName;
ns = contextNamespace;
}
} else {
mode = framesetOk ? FRAMESET_OK : IN_BODY; // XXX from Hixie's email
return;
@ -4353,7 +4366,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
mode = IN_CAPTION;
return;
} else if ("colgroup" == name) {
// TODO: Fragment case. Add error reporting.
mode = IN_COLUMN_GROUP;
return;
} else if ("table" == name) {
@ -4368,7 +4380,6 @@ public abstract class TreeBuilder<T> implements TokenHandler,
return;
} else if ("head" == name) {
if (name == contextName) {
// TODO: Fragment case. Add error reporting.
mode = framesetOk ? FRAMESET_OK : IN_BODY; // really
} else {
mode = IN_HEAD;

View File

@ -1766,15 +1766,16 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case NS_HTML5TREE_BUILDER_BASE: {
case NS_HTML5TREE_BUILDER_TEMPLATE: {
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
appendVoidElementToCurrentMayFoster(elementName, attributes);
selfClosing = false;
pop();
nsHtml5StackNode* headOnStack = stack[currentPtr];
startTagTemplateInHead(elementName, attributes);
removeFromStack(headOnStack);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case NS_HTML5TREE_BUILDER_BASE:
case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND: {
errFooBetweenHeadAndBody(name);
pushHeadPointerOntoStack();
@ -2925,6 +2926,10 @@ nsHtml5TreeBuilder::endTag(nsHtml5ElementName* elementName)
}
case NS_HTML5TREE_BUILDER_AFTER_HEAD: {
switch(group) {
case NS_HTML5TREE_BUILDER_TEMPLATE: {
endTagTemplateInHead();
NS_HTML5_BREAK(endtagloop);
}
case NS_HTML5TREE_BUILDER_HTML:
case NS_HTML5TREE_BUILDER_BODY:
case NS_HTML5TREE_BUILDER_BR: {
@ -3254,8 +3259,10 @@ nsHtml5TreeBuilder::resetTheInsertionMode()
ns = node->ns;
if (!i) {
if (!(contextNamespace == kNameSpaceID_XHTML && (contextName == nsHtml5Atoms::td || contextName == nsHtml5Atoms::th))) {
name = contextName;
ns = contextNamespace;
if (fragment) {
name = contextName;
ns = contextNamespace;
}
} else {
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
return;