Bug 483155 - Put content creator function pointers onto nsHtml5ElementName. r=smaug

MozReview-Commit-ID: E2AAx7Zz2UF
This commit is contained in:
Henri Sivonen
2017-07-04 11:00:03 +03:00
parent 1a05fb7209
commit b2625c0d7e
39 changed files with 3444 additions and 1354 deletions

View File

@@ -169,7 +169,8 @@ nsHtml5TreeBuilder::startTokenization(nsHtml5Tokenizer* self)
nsIContentHandle* elt = createElement(kNameSpaceID_SVG,
nsGkAtoms::svg,
tokenizer->emptyAttributes(),
nullptr);
nullptr,
svgCreator(NS_NewSVGSVGElement));
nsHtml5StackNode* node =
createStackNode(nsHtml5ElementName::ELT_SVG, nsGkAtoms::svg, elt);
currentPtr++;
@@ -204,6 +205,7 @@ nsHtml5TreeBuilder::doctype(nsIAtom* name,
return;
}
errStrayDoctype();
return;
}
void
@@ -231,6 +233,7 @@ nsHtml5TreeBuilder::comment(char16_t* buf, int32_t start, int32_t length)
}
flushCharacters();
appendComment(stack[currentPtr]->node, buf, start, length);
return;
}
void
@@ -932,7 +935,7 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
if (!nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("hidden", attributes->getValue(nsHtml5AttributeName::ATTR_TYPE))) {
NS_HTML5_BREAK(intableloop);
}
appendVoidElementToCurrent(name, attributes, formPointer);
appendVoidInputToCurrent(attributes, formPointer);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
@@ -1292,7 +1295,8 @@ nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttribu
case KEYGEN:
case INPUT: {
reconstructTheActiveFormattingElements();
appendVoidElementToCurrentMayFoster(name, attributes, formPointer);
appendVoidElementToCurrentMayFoster(
elementName, attributes, formPointer);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
@@ -3341,6 +3345,7 @@ nsHtml5TreeBuilder::closeTheCell(int32_t eltPos)
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_ROW;
return;
}
int32_t
@@ -3706,13 +3711,19 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
}
MOZ_ASSERT(node == listOfActiveFormattingElements[nodeListPos]);
MOZ_ASSERT(node == stack[nodePos]);
nsIContentHandle* clone = createElement(kNameSpaceID_XHTML, node->name, node->attributes->cloneAttributes(nullptr), commonAncestor->node);
nsIContentHandle* clone =
createElement(kNameSpaceID_XHTML,
node->name,
node->attributes->cloneAttributes(nullptr),
commonAncestor->node,
htmlCreator(node->getHtmlCreator()));
nsHtml5StackNode* newNode = createStackNode(node->getFlags(),
node->ns,
node->name,
clone,
node->popName,
node->attributes);
node->attributes,
node->getHtmlCreator());
node->dropAttributes();
stack[nodePos] = newNode;
newNode->retain();
@@ -3732,14 +3743,20 @@ nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
detachFromParent(lastNode->node);
appendElement(lastNode->node, commonAncestor->node);
}
nsIContentHandle* clone = createElement(kNameSpaceID_XHTML, formattingElt->name, formattingElt->attributes->cloneAttributes(nullptr), furthestBlock->node);
nsIContentHandle* clone =
createElement(kNameSpaceID_XHTML,
formattingElt->name,
formattingElt->attributes->cloneAttributes(nullptr),
furthestBlock->node,
htmlCreator(formattingElt->getHtmlCreator()));
nsHtml5StackNode* formattingClone =
createStackNode(formattingElt->getFlags(),
formattingElt->ns,
formattingElt->name,
clone,
formattingElt->popName,
formattingElt->attributes);
formattingElt->attributes,
formattingElt->getHtmlCreator());
formattingElt->dropAttributes();
appendChildrenToNewParent(furthestBlock->node, clone);
appendElement(clone, furthestBlock->node);
@@ -3902,9 +3919,17 @@ nsHtml5TreeBuilder::reconstructTheActiveFormattingElements()
nsHtml5StackNode* currentNode = stack[currentPtr];
nsIContentHandle* clone;
if (currentNode->isFosterParenting()) {
clone = createAndInsertFosterParentedElement(kNameSpaceID_XHTML, entry->name, entry->attributes->cloneAttributes(nullptr));
clone = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML,
entry->name,
entry->attributes->cloneAttributes(nullptr),
htmlCreator(entry->getHtmlCreator()));
} else {
clone = createElement(kNameSpaceID_XHTML, entry->name, entry->attributes->cloneAttributes(nullptr), currentNode->node);
clone = createElement(kNameSpaceID_XHTML,
entry->name,
entry->attributes->cloneAttributes(nullptr),
currentNode->node,
htmlCreator(entry->getHtmlCreator()));
appendElement(clone, currentNode->node);
}
nsHtml5StackNode* entryClone = createStackNode(entry->getFlags(),
@@ -3912,7 +3937,8 @@ nsHtml5TreeBuilder::reconstructTheActiveFormattingElements()
entry->name,
clone,
entry->popName,
entry->attributes);
entry->attributes,
entry->getHtmlCreator());
entry->dropAttributes();
push(entryClone);
listOfActiveFormattingElements[entryPos] = entryClone;
@@ -3953,15 +3979,17 @@ nsHtml5TreeBuilder::getUnusedStackNode()
}
nsHtml5StackNode*
nsHtml5TreeBuilder::createStackNode(int32_t flags,
int32_t ns,
nsIAtom* name,
nsIContentHandle* node,
nsIAtom* popName,
nsHtml5HtmlAttributes* attributes)
nsHtml5TreeBuilder::createStackNode(
int32_t flags,
int32_t ns,
nsIAtom* name,
nsIContentHandle* node,
nsIAtom* popName,
nsHtml5HtmlAttributes* attributes,
mozilla::dom::HTMLContentCreatorFunction htmlCreator)
{
nsHtml5StackNode* instance = getUnusedStackNode();
instance->setValues(flags, ns, name, node, popName, attributes);
instance->setValues(flags, ns, name, node, popName, attributes, htmlCreator);
return instance;
}
@@ -4028,24 +4056,36 @@ nsHtml5TreeBuilder::insertIntoFosterParent(nsIContentHandle* child)
insertFosterParentedChild(child, node->node, stack[tablePos - 1]->node);
}
nsIContentHandle*
nsHtml5TreeBuilder::createAndInsertFosterParentedElement(int32_t ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes)
nsIContentHandle*
nsHtml5TreeBuilder::createAndInsertFosterParentedElement(
int32_t ns,
nsIAtom* name,
nsHtml5HtmlAttributes* attributes,
nsHtml5ContentCreatorFunction creator)
{
return createAndInsertFosterParentedElement(ns, name, attributes, nullptr);
return createAndInsertFosterParentedElement(
ns, name, attributes, nullptr, creator);
}
nsIContentHandle*
nsHtml5TreeBuilder::createAndInsertFosterParentedElement(int32_t ns, nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContentHandle* form)
nsIContentHandle*
nsHtml5TreeBuilder::createAndInsertFosterParentedElement(
int32_t ns,
nsIAtom* name,
nsHtml5HtmlAttributes* attributes,
nsIContentHandle* form,
nsHtml5ContentCreatorFunction creator)
{
int32_t tablePos = findLastOrRoot(nsHtml5TreeBuilder::TABLE);
int32_t templatePos = findLastOrRoot(nsHtml5TreeBuilder::TEMPLATE);
if (templatePos >= tablePos) {
nsIContentHandle* child = createElement(ns, name, attributes, form, stack[templatePos]->node);
nsIContentHandle* child = createElement(
ns, name, attributes, form, stack[templatePos]->node, creator);
appendElement(child, stack[templatePos]->node);
return child;
}
nsHtml5StackNode* node = stack[tablePos];
return createAndInsertFosterParentedElement(ns, name, attributes, form, node->node, stack[tablePos - 1]->node);
return createAndInsertFosterParentedElement(
ns, name, attributes, form, node->node, stack[tablePos - 1]->node, creator);
}
bool
@@ -4113,8 +4153,11 @@ void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes* attributes)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* elt =
createElement(kNameSpaceID_XHTML, nsGkAtoms::head, attributes, currentNode);
nsIContentHandle* elt = createElement(kNameSpaceID_XHTML,
nsGkAtoms::head,
attributes,
currentNode,
htmlCreator(NS_NewHTMLSharedElement));
appendElement(elt, currentNode);
headPointer = elt;
nsHtml5StackNode* node = createStackNode(nsHtml5ElementName::ELT_HEAD, elt);
@@ -4140,11 +4183,17 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAt
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML, nsGkAtoms::form, attributes);
elt =
createAndInsertFosterParentedElement(kNameSpaceID_XHTML,
nsGkAtoms::form,
attributes,
htmlCreator(NS_NewHTMLFormElement));
} else {
elt = createElement(
kNameSpaceID_XHTML, nsGkAtoms::form, attributes, current->node);
elt = createElement(kNameSpaceID_XHTML,
nsGkAtoms::form,
attributes,
current->node,
htmlCreator(NS_NewHTMLFormElement));
appendElement(elt, current->node);
}
if (!isTemplateContents()) {
@@ -4163,10 +4212,16 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormattingElementMayFoster(nsHtml5
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML, elementName->getName(), attributes);
kNameSpaceID_XHTML,
elementName->getName(),
attributes,
htmlCreator(elementName->getHtmlCreator()));
} else {
elt = createElement(
kNameSpaceID_XHTML, elementName->getName(), attributes, current->node);
elt = createElement(kNameSpaceID_XHTML,
elementName->getName(),
attributes,
current->node,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
}
nsHtml5StackNode* node = createStackNode(elementName, elt, clone);
@@ -4179,8 +4234,12 @@ void
nsHtml5TreeBuilder::appendToCurrentNodeAndPushElement(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* elt = createElement(
kNameSpaceID_XHTML, elementName->getName(), attributes, currentNode);
nsIContentHandle* elt =
createElement(kNameSpaceID_XHTML,
elementName->getName(),
attributes,
currentNode,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, currentNode);
if (nsHtml5ElementName::ELT_TEMPLATE == elementName) {
elt = getDocumentFragmentForTemplate(elt);
@@ -4197,9 +4256,17 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementNam
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_XHTML, popName, attributes);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML,
popName,
attributes,
htmlCreator(elementName->getHtmlCreator()));
} else {
elt = createElement(kNameSpaceID_XHTML, popName, attributes, current->node);
elt = createElement(kNameSpaceID_XHTML,
popName,
attributes,
current->node,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
}
nsHtml5StackNode* node = createStackNode(elementName, elt, popName);
@@ -4218,9 +4285,14 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterMathML(nsHtml5Elem
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_MathML, popName, attributes);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_MathML, popName, attributes, htmlCreator(nullptr));
} else {
elt = createElement(kNameSpaceID_MathML, popName, attributes, current->node);
elt = createElement(kNameSpaceID_MathML,
popName,
attributes,
current->node,
htmlCreator(nullptr));
appendElement(elt, current->node);
}
nsHtml5StackNode* node =
@@ -4247,9 +4319,17 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterSVG(nsHtml5Element
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_SVG, popName, attributes);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_SVG,
popName,
attributes,
svgCreator(elementName->getSvgCreator()));
} else {
elt = createElement(kNameSpaceID_SVG, popName, attributes, current->node);
elt = createElement(kNameSpaceID_SVG,
popName,
attributes,
current->node,
svgCreator(elementName->getSvgCreator()));
appendElement(elt, current->node);
}
nsHtml5StackNode* node = createStackNode(elementName, popName, elt);
@@ -4265,30 +4345,49 @@ nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementNam
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML, elementName->getName(), attributes, formOwner);
kNameSpaceID_XHTML,
elementName->getName(),
attributes,
formOwner,
htmlCreator(elementName->getHtmlCreator()));
} else {
elt = createElement(kNameSpaceID_XHTML,
elementName->getName(),
attributes,
formOwner,
current->node);
current->node,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
}
nsHtml5StackNode* node = createStackNode(elementName, elt);
push(node);
}
void
nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContentHandle* form)
void
nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(
nsHtml5ElementName* elementName,
nsHtml5HtmlAttributes* attributes,
nsIContentHandle* form)
{
nsIAtom* name = elementName->getName();
nsIContentHandle* elt;
nsIContentHandle* formOwner = !form || fragment || isTemplateContents() ? nullptr : form;
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_XHTML, name, attributes, formOwner);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML,
name,
attributes,
formOwner,
htmlCreator(elementName->getHtmlCreator()));
} else {
elt = createElement(kNameSpaceID_XHTML, name, attributes, formOwner, current->node);
elt = createElement(kNameSpaceID_XHTML,
name,
attributes,
formOwner,
current->node,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
}
elementPushed(kNameSpaceID_XHTML, name, elt);
@@ -4303,9 +4402,17 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(nsHtml5ElementName* elem
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_XHTML, popName, attributes);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_XHTML,
popName,
attributes,
htmlCreator(elementName->getHtmlCreator()));
} else {
elt = createElement(kNameSpaceID_XHTML, popName, attributes, current->node);
elt = createElement(kNameSpaceID_XHTML,
popName,
attributes,
current->node,
htmlCreator(elementName->getHtmlCreator()));
appendElement(elt, current->node);
}
elementPushed(kNameSpaceID_XHTML, popName, elt);
@@ -4320,9 +4427,17 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterSVG(nsHtml5ElementName* e
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_SVG, popName, attributes);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_SVG,
popName,
attributes,
svgCreator(elementName->getSvgCreator()));
} else {
elt = createElement(kNameSpaceID_SVG, popName, attributes, current->node);
elt = createElement(kNameSpaceID_SVG,
popName,
attributes,
current->node,
svgCreator(elementName->getSvgCreator()));
appendElement(elt, current->node);
}
elementPushed(kNameSpaceID_SVG, popName, elt);
@@ -4337,31 +4452,46 @@ nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterMathML(nsHtml5ElementName
nsHtml5StackNode* current = stack[currentPtr];
if (current->isFosterParenting()) {
elt = createAndInsertFosterParentedElement(kNameSpaceID_MathML, popName, attributes);
elt = createAndInsertFosterParentedElement(
kNameSpaceID_MathML, popName, attributes, htmlCreator(nullptr));
} else {
elt = createElement(kNameSpaceID_MathML, popName, attributes, current->node);
elt = createElement(kNameSpaceID_MathML,
popName,
attributes,
current->node,
htmlCreator(nullptr));
appendElement(elt, current->node);
}
elementPushed(kNameSpaceID_MathML, popName, elt);
elementPopped(kNameSpaceID_MathML, popName, elt);
}
void
nsHtml5TreeBuilder::appendVoidElementToCurrent(nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContentHandle* form)
void
nsHtml5TreeBuilder::appendVoidInputToCurrent(nsHtml5HtmlAttributes* attributes,
nsIContentHandle* form)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* elt = createElement(kNameSpaceID_XHTML, name, attributes, !form || fragment || isTemplateContents() ? nullptr : form, currentNode);
nsIContentHandle* elt =
createElement(kNameSpaceID_XHTML,
nsGkAtoms::input,
attributes,
!form || fragment || isTemplateContents() ? nullptr : form,
currentNode,
htmlCreator(NS_NewHTMLInputElement));
appendElement(elt, currentNode);
elementPushed(kNameSpaceID_XHTML, name, elt);
elementPopped(kNameSpaceID_XHTML, name, elt);
elementPushed(kNameSpaceID_XHTML, nsGkAtoms::input, elt);
elementPopped(kNameSpaceID_XHTML, nsGkAtoms::input, elt);
}
void
nsHtml5TreeBuilder::appendVoidFormToCurrent(nsHtml5HtmlAttributes* attributes)
{
nsIContentHandle* currentNode = stack[currentPtr]->node;
nsIContentHandle* elt =
createElement(kNameSpaceID_XHTML, nsGkAtoms::form, attributes, currentNode);
nsIContentHandle* elt = createElement(kNameSpaceID_XHTML,
nsGkAtoms::form,
attributes,
currentNode,
htmlCreator(NS_NewHTMLFormElement));
formPointer = elt;
appendElement(elt, currentNode);
elementPushed(kNameSpaceID_XHTML, nsGkAtoms::form, elt);
@@ -4486,7 +4616,8 @@ nsHtml5TreeBuilder::newSnapshot()
node->name,
node->node,
node->popName,
node->attributes->cloneAttributes(nullptr));
node->attributes->cloneAttributes(nullptr),
node->getHtmlCreator());
listCopy[i] = newNode;
} else {
listCopy[i] = nullptr;
@@ -4503,7 +4634,8 @@ nsHtml5TreeBuilder::newSnapshot()
node->name,
node->node,
node->popName,
nullptr);
nullptr,
node->getHtmlCreator());
stackCopy[i] = newNode;
} else {
stackCopy[i] = listCopy[listIndex];
@@ -4588,7 +4720,8 @@ nsHtml5TreeBuilder::loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTab
nsHtml5Portability::newLocalFromLocal(node->name, interner),
node->node,
nsHtml5Portability::newLocalFromLocal(node->popName, interner),
node->attributes->cloneAttributes(nullptr));
node->attributes->cloneAttributes(nullptr),
node->getHtmlCreator());
listOfActiveFormattingElements[i] = newNode;
} else {
listOfActiveFormattingElements[i] = nullptr;
@@ -4604,7 +4737,8 @@ nsHtml5TreeBuilder::loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTab
nsHtml5Portability::newLocalFromLocal(node->name, interner),
node->node,
nsHtml5Portability::newLocalFromLocal(node->popName, interner),
nullptr);
nullptr,
node->getHtmlCreator());
stack[i] = newNode;
} else {
stack[i] = listOfActiveFormattingElements[listIndex];