Source code

Revision control

Copy as Markdown

Other Tools

/*
* Copyright (c) 2007 Henri Sivonen
* Copyright (c) 2007-2017 Mozilla Foundation
* Portions of comments Copyright 2004-2008 Apple Computer, Inc., Mozilla
* Foundation, and Opera Software ASA.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
* Please edit TreeBuilder.java instead and regenerate.
*/
#define nsHtml5TreeBuilder_cpp__
#include "nsHtml5AttributeName.h"
#include "nsHtml5ElementName.h"
#include "nsHtml5Tokenizer.h"
#include "nsHtml5StackNode.h"
#include "nsHtml5UTF16Buffer.h"
#include "nsHtml5StateSnapshot.h"
#include "nsHtml5Portability.h"
#include "nsHtml5TreeBuilder.h"
char16_t nsHtml5TreeBuilder::REPLACEMENT_CHARACTER[] = {0xfffd};
static const char* const QUIRKY_PUBLIC_IDS_DATA[] = {
"+//silmaril//dtd html pro v0r11 19970101//",
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//",
"-//as//dtd html 3.0 aswedit + extensions//",
"-//ietf//dtd html 2.0 level 1//",
"-//ietf//dtd html 2.0 level 2//",
"-//ietf//dtd html 2.0 strict level 1//",
"-//ietf//dtd html 2.0 strict level 2//",
"-//ietf//dtd html 2.0 strict//",
"-//ietf//dtd html 2.0//",
"-//ietf//dtd html 2.1e//",
"-//ietf//dtd html 3.0//",
"-//ietf//dtd html 3.2 final//",
"-//ietf//dtd html 3.2//",
"-//ietf//dtd html 3//",
"-//ietf//dtd html level 0//",
"-//ietf//dtd html level 1//",
"-//ietf//dtd html level 2//",
"-//ietf//dtd html level 3//",
"-//ietf//dtd html strict level 0//",
"-//ietf//dtd html strict level 1//",
"-//ietf//dtd html strict level 2//",
"-//ietf//dtd html strict level 3//",
"-//ietf//dtd html strict//",
"-//ietf//dtd html//",
"-//metrius//dtd metrius presentational//",
"-//microsoft//dtd internet explorer 2.0 html strict//",
"-//microsoft//dtd internet explorer 2.0 html//",
"-//microsoft//dtd internet explorer 2.0 tables//",
"-//microsoft//dtd internet explorer 3.0 html strict//",
"-//microsoft//dtd internet explorer 3.0 html//",
"-//microsoft//dtd internet explorer 3.0 tables//",
"-//netscape comm. corp.//dtd html//",
"-//netscape comm. corp.//dtd strict html//",
"-//o'reilly and associates//dtd html 2.0//",
"-//o'reilly and associates//dtd html extended 1.0//",
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
"-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html "
"4.0//",
"-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//",
"-//spyglass//dtd html 2.0 extended//",
"-//sq//dtd html 2.0 hotmetal + extensions//",
"-//sun microsystems corp.//dtd hotjava html//",
"-//sun microsystems corp.//dtd hotjava strict html//",
"-//w3c//dtd html 3 1995-03-24//",
"-//w3c//dtd html 3.2 draft//",
"-//w3c//dtd html 3.2 final//",
"-//w3c//dtd html 3.2//",
"-//w3c//dtd html 3.2s draft//",
"-//w3c//dtd html 4.0 frameset//",
"-//w3c//dtd html 4.0 transitional//",
"-//w3c//dtd html experimental 19960712//",
"-//w3c//dtd html experimental 970421//",
"-//w3c//dtd w3 html//",
"-//w3o//dtd w3 html 3.0//",
"-//webtechs//dtd mozilla html 2.0//",
"-//webtechs//dtd mozilla html//"};
staticJArray<const char*, int32_t> nsHtml5TreeBuilder::QUIRKY_PUBLIC_IDS = {
QUIRKY_PUBLIC_IDS_DATA, std::size(QUIRKY_PUBLIC_IDS_DATA)};
void nsHtml5TreeBuilder::setKeepBuffer(bool keepBuffer) {
this->keepBuffer = keepBuffer;
}
bool nsHtml5TreeBuilder::dropBufferIfLongerThan(int32_t length) {
if (charBuffer.length > length) {
charBuffer = nullptr;
return true;
}
return false;
}
void nsHtml5TreeBuilder::startTokenization(nsHtml5Tokenizer* self) {
tokenizer = self;
stackNodes = jArray<nsHtml5StackNode*, int32_t>::newJArray(64);
stack = jArray<nsHtml5StackNode*, int32_t>::newJArray(64);
templateModeStack = jArray<int32_t, int32_t>::newJArray(64);
listOfActiveFormattingElements =
jArray<nsHtml5StackNode*, int32_t>::newJArray(64);
needToDropLF = false;
originalMode = INITIAL;
templateModePtr = -1;
stackNodesIdx = 0;
numStackNodes = 0;
currentPtr = -1;
listPtr = -1;
formPointer = nullptr;
headPointer = nullptr;
start(fragment);
charBufferLen = 0;
if (!keepBuffer) {
charBuffer = nullptr;
}
framesetOk = true;
if (fragment) {
nsIContentHandle* elt;
if (contextNode) {
elt = contextNode;
} else {
elt = createHtmlElementSetAsRoot(tokenizer->emptyAttributes());
}
if (contextNamespace == kNameSpaceID_SVG) {
nsHtml5ElementName* elementName = nsHtml5ElementName::ELT_SVG;
if (nsGkAtoms::title == contextName || nsGkAtoms::desc == contextName ||
nsGkAtoms::foreignObject == contextName) {
elementName = nsHtml5ElementName::ELT_FOREIGNOBJECT;
}
nsHtml5StackNode* node =
createStackNode(elementName, elementName->getCamelCaseName(), elt);
currentPtr++;
stack[currentPtr] = node;
tokenizer->setState(nsHtml5Tokenizer::DATA);
mode = FRAMESET_OK;
} else if (contextNamespace == kNameSpaceID_MathML) {
nsHtml5ElementName* elementName = nsHtml5ElementName::ELT_MATH;
if (nsGkAtoms::mi_ == contextName || nsGkAtoms::mo_ == contextName ||
nsGkAtoms::mn_ == contextName || nsGkAtoms::ms_ == contextName ||
nsGkAtoms::mtext_ == contextName) {
elementName = nsHtml5ElementName::ELT_MTEXT;
} else if (nsGkAtoms::annotation_xml_ == contextName) {
elementName = nsHtml5ElementName::ELT_ANNOTATION_XML;
}
nsHtml5StackNode* node =
createStackNode(elementName, elt, elementName->getName(), false);
currentPtr++;
stack[currentPtr] = node;
tokenizer->setState(nsHtml5Tokenizer::DATA);
mode = FRAMESET_OK;
} else {
nsHtml5StackNode* node =
createStackNode(nsHtml5ElementName::ELT_HTML, elt);
currentPtr++;
stack[currentPtr] = node;
if (nsGkAtoms::_template == contextName) {
pushTemplateMode(IN_TEMPLATE);
}
resetTheInsertionMode();
formPointer = getFormPointerForContext(contextNode);
if (nsGkAtoms::title == contextName ||
nsGkAtoms::textarea == contextName) {
tokenizer->setState(nsHtml5Tokenizer::RCDATA);
} else if (nsGkAtoms::style == contextName ||
nsGkAtoms::xmp == contextName ||
nsGkAtoms::iframe == contextName ||
nsGkAtoms::noembed == contextName ||
nsGkAtoms::noframes == contextName ||
(scriptingEnabled && nsGkAtoms::noscript == contextName)) {
tokenizer->setState(nsHtml5Tokenizer::RAWTEXT);
} else if (nsGkAtoms::plaintext == contextName) {
tokenizer->setState(nsHtml5Tokenizer::PLAINTEXT);
} else if (nsGkAtoms::script == contextName) {
tokenizer->setState(nsHtml5Tokenizer::SCRIPT_DATA);
} else {
tokenizer->setState(nsHtml5Tokenizer::DATA);
}
}
} else {
mode = INITIAL;
if (tokenizer->isViewingXmlSource()) {
nsIContentHandle* elt = createElement(
kNameSpaceID_SVG, nsGkAtoms::svg, tokenizer->emptyAttributes(),
nullptr, svgCreator(NS_NewSVGSVGElement));
nsHtml5StackNode* node =
createStackNode(nsHtml5ElementName::ELT_SVG, nsGkAtoms::svg, elt);
currentPtr++;
stack[currentPtr] = node;
}
}
}
void nsHtml5TreeBuilder::doctype(nsAtom* name, nsHtml5String publicIdentifier,
nsHtml5String systemIdentifier,
bool forceQuirks) {
needToDropLF = false;
if (!isInForeign() && mode == INITIAL) {
nsHtml5String emptyString = nsHtml5Portability::newEmptyString();
appendDoctypeToDocument(!name ? nsGkAtoms::_empty : name,
!publicIdentifier ? emptyString : publicIdentifier,
!systemIdentifier ? emptyString : systemIdentifier);
emptyString.Release();
if (isQuirky(name, publicIdentifier, systemIdentifier, forceQuirks)) {
errQuirkyDoctype();
documentModeInternal(QUIRKS_MODE, publicIdentifier, systemIdentifier);
} else if (isAlmostStandards(publicIdentifier, systemIdentifier)) {
errAlmostStandardsDoctype();
documentModeInternal(ALMOST_STANDARDS_MODE, publicIdentifier,
systemIdentifier);
} else {
documentModeInternal(STANDARDS_MODE, publicIdentifier, systemIdentifier);
}
mode = BEFORE_HTML;
return;
}
errStrayDoctype();
return;
}
void nsHtml5TreeBuilder::comment(char16_t* buf, int32_t start, int32_t length) {
needToDropLF = false;
if (!isInForeign()) {
switch (mode) {
case INITIAL:
case BEFORE_HTML:
case AFTER_AFTER_BODY:
case AFTER_AFTER_FRAMESET: {
appendCommentToDocument(buf, start, length);
return;
}
case AFTER_BODY: {
flushCharacters();
appendComment(stack[0]->node, buf, start, length);
return;
}
default: {
break;
}
}
}
flushCharacters();
appendComment(stack[currentPtr]->node, buf, start, length);
return;
}
void nsHtml5TreeBuilder::characters(const char16_t* buf, int32_t start,
int32_t length) {
if (tokenizer->isViewingXmlSource()) {
return;
}
if (needToDropLF) {
needToDropLF = false;
if (buf[start] == '\n') {
start++;
length--;
if (!length) {
return;
}
}
}
switch (mode) {
case IN_BODY:
case IN_CELL:
case IN_CAPTION: {
if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
reconstructTheActiveFormattingElements();
}
[[fallthrough]];
}
case TEXT: {
accumulateCharacters(buf, start, length);
return;
}
case IN_TABLE:
case IN_TABLE_BODY:
case IN_ROW: {
accumulateCharactersForced(buf, start, length);
return;
}
default: {
int32_t end = start + length;
for (int32_t i = start; i < end; i++) {
switch (buf[i]) {
case ' ':
case '\t':
case '\n':
case '\r':
case '\f': {
switch (mode) {
case INITIAL:
case BEFORE_HTML:
case BEFORE_HEAD: {
start = i + 1;
continue;
}
case IN_HEAD:
case IN_HEAD_NOSCRIPT:
case AFTER_HEAD:
case IN_COLUMN_GROUP:
case IN_FRAMESET:
case AFTER_FRAMESET: {
continue;
}
case FRAMESET_OK:
case IN_TEMPLATE:
case IN_BODY:
case IN_CELL:
case IN_CAPTION: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
flushCharacters();
reconstructTheActiveFormattingElements();
}
NS_HTML5_BREAK(charactersloop);
}
case IN_SELECT:
case IN_SELECT_IN_TABLE: {
NS_HTML5_BREAK(charactersloop);
}
case IN_TABLE:
case IN_TABLE_BODY:
case IN_ROW: {
accumulateCharactersForced(buf, i, 1);
start = i + 1;
continue;
}
case AFTER_BODY:
case AFTER_AFTER_BODY:
case AFTER_AFTER_FRAMESET: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
flushCharacters();
reconstructTheActiveFormattingElements();
continue;
}
}
MOZ_FALLTHROUGH_ASSERT();
}
default: {
switch (mode) {
case INITIAL: {
documentModeInternal(QUIRKS_MODE, nullptr, nullptr);
mode = BEFORE_HTML;
i--;
continue;
}
case BEFORE_HTML: {
appendHtmlElementToDocumentAndPush();
mode = BEFORE_HEAD;
i--;
continue;
}
case BEFORE_HEAD: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
flushCharacters();
appendToCurrentNodeAndPushHeadElement(
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
mode = IN_HEAD;
i--;
continue;
}
case IN_HEAD: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
flushCharacters();
pop();
mode = AFTER_HEAD;
i--;
continue;
}
case IN_HEAD_NOSCRIPT: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
errNonSpaceInNoscriptInHead();
flushCharacters();
pop();
mode = IN_HEAD;
i--;
continue;
}
case AFTER_HEAD: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
flushCharacters();
appendToCurrentNodeAndPushBodyElement();
mode = FRAMESET_OK;
i--;
continue;
}
case FRAMESET_OK: {
framesetOk = false;
mode = IN_BODY;
i--;
continue;
}
case IN_TEMPLATE:
case IN_BODY:
case IN_CELL:
case IN_CAPTION: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
flushCharacters();
reconstructTheActiveFormattingElements();
}
NS_HTML5_BREAK(charactersloop);
}
case IN_TABLE:
case IN_TABLE_BODY:
case IN_ROW: {
accumulateCharactersForced(buf, i, 1);
start = i + 1;
continue;
}
case IN_COLUMN_GROUP: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
start = i;
}
if (!currentPtr || stack[currentPtr]->getGroup() ==
nsHtml5TreeBuilder::TEMPLATE) {
errNonSpaceInColgroupInFragment();
start = i + 1;
continue;
}
flushCharacters();
pop();
mode = IN_TABLE;
i--;
continue;
}
case IN_SELECT:
case IN_SELECT_IN_TABLE: {
NS_HTML5_BREAK(charactersloop);
}
case AFTER_BODY: {
errNonSpaceAfterBody();
mode = framesetOk ? FRAMESET_OK : IN_BODY;
i--;
continue;
}
case IN_FRAMESET: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
}
errNonSpaceInFrameset();
start = i + 1;
continue;
}
case AFTER_FRAMESET: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
}
errNonSpaceAfterFrameset();
start = i + 1;
continue;
}
case AFTER_AFTER_BODY: {
errNonSpaceInTrailer();
mode = framesetOk ? FRAMESET_OK : IN_BODY;
i--;
continue;
}
case AFTER_AFTER_FRAMESET: {
if (start < i) {
accumulateCharacters(buf, start, i - start);
}
errNonSpaceInTrailer();
start = i + 1;
continue;
}
}
}
}
}
charactersloop_end:;
if (start < end) {
accumulateCharacters(buf, start, end - start);
}
}
}
}
void nsHtml5TreeBuilder::zeroOriginatingReplacementCharacter() {
if (mode == TEXT) {
accumulateCharacters(REPLACEMENT_CHARACTER, 0, 1);
return;
}
if (currentPtr >= 0) {
if (isSpecialParentInForeign(stack[currentPtr])) {
return;
}
accumulateCharacters(REPLACEMENT_CHARACTER, 0, 1);
}
}
void nsHtml5TreeBuilder::zeroOrReplacementCharacter() {
zeroOriginatingReplacementCharacter();
}
void nsHtml5TreeBuilder::eof() {
flushCharacters();
for (;;) {
switch (mode) {
case INITIAL: {
documentModeInternal(QUIRKS_MODE, nullptr, nullptr);
mode = BEFORE_HTML;
continue;
}
case BEFORE_HTML: {
appendHtmlElementToDocumentAndPush();
mode = BEFORE_HEAD;
continue;
}
case BEFORE_HEAD: {
appendToCurrentNodeAndPushHeadElement(
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
mode = IN_HEAD;
continue;
}
case IN_HEAD: {
while (currentPtr > 0) {
popOnEof();
}
mode = AFTER_HEAD;
continue;
}
case IN_HEAD_NOSCRIPT: {
while (currentPtr > 1) {
popOnEof();
}
mode = IN_HEAD;
continue;
}
case AFTER_HEAD: {
appendToCurrentNodeAndPushBodyElement();
mode = IN_BODY;
continue;
}
case IN_TABLE_BODY:
case IN_ROW:
case IN_TABLE:
case IN_SELECT_IN_TABLE:
case IN_SELECT:
case IN_COLUMN_GROUP:
case FRAMESET_OK:
case IN_CAPTION:
case IN_CELL:
case IN_BODY: {
if (isTemplateModeStackEmpty()) {
NS_HTML5_BREAK(eofloop);
}
[[fallthrough]];
}
case IN_TEMPLATE: {
int32_t eltPos = findLast(nsGkAtoms::_template);
if (eltPos == nsHtml5TreeBuilder::NOT_FOUND_ON_STACK) {
MOZ_ASSERT(fragment);
NS_HTML5_BREAK(eofloop);
}
if (MOZ_UNLIKELY(mViewSource)) {
errListUnclosedStartTags(0);
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
popTemplateMode();
resetTheInsertionMode();
continue;
}
case TEXT: {
if (originalMode == AFTER_HEAD) {
popOnEof();
}
popOnEof();
mode = originalMode;
continue;
}
case IN_FRAMESET: {
NS_HTML5_BREAK(eofloop);
}
case AFTER_BODY:
case AFTER_FRAMESET:
case AFTER_AFTER_BODY:
case AFTER_AFTER_FRAMESET:
default: {
NS_HTML5_BREAK(eofloop);
}
}
}
eofloop_end:;
while (currentPtr > 0) {
popOnEof();
}
if (!fragment) {
popOnEof();
}
}
void nsHtml5TreeBuilder::endTokenization() {
formPointer = nullptr;
headPointer = nullptr;
contextName = nullptr;
contextNode = nullptr;
templateModeStack = nullptr;
if (stack) {
while (currentPtr > -1) {
stack[currentPtr]->release(this);
currentPtr--;
}
stack = nullptr;
}
if (listOfActiveFormattingElements) {
while (listPtr > -1) {
if (listOfActiveFormattingElements[listPtr]) {
listOfActiveFormattingElements[listPtr]->release(this);
}
listPtr--;
}
listOfActiveFormattingElements = nullptr;
}
if (stackNodes) {
for (int32_t i = 0; i < numStackNodes; i++) {
MOZ_ASSERT(stackNodes[i]->isUnused());
delete stackNodes[i];
}
numStackNodes = 0;
stackNodesIdx = 0;
stackNodes = nullptr;
}
if (!keepBuffer) {
charBuffer = nullptr;
}
end();
}
void nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName,
nsHtml5HtmlAttributes* attributes,
bool selfClosing) {
flushCharacters();
int32_t eltPos;
needToDropLF = false;
starttagloop:
for (;;) {
int32_t group = elementName->getGroup();
nsAtom* name = elementName->getName();
if (isInForeign()) {
nsHtml5StackNode* currentNode = stack[currentPtr];
int32_t currNs = currentNode->ns;
if (!(currentNode->isHtmlIntegrationPoint() ||
(currNs == kNameSpaceID_MathML &&
((currentNode->getGroup() == MI_MO_MN_MS_MTEXT &&
group != MGLYPH_OR_MALIGNMARK) ||
(currentNode->getGroup() == ANNOTATION_XML && group == SVG))))) {
switch (group) {
case B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
case DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
case BODY:
case BR:
case RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR:
case DD_OR_DT:
case UL_OR_OL_OR_DL:
case EMBED:
case IMG:
case H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6:
case HEAD:
case HR:
case LI:
case META:
case NOBR:
case P:
case PRE_OR_LISTING:
case TABLE:
case FONT: {
if (!(group == FONT &&
!(attributes->contains(nsHtml5AttributeName::ATTR_COLOR) ||
attributes->contains(nsHtml5AttributeName::ATTR_FACE) ||
attributes->contains(nsHtml5AttributeName::ATTR_SIZE)))) {
errHtmlStartTagInForeignContext(name);
if (!fragment) {
while (!isSpecialParentInForeign(stack[currentPtr])) {
popForeign(-1, -1);
}
NS_HTML5_CONTINUE(starttagloop);
}
}
[[fallthrough]];
}
default: {
if (kNameSpaceID_SVG == currNs) {
attributes->adjustForSvg();
if (selfClosing) {
appendVoidElementToCurrentMayFosterSVG(elementName, attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterSVG(elementName,
attributes);
}
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
} else {
attributes->adjustForMath();
if (selfClosing) {
appendVoidElementToCurrentMayFosterMathML(elementName,
attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterMathML(elementName,
attributes);
}
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
}
}
}
}
switch (mode) {
case IN_TEMPLATE: {
switch (group) {
case COL: {
popTemplateMode();
pushTemplateMode(IN_COLUMN_GROUP);
mode = IN_COLUMN_GROUP;
continue;
}
case CAPTION:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT: {
popTemplateMode();
pushTemplateMode(IN_TABLE);
mode = IN_TABLE;
continue;
}
case TR: {
popTemplateMode();
pushTemplateMode(IN_TABLE_BODY);
mode = IN_TABLE_BODY;
continue;
}
case TD_OR_TH: {
popTemplateMode();
pushTemplateMode(IN_ROW);
mode = IN_ROW;
continue;
}
case META: {
checkMetaCharset(attributes);
appendVoidElementToCurrentMayFoster(elementName, attributes);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case TITLE: {
startTagTitleInHead(elementName, attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND: {
appendVoidElementToCurrentMayFoster(elementName, attributes);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case SCRIPT: {
startTagScriptInHead(elementName, attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case NOFRAMES:
case STYLE: {
startTagGenericRawText(elementName, attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case TEMPLATE: {
startTagTemplateInHead(elementName, attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
default: {
popTemplateMode();
pushTemplateMode(IN_BODY);
mode = IN_BODY;
continue;
}
}
}
case IN_ROW: {
switch (group) {
case TD_OR_TH: {
clearStackBackTo(findLastOrRoot(nsHtml5TreeBuilder::TR));
appendToCurrentNodeAndPushElement(elementName, attributes);
mode = IN_CELL;
insertMarker();
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR: {
eltPos = findLastOrRoot(nsHtml5TreeBuilder::TR);
if (!eltPos) {
MOZ_ASSERT(fragment || isTemplateContents());
errNoTableRowToClose();
NS_HTML5_BREAK(starttagloop);
}
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE_BODY;
continue;
}
default:; // fall through
}
[[fallthrough]];
}
case IN_TABLE_BODY: {
switch (group) {
case TR: {
clearStackBackTo(
findLastInTableScopeOrRootTemplateTbodyTheadTfoot());
appendToCurrentNodeAndPushElement(elementName, attributes);
mode = IN_ROW;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case TD_OR_TH: {
errStartTagInTableBody(name);
clearStackBackTo(
findLastInTableScopeOrRootTemplateTbodyTheadTfoot());
appendToCurrentNodeAndPushElement(
nsHtml5ElementName::ELT_TR,
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
mode = IN_ROW;
continue;
}
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT: {
eltPos = findLastInTableScopeOrRootTemplateTbodyTheadTfoot();
if (!eltPos || stack[eltPos]->getGroup() == TEMPLATE) {
MOZ_ASSERT(fragment || isTemplateContents());
errStrayStartTag(name);
NS_HTML5_BREAK(starttagloop);
} else {
clearStackBackTo(eltPos);
pop();
mode = IN_TABLE;
continue;
}
}
default:; // fall through
}
[[fallthrough]];
}
case IN_TABLE: {
for (;;) {
switch (group) {
case CAPTION: {
clearStackBackTo(findLastOrRoot(nsHtml5TreeBuilder::TABLE));
insertMarker();
appendToCurrentNodeAndPushElement(elementName, attributes);
mode = IN_CAPTION;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case COLGROUP: {
clearStackBackTo(findLastOrRoot(nsHtml5TreeBuilder::TABLE));
appendToCurrentNodeAndPushElement(elementName, attributes);
mode = IN_COLUMN_GROUP;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case COL: {
clearStackBackTo(findLastOrRoot(nsHtml5TreeBuilder::TABLE));
appendToCurrentNodeAndPushElement(
nsHtml5ElementName::ELT_COLGROUP,
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
mode = IN_COLUMN_GROUP;
NS_HTML5_CONTINUE(starttagloop);
}
case TBODY_OR_THEAD_OR_TFOOT: {
clearStackBackTo(findLastOrRoot(nsHtml5TreeBuilder::TABLE));
appendToCurrentNodeAndPushElement(elementName, attributes);
mode = IN_TABLE_BODY;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case TR:
case TD_OR_TH: {
clearStackBackTo(findLastOrRoot(nsHtml5TreeBuilder::TABLE));
appendToCurrentNodeAndPushElement(
nsHtml5ElementName::ELT_TBODY,
nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
mode = IN_TABLE_BODY;
NS_HTML5_CONTINUE(starttagloop);
}
case TEMPLATE: {
NS_HTML5_BREAK(intableloop);
}
case TABLE: {
errTableSeenWhileTableOpen();
eltPos = findLastInTableScope(name);
if (eltPos == nsHtml5TreeBuilder::NOT_FOUND_ON_STACK) {
MOZ_ASSERT(fragment || isTemplateContents());
NS_HTML5_BREAK(starttagloop);
}
generateImpliedEndTags();
if (!!MOZ_UNLIKELY(mViewSource) && !isCurrent(nsGkAtoms::table)) {
errNoCheckUnclosedElementsOnStack();
}
while (currentPtr >= eltPos) {
pop();
}
resetTheInsertionMode();
NS_HTML5_CONTINUE(starttagloop);
}
case SCRIPT: {
appendToCurrentNodeAndPushElement(elementName, attributes);
originalMode = mode;
mode = TEXT;
tokenizer->setStateAndEndTagExpectation(
nsHtml5Tokenizer::SCRIPT_DATA, elementName);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case STYLE: {
appendToCurrentNodeAndPushElement(elementName, attributes);
originalMode = mode;
mode = TEXT;
tokenizer->setStateAndEndTagExpectation(nsHtml5Tokenizer::RAWTEXT,
elementName);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case INPUT: {
errStartTagInTable(name);
if (!nsHtml5Portability::
lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"hidden", attributes->getValue(
nsHtml5AttributeName::ATTR_TYPE))) {
NS_HTML5_BREAK(intableloop);
}
appendVoidInputToCurrent(attributes, formPointer);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case FORM: {
if (!!formPointer || isTemplateContents()) {
errFormWhenFormOpen();
NS_HTML5_BREAK(starttagloop);
} else {
errStartTagInTable(name);
appendVoidFormToCurrent(attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
}
default: {
errStartTagInTable(name);
NS_HTML5_BREAK(intableloop);
}
}
}
intableloop_end:;
[[fallthrough]];
}
case IN_CAPTION: {
switch (group) {
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH: {
eltPos = findLastInTableScope(nsGkAtoms::caption);
if (eltPos == nsHtml5TreeBuilder::NOT_FOUND_ON_STACK) {
MOZ_ASSERT(fragment || isTemplateContents());
errStrayStartTag(name);
NS_HTML5_BREAK(starttagloop);
}
generateImpliedEndTags();
if (!!MOZ_UNLIKELY(mViewSource) && currentPtr != eltPos) {
errNoCheckUnclosedElementsOnStack();
}
while (currentPtr >= eltPos) {
pop();
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker();
mode = IN_TABLE;
continue;
}
default:; // fall through
}
[[fallthrough]];
}
case IN_CELL: {
switch (group) {
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH: {
eltPos = findLastInTableScopeTdTh();
if (eltPos == nsHtml5TreeBuilder::NOT_FOUND_ON_STACK) {
errNoCellToClose();
NS_HTML5_BREAK(starttagloop);
} else {
closeTheCell(eltPos);
continue;
}
}
default:; // fall through
}
[[fallthrough]];
}
case FRAMESET_OK: {
switch (group) {
case FRAMESET: {
if (mode == FRAMESET_OK) {
if (!currentPtr || stack[1]->getGroup() != BODY) {
MOZ_ASSERT(fragment || isTemplateContents());
errStrayStartTag(name);
NS_HTML5_BREAK(starttagloop);
} else {
errFramesetStart();
detachFromParent(stack[1]->node);
while (currentPtr > 0) {
pop();
}
appendToCurrentNodeAndPushElement(elementName, attributes);
mode = IN_FRAMESET;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
} else {
errStrayStartTag(name);
NS_HTML5_BREAK(starttagloop);
}
}
case PRE_OR_LISTING:
case LI:
case DD_OR_DT:
case BUTTON:
case MARQUEE_OR_APPLET:
case OBJECT:
case TABLE:
case AREA_OR_WBR:
case KEYGEN:
case BR:
case EMBED:
case IMG:
case INPUT:
case HR:
case TEXTAREA:
case XMP:
case IFRAME:
case SELECT: {
if (mode == FRAMESET_OK &&
!(group == INPUT &&
nsHtml5Portability::
lowerCaseLiteralEqualsIgnoreAsciiCaseString(
"hidden", attributes->getValue(
nsHtml5AttributeName::ATTR_TYPE)))) {
framesetOk = false;
mode = IN_BODY;
}
[[fallthrough]];
}
default:; // fall through
}
[[fallthrough]];
}
case IN_BODY: {
for (;;) {
switch (group) {
case HTML: {
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = nullptr;
}
NS_HTML5_BREAK(starttagloop);
}
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND:
case META:
case STYLE:
case SCRIPT:
case TITLE:
case TEMPLATE: {
NS_HTML5_BREAK(inbodyloop);
}
case BODY: {
if (!currentPtr || stack[1]->getGroup() != BODY ||
isTemplateContents()) {
MOZ_ASSERT(fragment || isTemplateContents());
errStrayStartTag(name);
NS_HTML5_BREAK(starttagloop);
}
errFooSeenWhenFooOpen(name);
framesetOk = false;
if (mode == FRAMESET_OK) {
mode = IN_BODY;
}
if (addAttributesToBody(attributes)) {
attributes = nullptr;
}
NS_HTML5_BREAK(starttagloop);
}
case P:
case DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
case UL_OR_OL_OR_DL:
case ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIALOG_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SEARCH_OR_SECTION_OR_SUMMARY: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6: {
implicitlyCloseP();
if (stack[currentPtr]->getGroup() ==
H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6) {
errHeadingWhenHeadingOpen();
pop();
}
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case FIELDSET: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(
elementName, attributes, formPointer);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case PRE_OR_LISTING: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
needToDropLF = true;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case FORM: {
if (!!formPointer && !isTemplateContents()) {
errFormWhenFormOpen();
NS_HTML5_BREAK(starttagloop);
} else {
implicitlyCloseP();
appendToCurrentNodeAndPushFormElementMayFoster(attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
}
case LI:
case DD_OR_DT: {
eltPos = currentPtr;
for (;;) {
nsHtml5StackNode* node = stack[eltPos];
if (node->getGroup() == group) {
generateImpliedEndTagsExceptFor(node->name);
if (!!MOZ_UNLIKELY(mViewSource) && eltPos != currentPtr) {
errUnclosedElementsImplied(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
break;
} else if (!eltPos || (node->isSpecial() &&
(node->ns != kNameSpaceID_XHTML ||
(node->name != nsGkAtoms::p &&
node->name != nsGkAtoms::address &&
node->name != nsGkAtoms::div)))) {
break;
}
eltPos--;
}
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case PLAINTEXT: {
implicitlyCloseP();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
tokenizer->setStateAndEndTagExpectation(
nsHtml5Tokenizer::PLAINTEXT, elementName);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case A: {
int32_t activeAPos =
findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(
nsGkAtoms::a);
if (activeAPos != -1) {
errFooSeenWhenFooOpen(name);
nsHtml5StackNode* activeA =
listOfActiveFormattingElements[activeAPos];
activeA->retain();
adoptionAgencyEndTag(nsGkAtoms::a);
removeFromStack(activeA);
activeAPos = findInListOfActiveFormattingElements(activeA);
if (activeAPos != -1) {
removeFromListOfActiveFormattingElements(activeAPos);
}
activeA->release(this);
}
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushFormattingElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
case FONT: {
reconstructTheActiveFormattingElements();
maybeForgetEarlierDuplicateFormattingElement(
elementName->getName(), attributes);
appendToCurrentNodeAndPushFormattingElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case NOBR: {
reconstructTheActiveFormattingElements();
if (nsHtml5TreeBuilder::NOT_FOUND_ON_STACK !=
findLastInScope(nsGkAtoms::nobr)) {
errFooSeenWhenFooOpen(name);
adoptionAgencyEndTag(nsGkAtoms::nobr);
reconstructTheActiveFormattingElements();
}
appendToCurrentNodeAndPushFormattingElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case BUTTON: {
eltPos = findLastInScope(name);
if (eltPos != nsHtml5TreeBuilder::NOT_FOUND_ON_STACK) {
errFooSeenWhenFooOpen(name);
generateImpliedEndTags();
if (!!MOZ_UNLIKELY(mViewSource) && !isCurrent(name)) {
errUnclosedElementsImplied(eltPos, name);
}
while (currentPtr >= eltPos) {
pop();
}
NS_HTML5_CONTINUE(starttagloop);
} else {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName, attributes, formPointer);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
}
case OBJECT: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName, attributes, formPointer);
insertMarker();
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case MARQUEE_OR_APPLET: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
insertMarker();
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case TABLE: {
if (!quirks) {
implicitlyCloseP();
}
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
mode = IN_TABLE;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case BR:
case EMBED:
case AREA_OR_WBR:
case KEYGEN: {
reconstructTheActiveFormattingElements();
[[fallthrough]];
}
case PARAM_OR_SOURCE_OR_TRACK: {
appendVoidElementToCurrentMayFoster(elementName, attributes);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case HR: {
implicitlyCloseP();
appendVoidElementToCurrentMayFoster(elementName, attributes);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case IMAGE: {
errImage();
elementName = nsHtml5ElementName::ELT_IMG;
NS_HTML5_CONTINUE(starttagloop);
}
case IMG:
case INPUT: {
reconstructTheActiveFormattingElements();
appendVoidElementToCurrentMayFoster(elementName, attributes,
formPointer);
selfClosing = false;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case TEXTAREA: {
appendToCurrentNodeAndPushElementMayFoster(
elementName, attributes, formPointer);
tokenizer->setStateAndEndTagExpectation(nsHtml5Tokenizer::RCDATA,
elementName);
originalMode = mode;
mode = TEXT;
needToDropLF = true;
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case XMP: {
implicitlyCloseP();
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
originalMode = mode;
mode = TEXT;
tokenizer->setStateAndEndTagExpectation(nsHtml5Tokenizer::RAWTEXT,
elementName);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case NOSCRIPT: {
if (!scriptingEnabled) {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
[[fallthrough]];
}
case NOFRAMES:
case IFRAME:
case NOEMBED: {
startTagGenericRawText(elementName, attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case SELECT: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName, attributes, formPointer);
switch (mode) {
case IN_TABLE:
case IN_CAPTION:
case IN_COLUMN_GROUP:
case IN_TABLE_BODY:
case IN_ROW:
case IN_CELL: {
mode = IN_SELECT_IN_TABLE;
break;
}
default: {
mode = IN_SELECT;
break;
}
}
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case OPTGROUP:
case OPTION: {
if (isCurrent(nsGkAtoms::option)) {
pop();
}
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case RB_OR_RTC: {
eltPos = findLastInScope(nsGkAtoms::ruby);
if (eltPos != NOT_FOUND_ON_STACK) {
generateImpliedEndTags();
}
if (eltPos != currentPtr) {
if (eltPos == NOT_FOUND_ON_STACK) {
errStartTagSeenWithoutRuby(name);
} else {
errUnclosedChildrenInRuby();
}
}
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case RT_OR_RP: {
eltPos = findLastInScope(nsGkAtoms::ruby);
if (eltPos != NOT_FOUND_ON_STACK) {
generateImpliedEndTagsExceptFor(nsGkAtoms::rtc);
}
if (eltPos != currentPtr) {
if (!isCurrent(nsGkAtoms::rtc)) {
if (eltPos == NOT_FOUND_ON_STACK) {
errStartTagSeenWithoutRuby(name);
} else {
errUnclosedChildrenInRuby();
}
}
}
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case MATH: {
reconstructTheActiveFormattingElements();
attributes->adjustForMath();
if (selfClosing) {
appendVoidElementToCurrentMayFosterMathML(elementName,
attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterMathML(elementName,
attributes);
}
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case SVG: {
reconstructTheActiveFormattingElements();
attributes->adjustForSvg();
if (selfClosing) {
appendVoidElementToCurrentMayFosterSVG(elementName, attributes);
selfClosing = false;
} else {
appendToCurrentNodeAndPushElementMayFosterSVG(elementName,
attributes);
}
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
case CAPTION:
case COL:
case COLGROUP:
case TBODY_OR_THEAD_OR_TFOOT:
case TR:
case TD_OR_TH:
case FRAME:
case FRAMESET:
case HEAD: {
errStrayStartTag(name);
NS_HTML5_BREAK(starttagloop);
}
case OUTPUT: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(
elementName, attributes, formPointer);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
default: {
reconstructTheActiveFormattingElements();
appendToCurrentNodeAndPushElementMayFoster(elementName,
attributes);
attributes = nullptr;
NS_HTML5_BREAK(starttagloop);
}
}
}
inbodyloop_end:;
[[fallthrough]];
}
case IN_HEAD: {
for (;;) {
switch (group) {
case HTML: {
errStrayStartTag(name);
if (!fragment && !isTemplateContents()) {
addAttributesToHtml(attributes);
attributes = nullptr;
}
NS_HTML5_BREAK(starttagloop);
}
case BASE:
case LINK_OR_BASEFONT_OR_BGSOUND: {
appendVoidElementToCurrentMayFoster(elementName, attributes);