LCOV - code coverage report
Current view: directory - parser/html - nsHtml5TreeBuilder.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 2220 374 16.8 %
Date: 2012-06-02 Functions: 102 36 35.3 %

       1                 : /*
       2                 :  * Copyright (c) 2007 Henri Sivonen
       3                 :  * Copyright (c) 2007-2011 Mozilla Foundation
       4                 :  * Portions of comments Copyright 2004-2008 Apple Computer, Inc., Mozilla 
       5                 :  * Foundation, and Opera Software ASA.
       6                 :  *
       7                 :  * Permission is hereby granted, free of charge, to any person obtaining a 
       8                 :  * copy of this software and associated documentation files (the "Software"), 
       9                 :  * to deal in the Software without restriction, including without limitation 
      10                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense, 
      11                 :  * and/or sell copies of the Software, and to permit persons to whom the 
      12                 :  * Software is furnished to do so, subject to the following conditions:
      13                 :  *
      14                 :  * The above copyright notice and this permission notice shall be included in 
      15                 :  * all copies or substantial portions of the Software.
      16                 :  *
      17                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
      18                 :  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
      19                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
      20                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
      21                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
      22                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
      23                 :  * DEALINGS IN THE SOFTWARE.
      24                 :  */
      25                 : 
      26                 : /*
      27                 :  * THIS IS A GENERATED FILE. PLEASE DO NOT EDIT.
      28                 :  * Please edit TreeBuilder.java instead and regenerate.
      29                 :  */
      30                 : 
      31                 : #define nsHtml5TreeBuilder_cpp__
      32                 : 
      33                 : #include "prtypes.h"
      34                 : #include "nsIAtom.h"
      35                 : #include "nsHtml5AtomTable.h"
      36                 : #include "nsITimer.h"
      37                 : #include "nsString.h"
      38                 : #include "nsINameSpaceManager.h"
      39                 : #include "nsIContent.h"
      40                 : #include "nsIDocument.h"
      41                 : #include "nsTraceRefcnt.h"
      42                 : #include "jArray.h"
      43                 : #include "nsHtml5DocumentMode.h"
      44                 : #include "nsHtml5ArrayCopy.h"
      45                 : #include "nsHtml5Parser.h"
      46                 : #include "nsHtml5Atoms.h"
      47                 : #include "nsHtml5TreeOperation.h"
      48                 : #include "nsHtml5PendingNotification.h"
      49                 : #include "nsHtml5StateSnapshot.h"
      50                 : #include "nsHtml5StackNode.h"
      51                 : #include "nsHtml5TreeOpExecutor.h"
      52                 : #include "nsHtml5StreamParser.h"
      53                 : #include "nsAHtml5TreeBuilderState.h"
      54                 : #include "nsHtml5Highlighter.h"
      55                 : #include "nsHtml5ViewSourceUtils.h"
      56                 : 
      57                 : #include "nsHtml5Tokenizer.h"
      58                 : #include "nsHtml5MetaScanner.h"
      59                 : #include "nsHtml5AttributeName.h"
      60                 : #include "nsHtml5ElementName.h"
      61                 : #include "nsHtml5HtmlAttributes.h"
      62                 : #include "nsHtml5StackNode.h"
      63                 : #include "nsHtml5UTF16Buffer.h"
      64                 : #include "nsHtml5StateSnapshot.h"
      65                 : #include "nsHtml5Portability.h"
      66                 : 
      67                 : #include "nsHtml5TreeBuilder.h"
      68                 : 
      69                 : PRUnichar nsHtml5TreeBuilder::REPLACEMENT_CHARACTER[] = { 0xfffd };
      70                 : 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//" };
      71                 : staticJArray<const char*,PRInt32> nsHtml5TreeBuilder::QUIRKY_PUBLIC_IDS = { QUIRKY_PUBLIC_IDS_DATA, NS_ARRAY_LENGTH(QUIRKY_PUBLIC_IDS_DATA) };
      72                 : void 
      73             234 : nsHtml5TreeBuilder::startTokenization(nsHtml5Tokenizer* self)
      74                 : {
      75             234 :   tokenizer = self;
      76             234 :   stack = jArray<nsHtml5StackNode*,PRInt32>::newJArray(64);
      77             234 :   listOfActiveFormattingElements = jArray<nsHtml5StackNode*,PRInt32>::newJArray(64);
      78             234 :   needToDropLF = false;
      79             234 :   originalMode = NS_HTML5TREE_BUILDER_INITIAL;
      80             234 :   currentPtr = -1;
      81             234 :   listPtr = -1;
      82             234 :   formPointer = nsnull;
      83             234 :   headPointer = nsnull;
      84             234 :   deepTreeSurrogateParent = nsnull;
      85             234 :   start(fragment);
      86             234 :   charBufferLen = 0;
      87             234 :   charBuffer = jArray<PRUnichar,PRInt32>::newJArray(1024);
      88             234 :   framesetOk = true;
      89             234 :   if (fragment) {
      90                 :     nsIContent** elt;
      91               0 :     if (contextNode) {
      92               0 :       elt = contextNode;
      93                 :     } else {
      94               0 :       elt = createHtmlElementSetAsRoot(tokenizer->emptyAttributes());
      95                 :     }
      96               0 :     nsHtml5StackNode* node = new nsHtml5StackNode(nsHtml5ElementName::ELT_HTML, elt);
      97               0 :     currentPtr++;
      98               0 :     stack[currentPtr] = node;
      99               0 :     resetTheInsertionMode();
     100               0 :     if (nsHtml5Atoms::title == contextName || nsHtml5Atoms::textarea == contextName) {
     101               0 :       tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RCDATA, contextName);
     102               0 :     } else if (nsHtml5Atoms::style == contextName || nsHtml5Atoms::xmp == contextName || nsHtml5Atoms::iframe == contextName || nsHtml5Atoms::noembed == contextName || nsHtml5Atoms::noframes == contextName || (scriptingEnabled && nsHtml5Atoms::noscript == contextName)) {
     103               0 :       tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, contextName);
     104               0 :     } else if (nsHtml5Atoms::plaintext == contextName) {
     105               0 :       tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_PLAINTEXT, contextName);
     106               0 :     } else if (nsHtml5Atoms::script == contextName) {
     107               0 :       tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_SCRIPT_DATA, contextName);
     108                 :     } else {
     109               0 :       tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_DATA, contextName);
     110                 :     }
     111               0 :     contextName = nsnull;
     112               0 :     contextNode = nsnull;
     113                 :   } else {
     114             234 :     mode = NS_HTML5TREE_BUILDER_INITIAL;
     115             234 :     if (tokenizer->isViewingXmlSource()) {
     116               0 :       nsIContent** elt = createElement(kNameSpaceID_SVG, nsHtml5Atoms::svg, tokenizer->emptyAttributes());
     117               0 :       nsHtml5StackNode* node = new nsHtml5StackNode(nsHtml5ElementName::ELT_SVG, nsHtml5Atoms::svg, elt);
     118               0 :       currentPtr++;
     119               0 :       stack[currentPtr] = node;
     120                 :     }
     121                 :   }
     122             234 : }
     123                 : 
     124                 : void 
     125               0 : nsHtml5TreeBuilder::doctype(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier, bool forceQuirks)
     126                 : {
     127               0 :   needToDropLF = false;
     128               0 :   if (!isInForeign()) {
     129               0 :     switch(mode) {
     130                 :       case NS_HTML5TREE_BUILDER_INITIAL: {
     131               0 :         nsString* emptyString = nsHtml5Portability::newEmptyString();
     132               0 :         appendDoctypeToDocument(!name ? nsHtml5Atoms::emptystring : name, !publicIdentifier ? emptyString : publicIdentifier, !systemIdentifier ? emptyString : systemIdentifier);
     133               0 :         nsHtml5Portability::releaseString(emptyString);
     134               0 :         if (isQuirky(name, publicIdentifier, systemIdentifier, forceQuirks)) {
     135               0 :           errQuirkyDoctype();
     136               0 :           documentModeInternal(QUIRKS_MODE, publicIdentifier, systemIdentifier, false);
     137               0 :         } else if (isAlmostStandards(publicIdentifier, systemIdentifier)) {
     138               0 :           errAlmostStandardsDoctype();
     139               0 :           documentModeInternal(ALMOST_STANDARDS_MODE, publicIdentifier, systemIdentifier, false);
     140                 :         } else {
     141               0 :           documentModeInternal(STANDARDS_MODE, publicIdentifier, systemIdentifier, false);
     142                 :         }
     143               0 :         mode = NS_HTML5TREE_BUILDER_BEFORE_HTML;
     144               0 :         return;
     145                 :       }
     146                 :       default: {
     147                 :         break;
     148                 :       }
     149                 :     }
     150                 :   }
     151               0 :   errStrayDoctype();
     152               0 :   return;
     153                 : }
     154                 : 
     155                 : void 
     156               0 : nsHtml5TreeBuilder::comment(PRUnichar* buf, PRInt32 start, PRInt32 length)
     157                 : {
     158               0 :   needToDropLF = false;
     159               0 :   if (!isInForeign()) {
     160               0 :     switch(mode) {
     161                 :       case NS_HTML5TREE_BUILDER_INITIAL:
     162                 :       case NS_HTML5TREE_BUILDER_BEFORE_HTML:
     163                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY:
     164                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET: {
     165               0 :         appendCommentToDocument(buf, start, length);
     166               0 :         return;
     167                 :       }
     168                 :       case NS_HTML5TREE_BUILDER_AFTER_BODY: {
     169               0 :         flushCharacters();
     170               0 :         appendComment(stack[0]->node, buf, start, length);
     171               0 :         return;
     172                 :       }
     173                 :       default: {
     174                 :         break;
     175                 :       }
     176                 :     }
     177                 :   }
     178               0 :   flushCharacters();
     179               0 :   appendComment(stack[currentPtr]->node, buf, start, length);
     180               0 :   return;
     181                 : }
     182                 : 
     183                 : void 
     184             323 : nsHtml5TreeBuilder::characters(const PRUnichar* buf, PRInt32 start, PRInt32 length)
     185                 : {
     186             323 :   if (tokenizer->isViewingXmlSource()) {
     187               0 :     return;
     188                 :   }
     189             323 :   if (needToDropLF) {
     190               0 :     needToDropLF = false;
     191               0 :     if (buf[start] == '\n') {
     192               0 :       start++;
     193               0 :       length--;
     194               0 :       if (!length) {
     195               0 :         return;
     196                 :       }
     197                 :     }
     198                 :   }
     199             323 :   switch(mode) {
     200                 :     case NS_HTML5TREE_BUILDER_IN_BODY:
     201                 :     case NS_HTML5TREE_BUILDER_IN_CELL:
     202                 :     case NS_HTML5TREE_BUILDER_IN_CAPTION: {
     203              90 :       if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
     204              90 :         reconstructTheActiveFormattingElements();
     205                 :       }
     206                 :     }
     207                 :     case NS_HTML5TREE_BUILDER_TEXT: {
     208              90 :       accumulateCharacters(buf, start, length);
     209              90 :       return;
     210                 :     }
     211                 :     case NS_HTML5TREE_BUILDER_IN_TABLE:
     212                 :     case NS_HTML5TREE_BUILDER_IN_TABLE_BODY:
     213                 :     case NS_HTML5TREE_BUILDER_IN_ROW: {
     214               0 :       accumulateCharactersForced(buf, start, length);
     215               0 :       return;
     216                 :     }
     217                 :     default: {
     218             233 :       PRInt32 end = start + length;
     219            1528 :       for (PRInt32 i = start; i < end; i++) {
     220            1526 :         switch(buf[i]) {
     221                 :           case ' ':
     222                 :           case '\t':
     223                 :           case '\n':
     224                 :           case '\r':
     225                 :           case '\f': {
     226               2 :             switch(mode) {
     227                 :               case NS_HTML5TREE_BUILDER_INITIAL:
     228                 :               case NS_HTML5TREE_BUILDER_BEFORE_HTML:
     229                 :               case NS_HTML5TREE_BUILDER_BEFORE_HEAD: {
     230               1 :                 start = i + 1;
     231               1 :                 continue;
     232                 :               }
     233                 :               case NS_HTML5TREE_BUILDER_IN_HEAD:
     234                 :               case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT:
     235                 :               case NS_HTML5TREE_BUILDER_AFTER_HEAD:
     236                 :               case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP:
     237                 :               case NS_HTML5TREE_BUILDER_IN_FRAMESET:
     238                 :               case NS_HTML5TREE_BUILDER_AFTER_FRAMESET: {
     239               0 :                 continue;
     240                 :               }
     241                 :               case NS_HTML5TREE_BUILDER_FRAMESET_OK:
     242                 :               case NS_HTML5TREE_BUILDER_IN_BODY:
     243                 :               case NS_HTML5TREE_BUILDER_IN_CELL:
     244                 :               case NS_HTML5TREE_BUILDER_IN_CAPTION: {
     245               0 :                 if (start < i) {
     246               0 :                   accumulateCharacters(buf, start, i - start);
     247               0 :                   start = i;
     248                 :                 }
     249               0 :                 if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
     250               0 :                   flushCharacters();
     251               0 :                   reconstructTheActiveFormattingElements();
     252                 :                 }
     253               0 :                 NS_HTML5_BREAK(charactersloop);
     254                 :               }
     255                 :               case NS_HTML5TREE_BUILDER_IN_SELECT:
     256                 :               case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE: {
     257               0 :                 NS_HTML5_BREAK(charactersloop);
     258                 :               }
     259                 :               case NS_HTML5TREE_BUILDER_IN_TABLE:
     260                 :               case NS_HTML5TREE_BUILDER_IN_TABLE_BODY:
     261                 :               case NS_HTML5TREE_BUILDER_IN_ROW: {
     262               0 :                 accumulateCharactersForced(buf, i, 1);
     263               0 :                 start = i + 1;
     264               0 :                 continue;
     265                 :               }
     266                 :               case NS_HTML5TREE_BUILDER_AFTER_BODY:
     267                 :               case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY:
     268                 :               case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET: {
     269               1 :                 if (start < i) {
     270               0 :                   accumulateCharacters(buf, start, i - start);
     271               0 :                   start = i;
     272                 :                 }
     273               1 :                 flushCharacters();
     274               1 :                 reconstructTheActiveFormattingElements();
     275               1 :                 continue;
     276                 :               }
     277                 :             }
     278                 :           }
     279                 :           default: {
     280            1524 :             switch(mode) {
     281                 :               case NS_HTML5TREE_BUILDER_INITIAL: {
     282             212 :                 documentModeInternal(QUIRKS_MODE, nsnull, nsnull, false);
     283             212 :                 mode = NS_HTML5TREE_BUILDER_BEFORE_HTML;
     284             212 :                 i--;
     285             212 :                 continue;
     286                 :               }
     287                 :               case NS_HTML5TREE_BUILDER_BEFORE_HTML: {
     288             212 :                 appendHtmlElementToDocumentAndPush();
     289             212 :                 mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
     290             212 :                 i--;
     291             212 :                 continue;
     292                 :               }
     293                 :               case NS_HTML5TREE_BUILDER_BEFORE_HEAD: {
     294             212 :                 if (start < i) {
     295               0 :                   accumulateCharacters(buf, start, i - start);
     296               0 :                   start = i;
     297                 :                 }
     298             212 :                 flushCharacters();
     299             212 :                 appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
     300             212 :                 mode = NS_HTML5TREE_BUILDER_IN_HEAD;
     301             212 :                 i--;
     302             212 :                 continue;
     303                 :               }
     304                 :               case NS_HTML5TREE_BUILDER_IN_HEAD: {
     305             213 :                 if (start < i) {
     306               0 :                   accumulateCharacters(buf, start, i - start);
     307               0 :                   start = i;
     308                 :                 }
     309             213 :                 flushCharacters();
     310             213 :                 pop();
     311             213 :                 mode = NS_HTML5TREE_BUILDER_AFTER_HEAD;
     312             213 :                 i--;
     313             213 :                 continue;
     314                 :               }
     315                 :               case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT: {
     316               0 :                 if (start < i) {
     317               0 :                   accumulateCharacters(buf, start, i - start);
     318               0 :                   start = i;
     319                 :                 }
     320               0 :                 errNonSpaceInNoscriptInHead();
     321               0 :                 flushCharacters();
     322               0 :                 pop();
     323               0 :                 mode = NS_HTML5TREE_BUILDER_IN_HEAD;
     324               0 :                 i--;
     325               0 :                 continue;
     326                 :               }
     327                 :               case NS_HTML5TREE_BUILDER_AFTER_HEAD: {
     328             213 :                 if (start < i) {
     329               0 :                   accumulateCharacters(buf, start, i - start);
     330               0 :                   start = i;
     331                 :                 }
     332             213 :                 flushCharacters();
     333             213 :                 appendToCurrentNodeAndPushBodyElement();
     334             213 :                 mode = NS_HTML5TREE_BUILDER_FRAMESET_OK;
     335             213 :                 i--;
     336             213 :                 continue;
     337                 :               }
     338                 :               case NS_HTML5TREE_BUILDER_FRAMESET_OK: {
     339             231 :                 framesetOk = false;
     340             231 :                 mode = NS_HTML5TREE_BUILDER_IN_BODY;
     341             231 :                 i--;
     342             231 :                 continue;
     343                 :               }
     344                 :               case NS_HTML5TREE_BUILDER_IN_BODY:
     345                 :               case NS_HTML5TREE_BUILDER_IN_CELL:
     346                 :               case NS_HTML5TREE_BUILDER_IN_CAPTION: {
     347             231 :                 if (start < i) {
     348               0 :                   accumulateCharacters(buf, start, i - start);
     349               0 :                   start = i;
     350                 :                 }
     351             231 :                 if (!isInForeignButNotHtmlOrMathTextIntegrationPoint()) {
     352             231 :                   flushCharacters();
     353             231 :                   reconstructTheActiveFormattingElements();
     354                 :                 }
     355             231 :                 NS_HTML5_BREAK(charactersloop);
     356                 :               }
     357                 :               case NS_HTML5TREE_BUILDER_IN_TABLE:
     358                 :               case NS_HTML5TREE_BUILDER_IN_TABLE_BODY:
     359                 :               case NS_HTML5TREE_BUILDER_IN_ROW: {
     360               0 :                 accumulateCharactersForced(buf, i, 1);
     361               0 :                 start = i + 1;
     362               0 :                 continue;
     363                 :               }
     364                 :               case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP: {
     365               0 :                 if (start < i) {
     366               0 :                   accumulateCharacters(buf, start, i - start);
     367               0 :                   start = i;
     368                 :                 }
     369               0 :                 if (!currentPtr) {
     370               0 :                   errNonSpaceInColgroupInFragment();
     371               0 :                   start = i + 1;
     372               0 :                   continue;
     373                 :                 }
     374               0 :                 flushCharacters();
     375               0 :                 pop();
     376               0 :                 mode = NS_HTML5TREE_BUILDER_IN_TABLE;
     377               0 :                 i--;
     378               0 :                 continue;
     379                 :               }
     380                 :               case NS_HTML5TREE_BUILDER_IN_SELECT:
     381                 :               case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE: {
     382               0 :                 NS_HTML5_BREAK(charactersloop);
     383                 :               }
     384                 :               case NS_HTML5TREE_BUILDER_AFTER_BODY: {
     385               0 :                 errNonSpaceAfterBody();
     386                 : 
     387               0 :                 mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
     388               0 :                 i--;
     389               0 :                 continue;
     390                 :               }
     391                 :               case NS_HTML5TREE_BUILDER_IN_FRAMESET: {
     392               0 :                 if (start < i) {
     393               0 :                   accumulateCharacters(buf, start, i - start);
     394               0 :                   start = i;
     395                 :                 }
     396               0 :                 errNonSpaceInFrameset();
     397               0 :                 start = i + 1;
     398               0 :                 continue;
     399                 :               }
     400                 :               case NS_HTML5TREE_BUILDER_AFTER_FRAMESET: {
     401               0 :                 if (start < i) {
     402               0 :                   accumulateCharacters(buf, start, i - start);
     403               0 :                   start = i;
     404                 :                 }
     405               0 :                 errNonSpaceAfterFrameset();
     406               0 :                 start = i + 1;
     407               0 :                 continue;
     408                 :               }
     409                 :               case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY: {
     410               0 :                 errNonSpaceInTrailer();
     411               0 :                 mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
     412               0 :                 i--;
     413               0 :                 continue;
     414                 :               }
     415                 :               case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET: {
     416               0 :                 errNonSpaceInTrailer();
     417               0 :                 mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
     418               0 :                 i--;
     419               0 :                 continue;
     420                 :               }
     421                 :             }
     422                 :           }
     423                 :         }
     424                 :       }
     425                 :       charactersloop_end: ;
     426             233 :       if (start < end) {
     427             232 :         accumulateCharacters(buf, start, end - start);
     428                 :       }
     429                 :     }
     430                 :   }
     431                 : }
     432                 : 
     433                 : void 
     434               0 : nsHtml5TreeBuilder::zeroOriginatingReplacementCharacter()
     435                 : {
     436               0 :   if (mode == NS_HTML5TREE_BUILDER_TEXT) {
     437               0 :     accumulateCharacters(REPLACEMENT_CHARACTER, 0, 1);
     438               0 :     return;
     439                 :   }
     440               0 :   if (currentPtr >= 0) {
     441               0 :     if (isSpecialParentInForeign(stack[currentPtr])) {
     442               0 :       return;
     443                 :     }
     444               0 :     accumulateCharacters(REPLACEMENT_CHARACTER, 0, 1);
     445                 :   }
     446                 : }
     447                 : 
     448                 : void 
     449             234 : nsHtml5TreeBuilder::eof()
     450                 : {
     451             234 :   flushCharacters();
     452               0 :   for (; ; ) {
     453             234 :     if (isInForeign()) {
     454               0 :       NS_HTML5_BREAK(eofloop);
     455                 :     }
     456             234 :     switch(mode) {
     457                 :       case NS_HTML5TREE_BUILDER_INITIAL: {
     458               0 :         documentModeInternal(QUIRKS_MODE, nsnull, nsnull, false);
     459               0 :         mode = NS_HTML5TREE_BUILDER_BEFORE_HTML;
     460               0 :         continue;
     461                 :       }
     462                 :       case NS_HTML5TREE_BUILDER_BEFORE_HTML: {
     463               0 :         appendHtmlElementToDocumentAndPush();
     464               0 :         mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
     465               0 :         continue;
     466                 :       }
     467                 :       case NS_HTML5TREE_BUILDER_BEFORE_HEAD: {
     468               0 :         appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
     469               0 :         mode = NS_HTML5TREE_BUILDER_IN_HEAD;
     470               0 :         continue;
     471                 :       }
     472                 :       case NS_HTML5TREE_BUILDER_IN_HEAD: {
     473               0 :         while (currentPtr > 0) {
     474               0 :           popOnEof();
     475                 :         }
     476               0 :         mode = NS_HTML5TREE_BUILDER_AFTER_HEAD;
     477               0 :         continue;
     478                 :       }
     479                 :       case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT: {
     480               0 :         while (currentPtr > 1) {
     481               0 :           popOnEof();
     482                 :         }
     483               0 :         mode = NS_HTML5TREE_BUILDER_IN_HEAD;
     484               0 :         continue;
     485                 :       }
     486                 :       case NS_HTML5TREE_BUILDER_AFTER_HEAD: {
     487               0 :         appendToCurrentNodeAndPushBodyElement();
     488               0 :         mode = NS_HTML5TREE_BUILDER_IN_BODY;
     489               0 :         continue;
     490                 :       }
     491                 :       case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP: {
     492               0 :         if (!currentPtr) {
     493                 : 
     494               0 :           NS_HTML5_BREAK(eofloop);
     495                 :         } else {
     496               0 :           popOnEof();
     497               0 :           mode = NS_HTML5TREE_BUILDER_IN_TABLE;
     498               0 :           continue;
     499                 :         }
     500                 :       }
     501                 :       case NS_HTML5TREE_BUILDER_FRAMESET_OK:
     502                 :       case NS_HTML5TREE_BUILDER_IN_CAPTION:
     503                 :       case NS_HTML5TREE_BUILDER_IN_CELL:
     504                 :       case NS_HTML5TREE_BUILDER_IN_BODY: {
     505             230 :         NS_HTML5_BREAK(eofloop);
     506                 :       }
     507                 :       case NS_HTML5TREE_BUILDER_TEXT: {
     508               0 :         if (originalMode == NS_HTML5TREE_BUILDER_AFTER_HEAD) {
     509               0 :           popOnEof();
     510                 :         }
     511               0 :         popOnEof();
     512               0 :         mode = originalMode;
     513               0 :         continue;
     514                 :       }
     515                 :       case NS_HTML5TREE_BUILDER_IN_TABLE_BODY:
     516                 :       case NS_HTML5TREE_BUILDER_IN_ROW:
     517                 :       case NS_HTML5TREE_BUILDER_IN_TABLE:
     518                 :       case NS_HTML5TREE_BUILDER_IN_SELECT:
     519                 :       case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE:
     520                 :       case NS_HTML5TREE_BUILDER_IN_FRAMESET: {
     521               0 :         NS_HTML5_BREAK(eofloop);
     522                 :       }
     523                 :       case NS_HTML5TREE_BUILDER_AFTER_BODY:
     524                 :       case NS_HTML5TREE_BUILDER_AFTER_FRAMESET:
     525                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY:
     526                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET:
     527                 :       default: {
     528               4 :         NS_HTML5_BREAK(eofloop);
     529                 :       }
     530                 :     }
     531                 :   }
     532                 :   eofloop_end: ;
     533             702 :   while (currentPtr > 0) {
     534             234 :     popOnEof();
     535                 :   }
     536             234 :   if (!fragment) {
     537             234 :     popOnEof();
     538                 :   }
     539             234 : }
     540                 : 
     541                 : void 
     542             234 : nsHtml5TreeBuilder::endTokenization()
     543                 : {
     544             234 :   formPointer = nsnull;
     545             234 :   headPointer = nsnull;
     546             234 :   deepTreeSurrogateParent = nsnull;
     547             234 :   if (stack) {
     548             468 :     while (currentPtr > -1) {
     549               0 :       stack[currentPtr]->release();
     550               0 :       currentPtr--;
     551                 :     }
     552             234 :     stack = nsnull;
     553                 :   }
     554             234 :   if (listOfActiveFormattingElements) {
     555             468 :     while (listPtr > -1) {
     556               0 :       if (listOfActiveFormattingElements[listPtr]) {
     557               0 :         listOfActiveFormattingElements[listPtr]->release();
     558                 :       }
     559               0 :       listPtr--;
     560                 :     }
     561             234 :     listOfActiveFormattingElements = nsnull;
     562                 :   }
     563             234 :   charBuffer = nsnull;
     564             234 :   end();
     565             234 : }
     566                 : 
     567                 : void 
     568              87 : nsHtml5TreeBuilder::startTag(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, bool selfClosing)
     569                 : {
     570              87 :   flushCharacters();
     571                 :   PRInt32 eltPos;
     572              87 :   needToDropLF = false;
     573              80 :   starttagloop: for (; ; ) {
     574             188 :     PRInt32 group = elementName->getGroup();
     575             188 :     nsIAtom* name = elementName->name;
     576             188 :     if (isInForeign()) {
     577               0 :       nsHtml5StackNode* currentNode = stack[currentPtr];
     578               0 :       PRInt32 currNs = currentNode->ns;
     579               0 :       if (!(currentNode->isHtmlIntegrationPoint() || (currNs == kNameSpaceID_MathML && ((currentNode->getGroup() == NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT && group != NS_HTML5TREE_BUILDER_MGLYPH_OR_MALIGNMARK) || (currentNode->getGroup() == NS_HTML5TREE_BUILDER_ANNOTATION_XML && group == NS_HTML5TREE_BUILDER_SVG))))) {
     580               0 :         switch(group) {
     581                 :           case NS_HTML5TREE_BUILDER_B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
     582                 :           case NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
     583                 :           case NS_HTML5TREE_BUILDER_BODY:
     584                 :           case NS_HTML5TREE_BUILDER_BR:
     585                 :           case NS_HTML5TREE_BUILDER_RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR:
     586                 :           case NS_HTML5TREE_BUILDER_DD_OR_DT:
     587                 :           case NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL:
     588                 :           case NS_HTML5TREE_BUILDER_EMBED_OR_IMG:
     589                 :           case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6:
     590                 :           case NS_HTML5TREE_BUILDER_HEAD:
     591                 :           case NS_HTML5TREE_BUILDER_HR:
     592                 :           case NS_HTML5TREE_BUILDER_LI:
     593                 :           case NS_HTML5TREE_BUILDER_META:
     594                 :           case NS_HTML5TREE_BUILDER_NOBR:
     595                 :           case NS_HTML5TREE_BUILDER_P:
     596                 :           case NS_HTML5TREE_BUILDER_PRE_OR_LISTING:
     597                 :           case NS_HTML5TREE_BUILDER_TABLE: {
     598               0 :             errHtmlStartTagInForeignContext(name);
     599               0 :             while (!isSpecialParentInForeign(stack[currentPtr])) {
     600               0 :               pop();
     601                 :             }
     602               0 :             NS_HTML5_CONTINUE(starttagloop);
     603                 :           }
     604                 :           case NS_HTML5TREE_BUILDER_FONT: {
     605               0 :             if (attributes->contains(nsHtml5AttributeName::ATTR_COLOR) || attributes->contains(nsHtml5AttributeName::ATTR_FACE) || attributes->contains(nsHtml5AttributeName::ATTR_SIZE)) {
     606               0 :               errHtmlStartTagInForeignContext(name);
     607               0 :               while (!isSpecialParentInForeign(stack[currentPtr])) {
     608               0 :                 pop();
     609                 :               }
     610               0 :               NS_HTML5_CONTINUE(starttagloop);
     611                 :             }
     612                 :           }
     613                 :           default: {
     614               0 :             if (kNameSpaceID_SVG == currNs) {
     615               0 :               attributes->adjustForSvg();
     616               0 :               if (selfClosing) {
     617               0 :                 appendVoidElementToCurrentMayFosterSVG(elementName, attributes);
     618               0 :                 selfClosing = false;
     619                 :               } else {
     620               0 :                 appendToCurrentNodeAndPushElementMayFosterSVG(elementName, attributes);
     621                 :               }
     622               0 :               attributes = nsnull;
     623               0 :               NS_HTML5_BREAK(starttagloop);
     624                 :             } else {
     625               0 :               attributes->adjustForMath();
     626               0 :               if (selfClosing) {
     627               0 :                 appendVoidElementToCurrentMayFosterMathML(elementName, attributes);
     628               0 :                 selfClosing = false;
     629                 :               } else {
     630               0 :                 appendToCurrentNodeAndPushElementMayFosterMathML(elementName, attributes);
     631                 :               }
     632               0 :               attributes = nsnull;
     633               0 :               NS_HTML5_BREAK(starttagloop);
     634                 :             }
     635                 :           }
     636                 :         }
     637                 :       }
     638                 :     }
     639             188 :     switch(mode) {
     640                 :       case NS_HTML5TREE_BUILDER_IN_TABLE_BODY: {
     641               0 :         switch(group) {
     642                 :           case NS_HTML5TREE_BUILDER_TR: {
     643               0 :             clearStackBackTo(findLastInTableScopeOrRootTbodyTheadTfoot());
     644               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
     645               0 :             mode = NS_HTML5TREE_BUILDER_IN_ROW;
     646               0 :             attributes = nsnull;
     647               0 :             NS_HTML5_BREAK(starttagloop);
     648                 :           }
     649                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
     650               0 :             errStartTagInTableBody(name);
     651               0 :             clearStackBackTo(findLastInTableScopeOrRootTbodyTheadTfoot());
     652               0 :             appendToCurrentNodeAndPushElement(nsHtml5ElementName::ELT_TR, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
     653               0 :             mode = NS_HTML5TREE_BUILDER_IN_ROW;
     654               0 :             continue;
     655                 :           }
     656                 :           case NS_HTML5TREE_BUILDER_CAPTION:
     657                 :           case NS_HTML5TREE_BUILDER_COL:
     658                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
     659                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT: {
     660               0 :             eltPos = findLastInTableScopeOrRootTbodyTheadTfoot();
     661               0 :             if (!eltPos) {
     662               0 :               errStrayStartTag(name);
     663               0 :               NS_HTML5_BREAK(starttagloop);
     664                 :             } else {
     665               0 :               clearStackBackTo(eltPos);
     666               0 :               pop();
     667               0 :               mode = NS_HTML5TREE_BUILDER_IN_TABLE;
     668               0 :               continue;
     669                 :             }
     670                 :           }
     671                 :           default:
     672                 :             ; // fall through
     673                 :         }
     674                 :       }
     675                 :       case NS_HTML5TREE_BUILDER_IN_ROW: {
     676               0 :         switch(group) {
     677                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
     678               0 :             clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TR));
     679               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
     680               0 :             mode = NS_HTML5TREE_BUILDER_IN_CELL;
     681               0 :             insertMarker();
     682               0 :             attributes = nsnull;
     683               0 :             NS_HTML5_BREAK(starttagloop);
     684                 :           }
     685                 :           case NS_HTML5TREE_BUILDER_CAPTION:
     686                 :           case NS_HTML5TREE_BUILDER_COL:
     687                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
     688                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
     689                 :           case NS_HTML5TREE_BUILDER_TR: {
     690               0 :             eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TR);
     691               0 :             if (!eltPos) {
     692                 : 
     693               0 :               errNoTableRowToClose();
     694               0 :               NS_HTML5_BREAK(starttagloop);
     695                 :             }
     696               0 :             clearStackBackTo(eltPos);
     697               0 :             pop();
     698               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
     699               0 :             continue;
     700                 :           }
     701                 :           default:
     702                 :             ; // fall through
     703                 :         }
     704                 :       }
     705                 :       case NS_HTML5TREE_BUILDER_IN_TABLE: {
     706                 :         for (; ; ) {
     707               0 :           switch(group) {
     708                 :             case NS_HTML5TREE_BUILDER_CAPTION: {
     709               0 :               clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
     710               0 :               insertMarker();
     711               0 :               appendToCurrentNodeAndPushElement(elementName, attributes);
     712               0 :               mode = NS_HTML5TREE_BUILDER_IN_CAPTION;
     713               0 :               attributes = nsnull;
     714               0 :               NS_HTML5_BREAK(starttagloop);
     715                 :             }
     716                 :             case NS_HTML5TREE_BUILDER_COLGROUP: {
     717               0 :               clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
     718               0 :               appendToCurrentNodeAndPushElement(elementName, attributes);
     719               0 :               mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP;
     720               0 :               attributes = nsnull;
     721               0 :               NS_HTML5_BREAK(starttagloop);
     722                 :             }
     723                 :             case NS_HTML5TREE_BUILDER_COL: {
     724               0 :               clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
     725               0 :               appendToCurrentNodeAndPushElement(nsHtml5ElementName::ELT_COLGROUP, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
     726               0 :               mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP;
     727               0 :               NS_HTML5_CONTINUE(starttagloop);
     728                 :             }
     729                 :             case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT: {
     730               0 :               clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
     731               0 :               appendToCurrentNodeAndPushElement(elementName, attributes);
     732               0 :               mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
     733               0 :               attributes = nsnull;
     734               0 :               NS_HTML5_BREAK(starttagloop);
     735                 :             }
     736                 :             case NS_HTML5TREE_BUILDER_TR:
     737                 :             case NS_HTML5TREE_BUILDER_TD_OR_TH: {
     738               0 :               clearStackBackTo(findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE));
     739               0 :               appendToCurrentNodeAndPushElement(nsHtml5ElementName::ELT_TBODY, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
     740               0 :               mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
     741               0 :               NS_HTML5_CONTINUE(starttagloop);
     742                 :             }
     743                 :             case NS_HTML5TREE_BUILDER_TABLE: {
     744               0 :               errTableSeenWhileTableOpen();
     745               0 :               eltPos = findLastInTableScope(name);
     746               0 :               if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
     747                 : 
     748               0 :                 NS_HTML5_BREAK(starttagloop);
     749                 :               }
     750               0 :               generateImpliedEndTags();
     751               0 :               if (!!NS_UNLIKELY(mViewSource) && !isCurrent(nsHtml5Atoms::table)) {
     752               0 :                 errNoCheckUnclosedElementsOnStack();
     753                 :               }
     754               0 :               while (currentPtr >= eltPos) {
     755               0 :                 pop();
     756                 :               }
     757               0 :               resetTheInsertionMode();
     758               0 :               NS_HTML5_CONTINUE(starttagloop);
     759                 :             }
     760                 :             case NS_HTML5TREE_BUILDER_SCRIPT: {
     761               0 :               appendToCurrentNodeAndPushElement(elementName, attributes);
     762               0 :               originalMode = mode;
     763               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
     764               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_SCRIPT_DATA, elementName);
     765               0 :               attributes = nsnull;
     766               0 :               NS_HTML5_BREAK(starttagloop);
     767                 :             }
     768                 :             case NS_HTML5TREE_BUILDER_STYLE: {
     769               0 :               appendToCurrentNodeAndPushElement(elementName, attributes);
     770               0 :               originalMode = mode;
     771               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
     772               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
     773               0 :               attributes = nsnull;
     774               0 :               NS_HTML5_BREAK(starttagloop);
     775                 :             }
     776                 :             case NS_HTML5TREE_BUILDER_INPUT: {
     777               0 :               if (!nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("hidden", attributes->getValue(nsHtml5AttributeName::ATTR_TYPE))) {
     778               0 :                 NS_HTML5_BREAK(intableloop);
     779                 :               }
     780               0 :               appendVoidElementToCurrent(name, attributes, formPointer);
     781               0 :               selfClosing = false;
     782               0 :               attributes = nsnull;
     783               0 :               NS_HTML5_BREAK(starttagloop);
     784                 :             }
     785                 :             case NS_HTML5TREE_BUILDER_FORM: {
     786               0 :               if (formPointer) {
     787               0 :                 errFormWhenFormOpen();
     788               0 :                 NS_HTML5_BREAK(starttagloop);
     789                 :               } else {
     790               0 :                 errStartTagInTable(name);
     791               0 :                 appendVoidFormToCurrent(attributes);
     792               0 :                 attributes = nsnull;
     793               0 :                 NS_HTML5_BREAK(starttagloop);
     794                 :               }
     795                 :             }
     796                 :             default: {
     797               0 :               errStartTagInTable(name);
     798               0 :               NS_HTML5_BREAK(intableloop);
     799                 :             }
     800                 :           }
     801                 :         }
     802                 :         intableloop_end: ;
     803                 :       }
     804                 :       case NS_HTML5TREE_BUILDER_IN_CAPTION: {
     805               0 :         switch(group) {
     806                 :           case NS_HTML5TREE_BUILDER_CAPTION:
     807                 :           case NS_HTML5TREE_BUILDER_COL:
     808                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
     809                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
     810                 :           case NS_HTML5TREE_BUILDER_TR:
     811                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
     812               0 :             errStrayStartTag(name);
     813               0 :             eltPos = findLastInTableScope(nsHtml5Atoms::caption);
     814               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
     815               0 :               NS_HTML5_BREAK(starttagloop);
     816                 :             }
     817               0 :             generateImpliedEndTags();
     818               0 :             if (!!NS_UNLIKELY(mViewSource) && currentPtr != eltPos) {
     819               0 :               errNoCheckUnclosedElementsOnStack();
     820                 :             }
     821               0 :             while (currentPtr >= eltPos) {
     822               0 :               pop();
     823                 :             }
     824               0 :             clearTheListOfActiveFormattingElementsUpToTheLastMarker();
     825               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
     826               0 :             continue;
     827                 :           }
     828                 :           default:
     829                 :             ; // fall through
     830                 :         }
     831                 :       }
     832                 :       case NS_HTML5TREE_BUILDER_IN_CELL: {
     833               0 :         switch(group) {
     834                 :           case NS_HTML5TREE_BUILDER_CAPTION:
     835                 :           case NS_HTML5TREE_BUILDER_COL:
     836                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
     837                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
     838                 :           case NS_HTML5TREE_BUILDER_TR:
     839                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
     840               0 :             eltPos = findLastInTableScopeTdTh();
     841               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
     842               0 :               errNoCellToClose();
     843               0 :               NS_HTML5_BREAK(starttagloop);
     844                 :             } else {
     845               0 :               closeTheCell(eltPos);
     846               0 :               continue;
     847                 :             }
     848                 :           }
     849                 :           default:
     850                 :             ; // fall through
     851                 :         }
     852                 :       }
     853                 :       case NS_HTML5TREE_BUILDER_FRAMESET_OK: {
     854              18 :         switch(group) {
     855                 :           case NS_HTML5TREE_BUILDER_FRAMESET: {
     856               0 :             if (mode == NS_HTML5TREE_BUILDER_FRAMESET_OK) {
     857               0 :               if (!currentPtr || stack[1]->getGroup() != NS_HTML5TREE_BUILDER_BODY) {
     858                 : 
     859               0 :                 errStrayStartTag(name);
     860               0 :                 NS_HTML5_BREAK(starttagloop);
     861                 :               } else {
     862               0 :                 errFramesetStart();
     863               0 :                 detachFromParent(stack[1]->node);
     864               0 :                 while (currentPtr > 0) {
     865               0 :                   pop();
     866                 :                 }
     867               0 :                 appendToCurrentNodeAndPushElement(elementName, attributes);
     868               0 :                 mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
     869               0 :                 attributes = nsnull;
     870               0 :                 NS_HTML5_BREAK(starttagloop);
     871                 :               }
     872                 :             } else {
     873               0 :               errStrayStartTag(name);
     874               0 :               NS_HTML5_BREAK(starttagloop);
     875                 :             }
     876                 :           }
     877                 :           case NS_HTML5TREE_BUILDER_PRE_OR_LISTING:
     878                 :           case NS_HTML5TREE_BUILDER_LI:
     879                 :           case NS_HTML5TREE_BUILDER_DD_OR_DT:
     880                 :           case NS_HTML5TREE_BUILDER_BUTTON:
     881                 :           case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET:
     882                 :           case NS_HTML5TREE_BUILDER_OBJECT:
     883                 :           case NS_HTML5TREE_BUILDER_TABLE:
     884                 :           case NS_HTML5TREE_BUILDER_AREA_OR_WBR:
     885                 :           case NS_HTML5TREE_BUILDER_BR:
     886                 :           case NS_HTML5TREE_BUILDER_EMBED_OR_IMG:
     887                 :           case NS_HTML5TREE_BUILDER_INPUT:
     888                 :           case NS_HTML5TREE_BUILDER_KEYGEN:
     889                 :           case NS_HTML5TREE_BUILDER_HR:
     890                 :           case NS_HTML5TREE_BUILDER_TEXTAREA:
     891                 :           case NS_HTML5TREE_BUILDER_XMP:
     892                 :           case NS_HTML5TREE_BUILDER_IFRAME:
     893                 :           case NS_HTML5TREE_BUILDER_SELECT: {
     894               0 :             if (mode == NS_HTML5TREE_BUILDER_FRAMESET_OK && !(group == NS_HTML5TREE_BUILDER_INPUT && nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("hidden", attributes->getValue(nsHtml5AttributeName::ATTR_TYPE)))) {
     895               0 :               framesetOk = false;
     896               0 :               mode = NS_HTML5TREE_BUILDER_IN_BODY;
     897                 :             }
     898                 :           }
     899                 :           default:
     900                 :             ; // fall through
     901                 :         }
     902                 :       }
     903                 :       case NS_HTML5TREE_BUILDER_IN_BODY: {
     904                 :         for (; ; ) {
     905              79 :           switch(group) {
     906                 :             case NS_HTML5TREE_BUILDER_HTML: {
     907               0 :               errStrayStartTag(name);
     908               0 :               if (!fragment) {
     909               0 :                 addAttributesToHtml(attributes);
     910               0 :                 attributes = nsnull;
     911                 :               }
     912               0 :               NS_HTML5_BREAK(starttagloop);
     913                 :             }
     914                 :             case NS_HTML5TREE_BUILDER_BASE:
     915                 :             case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND:
     916                 :             case NS_HTML5TREE_BUILDER_META:
     917                 :             case NS_HTML5TREE_BUILDER_STYLE:
     918                 :             case NS_HTML5TREE_BUILDER_SCRIPT:
     919                 :             case NS_HTML5TREE_BUILDER_TITLE:
     920                 :             case NS_HTML5TREE_BUILDER_COMMAND: {
     921               0 :               NS_HTML5_BREAK(inbodyloop);
     922                 :             }
     923                 :             case NS_HTML5TREE_BUILDER_BODY: {
     924               1 :               if (!currentPtr || stack[1]->getGroup() != NS_HTML5TREE_BUILDER_BODY) {
     925                 : 
     926               0 :                 errStrayStartTag(name);
     927               0 :                 NS_HTML5_BREAK(starttagloop);
     928                 :               }
     929               1 :               errFooSeenWhenFooOpen(name);
     930               1 :               framesetOk = false;
     931               1 :               if (mode == NS_HTML5TREE_BUILDER_FRAMESET_OK) {
     932               0 :                 mode = NS_HTML5TREE_BUILDER_IN_BODY;
     933                 :               }
     934               1 :               if (addAttributesToBody(attributes)) {
     935               1 :                 attributes = nsnull;
     936                 :               }
     937               1 :               NS_HTML5_BREAK(starttagloop);
     938                 :             }
     939                 :             case NS_HTML5TREE_BUILDER_P:
     940                 :             case NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
     941                 :             case NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL:
     942                 :             case NS_HTML5TREE_BUILDER_ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_NAV_OR_SECTION_OR_SUMMARY: {
     943              22 :               implicitlyCloseP();
     944              22 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
     945              22 :               attributes = nsnull;
     946              22 :               NS_HTML5_BREAK(starttagloop);
     947                 :             }
     948                 :             case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6: {
     949               4 :               implicitlyCloseP();
     950               4 :               if (stack[currentPtr]->getGroup() == NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6) {
     951               0 :                 errHeadingWhenHeadingOpen();
     952               0 :                 pop();
     953                 :               }
     954               4 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
     955               4 :               attributes = nsnull;
     956               4 :               NS_HTML5_BREAK(starttagloop);
     957                 :             }
     958                 :             case NS_HTML5TREE_BUILDER_FIELDSET: {
     959               0 :               implicitlyCloseP();
     960               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes, formPointer);
     961               0 :               attributes = nsnull;
     962               0 :               NS_HTML5_BREAK(starttagloop);
     963                 :             }
     964                 :             case NS_HTML5TREE_BUILDER_PRE_OR_LISTING: {
     965               0 :               implicitlyCloseP();
     966               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
     967               0 :               needToDropLF = true;
     968               0 :               attributes = nsnull;
     969               0 :               NS_HTML5_BREAK(starttagloop);
     970                 :             }
     971                 :             case NS_HTML5TREE_BUILDER_FORM: {
     972               0 :               if (formPointer) {
     973               0 :                 errFormWhenFormOpen();
     974               0 :                 NS_HTML5_BREAK(starttagloop);
     975                 :               } else {
     976               0 :                 implicitlyCloseP();
     977               0 :                 appendToCurrentNodeAndPushFormElementMayFoster(attributes);
     978               0 :                 attributes = nsnull;
     979               0 :                 NS_HTML5_BREAK(starttagloop);
     980                 :               }
     981                 :             }
     982                 :             case NS_HTML5TREE_BUILDER_LI:
     983                 :             case NS_HTML5TREE_BUILDER_DD_OR_DT: {
     984               8 :               eltPos = currentPtr;
     985               0 :               for (; ; ) {
     986               8 :                 nsHtml5StackNode* node = stack[eltPos];
     987               8 :                 if (node->getGroup() == group) {
     988               4 :                   generateImpliedEndTagsExceptFor(node->name);
     989               4 :                   if (!!NS_UNLIKELY(mViewSource) && eltPos != currentPtr) {
     990               0 :                     errUnclosedElementsImplied(eltPos, name);
     991                 :                   }
     992              12 :                   while (currentPtr >= eltPos) {
     993               4 :                     pop();
     994                 :                   }
     995               4 :                   break;
     996               4 :                 } else if (node->isScoping() || (node->isSpecial() && node->name != nsHtml5Atoms::p && node->name != nsHtml5Atoms::address && node->name != nsHtml5Atoms::div)) {
     997               4 :                   break;
     998                 :                 }
     999               0 :                 eltPos--;
    1000                 :               }
    1001               8 :               implicitlyCloseP();
    1002               8 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1003               8 :               attributes = nsnull;
    1004               8 :               NS_HTML5_BREAK(starttagloop);
    1005                 :             }
    1006                 :             case NS_HTML5TREE_BUILDER_PLAINTEXT: {
    1007               0 :               implicitlyCloseP();
    1008               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1009               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_PLAINTEXT, elementName);
    1010               0 :               attributes = nsnull;
    1011               0 :               NS_HTML5_BREAK(starttagloop);
    1012                 :             }
    1013                 :             case NS_HTML5TREE_BUILDER_A: {
    1014               0 :               PRInt32 activeAPos = findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsHtml5Atoms::a);
    1015               0 :               if (activeAPos != -1) {
    1016               0 :                 errFooSeenWhenFooOpen(name);
    1017               0 :                 nsHtml5StackNode* activeA = listOfActiveFormattingElements[activeAPos];
    1018               0 :                 activeA->retain();
    1019               0 :                 adoptionAgencyEndTag(nsHtml5Atoms::a);
    1020               0 :                 removeFromStack(activeA);
    1021               0 :                 activeAPos = findInListOfActiveFormattingElements(activeA);
    1022               0 :                 if (activeAPos != -1) {
    1023               0 :                   removeFromListOfActiveFormattingElements(activeAPos);
    1024                 :                 }
    1025               0 :                 activeA->release();
    1026                 :               }
    1027               0 :               reconstructTheActiveFormattingElements();
    1028               0 :               appendToCurrentNodeAndPushFormattingElementMayFoster(elementName, attributes);
    1029               0 :               attributes = nsnull;
    1030               0 :               NS_HTML5_BREAK(starttagloop);
    1031                 :             }
    1032                 :             case NS_HTML5TREE_BUILDER_B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
    1033                 :             case NS_HTML5TREE_BUILDER_FONT: {
    1034               0 :               reconstructTheActiveFormattingElements();
    1035               0 :               maybeForgetEarlierDuplicateFormattingElement(elementName->name, attributes);
    1036               0 :               appendToCurrentNodeAndPushFormattingElementMayFoster(elementName, attributes);
    1037               0 :               attributes = nsnull;
    1038               0 :               NS_HTML5_BREAK(starttagloop);
    1039                 :             }
    1040                 :             case NS_HTML5TREE_BUILDER_NOBR: {
    1041               0 :               reconstructTheActiveFormattingElements();
    1042               0 :               if (NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK != findLastInScope(nsHtml5Atoms::nobr)) {
    1043               0 :                 errFooSeenWhenFooOpen(name);
    1044               0 :                 adoptionAgencyEndTag(nsHtml5Atoms::nobr);
    1045               0 :                 reconstructTheActiveFormattingElements();
    1046                 :               }
    1047               0 :               appendToCurrentNodeAndPushFormattingElementMayFoster(elementName, attributes);
    1048               0 :               attributes = nsnull;
    1049               0 :               NS_HTML5_BREAK(starttagloop);
    1050                 :             }
    1051                 :             case NS_HTML5TREE_BUILDER_BUTTON: {
    1052               0 :               eltPos = findLastInScope(name);
    1053               0 :               if (eltPos != NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    1054               0 :                 errFooSeenWhenFooOpen(name);
    1055               0 :                 generateImpliedEndTags();
    1056               0 :                 if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    1057               0 :                   errUnclosedElementsImplied(eltPos, name);
    1058                 :                 }
    1059               0 :                 while (currentPtr >= eltPos) {
    1060               0 :                   pop();
    1061                 :                 }
    1062               0 :                 NS_HTML5_CONTINUE(starttagloop);
    1063                 :               } else {
    1064               0 :                 reconstructTheActiveFormattingElements();
    1065               0 :                 appendToCurrentNodeAndPushElementMayFoster(elementName, attributes, formPointer);
    1066               0 :                 attributes = nsnull;
    1067               0 :                 NS_HTML5_BREAK(starttagloop);
    1068                 :               }
    1069                 :             }
    1070                 :             case NS_HTML5TREE_BUILDER_OBJECT: {
    1071               0 :               reconstructTheActiveFormattingElements();
    1072               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes, formPointer);
    1073               0 :               insertMarker();
    1074               0 :               attributes = nsnull;
    1075               0 :               NS_HTML5_BREAK(starttagloop);
    1076                 :             }
    1077                 :             case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET: {
    1078               0 :               reconstructTheActiveFormattingElements();
    1079               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1080               0 :               insertMarker();
    1081               0 :               attributes = nsnull;
    1082               0 :               NS_HTML5_BREAK(starttagloop);
    1083                 :             }
    1084                 :             case NS_HTML5TREE_BUILDER_TABLE: {
    1085               0 :               if (!quirks) {
    1086               0 :                 implicitlyCloseP();
    1087                 :               }
    1088               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1089               0 :               mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    1090               0 :               attributes = nsnull;
    1091               0 :               NS_HTML5_BREAK(starttagloop);
    1092                 :             }
    1093                 :             case NS_HTML5TREE_BUILDER_BR:
    1094                 :             case NS_HTML5TREE_BUILDER_EMBED_OR_IMG:
    1095                 :             case NS_HTML5TREE_BUILDER_AREA_OR_WBR: {
    1096              42 :               reconstructTheActiveFormattingElements();
    1097                 :             }
    1098                 : #ifdef ENABLE_VOID_MENUITEM
    1099                 :             case NS_HTML5TREE_BUILDER_MENUITEM:
    1100                 : #endif
    1101                 :             case NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE_OR_TRACK: {
    1102              42 :               appendVoidElementToCurrentMayFoster(elementName, attributes);
    1103              42 :               selfClosing = false;
    1104              42 :               attributes = nsnull;
    1105              42 :               NS_HTML5_BREAK(starttagloop);
    1106                 :             }
    1107                 :             case NS_HTML5TREE_BUILDER_HR: {
    1108               0 :               implicitlyCloseP();
    1109               0 :               appendVoidElementToCurrentMayFoster(elementName, attributes);
    1110               0 :               selfClosing = false;
    1111               0 :               attributes = nsnull;
    1112               0 :               NS_HTML5_BREAK(starttagloop);
    1113                 :             }
    1114                 :             case NS_HTML5TREE_BUILDER_IMAGE: {
    1115               0 :               errImage();
    1116               0 :               elementName = nsHtml5ElementName::ELT_IMG;
    1117               0 :               NS_HTML5_CONTINUE(starttagloop);
    1118                 :             }
    1119                 :             case NS_HTML5TREE_BUILDER_KEYGEN:
    1120                 :             case NS_HTML5TREE_BUILDER_INPUT: {
    1121               0 :               reconstructTheActiveFormattingElements();
    1122               0 :               appendVoidElementToCurrentMayFoster(name, attributes, formPointer);
    1123               0 :               selfClosing = false;
    1124               0 :               attributes = nsnull;
    1125               0 :               NS_HTML5_BREAK(starttagloop);
    1126                 :             }
    1127                 :             case NS_HTML5TREE_BUILDER_ISINDEX: {
    1128               0 :               errIsindex();
    1129               0 :               if (formPointer) {
    1130               0 :                 NS_HTML5_BREAK(starttagloop);
    1131                 :               }
    1132               0 :               implicitlyCloseP();
    1133               0 :               nsHtml5HtmlAttributes* formAttrs = new nsHtml5HtmlAttributes(0);
    1134               0 :               PRInt32 actionIndex = attributes->getIndex(nsHtml5AttributeName::ATTR_ACTION);
    1135               0 :               if (actionIndex > -1) {
    1136               0 :                 formAttrs->addAttribute(nsHtml5AttributeName::ATTR_ACTION, attributes->getValue(actionIndex));
    1137                 :               }
    1138               0 :               appendToCurrentNodeAndPushFormElementMayFoster(formAttrs);
    1139               0 :               appendVoidElementToCurrentMayFoster(nsHtml5ElementName::ELT_HR, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    1140               0 :               appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName::ELT_LABEL, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    1141               0 :               PRInt32 promptIndex = attributes->getIndex(nsHtml5AttributeName::ATTR_PROMPT);
    1142               0 :               if (promptIndex > -1) {
    1143               0 :                 autoJArray<PRUnichar,PRInt32> prompt = nsHtml5Portability::newCharArrayFromString(attributes->getValue(promptIndex));
    1144               0 :                 appendCharacters(stack[currentPtr]->node, prompt, 0, prompt.length);
    1145                 :               } else {
    1146               0 :                 appendIsindexPrompt(stack[currentPtr]->node);
    1147                 :               }
    1148               0 :               nsHtml5HtmlAttributes* inputAttributes = new nsHtml5HtmlAttributes(0);
    1149               0 :               inputAttributes->addAttribute(nsHtml5AttributeName::ATTR_NAME, nsHtml5Portability::newStringFromLiteral("isindex"));
    1150               0 :               for (PRInt32 i = 0; i < attributes->getLength(); i++) {
    1151               0 :                 nsHtml5AttributeName* attributeQName = attributes->getAttributeName(i);
    1152               0 :                 if (nsHtml5AttributeName::ATTR_NAME == attributeQName || nsHtml5AttributeName::ATTR_PROMPT == attributeQName) {
    1153               0 :                   attributes->releaseValue(i);
    1154               0 :                 } else if (nsHtml5AttributeName::ATTR_ACTION != attributeQName) {
    1155               0 :                   inputAttributes->addAttribute(attributeQName, attributes->getValue(i));
    1156                 :                 }
    1157                 :               }
    1158               0 :               attributes->clearWithoutReleasingContents();
    1159               0 :               appendVoidElementToCurrentMayFoster(nsHtml5Atoms::input, inputAttributes, formPointer);
    1160               0 :               pop();
    1161               0 :               appendVoidElementToCurrentMayFoster(nsHtml5ElementName::ELT_HR, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    1162               0 :               pop();
    1163               0 :               selfClosing = false;
    1164               0 :               NS_HTML5_BREAK(starttagloop);
    1165                 :             }
    1166                 :             case NS_HTML5TREE_BUILDER_TEXTAREA: {
    1167               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes, formPointer);
    1168               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RCDATA, elementName);
    1169               0 :               originalMode = mode;
    1170               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
    1171               0 :               needToDropLF = true;
    1172               0 :               attributes = nsnull;
    1173               0 :               NS_HTML5_BREAK(starttagloop);
    1174                 :             }
    1175                 :             case NS_HTML5TREE_BUILDER_XMP: {
    1176               0 :               implicitlyCloseP();
    1177               0 :               reconstructTheActiveFormattingElements();
    1178               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1179               0 :               originalMode = mode;
    1180               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
    1181               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1182               0 :               attributes = nsnull;
    1183               0 :               NS_HTML5_BREAK(starttagloop);
    1184                 :             }
    1185                 :             case NS_HTML5TREE_BUILDER_NOSCRIPT: {
    1186               0 :               if (!scriptingEnabled) {
    1187               0 :                 reconstructTheActiveFormattingElements();
    1188               0 :                 appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1189               0 :                 attributes = nsnull;
    1190               0 :                 NS_HTML5_BREAK(starttagloop);
    1191                 :               } else {
    1192                 :               }
    1193                 :             }
    1194                 :             case NS_HTML5TREE_BUILDER_NOFRAMES:
    1195                 :             case NS_HTML5TREE_BUILDER_IFRAME:
    1196                 :             case NS_HTML5TREE_BUILDER_NOEMBED: {
    1197               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1198               0 :               originalMode = mode;
    1199               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
    1200               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1201               0 :               attributes = nsnull;
    1202               0 :               NS_HTML5_BREAK(starttagloop);
    1203                 :             }
    1204                 :             case NS_HTML5TREE_BUILDER_SELECT: {
    1205               0 :               reconstructTheActiveFormattingElements();
    1206               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes, formPointer);
    1207               0 :               switch(mode) {
    1208                 :                 case NS_HTML5TREE_BUILDER_IN_TABLE:
    1209                 :                 case NS_HTML5TREE_BUILDER_IN_CAPTION:
    1210                 :                 case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP:
    1211                 :                 case NS_HTML5TREE_BUILDER_IN_TABLE_BODY:
    1212                 :                 case NS_HTML5TREE_BUILDER_IN_ROW:
    1213                 :                 case NS_HTML5TREE_BUILDER_IN_CELL: {
    1214               0 :                   mode = NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE;
    1215               0 :                   break;
    1216                 :                 }
    1217                 :                 default: {
    1218               0 :                   mode = NS_HTML5TREE_BUILDER_IN_SELECT;
    1219               0 :                   break;
    1220                 :                 }
    1221                 :               }
    1222               0 :               attributes = nsnull;
    1223               0 :               NS_HTML5_BREAK(starttagloop);
    1224                 :             }
    1225                 :             case NS_HTML5TREE_BUILDER_OPTGROUP:
    1226                 :             case NS_HTML5TREE_BUILDER_OPTION: {
    1227               0 :               if (isCurrent(nsHtml5Atoms::option)) {
    1228               0 :                 pop();
    1229                 :               }
    1230               0 :               reconstructTheActiveFormattingElements();
    1231               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1232               0 :               attributes = nsnull;
    1233               0 :               NS_HTML5_BREAK(starttagloop);
    1234                 :             }
    1235                 :             case NS_HTML5TREE_BUILDER_RT_OR_RP: {
    1236               0 :               eltPos = findLastInScope(nsHtml5Atoms::ruby);
    1237               0 :               if (eltPos != NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    1238               0 :                 generateImpliedEndTags();
    1239                 :               }
    1240               0 :               if (eltPos != currentPtr) {
    1241               0 :                 if (eltPos != NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    1242               0 :                   errStartTagSeenWithoutRuby(name);
    1243                 :                 } else {
    1244               0 :                   errUnclosedChildrenInRuby();
    1245                 :                 }
    1246                 :               }
    1247               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1248               0 :               attributes = nsnull;
    1249               0 :               NS_HTML5_BREAK(starttagloop);
    1250                 :             }
    1251                 :             case NS_HTML5TREE_BUILDER_MATH: {
    1252               0 :               reconstructTheActiveFormattingElements();
    1253               0 :               attributes->adjustForMath();
    1254               0 :               if (selfClosing) {
    1255               0 :                 appendVoidElementToCurrentMayFosterMathML(elementName, attributes);
    1256               0 :                 selfClosing = false;
    1257                 :               } else {
    1258               0 :                 appendToCurrentNodeAndPushElementMayFosterMathML(elementName, attributes);
    1259                 :               }
    1260               0 :               attributes = nsnull;
    1261               0 :               NS_HTML5_BREAK(starttagloop);
    1262                 :             }
    1263                 :             case NS_HTML5TREE_BUILDER_SVG: {
    1264               0 :               reconstructTheActiveFormattingElements();
    1265               0 :               attributes->adjustForSvg();
    1266               0 :               if (selfClosing) {
    1267               0 :                 appendVoidElementToCurrentMayFosterSVG(elementName, attributes);
    1268               0 :                 selfClosing = false;
    1269                 :               } else {
    1270               0 :                 appendToCurrentNodeAndPushElementMayFosterSVG(elementName, attributes);
    1271                 :               }
    1272               0 :               attributes = nsnull;
    1273               0 :               NS_HTML5_BREAK(starttagloop);
    1274                 :             }
    1275                 :             case NS_HTML5TREE_BUILDER_CAPTION:
    1276                 :             case NS_HTML5TREE_BUILDER_COL:
    1277                 :             case NS_HTML5TREE_BUILDER_COLGROUP:
    1278                 :             case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    1279                 :             case NS_HTML5TREE_BUILDER_TR:
    1280                 :             case NS_HTML5TREE_BUILDER_TD_OR_TH:
    1281                 :             case NS_HTML5TREE_BUILDER_FRAME:
    1282                 :             case NS_HTML5TREE_BUILDER_FRAMESET:
    1283                 :             case NS_HTML5TREE_BUILDER_HEAD: {
    1284               1 :               errStrayStartTag(name);
    1285               1 :               NS_HTML5_BREAK(starttagloop);
    1286                 :             }
    1287                 :             case NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL: {
    1288               0 :               reconstructTheActiveFormattingElements();
    1289               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes, formPointer);
    1290               0 :               attributes = nsnull;
    1291               0 :               NS_HTML5_BREAK(starttagloop);
    1292                 :             }
    1293                 :             default: {
    1294               1 :               reconstructTheActiveFormattingElements();
    1295               1 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1296               1 :               attributes = nsnull;
    1297               1 :               NS_HTML5_BREAK(starttagloop);
    1298                 :             }
    1299                 :           }
    1300                 :         }
    1301                 :         inbodyloop_end: ;
    1302                 :       }
    1303                 :       case NS_HTML5TREE_BUILDER_IN_HEAD: {
    1304                 :         for (; ; ) {
    1305              22 :           switch(group) {
    1306                 :             case NS_HTML5TREE_BUILDER_HTML: {
    1307               0 :               errStrayStartTag(name);
    1308               0 :               if (!fragment) {
    1309               0 :                 addAttributesToHtml(attributes);
    1310               0 :                 attributes = nsnull;
    1311                 :               }
    1312               0 :               NS_HTML5_BREAK(starttagloop);
    1313                 :             }
    1314                 :             case NS_HTML5TREE_BUILDER_BASE:
    1315                 :             case NS_HTML5TREE_BUILDER_COMMAND: {
    1316               1 :               appendVoidElementToCurrentMayFoster(elementName, attributes);
    1317               1 :               selfClosing = false;
    1318               1 :               attributes = nsnull;
    1319               1 :               NS_HTML5_BREAK(starttagloop);
    1320                 :             }
    1321                 :             case NS_HTML5TREE_BUILDER_META:
    1322                 :             case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND: {
    1323               0 :               NS_HTML5_BREAK(inheadloop);
    1324                 :             }
    1325                 :             case NS_HTML5TREE_BUILDER_TITLE: {
    1326               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1327               0 :               originalMode = mode;
    1328               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
    1329               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RCDATA, elementName);
    1330               0 :               attributes = nsnull;
    1331               0 :               NS_HTML5_BREAK(starttagloop);
    1332                 :             }
    1333                 :             case NS_HTML5TREE_BUILDER_NOSCRIPT: {
    1334               0 :               if (scriptingEnabled) {
    1335               0 :                 appendToCurrentNodeAndPushElement(elementName, attributes);
    1336               0 :                 originalMode = mode;
    1337               0 :                 mode = NS_HTML5TREE_BUILDER_TEXT;
    1338               0 :                 tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1339                 :               } else {
    1340               0 :                 appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1341               0 :                 mode = NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT;
    1342                 :               }
    1343               0 :               attributes = nsnull;
    1344               0 :               NS_HTML5_BREAK(starttagloop);
    1345                 :             }
    1346                 :             case NS_HTML5TREE_BUILDER_SCRIPT: {
    1347               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1348               0 :               originalMode = mode;
    1349               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
    1350               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_SCRIPT_DATA, elementName);
    1351               0 :               attributes = nsnull;
    1352               0 :               NS_HTML5_BREAK(starttagloop);
    1353                 :             }
    1354                 :             case NS_HTML5TREE_BUILDER_STYLE:
    1355                 :             case NS_HTML5TREE_BUILDER_NOFRAMES: {
    1356               0 :               appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1357               0 :               originalMode = mode;
    1358               0 :               mode = NS_HTML5TREE_BUILDER_TEXT;
    1359               0 :               tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1360               0 :               attributes = nsnull;
    1361               0 :               NS_HTML5_BREAK(starttagloop);
    1362                 :             }
    1363                 :             case NS_HTML5TREE_BUILDER_HEAD: {
    1364               0 :               errFooSeenWhenFooOpen(name);
    1365               0 :               NS_HTML5_BREAK(starttagloop);
    1366                 :             }
    1367                 :             default: {
    1368              21 :               pop();
    1369              21 :               mode = NS_HTML5TREE_BUILDER_AFTER_HEAD;
    1370              21 :               NS_HTML5_CONTINUE(starttagloop);
    1371                 :             }
    1372                 :           }
    1373                 :         }
    1374                 :         inheadloop_end: ;
    1375                 :       }
    1376                 :       case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT: {
    1377               0 :         switch(group) {
    1378                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1379               0 :             errStrayStartTag(name);
    1380               0 :             if (!fragment) {
    1381               0 :               addAttributesToHtml(attributes);
    1382               0 :               attributes = nsnull;
    1383                 :             }
    1384               0 :             NS_HTML5_BREAK(starttagloop);
    1385                 :           }
    1386                 :           case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND: {
    1387               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1388               0 :             selfClosing = false;
    1389               0 :             attributes = nsnull;
    1390               0 :             NS_HTML5_BREAK(starttagloop);
    1391                 :           }
    1392                 :           case NS_HTML5TREE_BUILDER_META: {
    1393               0 :             checkMetaCharset(attributes);
    1394               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1395               0 :             selfClosing = false;
    1396               0 :             attributes = nsnull;
    1397               0 :             NS_HTML5_BREAK(starttagloop);
    1398                 :           }
    1399                 :           case NS_HTML5TREE_BUILDER_STYLE:
    1400                 :           case NS_HTML5TREE_BUILDER_NOFRAMES: {
    1401               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1402               0 :             originalMode = mode;
    1403               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1404               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1405               0 :             attributes = nsnull;
    1406               0 :             NS_HTML5_BREAK(starttagloop);
    1407                 :           }
    1408                 :           case NS_HTML5TREE_BUILDER_HEAD: {
    1409               0 :             errFooSeenWhenFooOpen(name);
    1410               0 :             NS_HTML5_BREAK(starttagloop);
    1411                 :           }
    1412                 :           case NS_HTML5TREE_BUILDER_NOSCRIPT: {
    1413               0 :             errFooSeenWhenFooOpen(name);
    1414               0 :             NS_HTML5_BREAK(starttagloop);
    1415                 :           }
    1416                 :           default: {
    1417               0 :             errBadStartTagInHead(name);
    1418               0 :             pop();
    1419               0 :             mode = NS_HTML5TREE_BUILDER_IN_HEAD;
    1420               0 :             continue;
    1421                 :           }
    1422                 :         }
    1423                 :       }
    1424                 :       case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP: {
    1425               0 :         switch(group) {
    1426                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1427               0 :             errStrayStartTag(name);
    1428               0 :             if (!fragment) {
    1429               0 :               addAttributesToHtml(attributes);
    1430               0 :               attributes = nsnull;
    1431                 :             }
    1432               0 :             NS_HTML5_BREAK(starttagloop);
    1433                 :           }
    1434                 :           case NS_HTML5TREE_BUILDER_COL: {
    1435               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1436               0 :             selfClosing = false;
    1437               0 :             attributes = nsnull;
    1438               0 :             NS_HTML5_BREAK(starttagloop);
    1439                 :           }
    1440                 :           default: {
    1441               0 :             if (!currentPtr) {
    1442                 : 
    1443               0 :               errGarbageInColgroup();
    1444               0 :               NS_HTML5_BREAK(starttagloop);
    1445                 :             }
    1446               0 :             pop();
    1447               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    1448               0 :             continue;
    1449                 :           }
    1450                 :         }
    1451                 :       }
    1452                 :       case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE: {
    1453               0 :         switch(group) {
    1454                 :           case NS_HTML5TREE_BUILDER_CAPTION:
    1455                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    1456                 :           case NS_HTML5TREE_BUILDER_TR:
    1457                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH:
    1458                 :           case NS_HTML5TREE_BUILDER_TABLE: {
    1459               0 :             errStartTagWithSelectOpen(name);
    1460               0 :             eltPos = findLastInTableScope(nsHtml5Atoms::select);
    1461               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    1462                 : 
    1463               0 :               NS_HTML5_BREAK(starttagloop);
    1464                 :             }
    1465               0 :             while (currentPtr >= eltPos) {
    1466               0 :               pop();
    1467                 :             }
    1468               0 :             resetTheInsertionMode();
    1469               0 :             continue;
    1470                 :           }
    1471                 :           default:
    1472                 :             ; // fall through
    1473                 :         }
    1474                 :       }
    1475                 :       case NS_HTML5TREE_BUILDER_IN_SELECT: {
    1476               0 :         switch(group) {
    1477                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1478               0 :             errStrayStartTag(name);
    1479               0 :             if (!fragment) {
    1480               0 :               addAttributesToHtml(attributes);
    1481               0 :               attributes = nsnull;
    1482                 :             }
    1483               0 :             NS_HTML5_BREAK(starttagloop);
    1484                 :           }
    1485                 :           case NS_HTML5TREE_BUILDER_OPTION: {
    1486               0 :             if (isCurrent(nsHtml5Atoms::option)) {
    1487               0 :               pop();
    1488                 :             }
    1489               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1490               0 :             attributes = nsnull;
    1491               0 :             NS_HTML5_BREAK(starttagloop);
    1492                 :           }
    1493                 :           case NS_HTML5TREE_BUILDER_OPTGROUP: {
    1494               0 :             if (isCurrent(nsHtml5Atoms::option)) {
    1495               0 :               pop();
    1496                 :             }
    1497               0 :             if (isCurrent(nsHtml5Atoms::optgroup)) {
    1498               0 :               pop();
    1499                 :             }
    1500               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1501               0 :             attributes = nsnull;
    1502               0 :             NS_HTML5_BREAK(starttagloop);
    1503                 :           }
    1504                 :           case NS_HTML5TREE_BUILDER_SELECT: {
    1505               0 :             errStartSelectWhereEndSelectExpected();
    1506               0 :             eltPos = findLastInTableScope(name);
    1507               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    1508                 : 
    1509               0 :               errNoSelectInTableScope();
    1510               0 :               NS_HTML5_BREAK(starttagloop);
    1511                 :             } else {
    1512               0 :               while (currentPtr >= eltPos) {
    1513               0 :                 pop();
    1514                 :               }
    1515               0 :               resetTheInsertionMode();
    1516               0 :               NS_HTML5_BREAK(starttagloop);
    1517                 :             }
    1518                 :           }
    1519                 :           case NS_HTML5TREE_BUILDER_INPUT:
    1520                 :           case NS_HTML5TREE_BUILDER_TEXTAREA:
    1521                 :           case NS_HTML5TREE_BUILDER_KEYGEN: {
    1522               0 :             errStartTagWithSelectOpen(name);
    1523               0 :             eltPos = findLastInTableScope(nsHtml5Atoms::select);
    1524               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    1525                 : 
    1526               0 :               NS_HTML5_BREAK(starttagloop);
    1527                 :             }
    1528               0 :             while (currentPtr >= eltPos) {
    1529               0 :               pop();
    1530                 :             }
    1531               0 :             resetTheInsertionMode();
    1532               0 :             continue;
    1533                 :           }
    1534                 :           case NS_HTML5TREE_BUILDER_SCRIPT: {
    1535               0 :             appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1536               0 :             originalMode = mode;
    1537               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1538               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_SCRIPT_DATA, elementName);
    1539               0 :             attributes = nsnull;
    1540               0 :             NS_HTML5_BREAK(starttagloop);
    1541                 :           }
    1542                 :           default: {
    1543               0 :             errStrayStartTag(name);
    1544               0 :             NS_HTML5_BREAK(starttagloop);
    1545                 :           }
    1546                 :         }
    1547                 :       }
    1548                 :       case NS_HTML5TREE_BUILDER_AFTER_BODY: {
    1549               0 :         switch(group) {
    1550                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1551               0 :             errStrayStartTag(name);
    1552               0 :             if (!fragment) {
    1553               0 :               addAttributesToHtml(attributes);
    1554               0 :               attributes = nsnull;
    1555                 :             }
    1556               0 :             NS_HTML5_BREAK(starttagloop);
    1557                 :           }
    1558                 :           default: {
    1559               0 :             errStrayStartTag(name);
    1560               0 :             mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    1561               0 :             continue;
    1562                 :           }
    1563                 :         }
    1564                 :       }
    1565                 :       case NS_HTML5TREE_BUILDER_IN_FRAMESET: {
    1566               0 :         switch(group) {
    1567                 :           case NS_HTML5TREE_BUILDER_FRAMESET: {
    1568               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1569               0 :             attributes = nsnull;
    1570               0 :             NS_HTML5_BREAK(starttagloop);
    1571                 :           }
    1572                 :           case NS_HTML5TREE_BUILDER_FRAME: {
    1573               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1574               0 :             selfClosing = false;
    1575               0 :             attributes = nsnull;
    1576               0 :             NS_HTML5_BREAK(starttagloop);
    1577                 :           }
    1578                 :           default:
    1579                 :             ; // fall through
    1580                 :         }
    1581                 :       }
    1582                 :       case NS_HTML5TREE_BUILDER_AFTER_FRAMESET: {
    1583               0 :         switch(group) {
    1584                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1585               0 :             errStrayStartTag(name);
    1586               0 :             if (!fragment) {
    1587               0 :               addAttributesToHtml(attributes);
    1588               0 :               attributes = nsnull;
    1589                 :             }
    1590               0 :             NS_HTML5_BREAK(starttagloop);
    1591                 :           }
    1592                 :           case NS_HTML5TREE_BUILDER_NOFRAMES: {
    1593               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1594               0 :             originalMode = mode;
    1595               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1596               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1597               0 :             attributes = nsnull;
    1598               0 :             NS_HTML5_BREAK(starttagloop);
    1599                 :           }
    1600                 :           default: {
    1601               0 :             errStrayStartTag(name);
    1602               0 :             NS_HTML5_BREAK(starttagloop);
    1603                 :           }
    1604                 :         }
    1605                 :       }
    1606                 :       case NS_HTML5TREE_BUILDER_INITIAL: {
    1607              22 :         errStartTagWithoutDoctype();
    1608              22 :         documentModeInternal(QUIRKS_MODE, nsnull, nsnull, false);
    1609              22 :         mode = NS_HTML5TREE_BUILDER_BEFORE_HTML;
    1610              22 :         continue;
    1611                 :       }
    1612                 :       case NS_HTML5TREE_BUILDER_BEFORE_HTML: {
    1613              22 :         switch(group) {
    1614                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1615               4 :             if (attributes == nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
    1616               4 :               appendHtmlElementToDocumentAndPush();
    1617                 :             } else {
    1618               0 :               appendHtmlElementToDocumentAndPush(attributes);
    1619                 :             }
    1620               4 :             mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
    1621               4 :             attributes = nsnull;
    1622               4 :             NS_HTML5_BREAK(starttagloop);
    1623                 :           }
    1624                 :           default: {
    1625              18 :             appendHtmlElementToDocumentAndPush();
    1626              18 :             mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
    1627              18 :             continue;
    1628                 :           }
    1629                 :         }
    1630                 :       }
    1631                 :       case NS_HTML5TREE_BUILDER_BEFORE_HEAD: {
    1632              22 :         switch(group) {
    1633                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1634               0 :             errStrayStartTag(name);
    1635               0 :             if (!fragment) {
    1636               0 :               addAttributesToHtml(attributes);
    1637               0 :               attributes = nsnull;
    1638                 :             }
    1639               0 :             NS_HTML5_BREAK(starttagloop);
    1640                 :           }
    1641                 :           case NS_HTML5TREE_BUILDER_HEAD: {
    1642               0 :             appendToCurrentNodeAndPushHeadElement(attributes);
    1643               0 :             mode = NS_HTML5TREE_BUILDER_IN_HEAD;
    1644               0 :             attributes = nsnull;
    1645               0 :             NS_HTML5_BREAK(starttagloop);
    1646                 :           }
    1647                 :           default: {
    1648              22 :             appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    1649              22 :             mode = NS_HTML5TREE_BUILDER_IN_HEAD;
    1650              22 :             continue;
    1651                 :           }
    1652                 :         }
    1653                 :       }
    1654                 :       case NS_HTML5TREE_BUILDER_AFTER_HEAD: {
    1655              21 :         switch(group) {
    1656                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1657               0 :             errStrayStartTag(name);
    1658               0 :             if (!fragment) {
    1659               0 :               addAttributesToHtml(attributes);
    1660               0 :               attributes = nsnull;
    1661                 :             }
    1662               0 :             NS_HTML5_BREAK(starttagloop);
    1663                 :           }
    1664                 :           case NS_HTML5TREE_BUILDER_BODY: {
    1665               3 :             if (!attributes->getLength()) {
    1666               3 :               appendToCurrentNodeAndPushBodyElement();
    1667                 :             } else {
    1668               0 :               appendToCurrentNodeAndPushBodyElement(attributes);
    1669                 :             }
    1670               3 :             framesetOk = false;
    1671               3 :             mode = NS_HTML5TREE_BUILDER_IN_BODY;
    1672               3 :             attributes = nsnull;
    1673               3 :             NS_HTML5_BREAK(starttagloop);
    1674                 :           }
    1675                 :           case NS_HTML5TREE_BUILDER_FRAMESET: {
    1676               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1677               0 :             mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
    1678               0 :             attributes = nsnull;
    1679               0 :             NS_HTML5_BREAK(starttagloop);
    1680                 :           }
    1681                 :           case NS_HTML5TREE_BUILDER_BASE: {
    1682               0 :             errFooBetweenHeadAndBody(name);
    1683               0 :             pushHeadPointerOntoStack();
    1684               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1685               0 :             selfClosing = false;
    1686               0 :             pop();
    1687               0 :             attributes = nsnull;
    1688               0 :             NS_HTML5_BREAK(starttagloop);
    1689                 :           }
    1690                 :           case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND: {
    1691               0 :             errFooBetweenHeadAndBody(name);
    1692               0 :             pushHeadPointerOntoStack();
    1693               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1694               0 :             selfClosing = false;
    1695               0 :             pop();
    1696               0 :             attributes = nsnull;
    1697               0 :             NS_HTML5_BREAK(starttagloop);
    1698                 :           }
    1699                 :           case NS_HTML5TREE_BUILDER_META: {
    1700               0 :             errFooBetweenHeadAndBody(name);
    1701               0 :             checkMetaCharset(attributes);
    1702               0 :             pushHeadPointerOntoStack();
    1703               0 :             appendVoidElementToCurrentMayFoster(elementName, attributes);
    1704               0 :             selfClosing = false;
    1705               0 :             pop();
    1706               0 :             attributes = nsnull;
    1707               0 :             NS_HTML5_BREAK(starttagloop);
    1708                 :           }
    1709                 :           case NS_HTML5TREE_BUILDER_SCRIPT: {
    1710               0 :             errFooBetweenHeadAndBody(name);
    1711               0 :             pushHeadPointerOntoStack();
    1712               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1713               0 :             originalMode = mode;
    1714               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1715               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_SCRIPT_DATA, elementName);
    1716               0 :             attributes = nsnull;
    1717               0 :             NS_HTML5_BREAK(starttagloop);
    1718                 :           }
    1719                 :           case NS_HTML5TREE_BUILDER_STYLE:
    1720                 :           case NS_HTML5TREE_BUILDER_NOFRAMES: {
    1721               0 :             errFooBetweenHeadAndBody(name);
    1722               0 :             pushHeadPointerOntoStack();
    1723               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1724               0 :             originalMode = mode;
    1725               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1726               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RAWTEXT, elementName);
    1727               0 :             attributes = nsnull;
    1728               0 :             NS_HTML5_BREAK(starttagloop);
    1729                 :           }
    1730                 :           case NS_HTML5TREE_BUILDER_TITLE: {
    1731               0 :             errFooBetweenHeadAndBody(name);
    1732               0 :             pushHeadPointerOntoStack();
    1733               0 :             appendToCurrentNodeAndPushElement(elementName, attributes);
    1734               0 :             originalMode = mode;
    1735               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1736               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_RCDATA, elementName);
    1737               0 :             attributes = nsnull;
    1738               0 :             NS_HTML5_BREAK(starttagloop);
    1739                 :           }
    1740                 :           case NS_HTML5TREE_BUILDER_HEAD: {
    1741               0 :             errStrayStartTag(name);
    1742               0 :             NS_HTML5_BREAK(starttagloop);
    1743                 :           }
    1744                 :           default: {
    1745              18 :             appendToCurrentNodeAndPushBodyElement();
    1746              18 :             mode = NS_HTML5TREE_BUILDER_FRAMESET_OK;
    1747              18 :             continue;
    1748                 :           }
    1749                 :         }
    1750                 :       }
    1751                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY: {
    1752               0 :         switch(group) {
    1753                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1754               0 :             errStrayStartTag(name);
    1755               0 :             if (!fragment) {
    1756               0 :               addAttributesToHtml(attributes);
    1757               0 :               attributes = nsnull;
    1758                 :             }
    1759               0 :             NS_HTML5_BREAK(starttagloop);
    1760                 :           }
    1761                 :           default: {
    1762               0 :             errStrayStartTag(name);
    1763                 : 
    1764               0 :             mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    1765               0 :             continue;
    1766                 :           }
    1767                 :         }
    1768                 :       }
    1769                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET: {
    1770               0 :         switch(group) {
    1771                 :           case NS_HTML5TREE_BUILDER_HTML: {
    1772               0 :             errStrayStartTag(name);
    1773               0 :             if (!fragment) {
    1774               0 :               addAttributesToHtml(attributes);
    1775               0 :               attributes = nsnull;
    1776                 :             }
    1777               0 :             NS_HTML5_BREAK(starttagloop);
    1778                 :           }
    1779                 :           case NS_HTML5TREE_BUILDER_NOFRAMES: {
    1780               0 :             appendToCurrentNodeAndPushElementMayFoster(elementName, attributes);
    1781               0 :             originalMode = mode;
    1782               0 :             mode = NS_HTML5TREE_BUILDER_TEXT;
    1783               0 :             tokenizer->setStateAndEndTagExpectation(NS_HTML5TOKENIZER_SCRIPT_DATA, elementName);
    1784               0 :             attributes = nsnull;
    1785               0 :             NS_HTML5_BREAK(starttagloop);
    1786                 :           }
    1787                 :           default: {
    1788               0 :             errStrayStartTag(name);
    1789               0 :             NS_HTML5_BREAK(starttagloop);
    1790                 :           }
    1791                 :         }
    1792                 :       }
    1793                 :       case NS_HTML5TREE_BUILDER_TEXT: {
    1794                 : 
    1795               0 :         NS_HTML5_BREAK(starttagloop);
    1796                 :       }
    1797                 :     }
    1798                 :   }
    1799                 :   starttagloop_end: ;
    1800              87 :   if (selfClosing) {
    1801               0 :     errSelfClosing();
    1802                 :   }
    1803              87 :   if (attributes != nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES) {
    1804              86 :     delete attributes;
    1805                 :   }
    1806              87 : }
    1807                 : 
    1808                 : bool 
    1809             321 : nsHtml5TreeBuilder::isSpecialParentInForeign(nsHtml5StackNode* stackNode)
    1810                 : {
    1811             321 :   PRInt32 ns = stackNode->ns;
    1812             321 :   return (kNameSpaceID_XHTML == ns) || (stackNode->isHtmlIntegrationPoint()) || ((kNameSpaceID_MathML == ns) && (stackNode->getGroup() == NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT));
    1813                 : }
    1814                 : 
    1815                 : nsString* 
    1816               0 : nsHtml5TreeBuilder::extractCharsetFromContent(nsString* attributeValue)
    1817                 : {
    1818               0 :   PRInt32 charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1819               0 :   PRInt32 start = -1;
    1820               0 :   PRInt32 end = -1;
    1821               0 :   autoJArray<PRUnichar,PRInt32> buffer = nsHtml5Portability::newCharArrayFromString(attributeValue);
    1822               0 :   for (PRInt32 i = 0; i < buffer.length; i++) {
    1823               0 :     PRUnichar c = buffer[i];
    1824               0 :     switch(charsetState) {
    1825                 :       case NS_HTML5TREE_BUILDER_CHARSET_INITIAL: {
    1826               0 :         switch(c) {
    1827                 :           case 'c':
    1828                 :           case 'C': {
    1829               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_C;
    1830               0 :             continue;
    1831                 :           }
    1832                 :           default: {
    1833               0 :             continue;
    1834                 :           }
    1835                 :         }
    1836                 :       }
    1837                 :       case NS_HTML5TREE_BUILDER_CHARSET_C: {
    1838               0 :         switch(c) {
    1839                 :           case 'h':
    1840                 :           case 'H': {
    1841               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_H;
    1842               0 :             continue;
    1843                 :           }
    1844                 :           default: {
    1845               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1846               0 :             continue;
    1847                 :           }
    1848                 :         }
    1849                 :       }
    1850                 :       case NS_HTML5TREE_BUILDER_CHARSET_H: {
    1851               0 :         switch(c) {
    1852                 :           case 'a':
    1853                 :           case 'A': {
    1854               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_A;
    1855               0 :             continue;
    1856                 :           }
    1857                 :           default: {
    1858               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1859               0 :             continue;
    1860                 :           }
    1861                 :         }
    1862                 :       }
    1863                 :       case NS_HTML5TREE_BUILDER_CHARSET_A: {
    1864               0 :         switch(c) {
    1865                 :           case 'r':
    1866                 :           case 'R': {
    1867               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_R;
    1868               0 :             continue;
    1869                 :           }
    1870                 :           default: {
    1871               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1872               0 :             continue;
    1873                 :           }
    1874                 :         }
    1875                 :       }
    1876                 :       case NS_HTML5TREE_BUILDER_CHARSET_R: {
    1877               0 :         switch(c) {
    1878                 :           case 's':
    1879                 :           case 'S': {
    1880               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_S;
    1881               0 :             continue;
    1882                 :           }
    1883                 :           default: {
    1884               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1885               0 :             continue;
    1886                 :           }
    1887                 :         }
    1888                 :       }
    1889                 :       case NS_HTML5TREE_BUILDER_CHARSET_S: {
    1890               0 :         switch(c) {
    1891                 :           case 'e':
    1892                 :           case 'E': {
    1893               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_E;
    1894               0 :             continue;
    1895                 :           }
    1896                 :           default: {
    1897               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1898               0 :             continue;
    1899                 :           }
    1900                 :         }
    1901                 :       }
    1902                 :       case NS_HTML5TREE_BUILDER_CHARSET_E: {
    1903               0 :         switch(c) {
    1904                 :           case 't':
    1905                 :           case 'T': {
    1906               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_T;
    1907               0 :             continue;
    1908                 :           }
    1909                 :           default: {
    1910               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL;
    1911               0 :             continue;
    1912                 :           }
    1913                 :         }
    1914                 :       }
    1915                 :       case NS_HTML5TREE_BUILDER_CHARSET_T: {
    1916               0 :         switch(c) {
    1917                 :           case '\t':
    1918                 :           case '\n':
    1919                 :           case '\f':
    1920                 :           case '\r':
    1921                 :           case ' ': {
    1922               0 :             continue;
    1923                 :           }
    1924                 :           case '=': {
    1925               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_EQUALS;
    1926               0 :             continue;
    1927                 :           }
    1928                 :           default: {
    1929               0 :             return nsnull;
    1930                 :           }
    1931                 :         }
    1932                 :       }
    1933                 :       case NS_HTML5TREE_BUILDER_CHARSET_EQUALS: {
    1934               0 :         switch(c) {
    1935                 :           case '\t':
    1936                 :           case '\n':
    1937                 :           case '\f':
    1938                 :           case '\r':
    1939                 :           case ' ': {
    1940               0 :             continue;
    1941                 :           }
    1942                 :           case '\'': {
    1943               0 :             start = i + 1;
    1944               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED;
    1945               0 :             continue;
    1946                 :           }
    1947                 :           case '\"': {
    1948               0 :             start = i + 1;
    1949               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED;
    1950               0 :             continue;
    1951                 :           }
    1952                 :           default: {
    1953               0 :             start = i;
    1954               0 :             charsetState = NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED;
    1955               0 :             continue;
    1956                 :           }
    1957                 :         }
    1958                 :       }
    1959                 :       case NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED: {
    1960               0 :         switch(c) {
    1961                 :           case '\'': {
    1962               0 :             end = i;
    1963               0 :             NS_HTML5_BREAK(charsetloop);
    1964                 :           }
    1965                 :           default: {
    1966               0 :             continue;
    1967                 :           }
    1968                 :         }
    1969                 :       }
    1970                 :       case NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED: {
    1971               0 :         switch(c) {
    1972                 :           case '\"': {
    1973               0 :             end = i;
    1974               0 :             NS_HTML5_BREAK(charsetloop);
    1975                 :           }
    1976                 :           default: {
    1977               0 :             continue;
    1978                 :           }
    1979                 :         }
    1980                 :       }
    1981                 :       case NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED: {
    1982               0 :         switch(c) {
    1983                 :           case '\t':
    1984                 :           case '\n':
    1985                 :           case '\f':
    1986                 :           case '\r':
    1987                 :           case ' ':
    1988                 :           case ';': {
    1989               0 :             end = i;
    1990               0 :             NS_HTML5_BREAK(charsetloop);
    1991                 :           }
    1992                 :           default: {
    1993               0 :             continue;
    1994                 :           }
    1995                 :         }
    1996                 :       }
    1997                 :     }
    1998                 :   }
    1999                 :   charsetloop_end: ;
    2000               0 :   nsString* charset = nsnull;
    2001               0 :   if (start != -1) {
    2002               0 :     if (end == -1) {
    2003               0 :       end = buffer.length;
    2004                 :     }
    2005               0 :     charset = nsHtml5Portability::newStringFromBuffer(buffer, start, end - start);
    2006                 :   }
    2007               0 :   return charset;
    2008                 : }
    2009                 : 
    2010                 : void 
    2011               0 : nsHtml5TreeBuilder::checkMetaCharset(nsHtml5HtmlAttributes* attributes)
    2012                 : {
    2013               0 :   nsString* charset = attributes->getValue(nsHtml5AttributeName::ATTR_CHARSET);
    2014               0 :   if (charset) {
    2015               0 :     if (tokenizer->internalEncodingDeclaration(charset)) {
    2016               0 :       requestSuspension();
    2017               0 :       return;
    2018                 :     }
    2019               0 :     return;
    2020                 :   }
    2021               0 :   if (!nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("content-type", attributes->getValue(nsHtml5AttributeName::ATTR_HTTP_EQUIV))) {
    2022               0 :     return;
    2023                 :   }
    2024               0 :   nsString* content = attributes->getValue(nsHtml5AttributeName::ATTR_CONTENT);
    2025               0 :   if (content) {
    2026               0 :     nsString* extract = nsHtml5TreeBuilder::extractCharsetFromContent(content);
    2027               0 :     if (extract) {
    2028               0 :       if (tokenizer->internalEncodingDeclaration(extract)) {
    2029               0 :         requestSuspension();
    2030                 :       }
    2031                 :     }
    2032               0 :     nsHtml5Portability::releaseString(extract);
    2033                 :   }
    2034                 : }
    2035                 : 
    2036                 : void 
    2037              37 : nsHtml5TreeBuilder::endTag(nsHtml5ElementName* elementName)
    2038                 : {
    2039              37 :   flushCharacters();
    2040              37 :   needToDropLF = false;
    2041                 :   PRInt32 eltPos;
    2042              37 :   PRInt32 group = elementName->getGroup();
    2043              37 :   nsIAtom* name = elementName->name;
    2044               0 :   for (; ; ) {
    2045              37 :     if (isInForeign()) {
    2046               0 :       if (stack[currentPtr]->name != name) {
    2047               0 :         errEndTagDidNotMatchCurrentOpenElement(name, stack[currentPtr]->popName);
    2048                 :       }
    2049               0 :       eltPos = currentPtr;
    2050               0 :       for (; ; ) {
    2051               0 :         if (stack[eltPos]->name == name) {
    2052               0 :           while (currentPtr >= eltPos) {
    2053               0 :             pop();
    2054                 :           }
    2055               0 :           NS_HTML5_BREAK(endtagloop);
    2056                 :         }
    2057               0 :         if (stack[--eltPos]->ns == kNameSpaceID_XHTML) {
    2058                 :           break;
    2059                 :         }
    2060                 :       }
    2061                 :     }
    2062              37 :     switch(mode) {
    2063                 :       case NS_HTML5TREE_BUILDER_IN_ROW: {
    2064               0 :         switch(group) {
    2065                 :           case NS_HTML5TREE_BUILDER_TR: {
    2066               0 :             eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TR);
    2067               0 :             if (!eltPos) {
    2068                 : 
    2069               0 :               errNoTableRowToClose();
    2070               0 :               NS_HTML5_BREAK(endtagloop);
    2071                 :             }
    2072               0 :             clearStackBackTo(eltPos);
    2073               0 :             pop();
    2074               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
    2075               0 :             NS_HTML5_BREAK(endtagloop);
    2076                 :           }
    2077                 :           case NS_HTML5TREE_BUILDER_TABLE: {
    2078               0 :             eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TR);
    2079               0 :             if (!eltPos) {
    2080                 : 
    2081               0 :               errNoTableRowToClose();
    2082               0 :               NS_HTML5_BREAK(endtagloop);
    2083                 :             }
    2084               0 :             clearStackBackTo(eltPos);
    2085               0 :             pop();
    2086               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
    2087               0 :             continue;
    2088                 :           }
    2089                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT: {
    2090               0 :             if (findLastInTableScope(name) == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2091               0 :               errStrayEndTag(name);
    2092               0 :               NS_HTML5_BREAK(endtagloop);
    2093                 :             }
    2094               0 :             eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TR);
    2095               0 :             if (!eltPos) {
    2096                 : 
    2097               0 :               errNoTableRowToClose();
    2098               0 :               NS_HTML5_BREAK(endtagloop);
    2099                 :             }
    2100               0 :             clearStackBackTo(eltPos);
    2101               0 :             pop();
    2102               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
    2103               0 :             continue;
    2104                 :           }
    2105                 :           case NS_HTML5TREE_BUILDER_BODY:
    2106                 :           case NS_HTML5TREE_BUILDER_CAPTION:
    2107                 :           case NS_HTML5TREE_BUILDER_COL:
    2108                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
    2109                 :           case NS_HTML5TREE_BUILDER_HTML:
    2110                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
    2111               0 :             errStrayEndTag(name);
    2112               0 :             NS_HTML5_BREAK(endtagloop);
    2113                 :           }
    2114                 :           default:
    2115                 :             ; // fall through
    2116                 :         }
    2117                 :       }
    2118                 :       case NS_HTML5TREE_BUILDER_IN_TABLE_BODY: {
    2119               0 :         switch(group) {
    2120                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT: {
    2121               0 :             eltPos = findLastOrRoot(name);
    2122               0 :             if (!eltPos) {
    2123               0 :               errStrayEndTag(name);
    2124               0 :               NS_HTML5_BREAK(endtagloop);
    2125                 :             }
    2126               0 :             clearStackBackTo(eltPos);
    2127               0 :             pop();
    2128               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    2129               0 :             NS_HTML5_BREAK(endtagloop);
    2130                 :           }
    2131                 :           case NS_HTML5TREE_BUILDER_TABLE: {
    2132               0 :             eltPos = findLastInTableScopeOrRootTbodyTheadTfoot();
    2133               0 :             if (!eltPos) {
    2134                 : 
    2135               0 :               errStrayEndTag(name);
    2136               0 :               NS_HTML5_BREAK(endtagloop);
    2137                 :             }
    2138               0 :             clearStackBackTo(eltPos);
    2139               0 :             pop();
    2140               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    2141               0 :             continue;
    2142                 :           }
    2143                 :           case NS_HTML5TREE_BUILDER_BODY:
    2144                 :           case NS_HTML5TREE_BUILDER_CAPTION:
    2145                 :           case NS_HTML5TREE_BUILDER_COL:
    2146                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
    2147                 :           case NS_HTML5TREE_BUILDER_HTML:
    2148                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH:
    2149                 :           case NS_HTML5TREE_BUILDER_TR: {
    2150               0 :             errStrayEndTag(name);
    2151               0 :             NS_HTML5_BREAK(endtagloop);
    2152                 :           }
    2153                 :           default:
    2154                 :             ; // fall through
    2155                 :         }
    2156                 :       }
    2157                 :       case NS_HTML5TREE_BUILDER_IN_TABLE: {
    2158               0 :         switch(group) {
    2159                 :           case NS_HTML5TREE_BUILDER_TABLE: {
    2160               0 :             eltPos = findLast(nsHtml5Atoms::table);
    2161               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2162                 : 
    2163               0 :               errStrayEndTag(name);
    2164               0 :               NS_HTML5_BREAK(endtagloop);
    2165                 :             }
    2166               0 :             while (currentPtr >= eltPos) {
    2167               0 :               pop();
    2168                 :             }
    2169               0 :             resetTheInsertionMode();
    2170               0 :             NS_HTML5_BREAK(endtagloop);
    2171                 :           }
    2172                 :           case NS_HTML5TREE_BUILDER_BODY:
    2173                 :           case NS_HTML5TREE_BUILDER_CAPTION:
    2174                 :           case NS_HTML5TREE_BUILDER_COL:
    2175                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
    2176                 :           case NS_HTML5TREE_BUILDER_HTML:
    2177                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    2178                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH:
    2179                 :           case NS_HTML5TREE_BUILDER_TR: {
    2180               0 :             errStrayEndTag(name);
    2181               0 :             NS_HTML5_BREAK(endtagloop);
    2182                 :           }
    2183                 :           default: {
    2184               0 :             errStrayEndTag(name);
    2185                 :           }
    2186                 :         }
    2187                 :       }
    2188                 :       case NS_HTML5TREE_BUILDER_IN_CAPTION: {
    2189               0 :         switch(group) {
    2190                 :           case NS_HTML5TREE_BUILDER_CAPTION: {
    2191               0 :             eltPos = findLastInTableScope(nsHtml5Atoms::caption);
    2192               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2193               0 :               NS_HTML5_BREAK(endtagloop);
    2194                 :             }
    2195               0 :             generateImpliedEndTags();
    2196               0 :             if (!!NS_UNLIKELY(mViewSource) && currentPtr != eltPos) {
    2197               0 :               errUnclosedElements(eltPos, name);
    2198                 :             }
    2199               0 :             while (currentPtr >= eltPos) {
    2200               0 :               pop();
    2201                 :             }
    2202               0 :             clearTheListOfActiveFormattingElementsUpToTheLastMarker();
    2203               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    2204               0 :             NS_HTML5_BREAK(endtagloop);
    2205                 :           }
    2206                 :           case NS_HTML5TREE_BUILDER_TABLE: {
    2207               0 :             errTableClosedWhileCaptionOpen();
    2208               0 :             eltPos = findLastInTableScope(nsHtml5Atoms::caption);
    2209               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2210               0 :               NS_HTML5_BREAK(endtagloop);
    2211                 :             }
    2212               0 :             generateImpliedEndTags();
    2213               0 :             if (!!NS_UNLIKELY(mViewSource) && currentPtr != eltPos) {
    2214               0 :               errUnclosedElements(eltPos, name);
    2215                 :             }
    2216               0 :             while (currentPtr >= eltPos) {
    2217               0 :               pop();
    2218                 :             }
    2219               0 :             clearTheListOfActiveFormattingElementsUpToTheLastMarker();
    2220               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    2221               0 :             continue;
    2222                 :           }
    2223                 :           case NS_HTML5TREE_BUILDER_BODY:
    2224                 :           case NS_HTML5TREE_BUILDER_COL:
    2225                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
    2226                 :           case NS_HTML5TREE_BUILDER_HTML:
    2227                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    2228                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH:
    2229                 :           case NS_HTML5TREE_BUILDER_TR: {
    2230               0 :             errStrayEndTag(name);
    2231               0 :             NS_HTML5_BREAK(endtagloop);
    2232                 :           }
    2233                 :           default:
    2234                 :             ; // fall through
    2235                 :         }
    2236                 :       }
    2237                 :       case NS_HTML5TREE_BUILDER_IN_CELL: {
    2238               0 :         switch(group) {
    2239                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
    2240               0 :             eltPos = findLastInTableScope(name);
    2241               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2242               0 :               errStrayEndTag(name);
    2243               0 :               NS_HTML5_BREAK(endtagloop);
    2244                 :             }
    2245               0 :             generateImpliedEndTags();
    2246               0 :             if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    2247               0 :               errUnclosedElements(eltPos, name);
    2248                 :             }
    2249               0 :             while (currentPtr >= eltPos) {
    2250               0 :               pop();
    2251                 :             }
    2252               0 :             clearTheListOfActiveFormattingElementsUpToTheLastMarker();
    2253               0 :             mode = NS_HTML5TREE_BUILDER_IN_ROW;
    2254               0 :             NS_HTML5_BREAK(endtagloop);
    2255                 :           }
    2256                 :           case NS_HTML5TREE_BUILDER_TABLE:
    2257                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    2258                 :           case NS_HTML5TREE_BUILDER_TR: {
    2259               0 :             if (findLastInTableScope(name) == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2260               0 :               errStrayEndTag(name);
    2261               0 :               NS_HTML5_BREAK(endtagloop);
    2262                 :             }
    2263               0 :             closeTheCell(findLastInTableScopeTdTh());
    2264               0 :             continue;
    2265                 :           }
    2266                 :           case NS_HTML5TREE_BUILDER_BODY:
    2267                 :           case NS_HTML5TREE_BUILDER_CAPTION:
    2268                 :           case NS_HTML5TREE_BUILDER_COL:
    2269                 :           case NS_HTML5TREE_BUILDER_COLGROUP:
    2270                 :           case NS_HTML5TREE_BUILDER_HTML: {
    2271               0 :             errStrayEndTag(name);
    2272               0 :             NS_HTML5_BREAK(endtagloop);
    2273                 :           }
    2274                 :           default:
    2275                 :             ; // fall through
    2276                 :         }
    2277                 :       }
    2278                 :       case NS_HTML5TREE_BUILDER_FRAMESET_OK:
    2279                 :       case NS_HTML5TREE_BUILDER_IN_BODY: {
    2280              33 :         switch(group) {
    2281                 :           case NS_HTML5TREE_BUILDER_BODY: {
    2282               4 :             if (!isSecondOnStackBody()) {
    2283                 : 
    2284               0 :               errStrayEndTag(name);
    2285               0 :               NS_HTML5_BREAK(endtagloop);
    2286                 :             }
    2287                 : 
    2288               4 :             if (NS_UNLIKELY(mViewSource)) {
    2289               0 :               for (PRInt32 i = 2; i <= currentPtr; i++) {
    2290               0 :                 switch(stack[i]->getGroup()) {
    2291                 :                   case NS_HTML5TREE_BUILDER_DD_OR_DT:
    2292                 :                   case NS_HTML5TREE_BUILDER_LI:
    2293                 :                   case NS_HTML5TREE_BUILDER_OPTGROUP:
    2294                 :                   case NS_HTML5TREE_BUILDER_OPTION:
    2295                 :                   case NS_HTML5TREE_BUILDER_P:
    2296                 :                   case NS_HTML5TREE_BUILDER_RT_OR_RP:
    2297                 :                   case NS_HTML5TREE_BUILDER_TD_OR_TH:
    2298                 :                   case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT: {
    2299                 :                     break;
    2300                 :                   }
    2301                 :                   default: {
    2302               0 :                     errEndWithUnclosedElements(name);
    2303               0 :                     NS_HTML5_BREAK(uncloseloop1);
    2304                 :                   }
    2305                 :                 }
    2306                 :               }
    2307                 :               uncloseloop1_end: ;
    2308                 :             }
    2309               4 :             mode = NS_HTML5TREE_BUILDER_AFTER_BODY;
    2310               4 :             NS_HTML5_BREAK(endtagloop);
    2311                 :           }
    2312                 :           case NS_HTML5TREE_BUILDER_HTML: {
    2313               0 :             if (!isSecondOnStackBody()) {
    2314                 : 
    2315               0 :               errStrayEndTag(name);
    2316               0 :               NS_HTML5_BREAK(endtagloop);
    2317                 :             }
    2318               0 :             if (NS_UNLIKELY(mViewSource)) {
    2319               0 :               for (PRInt32 i = 0; i <= currentPtr; i++) {
    2320               0 :                 switch(stack[i]->getGroup()) {
    2321                 :                   case NS_HTML5TREE_BUILDER_DD_OR_DT:
    2322                 :                   case NS_HTML5TREE_BUILDER_LI:
    2323                 :                   case NS_HTML5TREE_BUILDER_P:
    2324                 :                   case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    2325                 :                   case NS_HTML5TREE_BUILDER_TD_OR_TH:
    2326                 :                   case NS_HTML5TREE_BUILDER_BODY:
    2327                 :                   case NS_HTML5TREE_BUILDER_HTML: {
    2328                 :                     break;
    2329                 :                   }
    2330                 :                   default: {
    2331               0 :                     errEndWithUnclosedElements(name);
    2332               0 :                     NS_HTML5_BREAK(uncloseloop2);
    2333                 :                   }
    2334                 :                 }
    2335                 :               }
    2336                 :               uncloseloop2_end: ;
    2337                 :             }
    2338               0 :             mode = NS_HTML5TREE_BUILDER_AFTER_BODY;
    2339               0 :             continue;
    2340                 :           }
    2341                 :           case NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU:
    2342                 :           case NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL:
    2343                 :           case NS_HTML5TREE_BUILDER_PRE_OR_LISTING:
    2344                 :           case NS_HTML5TREE_BUILDER_FIELDSET:
    2345                 :           case NS_HTML5TREE_BUILDER_BUTTON:
    2346                 :           case NS_HTML5TREE_BUILDER_ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_NAV_OR_SECTION_OR_SUMMARY: {
    2347               4 :             eltPos = findLastInScope(name);
    2348               4 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2349               0 :               errStrayEndTag(name);
    2350                 :             } else {
    2351               4 :               generateImpliedEndTags();
    2352               4 :               if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    2353               0 :                 errUnclosedElements(eltPos, name);
    2354                 :               }
    2355              12 :               while (currentPtr >= eltPos) {
    2356               4 :                 pop();
    2357                 :               }
    2358                 :             }
    2359               4 :             NS_HTML5_BREAK(endtagloop);
    2360                 :           }
    2361                 :           case NS_HTML5TREE_BUILDER_FORM: {
    2362               0 :             if (!formPointer) {
    2363               0 :               errStrayEndTag(name);
    2364               0 :               NS_HTML5_BREAK(endtagloop);
    2365                 :             }
    2366               0 :             formPointer = nsnull;
    2367               0 :             eltPos = findLastInScope(name);
    2368               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2369               0 :               errStrayEndTag(name);
    2370               0 :               NS_HTML5_BREAK(endtagloop);
    2371                 :             }
    2372               0 :             generateImpliedEndTags();
    2373               0 :             if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    2374               0 :               errUnclosedElements(eltPos, name);
    2375                 :             }
    2376               0 :             removeFromStack(eltPos);
    2377               0 :             NS_HTML5_BREAK(endtagloop);
    2378                 :           }
    2379                 :           case NS_HTML5TREE_BUILDER_P: {
    2380              18 :             eltPos = findLastInButtonScope(nsHtml5Atoms::p);
    2381              18 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2382               0 :               errNoElementToCloseButEndTagSeen(nsHtml5Atoms::p);
    2383               0 :               if (isInForeign()) {
    2384               0 :                 errHtmlStartTagInForeignContext(name);
    2385               0 :                 while (stack[currentPtr]->ns != kNameSpaceID_XHTML) {
    2386               0 :                   pop();
    2387                 :                 }
    2388                 :               }
    2389               0 :               appendVoidElementToCurrentMayFoster(elementName, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    2390               0 :               NS_HTML5_BREAK(endtagloop);
    2391                 :             }
    2392              18 :             generateImpliedEndTagsExceptFor(nsHtml5Atoms::p);
    2393                 : 
    2394              18 :             if (!!NS_UNLIKELY(mViewSource) && eltPos != currentPtr) {
    2395               0 :               errUnclosedElements(eltPos, name);
    2396                 :             }
    2397              54 :             while (currentPtr >= eltPos) {
    2398              18 :               pop();
    2399                 :             }
    2400              18 :             NS_HTML5_BREAK(endtagloop);
    2401                 :           }
    2402                 :           case NS_HTML5TREE_BUILDER_LI: {
    2403               0 :             eltPos = findLastInListScope(name);
    2404               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2405               0 :               errNoElementToCloseButEndTagSeen(name);
    2406                 :             } else {
    2407               0 :               generateImpliedEndTagsExceptFor(name);
    2408               0 :               if (!!NS_UNLIKELY(mViewSource) && eltPos != currentPtr) {
    2409               0 :                 errUnclosedElements(eltPos, name);
    2410                 :               }
    2411               0 :               while (currentPtr >= eltPos) {
    2412               0 :                 pop();
    2413                 :               }
    2414                 :             }
    2415               0 :             NS_HTML5_BREAK(endtagloop);
    2416                 :           }
    2417                 :           case NS_HTML5TREE_BUILDER_DD_OR_DT: {
    2418               0 :             eltPos = findLastInScope(name);
    2419               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2420               0 :               errNoElementToCloseButEndTagSeen(name);
    2421                 :             } else {
    2422               0 :               generateImpliedEndTagsExceptFor(name);
    2423               0 :               if (!!NS_UNLIKELY(mViewSource) && eltPos != currentPtr) {
    2424               0 :                 errUnclosedElements(eltPos, name);
    2425                 :               }
    2426               0 :               while (currentPtr >= eltPos) {
    2427               0 :                 pop();
    2428                 :               }
    2429                 :             }
    2430               0 :             NS_HTML5_BREAK(endtagloop);
    2431                 :           }
    2432                 :           case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6: {
    2433               4 :             eltPos = findLastInScopeHn();
    2434               4 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2435               0 :               errStrayEndTag(name);
    2436                 :             } else {
    2437               4 :               generateImpliedEndTags();
    2438               4 :               if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    2439               0 :                 errUnclosedElements(eltPos, name);
    2440                 :               }
    2441              12 :               while (currentPtr >= eltPos) {
    2442               4 :                 pop();
    2443                 :               }
    2444                 :             }
    2445               4 :             NS_HTML5_BREAK(endtagloop);
    2446                 :           }
    2447                 :           case NS_HTML5TREE_BUILDER_OBJECT:
    2448                 :           case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET: {
    2449               0 :             eltPos = findLastInScope(name);
    2450               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2451               0 :               errStrayEndTag(name);
    2452                 :             } else {
    2453               0 :               generateImpliedEndTags();
    2454               0 :               if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    2455               0 :                 errUnclosedElements(eltPos, name);
    2456                 :               }
    2457               0 :               while (currentPtr >= eltPos) {
    2458               0 :                 pop();
    2459                 :               }
    2460               0 :               clearTheListOfActiveFormattingElementsUpToTheLastMarker();
    2461                 :             }
    2462               0 :             NS_HTML5_BREAK(endtagloop);
    2463                 :           }
    2464                 :           case NS_HTML5TREE_BUILDER_BR: {
    2465               0 :             errEndTagBr();
    2466               0 :             if (isInForeign()) {
    2467               0 :               errHtmlStartTagInForeignContext(name);
    2468               0 :               while (stack[currentPtr]->ns != kNameSpaceID_XHTML) {
    2469               0 :                 pop();
    2470                 :               }
    2471                 :             }
    2472               0 :             reconstructTheActiveFormattingElements();
    2473               0 :             appendVoidElementToCurrentMayFoster(elementName, nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    2474               0 :             NS_HTML5_BREAK(endtagloop);
    2475                 :           }
    2476                 :           case NS_HTML5TREE_BUILDER_AREA_OR_WBR:
    2477                 : #ifdef ENABLE_VOID_MENUITEM
    2478                 :           case NS_HTML5TREE_BUILDER_MENUITEM:
    2479                 : #endif
    2480                 :           case NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE_OR_TRACK:
    2481                 :           case NS_HTML5TREE_BUILDER_EMBED_OR_IMG:
    2482                 :           case NS_HTML5TREE_BUILDER_IMAGE:
    2483                 :           case NS_HTML5TREE_BUILDER_INPUT:
    2484                 :           case NS_HTML5TREE_BUILDER_KEYGEN:
    2485                 :           case NS_HTML5TREE_BUILDER_HR:
    2486                 :           case NS_HTML5TREE_BUILDER_ISINDEX:
    2487                 :           case NS_HTML5TREE_BUILDER_IFRAME:
    2488                 :           case NS_HTML5TREE_BUILDER_NOEMBED:
    2489                 :           case NS_HTML5TREE_BUILDER_NOFRAMES:
    2490                 :           case NS_HTML5TREE_BUILDER_SELECT:
    2491                 :           case NS_HTML5TREE_BUILDER_TABLE:
    2492                 :           case NS_HTML5TREE_BUILDER_TEXTAREA: {
    2493               0 :             errStrayEndTag(name);
    2494               0 :             NS_HTML5_BREAK(endtagloop);
    2495                 :           }
    2496                 :           case NS_HTML5TREE_BUILDER_NOSCRIPT: {
    2497               0 :             if (scriptingEnabled) {
    2498               0 :               errStrayEndTag(name);
    2499               0 :               NS_HTML5_BREAK(endtagloop);
    2500                 :             } else {
    2501                 :             }
    2502                 :           }
    2503                 :           case NS_HTML5TREE_BUILDER_A:
    2504                 :           case NS_HTML5TREE_BUILDER_B_OR_BIG_OR_CODE_OR_EM_OR_I_OR_S_OR_SMALL_OR_STRIKE_OR_STRONG_OR_TT_OR_U:
    2505                 :           case NS_HTML5TREE_BUILDER_FONT:
    2506                 :           case NS_HTML5TREE_BUILDER_NOBR: {
    2507               0 :             if (adoptionAgencyEndTag(name)) {
    2508               0 :               NS_HTML5_BREAK(endtagloop);
    2509                 :             }
    2510                 :           }
    2511                 :           default: {
    2512               3 :             if (isCurrent(name)) {
    2513               1 :               pop();
    2514               1 :               NS_HTML5_BREAK(endtagloop);
    2515                 :             }
    2516               2 :             eltPos = currentPtr;
    2517               0 :             for (; ; ) {
    2518               2 :               nsHtml5StackNode* node = stack[eltPos];
    2519               2 :               if (node->name == name) {
    2520               0 :                 generateImpliedEndTags();
    2521               0 :                 if (!!NS_UNLIKELY(mViewSource) && !isCurrent(name)) {
    2522               0 :                   errUnclosedElements(eltPos, name);
    2523                 :                 }
    2524               0 :                 while (currentPtr >= eltPos) {
    2525               0 :                   pop();
    2526                 :                 }
    2527               0 :                 NS_HTML5_BREAK(endtagloop);
    2528               2 :               } else if (node->isSpecial()) {
    2529               2 :                 errStrayEndTag(name);
    2530               2 :                 NS_HTML5_BREAK(endtagloop);
    2531                 :               }
    2532               0 :               eltPos--;
    2533                 :             }
    2534                 :           }
    2535                 :         }
    2536                 :       }
    2537                 :       case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP: {
    2538               0 :         switch(group) {
    2539                 :           case NS_HTML5TREE_BUILDER_COLGROUP: {
    2540               0 :             if (!currentPtr) {
    2541                 : 
    2542               0 :               errGarbageInColgroup();
    2543               0 :               NS_HTML5_BREAK(endtagloop);
    2544                 :             }
    2545               0 :             pop();
    2546               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    2547               0 :             NS_HTML5_BREAK(endtagloop);
    2548                 :           }
    2549                 :           case NS_HTML5TREE_BUILDER_COL: {
    2550               0 :             errStrayEndTag(name);
    2551               0 :             NS_HTML5_BREAK(endtagloop);
    2552                 :           }
    2553                 :           default: {
    2554               0 :             if (!currentPtr) {
    2555                 : 
    2556               0 :               errGarbageInColgroup();
    2557               0 :               NS_HTML5_BREAK(endtagloop);
    2558                 :             }
    2559               0 :             pop();
    2560               0 :             mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    2561               0 :             continue;
    2562                 :           }
    2563                 :         }
    2564                 :       }
    2565                 :       case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE: {
    2566               0 :         switch(group) {
    2567                 :           case NS_HTML5TREE_BUILDER_CAPTION:
    2568                 :           case NS_HTML5TREE_BUILDER_TABLE:
    2569                 :           case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT:
    2570                 :           case NS_HTML5TREE_BUILDER_TR:
    2571                 :           case NS_HTML5TREE_BUILDER_TD_OR_TH: {
    2572               0 :             errEndTagSeenWithSelectOpen(name);
    2573               0 :             if (findLastInTableScope(name) != NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2574               0 :               eltPos = findLastInTableScope(nsHtml5Atoms::select);
    2575               0 :               if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2576                 : 
    2577               0 :                 NS_HTML5_BREAK(endtagloop);
    2578                 :               }
    2579               0 :               while (currentPtr >= eltPos) {
    2580               0 :                 pop();
    2581                 :               }
    2582               0 :               resetTheInsertionMode();
    2583               0 :               continue;
    2584                 :             } else {
    2585               0 :               NS_HTML5_BREAK(endtagloop);
    2586                 :             }
    2587                 :           }
    2588                 :           default:
    2589                 :             ; // fall through
    2590                 :         }
    2591                 :       }
    2592                 :       case NS_HTML5TREE_BUILDER_IN_SELECT: {
    2593               0 :         switch(group) {
    2594                 :           case NS_HTML5TREE_BUILDER_OPTION: {
    2595               0 :             if (isCurrent(nsHtml5Atoms::option)) {
    2596               0 :               pop();
    2597               0 :               NS_HTML5_BREAK(endtagloop);
    2598                 :             } else {
    2599               0 :               errStrayEndTag(name);
    2600               0 :               NS_HTML5_BREAK(endtagloop);
    2601                 :             }
    2602                 :           }
    2603                 :           case NS_HTML5TREE_BUILDER_OPTGROUP: {
    2604               0 :             if (isCurrent(nsHtml5Atoms::option) && nsHtml5Atoms::optgroup == stack[currentPtr - 1]->name) {
    2605               0 :               pop();
    2606                 :             }
    2607               0 :             if (isCurrent(nsHtml5Atoms::optgroup)) {
    2608               0 :               pop();
    2609                 :             } else {
    2610               0 :               errStrayEndTag(name);
    2611                 :             }
    2612               0 :             NS_HTML5_BREAK(endtagloop);
    2613                 :           }
    2614                 :           case NS_HTML5TREE_BUILDER_SELECT: {
    2615               0 :             eltPos = findLastInTableScope(nsHtml5Atoms::select);
    2616               0 :             if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    2617                 : 
    2618               0 :               errStrayEndTag(name);
    2619               0 :               NS_HTML5_BREAK(endtagloop);
    2620                 :             }
    2621               0 :             while (currentPtr >= eltPos) {
    2622               0 :               pop();
    2623                 :             }
    2624               0 :             resetTheInsertionMode();
    2625               0 :             NS_HTML5_BREAK(endtagloop);
    2626                 :           }
    2627                 :           default: {
    2628               0 :             errStrayEndTag(name);
    2629               0 :             NS_HTML5_BREAK(endtagloop);
    2630                 :           }
    2631                 :         }
    2632                 :       }
    2633                 :       case NS_HTML5TREE_BUILDER_AFTER_BODY: {
    2634               4 :         switch(group) {
    2635                 :           case NS_HTML5TREE_BUILDER_HTML: {
    2636               4 :             if (fragment) {
    2637               0 :               errStrayEndTag(name);
    2638               0 :               NS_HTML5_BREAK(endtagloop);
    2639                 :             } else {
    2640               4 :               mode = NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY;
    2641               4 :               NS_HTML5_BREAK(endtagloop);
    2642                 :             }
    2643                 :           }
    2644                 :           default: {
    2645               0 :             errEndTagAfterBody();
    2646               0 :             mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    2647               0 :             continue;
    2648                 :           }
    2649                 :         }
    2650                 :       }
    2651                 :       case NS_HTML5TREE_BUILDER_IN_FRAMESET: {
    2652               0 :         switch(group) {
    2653                 :           case NS_HTML5TREE_BUILDER_FRAMESET: {
    2654               0 :             if (!currentPtr) {
    2655                 : 
    2656               0 :               errStrayEndTag(name);
    2657               0 :               NS_HTML5_BREAK(endtagloop);
    2658                 :             }
    2659               0 :             pop();
    2660               0 :             if ((!fragment) && !isCurrent(nsHtml5Atoms::frameset)) {
    2661               0 :               mode = NS_HTML5TREE_BUILDER_AFTER_FRAMESET;
    2662                 :             }
    2663               0 :             NS_HTML5_BREAK(endtagloop);
    2664                 :           }
    2665                 :           default: {
    2666               0 :             errStrayEndTag(name);
    2667               0 :             NS_HTML5_BREAK(endtagloop);
    2668                 :           }
    2669                 :         }
    2670                 :       }
    2671                 :       case NS_HTML5TREE_BUILDER_AFTER_FRAMESET: {
    2672               0 :         switch(group) {
    2673                 :           case NS_HTML5TREE_BUILDER_HTML: {
    2674               0 :             mode = NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET;
    2675               0 :             NS_HTML5_BREAK(endtagloop);
    2676                 :           }
    2677                 :           default: {
    2678               0 :             errStrayEndTag(name);
    2679               0 :             NS_HTML5_BREAK(endtagloop);
    2680                 :           }
    2681                 :         }
    2682                 :       }
    2683                 :       case NS_HTML5TREE_BUILDER_INITIAL: {
    2684               0 :         errEndTagSeenWithoutDoctype();
    2685               0 :         documentModeInternal(QUIRKS_MODE, nsnull, nsnull, false);
    2686               0 :         mode = NS_HTML5TREE_BUILDER_BEFORE_HTML;
    2687               0 :         continue;
    2688                 :       }
    2689                 :       case NS_HTML5TREE_BUILDER_BEFORE_HTML: {
    2690               0 :         switch(group) {
    2691                 :           case NS_HTML5TREE_BUILDER_HEAD:
    2692                 :           case NS_HTML5TREE_BUILDER_BR:
    2693                 :           case NS_HTML5TREE_BUILDER_HTML:
    2694                 :           case NS_HTML5TREE_BUILDER_BODY: {
    2695               0 :             appendHtmlElementToDocumentAndPush();
    2696               0 :             mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
    2697               0 :             continue;
    2698                 :           }
    2699                 :           default: {
    2700               0 :             errStrayEndTag(name);
    2701               0 :             NS_HTML5_BREAK(endtagloop);
    2702                 :           }
    2703                 :         }
    2704                 :       }
    2705                 :       case NS_HTML5TREE_BUILDER_BEFORE_HEAD: {
    2706               0 :         switch(group) {
    2707                 :           case NS_HTML5TREE_BUILDER_HEAD:
    2708                 :           case NS_HTML5TREE_BUILDER_BR:
    2709                 :           case NS_HTML5TREE_BUILDER_HTML:
    2710                 :           case NS_HTML5TREE_BUILDER_BODY: {
    2711               0 :             appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes::EMPTY_ATTRIBUTES);
    2712               0 :             mode = NS_HTML5TREE_BUILDER_IN_HEAD;
    2713               0 :             continue;
    2714                 :           }
    2715                 :           default: {
    2716               0 :             errStrayEndTag(name);
    2717               0 :             NS_HTML5_BREAK(endtagloop);
    2718                 :           }
    2719                 :         }
    2720                 :       }
    2721                 :       case NS_HTML5TREE_BUILDER_IN_HEAD: {
    2722               0 :         switch(group) {
    2723                 :           case NS_HTML5TREE_BUILDER_HEAD: {
    2724               0 :             pop();
    2725               0 :             mode = NS_HTML5TREE_BUILDER_AFTER_HEAD;
    2726               0 :             NS_HTML5_BREAK(endtagloop);
    2727                 :           }
    2728                 :           case NS_HTML5TREE_BUILDER_BR:
    2729                 :           case NS_HTML5TREE_BUILDER_HTML:
    2730                 :           case NS_HTML5TREE_BUILDER_BODY: {
    2731               0 :             pop();
    2732               0 :             mode = NS_HTML5TREE_BUILDER_AFTER_HEAD;
    2733               0 :             continue;
    2734                 :           }
    2735                 :           default: {
    2736               0 :             errStrayEndTag(name);
    2737               0 :             NS_HTML5_BREAK(endtagloop);
    2738                 :           }
    2739                 :         }
    2740                 :       }
    2741                 :       case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT: {
    2742               0 :         switch(group) {
    2743                 :           case NS_HTML5TREE_BUILDER_NOSCRIPT: {
    2744               0 :             pop();
    2745               0 :             mode = NS_HTML5TREE_BUILDER_IN_HEAD;
    2746               0 :             NS_HTML5_BREAK(endtagloop);
    2747                 :           }
    2748                 :           case NS_HTML5TREE_BUILDER_BR: {
    2749               0 :             errStrayEndTag(name);
    2750               0 :             pop();
    2751               0 :             mode = NS_HTML5TREE_BUILDER_IN_HEAD;
    2752               0 :             continue;
    2753                 :           }
    2754                 :           default: {
    2755               0 :             errStrayEndTag(name);
    2756               0 :             NS_HTML5_BREAK(endtagloop);
    2757                 :           }
    2758                 :         }
    2759                 :       }
    2760                 :       case NS_HTML5TREE_BUILDER_AFTER_HEAD: {
    2761               0 :         switch(group) {
    2762                 :           case NS_HTML5TREE_BUILDER_HTML:
    2763                 :           case NS_HTML5TREE_BUILDER_BODY:
    2764                 :           case NS_HTML5TREE_BUILDER_BR: {
    2765               0 :             appendToCurrentNodeAndPushBodyElement();
    2766               0 :             mode = NS_HTML5TREE_BUILDER_FRAMESET_OK;
    2767               0 :             continue;
    2768                 :           }
    2769                 :           default: {
    2770               0 :             errStrayEndTag(name);
    2771               0 :             NS_HTML5_BREAK(endtagloop);
    2772                 :           }
    2773                 :         }
    2774                 :       }
    2775                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY: {
    2776               0 :         errStrayEndTag(name);
    2777               0 :         mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    2778               0 :         continue;
    2779                 :       }
    2780                 :       case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET: {
    2781               0 :         errStrayEndTag(name);
    2782               0 :         mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
    2783               0 :         continue;
    2784                 :       }
    2785                 :       case NS_HTML5TREE_BUILDER_TEXT: {
    2786               0 :         pop();
    2787               0 :         if (originalMode == NS_HTML5TREE_BUILDER_AFTER_HEAD) {
    2788               0 :           silentPop();
    2789                 :         }
    2790               0 :         mode = originalMode;
    2791               0 :         NS_HTML5_BREAK(endtagloop);
    2792                 :       }
    2793                 :     }
    2794                 :   }
    2795                 :   endtagloop_end: ;
    2796              37 : }
    2797                 : 
    2798                 : PRInt32 
    2799               0 : nsHtml5TreeBuilder::findLastInTableScopeOrRootTbodyTheadTfoot()
    2800                 : {
    2801               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2802               0 :     if (stack[i]->getGroup() == NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT) {
    2803               0 :       return i;
    2804                 :     }
    2805                 :   }
    2806               0 :   return 0;
    2807                 : }
    2808                 : 
    2809                 : PRInt32 
    2810               0 : nsHtml5TreeBuilder::findLast(nsIAtom* name)
    2811                 : {
    2812               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2813               0 :     if (stack[i]->name == name) {
    2814               0 :       return i;
    2815                 :     }
    2816                 :   }
    2817               0 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2818                 : }
    2819                 : 
    2820                 : PRInt32 
    2821               0 : nsHtml5TreeBuilder::findLastInTableScope(nsIAtom* name)
    2822                 : {
    2823               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2824               0 :     if (stack[i]->name == name) {
    2825               0 :       return i;
    2826               0 :     } else if (stack[i]->name == nsHtml5Atoms::table) {
    2827               0 :       return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2828                 :     }
    2829                 :   }
    2830               0 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2831                 : }
    2832                 : 
    2833                 : PRInt32 
    2834              52 : nsHtml5TreeBuilder::findLastInButtonScope(nsIAtom* name)
    2835                 : {
    2836              94 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2837              60 :     if (stack[i]->name == name) {
    2838              18 :       return i;
    2839              42 :     } else if (stack[i]->isScoping() || stack[i]->name == nsHtml5Atoms::button) {
    2840               0 :       return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2841                 :     }
    2842                 :   }
    2843              34 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2844                 : }
    2845                 : 
    2846                 : PRInt32 
    2847               4 : nsHtml5TreeBuilder::findLastInScope(nsIAtom* name)
    2848                 : {
    2849               8 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2850               8 :     if (stack[i]->name == name) {
    2851               4 :       return i;
    2852               4 :     } else if (stack[i]->isScoping()) {
    2853               0 :       return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2854                 :     }
    2855                 :   }
    2856               0 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2857                 : }
    2858                 : 
    2859                 : PRInt32 
    2860               0 : nsHtml5TreeBuilder::findLastInListScope(nsIAtom* name)
    2861                 : {
    2862               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2863               0 :     if (stack[i]->name == name) {
    2864               0 :       return i;
    2865               0 :     } else if (stack[i]->isScoping() || stack[i]->name == nsHtml5Atoms::ul || stack[i]->name == nsHtml5Atoms::ol) {
    2866               0 :       return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2867                 :     }
    2868                 :   }
    2869               0 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2870                 : }
    2871                 : 
    2872                 : PRInt32 
    2873               4 : nsHtml5TreeBuilder::findLastInScopeHn()
    2874                 : {
    2875               4 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    2876               4 :     if (stack[i]->getGroup() == NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6) {
    2877               4 :       return i;
    2878               0 :     } else if (stack[i]->isScoping()) {
    2879               0 :       return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2880                 :     }
    2881                 :   }
    2882               0 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    2883                 : }
    2884                 : 
    2885                 : void 
    2886              22 : nsHtml5TreeBuilder::generateImpliedEndTagsExceptFor(nsIAtom* name)
    2887                 : {
    2888               0 :   for (; ; ) {
    2889              22 :     nsHtml5StackNode* node = stack[currentPtr];
    2890              22 :     switch(node->getGroup()) {
    2891                 :       case NS_HTML5TREE_BUILDER_P:
    2892                 :       case NS_HTML5TREE_BUILDER_LI:
    2893                 :       case NS_HTML5TREE_BUILDER_DD_OR_DT:
    2894                 :       case NS_HTML5TREE_BUILDER_OPTION:
    2895                 :       case NS_HTML5TREE_BUILDER_OPTGROUP:
    2896                 :       case NS_HTML5TREE_BUILDER_RT_OR_RP: {
    2897              22 :         if (node->name == name) {
    2898              22 :           return;
    2899                 :         }
    2900               0 :         pop();
    2901               0 :         continue;
    2902                 :       }
    2903                 :       default: {
    2904               0 :         return;
    2905                 :       }
    2906                 :     }
    2907                 :   }
    2908                 : }
    2909                 : 
    2910                 : void 
    2911              12 : nsHtml5TreeBuilder::generateImpliedEndTags()
    2912                 : {
    2913               4 :   for (; ; ) {
    2914              12 :     switch(stack[currentPtr]->getGroup()) {
    2915                 :       case NS_HTML5TREE_BUILDER_P:
    2916                 :       case NS_HTML5TREE_BUILDER_LI:
    2917                 :       case NS_HTML5TREE_BUILDER_DD_OR_DT:
    2918                 :       case NS_HTML5TREE_BUILDER_OPTION:
    2919                 :       case NS_HTML5TREE_BUILDER_OPTGROUP:
    2920                 :       case NS_HTML5TREE_BUILDER_RT_OR_RP: {
    2921               4 :         pop();
    2922               4 :         continue;
    2923                 :       }
    2924                 :       default: {
    2925                 :         return;
    2926                 :       }
    2927                 :     }
    2928                 :   }
    2929                 : }
    2930                 : 
    2931                 : bool 
    2932               4 : nsHtml5TreeBuilder::isSecondOnStackBody()
    2933                 : {
    2934               4 :   return currentPtr >= 1 && stack[1]->getGroup() == NS_HTML5TREE_BUILDER_BODY;
    2935                 : }
    2936                 : 
    2937                 : void 
    2938             234 : nsHtml5TreeBuilder::documentModeInternal(nsHtml5DocumentMode m, nsString* publicIdentifier, nsString* systemIdentifier, bool html4SpecificAdditionalErrorChecks)
    2939                 : {
    2940             234 :   quirks = (m == QUIRKS_MODE);
    2941             234 :   if (this) {
    2942             234 :     this->documentMode(m);
    2943                 :   }
    2944             234 : }
    2945                 : 
    2946                 : bool 
    2947               0 : nsHtml5TreeBuilder::isAlmostStandards(nsString* publicIdentifier, nsString* systemIdentifier)
    2948                 : {
    2949               0 :   if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3c//dtd xhtml 1.0 transitional//en", publicIdentifier)) {
    2950               0 :     return true;
    2951                 :   }
    2952               0 :   if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3c//dtd xhtml 1.0 frameset//en", publicIdentifier)) {
    2953               0 :     return true;
    2954                 :   }
    2955               0 :   if (systemIdentifier) {
    2956               0 :     if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3c//dtd html 4.01 transitional//en", publicIdentifier)) {
    2957               0 :       return true;
    2958                 :     }
    2959               0 :     if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3c//dtd html 4.01 frameset//en", publicIdentifier)) {
    2960               0 :       return true;
    2961                 :     }
    2962                 :   }
    2963               0 :   return false;
    2964                 : }
    2965                 : 
    2966                 : bool 
    2967               0 : nsHtml5TreeBuilder::isQuirky(nsIAtom* name, nsString* publicIdentifier, nsString* systemIdentifier, bool forceQuirks)
    2968                 : {
    2969               0 :   if (forceQuirks) {
    2970               0 :     return true;
    2971                 :   }
    2972               0 :   if (name != nsHtml5Atoms::html) {
    2973               0 :     return true;
    2974                 :   }
    2975               0 :   if (publicIdentifier) {
    2976               0 :     for (PRInt32 i = 0; i < nsHtml5TreeBuilder::QUIRKY_PUBLIC_IDS.length; i++) {
    2977               0 :       if (nsHtml5Portability::lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString(nsHtml5TreeBuilder::QUIRKY_PUBLIC_IDS[i], publicIdentifier)) {
    2978               0 :         return true;
    2979                 :       }
    2980                 :     }
    2981               0 :     if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3o//dtd w3 html strict 3.0//en//", publicIdentifier) || nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-/w3c/dtd html 4.0 transitional/en", publicIdentifier) || nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("html", publicIdentifier)) {
    2982               0 :       return true;
    2983                 :     }
    2984                 :   }
    2985               0 :   if (!systemIdentifier) {
    2986               0 :     if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3c//dtd html 4.01 transitional//en", publicIdentifier)) {
    2987               0 :       return true;
    2988               0 :     } else if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("-//w3c//dtd html 4.01 frameset//en", publicIdentifier)) {
    2989               0 :       return true;
    2990                 :     }
    2991               0 :   } else if (nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd", systemIdentifier)) {
    2992               0 :     return true;
    2993                 :   }
    2994               0 :   return false;
    2995                 : }
    2996                 : 
    2997                 : void 
    2998               0 : nsHtml5TreeBuilder::closeTheCell(PRInt32 eltPos)
    2999                 : {
    3000               0 :   generateImpliedEndTags();
    3001               0 :   if (!!NS_UNLIKELY(mViewSource) && eltPos != currentPtr) {
    3002               0 :     errUnclosedElementsCell(eltPos);
    3003                 :   }
    3004               0 :   while (currentPtr >= eltPos) {
    3005               0 :     pop();
    3006                 :   }
    3007               0 :   clearTheListOfActiveFormattingElementsUpToTheLastMarker();
    3008               0 :   mode = NS_HTML5TREE_BUILDER_IN_ROW;
    3009                 :   return;
    3010                 : }
    3011                 : 
    3012                 : PRInt32 
    3013               0 : nsHtml5TreeBuilder::findLastInTableScopeTdTh()
    3014                 : {
    3015               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    3016               0 :     nsIAtom* name = stack[i]->name;
    3017               0 :     if (nsHtml5Atoms::td == name || nsHtml5Atoms::th == name) {
    3018               0 :       return i;
    3019               0 :     } else if (name == nsHtml5Atoms::table) {
    3020               0 :       return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    3021                 :     }
    3022                 :   }
    3023               0 :   return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK;
    3024                 : }
    3025                 : 
    3026                 : void 
    3027               0 : nsHtml5TreeBuilder::clearStackBackTo(PRInt32 eltPos)
    3028                 : {
    3029               0 :   while (currentPtr > eltPos) {
    3030               0 :     pop();
    3031                 :   }
    3032               0 : }
    3033                 : 
    3034                 : void 
    3035               0 : nsHtml5TreeBuilder::resetTheInsertionMode()
    3036                 : {
    3037                 :   nsHtml5StackNode* node;
    3038                 :   nsIAtom* name;
    3039                 :   PRInt32 ns;
    3040               0 :   for (PRInt32 i = currentPtr; i >= 0; i--) {
    3041               0 :     node = stack[i];
    3042               0 :     name = node->name;
    3043               0 :     ns = node->ns;
    3044               0 :     if (!i) {
    3045               0 :       if (!(contextNamespace == kNameSpaceID_XHTML && (contextName == nsHtml5Atoms::td || contextName == nsHtml5Atoms::th))) {
    3046               0 :         name = contextName;
    3047               0 :         ns = contextNamespace;
    3048                 :       } else {
    3049               0 :         mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    3050               0 :         return;
    3051                 :       }
    3052                 :     }
    3053               0 :     if (nsHtml5Atoms::select == name) {
    3054               0 :       mode = NS_HTML5TREE_BUILDER_IN_SELECT;
    3055               0 :       return;
    3056               0 :     } else if (nsHtml5Atoms::td == name || nsHtml5Atoms::th == name) {
    3057               0 :       mode = NS_HTML5TREE_BUILDER_IN_CELL;
    3058               0 :       return;
    3059               0 :     } else if (nsHtml5Atoms::tr == name) {
    3060               0 :       mode = NS_HTML5TREE_BUILDER_IN_ROW;
    3061               0 :       return;
    3062               0 :     } else if (nsHtml5Atoms::tbody == name || nsHtml5Atoms::thead == name || nsHtml5Atoms::tfoot == name) {
    3063               0 :       mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY;
    3064               0 :       return;
    3065               0 :     } else if (nsHtml5Atoms::caption == name) {
    3066               0 :       mode = NS_HTML5TREE_BUILDER_IN_CAPTION;
    3067               0 :       return;
    3068               0 :     } else if (nsHtml5Atoms::colgroup == name) {
    3069               0 :       mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP;
    3070               0 :       return;
    3071               0 :     } else if (nsHtml5Atoms::table == name) {
    3072               0 :       mode = NS_HTML5TREE_BUILDER_IN_TABLE;
    3073               0 :       return;
    3074               0 :     } else if (kNameSpaceID_XHTML != ns) {
    3075               0 :       mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    3076               0 :       return;
    3077               0 :     } else if (nsHtml5Atoms::head == name) {
    3078               0 :       mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    3079               0 :       return;
    3080               0 :     } else if (nsHtml5Atoms::body == name) {
    3081               0 :       mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    3082               0 :       return;
    3083               0 :     } else if (nsHtml5Atoms::frameset == name) {
    3084               0 :       mode = NS_HTML5TREE_BUILDER_IN_FRAMESET;
    3085               0 :       return;
    3086               0 :     } else if (nsHtml5Atoms::html == name) {
    3087               0 :       if (!headPointer) {
    3088               0 :         mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD;
    3089                 :       } else {
    3090               0 :         mode = NS_HTML5TREE_BUILDER_AFTER_HEAD;
    3091                 :       }
    3092               0 :       return;
    3093               0 :     } else if (!i) {
    3094               0 :       mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY;
    3095               0 :       return;
    3096                 :     }
    3097                 :   }
    3098                 : }
    3099                 : 
    3100                 : void 
    3101              34 : nsHtml5TreeBuilder::implicitlyCloseP()
    3102                 : {
    3103              34 :   PRInt32 eltPos = findLastInButtonScope(nsHtml5Atoms::p);
    3104              34 :   if (eltPos == NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK) {
    3105              34 :     return;
    3106                 :   }
    3107               0 :   generateImpliedEndTagsExceptFor(nsHtml5Atoms::p);
    3108               0 :   if (!!NS_UNLIKELY(mViewSource) && eltPos != currentPtr) {
    3109               0 :     errUnclosedElementsImplied(eltPos, nsHtml5Atoms::p);
    3110                 :   }
    3111               0 :   while (currentPtr >= eltPos) {
    3112               0 :     pop();
    3113                 :   }
    3114                 : }
    3115                 : 
    3116                 : bool 
    3117               0 : nsHtml5TreeBuilder::clearLastStackSlot()
    3118                 : {
    3119               0 :   stack[currentPtr] = nsnull;
    3120               0 :   return true;
    3121                 : }
    3122                 : 
    3123                 : bool 
    3124               0 : nsHtml5TreeBuilder::clearLastListSlot()
    3125                 : {
    3126               0 :   listOfActiveFormattingElements[listPtr] = nsnull;
    3127               0 :   return true;
    3128                 : }
    3129                 : 
    3130                 : void 
    3131             737 : nsHtml5TreeBuilder::push(nsHtml5StackNode* node)
    3132                 : {
    3133             737 :   currentPtr++;
    3134             737 :   if (currentPtr == stack.length) {
    3135               0 :     jArray<nsHtml5StackNode*,PRInt32> newStack = jArray<nsHtml5StackNode*,PRInt32>::newJArray(stack.length + 64);
    3136               0 :     nsHtml5ArrayCopy::arraycopy(stack, newStack, stack.length);
    3137               0 :     stack = newStack;
    3138                 :   }
    3139             737 :   stack[currentPtr] = node;
    3140             737 :   elementPushed(node->ns, node->popName, node->node);
    3141             737 : }
    3142                 : 
    3143                 : void 
    3144               0 : nsHtml5TreeBuilder::silentPush(nsHtml5StackNode* node)
    3145                 : {
    3146               0 :   currentPtr++;
    3147               0 :   if (currentPtr == stack.length) {
    3148               0 :     jArray<nsHtml5StackNode*,PRInt32> newStack = jArray<nsHtml5StackNode*,PRInt32>::newJArray(stack.length + 64);
    3149               0 :     nsHtml5ArrayCopy::arraycopy(stack, newStack, stack.length);
    3150               0 :     stack = newStack;
    3151                 :   }
    3152               0 :   stack[currentPtr] = node;
    3153               0 : }
    3154                 : 
    3155                 : void 
    3156               0 : nsHtml5TreeBuilder::append(nsHtml5StackNode* node)
    3157                 : {
    3158               0 :   listPtr++;
    3159               0 :   if (listPtr == listOfActiveFormattingElements.length) {
    3160               0 :     jArray<nsHtml5StackNode*,PRInt32> newList = jArray<nsHtml5StackNode*,PRInt32>::newJArray(listOfActiveFormattingElements.length + 64);
    3161               0 :     nsHtml5ArrayCopy::arraycopy(listOfActiveFormattingElements, newList, listOfActiveFormattingElements.length);
    3162               0 :     listOfActiveFormattingElements = newList;
    3163                 :   }
    3164               0 :   listOfActiveFormattingElements[listPtr] = node;
    3165               0 : }
    3166                 : 
    3167                 : void 
    3168               0 : nsHtml5TreeBuilder::clearTheListOfActiveFormattingElementsUpToTheLastMarker()
    3169                 : {
    3170               0 :   while (listPtr > -1) {
    3171               0 :     if (!listOfActiveFormattingElements[listPtr]) {
    3172               0 :       --listPtr;
    3173               0 :       return;
    3174                 :     }
    3175               0 :     listOfActiveFormattingElements[listPtr]->release();
    3176               0 :     --listPtr;
    3177                 :   }
    3178                 : }
    3179                 : 
    3180                 : void 
    3181               0 : nsHtml5TreeBuilder::removeFromStack(PRInt32 pos)
    3182                 : {
    3183               0 :   if (currentPtr == pos) {
    3184               0 :     pop();
    3185                 :   } else {
    3186                 : 
    3187               0 :     stack[pos]->release();
    3188               0 :     nsHtml5ArrayCopy::arraycopy(stack, pos + 1, pos, currentPtr - pos);
    3189                 : 
    3190               0 :     currentPtr--;
    3191                 :   }
    3192               0 : }
    3193                 : 
    3194                 : void 
    3195               0 : nsHtml5TreeBuilder::removeFromStack(nsHtml5StackNode* node)
    3196                 : {
    3197               0 :   if (stack[currentPtr] == node) {
    3198               0 :     pop();
    3199                 :   } else {
    3200               0 :     PRInt32 pos = currentPtr - 1;
    3201               0 :     while (pos >= 0 && stack[pos] != node) {
    3202               0 :       pos--;
    3203                 :     }
    3204               0 :     if (pos == -1) {
    3205               0 :       return;
    3206                 :     }
    3207                 : 
    3208               0 :     node->release();
    3209               0 :     nsHtml5ArrayCopy::arraycopy(stack, pos + 1, pos, currentPtr - pos);
    3210               0 :     currentPtr--;
    3211                 :   }
    3212                 : }
    3213                 : 
    3214                 : void 
    3215               0 : nsHtml5TreeBuilder::removeFromListOfActiveFormattingElements(PRInt32 pos)
    3216                 : {
    3217                 : 
    3218               0 :   listOfActiveFormattingElements[pos]->release();
    3219               0 :   if (pos == listPtr) {
    3220                 : 
    3221               0 :     listPtr--;
    3222               0 :     return;
    3223                 :   }
    3224                 : 
    3225               0 :   nsHtml5ArrayCopy::arraycopy(listOfActiveFormattingElements, pos + 1, pos, listPtr - pos);
    3226                 : 
    3227               0 :   listPtr--;
    3228                 : }
    3229                 : 
    3230                 : bool 
    3231               0 : nsHtml5TreeBuilder::adoptionAgencyEndTag(nsIAtom* name)
    3232                 : {
    3233               0 :   for (PRInt32 i = 0; i < 8; ++i) {
    3234               0 :     PRInt32 formattingEltListPos = listPtr;
    3235               0 :     while (formattingEltListPos > -1) {
    3236               0 :       nsHtml5StackNode* listNode = listOfActiveFormattingElements[formattingEltListPos];
    3237               0 :       if (!listNode) {
    3238               0 :         formattingEltListPos = -1;
    3239               0 :         break;
    3240               0 :       } else if (listNode->name == name) {
    3241               0 :         break;
    3242                 :       }
    3243               0 :       formattingEltListPos--;
    3244                 :     }
    3245               0 :     if (formattingEltListPos == -1) {
    3246               0 :       return false;
    3247                 :     }
    3248               0 :     nsHtml5StackNode* formattingElt = listOfActiveFormattingElements[formattingEltListPos];
    3249               0 :     PRInt32 formattingEltStackPos = currentPtr;
    3250               0 :     bool inScope = true;
    3251               0 :     while (formattingEltStackPos > -1) {
    3252               0 :       nsHtml5StackNode* node = stack[formattingEltStackPos];
    3253               0 :       if (node == formattingElt) {
    3254               0 :         break;
    3255               0 :       } else if (node->isScoping()) {
    3256               0 :         inScope = false;
    3257                 :       }
    3258               0 :       formattingEltStackPos--;
    3259                 :     }
    3260               0 :     if (formattingEltStackPos == -1) {
    3261               0 :       errNoElementToCloseButEndTagSeen(name);
    3262               0 :       removeFromListOfActiveFormattingElements(formattingEltListPos);
    3263               0 :       return true;
    3264                 :     }
    3265               0 :     if (!inScope) {
    3266               0 :       errNoElementToCloseButEndTagSeen(name);
    3267               0 :       return true;
    3268                 :     }
    3269               0 :     if (formattingEltStackPos != currentPtr) {
    3270               0 :       errEndTagViolatesNestingRules(name);
    3271                 :     }
    3272               0 :     PRInt32 furthestBlockPos = formattingEltStackPos + 1;
    3273               0 :     while (furthestBlockPos <= currentPtr) {
    3274               0 :       nsHtml5StackNode* node = stack[furthestBlockPos];
    3275               0 :       if (node->isSpecial()) {
    3276               0 :         break;
    3277                 :       }
    3278               0 :       furthestBlockPos++;
    3279                 :     }
    3280               0 :     if (furthestBlockPos > currentPtr) {
    3281               0 :       while (currentPtr >= formattingEltStackPos) {
    3282               0 :         pop();
    3283                 :       }
    3284               0 :       removeFromListOfActiveFormattingElements(formattingEltListPos);
    3285               0 :       return true;
    3286                 :     }
    3287               0 :     nsHtml5StackNode* commonAncestor = stack[formattingEltStackPos - 1];
    3288               0 :     nsHtml5StackNode* furthestBlock = stack[furthestBlockPos];
    3289               0 :     PRInt32 bookmark = formattingEltListPos;
    3290               0 :     PRInt32 nodePos = furthestBlockPos;
    3291               0 :     nsHtml5StackNode* lastNode = furthestBlock;
    3292               0 :     for (PRInt32 j = 0; j < 3; ++j) {
    3293               0 :       nodePos--;
    3294               0 :       nsHtml5StackNode* node = stack[nodePos];
    3295               0 :       PRInt32 nodeListPos = findInListOfActiveFormattingElements(node);
    3296               0 :       if (nodeListPos == -1) {
    3297                 : 
    3298                 : 
    3299                 : 
    3300               0 :         removeFromStack(nodePos);
    3301               0 :         furthestBlockPos--;
    3302               0 :         continue;
    3303                 :       }
    3304               0 :       if (nodePos == formattingEltStackPos) {
    3305               0 :         break;
    3306                 :       }
    3307               0 :       if (nodePos == furthestBlockPos) {
    3308               0 :         bookmark = nodeListPos + 1;
    3309                 :       }
    3310                 : 
    3311                 : 
    3312               0 :       nsIContent** clone = createElement(kNameSpaceID_XHTML, node->name, node->attributes->cloneAttributes(nsnull));
    3313               0 :       nsHtml5StackNode* newNode = new nsHtml5StackNode(node->getFlags(), node->ns, node->name, clone, node->popName, node->attributes);
    3314               0 :       node->dropAttributes();
    3315               0 :       stack[nodePos] = newNode;
    3316               0 :       newNode->retain();
    3317               0 :       listOfActiveFormattingElements[nodeListPos] = newNode;
    3318               0 :       node->release();
    3319               0 :       node->release();
    3320               0 :       node = newNode;
    3321               0 :       detachFromParent(lastNode->node);
    3322               0 :       appendElement(lastNode->node, node->node);
    3323               0 :       lastNode = node;
    3324                 :     }
    3325               0 :     if (commonAncestor->isFosterParenting()) {
    3326                 : 
    3327               0 :       detachFromParent(lastNode->node);
    3328               0 :       insertIntoFosterParent(lastNode->node);
    3329                 :     } else {
    3330               0 :       detachFromParent(lastNode->node);
    3331               0 :       appendElement(lastNode->node, commonAncestor->node);
    3332                 :     }
    3333               0 :     nsIContent** clone = createElement(kNameSpaceID_XHTML, formattingElt->name, formattingElt->attributes->cloneAttributes(nsnull));
    3334               0 :     nsHtml5StackNode* formattingClone = new nsHtml5StackNode(formattingElt->getFlags(), formattingElt->ns, formattingElt->name, clone, formattingElt->popName, formattingElt->attributes);
    3335               0 :     formattingElt->dropAttributes();
    3336               0 :     appendChildrenToNewParent(furthestBlock->node, clone);
    3337               0 :     appendElement(clone, furthestBlock->node);
    3338               0 :     removeFromListOfActiveFormattingElements(formattingEltListPos);
    3339               0 :     insertIntoListOfActiveFormattingElements(formattingClone, bookmark);
    3340                 : 
    3341               0 :     removeFromStack(formattingEltStackPos);
    3342               0 :     insertIntoStack(formattingClone, furthestBlockPos);
    3343                 :   }
    3344               0 :   return true;
    3345                 : }
    3346                 : 
    3347                 : void 
    3348               0 : nsHtml5TreeBuilder::insertIntoStack(nsHtml5StackNode* node, PRInt32 position)
    3349                 : {
    3350                 : 
    3351                 : 
    3352               0 :   if (position == currentPtr + 1) {
    3353               0 :     push(node);
    3354                 :   } else {
    3355               0 :     nsHtml5ArrayCopy::arraycopy(stack, position, position + 1, (currentPtr - position) + 1);
    3356               0 :     currentPtr++;
    3357               0 :     stack[position] = node;
    3358                 :   }
    3359               0 : }
    3360                 : 
    3361                 : void 
    3362               0 : nsHtml5TreeBuilder::insertIntoListOfActiveFormattingElements(nsHtml5StackNode* formattingClone, PRInt32 bookmark)
    3363                 : {
    3364               0 :   formattingClone->retain();
    3365                 : 
    3366               0 :   if (bookmark <= listPtr) {
    3367               0 :     nsHtml5ArrayCopy::arraycopy(listOfActiveFormattingElements, bookmark, bookmark + 1, (listPtr - bookmark) + 1);
    3368                 :   }
    3369               0 :   listPtr++;
    3370               0 :   listOfActiveFormattingElements[bookmark] = formattingClone;
    3371               0 : }
    3372                 : 
    3373                 : PRInt32 
    3374               0 : nsHtml5TreeBuilder::findInListOfActiveFormattingElements(nsHtml5StackNode* node)
    3375                 : {
    3376               0 :   for (PRInt32 i = listPtr; i >= 0; i--) {
    3377               0 :     if (node == listOfActiveFormattingElements[i]) {
    3378               0 :       return i;
    3379                 :     }
    3380                 :   }
    3381               0 :   return -1;
    3382                 : }
    3383                 : 
    3384                 : PRInt32 
    3385               0 : nsHtml5TreeBuilder::findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker(nsIAtom* name)
    3386                 : {
    3387               0 :   for (PRInt32 i = listPtr; i >= 0; i--) {
    3388               0 :     nsHtml5StackNode* node = listOfActiveFormattingElements[i];
    3389               0 :     if (!node) {
    3390               0 :       return -1;
    3391               0 :     } else if (node->name == name) {
    3392               0 :       return i;
    3393                 :     }
    3394                 :   }
    3395               0 :   return -1;
    3396                 : }
    3397                 : 
    3398                 : void 
    3399               0 : nsHtml5TreeBuilder::maybeForgetEarlierDuplicateFormattingElement(nsIAtom* name, nsHtml5HtmlAttributes* attributes)
    3400                 : {
    3401               0 :   PRInt32 candidate = -1;
    3402               0 :   PRInt32 count = 0;
    3403               0 :   for (PRInt32 i = listPtr; i >= 0; i--) {
    3404               0 :     nsHtml5StackNode* node = listOfActiveFormattingElements[i];
    3405               0 :     if (!node) {
    3406               0 :       break;
    3407                 :     }
    3408               0 :     if (node->name == name && node->attributes->equalsAnother(attributes)) {
    3409               0 :       candidate = i;
    3410               0 :       ++count;
    3411                 :     }
    3412                 :   }
    3413               0 :   if (count >= 3) {
    3414               0 :     removeFromListOfActiveFormattingElements(candidate);
    3415                 :   }
    3416               0 : }
    3417                 : 
    3418                 : PRInt32 
    3419               0 : nsHtml5TreeBuilder::findLastOrRoot(nsIAtom* name)
    3420                 : {
    3421               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    3422               0 :     if (stack[i]->name == name) {
    3423               0 :       return i;
    3424                 :     }
    3425                 :   }
    3426               0 :   return 0;
    3427                 : }
    3428                 : 
    3429                 : PRInt32 
    3430               0 : nsHtml5TreeBuilder::findLastOrRoot(PRInt32 group)
    3431                 : {
    3432               0 :   for (PRInt32 i = currentPtr; i > 0; i--) {
    3433               0 :     if (stack[i]->getGroup() == group) {
    3434               0 :       return i;
    3435                 :     }
    3436                 :   }
    3437               0 :   return 0;
    3438                 : }
    3439                 : 
    3440                 : bool 
    3441               1 : nsHtml5TreeBuilder::addAttributesToBody(nsHtml5HtmlAttributes* attributes)
    3442                 : {
    3443               1 :   if (currentPtr >= 1) {
    3444               1 :     nsHtml5StackNode* body = stack[1];
    3445               1 :     if (body->getGroup() == NS_HTML5TREE_BUILDER_BODY) {
    3446               1 :       addAttributesToElement(body->node, attributes);
    3447               1 :       return true;
    3448                 :     }
    3449                 :   }
    3450               0 :   return false;
    3451                 : }
    3452                 : 
    3453                 : void 
    3454               0 : nsHtml5TreeBuilder::addAttributesToHtml(nsHtml5HtmlAttributes* attributes)
    3455                 : {
    3456               0 :   addAttributesToElement(stack[0]->node, attributes);
    3457               0 : }
    3458                 : 
    3459                 : void 
    3460               0 : nsHtml5TreeBuilder::pushHeadPointerOntoStack()
    3461                 : {
    3462                 : 
    3463                 : 
    3464                 : 
    3465                 : 
    3466               0 :   silentPush(new nsHtml5StackNode(nsHtml5ElementName::ELT_HEAD, headPointer));
    3467               0 : }
    3468                 : 
    3469                 : void 
    3470             365 : nsHtml5TreeBuilder::reconstructTheActiveFormattingElements()
    3471                 : {
    3472             365 :   if (listPtr == -1) {
    3473             365 :     return;
    3474                 :   }
    3475               0 :   nsHtml5StackNode* mostRecent = listOfActiveFormattingElements[listPtr];
    3476               0 :   if (!mostRecent || isInStack(mostRecent)) {
    3477               0 :     return;
    3478                 :   }
    3479               0 :   PRInt32 entryPos = listPtr;
    3480               0 :   for (; ; ) {
    3481               0 :     entryPos--;
    3482               0 :     if (entryPos == -1) {
    3483               0 :       break;
    3484                 :     }
    3485               0 :     if (!listOfActiveFormattingElements[entryPos]) {
    3486               0 :       break;
    3487                 :     }
    3488               0 :     if (isInStack(listOfActiveFormattingElements[entryPos])) {
    3489               0 :       break;
    3490                 :     }
    3491                 :   }
    3492               0 :   while (entryPos < listPtr) {
    3493               0 :     entryPos++;
    3494               0 :     nsHtml5StackNode* entry = listOfActiveFormattingElements[entryPos];
    3495               0 :     nsIContent** clone = createElement(kNameSpaceID_XHTML, entry->name, entry->attributes->cloneAttributes(nsnull));
    3496               0 :     nsHtml5StackNode* entryClone = new nsHtml5StackNode(entry->getFlags(), entry->ns, entry->name, clone, entry->popName, entry->attributes);
    3497               0 :     entry->dropAttributes();
    3498               0 :     nsHtml5StackNode* currentNode = stack[currentPtr];
    3499               0 :     if (currentNode->isFosterParenting()) {
    3500               0 :       insertIntoFosterParent(clone);
    3501                 :     } else {
    3502               0 :       appendElement(clone, currentNode->node);
    3503                 :     }
    3504               0 :     push(entryClone);
    3505               0 :     listOfActiveFormattingElements[entryPos] = entryClone;
    3506               0 :     entry->release();
    3507               0 :     entryClone->retain();
    3508                 :   }
    3509                 : }
    3510                 : 
    3511                 : void 
    3512               0 : nsHtml5TreeBuilder::insertIntoFosterParent(nsIContent** child)
    3513                 : {
    3514               0 :   PRInt32 eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE);
    3515               0 :   nsHtml5StackNode* node = stack[eltPos];
    3516               0 :   nsIContent** elt = node->node;
    3517               0 :   if (!eltPos) {
    3518               0 :     appendElement(child, elt);
    3519               0 :     return;
    3520                 :   }
    3521               0 :   insertFosterParentedChild(child, elt, stack[eltPos - 1]->node);
    3522                 : }
    3523                 : 
    3524                 : bool 
    3525               0 : nsHtml5TreeBuilder::isInStack(nsHtml5StackNode* node)
    3526                 : {
    3527               0 :   for (PRInt32 i = currentPtr; i >= 0; i--) {
    3528               0 :     if (stack[i] == node) {
    3529               0 :       return true;
    3530                 :     }
    3531                 :   }
    3532               0 :   return false;
    3533                 : }
    3534                 : 
    3535                 : void 
    3536             269 : nsHtml5TreeBuilder::pop()
    3537                 : {
    3538             269 :   nsHtml5StackNode* node = stack[currentPtr];
    3539                 : 
    3540             269 :   currentPtr--;
    3541             269 :   elementPopped(node->ns, node->popName, node->node);
    3542             269 :   node->release();
    3543             269 : }
    3544                 : 
    3545                 : void 
    3546               0 : nsHtml5TreeBuilder::silentPop()
    3547                 : {
    3548               0 :   nsHtml5StackNode* node = stack[currentPtr];
    3549                 : 
    3550               0 :   currentPtr--;
    3551               0 :   node->release();
    3552               0 : }
    3553                 : 
    3554                 : void 
    3555             468 : nsHtml5TreeBuilder::popOnEof()
    3556                 : {
    3557             468 :   nsHtml5StackNode* node = stack[currentPtr];
    3558                 : 
    3559             468 :   currentPtr--;
    3560             468 :   markMalformedIfScript(node->node);
    3561             468 :   elementPopped(node->ns, node->popName, node->node);
    3562             468 :   node->release();
    3563             468 : }
    3564                 : 
    3565                 : void 
    3566             234 : nsHtml5TreeBuilder::appendHtmlElementToDocumentAndPush(nsHtml5HtmlAttributes* attributes)
    3567                 : {
    3568             234 :   nsIContent** elt = createHtmlElementSetAsRoot(attributes);
    3569             234 :   nsHtml5StackNode* node = new nsHtml5StackNode(nsHtml5ElementName::ELT_HTML, elt);
    3570             234 :   push(node);
    3571             234 : }
    3572                 : 
    3573                 : void 
    3574             234 : nsHtml5TreeBuilder::appendHtmlElementToDocumentAndPush()
    3575                 : {
    3576             234 :   appendHtmlElementToDocumentAndPush(tokenizer->emptyAttributes());
    3577             234 : }
    3578                 : 
    3579                 : void 
    3580             234 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushHeadElement(nsHtml5HtmlAttributes* attributes)
    3581                 : {
    3582             234 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::head, attributes);
    3583             234 :   appendElement(elt, stack[currentPtr]->node);
    3584             234 :   headPointer = elt;
    3585             234 :   nsHtml5StackNode* node = new nsHtml5StackNode(nsHtml5ElementName::ELT_HEAD, elt);
    3586             234 :   push(node);
    3587             234 : }
    3588                 : 
    3589                 : void 
    3590             234 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushBodyElement(nsHtml5HtmlAttributes* attributes)
    3591                 : {
    3592             234 :   appendToCurrentNodeAndPushElement(nsHtml5ElementName::ELT_BODY, attributes);
    3593             234 : }
    3594                 : 
    3595                 : void 
    3596             234 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushBodyElement()
    3597                 : {
    3598             234 :   appendToCurrentNodeAndPushBodyElement(tokenizer->emptyAttributes());
    3599             234 : }
    3600                 : 
    3601                 : void 
    3602               0 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormElementMayFoster(nsHtml5HtmlAttributes* attributes)
    3603                 : {
    3604               0 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::form, attributes);
    3605               0 :   formPointer = elt;
    3606               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3607               0 :   if (current->isFosterParenting()) {
    3608                 : 
    3609               0 :     insertIntoFosterParent(elt);
    3610                 :   } else {
    3611               0 :     appendElement(elt, current->node);
    3612                 :   }
    3613               0 :   nsHtml5StackNode* node = new nsHtml5StackNode(nsHtml5ElementName::ELT_FORM, elt);
    3614               0 :   push(node);
    3615               0 : }
    3616                 : 
    3617                 : void 
    3618               0 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushFormattingElementMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3619                 : {
    3620               0 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, elementName->name, attributes);
    3621               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3622               0 :   if (current->isFosterParenting()) {
    3623                 : 
    3624               0 :     insertIntoFosterParent(elt);
    3625                 :   } else {
    3626               0 :     appendElement(elt, current->node);
    3627                 :   }
    3628               0 :   nsHtml5StackNode* node = new nsHtml5StackNode(elementName, elt, attributes->cloneAttributes(nsnull));
    3629               0 :   push(node);
    3630               0 :   append(node);
    3631               0 :   node->retain();
    3632               0 : }
    3633                 : 
    3634                 : void 
    3635             234 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushElement(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3636                 : {
    3637             234 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, elementName->name, attributes);
    3638             234 :   appendElement(elt, stack[currentPtr]->node);
    3639             234 :   nsHtml5StackNode* node = new nsHtml5StackNode(elementName, elt);
    3640             234 :   push(node);
    3641             234 : }
    3642                 : 
    3643                 : void 
    3644              35 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3645                 : {
    3646              35 :   nsIAtom* popName = elementName->name;
    3647              35 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, popName, attributes);
    3648              35 :   nsHtml5StackNode* current = stack[currentPtr];
    3649              35 :   if (current->isFosterParenting()) {
    3650                 : 
    3651               0 :     insertIntoFosterParent(elt);
    3652                 :   } else {
    3653              35 :     appendElement(elt, current->node);
    3654                 :   }
    3655              35 :   nsHtml5StackNode* node = new nsHtml5StackNode(elementName, elt, popName);
    3656              35 :   push(node);
    3657              35 : }
    3658                 : 
    3659                 : void 
    3660               0 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterMathML(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3661                 : {
    3662               0 :   nsIAtom* popName = elementName->name;
    3663               0 :   nsIContent** elt = createElement(kNameSpaceID_MathML, popName, attributes);
    3664               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3665               0 :   if (current->isFosterParenting()) {
    3666                 : 
    3667               0 :     insertIntoFosterParent(elt);
    3668                 :   } else {
    3669               0 :     appendElement(elt, current->node);
    3670                 :   }
    3671               0 :   bool markAsHtmlIntegrationPoint = false;
    3672               0 :   if (nsHtml5ElementName::ELT_ANNOTATION_XML == elementName && annotationXmlEncodingPermitsHtml(attributes)) {
    3673               0 :     markAsHtmlIntegrationPoint = true;
    3674                 :   }
    3675               0 :   nsHtml5StackNode* node = new nsHtml5StackNode(elementName, elt, popName, markAsHtmlIntegrationPoint);
    3676               0 :   push(node);
    3677               0 : }
    3678                 : 
    3679                 : bool 
    3680               0 : nsHtml5TreeBuilder::annotationXmlEncodingPermitsHtml(nsHtml5HtmlAttributes* attributes)
    3681                 : {
    3682               0 :   nsString* encoding = attributes->getValue(nsHtml5AttributeName::ATTR_ENCODING);
    3683               0 :   if (!encoding) {
    3684               0 :     return false;
    3685                 :   }
    3686               0 :   return nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("application/xhtml+xml", encoding) || nsHtml5Portability::lowerCaseLiteralEqualsIgnoreAsciiCaseString("text/html", encoding);
    3687                 : }
    3688                 : 
    3689                 : void 
    3690               0 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFosterSVG(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3691                 : {
    3692               0 :   nsIAtom* popName = elementName->camelCaseName;
    3693               0 :   nsIContent** elt = createElement(kNameSpaceID_SVG, popName, attributes);
    3694               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3695               0 :   if (current->isFosterParenting()) {
    3696                 : 
    3697               0 :     insertIntoFosterParent(elt);
    3698                 :   } else {
    3699               0 :     appendElement(elt, current->node);
    3700                 :   }
    3701               0 :   nsHtml5StackNode* node = new nsHtml5StackNode(elementName, popName, elt);
    3702               0 :   push(node);
    3703               0 : }
    3704                 : 
    3705                 : void 
    3706               0 : nsHtml5TreeBuilder::appendToCurrentNodeAndPushElementMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes, nsIContent** form)
    3707                 : {
    3708               0 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, elementName->name, attributes, fragment ? nsnull : form);
    3709               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3710               0 :   if (current->isFosterParenting()) {
    3711                 : 
    3712               0 :     insertIntoFosterParent(elt);
    3713                 :   } else {
    3714               0 :     appendElement(elt, current->node);
    3715                 :   }
    3716               0 :   nsHtml5StackNode* node = new nsHtml5StackNode(elementName, elt);
    3717               0 :   push(node);
    3718               0 : }
    3719                 : 
    3720                 : void 
    3721               0 : nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form)
    3722                 : {
    3723               0 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, name, attributes, fragment ? nsnull : form);
    3724               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3725               0 :   if (current->isFosterParenting()) {
    3726                 : 
    3727               0 :     insertIntoFosterParent(elt);
    3728                 :   } else {
    3729               0 :     appendElement(elt, current->node);
    3730                 :   }
    3731               0 :   elementPushed(kNameSpaceID_XHTML, name, elt);
    3732               0 :   elementPopped(kNameSpaceID_XHTML, name, elt);
    3733               0 : }
    3734                 : 
    3735                 : void 
    3736              43 : nsHtml5TreeBuilder::appendVoidElementToCurrentMayFoster(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3737                 : {
    3738              43 :   nsIAtom* popName = elementName->name;
    3739              43 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, popName, attributes);
    3740              43 :   nsHtml5StackNode* current = stack[currentPtr];
    3741              43 :   if (current->isFosterParenting()) {
    3742                 : 
    3743               0 :     insertIntoFosterParent(elt);
    3744                 :   } else {
    3745              43 :     appendElement(elt, current->node);
    3746                 :   }
    3747              43 :   elementPushed(kNameSpaceID_XHTML, popName, elt);
    3748              43 :   elementPopped(kNameSpaceID_XHTML, popName, elt);
    3749              43 : }
    3750                 : 
    3751                 : void 
    3752               0 : nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterSVG(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3753                 : {
    3754               0 :   nsIAtom* popName = elementName->camelCaseName;
    3755               0 :   nsIContent** elt = createElement(kNameSpaceID_SVG, popName, attributes);
    3756               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3757               0 :   if (current->isFosterParenting()) {
    3758                 : 
    3759               0 :     insertIntoFosterParent(elt);
    3760                 :   } else {
    3761               0 :     appendElement(elt, current->node);
    3762                 :   }
    3763               0 :   elementPushed(kNameSpaceID_SVG, popName, elt);
    3764               0 :   elementPopped(kNameSpaceID_SVG, popName, elt);
    3765               0 : }
    3766                 : 
    3767                 : void 
    3768               0 : nsHtml5TreeBuilder::appendVoidElementToCurrentMayFosterMathML(nsHtml5ElementName* elementName, nsHtml5HtmlAttributes* attributes)
    3769                 : {
    3770               0 :   nsIAtom* popName = elementName->name;
    3771               0 :   nsIContent** elt = createElement(kNameSpaceID_MathML, popName, attributes);
    3772               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3773               0 :   if (current->isFosterParenting()) {
    3774                 : 
    3775               0 :     insertIntoFosterParent(elt);
    3776                 :   } else {
    3777               0 :     appendElement(elt, current->node);
    3778                 :   }
    3779               0 :   elementPushed(kNameSpaceID_MathML, popName, elt);
    3780               0 :   elementPopped(kNameSpaceID_MathML, popName, elt);
    3781               0 : }
    3782                 : 
    3783                 : void 
    3784               0 : nsHtml5TreeBuilder::appendVoidElementToCurrent(nsIAtom* name, nsHtml5HtmlAttributes* attributes, nsIContent** form)
    3785                 : {
    3786               0 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, name, attributes, fragment ? nsnull : form);
    3787               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3788               0 :   appendElement(elt, current->node);
    3789               0 :   elementPushed(kNameSpaceID_XHTML, name, elt);
    3790               0 :   elementPopped(kNameSpaceID_XHTML, name, elt);
    3791               0 : }
    3792                 : 
    3793                 : void 
    3794               0 : nsHtml5TreeBuilder::appendVoidFormToCurrent(nsHtml5HtmlAttributes* attributes)
    3795                 : {
    3796               0 :   nsIContent** elt = createElement(kNameSpaceID_XHTML, nsHtml5Atoms::form, attributes);
    3797               0 :   formPointer = elt;
    3798               0 :   nsHtml5StackNode* current = stack[currentPtr];
    3799               0 :   appendElement(elt, current->node);
    3800               0 :   elementPushed(kNameSpaceID_XHTML, nsHtml5Atoms::form, elt);
    3801               0 :   elementPopped(kNameSpaceID_XHTML, nsHtml5Atoms::form, elt);
    3802               0 : }
    3803                 : 
    3804                 : void 
    3805               0 : nsHtml5TreeBuilder::requestSuspension()
    3806                 : {
    3807               0 :   tokenizer->requestSuspension();
    3808               0 : }
    3809                 : 
    3810                 : bool 
    3811             459 : nsHtml5TreeBuilder::isInForeign()
    3812                 : {
    3813             459 :   return currentPtr >= 0 && stack[currentPtr]->ns != kNameSpaceID_XHTML;
    3814                 : }
    3815                 : 
    3816                 : bool 
    3817             321 : nsHtml5TreeBuilder::isInForeignButNotHtmlOrMathTextIntegrationPoint()
    3818                 : {
    3819             321 :   if (currentPtr < 0) {
    3820               0 :     return false;
    3821                 :   }
    3822             321 :   return !isSpecialParentInForeign(stack[currentPtr]);
    3823                 : }
    3824                 : 
    3825                 : void 
    3826             234 : nsHtml5TreeBuilder::setFragmentContext(nsIAtom* context, PRInt32 ns, nsIContent** node, bool quirks)
    3827                 : {
    3828             234 :   this->contextName = context;
    3829             234 :   this->contextNamespace = ns;
    3830             234 :   this->contextNode = node;
    3831             234 :   this->fragment = (!!contextName);
    3832             234 :   this->quirks = quirks;
    3833             234 : }
    3834                 : 
    3835                 : nsIContent** 
    3836             287 : nsHtml5TreeBuilder::currentNode()
    3837                 : {
    3838             287 :   return stack[currentPtr]->node;
    3839                 : }
    3840                 : 
    3841                 : bool 
    3842               0 : nsHtml5TreeBuilder::isScriptingEnabled()
    3843                 : {
    3844               0 :   return scriptingEnabled;
    3845                 : }
    3846                 : 
    3847                 : void 
    3848             234 : nsHtml5TreeBuilder::setScriptingEnabled(bool scriptingEnabled)
    3849                 : {
    3850             234 :   this->scriptingEnabled = scriptingEnabled;
    3851             234 : }
    3852                 : 
    3853                 : void 
    3854            1462 : nsHtml5TreeBuilder::flushCharacters()
    3855                 : {
    3856            1462 :   if (charBufferLen > 0) {
    3857             287 :     if ((mode == NS_HTML5TREE_BUILDER_IN_TABLE || mode == NS_HTML5TREE_BUILDER_IN_TABLE_BODY || mode == NS_HTML5TREE_BUILDER_IN_ROW) && charBufferContainsNonWhitespace()) {
    3858               0 :       errNonSpaceInTable();
    3859               0 :       reconstructTheActiveFormattingElements();
    3860               0 :       if (!stack[currentPtr]->isFosterParenting()) {
    3861               0 :         appendCharacters(currentNode(), charBuffer, 0, charBufferLen);
    3862               0 :         charBufferLen = 0;
    3863               0 :         return;
    3864                 :       }
    3865               0 :       PRInt32 eltPos = findLastOrRoot(NS_HTML5TREE_BUILDER_TABLE);
    3866               0 :       nsHtml5StackNode* node = stack[eltPos];
    3867               0 :       nsIContent** elt = node->node;
    3868               0 :       if (!eltPos) {
    3869               0 :         appendCharacters(elt, charBuffer, 0, charBufferLen);
    3870               0 :         charBufferLen = 0;
    3871               0 :         return;
    3872                 :       }
    3873               0 :       insertFosterParentedCharacters(charBuffer, 0, charBufferLen, elt, stack[eltPos - 1]->node);
    3874               0 :       charBufferLen = 0;
    3875               0 :       return;
    3876                 :     }
    3877             287 :     appendCharacters(currentNode(), charBuffer, 0, charBufferLen);
    3878             287 :     charBufferLen = 0;
    3879                 :   }
    3880                 : }
    3881                 : 
    3882                 : bool 
    3883               0 : nsHtml5TreeBuilder::charBufferContainsNonWhitespace()
    3884                 : {
    3885               0 :   for (PRInt32 i = 0; i < charBufferLen; i++) {
    3886               0 :     switch(charBuffer[i]) {
    3887                 :       case ' ':
    3888                 :       case '\t':
    3889                 :       case '\n':
    3890                 :       case '\r':
    3891                 :       case '\f': {
    3892               0 :         continue;
    3893                 :       }
    3894                 :       default: {
    3895               0 :         return true;
    3896                 :       }
    3897                 :     }
    3898                 :   }
    3899               0 :   return false;
    3900                 : }
    3901                 : 
    3902                 : nsAHtml5TreeBuilderState* 
    3903               0 : nsHtml5TreeBuilder::newSnapshot()
    3904                 : {
    3905               0 :   jArray<nsHtml5StackNode*,PRInt32> listCopy = jArray<nsHtml5StackNode*,PRInt32>::newJArray(listPtr + 1);
    3906               0 :   for (PRInt32 i = 0; i < listCopy.length; i++) {
    3907               0 :     nsHtml5StackNode* node = listOfActiveFormattingElements[i];
    3908               0 :     if (node) {
    3909               0 :       nsHtml5StackNode* newNode = new nsHtml5StackNode(node->getFlags(), node->ns, node->name, node->node, node->popName, node->attributes->cloneAttributes(nsnull));
    3910               0 :       listCopy[i] = newNode;
    3911                 :     } else {
    3912               0 :       listCopy[i] = nsnull;
    3913                 :     }
    3914                 :   }
    3915               0 :   jArray<nsHtml5StackNode*,PRInt32> stackCopy = jArray<nsHtml5StackNode*,PRInt32>::newJArray(currentPtr + 1);
    3916               0 :   for (PRInt32 i = 0; i < stackCopy.length; i++) {
    3917               0 :     nsHtml5StackNode* node = stack[i];
    3918               0 :     PRInt32 listIndex = findInListOfActiveFormattingElements(node);
    3919               0 :     if (listIndex == -1) {
    3920               0 :       nsHtml5StackNode* newNode = new nsHtml5StackNode(node->getFlags(), node->ns, node->name, node->node, node->popName, nsnull);
    3921               0 :       stackCopy[i] = newNode;
    3922                 :     } else {
    3923               0 :       stackCopy[i] = listCopy[listIndex];
    3924               0 :       stackCopy[i]->retain();
    3925                 :     }
    3926                 :   }
    3927               0 :   return new nsHtml5StateSnapshot(stackCopy, listCopy, formPointer, headPointer, deepTreeSurrogateParent, mode, originalMode, framesetOk, needToDropLF, quirks);
    3928                 : }
    3929                 : 
    3930                 : bool 
    3931               0 : nsHtml5TreeBuilder::snapshotMatches(nsAHtml5TreeBuilderState* snapshot)
    3932                 : {
    3933               0 :   jArray<nsHtml5StackNode*,PRInt32> stackCopy = snapshot->getStack();
    3934               0 :   PRInt32 stackLen = snapshot->getStackLength();
    3935               0 :   jArray<nsHtml5StackNode*,PRInt32> listCopy = snapshot->getListOfActiveFormattingElements();
    3936               0 :   PRInt32 listLen = snapshot->getListOfActiveFormattingElementsLength();
    3937               0 :   if (stackLen != currentPtr + 1 || listLen != listPtr + 1 || formPointer != snapshot->getFormPointer() || headPointer != snapshot->getHeadPointer() || deepTreeSurrogateParent != snapshot->getDeepTreeSurrogateParent() || mode != snapshot->getMode() || originalMode != snapshot->getOriginalMode() || framesetOk != snapshot->isFramesetOk() || needToDropLF != snapshot->isNeedToDropLF() || quirks != snapshot->isQuirks()) {
    3938               0 :     return false;
    3939                 :   }
    3940               0 :   for (PRInt32 i = listLen - 1; i >= 0; i--) {
    3941               0 :     if (!listCopy[i] && !listOfActiveFormattingElements[i]) {
    3942               0 :       continue;
    3943               0 :     } else if (!listCopy[i] || !listOfActiveFormattingElements[i]) {
    3944               0 :       return false;
    3945                 :     }
    3946               0 :     if (listCopy[i]->node != listOfActiveFormattingElements[i]->node) {
    3947               0 :       return false;
    3948                 :     }
    3949                 :   }
    3950               0 :   for (PRInt32 i = stackLen - 1; i >= 0; i--) {
    3951               0 :     if (stackCopy[i]->node != stack[i]->node) {
    3952               0 :       return false;
    3953                 :     }
    3954                 :   }
    3955               0 :   return true;
    3956                 : }
    3957                 : 
    3958                 : void 
    3959               0 : nsHtml5TreeBuilder::loadState(nsAHtml5TreeBuilderState* snapshot, nsHtml5AtomTable* interner)
    3960                 : {
    3961               0 :   jArray<nsHtml5StackNode*,PRInt32> stackCopy = snapshot->getStack();
    3962               0 :   PRInt32 stackLen = snapshot->getStackLength();
    3963               0 :   jArray<nsHtml5StackNode*,PRInt32> listCopy = snapshot->getListOfActiveFormattingElements();
    3964               0 :   PRInt32 listLen = snapshot->getListOfActiveFormattingElementsLength();
    3965               0 :   for (PRInt32 i = 0; i <= listPtr; i++) {
    3966               0 :     if (listOfActiveFormattingElements[i]) {
    3967               0 :       listOfActiveFormattingElements[i]->release();
    3968                 :     }
    3969                 :   }
    3970               0 :   if (listOfActiveFormattingElements.length < listLen) {
    3971               0 :     listOfActiveFormattingElements = jArray<nsHtml5StackNode*,PRInt32>::newJArray(listLen);
    3972                 :   }
    3973               0 :   listPtr = listLen - 1;
    3974               0 :   for (PRInt32 i = 0; i <= currentPtr; i++) {
    3975               0 :     stack[i]->release();
    3976                 :   }
    3977               0 :   if (stack.length < stackLen) {
    3978               0 :     stack = jArray<nsHtml5StackNode*,PRInt32>::newJArray(stackLen);
    3979                 :   }
    3980               0 :   currentPtr = stackLen - 1;
    3981               0 :   for (PRInt32 i = 0; i < listLen; i++) {
    3982               0 :     nsHtml5StackNode* node = listCopy[i];
    3983               0 :     if (node) {
    3984               0 :       nsHtml5StackNode* newNode = new nsHtml5StackNode(node->getFlags(), node->ns, nsHtml5Portability::newLocalFromLocal(node->name, interner), node->node, nsHtml5Portability::newLocalFromLocal(node->popName, interner), node->attributes->cloneAttributes(nsnull));
    3985               0 :       listOfActiveFormattingElements[i] = newNode;
    3986                 :     } else {
    3987               0 :       listOfActiveFormattingElements[i] = nsnull;
    3988                 :     }
    3989                 :   }
    3990               0 :   for (PRInt32 i = 0; i < stackLen; i++) {
    3991               0 :     nsHtml5StackNode* node = stackCopy[i];
    3992               0 :     PRInt32 listIndex = findInArray(node, listCopy);
    3993               0 :     if (listIndex == -1) {
    3994               0 :       nsHtml5StackNode* newNode = new nsHtml5StackNode(node->getFlags(), node->ns, nsHtml5Portability::newLocalFromLocal(node->name, interner), node->node, nsHtml5Portability::newLocalFromLocal(node->popName, interner), nsnull);
    3995               0 :       stack[i] = newNode;
    3996                 :     } else {
    3997               0 :       stack[i] = listOfActiveFormattingElements[listIndex];
    3998               0 :       stack[i]->retain();
    3999                 :     }
    4000                 :   }
    4001               0 :   formPointer = snapshot->getFormPointer();
    4002               0 :   headPointer = snapshot->getHeadPointer();
    4003               0 :   deepTreeSurrogateParent = snapshot->getDeepTreeSurrogateParent();
    4004               0 :   mode = snapshot->getMode();
    4005               0 :   originalMode = snapshot->getOriginalMode();
    4006               0 :   framesetOk = snapshot->isFramesetOk();
    4007               0 :   needToDropLF = snapshot->isNeedToDropLF();
    4008               0 :   quirks = snapshot->isQuirks();
    4009               0 : }
    4010                 : 
    4011                 : PRInt32 
    4012               0 : nsHtml5TreeBuilder::findInArray(nsHtml5StackNode* node, jArray<nsHtml5StackNode*,PRInt32> arr)
    4013                 : {
    4014               0 :   for (PRInt32 i = listPtr; i >= 0; i--) {
    4015               0 :     if (node == arr[i]) {
    4016               0 :       return i;
    4017                 :     }
    4018                 :   }
    4019               0 :   return -1;
    4020                 : }
    4021                 : 
    4022                 : nsIContent** 
    4023               0 : nsHtml5TreeBuilder::getFormPointer()
    4024                 : {
    4025               0 :   return formPointer;
    4026                 : }
    4027                 : 
    4028                 : nsIContent** 
    4029               0 : nsHtml5TreeBuilder::getHeadPointer()
    4030                 : {
    4031               0 :   return headPointer;
    4032                 : }
    4033                 : 
    4034                 : nsIContent** 
    4035               0 : nsHtml5TreeBuilder::getDeepTreeSurrogateParent()
    4036                 : {
    4037               0 :   return deepTreeSurrogateParent;
    4038                 : }
    4039                 : 
    4040                 : jArray<nsHtml5StackNode*,PRInt32> 
    4041               0 : nsHtml5TreeBuilder::getListOfActiveFormattingElements()
    4042                 : {
    4043               0 :   return listOfActiveFormattingElements;
    4044                 : }
    4045                 : 
    4046                 : jArray<nsHtml5StackNode*,PRInt32> 
    4047               0 : nsHtml5TreeBuilder::getStack()
    4048                 : {
    4049               0 :   return stack;
    4050                 : }
    4051                 : 
    4052                 : PRInt32 
    4053               0 : nsHtml5TreeBuilder::getMode()
    4054                 : {
    4055               0 :   return mode;
    4056                 : }
    4057                 : 
    4058                 : PRInt32 
    4059               0 : nsHtml5TreeBuilder::getOriginalMode()
    4060                 : {
    4061               0 :   return originalMode;
    4062                 : }
    4063                 : 
    4064                 : bool 
    4065               0 : nsHtml5TreeBuilder::isFramesetOk()
    4066                 : {
    4067               0 :   return framesetOk;
    4068                 : }
    4069                 : 
    4070                 : bool 
    4071               0 : nsHtml5TreeBuilder::isNeedToDropLF()
    4072                 : {
    4073               0 :   return needToDropLF;
    4074                 : }
    4075                 : 
    4076                 : bool 
    4077               0 : nsHtml5TreeBuilder::isQuirks()
    4078                 : {
    4079               0 :   return quirks;
    4080                 : }
    4081                 : 
    4082                 : PRInt32 
    4083               0 : nsHtml5TreeBuilder::getListOfActiveFormattingElementsLength()
    4084                 : {
    4085               0 :   return listPtr + 1;
    4086                 : }
    4087                 : 
    4088                 : PRInt32 
    4089               0 : nsHtml5TreeBuilder::getStackLength()
    4090                 : {
    4091               0 :   return currentPtr + 1;
    4092                 : }
    4093                 : 
    4094                 : void
    4095            1404 : nsHtml5TreeBuilder::initializeStatics()
    4096                 : {
    4097            1404 : }
    4098                 : 
    4099                 : void
    4100            1403 : nsHtml5TreeBuilder::releaseStatics()
    4101                 : {
    4102            1403 : }
    4103                 : 
    4104                 : 
    4105                 : #include "nsHtml5TreeBuilderCppSupplement.h"
    4106                 : 

Generated by: LCOV version 1.7