2009-06-28 15:44:22 -07:00
/*
* Copyright ( c ) 2007 Henri Sivonen
2011-04-07 23:07:27 -07:00
* Copyright ( c ) 2007 - 2011 Mozilla Foundation
2013-03-26 00:15:23 -07:00
* Portions of comments Copyright 2004 - 2008 Apple Computer , Inc . , Mozilla
2009-06-28 15:44:22 -07:00
* Foundation , and Opera Software ASA .
*
2013-03-26 00:15:23 -07:00
* Permission is hereby granted , free of charge , to any person obtaining a
* copy of this software and associated documentation files ( the " Software " ) ,
* to deal in the Software without restriction , including without limitation
* the rights to use , copy , modify , merge , publish , distribute , sublicense ,
* and / or sell copies of the Software , and to permit persons to whom the
2009-06-28 15:44:22 -07:00
* Software is furnished to do so , subject to the following conditions :
*
2013-03-26 00:15:23 -07:00
* The above copyright notice and this permission notice shall be included in
2009-06-28 15:44:22 -07:00
* all copies or substantial portions of the Software .
*
2013-03-26 00:15:23 -07:00
* THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING
* FROM , OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2009-06-28 15:44:22 -07:00
* DEALINGS IN THE SOFTWARE .
*/
/*
* THIS IS A GENERATED FILE . PLEASE DO NOT EDIT .
* Please edit TreeBuilder . java instead and regenerate .
*/
# define nsHtml5TreeBuilder_cpp__
2014-03-05 11:38:50 -08:00
# include "nsContentUtils.h"
2009-06-28 15:44:22 -07:00
# include "nsIAtom.h"
2009-09-21 06:18:20 -07:00
# include "nsHtml5AtomTable.h"
2009-06-28 15:44:22 -07:00
# include "nsITimer.h"
# include "nsString.h"
2014-02-27 15:04:46 -08:00
# include "nsNameSpaceManager.h"
2009-06-28 15:44:22 -07:00
# include "nsIContent.h"
2014-03-05 11:38:49 -08:00
# include "nsTraceRefcnt.h"
2009-06-28 15:44:22 -07:00
# include "jArray.h"
# include "nsHtml5DocumentMode.h"
# include "nsHtml5ArrayCopy.h"
# include "nsHtml5Parser.h"
# include "nsHtml5Atoms.h"
# include "nsHtml5TreeOperation.h"
# include "nsHtml5StateSnapshot.h"
# include "nsHtml5StackNode.h"
2009-09-18 02:21:47 -07:00
# include "nsHtml5TreeOpExecutor.h"
# include "nsHtml5StreamParser.h"
2009-09-21 06:18:20 -07:00
# include "nsAHtml5TreeBuilderState.h"
2011-11-01 04:33:11 -07:00
# include "nsHtml5Highlighter.h"
2013-03-26 00:15:23 -07:00
# include "nsHtml5PlainTextUtils.h"
2011-11-30 09:44:31 -08:00
# include "nsHtml5ViewSourceUtils.h"
2012-11-09 01:04:28 -08:00
# include "mozilla/Likely.h"
2014-03-05 11:38:49 -08:00
# include "nsIContentHandle.h"
2014-03-05 11:38:50 -08:00
# include "nsHtml5OplessBuilder.h"
2009-06-28 15:44:22 -07:00
# include "nsHtml5Tokenizer.h"
# include "nsHtml5MetaScanner.h"
# include "nsHtml5AttributeName.h"
# include "nsHtml5ElementName.h"
# include "nsHtml5HtmlAttributes.h"
# include "nsHtml5StackNode.h"
# include "nsHtml5UTF16Buffer.h"
# include "nsHtml5StateSnapshot.h"
# include "nsHtml5Portability.h"
# include "nsHtml5TreeBuilder.h"
2014-01-04 07:02:17 -08:00
char16_t nsHtml5TreeBuilder : : REPLACEMENT_CHARACTER [ ] = { 0xfffd } ;
2010-09-28 00:32:31 -07:00
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// " } ;
2013-03-26 00:15:23 -07:00
staticJArray < const char * , int32_t > nsHtml5TreeBuilder : : QUIRKY_PUBLIC_IDS = { QUIRKY_PUBLIC_IDS_DATA , MOZ_ARRAY_LENGTH ( QUIRKY_PUBLIC_IDS_DATA ) } ;
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : startTokenization ( nsHtml5Tokenizer * self )
{
tokenizer = self ;
2012-08-22 08:56:38 -07:00
stack = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( 64 ) ;
2013-03-26 00:15:23 -07:00
templateModeStack = jArray < int32_t , int32_t > : : newJArray ( 64 ) ;
2012-08-22 08:56:38 -07:00
listOfActiveFormattingElements = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( 64 ) ;
2011-10-17 07:59:28 -07:00
needToDropLF = false ;
2009-06-28 15:44:22 -07:00
originalMode = NS_HTML5TREE_BUILDER_INITIAL ;
2013-03-26 00:15:23 -07:00
templateModePtr = - 1 ;
2009-06-28 15:44:22 -07:00
currentPtr = - 1 ;
listPtr = - 1 ;
2012-07-30 07:20:58 -07:00
formPointer = nullptr ;
headPointer = nullptr ;
deepTreeSurrogateParent = nullptr ;
2009-06-28 15:44:22 -07:00
start ( fragment ) ;
charBufferLen = 0 ;
2014-01-04 07:02:17 -08:00
charBuffer = jArray < char16_t , int32_t > : : newJArray ( 1024 ) ;
2011-10-17 07:59:28 -07:00
framesetOk = true ;
2009-06-28 15:44:22 -07:00
if ( fragment ) {
2014-03-05 11:38:49 -08:00
nsIContentHandle * elt ;
2010-04-19 06:25:13 -07:00
if ( contextNode ) {
2009-06-28 15:44:22 -07:00
elt = contextNode ;
} else {
elt = createHtmlElementSetAsRoot ( tokenizer - > emptyAttributes ( ) ) ;
}
2014-10-27 02:48:11 -07:00
if ( contextNamespace = = kNameSpaceID_SVG ) {
nsHtml5ElementName * elementName = nsHtml5ElementName : : ELT_SVG ;
if ( nsHtml5Atoms : : title = = contextName | | nsHtml5Atoms : : desc = = contextName | | nsHtml5Atoms : : foreignObject = = contextName ) {
elementName = nsHtml5ElementName : : ELT_FOREIGNOBJECT ;
}
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elementName - > camelCaseName , elt ) ;
currentPtr + + ;
stack [ currentPtr ] = node ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_DATA , contextName ) ;
mode = NS_HTML5TREE_BUILDER_FRAMESET_OK ;
} else if ( contextNamespace = = kNameSpaceID_MathML ) {
nsHtml5ElementName * elementName = nsHtml5ElementName : : ELT_MATH ;
if ( nsHtml5Atoms : : mi = = contextName | | nsHtml5Atoms : : mo = = contextName | | nsHtml5Atoms : : mn = = contextName | | nsHtml5Atoms : : ms = = contextName | | nsHtml5Atoms : : mtext = = contextName ) {
elementName = nsHtml5ElementName : : ELT_MTEXT ;
} else if ( nsHtml5Atoms : : annotation_xml = = contextName ) {
elementName = nsHtml5ElementName : : ELT_ANNOTATION_XML ;
}
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elt , elementName - > name , false ) ;
currentPtr + + ;
stack [ currentPtr ] = node ;
2010-04-16 03:52:06 -07:00
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_DATA , contextName ) ;
2014-10-27 02:48:11 -07:00
mode = NS_HTML5TREE_BUILDER_FRAMESET_OK ;
} else {
nsHtml5StackNode * node = new nsHtml5StackNode ( nsHtml5ElementName : : ELT_HTML , elt ) ;
currentPtr + + ;
stack [ currentPtr ] = node ;
if ( nsHtml5Atoms : : template_ = = contextName ) {
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_TEMPLATE ) ;
}
resetTheInsertionMode ( ) ;
formPointer = getFormPointerForContext ( contextNode ) ;
if ( nsHtml5Atoms : : title = = contextName | | nsHtml5Atoms : : textarea = = contextName ) {
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RCDATA , contextName ) ;
} else if ( nsHtml5Atoms : : style = = contextName | | nsHtml5Atoms : : xmp = = contextName | | nsHtml5Atoms : : iframe = = contextName | | nsHtml5Atoms : : noembed = = contextName | | nsHtml5Atoms : : noframes = = contextName | | ( scriptingEnabled & & nsHtml5Atoms : : noscript = = contextName ) ) {
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , contextName ) ;
} else if ( nsHtml5Atoms : : plaintext = = contextName ) {
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_PLAINTEXT , contextName ) ;
} else if ( nsHtml5Atoms : : script = = contextName ) {
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_SCRIPT_DATA , contextName ) ;
} else {
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_DATA , contextName ) ;
}
2009-06-28 15:44:22 -07:00
}
2012-07-30 07:20:58 -07:00
contextName = nullptr ;
contextNode = nullptr ;
2009-06-28 15:44:22 -07:00
} else {
mode = NS_HTML5TREE_BUILDER_INITIAL ;
2011-11-01 04:33:11 -07:00
if ( tokenizer - > isViewingXmlSource ( ) ) {
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt = createElement ( kNameSpaceID_SVG , nsHtml5Atoms : : svg , tokenizer - > emptyAttributes ( ) , nullptr ) ;
2011-11-01 04:33:11 -07:00
nsHtml5StackNode * node = new nsHtml5StackNode ( nsHtml5ElementName : : ELT_SVG , nsHtml5Atoms : : svg , elt ) ;
currentPtr + + ;
stack [ currentPtr ] = node ;
}
2009-06-28 15:44:22 -07:00
}
}
void
2011-09-28 23:19:26 -07:00
nsHtml5TreeBuilder : : doctype ( nsIAtom * name , nsString * publicIdentifier , nsString * systemIdentifier , bool forceQuirks )
2009-06-28 15:44:22 -07:00
{
2011-10-17 07:59:28 -07:00
needToDropLF = false ;
2012-11-09 01:04:28 -08:00
if ( ! isInForeign ( ) & & mode = = NS_HTML5TREE_BUILDER_INITIAL ) {
nsString * emptyString = nsHtml5Portability : : newEmptyString ( ) ;
appendDoctypeToDocument ( ! name ? nsHtml5Atoms : : emptystring : name , ! publicIdentifier ? emptyString : publicIdentifier , ! systemIdentifier ? emptyString : systemIdentifier ) ;
nsHtml5Portability : : releaseString ( emptyString ) ;
if ( isQuirky ( name , publicIdentifier , systemIdentifier , forceQuirks ) ) {
errQuirkyDoctype ( ) ;
documentModeInternal ( QUIRKS_MODE , publicIdentifier , systemIdentifier , false ) ;
} else if ( isAlmostStandards ( publicIdentifier , systemIdentifier ) ) {
errAlmostStandardsDoctype ( ) ;
documentModeInternal ( ALMOST_STANDARDS_MODE , publicIdentifier , systemIdentifier , false ) ;
} else {
documentModeInternal ( STANDARDS_MODE , publicIdentifier , systemIdentifier , false ) ;
2009-06-28 15:44:22 -07:00
}
2012-11-09 01:04:28 -08:00
mode = NS_HTML5TREE_BUILDER_BEFORE_HTML ;
return ;
2009-06-28 15:44:22 -07:00
}
2011-11-01 04:33:11 -07:00
errStrayDoctype ( ) ;
2009-06-28 15:44:22 -07:00
return ;
}
void
2014-01-04 07:02:17 -08:00
nsHtml5TreeBuilder : : comment ( char16_t * buf , int32_t start , int32_t length )
2009-06-28 15:44:22 -07:00
{
2011-10-17 07:59:28 -07:00
needToDropLF = false ;
2010-12-09 01:27:58 -08:00
if ( ! isInForeign ( ) ) {
2010-04-16 03:52:06 -07:00
switch ( mode ) {
case NS_HTML5TREE_BUILDER_INITIAL :
case NS_HTML5TREE_BUILDER_BEFORE_HTML :
case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY :
case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET : {
appendCommentToDocument ( buf , start , length ) ;
return ;
}
case NS_HTML5TREE_BUILDER_AFTER_BODY : {
flushCharacters ( ) ;
appendComment ( stack [ 0 ] - > node , buf , start , length ) ;
return ;
2009-06-28 15:44:22 -07:00
}
default : {
2010-04-16 03:52:06 -07:00
break ;
2009-06-28 15:44:22 -07:00
}
}
}
flushCharacters ( ) ;
appendComment ( stack [ currentPtr ] - > node , buf , start , length ) ;
return ;
}
void
2014-01-04 07:02:17 -08:00
nsHtml5TreeBuilder : : characters ( const char16_t * buf , int32_t start , int32_t length )
2009-06-28 15:44:22 -07:00
{
2011-11-01 04:33:11 -07:00
if ( tokenizer - > isViewingXmlSource ( ) ) {
return ;
}
2009-06-28 15:44:22 -07:00
if ( needToDropLF ) {
2011-10-17 07:59:28 -07:00
needToDropLF = false ;
2009-06-28 15:44:22 -07:00
if ( buf [ start ] = = ' \n ' ) {
start + + ;
length - - ;
if ( ! length ) {
return ;
}
}
}
switch ( mode ) {
case NS_HTML5TREE_BUILDER_IN_BODY :
case NS_HTML5TREE_BUILDER_IN_CELL :
case NS_HTML5TREE_BUILDER_IN_CAPTION : {
2012-01-02 06:18:29 -08:00
if ( ! isInForeignButNotHtmlOrMathTextIntegrationPoint ( ) ) {
2010-09-15 01:37:55 -07:00
reconstructTheActiveFormattingElements ( ) ;
}
2009-06-28 15:44:22 -07:00
}
2009-11-30 07:34:51 -08:00
case NS_HTML5TREE_BUILDER_TEXT : {
2009-06-28 15:44:22 -07:00
accumulateCharacters ( buf , start , length ) ;
return ;
}
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_IN_TABLE :
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY :
case NS_HTML5TREE_BUILDER_IN_ROW : {
accumulateCharactersForced ( buf , start , length ) ;
return ;
}
2009-06-28 15:44:22 -07:00
default : {
2012-08-22 08:56:38 -07:00
int32_t end = start + length ;
for ( int32_t i = start ; i < end ; i + + ) {
2009-06-28 15:44:22 -07:00
switch ( buf [ i ] ) {
case ' ' :
case ' \t ' :
case ' \n ' :
2010-03-09 05:13:48 -08:00
case ' \r ' :
2009-06-28 15:44:22 -07:00
case ' \f ' : {
switch ( mode ) {
case NS_HTML5TREE_BUILDER_INITIAL :
case NS_HTML5TREE_BUILDER_BEFORE_HTML :
case NS_HTML5TREE_BUILDER_BEFORE_HEAD : {
start = i + 1 ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD :
case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT :
case NS_HTML5TREE_BUILDER_AFTER_HEAD :
case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP :
case NS_HTML5TREE_BUILDER_IN_FRAMESET :
case NS_HTML5TREE_BUILDER_AFTER_FRAMESET : {
continue ;
}
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_FRAMESET_OK :
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_IN_TEMPLATE :
2009-06-28 15:44:22 -07:00
case NS_HTML5TREE_BUILDER_IN_BODY :
case NS_HTML5TREE_BUILDER_IN_CELL :
case NS_HTML5TREE_BUILDER_IN_CAPTION : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2012-01-02 06:18:29 -08:00
if ( ! isInForeignButNotHtmlOrMathTextIntegrationPoint ( ) ) {
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
reconstructTheActiveFormattingElements ( ) ;
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charactersloop ) ;
2009-06-28 15:44:22 -07:00
}
case NS_HTML5TREE_BUILDER_IN_SELECT :
case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE : {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charactersloop ) ;
2009-06-28 15:44:22 -07:00
}
case NS_HTML5TREE_BUILDER_IN_TABLE :
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY :
case NS_HTML5TREE_BUILDER_IN_ROW : {
2010-09-15 01:37:55 -07:00
accumulateCharactersForced ( buf , i , 1 ) ;
2009-06-28 15:44:22 -07:00
start = i + 1 ;
continue ;
}
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_AFTER_BODY :
2009-06-28 15:44:22 -07:00
case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY :
case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2009-06-28 15:44:22 -07:00
reconstructTheActiveFormattingElements ( ) ;
continue ;
}
}
}
default : {
switch ( mode ) {
case NS_HTML5TREE_BUILDER_INITIAL : {
2012-07-30 07:20:58 -07:00
documentModeInternal ( QUIRKS_MODE , nullptr , nullptr , false ) ;
2009-06-28 15:44:22 -07:00
mode = NS_HTML5TREE_BUILDER_BEFORE_HTML ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_BEFORE_HTML : {
appendHtmlElementToDocumentAndPush ( ) ;
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_BEFORE_HEAD : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2009-06-28 15:44:22 -07:00
appendToCurrentNodeAndPushHeadElement ( nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2009-06-28 15:44:22 -07:00
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_AFTER_HEAD ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2011-11-01 04:33:11 -07:00
errNonSpaceInNoscriptInHead ( ) ;
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2009-06-28 15:44:22 -07:00
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_AFTER_HEAD : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2009-06-28 15:44:22 -07:00
appendToCurrentNodeAndPushBodyElement ( ) ;
mode = NS_HTML5TREE_BUILDER_FRAMESET_OK ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_FRAMESET_OK : {
2011-10-17 07:59:28 -07:00
framesetOk = false ;
2009-06-28 15:44:22 -07:00
mode = NS_HTML5TREE_BUILDER_IN_BODY ;
i - - ;
continue ;
}
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_IN_TEMPLATE :
2009-06-28 15:44:22 -07:00
case NS_HTML5TREE_BUILDER_IN_BODY :
case NS_HTML5TREE_BUILDER_IN_CELL :
case NS_HTML5TREE_BUILDER_IN_CAPTION : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2012-01-02 06:18:29 -08:00
if ( ! isInForeignButNotHtmlOrMathTextIntegrationPoint ( ) ) {
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
reconstructTheActiveFormattingElements ( ) ;
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charactersloop ) ;
2009-06-28 15:44:22 -07:00
}
case NS_HTML5TREE_BUILDER_IN_TABLE :
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY :
case NS_HTML5TREE_BUILDER_IN_ROW : {
2010-09-15 01:37:55 -07:00
accumulateCharactersForced ( buf , i , 1 ) ;
2009-06-28 15:44:22 -07:00
start = i + 1 ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
start = i ;
}
2013-03-26 00:15:23 -07:00
if ( ! currentPtr | | stack [ currentPtr ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
2011-11-01 04:33:11 -07:00
errNonSpaceInColgroupInFragment ( ) ;
2009-06-28 15:44:22 -07:00
start = i + 1 ;
continue ;
}
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2009-06-28 15:44:22 -07:00
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_SELECT :
case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE : {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charactersloop ) ;
2009-06-28 15:44:22 -07:00
}
case NS_HTML5TREE_BUILDER_AFTER_BODY : {
2011-11-01 04:33:11 -07:00
errNonSpaceAfterBody ( ) ;
2009-06-28 15:44:22 -07:00
2009-12-23 00:31:48 -08:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_FRAMESET : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
}
2011-11-01 04:33:11 -07:00
errNonSpaceInFrameset ( ) ;
2009-06-28 15:44:22 -07:00
start = i + 1 ;
continue ;
}
case NS_HTML5TREE_BUILDER_AFTER_FRAMESET : {
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
}
2011-11-01 04:33:11 -07:00
errNonSpaceAfterFrameset ( ) ;
2009-06-28 15:44:22 -07:00
start = i + 1 ;
continue ;
}
case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY : {
2011-11-01 04:33:11 -07:00
errNonSpaceInTrailer ( ) ;
2009-12-23 00:31:48 -08:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
i - - ;
continue ;
}
case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET : {
2014-05-06 13:29:31 -07:00
if ( start < i ) {
accumulateCharacters ( buf , start , i - start ) ;
}
2011-11-01 04:33:11 -07:00
errNonSpaceInTrailer ( ) ;
2014-05-06 13:29:31 -07:00
start = i + 1 ;
2009-06-28 15:44:22 -07:00
continue ;
}
}
}
}
}
charactersloop_end : ;
if ( start < end ) {
accumulateCharacters ( buf , start , end - start ) ;
}
}
}
}
2010-06-08 23:45:32 -07:00
void
nsHtml5TreeBuilder : : zeroOriginatingReplacementCharacter ( )
{
2010-12-09 01:27:58 -08:00
if ( mode = = NS_HTML5TREE_BUILDER_TEXT ) {
accumulateCharacters ( REPLACEMENT_CHARACTER , 0 , 1 ) ;
return ;
}
if ( currentPtr > = 0 ) {
2012-01-02 06:18:29 -08:00
if ( isSpecialParentInForeign ( stack [ currentPtr ] ) ) {
2010-12-09 01:27:58 -08:00
return ;
}
accumulateCharacters ( REPLACEMENT_CHARACTER , 0 , 1 ) ;
2010-06-08 23:45:32 -07:00
}
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : eof ( )
{
flushCharacters ( ) ;
2010-09-15 01:37:55 -07:00
for ( ; ; ) {
2009-06-28 15:44:22 -07:00
switch ( mode ) {
case NS_HTML5TREE_BUILDER_INITIAL : {
2012-07-30 07:20:58 -07:00
documentModeInternal ( QUIRKS_MODE , nullptr , nullptr , false ) ;
2009-06-28 15:44:22 -07:00
mode = NS_HTML5TREE_BUILDER_BEFORE_HTML ;
continue ;
}
case NS_HTML5TREE_BUILDER_BEFORE_HTML : {
appendHtmlElementToDocumentAndPush ( ) ;
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD ;
continue ;
}
case NS_HTML5TREE_BUILDER_BEFORE_HEAD : {
appendToCurrentNodeAndPushHeadElement ( nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD : {
while ( currentPtr > 0 ) {
popOnEof ( ) ;
}
mode = NS_HTML5TREE_BUILDER_AFTER_HEAD ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT : {
while ( currentPtr > 1 ) {
popOnEof ( ) ;
}
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
continue ;
}
case NS_HTML5TREE_BUILDER_AFTER_HEAD : {
appendToCurrentNodeAndPushBodyElement ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_BODY ;
continue ;
}
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY :
case NS_HTML5TREE_BUILDER_IN_ROW :
case NS_HTML5TREE_BUILDER_IN_TABLE :
case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE :
case NS_HTML5TREE_BUILDER_IN_SELECT :
case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP :
2009-06-28 15:44:22 -07:00
case NS_HTML5TREE_BUILDER_FRAMESET_OK :
case NS_HTML5TREE_BUILDER_IN_CAPTION :
case NS_HTML5TREE_BUILDER_IN_CELL :
case NS_HTML5TREE_BUILDER_IN_BODY : {
2013-08-12 14:46:12 -07:00
if ( isTemplateModeStackEmpty ( ) ) {
NS_HTML5_BREAK ( eofloop ) ;
}
}
case NS_HTML5TREE_BUILDER_IN_TEMPLATE : {
int32_t eltPos = findLast ( nsHtml5Atoms : : template_ ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
MOZ_ASSERT ( fragment ) ;
NS_HTML5_BREAK ( eofloop ) ;
}
if ( MOZ_UNLIKELY ( mViewSource ) ) {
errUnclosedElements ( eltPos , nsHtml5Atoms : : template_ ) ;
}
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
popTemplateMode ( ) ;
resetTheInsertionMode ( ) ;
continue ;
2009-06-28 15:44:22 -07:00
}
2009-11-30 07:34:51 -08:00
case NS_HTML5TREE_BUILDER_TEXT : {
2009-06-28 15:44:22 -07:00
if ( originalMode = = NS_HTML5TREE_BUILDER_AFTER_HEAD ) {
popOnEof ( ) ;
}
popOnEof ( ) ;
mode = originalMode ;
continue ;
}
case NS_HTML5TREE_BUILDER_IN_FRAMESET : {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( eofloop ) ;
2009-06-28 15:44:22 -07:00
}
case NS_HTML5TREE_BUILDER_AFTER_BODY :
case NS_HTML5TREE_BUILDER_AFTER_FRAMESET :
case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY :
case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET :
default : {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( eofloop ) ;
2009-06-28 15:44:22 -07:00
}
}
}
eofloop_end : ;
while ( currentPtr > 0 ) {
popOnEof ( ) ;
}
if ( ! fragment ) {
popOnEof ( ) ;
}
}
void
nsHtml5TreeBuilder : : endTokenization ( )
{
2012-07-30 07:20:58 -07:00
formPointer = nullptr ;
headPointer = nullptr ;
deepTreeSurrogateParent = nullptr ;
2013-03-26 00:15:23 -07:00
templateModeStack = nullptr ;
2010-04-19 06:25:13 -07:00
if ( stack ) {
2009-09-21 06:18:20 -07:00
while ( currentPtr > - 1 ) {
stack [ currentPtr ] - > release ( ) ;
currentPtr - - ;
}
2012-10-01 01:49:01 -07:00
stack = nullptr ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
if ( listOfActiveFormattingElements ) {
2009-09-21 06:18:20 -07:00
while ( listPtr > - 1 ) {
2010-04-19 06:25:13 -07:00
if ( listOfActiveFormattingElements [ listPtr ] ) {
2009-09-21 06:18:20 -07:00
listOfActiveFormattingElements [ listPtr ] - > release ( ) ;
}
listPtr - - ;
2009-06-28 15:44:22 -07:00
}
2012-10-01 01:49:01 -07:00
listOfActiveFormattingElements = nullptr ;
2009-09-21 06:18:20 -07:00
}
2012-10-01 01:49:01 -07:00
charBuffer = nullptr ;
2009-06-28 15:44:22 -07:00
end ( ) ;
}
void
2011-09-28 23:19:26 -07:00
nsHtml5TreeBuilder : : startTag ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes , bool selfClosing )
2009-06-28 15:44:22 -07:00
{
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2012-08-22 08:56:38 -07:00
int32_t eltPos ;
2011-10-17 07:59:28 -07:00
needToDropLF = false ;
2009-06-28 15:44:22 -07:00
starttagloop : for ( ; ; ) {
2012-08-22 08:56:38 -07:00
int32_t group = elementName - > getGroup ( ) ;
2009-06-28 15:44:22 -07:00
nsIAtom * name = elementName - > name ;
2010-12-09 01:27:58 -08:00
if ( isInForeign ( ) ) {
2010-04-19 06:25:13 -07:00
nsHtml5StackNode * currentNode = stack [ currentPtr ] ;
2012-08-22 08:56:38 -07:00
int32_t currNs = currentNode - > ns ;
2010-12-09 01:27:58 -08:00
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 ) ) ) ) ) {
2010-04-19 06:25:13 -07:00
switch ( group ) {
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 :
case NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU :
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_BR :
case NS_HTML5TREE_BUILDER_RUBY_OR_SPAN_OR_SUB_OR_SUP_OR_VAR :
case NS_HTML5TREE_BUILDER_DD_OR_DT :
case NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL :
2013-06-06 01:02:30 -07:00
case NS_HTML5TREE_BUILDER_EMBED :
case NS_HTML5TREE_BUILDER_IMG :
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 :
case NS_HTML5TREE_BUILDER_HEAD :
case NS_HTML5TREE_BUILDER_HR :
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_META :
case NS_HTML5TREE_BUILDER_NOBR :
case NS_HTML5TREE_BUILDER_P :
case NS_HTML5TREE_BUILDER_PRE_OR_LISTING :
2014-10-27 02:48:11 -07:00
case NS_HTML5TREE_BUILDER_TABLE :
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_FONT : {
2014-10-27 02:48:11 -07:00
if ( ! ( group = = NS_HTML5TREE_BUILDER_FONT & & ! ( attributes - > contains ( nsHtml5AttributeName : : ATTR_COLOR ) | | attributes - > contains ( nsHtml5AttributeName : : ATTR_FACE ) | | attributes - > contains ( nsHtml5AttributeName : : ATTR_SIZE ) ) ) ) {
2011-11-01 04:33:11 -07:00
errHtmlStartTagInForeignContext ( name ) ;
2014-10-27 02:48:11 -07:00
if ( ! fragment ) {
while ( ! isSpecialParentInForeign ( stack [ currentPtr ] ) ) {
pop ( ) ;
}
NS_HTML5_CONTINUE ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
}
default : {
if ( kNameSpaceID_SVG = = currNs ) {
attributes - > adjustForSvg ( ) ;
if ( selfClosing ) {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFosterSVG ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2010-04-19 06:25:13 -07:00
} else {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFosterSVG ( elementName , attributes ) ;
2009-06-28 15:44:22 -07:00
}
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
attributes - > adjustForMath ( ) ;
if ( selfClosing ) {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFosterMathML ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2009-06-28 15:44:22 -07:00
} else {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFosterMathML ( elementName , attributes ) ;
2009-06-28 15:44:22 -07:00
}
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
}
}
2010-04-19 06:25:13 -07:00
}
switch ( mode ) {
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_IN_TEMPLATE : {
2013-03-26 00:15:23 -07:00
switch ( group ) {
case NS_HTML5TREE_BUILDER_COL : {
popTemplateMode ( ) ;
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP ) ;
mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP ;
continue ;
}
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT : {
popTemplateMode ( ) ;
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_TABLE ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
}
case NS_HTML5TREE_BUILDER_TR : {
popTemplateMode ( ) ;
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_TABLE_BODY ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
continue ;
}
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
popTemplateMode ( ) ;
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_ROW ) ;
mode = NS_HTML5TREE_BUILDER_IN_ROW ;
continue ;
}
case NS_HTML5TREE_BUILDER_META : {
checkMetaCharset ( attributes ) ;
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
selfClosing = false ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_TITLE : {
startTagTitleInHead ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_BASE :
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND : {
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
selfClosing = false ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SCRIPT : {
startTagScriptInHead ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_NOFRAMES :
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_STYLE : {
startTagGenericRawText ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TEMPLATE : {
startTagTemplateInHead ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
popTemplateMode ( ) ;
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_BODY ) ;
mode = NS_HTML5TREE_BUILDER_IN_BODY ;
continue ;
}
}
}
2012-11-09 01:04:28 -08:00
case NS_HTML5TREE_BUILDER_IN_ROW : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
clearStackBackTo ( findLastOrRoot ( NS_HTML5TREE_BUILDER_TR ) ) ;
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
mode = NS_HTML5TREE_BUILDER_IN_CELL ;
insertMarker ( ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR : {
eltPos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TR ) ;
if ( ! eltPos ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2012-11-09 01:04:28 -08:00
errNoTableRowToClose ( ) ;
NS_HTML5_BREAK ( starttagloop ) ;
}
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
continue ;
}
default :
; // fall through
}
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_TR : {
2013-03-26 00:15:23 -07:00
clearStackBackTo ( findLastInTableScopeOrRootTemplateTbodyTheadTfoot ( ) ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_ROW ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
2011-11-01 04:33:11 -07:00
errStartTagInTableBody ( name ) ;
2013-03-26 00:15:23 -07:00
clearStackBackTo ( findLastInTableScopeOrRootTemplateTbodyTheadTfoot ( ) ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( nsHtml5ElementName : : ELT_TR , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_ROW ;
continue ;
}
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT : {
2013-03-26 00:15:23 -07:00
eltPos = findLastInTableScopeOrRootTemplateTbodyTheadTfoot ( ) ;
if ( ! eltPos | | stack [ eltPos ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_IN_TABLE : {
for ( ; ; ) {
switch ( group ) {
case NS_HTML5TREE_BUILDER_CAPTION : {
clearStackBackTo ( findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ) ;
insertMarker ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_CAPTION ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_COLGROUP : {
clearStackBackTo ( findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_COL : {
clearStackBackTo ( findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( nsHtml5ElementName : : ELT_COLGROUP , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP ;
NS_HTML5_CONTINUE ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT : {
clearStackBackTo ( findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TR :
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
clearStackBackTo ( findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( nsHtml5ElementName : : ELT_TBODY , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
NS_HTML5_CONTINUE ( starttagloop ) ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
NS_HTML5_BREAK ( intableloop ) ;
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_TABLE : {
2011-11-01 04:33:11 -07:00
errTableSeenWhileTableOpen ( ) ;
2010-04-19 06:25:13 -07:00
eltPos = findLastInTableScope ( name ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( nsHtml5Atoms : : table ) ) {
2011-11-01 04:33:11 -07:00
errNoCheckUnclosedElementsOnStack ( ) ;
}
2010-04-19 06:25:13 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
resetTheInsertionMode ( ) ;
NS_HTML5_CONTINUE ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SCRIPT : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_SCRIPT_DATA , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_STYLE : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_INPUT : {
2013-09-17 05:47:32 -07:00
errStartTagInTable ( name ) ;
2010-04-19 06:25:13 -07:00
if ( ! nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " hidden " , attributes - > getValue ( nsHtml5AttributeName : : ATTR_TYPE ) ) ) {
NS_HTML5_BREAK ( intableloop ) ;
}
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrent ( name , attributes , formPointer ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_FORM : {
2014-01-31 15:03:24 -08:00
if ( ! ! formPointer | | isTemplateContents ( ) ) {
2011-11-01 04:33:11 -07:00
errFormWhenFormOpen ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
2011-11-01 04:33:11 -07:00
errStartTagInTable ( name ) ;
2010-04-19 06:25:13 -07:00
appendVoidFormToCurrent ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
default : {
2011-11-01 04:33:11 -07:00
errStartTagInTable ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( intableloop ) ;
}
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
}
intableloop_end : ;
}
case NS_HTML5TREE_BUILDER_IN_CAPTION : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR :
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
eltPos = findLastInTableScope ( nsHtml5Atoms : : caption ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
NS_HTML5_BREAK ( starttagloop ) ;
}
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & currentPtr ! = eltPos ) {
2011-11-01 04:33:11 -07:00
errNoCheckUnclosedElementsOnStack ( ) ;
}
2010-04-19 06:25:13 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_IN_CELL : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR :
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
eltPos = findLastInTableScopeTdTh ( ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2011-11-01 04:33:11 -07:00
errNoCellToClose ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
closeTheCell ( eltPos ) ;
continue ;
}
}
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_FRAMESET_OK : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_FRAMESET : {
if ( mode = = NS_HTML5TREE_BUILDER_FRAMESET_OK ) {
2010-12-09 01:27:57 -08:00
if ( ! currentPtr | | stack [ 1 ] - > getGroup ( ) ! = NS_HTML5TREE_BUILDER_BODY ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
2011-11-01 04:33:11 -07:00
errFramesetStart ( ) ;
2010-04-19 06:25:13 -07:00
detachFromParent ( stack [ 1 ] - > node ) ;
while ( currentPtr > 0 ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_FRAMESET ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
} else {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_PRE_OR_LISTING :
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_DD_OR_DT :
case NS_HTML5TREE_BUILDER_BUTTON :
case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET :
case NS_HTML5TREE_BUILDER_OBJECT :
case NS_HTML5TREE_BUILDER_TABLE :
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_AREA_OR_WBR :
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_BR :
2013-06-06 01:02:30 -07:00
case NS_HTML5TREE_BUILDER_EMBED :
case NS_HTML5TREE_BUILDER_IMG :
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_INPUT :
case NS_HTML5TREE_BUILDER_KEYGEN :
case NS_HTML5TREE_BUILDER_HR :
case NS_HTML5TREE_BUILDER_TEXTAREA :
case NS_HTML5TREE_BUILDER_XMP :
case NS_HTML5TREE_BUILDER_IFRAME :
case NS_HTML5TREE_BUILDER_SELECT : {
2010-11-18 00:19:59 -08:00
if ( mode = = NS_HTML5TREE_BUILDER_FRAMESET_OK & & ! ( group = = NS_HTML5TREE_BUILDER_INPUT & & nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " hidden " , attributes - > getValue ( nsHtml5AttributeName : : ATTR_TYPE ) ) ) ) {
2011-10-17 07:59:28 -07:00
framesetOk = false ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_BODY ;
}
}
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_IN_BODY : {
for ( ; ; ) {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_BASE :
2010-06-11 08:08:13 -07:00
case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND :
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_META :
case NS_HTML5TREE_BUILDER_STYLE :
case NS_HTML5TREE_BUILDER_SCRIPT :
case NS_HTML5TREE_BUILDER_TITLE :
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( inbodyloop ) ;
}
case NS_HTML5TREE_BUILDER_BODY : {
2013-03-26 00:15:23 -07:00
if ( ! currentPtr | | stack [ 1 ] - > getGroup ( ) ! = NS_HTML5TREE_BUILDER_BODY | | isTemplateContents ( ) ) {
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-12-09 01:27:58 -08:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2011-10-17 07:59:28 -07:00
framesetOk = false ;
2010-12-09 01:27:58 -08:00
if ( mode = = NS_HTML5TREE_BUILDER_FRAMESET_OK ) {
mode = NS_HTML5TREE_BUILDER_IN_BODY ;
}
2010-06-08 23:44:25 -07:00
if ( addAttributesToBody ( attributes ) ) {
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_P :
case NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU :
case NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL :
2013-01-29 04:31:45 -08:00
case NS_HTML5TREE_BUILDER_ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY : {
2010-04-19 06:25:13 -07:00
implicitlyCloseP ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 : {
implicitlyCloseP ( ) ;
2010-12-09 01:27:57 -08:00
if ( stack [ currentPtr ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 ) {
2011-11-01 04:33:11 -07:00
errHeadingWhenHeadingOpen ( ) ;
2010-04-19 06:25:13 -07:00
pop ( ) ;
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_FIELDSET : {
implicitlyCloseP ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes , formPointer ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_PRE_OR_LISTING : {
implicitlyCloseP ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
needToDropLF = true ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_FORM : {
2014-01-31 15:03:24 -08:00
if ( ! ! formPointer & & ! isTemplateContents ( ) ) {
2011-11-01 04:33:11 -07:00
errFormWhenFormOpen ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
implicitlyCloseP ( ) ;
appendToCurrentNodeAndPushFormElementMayFoster ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
}
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_DD_OR_DT : {
eltPos = currentPtr ;
for ( ; ; ) {
nsHtml5StackNode * node = stack [ eltPos ] ;
2010-12-09 01:27:57 -08:00
if ( node - > getGroup ( ) = = group ) {
2010-04-19 06:25:13 -07:00
generateImpliedEndTagsExceptFor ( node - > name ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & eltPos ! = currentPtr ) {
2011-11-01 04:33:11 -07:00
errUnclosedElementsImplied ( eltPos , name ) ;
}
2010-04-19 06:25:13 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
break ;
2013-08-12 14:46:12 -07:00
} else if ( node - > isSpecial ( ) & & ( node - > ns ! = kNameSpaceID_XHTML | | ( node - > name ! = nsHtml5Atoms : : p & & node - > name ! = nsHtml5Atoms : : address & & node - > name ! = nsHtml5Atoms : : div ) ) ) {
2010-04-19 06:25:13 -07:00
break ;
}
eltPos - - ;
}
implicitlyCloseP ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_PLAINTEXT : {
implicitlyCloseP ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_PLAINTEXT , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_A : {
2012-08-22 08:56:38 -07:00
int32_t activeAPos = findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker ( nsHtml5Atoms : : a ) ;
2010-04-19 06:25:13 -07:00
if ( activeAPos ! = - 1 ) {
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2010-04-19 06:25:13 -07:00
nsHtml5StackNode * activeA = listOfActiveFormattingElements [ activeAPos ] ;
activeA - > retain ( ) ;
adoptionAgencyEndTag ( nsHtml5Atoms : : a ) ;
removeFromStack ( activeA ) ;
activeAPos = findInListOfActiveFormattingElements ( activeA ) ;
if ( activeAPos ! = - 1 ) {
removeFromListOfActiveFormattingElements ( activeAPos ) ;
}
activeA - > release ( ) ;
}
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushFormattingElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
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 :
case NS_HTML5TREE_BUILDER_FONT : {
reconstructTheActiveFormattingElements ( ) ;
2010-10-15 02:23:42 -07:00
maybeForgetEarlierDuplicateFormattingElement ( elementName - > name , attributes ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushFormattingElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_NOBR : {
reconstructTheActiveFormattingElements ( ) ;
if ( NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ! = findLastInScope ( nsHtml5Atoms : : nobr ) ) {
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2010-04-19 06:25:13 -07:00
adoptionAgencyEndTag ( nsHtml5Atoms : : nobr ) ;
2011-02-21 15:06:27 -08:00
reconstructTheActiveFormattingElements ( ) ;
2010-04-19 06:25:13 -07:00
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushFormattingElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_BUTTON : {
eltPos = findLastInScope ( name ) ;
if ( eltPos ! = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2010-04-19 06:25:13 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
2011-11-01 04:33:11 -07:00
errUnclosedElementsImplied ( eltPos , name ) ;
}
2010-04-19 06:25:13 -07:00
while ( currentPtr > = eltPos ) {
2009-06-28 15:44:22 -07:00
pop ( ) ;
}
2010-04-19 06:25:13 -07:00
NS_HTML5_CONTINUE ( starttagloop ) ;
} else {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes , formPointer ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
}
case NS_HTML5TREE_BUILDER_OBJECT : {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes , formPointer ) ;
2010-04-19 06:25:13 -07:00
insertMarker ( ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET : {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
insertMarker ( ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TABLE : {
if ( ! quirks ) {
implicitlyCloseP ( ) ;
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_BR :
2013-06-06 01:02:30 -07:00
case NS_HTML5TREE_BUILDER_EMBED :
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_AREA_OR_WBR : {
2010-04-19 06:25:13 -07:00
reconstructTheActiveFormattingElements ( ) ;
}
2011-08-05 23:41:36 -07:00
# ifdef ENABLE_VOID_MENUITEM
case NS_HTML5TREE_BUILDER_MENUITEM :
# endif
2011-01-12 00:05:09 -08:00
case NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE_OR_TRACK : {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_HR : {
implicitlyCloseP ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_IMAGE : {
2011-11-01 04:33:11 -07:00
errImage ( ) ;
2010-04-19 06:25:13 -07:00
elementName = nsHtml5ElementName : : ELT_IMG ;
NS_HTML5_CONTINUE ( starttagloop ) ;
}
2013-06-06 01:02:30 -07:00
case NS_HTML5TREE_BUILDER_IMG :
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_KEYGEN :
case NS_HTML5TREE_BUILDER_INPUT : {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( name , attributes , formPointer ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_ISINDEX : {
2011-11-01 04:33:11 -07:00
errIsindex ( ) ;
2014-01-31 15:03:24 -08:00
if ( ! ! formPointer & & ! isTemplateContents ( ) ) {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
implicitlyCloseP ( ) ;
nsHtml5HtmlAttributes * formAttrs = new nsHtml5HtmlAttributes ( 0 ) ;
2012-08-22 08:56:38 -07:00
int32_t actionIndex = attributes - > getIndex ( nsHtml5AttributeName : : ATTR_ACTION ) ;
2010-04-19 06:25:13 -07:00
if ( actionIndex > - 1 ) {
2012-10-01 01:49:01 -07:00
formAttrs - > addAttribute ( nsHtml5AttributeName : : ATTR_ACTION , attributes - > getValueNoBoundsCheck ( actionIndex ) ) ;
2010-04-19 06:25:13 -07:00
}
appendToCurrentNodeAndPushFormElementMayFoster ( formAttrs ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( nsHtml5ElementName : : ELT_HR , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
appendToCurrentNodeAndPushElementMayFoster ( nsHtml5ElementName : : ELT_LABEL , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2012-08-22 08:56:38 -07:00
int32_t promptIndex = attributes - > getIndex ( nsHtml5AttributeName : : ATTR_PROMPT ) ;
2010-04-19 06:25:13 -07:00
if ( promptIndex > - 1 ) {
2014-01-04 07:02:17 -08:00
autoJArray < char16_t , int32_t > prompt = nsHtml5Portability : : newCharArrayFromString ( attributes - > getValueNoBoundsCheck ( promptIndex ) ) ;
2010-04-19 06:25:13 -07:00
appendCharacters ( stack [ currentPtr ] - > node , prompt , 0 , prompt . length ) ;
} else {
2010-06-11 08:08:13 -07:00
appendIsindexPrompt ( stack [ currentPtr ] - > node ) ;
2010-04-19 06:25:13 -07:00
}
nsHtml5HtmlAttributes * inputAttributes = new nsHtml5HtmlAttributes ( 0 ) ;
inputAttributes - > addAttribute ( nsHtml5AttributeName : : ATTR_NAME , nsHtml5Portability : : newStringFromLiteral ( " isindex " ) ) ;
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < attributes - > getLength ( ) ; i + + ) {
2012-10-01 01:49:01 -07:00
nsHtml5AttributeName * attributeQName = attributes - > getAttributeNameNoBoundsCheck ( i ) ;
2010-04-19 06:25:13 -07:00
if ( nsHtml5AttributeName : : ATTR_NAME = = attributeQName | | nsHtml5AttributeName : : ATTR_PROMPT = = attributeQName ) {
attributes - > releaseValue ( i ) ;
} else if ( nsHtml5AttributeName : : ATTR_ACTION ! = attributeQName ) {
2012-10-01 01:49:01 -07:00
inputAttributes - > addAttribute ( attributeQName , attributes - > getValueNoBoundsCheck ( i ) ) ;
2009-11-30 07:34:51 -08:00
}
2010-04-19 06:25:13 -07:00
}
attributes - > clearWithoutReleasingContents ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( nsHtml5Atoms : : input , inputAttributes , formPointer ) ;
2010-04-19 06:25:13 -07:00
pop ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( nsHtml5ElementName : : ELT_HR , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2010-04-19 06:25:13 -07:00
pop ( ) ;
2014-01-31 15:03:24 -08:00
if ( ! isTemplateContents ( ) ) {
formPointer = nullptr ;
}
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TEXTAREA : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes , formPointer ) ;
2010-04-19 06:25:13 -07:00
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RCDATA , elementName ) ;
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
2011-10-17 07:59:28 -07:00
needToDropLF = true ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_XMP : {
implicitlyCloseP ( ) ;
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_NOSCRIPT : {
if ( ! scriptingEnabled ) {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
}
}
case NS_HTML5TREE_BUILDER_NOFRAMES :
case NS_HTML5TREE_BUILDER_IFRAME :
case NS_HTML5TREE_BUILDER_NOEMBED : {
2013-03-26 00:15:23 -07:00
startTagGenericRawText ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SELECT : {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes , formPointer ) ;
2010-04-19 06:25:13 -07:00
switch ( mode ) {
case NS_HTML5TREE_BUILDER_IN_TABLE :
case NS_HTML5TREE_BUILDER_IN_CAPTION :
case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP :
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY :
case NS_HTML5TREE_BUILDER_IN_ROW :
case NS_HTML5TREE_BUILDER_IN_CELL : {
mode = NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE ;
break ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
default : {
mode = NS_HTML5TREE_BUILDER_IN_SELECT ;
break ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
}
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_OPTGROUP :
case NS_HTML5TREE_BUILDER_OPTION : {
2010-12-09 01:27:58 -08:00
if ( isCurrent ( nsHtml5Atoms : : option ) ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2014-08-18 22:33:45 -07:00
case NS_HTML5TREE_BUILDER_RB_OR_RTC : {
2010-04-19 06:25:13 -07:00
eltPos = findLastInScope ( nsHtml5Atoms : : ruby ) ;
if ( eltPos ! = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
generateImpliedEndTags ( ) ;
}
if ( eltPos ! = currentPtr ) {
2014-08-04 15:54:20 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2011-11-01 04:33:11 -07:00
errStartTagSeenWithoutRuby ( name ) ;
} else {
errUnclosedChildrenInRuby ( ) ;
}
2009-06-28 15:44:22 -07:00
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2014-08-18 22:33:45 -07:00
case NS_HTML5TREE_BUILDER_RT_OR_RP : {
2014-06-20 17:08:31 -07:00
eltPos = findLastInScope ( nsHtml5Atoms : : ruby ) ;
if ( eltPos ! = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
generateImpliedEndTagsExceptFor ( nsHtml5Atoms : : rtc ) ;
}
if ( eltPos ! = currentPtr ) {
if ( ! isCurrent ( nsHtml5Atoms : : rtc ) ) {
2014-08-04 15:54:20 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2014-06-20 17:08:31 -07:00
errStartTagSeenWithoutRuby ( name ) ;
} else {
errUnclosedChildrenInRuby ( ) ;
}
}
}
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_MATH : {
reconstructTheActiveFormattingElements ( ) ;
attributes - > adjustForMath ( ) ;
if ( selfClosing ) {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFosterMathML ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2010-04-19 06:25:13 -07:00
} else {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFosterMathML ( elementName , attributes ) ;
2009-06-28 15:44:22 -07:00
}
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SVG : {
reconstructTheActiveFormattingElements ( ) ;
attributes - > adjustForSvg ( ) ;
if ( selfClosing ) {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFosterSVG ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2010-04-19 06:25:13 -07:00
} else {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFosterSVG ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
}
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR :
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_FRAME :
case NS_HTML5TREE_BUILDER_FRAMESET :
case NS_HTML5TREE_BUILDER_HEAD : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_OUTPUT_OR_LABEL : {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes , formPointer ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
}
}
inbodyloop_end : ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD : {
for ( ; ; ) {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_BASE :
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND : {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_META : {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( inheadloop ) ;
}
case NS_HTML5TREE_BUILDER_TITLE : {
2013-08-12 14:46:12 -07:00
startTagTitleInHead ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_NOSCRIPT : {
if ( scriptingEnabled ) {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2009-06-28 15:44:22 -07:00
originalMode = mode ;
2009-11-30 07:34:51 -08:00
mode = NS_HTML5TREE_BUILDER_TEXT ;
2010-04-16 03:52:06 -07:00
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
2010-04-19 06:25:13 -07:00
} else {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT ;
2009-06-28 15:44:22 -07:00
}
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SCRIPT : {
2013-03-26 00:15:23 -07:00
startTagScriptInHead ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_STYLE :
case NS_HTML5TREE_BUILDER_NOFRAMES : {
2013-03-26 00:15:23 -07:00
startTagGenericRawText ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_HEAD : {
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
startTagTemplateInHead ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
2010-04-19 06:25:13 -07:00
default : {
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_AFTER_HEAD ;
NS_HTML5_CONTINUE ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
}
inheadloop_end : ;
}
case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2010-06-11 08:08:13 -07:00
case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND : {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_META : {
checkMetaCharset ( attributes ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_STYLE :
case NS_HTML5TREE_BUILDER_NOFRAMES : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_HEAD : {
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_NOSCRIPT : {
2011-11-01 04:33:11 -07:00
errFooSeenWhenFooOpen ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
default : {
2011-11-01 04:33:11 -07:00
errBadStartTagInHead ( name ) ;
2010-04-19 06:25:13 -07:00
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_COL : {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
startTagTemplateInHead ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
2010-04-19 06:25:13 -07:00
default : {
2013-03-26 00:15:23 -07:00
if ( ! currentPtr | | stack [ currentPtr ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errGarbageInColgroup ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR :
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_TABLE : {
2011-11-01 04:33:11 -07:00
errStartTagWithSelectOpen ( name ) ;
2010-04-19 06:25:13 -07:00
eltPos = findLastInTableScope ( nsHtml5Atoms : : select ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( fragment ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
resetTheInsertionMode ( ) ;
continue ;
}
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_IN_SELECT : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-06-08 23:44:25 -07:00
if ( ! fragment ) {
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_OPTION : {
if ( isCurrent ( nsHtml5Atoms : : option ) ) {
pop ( ) ;
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_OPTGROUP : {
if ( isCurrent ( nsHtml5Atoms : : option ) ) {
pop ( ) ;
}
if ( isCurrent ( nsHtml5Atoms : : optgroup ) ) {
pop ( ) ;
}
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SELECT : {
2011-11-01 04:33:11 -07:00
errStartSelectWhereEndSelectExpected ( ) ;
2010-04-19 06:25:13 -07:00
eltPos = findLastInTableScope ( name ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( fragment ) ;
2011-11-01 04:33:11 -07:00
errNoSelectInTableScope ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
} else {
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
resetTheInsertionMode ( ) ;
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_INPUT :
case NS_HTML5TREE_BUILDER_TEXTAREA :
case NS_HTML5TREE_BUILDER_KEYGEN : {
2011-11-01 04:33:11 -07:00
errStartTagWithSelectOpen ( name ) ;
2010-04-19 06:25:13 -07:00
eltPos = findLastInTableScope ( nsHtml5Atoms : : select ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( fragment ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
resetTheInsertionMode ( ) ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_SCRIPT : {
2013-03-26 00:15:23 -07:00
startTagScriptInHead ( elementName , attributes ) ;
attributes = nullptr ;
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TEMPLATE : {
startTagTemplateInHead ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
}
}
case NS_HTML5TREE_BUILDER_AFTER_BODY : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
default : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
continue ;
}
2010-04-19 06:25:13 -07:00
}
}
case NS_HTML5TREE_BUILDER_IN_FRAMESET : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_FRAMESET : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_FRAME : {
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_AFTER_FRAMESET : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_NOFRAMES : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
}
}
case NS_HTML5TREE_BUILDER_INITIAL : {
2011-11-01 04:33:11 -07:00
errStartTagWithoutDoctype ( ) ;
2012-07-30 07:20:58 -07:00
documentModeInternal ( QUIRKS_MODE , nullptr , nullptr , false ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_BEFORE_HTML ;
continue ;
}
case NS_HTML5TREE_BUILDER_BEFORE_HTML : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
if ( attributes = = nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) {
appendHtmlElementToDocumentAndPush ( ) ;
} else {
appendHtmlElementToDocumentAndPush ( attributes ) ;
}
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
appendHtmlElementToDocumentAndPush ( ) ;
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_BEFORE_HEAD : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_HEAD : {
appendToCurrentNodeAndPushHeadElement ( attributes ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
appendToCurrentNodeAndPushHeadElement ( nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_AFTER_HEAD : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_BODY : {
if ( ! attributes - > getLength ( ) ) {
appendToCurrentNodeAndPushBodyElement ( ) ;
} else {
appendToCurrentNodeAndPushBodyElement ( attributes ) ;
}
2011-10-17 07:59:28 -07:00
framesetOk = false ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_BODY ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_FRAMESET : {
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
mode = NS_HTML5TREE_BUILDER_IN_FRAMESET ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-11-04 17:19:22 -08:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
2011-11-01 04:33:11 -07:00
errFooBetweenHeadAndBody ( name ) ;
2010-04-19 06:25:13 -07:00
pushHeadPointerOntoStack ( ) ;
2013-11-04 17:19:22 -08:00
nsHtml5StackNode * headOnStack = stack [ currentPtr ] ;
startTagTemplateInHead ( elementName , attributes ) ;
removeFromStack ( headOnStack ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2013-11-04 17:19:22 -08:00
case NS_HTML5TREE_BUILDER_BASE :
2010-06-11 08:08:13 -07:00
case NS_HTML5TREE_BUILDER_LINK_OR_BASEFONT_OR_BGSOUND : {
2011-11-01 04:33:11 -07:00
errFooBetweenHeadAndBody ( name ) ;
2010-04-19 06:25:13 -07:00
pushHeadPointerOntoStack ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2010-04-19 06:25:13 -07:00
pop ( ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_META : {
2011-11-01 04:33:11 -07:00
errFooBetweenHeadAndBody ( name ) ;
2010-04-19 06:25:13 -07:00
checkMetaCharset ( attributes ) ;
pushHeadPointerOntoStack ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , attributes ) ;
2011-10-17 07:59:28 -07:00
selfClosing = false ;
2010-04-19 06:25:13 -07:00
pop ( ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_SCRIPT : {
2011-11-01 04:33:11 -07:00
errFooBetweenHeadAndBody ( name ) ;
2010-04-19 06:25:13 -07:00
pushHeadPointerOntoStack ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_SCRIPT_DATA , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_STYLE :
case NS_HTML5TREE_BUILDER_NOFRAMES : {
2011-11-01 04:33:11 -07:00
errFooBetweenHeadAndBody ( name ) ;
2010-04-19 06:25:13 -07:00
pushHeadPointerOntoStack ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_TITLE : {
2011-11-01 04:33:11 -07:00
errFooBetweenHeadAndBody ( name ) ;
2010-04-19 06:25:13 -07:00
pushHeadPointerOntoStack ( ) ;
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2010-04-19 06:25:13 -07:00
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RCDATA , elementName ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
case NS_HTML5TREE_BUILDER_HEAD : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
appendToCurrentNodeAndPushBodyElement ( ) ;
mode = NS_HTML5TREE_BUILDER_FRAMESET_OK ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
}
}
case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-06-08 23:44:25 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-06-08 23:44:25 -07:00
}
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2009-06-28 15:44:22 -07:00
2010-04-19 06:25:13 -07:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
}
}
case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET : {
switch ( group ) {
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2013-03-26 00:15:23 -07:00
if ( ! fragment & & ! isTemplateContents ( ) ) {
2010-09-15 01:37:55 -07:00
addAttributesToHtml ( attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-09-15 01:37:55 -07:00
}
NS_HTML5_BREAK ( starttagloop ) ;
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_NOFRAMES : {
2013-11-13 14:57:07 -08:00
startTagGenericRawText ( elementName , attributes ) ;
2012-07-30 07:20:58 -07:00
attributes = nullptr ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
default : {
2011-11-01 04:33:11 -07:00
errStrayStartTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
2010-03-12 02:27:15 -08:00
}
2009-06-28 15:44:22 -07:00
}
}
2010-04-19 06:25:13 -07:00
case NS_HTML5TREE_BUILDER_TEXT : {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( false ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( starttagloop ) ;
}
2009-06-28 15:44:22 -07:00
}
}
starttagloop_end : ;
2011-11-01 04:33:11 -07:00
if ( selfClosing ) {
errSelfClosing ( ) ;
}
2014-03-05 11:38:50 -08:00
if ( ! mBuilder & & attributes ! = nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) {
2009-09-21 04:43:43 -07:00
delete attributes ;
}
2009-06-28 15:44:22 -07:00
}
2013-08-12 14:46:12 -07:00
void
nsHtml5TreeBuilder : : startTagTitleInHead ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
{
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RCDATA , elementName ) ;
}
2013-03-26 00:15:23 -07:00
void
nsHtml5TreeBuilder : : startTagGenericRawText ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
{
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_RAWTEXT , elementName ) ;
}
void
nsHtml5TreeBuilder : : startTagScriptInHead ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
{
appendToCurrentNodeAndPushElementMayFoster ( elementName , attributes ) ;
originalMode = mode ;
mode = NS_HTML5TREE_BUILDER_TEXT ;
tokenizer - > setStateAndEndTagExpectation ( NS_HTML5TOKENIZER_SCRIPT_DATA , elementName ) ;
}
void
nsHtml5TreeBuilder : : startTagTemplateInHead ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
{
appendToCurrentNodeAndPushElement ( elementName , attributes ) ;
2013-08-12 14:46:12 -07:00
insertMarker ( ) ;
framesetOk = false ;
2013-03-26 00:15:23 -07:00
originalMode = mode ;
2013-08-12 14:46:12 -07:00
mode = NS_HTML5TREE_BUILDER_IN_TEMPLATE ;
pushTemplateMode ( NS_HTML5TREE_BUILDER_IN_TEMPLATE ) ;
2013-03-26 00:15:23 -07:00
}
bool
nsHtml5TreeBuilder : : isTemplateContents ( )
{
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ! = findLast ( nsHtml5Atoms : : template_ ) ;
}
2013-08-12 14:46:12 -07:00
bool
nsHtml5TreeBuilder : : isTemplateModeStackEmpty ( )
{
return templateModePtr = = - 1 ;
}
2011-09-28 23:19:26 -07:00
bool
2010-09-15 01:37:55 -07:00
nsHtml5TreeBuilder : : isSpecialParentInForeign ( nsHtml5StackNode * stackNode )
{
2012-08-22 08:56:38 -07:00
int32_t ns = stackNode - > ns ;
2010-12-09 01:27:58 -08:00
return ( kNameSpaceID_XHTML = = ns ) | | ( stackNode - > isHtmlIntegrationPoint ( ) ) | | ( ( kNameSpaceID_MathML = = ns ) & & ( stackNode - > getGroup ( ) = = NS_HTML5TREE_BUILDER_MI_MO_MN_MS_MTEXT ) ) ;
2010-09-15 01:37:55 -07:00
}
2009-06-28 15:44:22 -07:00
nsString *
nsHtml5TreeBuilder : : extractCharsetFromContent ( nsString * attributeValue )
{
2012-08-22 08:56:38 -07:00
int32_t charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
int32_t start = - 1 ;
int32_t end = - 1 ;
2014-01-04 07:02:17 -08:00
autoJArray < char16_t , int32_t > buffer = nsHtml5Portability : : newCharArrayFromString ( attributeValue ) ;
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < buffer . length ; i + + ) {
2014-01-04 07:02:17 -08:00
char16_t c = buffer [ i ] ;
2009-06-28 15:44:22 -07:00
switch ( charsetState ) {
case NS_HTML5TREE_BUILDER_CHARSET_INITIAL : {
switch ( c ) {
case ' c ' :
case ' C ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_C ;
continue ;
}
default : {
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_C : {
switch ( c ) {
case ' h ' :
case ' H ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_H ;
continue ;
}
default : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_H : {
switch ( c ) {
case ' a ' :
case ' A ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_A ;
continue ;
}
default : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_A : {
switch ( c ) {
case ' r ' :
case ' R ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_R ;
continue ;
}
default : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_R : {
switch ( c ) {
case ' s ' :
case ' S ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_S ;
continue ;
}
default : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_S : {
switch ( c ) {
case ' e ' :
case ' E ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_E ;
continue ;
}
default : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_E : {
switch ( c ) {
case ' t ' :
case ' T ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_T ;
continue ;
}
default : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_INITIAL ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_T : {
switch ( c ) {
case ' \t ' :
case ' \n ' :
case ' \f ' :
case ' \r ' :
case ' ' : {
continue ;
}
case ' = ' : {
charsetState = NS_HTML5TREE_BUILDER_CHARSET_EQUALS ;
continue ;
}
default : {
2012-07-30 07:20:58 -07:00
return nullptr ;
2009-06-28 15:44:22 -07:00
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_EQUALS : {
switch ( c ) {
case ' \t ' :
case ' \n ' :
case ' \f ' :
case ' \r ' :
case ' ' : {
continue ;
}
case ' \' ' : {
start = i + 1 ;
charsetState = NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED ;
continue ;
}
case ' \" ' : {
start = i + 1 ;
charsetState = NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED ;
continue ;
}
default : {
start = i ;
charsetState = NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED ;
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_SINGLE_QUOTED : {
switch ( c ) {
case ' \' ' : {
end = i ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charsetloop ) ;
2009-06-28 15:44:22 -07:00
}
default : {
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_DOUBLE_QUOTED : {
switch ( c ) {
case ' \" ' : {
end = i ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charsetloop ) ;
2009-06-28 15:44:22 -07:00
}
default : {
continue ;
}
}
}
case NS_HTML5TREE_BUILDER_CHARSET_UNQUOTED : {
switch ( c ) {
case ' \t ' :
case ' \n ' :
case ' \f ' :
case ' \r ' :
case ' ' :
case ' ; ' : {
end = i ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( charsetloop ) ;
2009-06-28 15:44:22 -07:00
}
default : {
continue ;
}
}
}
}
}
charsetloop_end : ;
2012-07-30 07:20:58 -07:00
nsString * charset = nullptr ;
2009-06-28 15:44:22 -07:00
if ( start ! = - 1 ) {
if ( end = = - 1 ) {
end = buffer . length ;
}
2009-07-15 04:30:33 -07:00
charset = nsHtml5Portability : : newStringFromBuffer ( buffer , start , end - start ) ;
2009-06-28 15:44:22 -07:00
}
2009-07-15 04:30:33 -07:00
return charset ;
2009-06-28 15:44:22 -07:00
}
void
nsHtml5TreeBuilder : : checkMetaCharset ( nsHtml5HtmlAttributes * attributes )
{
2010-12-08 04:37:19 -08:00
nsString * charset = attributes - > getValue ( nsHtml5AttributeName : : ATTR_CHARSET ) ;
if ( charset ) {
if ( tokenizer - > internalEncodingDeclaration ( charset ) ) {
requestSuspension ( ) ;
return ;
}
return ;
}
if ( ! nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " content-type " , attributes - > getValue ( nsHtml5AttributeName : : ATTR_HTTP_EQUIV ) ) ) {
return ;
}
2009-06-30 03:50:56 -07:00
nsString * content = attributes - > getValue ( nsHtml5AttributeName : : ATTR_CONTENT ) ;
2010-04-19 06:25:13 -07:00
if ( content ) {
2010-12-08 04:37:19 -08:00
nsString * extract = nsHtml5TreeBuilder : : extractCharsetFromContent ( content ) ;
if ( extract ) {
if ( tokenizer - > internalEncodingDeclaration ( extract ) ) {
requestSuspension ( ) ;
}
2009-06-28 15:44:22 -07:00
}
2010-12-08 04:37:19 -08:00
nsHtml5Portability : : releaseString ( extract ) ;
2009-06-28 15:44:22 -07:00
}
}
void
nsHtml5TreeBuilder : : endTag ( nsHtml5ElementName * elementName )
{
2010-09-15 01:37:55 -07:00
flushCharacters ( ) ;
2011-10-17 07:59:28 -07:00
needToDropLF = false ;
2012-08-22 08:56:38 -07:00
int32_t eltPos ;
int32_t group = elementName - > getGroup ( ) ;
2010-05-26 23:27:27 -07:00
nsIAtom * name = elementName - > name ;
2010-07-21 06:10:58 -07:00
for ( ; ; ) {
2010-12-09 01:27:58 -08:00
if ( isInForeign ( ) ) {
2011-11-01 04:33:11 -07:00
if ( stack [ currentPtr ] - > name ! = name ) {
2014-10-27 02:48:11 -07:00
if ( ! currentPtr ) {
errStrayEndTag ( name ) ;
} else {
errEndTagDidNotMatchCurrentOpenElement ( name , stack [ currentPtr ] - > popName ) ;
}
2011-11-01 04:33:11 -07:00
}
2010-07-21 06:10:58 -07:00
eltPos = currentPtr ;
for ( ; ; ) {
2014-10-27 02:48:11 -07:00
if ( ! eltPos ) {
MOZ_ASSERT ( fragment , " We can get this close to the root of the stack in foreign content only in the fragment case. " ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
if ( stack [ eltPos ] - > name = = name ) {
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
2010-09-09 00:30:07 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2010-07-21 06:10:58 -07:00
}
if ( stack [ - - eltPos ] - > ns = = kNameSpaceID_XHTML ) {
break ;
2010-05-26 23:27:27 -07:00
}
}
}
2010-07-21 06:10:58 -07:00
switch ( mode ) {
2013-08-12 14:46:12 -07:00
case NS_HTML5TREE_BUILDER_IN_TEMPLATE : {
2013-03-26 00:15:23 -07:00
switch ( group ) {
case NS_HTML5TREE_BUILDER_TEMPLATE : {
break ;
}
default : {
errStrayEndTag ( name ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
}
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_IN_ROW : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_TR : {
eltPos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TR ) ;
if ( ! eltPos ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errNoTableRowToClose ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_TABLE : {
eltPos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TR ) ;
if ( ! eltPos ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errNoTableRowToClose ( ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
continue ;
}
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT : {
if ( findLastInTableScope ( name ) = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
eltPos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TR ) ;
if ( ! eltPos ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errNoTableRowToClose ( ) ;
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
default :
; // fall through
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_IN_TABLE_BODY : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT : {
eltPos = findLastOrRoot ( name ) ;
if ( ! eltPos ) {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_TABLE : {
2013-03-26 00:15:23 -07:00
eltPos = findLastInTableScopeOrRootTemplateTbodyTheadTfoot ( ) ;
if ( ! eltPos | | stack [ eltPos ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
clearStackBackTo ( eltPos ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_TR : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
default :
; // fall through
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_IN_TABLE : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_TABLE : {
eltPos = findLast ( nsHtml5Atoms : : table ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
resetTheInsertionMode ( ) ;
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_TR : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
break ;
}
2011-11-01 04:33:11 -07:00
default : {
errStrayEndTag ( name ) ;
}
2010-07-21 06:10:58 -07:00
}
}
case NS_HTML5TREE_BUILDER_IN_CAPTION : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_CAPTION : {
eltPos = findLastInTableScope ( nsHtml5Atoms : : caption ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & currentPtr ! = eltPos ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_TABLE : {
2011-11-01 04:33:11 -07:00
errTableClosedWhileCaptionOpen ( ) ;
2010-07-21 06:10:58 -07:00
eltPos = findLastInTableScope ( nsHtml5Atoms : : caption ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & currentPtr ! = eltPos ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_TR : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_IN_CELL : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
eltPos = findLastInTableScope ( name ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_ROW ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_TABLE :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR : {
if ( findLastInTableScope ( name ) = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( name = = nsHtml5Atoms : : tbody | | name = = nsHtml5Atoms : : tfoot | | name = = nsHtml5Atoms : : thead | | fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
closeTheCell ( findLastInTableScopeTdTh ( ) ) ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_COL :
case NS_HTML5TREE_BUILDER_COLGROUP :
case NS_HTML5TREE_BUILDER_HTML : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
default :
; // fall through
}
}
case NS_HTML5TREE_BUILDER_FRAMESET_OK :
case NS_HTML5TREE_BUILDER_IN_BODY : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_BODY : {
if ( ! isSecondOnStackBody ( ) ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( currentPtr > = 1 ) ;
2012-10-26 06:32:10 -07:00
if ( MOZ_UNLIKELY ( mViewSource ) ) {
2012-08-22 08:56:38 -07:00
for ( int32_t i = 2 ; i < = currentPtr ; i + + ) {
2011-11-01 04:33:11 -07:00
switch ( stack [ i ] - > getGroup ( ) ) {
case NS_HTML5TREE_BUILDER_DD_OR_DT :
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_OPTGROUP :
case NS_HTML5TREE_BUILDER_OPTION :
case NS_HTML5TREE_BUILDER_P :
2014-08-18 22:33:45 -07:00
case NS_HTML5TREE_BUILDER_RB_OR_RTC :
case NS_HTML5TREE_BUILDER_RT_OR_RP :
2011-11-01 04:33:11 -07:00
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT : {
break ;
}
default : {
errEndWithUnclosedElements ( name ) ;
NS_HTML5_BREAK ( uncloseloop1 ) ;
}
}
}
uncloseloop1_end : ;
}
2010-07-21 06:10:58 -07:00
mode = NS_HTML5TREE_BUILDER_AFTER_BODY ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_HTML : {
if ( ! isSecondOnStackBody ( ) ) {
2013-03-26 00:15:23 -07:00
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2012-10-26 06:32:10 -07:00
if ( MOZ_UNLIKELY ( mViewSource ) ) {
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < = currentPtr ; i + + ) {
2011-11-01 04:33:11 -07:00
switch ( stack [ i ] - > getGroup ( ) ) {
case NS_HTML5TREE_BUILDER_DD_OR_DT :
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_P :
2014-08-18 22:33:45 -07:00
case NS_HTML5TREE_BUILDER_RB_OR_RTC :
case NS_HTML5TREE_BUILDER_RT_OR_RP :
2011-11-01 04:33:11 -07:00
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TD_OR_TH :
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_HTML : {
break ;
}
default : {
errEndWithUnclosedElements ( name ) ;
NS_HTML5_BREAK ( uncloseloop2 ) ;
}
}
}
uncloseloop2_end : ;
}
2010-07-21 06:10:58 -07:00
mode = NS_HTML5TREE_BUILDER_AFTER_BODY ;
continue ;
}
case NS_HTML5TREE_BUILDER_DIV_OR_BLOCKQUOTE_OR_CENTER_OR_MENU :
case NS_HTML5TREE_BUILDER_UL_OR_OL_OR_DL :
case NS_HTML5TREE_BUILDER_PRE_OR_LISTING :
case NS_HTML5TREE_BUILDER_FIELDSET :
case NS_HTML5TREE_BUILDER_BUTTON :
2013-01-29 04:31:45 -08:00
case NS_HTML5TREE_BUILDER_ADDRESS_OR_ARTICLE_OR_ASIDE_OR_DETAILS_OR_DIR_OR_FIGCAPTION_OR_FIGURE_OR_FOOTER_OR_HEADER_OR_HGROUP_OR_MAIN_OR_NAV_OR_SECTION_OR_SUMMARY : {
2010-07-21 06:10:58 -07:00
eltPos = findLastInScope ( name ) ;
2011-11-01 04:33:11 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errStrayEndTag ( name ) ;
} else {
2009-06-28 15:44:22 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2009-06-28 15:44:22 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_FORM : {
2014-01-31 15:03:24 -08:00
if ( ! isTemplateContents ( ) ) {
if ( ! formPointer ) {
errStrayEndTag ( name ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
formPointer = nullptr ;
eltPos = findLastInScope ( name ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errStrayEndTag ( name ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
generateImpliedEndTags ( ) ;
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
errUnclosedElements ( eltPos , name ) ;
}
removeFromStack ( eltPos ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2014-01-31 15:03:24 -08:00
} else {
eltPos = findLastInScope ( name ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errStrayEndTag ( name ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
generateImpliedEndTags ( ) ;
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
errUnclosedElements ( eltPos , name ) ;
}
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_P : {
2010-09-08 09:31:22 -07:00
eltPos = findLastInButtonScope ( nsHtml5Atoms : : p ) ;
2010-07-21 06:10:58 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2011-11-01 04:33:11 -07:00
errNoElementToCloseButEndTagSeen ( nsHtml5Atoms : : p ) ;
2010-12-09 01:27:58 -08:00
if ( isInForeign ( ) ) {
2011-11-01 04:33:11 -07:00
errHtmlStartTagInForeignContext ( name ) ;
2014-10-27 02:48:11 -07:00
while ( currentPtr > = 0 & & stack [ currentPtr ] - > ns ! = kNameSpaceID_XHTML ) {
2009-06-28 15:44:22 -07:00
pop ( ) ;
}
}
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
generateImpliedEndTagsExceptFor ( nsHtml5Atoms : : p ) ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( eltPos ! = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & eltPos ! = currentPtr ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-11-30 07:34:51 -08:00
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_LI : {
eltPos = findLastInListScope ( name ) ;
2011-11-01 04:33:11 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errNoElementToCloseButEndTagSeen ( name ) ;
} else {
2010-07-21 06:10:58 -07:00
generateImpliedEndTagsExceptFor ( name ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & eltPos ! = currentPtr ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_DD_OR_DT : {
eltPos = findLastInScope ( name ) ;
2011-11-01 04:33:11 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errNoElementToCloseButEndTagSeen ( name ) ;
} else {
2010-07-21 06:10:58 -07:00
generateImpliedEndTagsExceptFor ( name ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & eltPos ! = currentPtr ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 : {
eltPos = findLastInScopeHn ( ) ;
2011-11-01 04:33:11 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errStrayEndTag ( name ) ;
} else {
2010-07-21 06:10:58 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_OBJECT :
case NS_HTML5TREE_BUILDER_MARQUEE_OR_APPLET : {
eltPos = findLastInScope ( name ) ;
2011-11-01 04:33:11 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
errStrayEndTag ( name ) ;
} else {
2010-07-21 06:10:58 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_BR : {
2011-11-01 04:33:11 -07:00
errEndTagBr ( ) ;
2010-12-09 01:27:58 -08:00
if ( isInForeign ( ) ) {
2011-11-01 04:33:11 -07:00
errHtmlStartTagInForeignContext ( name ) ;
2014-10-27 02:48:11 -07:00
while ( currentPtr > = 0 & & stack [ currentPtr ] - > ns ! = kNameSpaceID_XHTML ) {
2010-07-21 06:10:58 -07:00
pop ( ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-07-21 06:10:58 -07:00
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:58 -08:00
appendVoidElementToCurrentMayFoster ( elementName , nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
break ;
}
2010-09-15 01:37:55 -07:00
case NS_HTML5TREE_BUILDER_AREA_OR_WBR :
2011-08-05 23:41:36 -07:00
# ifdef ENABLE_VOID_MENUITEM
case NS_HTML5TREE_BUILDER_MENUITEM :
# endif
2011-01-12 00:05:09 -08:00
case NS_HTML5TREE_BUILDER_PARAM_OR_SOURCE_OR_TRACK :
2013-06-06 01:02:30 -07:00
case NS_HTML5TREE_BUILDER_EMBED :
case NS_HTML5TREE_BUILDER_IMG :
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_IMAGE :
case NS_HTML5TREE_BUILDER_INPUT :
case NS_HTML5TREE_BUILDER_KEYGEN :
case NS_HTML5TREE_BUILDER_HR :
case NS_HTML5TREE_BUILDER_ISINDEX :
case NS_HTML5TREE_BUILDER_IFRAME :
case NS_HTML5TREE_BUILDER_NOEMBED :
case NS_HTML5TREE_BUILDER_NOFRAMES :
case NS_HTML5TREE_BUILDER_SELECT :
case NS_HTML5TREE_BUILDER_TABLE :
case NS_HTML5TREE_BUILDER_TEXTAREA : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_NOSCRIPT : {
if ( scriptingEnabled ) {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
} else {
}
}
2010-10-15 02:23:42 -07:00
case NS_HTML5TREE_BUILDER_A :
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 :
case NS_HTML5TREE_BUILDER_FONT :
case NS_HTML5TREE_BUILDER_NOBR : {
if ( adoptionAgencyEndTag ( name ) ) {
NS_HTML5_BREAK ( endtagloop ) ;
}
}
2010-07-21 06:10:58 -07:00
default : {
if ( isCurrent ( name ) ) {
pop ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
eltPos = currentPtr ;
for ( ; ; ) {
nsHtml5StackNode * node = stack [ eltPos ] ;
2013-08-12 14:46:12 -07:00
if ( node - > ns = = kNameSpaceID_XHTML & & node - > name = = name ) {
2010-07-21 06:10:58 -07:00
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( name ) ) {
2011-11-01 04:33:11 -07:00
errUnclosedElements ( eltPos , name ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
NS_HTML5_BREAK ( endtagloop ) ;
2010-12-09 01:27:58 -08:00
} else if ( node - > isSpecial ( ) ) {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-11-30 07:34:51 -08:00
}
2010-07-21 06:10:58 -07:00
eltPos - - ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
}
}
}
2012-11-09 01:04:28 -08:00
case NS_HTML5TREE_BUILDER_IN_HEAD : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HEAD : {
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_AFTER_HEAD ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_BR :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_BODY : {
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_AFTER_HEAD ;
continue ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
2013-08-12 14:46:12 -07:00
endTagTemplateInHead ( ) ;
2013-03-26 00:15:23 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2012-11-09 01:04:28 -08:00
default : {
errStrayEndTag ( name ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
}
}
case NS_HTML5TREE_BUILDER_IN_HEAD_NOSCRIPT : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_NOSCRIPT : {
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_BR : {
errStrayEndTag ( name ) ;
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
continue ;
}
default : {
errStrayEndTag ( name ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
}
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_COLGROUP : {
2013-03-26 00:15:23 -07:00
if ( ! currentPtr | | stack [ currentPtr ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errGarbageInColgroup ( ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_COL : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
2013-08-12 14:46:12 -07:00
endTagTemplateInHead ( ) ;
2013-03-26 00:15:23 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
default : {
2013-03-26 00:15:23 -07:00
if ( ! currentPtr | | stack [ currentPtr ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
MOZ_ASSERT ( fragment | | isTemplateContents ( ) ) ;
2011-11-01 04:33:11 -07:00
errGarbageInColgroup ( ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
pop ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
continue ;
2009-06-28 15:44:22 -07:00
}
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_CAPTION :
case NS_HTML5TREE_BUILDER_TABLE :
case NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT :
case NS_HTML5TREE_BUILDER_TR :
case NS_HTML5TREE_BUILDER_TD_OR_TH : {
2011-11-01 04:33:11 -07:00
errEndTagSeenWithSelectOpen ( name ) ;
2010-07-21 06:10:58 -07:00
if ( findLastInTableScope ( name ) ! = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
eltPos = findLastInTableScope ( nsHtml5Atoms : : select ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( fragment ) ;
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
resetTheInsertionMode ( ) ;
continue ;
} else {
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-11-30 07:34:51 -08:00
}
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
default :
; // fall through
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_IN_SELECT : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_OPTION : {
if ( isCurrent ( nsHtml5Atoms : : option ) ) {
pop ( ) ;
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2010-07-21 06:10:58 -07:00
} else {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_OPTGROUP : {
if ( isCurrent ( nsHtml5Atoms : : option ) & & nsHtml5Atoms : : optgroup = = stack [ currentPtr - 1 ] - > name ) {
pop ( ) ;
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
if ( isCurrent ( nsHtml5Atoms : : optgroup ) ) {
pop ( ) ;
2011-11-01 04:33:11 -07:00
} else {
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
}
NS_HTML5_BREAK ( endtagloop ) ;
}
case NS_HTML5TREE_BUILDER_SELECT : {
eltPos = findLastInTableScope ( nsHtml5Atoms : : select ) ;
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( fragment ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
resetTheInsertionMode ( ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
2013-03-26 00:15:23 -07:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
2013-08-12 14:46:12 -07:00
endTagTemplateInHead ( ) ;
2013-03-26 00:15:23 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
default : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-05-26 23:27:27 -07:00
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_AFTER_BODY : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
if ( fragment ) {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
} else {
mode = NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY ;
2010-05-26 23:27:27 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
default : {
2011-11-01 04:33:11 -07:00
errEndTagAfterBody ( ) ;
2010-07-21 06:10:58 -07:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
continue ;
}
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_IN_FRAMESET : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_FRAMESET : {
2013-08-12 14:46:12 -07:00
if ( ! currentPtr ) {
MOZ_ASSERT ( fragment ) ;
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-04-19 06:25:13 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
pop ( ) ;
if ( ( ! fragment ) & & ! isCurrent ( nsHtml5Atoms : : frameset ) ) {
mode = NS_HTML5TREE_BUILDER_AFTER_FRAMESET ;
2009-06-28 15:44:22 -07:00
}
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_AFTER_FRAMESET : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HTML : {
mode = NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET ;
NS_HTML5_BREAK ( endtagloop ) ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
}
}
}
case NS_HTML5TREE_BUILDER_INITIAL : {
2011-11-01 04:33:11 -07:00
errEndTagSeenWithoutDoctype ( ) ;
2012-07-30 07:20:58 -07:00
documentModeInternal ( QUIRKS_MODE , nullptr , nullptr , false ) ;
2010-07-21 06:10:58 -07:00
mode = NS_HTML5TREE_BUILDER_BEFORE_HTML ;
continue ;
}
case NS_HTML5TREE_BUILDER_BEFORE_HTML : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HEAD :
case NS_HTML5TREE_BUILDER_BR :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_BODY : {
appendHtmlElementToDocumentAndPush ( ) ;
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD ;
continue ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-11-30 07:34:51 -08:00
}
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_BEFORE_HEAD : {
switch ( group ) {
case NS_HTML5TREE_BUILDER_HEAD :
case NS_HTML5TREE_BUILDER_BR :
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_BODY : {
appendToCurrentNodeAndPushHeadElement ( nsHtml5HtmlAttributes : : EMPTY_ATTRIBUTES ) ;
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
continue ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_AFTER_HEAD : {
switch ( group ) {
2013-11-04 17:19:22 -08:00
case NS_HTML5TREE_BUILDER_TEMPLATE : {
endTagTemplateInHead ( ) ;
NS_HTML5_BREAK ( endtagloop ) ;
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_HTML :
case NS_HTML5TREE_BUILDER_BODY :
case NS_HTML5TREE_BUILDER_BR : {
appendToCurrentNodeAndPushBodyElement ( ) ;
mode = NS_HTML5TREE_BUILDER_FRAMESET_OK ;
continue ;
}
default : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
NS_HTML5_BREAK ( endtagloop ) ;
2009-06-28 15:44:22 -07:00
}
}
}
2010-07-21 06:10:58 -07:00
case NS_HTML5TREE_BUILDER_AFTER_AFTER_BODY : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2010-07-21 06:10:58 -07:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
continue ;
}
case NS_HTML5TREE_BUILDER_AFTER_AFTER_FRAMESET : {
2011-11-01 04:33:11 -07:00
errStrayEndTag ( name ) ;
2013-11-13 14:57:07 -08:00
NS_HTML5_BREAK ( endtagloop ) ;
2010-07-21 06:10:58 -07:00
}
case NS_HTML5TREE_BUILDER_TEXT : {
pop ( ) ;
if ( originalMode = = NS_HTML5TREE_BUILDER_AFTER_HEAD ) {
silentPop ( ) ;
}
mode = originalMode ;
NS_HTML5_BREAK ( endtagloop ) ;
}
2009-06-28 15:44:22 -07:00
}
}
2010-07-21 06:10:58 -07:00
endtagloop_end : ;
2009-06-28 15:44:22 -07:00
}
2013-03-26 00:15:23 -07:00
void
2013-08-12 14:46:12 -07:00
nsHtml5TreeBuilder : : endTagTemplateInHead ( )
2013-03-26 00:15:23 -07:00
{
2013-08-12 14:46:12 -07:00
int32_t eltPos = findLast ( nsHtml5Atoms : : template_ ) ;
2013-03-26 00:15:23 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
2013-08-12 14:46:12 -07:00
errStrayEndTag ( nsHtml5Atoms : : template_ ) ;
2013-03-26 00:15:23 -07:00
return ;
}
generateImpliedEndTags ( ) ;
2013-08-12 14:46:12 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & ! isCurrent ( nsHtml5Atoms : : template_ ) ) {
errUnclosedElements ( eltPos , nsHtml5Atoms : : template_ ) ;
2013-03-26 00:15:23 -07:00
}
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
popTemplateMode ( ) ;
resetTheInsertionMode ( ) ;
}
2012-08-22 08:56:38 -07:00
int32_t
2013-03-26 00:15:23 -07:00
nsHtml5TreeBuilder : : findLastInTableScopeOrRootTemplateTbodyTheadTfoot ( )
2009-06-28 15:44:22 -07:00
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-03-26 00:15:23 -07:00
if ( stack [ i ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT | | stack [ i ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE ) {
2009-06-28 15:44:22 -07:00
return i ;
}
}
return 0 ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findLast ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML & & stack [ i ] - > name = = name ) {
2009-06-28 15:44:22 -07:00
return i ;
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findLastInTableScope ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML ) {
if ( stack [ i ] - > name = = name ) {
return i ;
} else if ( stack [ i ] - > name = = nsHtml5Atoms : : table | | stack [ i ] - > name = = nsHtml5Atoms : : template_ ) {
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2009-06-28 15:44:22 -07:00
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2012-08-22 08:56:38 -07:00
int32_t
2010-09-08 09:31:22 -07:00
nsHtml5TreeBuilder : : findLastInButtonScope ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML ) {
if ( stack [ i ] - > name = = name ) {
return i ;
} else if ( stack [ i ] - > name = = nsHtml5Atoms : : button ) {
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
}
if ( stack [ i ] - > isScoping ( ) ) {
2010-09-08 09:31:22 -07:00
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findLastInScope ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML & & stack [ i ] - > name = = name ) {
2009-06-28 15:44:22 -07:00
return i ;
2010-12-09 01:27:57 -08:00
} else if ( stack [ i ] - > isScoping ( ) ) {
2009-06-28 15:44:22 -07:00
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-11-30 07:34:51 -08:00
nsHtml5TreeBuilder : : findLastInListScope ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML ) {
if ( stack [ i ] - > name = = name ) {
return i ;
} else if ( stack [ i ] - > name = = nsHtml5Atoms : : ul | | stack [ i ] - > name = = nsHtml5Atoms : : ol ) {
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
}
if ( stack [ i ] - > isScoping ( ) ) {
2009-11-30 07:34:51 -08:00
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findLastInScopeHn ( )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2010-12-09 01:27:57 -08:00
if ( stack [ i ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_H1_OR_H2_OR_H3_OR_H4_OR_H5_OR_H6 ) {
2009-06-28 15:44:22 -07:00
return i ;
2010-12-09 01:27:57 -08:00
} else if ( stack [ i ] - > isScoping ( ) ) {
2009-06-28 15:44:22 -07:00
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
void
nsHtml5TreeBuilder : : generateImpliedEndTagsExceptFor ( nsIAtom * name )
{
for ( ; ; ) {
nsHtml5StackNode * node = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
switch ( node - > getGroup ( ) ) {
2009-06-28 15:44:22 -07:00
case NS_HTML5TREE_BUILDER_P :
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_DD_OR_DT :
case NS_HTML5TREE_BUILDER_OPTION :
case NS_HTML5TREE_BUILDER_OPTGROUP :
2014-08-18 22:33:45 -07:00
case NS_HTML5TREE_BUILDER_RB_OR_RTC :
case NS_HTML5TREE_BUILDER_RT_OR_RP : {
2013-08-12 14:46:12 -07:00
if ( node - > ns = = kNameSpaceID_XHTML & & node - > name = = name ) {
2009-06-28 15:44:22 -07:00
return ;
}
pop ( ) ;
continue ;
}
default : {
return ;
}
}
}
}
void
nsHtml5TreeBuilder : : generateImpliedEndTags ( )
{
for ( ; ; ) {
2010-12-09 01:27:57 -08:00
switch ( stack [ currentPtr ] - > getGroup ( ) ) {
2009-06-28 15:44:22 -07:00
case NS_HTML5TREE_BUILDER_P :
case NS_HTML5TREE_BUILDER_LI :
case NS_HTML5TREE_BUILDER_DD_OR_DT :
case NS_HTML5TREE_BUILDER_OPTION :
case NS_HTML5TREE_BUILDER_OPTGROUP :
2014-08-18 22:33:45 -07:00
case NS_HTML5TREE_BUILDER_RB_OR_RTC :
case NS_HTML5TREE_BUILDER_RT_OR_RP : {
2009-06-28 15:44:22 -07:00
pop ( ) ;
continue ;
}
default : {
return ;
}
}
}
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : isSecondOnStackBody ( )
{
2010-12-09 01:27:57 -08:00
return currentPtr > = 1 & & stack [ 1 ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_BODY ;
2009-06-28 15:44:22 -07:00
}
void
2011-09-28 23:19:26 -07:00
nsHtml5TreeBuilder : : documentModeInternal ( nsHtml5DocumentMode m , nsString * publicIdentifier , nsString * systemIdentifier , bool html4SpecificAdditionalErrorChecks )
2009-06-28 15:44:22 -07:00
{
2013-06-28 20:13:23 -07:00
if ( isSrcdocDocument ) {
quirks = false ;
if ( this ) {
this - > documentMode ( STANDARDS_MODE ) ;
}
return ;
}
2009-06-28 15:44:22 -07:00
quirks = ( m = = QUIRKS_MODE ) ;
2010-04-19 06:25:13 -07:00
if ( this ) {
2009-09-18 02:21:47 -07:00
this - > documentMode ( m ) ;
2009-06-28 15:44:22 -07:00
}
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : isAlmostStandards ( nsString * publicIdentifier , nsString * systemIdentifier )
{
if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " -//w3c//dtd xhtml 1.0 transitional//en " , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " -//w3c//dtd xhtml 1.0 frameset//en " , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
if ( systemIdentifier ) {
2009-06-28 15:44:22 -07:00
if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " -//w3c//dtd html 4.01 transitional//en " , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " -//w3c//dtd html 4.01 frameset//en " , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
}
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
2011-09-28 23:19:26 -07:00
bool
nsHtml5TreeBuilder : : isQuirky ( nsIAtom * name , nsString * publicIdentifier , nsString * systemIdentifier , bool forceQuirks )
2009-06-28 15:44:22 -07:00
{
if ( forceQuirks ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
if ( name ! = nsHtml5Atoms : : html ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2010-04-19 06:25:13 -07:00
if ( publicIdentifier ) {
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < nsHtml5TreeBuilder : : QUIRKY_PUBLIC_IDS . length ; i + + ) {
2009-06-28 15:44:22 -07:00
if ( nsHtml5Portability : : lowerCaseLiteralIsPrefixOfIgnoreAsciiCaseString ( nsHtml5TreeBuilder : : QUIRKY_PUBLIC_IDS [ i ] , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
}
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 ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
}
if ( ! systemIdentifier ) {
if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " -//w3c//dtd html 4.01 transitional//en " , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
} else if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " -//w3c//dtd html 4.01 frameset//en " , publicIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
} else if ( nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd " , systemIdentifier ) ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
void
2012-08-22 08:56:38 -07:00
nsHtml5TreeBuilder : : closeTheCell ( int32_t eltPos )
2009-06-28 15:44:22 -07:00
{
generateImpliedEndTags ( ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & eltPos ! = currentPtr ) {
2011-11-01 04:33:11 -07:00
errUnclosedElementsCell ( eltPos ) ;
}
2009-06-28 15:44:22 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
clearTheListOfActiveFormattingElementsUpToTheLastMarker ( ) ;
mode = NS_HTML5TREE_BUILDER_IN_ROW ;
return ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findLastInTableScopeTdTh ( )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2009-06-28 15:44:22 -07:00
nsIAtom * name = stack [ i ] - > name ;
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML ) {
if ( nsHtml5Atoms : : td = = name | | nsHtml5Atoms : : th = = name ) {
return i ;
} else if ( name = = nsHtml5Atoms : : table | | name = = nsHtml5Atoms : : template_ ) {
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
2009-06-28 15:44:22 -07:00
}
}
return NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ;
}
void
2012-08-22 08:56:38 -07:00
nsHtml5TreeBuilder : : clearStackBackTo ( int32_t eltPos )
2009-06-28 15:44:22 -07:00
{
2013-03-26 00:15:23 -07:00
int32_t eltGroup = stack [ eltPos ] - > getGroup ( ) ;
2009-06-28 15:44:22 -07:00
while ( currentPtr > eltPos ) {
2013-08-12 14:46:12 -07:00
if ( stack [ currentPtr ] - > ns = = kNameSpaceID_XHTML & & stack [ currentPtr ] - > getGroup ( ) = = NS_HTML5TREE_BUILDER_TEMPLATE & & ( eltGroup = = NS_HTML5TREE_BUILDER_TABLE | | eltGroup = = NS_HTML5TREE_BUILDER_TBODY_OR_THEAD_OR_TFOOT | | eltGroup = = NS_HTML5TREE_BUILDER_TR | | eltGroup = = NS_HTML5TREE_BUILDER_HTML ) ) {
2013-03-26 00:15:23 -07:00
return ;
}
2009-06-28 15:44:22 -07:00
pop ( ) ;
}
}
void
nsHtml5TreeBuilder : : resetTheInsertionMode ( )
{
nsHtml5StackNode * node ;
nsIAtom * name ;
2012-08-22 08:56:38 -07:00
int32_t ns ;
for ( int32_t i = currentPtr ; i > = 0 ; i - - ) {
2009-06-28 15:44:22 -07:00
node = stack [ i ] ;
name = node - > name ;
ns = node - > ns ;
if ( ! i ) {
if ( ! ( contextNamespace = = kNameSpaceID_XHTML & & ( contextName = = nsHtml5Atoms : : td | | contextName = = nsHtml5Atoms : : th ) ) ) {
2013-11-04 17:19:22 -08:00
if ( fragment ) {
name = contextName ;
ns = contextNamespace ;
}
2009-06-28 15:44:22 -07:00
} else {
2009-12-23 00:31:48 -08:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
return ;
}
}
2013-08-12 14:46:12 -07:00
if ( nsHtml5Atoms : : select = = name ) {
2013-10-17 13:26:49 -07:00
int32_t ancestorIndex = i ;
while ( ancestorIndex > 0 ) {
nsHtml5StackNode * ancestor = stack [ ancestorIndex - - ] ;
if ( kNameSpaceID_XHTML = = ancestor - > ns ) {
if ( nsHtml5Atoms : : template_ = = ancestor - > name ) {
break ;
}
if ( nsHtml5Atoms : : table = = ancestor - > name ) {
mode = NS_HTML5TREE_BUILDER_IN_SELECT_IN_TABLE ;
return ;
}
}
}
2009-06-28 15:44:22 -07:00
mode = NS_HTML5TREE_BUILDER_IN_SELECT ;
return ;
} else if ( nsHtml5Atoms : : td = = name | | nsHtml5Atoms : : th = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_CELL ;
return ;
} else if ( nsHtml5Atoms : : tr = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_ROW ;
return ;
} else if ( nsHtml5Atoms : : tbody = = name | | nsHtml5Atoms : : thead = = name | | nsHtml5Atoms : : tfoot = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_TABLE_BODY ;
return ;
} else if ( nsHtml5Atoms : : caption = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_CAPTION ;
return ;
} else if ( nsHtml5Atoms : : colgroup = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_COLUMN_GROUP ;
return ;
} else if ( nsHtml5Atoms : : table = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_TABLE ;
return ;
2009-12-15 05:19:09 -08:00
} else if ( kNameSpaceID_XHTML ! = ns ) {
2009-12-23 00:31:48 -08:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
return ;
2013-08-12 14:46:12 -07:00
} else if ( nsHtml5Atoms : : template_ = = name ) {
MOZ_ASSERT ( templateModePtr > = 0 ) ;
mode = templateModeStack [ templateModePtr ] ;
return ;
2009-06-28 15:44:22 -07:00
} else if ( nsHtml5Atoms : : head = = name ) {
2013-03-26 00:15:23 -07:00
if ( name = = contextName ) {
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
} else {
mode = NS_HTML5TREE_BUILDER_IN_HEAD ;
}
2009-06-28 15:44:22 -07:00
return ;
} else if ( nsHtml5Atoms : : body = = name ) {
2009-12-23 00:31:48 -08:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
return ;
} else if ( nsHtml5Atoms : : frameset = = name ) {
mode = NS_HTML5TREE_BUILDER_IN_FRAMESET ;
return ;
} else if ( nsHtml5Atoms : : html = = name ) {
if ( ! headPointer ) {
mode = NS_HTML5TREE_BUILDER_BEFORE_HEAD ;
} else {
mode = NS_HTML5TREE_BUILDER_AFTER_HEAD ;
}
return ;
} else if ( ! i ) {
2009-12-23 00:31:48 -08:00
mode = framesetOk ? NS_HTML5TREE_BUILDER_FRAMESET_OK : NS_HTML5TREE_BUILDER_IN_BODY ;
2009-06-28 15:44:22 -07:00
return ;
}
}
}
void
nsHtml5TreeBuilder : : implicitlyCloseP ( )
{
2012-08-22 08:56:38 -07:00
int32_t eltPos = findLastInButtonScope ( nsHtml5Atoms : : p ) ;
2009-06-28 15:44:22 -07:00
if ( eltPos = = NS_HTML5TREE_BUILDER_NOT_FOUND_ON_STACK ) {
return ;
}
generateImpliedEndTagsExceptFor ( nsHtml5Atoms : : p ) ;
2012-10-26 06:32:10 -07:00
if ( ! ! MOZ_UNLIKELY ( mViewSource ) & & eltPos ! = currentPtr ) {
2011-11-01 04:33:11 -07:00
errUnclosedElementsImplied ( eltPos , nsHtml5Atoms : : p ) ;
}
2009-06-28 15:44:22 -07:00
while ( currentPtr > = eltPos ) {
pop ( ) ;
}
}
2011-09-28 23:19:26 -07:00
bool
2012-10-01 01:52:32 -07:00
nsHtml5TreeBuilder : : debugOnlyClearLastStackSlot ( )
2009-06-28 15:44:22 -07:00
{
2012-07-30 07:20:58 -07:00
stack [ currentPtr ] = nullptr ;
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2011-09-28 23:19:26 -07:00
bool
2012-10-01 01:52:32 -07:00
nsHtml5TreeBuilder : : debugOnlyClearLastListSlot ( )
2009-06-28 15:44:22 -07:00
{
2012-07-30 07:20:58 -07:00
listOfActiveFormattingElements [ listPtr ] = nullptr ;
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2013-03-26 00:15:23 -07:00
void
nsHtml5TreeBuilder : : pushTemplateMode ( int32_t mode )
{
templateModePtr + + ;
if ( templateModePtr = = templateModeStack . length ) {
jArray < int32_t , int32_t > newStack = jArray < int32_t , int32_t > : : newJArray ( templateModeStack . length + 64 ) ;
nsHtml5ArrayCopy : : arraycopy ( templateModeStack , newStack , templateModeStack . length ) ;
templateModeStack = newStack ;
}
templateModeStack [ templateModePtr ] = mode ;
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : push ( nsHtml5StackNode * node )
{
currentPtr + + ;
if ( currentPtr = = stack . length ) {
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > newStack = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( stack . length + 64 ) ;
2009-06-28 15:44:22 -07:00
nsHtml5ArrayCopy : : arraycopy ( stack , newStack , stack . length ) ;
stack = newStack ;
}
stack [ currentPtr ] = node ;
elementPushed ( node - > ns , node - > popName , node - > node ) ;
}
2009-12-10 16:27:48 -08:00
void
nsHtml5TreeBuilder : : silentPush ( nsHtml5StackNode * node )
{
currentPtr + + ;
if ( currentPtr = = stack . length ) {
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > newStack = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( stack . length + 64 ) ;
2009-12-10 16:27:48 -08:00
nsHtml5ArrayCopy : : arraycopy ( stack , newStack , stack . length ) ;
stack = newStack ;
}
stack [ currentPtr ] = node ;
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : append ( nsHtml5StackNode * node )
{
listPtr + + ;
if ( listPtr = = listOfActiveFormattingElements . length ) {
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > newList = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( listOfActiveFormattingElements . length + 64 ) ;
2009-06-28 15:44:22 -07:00
nsHtml5ArrayCopy : : arraycopy ( listOfActiveFormattingElements , newList , listOfActiveFormattingElements . length ) ;
listOfActiveFormattingElements = newList ;
}
listOfActiveFormattingElements [ listPtr ] = node ;
}
void
nsHtml5TreeBuilder : : clearTheListOfActiveFormattingElementsUpToTheLastMarker ( )
{
while ( listPtr > - 1 ) {
if ( ! listOfActiveFormattingElements [ listPtr ] ) {
- - listPtr ;
return ;
}
listOfActiveFormattingElements [ listPtr ] - > release ( ) ;
- - listPtr ;
}
}
void
2012-08-22 08:56:38 -07:00
nsHtml5TreeBuilder : : removeFromStack ( int32_t pos )
2009-06-28 15:44:22 -07:00
{
if ( currentPtr = = pos ) {
pop ( ) ;
} else {
stack [ pos ] - > release ( ) ;
nsHtml5ArrayCopy : : arraycopy ( stack , pos + 1 , pos , currentPtr - pos ) ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( debugOnlyClearLastStackSlot ( ) ) ;
2009-06-28 15:44:22 -07:00
currentPtr - - ;
}
}
void
nsHtml5TreeBuilder : : removeFromStack ( nsHtml5StackNode * node )
{
if ( stack [ currentPtr ] = = node ) {
pop ( ) ;
} else {
2012-08-22 08:56:38 -07:00
int32_t pos = currentPtr - 1 ;
2009-06-28 15:44:22 -07:00
while ( pos > = 0 & & stack [ pos ] ! = node ) {
pos - - ;
}
if ( pos = = - 1 ) {
return ;
}
node - > release ( ) ;
nsHtml5ArrayCopy : : arraycopy ( stack , pos + 1 , pos , currentPtr - pos ) ;
currentPtr - - ;
}
}
void
2012-08-22 08:56:38 -07:00
nsHtml5TreeBuilder : : removeFromListOfActiveFormattingElements ( int32_t pos )
2009-06-28 15:44:22 -07:00
{
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( ! ! listOfActiveFormattingElements [ pos ] ) ;
2009-06-28 15:44:22 -07:00
listOfActiveFormattingElements [ pos ] - > release ( ) ;
if ( pos = = listPtr ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( debugOnlyClearLastListSlot ( ) ) ;
2009-06-28 15:44:22 -07:00
listPtr - - ;
return ;
}
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( pos < listPtr ) ;
2009-06-28 15:44:22 -07:00
nsHtml5ArrayCopy : : arraycopy ( listOfActiveFormattingElements , pos + 1 , pos , listPtr - pos ) ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( debugOnlyClearLastListSlot ( ) ) ;
2009-06-28 15:44:22 -07:00
listPtr - - ;
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : adoptionAgencyEndTag ( nsIAtom * name )
{
2014-03-07 15:48:19 -08:00
if ( stack [ currentPtr ] - > ns = = kNameSpaceID_XHTML & & stack [ currentPtr ] - > name = = name & & findInListOfActiveFormattingElements ( stack [ currentPtr ] ) = = - 1 ) {
pop ( ) ;
return true ;
}
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < 8 ; + + i ) {
int32_t formattingEltListPos = listPtr ;
2009-06-28 15:44:22 -07:00
while ( formattingEltListPos > - 1 ) {
nsHtml5StackNode * listNode = listOfActiveFormattingElements [ formattingEltListPos ] ;
if ( ! listNode ) {
formattingEltListPos = - 1 ;
break ;
} else if ( listNode - > name = = name ) {
break ;
}
formattingEltListPos - - ;
}
if ( formattingEltListPos = = - 1 ) {
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
nsHtml5StackNode * formattingElt = listOfActiveFormattingElements [ formattingEltListPos ] ;
2012-08-22 08:56:38 -07:00
int32_t formattingEltStackPos = currentPtr ;
2011-09-28 23:19:26 -07:00
bool inScope = true ;
2009-06-28 15:44:22 -07:00
while ( formattingEltStackPos > - 1 ) {
nsHtml5StackNode * node = stack [ formattingEltStackPos ] ;
if ( node = = formattingElt ) {
break ;
2010-12-09 01:27:57 -08:00
} else if ( node - > isScoping ( ) ) {
2011-10-17 07:59:28 -07:00
inScope = false ;
2009-06-28 15:44:22 -07:00
}
formattingEltStackPos - - ;
}
if ( formattingEltStackPos = = - 1 ) {
2011-11-01 04:33:11 -07:00
errNoElementToCloseButEndTagSeen ( name ) ;
2009-06-28 15:44:22 -07:00
removeFromListOfActiveFormattingElements ( formattingEltListPos ) ;
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
if ( ! inScope ) {
2011-11-01 04:33:11 -07:00
errNoElementToCloseButEndTagSeen ( name ) ;
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2011-11-01 04:33:11 -07:00
if ( formattingEltStackPos ! = currentPtr ) {
errEndTagViolatesNestingRules ( name ) ;
}
2012-08-22 08:56:38 -07:00
int32_t furthestBlockPos = formattingEltStackPos + 1 ;
2009-06-28 15:44:22 -07:00
while ( furthestBlockPos < = currentPtr ) {
nsHtml5StackNode * node = stack [ furthestBlockPos ] ;
2010-12-09 01:27:58 -08:00
if ( node - > isSpecial ( ) ) {
2009-06-28 15:44:22 -07:00
break ;
}
furthestBlockPos + + ;
}
if ( furthestBlockPos > currentPtr ) {
while ( currentPtr > = formattingEltStackPos ) {
pop ( ) ;
}
removeFromListOfActiveFormattingElements ( formattingEltListPos ) ;
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
nsHtml5StackNode * commonAncestor = stack [ formattingEltStackPos - 1 ] ;
nsHtml5StackNode * furthestBlock = stack [ furthestBlockPos ] ;
2012-08-22 08:56:38 -07:00
int32_t bookmark = formattingEltListPos ;
int32_t nodePos = furthestBlockPos ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * lastNode = furthestBlock ;
2014-03-04 18:06:15 -08:00
int32_t j = 0 ;
for ( ; ; ) {
+ + j ;
2009-06-28 15:44:22 -07:00
nodePos - - ;
2014-03-04 18:06:15 -08:00
if ( nodePos = = formattingEltStackPos ) {
break ;
}
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * node = stack [ nodePos ] ;
2012-08-22 08:56:38 -07:00
int32_t nodeListPos = findInListOfActiveFormattingElements ( node ) ;
2014-03-04 18:06:15 -08:00
if ( j > 3 & & nodeListPos ! = - 1 ) {
removeFromListOfActiveFormattingElements ( nodeListPos ) ;
2014-03-17 17:34:47 -07:00
if ( nodeListPos < = formattingEltListPos ) {
formattingEltListPos - - ;
}
if ( nodeListPos < = bookmark ) {
bookmark - - ;
}
2014-03-04 18:06:15 -08:00
nodeListPos = - 1 ;
}
2009-06-28 15:44:22 -07:00
if ( nodeListPos = = - 1 ) {
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( formattingEltStackPos < nodePos ) ;
MOZ_ASSERT ( bookmark < nodePos ) ;
MOZ_ASSERT ( furthestBlockPos > nodePos ) ;
2009-06-28 15:44:22 -07:00
removeFromStack ( nodePos ) ;
furthestBlockPos - - ;
continue ;
}
if ( nodePos = = furthestBlockPos ) {
bookmark = nodeListPos + 1 ;
}
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( node = = listOfActiveFormattingElements [ nodeListPos ] ) ;
MOZ_ASSERT ( node = = stack [ nodePos ] ) ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * clone = createElement ( kNameSpaceID_XHTML , node - > name , node - > attributes - > cloneAttributes ( nullptr ) , commonAncestor - > node ) ;
2010-12-09 01:27:57 -08:00
nsHtml5StackNode * newNode = new nsHtml5StackNode ( node - > getFlags ( ) , node - > ns , node - > name , clone , node - > popName , node - > attributes ) ;
2009-09-21 00:00:10 -07:00
node - > dropAttributes ( ) ;
2009-06-28 15:44:22 -07:00
stack [ nodePos ] = newNode ;
newNode - > retain ( ) ;
listOfActiveFormattingElements [ nodeListPos ] = newNode ;
node - > release ( ) ;
node - > release ( ) ;
node = newNode ;
detachFromParent ( lastNode - > node ) ;
appendElement ( lastNode - > node , node - > node ) ;
lastNode = node ;
}
2010-12-09 01:27:57 -08:00
if ( commonAncestor - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
detachFromParent ( lastNode - > node ) ;
insertIntoFosterParent ( lastNode - > node ) ;
} else {
detachFromParent ( lastNode - > node ) ;
appendElement ( lastNode - > node , commonAncestor - > node ) ;
}
2014-11-09 22:50:18 -08:00
nsIContentHandle * clone = createElement ( kNameSpaceID_XHTML , formattingElt - > name , formattingElt - > attributes - > cloneAttributes ( nullptr ) , furthestBlock - > node ) ;
2010-12-09 01:27:57 -08:00
nsHtml5StackNode * formattingClone = new nsHtml5StackNode ( formattingElt - > getFlags ( ) , formattingElt - > ns , formattingElt - > name , clone , formattingElt - > popName , formattingElt - > attributes ) ;
2009-09-21 00:00:10 -07:00
formattingElt - > dropAttributes ( ) ;
2009-06-28 15:44:22 -07:00
appendChildrenToNewParent ( furthestBlock - > node , clone ) ;
appendElement ( clone , furthestBlock - > node ) ;
removeFromListOfActiveFormattingElements ( formattingEltListPos ) ;
insertIntoListOfActiveFormattingElements ( formattingClone , bookmark ) ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( formattingEltStackPos < furthestBlockPos ) ;
2009-06-28 15:44:22 -07:00
removeFromStack ( formattingEltStackPos ) ;
insertIntoStack ( formattingClone , furthestBlockPos ) ;
}
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
void
2012-08-22 08:56:38 -07:00
nsHtml5TreeBuilder : : insertIntoStack ( nsHtml5StackNode * node , int32_t position )
2009-06-28 15:44:22 -07:00
{
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( currentPtr + 1 < stack . length ) ;
MOZ_ASSERT ( position < = currentPtr + 1 ) ;
2009-06-28 15:44:22 -07:00
if ( position = = currentPtr + 1 ) {
push ( node ) ;
} else {
nsHtml5ArrayCopy : : arraycopy ( stack , position , position + 1 , ( currentPtr - position ) + 1 ) ;
currentPtr + + ;
stack [ position ] = node ;
}
}
void
2012-08-22 08:56:38 -07:00
nsHtml5TreeBuilder : : insertIntoListOfActiveFormattingElements ( nsHtml5StackNode * formattingClone , int32_t bookmark )
2009-06-28 15:44:22 -07:00
{
formattingClone - > retain ( ) ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( listPtr + 1 < listOfActiveFormattingElements . length ) ;
2009-06-28 15:44:22 -07:00
if ( bookmark < = listPtr ) {
nsHtml5ArrayCopy : : arraycopy ( listOfActiveFormattingElements , bookmark , bookmark + 1 , ( listPtr - bookmark ) + 1 ) ;
}
listPtr + + ;
listOfActiveFormattingElements [ bookmark ] = formattingClone ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findInListOfActiveFormattingElements ( nsHtml5StackNode * node )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = listPtr ; i > = 0 ; i - - ) {
2009-06-28 15:44:22 -07:00
if ( node = = listOfActiveFormattingElements [ i ] ) {
return i ;
}
}
return - 1 ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findInListOfActiveFormattingElementsContainsBetweenEndAndLastMarker ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = listPtr ; i > = 0 ; i - - ) {
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * node = listOfActiveFormattingElements [ i ] ;
if ( ! node ) {
return - 1 ;
} else if ( node - > name = = name ) {
return i ;
}
}
return - 1 ;
}
2010-10-15 02:23:42 -07:00
void
nsHtml5TreeBuilder : : maybeForgetEarlierDuplicateFormattingElement ( nsIAtom * name , nsHtml5HtmlAttributes * attributes )
{
2012-08-22 08:56:38 -07:00
int32_t candidate = - 1 ;
int32_t count = 0 ;
for ( int32_t i = listPtr ; i > = 0 ; i - - ) {
2010-10-15 02:23:42 -07:00
nsHtml5StackNode * node = listOfActiveFormattingElements [ i ] ;
if ( ! node ) {
break ;
}
if ( node - > name = = name & & node - > attributes - > equalsAnother ( attributes ) ) {
candidate = i ;
+ + count ;
}
}
if ( count > = 3 ) {
removeFromListOfActiveFormattingElements ( candidate ) ;
}
}
2012-08-22 08:56:38 -07:00
int32_t
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : findLastOrRoot ( nsIAtom * name )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2013-08-12 14:46:12 -07:00
if ( stack [ i ] - > ns = = kNameSpaceID_XHTML & & stack [ i ] - > name = = name ) {
2009-06-28 15:44:22 -07:00
return i ;
}
}
return 0 ;
}
2012-08-22 08:56:38 -07:00
int32_t
nsHtml5TreeBuilder : : findLastOrRoot ( int32_t group )
2009-06-28 15:44:22 -07:00
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > 0 ; i - - ) {
2010-12-09 01:27:57 -08:00
if ( stack [ i ] - > getGroup ( ) = = group ) {
2009-06-28 15:44:22 -07:00
return i ;
}
}
return 0 ;
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : addAttributesToBody ( nsHtml5HtmlAttributes * attributes )
{
if ( currentPtr > = 1 ) {
nsHtml5StackNode * body = stack [ 1 ] ;
2010-12-09 01:27:57 -08:00
if ( body - > getGroup ( ) = = NS_HTML5TREE_BUILDER_BODY ) {
2009-06-28 15:44:22 -07:00
addAttributesToElement ( body - > node , attributes ) ;
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
}
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
void
nsHtml5TreeBuilder : : addAttributesToHtml ( nsHtml5HtmlAttributes * attributes )
{
addAttributesToElement ( stack [ 0 ] - > node , attributes ) ;
}
void
nsHtml5TreeBuilder : : pushHeadPointerOntoStack ( )
{
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( ! ! headPointer ) ;
MOZ_ASSERT ( mode = = NS_HTML5TREE_BUILDER_AFTER_HEAD ) ;
2009-12-10 16:27:48 -08:00
2010-12-09 01:27:58 -08:00
silentPush ( new nsHtml5StackNode ( nsHtml5ElementName : : ELT_HEAD , headPointer ) ) ;
2009-06-28 15:44:22 -07:00
}
void
nsHtml5TreeBuilder : : reconstructTheActiveFormattingElements ( )
{
if ( listPtr = = - 1 ) {
return ;
}
nsHtml5StackNode * mostRecent = listOfActiveFormattingElements [ listPtr ] ;
if ( ! mostRecent | | isInStack ( mostRecent ) ) {
return ;
}
2012-08-22 08:56:38 -07:00
int32_t entryPos = listPtr ;
2009-06-28 15:44:22 -07:00
for ( ; ; ) {
entryPos - - ;
if ( entryPos = = - 1 ) {
break ;
}
if ( ! listOfActiveFormattingElements [ entryPos ] ) {
break ;
}
if ( isInStack ( listOfActiveFormattingElements [ entryPos ] ) ) {
break ;
}
}
while ( entryPos < listPtr ) {
entryPos + + ;
nsHtml5StackNode * entry = listOfActiveFormattingElements [ entryPos ] ;
nsHtml5StackNode * currentNode = stack [ currentPtr ] ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * clone ;
2010-12-09 01:27:57 -08:00
if ( currentNode - > isFosterParenting ( ) ) {
2014-11-09 22:50:18 -08:00
clone = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , entry - > name , entry - > attributes - > cloneAttributes ( nullptr ) ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
clone = createElement ( kNameSpaceID_XHTML , entry - > name , entry - > attributes - > cloneAttributes ( nullptr ) , currentNode - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( clone , currentNode - > node ) ;
}
2014-11-09 22:50:18 -08:00
nsHtml5StackNode * entryClone = new nsHtml5StackNode ( entry - > getFlags ( ) , entry - > ns , entry - > name , clone , entry - > popName , entry - > attributes ) ;
entry - > dropAttributes ( ) ;
2009-06-28 15:44:22 -07:00
push ( entryClone ) ;
listOfActiveFormattingElements [ entryPos ] = entryClone ;
entry - > release ( ) ;
entryClone - > retain ( ) ;
}
}
void
2014-03-05 11:38:49 -08:00
nsHtml5TreeBuilder : : insertIntoFosterParent ( nsIContentHandle * child )
2009-06-28 15:44:22 -07:00
{
2013-03-26 00:15:23 -07:00
int32_t tablePos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ;
int32_t templatePos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TEMPLATE ) ;
if ( templatePos > = tablePos ) {
appendElement ( child , stack [ templatePos ] - > node ) ;
2009-06-28 15:44:22 -07:00
return ;
}
2013-03-26 00:15:23 -07:00
nsHtml5StackNode * node = stack [ tablePos ] ;
insertFosterParentedChild ( child , node - > node , stack [ tablePos - 1 ] - > node ) ;
2009-06-28 15:44:22 -07:00
}
2014-11-09 22:50:18 -08:00
nsIContentHandle *
nsHtml5TreeBuilder : : createAndInsertFosterParentedElement ( int32_t ns , nsIAtom * name , nsHtml5HtmlAttributes * attributes )
{
return createAndInsertFosterParentedElement ( ns , name , attributes , nullptr ) ;
}
nsIContentHandle *
nsHtml5TreeBuilder : : createAndInsertFosterParentedElement ( int32_t ns , nsIAtom * name , nsHtml5HtmlAttributes * attributes , nsIContentHandle * form )
{
int32_t tablePos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ;
int32_t templatePos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TEMPLATE ) ;
if ( templatePos > = tablePos ) {
nsIContentHandle * child = createElement ( ns , name , attributes , form , stack [ templatePos ] - > node ) ;
appendElement ( child , stack [ templatePos ] - > node ) ;
return child ;
}
nsHtml5StackNode * node = stack [ tablePos ] ;
return createAndInsertFosterParentedElement ( ns , name , attributes , form , node - > node , stack [ tablePos - 1 ] - > node ) ;
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : isInStack ( nsHtml5StackNode * node )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = currentPtr ; i > = 0 ; i - - ) {
2009-06-28 15:44:22 -07:00
if ( stack [ i ] = = node ) {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
}
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
2013-03-26 00:15:23 -07:00
void
nsHtml5TreeBuilder : : popTemplateMode ( )
{
templateModePtr - - ;
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : pop ( )
{
nsHtml5StackNode * node = stack [ currentPtr ] ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( debugOnlyClearLastStackSlot ( ) ) ;
2009-06-28 15:44:22 -07:00
currentPtr - - ;
elementPopped ( node - > ns , node - > popName , node - > node ) ;
node - > release ( ) ;
}
2009-12-10 16:27:48 -08:00
void
nsHtml5TreeBuilder : : silentPop ( )
{
nsHtml5StackNode * node = stack [ currentPtr ] ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( debugOnlyClearLastStackSlot ( ) ) ;
2009-12-10 16:27:48 -08:00
currentPtr - - ;
node - > release ( ) ;
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : popOnEof ( )
{
nsHtml5StackNode * node = stack [ currentPtr ] ;
2012-10-01 01:52:32 -07:00
MOZ_ASSERT ( debugOnlyClearLastStackSlot ( ) ) ;
2009-06-28 15:44:22 -07:00
currentPtr - - ;
markMalformedIfScript ( node - > node ) ;
2009-09-21 06:18:20 -07:00
elementPopped ( node - > ns , node - > popName , node - > node ) ;
2009-06-28 15:44:22 -07:00
node - > release ( ) ;
}
void
nsHtml5TreeBuilder : : appendHtmlElementToDocumentAndPush ( nsHtml5HtmlAttributes * attributes )
{
2014-03-05 11:38:49 -08:00
nsIContentHandle * elt = createHtmlElementSetAsRoot ( attributes ) ;
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( nsHtml5ElementName : : ELT_HTML , elt ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
nsHtml5TreeBuilder : : appendHtmlElementToDocumentAndPush ( )
{
appendHtmlElementToDocumentAndPush ( tokenizer - > emptyAttributes ( ) ) ;
}
void
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushHeadElement ( nsHtml5HtmlAttributes * attributes )
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * currentNode = stack [ currentPtr ] - > node ;
nsIContentHandle * elt = createElement ( kNameSpaceID_XHTML , nsHtml5Atoms : : head , attributes , currentNode ) ;
appendElement ( elt , currentNode ) ;
2009-06-28 15:44:22 -07:00
headPointer = elt ;
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( nsHtml5ElementName : : ELT_HEAD , elt ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushBodyElement ( nsHtml5HtmlAttributes * attributes )
{
2010-12-09 01:27:58 -08:00
appendToCurrentNodeAndPushElement ( nsHtml5ElementName : : ELT_BODY , attributes ) ;
2009-06-28 15:44:22 -07:00
}
void
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushBodyElement ( )
{
appendToCurrentNodeAndPushBodyElement ( tokenizer - > emptyAttributes ( ) ) ;
}
void
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushFormElementMayFoster ( nsHtml5HtmlAttributes * attributes )
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , nsHtml5Atoms : : form , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_XHTML , nsHtml5Atoms : : form , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2014-11-09 22:50:18 -08:00
if ( ! isTemplateContents ( ) ) {
formPointer = elt ;
}
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( nsHtml5ElementName : : ELT_FORM , elt ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushFormattingElementMayFoster ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
2014-03-05 11:38:50 -08:00
nsHtml5HtmlAttributes * clone = attributes - > cloneAttributes ( nullptr ) ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , elementName - > name , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_XHTML , elementName - > name , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2014-03-05 11:38:50 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elt , clone ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
append ( node ) ;
node - > retain ( ) ;
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushElement ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * currentNode = stack [ currentPtr ] - > node ;
nsIContentHandle * elt = createElement ( kNameSpaceID_XHTML , elementName - > name , attributes , currentNode ) ;
appendElement ( elt , currentNode ) ;
2013-03-26 00:15:23 -07:00
if ( nsHtml5ElementName : : ELT_TEMPLATE = = elementName ) {
elt = getDocumentFragmentForTemplate ( elt ) ;
}
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elt ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushElementMayFoster ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
nsIAtom * popName = elementName - > name ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , popName , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_XHTML , popName , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elt , popName ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushElementMayFosterMathML ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
nsIAtom * popName = elementName - > name ;
2014-03-05 11:38:50 -08:00
bool markAsHtmlIntegrationPoint = false ;
if ( nsHtml5ElementName : : ELT_ANNOTATION_XML = = elementName & & annotationXmlEncodingPermitsHtml ( attributes ) ) {
markAsHtmlIntegrationPoint = true ;
}
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_MathML , popName , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_MathML , popName , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elt , popName , markAsHtmlIntegrationPoint ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
2011-09-28 23:19:26 -07:00
bool
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : annotationXmlEncodingPermitsHtml ( nsHtml5HtmlAttributes * attributes )
{
nsString * encoding = attributes - > getValue ( nsHtml5AttributeName : : ATTR_ENCODING ) ;
if ( ! encoding ) {
2011-10-17 07:59:28 -07:00
return false ;
2010-12-09 01:27:58 -08:00
}
return nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " application/xhtml+xml " , encoding ) | | nsHtml5Portability : : lowerCaseLiteralEqualsIgnoreAsciiCaseString ( " text/html " , encoding ) ;
}
2009-06-28 15:44:22 -07:00
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushElementMayFosterSVG ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
nsIAtom * popName = elementName - > camelCaseName ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_SVG , popName , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_SVG , popName , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , popName , elt ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
2014-03-05 11:38:49 -08:00
nsHtml5TreeBuilder : : appendToCurrentNodeAndPushElementMayFoster ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes , nsIContentHandle * form )
2009-06-28 15:44:22 -07:00
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
nsIContentHandle * formOwner = ! form | | fragment | | isTemplateContents ( ) ? nullptr : form ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , elementName - > name , attributes , formOwner ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_XHTML , elementName - > name , attributes , formOwner , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * node = new nsHtml5StackNode ( elementName , elt ) ;
2009-06-28 15:44:22 -07:00
push ( node ) ;
}
void
2014-03-05 11:38:49 -08:00
nsHtml5TreeBuilder : : appendVoidElementToCurrentMayFoster ( nsIAtom * name , nsHtml5HtmlAttributes * attributes , nsIContentHandle * form )
2009-06-28 15:44:22 -07:00
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
nsIContentHandle * formOwner = ! form | | fragment | | isTemplateContents ( ) ? nullptr : form ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , name , attributes , formOwner ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_XHTML , name , attributes , formOwner , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
elementPushed ( kNameSpaceID_XHTML , name , elt ) ;
elementPopped ( kNameSpaceID_XHTML , name , elt ) ;
2009-06-28 15:44:22 -07:00
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendVoidElementToCurrentMayFoster ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
nsIAtom * popName = elementName - > name ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_XHTML , popName , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_XHTML , popName , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
elementPushed ( kNameSpaceID_XHTML , popName , elt ) ;
elementPopped ( kNameSpaceID_XHTML , popName , elt ) ;
2009-06-28 15:44:22 -07:00
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendVoidElementToCurrentMayFosterSVG ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
nsIAtom * popName = elementName - > camelCaseName ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
2010-12-09 01:27:57 -08:00
if ( current - > isFosterParenting ( ) ) {
2009-06-28 15:44:22 -07:00
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_SVG , popName , attributes ) ;
2009-06-28 15:44:22 -07:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_SVG , popName , attributes , current - > node ) ;
2009-06-28 15:44:22 -07:00
appendElement ( elt , current - > node ) ;
}
2010-12-09 01:27:58 -08:00
elementPushed ( kNameSpaceID_SVG , popName , elt ) ;
elementPopped ( kNameSpaceID_SVG , popName , elt ) ;
2009-06-28 15:44:22 -07:00
}
void
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : appendVoidElementToCurrentMayFosterMathML ( nsHtml5ElementName * elementName , nsHtml5HtmlAttributes * attributes )
2009-06-28 15:44:22 -07:00
{
2010-12-09 01:27:58 -08:00
nsIAtom * popName = elementName - > name ;
2014-11-09 22:50:18 -08:00
nsIContentHandle * elt ;
2010-12-09 01:27:58 -08:00
nsHtml5StackNode * current = stack [ currentPtr ] ;
if ( current - > isFosterParenting ( ) ) {
2014-11-09 22:50:18 -08:00
elt = createAndInsertFosterParentedElement ( kNameSpaceID_MathML , popName , attributes ) ;
2010-12-09 01:27:58 -08:00
} else {
2014-11-09 22:50:18 -08:00
elt = createElement ( kNameSpaceID_MathML , popName , attributes , current - > node ) ;
2010-12-09 01:27:58 -08:00
appendElement ( elt , current - > node ) ;
}
elementPushed ( kNameSpaceID_MathML , popName , elt ) ;
elementPopped ( kNameSpaceID_MathML , popName , elt ) ;
}
void
2014-03-05 11:38:49 -08:00
nsHtml5TreeBuilder : : appendVoidElementToCurrent ( nsIAtom * name , nsHtml5HtmlAttributes * attributes , nsIContentHandle * form )
2010-12-09 01:27:58 -08:00
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * currentNode = stack [ currentPtr ] - > node ;
nsIContentHandle * elt = createElement ( kNameSpaceID_XHTML , name , attributes , ! form | | fragment | | isTemplateContents ( ) ? nullptr : form , currentNode ) ;
appendElement ( elt , currentNode ) ;
2010-12-09 01:27:58 -08:00
elementPushed ( kNameSpaceID_XHTML , name , elt ) ;
elementPopped ( kNameSpaceID_XHTML , name , elt ) ;
2009-11-30 07:34:51 -08:00
}
void
2009-12-16 06:07:06 -08:00
nsHtml5TreeBuilder : : appendVoidFormToCurrent ( nsHtml5HtmlAttributes * attributes )
2009-11-30 07:34:51 -08:00
{
2014-11-09 22:50:18 -08:00
nsIContentHandle * currentNode = stack [ currentPtr ] - > node ;
nsIContentHandle * elt = createElement ( kNameSpaceID_XHTML , nsHtml5Atoms : : form , attributes , currentNode ) ;
2009-12-16 06:07:06 -08:00
formPointer = elt ;
2014-11-09 22:50:18 -08:00
appendElement ( elt , currentNode ) ;
2009-12-16 06:07:06 -08:00
elementPushed ( kNameSpaceID_XHTML , nsHtml5Atoms : : form , elt ) ;
elementPopped ( kNameSpaceID_XHTML , nsHtml5Atoms : : form , elt ) ;
2009-06-28 15:44:22 -07:00
}
void
nsHtml5TreeBuilder : : requestSuspension ( )
{
tokenizer - > requestSuspension ( ) ;
}
2014-11-09 22:50:18 -08:00
; bool
2010-12-09 01:27:58 -08:00
nsHtml5TreeBuilder : : isInForeign ( )
2010-09-15 01:37:55 -07:00
{
2010-12-09 01:27:58 -08:00
return currentPtr > = 0 & & stack [ currentPtr ] - > ns ! = kNameSpaceID_XHTML ;
2010-09-15 01:37:55 -07:00
}
2011-09-28 23:19:26 -07:00
bool
2012-01-02 06:18:29 -08:00
nsHtml5TreeBuilder : : isInForeignButNotHtmlOrMathTextIntegrationPoint ( )
2011-04-07 23:07:28 -07:00
{
2012-01-02 06:18:29 -08:00
if ( currentPtr < 0 ) {
return false ;
}
return ! isSpecialParentInForeign ( stack [ currentPtr ] ) ;
2011-04-07 23:07:28 -07:00
}
2009-06-28 15:44:22 -07:00
void
2014-03-05 11:38:49 -08:00
nsHtml5TreeBuilder : : setFragmentContext ( nsIAtom * context , int32_t ns , nsIContentHandle * node , bool quirks )
2009-06-28 15:44:22 -07:00
{
this - > contextName = context ;
this - > contextNamespace = ns ;
this - > contextNode = node ;
this - > fragment = ( ! ! contextName ) ;
this - > quirks = quirks ;
}
2014-03-05 11:38:49 -08:00
nsIContentHandle *
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : currentNode ( )
{
return stack [ currentPtr ] - > node ;
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : isScriptingEnabled ( )
{
return scriptingEnabled ;
}
void
2011-09-28 23:19:26 -07:00
nsHtml5TreeBuilder : : setScriptingEnabled ( bool scriptingEnabled )
2009-06-28 15:44:22 -07:00
{
this - > scriptingEnabled = scriptingEnabled ;
}
2013-06-28 20:13:23 -07:00
void
nsHtml5TreeBuilder : : setIsSrcdocDocument ( bool isSrcdocDocument )
{
this - > isSrcdocDocument = isSrcdocDocument ;
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : flushCharacters ( )
{
if ( charBufferLen > 0 ) {
2010-09-15 01:37:55 -07:00
if ( ( mode = = NS_HTML5TREE_BUILDER_IN_TABLE | | mode = = NS_HTML5TREE_BUILDER_IN_TABLE_BODY | | mode = = NS_HTML5TREE_BUILDER_IN_ROW ) & & charBufferContainsNonWhitespace ( ) ) {
2011-11-01 04:33:11 -07:00
errNonSpaceInTable ( ) ;
2010-09-15 01:37:55 -07:00
reconstructTheActiveFormattingElements ( ) ;
2010-12-09 01:27:57 -08:00
if ( ! stack [ currentPtr ] - > isFosterParenting ( ) ) {
2010-09-15 01:37:55 -07:00
appendCharacters ( currentNode ( ) , charBuffer , 0 , charBufferLen ) ;
charBufferLen = 0 ;
return ;
}
2013-11-10 22:45:43 -08:00
int32_t tablePos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TABLE ) ;
int32_t templatePos = findLastOrRoot ( NS_HTML5TREE_BUILDER_TEMPLATE ) ;
if ( templatePos > = tablePos ) {
appendCharacters ( stack [ templatePos ] - > node , charBuffer , 0 , charBufferLen ) ;
2009-06-28 15:44:22 -07:00
charBufferLen = 0 ;
return ;
}
2013-11-10 22:45:43 -08:00
nsHtml5StackNode * tableElt = stack [ tablePos ] ;
insertFosterParentedCharacters ( charBuffer , 0 , charBufferLen , tableElt - > node , stack [ tablePos - 1 ] - > node ) ;
2009-06-28 15:44:22 -07:00
charBufferLen = 0 ;
return ;
}
appendCharacters ( currentNode ( ) , charBuffer , 0 , charBufferLen ) ;
charBufferLen = 0 ;
}
}
2011-09-28 23:19:26 -07:00
bool
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : charBufferContainsNonWhitespace ( )
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < charBufferLen ; i + + ) {
2009-06-28 15:44:22 -07:00
switch ( charBuffer [ i ] ) {
case ' ' :
case ' \t ' :
case ' \n ' :
2010-03-09 05:13:48 -08:00
case ' \r ' :
2009-06-28 15:44:22 -07:00
case ' \f ' : {
continue ;
}
default : {
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
}
}
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
2009-09-21 06:18:20 -07:00
nsAHtml5TreeBuilderState *
2009-06-28 15:44:22 -07:00
nsHtml5TreeBuilder : : newSnapshot ( )
{
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > listCopy = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( listPtr + 1 ) ;
for ( int32_t i = 0 ; i < listCopy . length ; i + + ) {
2009-06-28 15:44:22 -07:00
nsHtml5StackNode * node = listOfActiveFormattingElements [ i ] ;
2010-04-19 06:25:13 -07:00
if ( node ) {
2012-07-30 07:20:58 -07:00
nsHtml5StackNode * newNode = new nsHtml5StackNode ( node - > getFlags ( ) , node - > ns , node - > name , node - > node , node - > popName , node - > attributes - > cloneAttributes ( nullptr ) ) ;
2009-09-21 06:18:20 -07:00
listCopy [ i ] = newNode ;
} else {
2012-07-30 07:20:58 -07:00
listCopy [ i ] = nullptr ;
2009-06-28 15:44:22 -07:00
}
}
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > stackCopy = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( currentPtr + 1 ) ;
for ( int32_t i = 0 ; i < stackCopy . length ; i + + ) {
2009-09-21 06:18:20 -07:00
nsHtml5StackNode * node = stack [ i ] ;
2012-08-22 08:56:38 -07:00
int32_t listIndex = findInListOfActiveFormattingElements ( node ) ;
2009-09-21 06:18:20 -07:00
if ( listIndex = = - 1 ) {
2012-07-30 07:20:58 -07:00
nsHtml5StackNode * newNode = new nsHtml5StackNode ( node - > getFlags ( ) , node - > ns , node - > name , node - > node , node - > popName , nullptr ) ;
2009-09-21 06:18:20 -07:00
stackCopy [ i ] = newNode ;
} else {
stackCopy [ i ] = listCopy [ listIndex ] ;
stackCopy [ i ] - > retain ( ) ;
}
}
2013-08-12 14:46:12 -07:00
jArray < int32_t , int32_t > templateModeStackCopy = jArray < int32_t , int32_t > : : newJArray ( templateModePtr + 1 ) ;
nsHtml5ArrayCopy : : arraycopy ( templateModeStack , templateModeStackCopy , templateModeStackCopy . length ) ;
return new nsHtml5StateSnapshot ( stackCopy , listCopy , templateModeStackCopy , formPointer , headPointer , deepTreeSurrogateParent , mode , originalMode , framesetOk , needToDropLF , quirks ) ;
2009-06-28 15:44:22 -07:00
}
2011-09-28 23:19:26 -07:00
bool
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : snapshotMatches ( nsAHtml5TreeBuilderState * snapshot )
2009-06-28 15:44:22 -07:00
{
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > stackCopy = snapshot - > getStack ( ) ;
int32_t stackLen = snapshot - > getStackLength ( ) ;
jArray < nsHtml5StackNode * , int32_t > listCopy = snapshot - > getListOfActiveFormattingElements ( ) ;
int32_t listLen = snapshot - > getListOfActiveFormattingElementsLength ( ) ;
2013-08-12 14:46:12 -07:00
jArray < int32_t , int32_t > templateModeStackCopy = snapshot - > getTemplateModeStack ( ) ;
int32_t templateModeStackLen = snapshot - > getTemplateModeStackLength ( ) ;
if ( stackLen ! = currentPtr + 1 | | listLen ! = listPtr + 1 | | templateModeStackLen ! = templateModePtr + 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 ( ) ) {
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
2012-08-22 08:56:38 -07:00
for ( int32_t i = listLen - 1 ; i > = 0 ; i - - ) {
2009-09-21 06:18:20 -07:00
if ( ! listCopy [ i ] & & ! listOfActiveFormattingElements [ i ] ) {
continue ;
} else if ( ! listCopy [ i ] | | ! listOfActiveFormattingElements [ i ] ) {
2011-10-17 07:59:28 -07:00
return false ;
2009-09-21 06:18:20 -07:00
}
if ( listCopy [ i ] - > node ! = listOfActiveFormattingElements [ i ] - > node ) {
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
}
2012-08-22 08:56:38 -07:00
for ( int32_t i = stackLen - 1 ; i > = 0 ; i - - ) {
2009-09-21 06:18:20 -07:00
if ( stackCopy [ i ] - > node ! = stack [ i ] - > node ) {
2011-10-17 07:59:28 -07:00
return false ;
2009-06-28 15:44:22 -07:00
}
}
2013-08-12 14:46:12 -07:00
for ( int32_t i = templateModeStackLen - 1 ; i > = 0 ; i - - ) {
if ( templateModeStackCopy [ i ] ! = templateModeStack [ i ] ) {
return false ;
}
}
2011-10-17 07:59:28 -07:00
return true ;
2009-06-28 15:44:22 -07:00
}
2009-09-21 06:18:20 -07:00
void
nsHtml5TreeBuilder : : loadState ( nsAHtml5TreeBuilderState * snapshot , nsHtml5AtomTable * interner )
{
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t > stackCopy = snapshot - > getStack ( ) ;
int32_t stackLen = snapshot - > getStackLength ( ) ;
jArray < nsHtml5StackNode * , int32_t > listCopy = snapshot - > getListOfActiveFormattingElements ( ) ;
int32_t listLen = snapshot - > getListOfActiveFormattingElementsLength ( ) ;
2013-08-12 14:46:12 -07:00
jArray < int32_t , int32_t > templateModeStackCopy = snapshot - > getTemplateModeStack ( ) ;
int32_t templateModeStackLen = snapshot - > getTemplateModeStackLength ( ) ;
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < = listPtr ; i + + ) {
2010-04-19 06:25:13 -07:00
if ( listOfActiveFormattingElements [ i ] ) {
2009-09-21 06:18:20 -07:00
listOfActiveFormattingElements [ i ] - > release ( ) ;
}
}
if ( listOfActiveFormattingElements . length < listLen ) {
2012-08-22 08:56:38 -07:00
listOfActiveFormattingElements = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( listLen ) ;
2009-09-21 06:18:20 -07:00
}
listPtr = listLen - 1 ;
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < = currentPtr ; i + + ) {
2009-09-21 06:18:20 -07:00
stack [ i ] - > release ( ) ;
}
if ( stack . length < stackLen ) {
2012-08-22 08:56:38 -07:00
stack = jArray < nsHtml5StackNode * , int32_t > : : newJArray ( stackLen ) ;
2009-09-21 06:18:20 -07:00
}
currentPtr = stackLen - 1 ;
2013-08-12 14:46:12 -07:00
if ( templateModeStack . length < templateModeStackLen ) {
templateModeStack = jArray < int32_t , int32_t > : : newJArray ( templateModeStackLen ) ;
}
templateModePtr = templateModeStackLen - 1 ;
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < listLen ; i + + ) {
2009-09-21 06:18:20 -07:00
nsHtml5StackNode * node = listCopy [ i ] ;
2010-04-19 06:25:13 -07:00
if ( node ) {
2012-07-30 07:20:58 -07:00
nsHtml5StackNode * newNode = new nsHtml5StackNode ( node - > getFlags ( ) , node - > ns , nsHtml5Portability : : newLocalFromLocal ( node - > name , interner ) , node - > node , nsHtml5Portability : : newLocalFromLocal ( node - > popName , interner ) , node - > attributes - > cloneAttributes ( nullptr ) ) ;
2009-09-21 06:18:20 -07:00
listOfActiveFormattingElements [ i ] = newNode ;
} else {
2012-07-30 07:20:58 -07:00
listOfActiveFormattingElements [ i ] = nullptr ;
2009-09-21 06:18:20 -07:00
}
}
2012-08-22 08:56:38 -07:00
for ( int32_t i = 0 ; i < stackLen ; i + + ) {
2009-09-21 06:18:20 -07:00
nsHtml5StackNode * node = stackCopy [ i ] ;
2012-08-22 08:56:38 -07:00
int32_t listIndex = findInArray ( node , listCopy ) ;
2009-09-21 06:18:20 -07:00
if ( listIndex = = - 1 ) {
2012-07-30 07:20:58 -07:00
nsHtml5StackNode * newNode = new nsHtml5StackNode ( node - > getFlags ( ) , node - > ns , nsHtml5Portability : : newLocalFromLocal ( node - > name , interner ) , node - > node , nsHtml5Portability : : newLocalFromLocal ( node - > popName , interner ) , nullptr ) ;
2009-09-21 06:18:20 -07:00
stack [ i ] = newNode ;
} else {
stack [ i ] = listOfActiveFormattingElements [ listIndex ] ;
stack [ i ] - > retain ( ) ;
}
}
2013-08-12 14:46:12 -07:00
nsHtml5ArrayCopy : : arraycopy ( templateModeStackCopy , templateModeStack , templateModeStackLen ) ;
2009-09-21 06:18:20 -07:00
formPointer = snapshot - > getFormPointer ( ) ;
headPointer = snapshot - > getHeadPointer ( ) ;
2010-09-06 00:41:26 -07:00
deepTreeSurrogateParent = snapshot - > getDeepTreeSurrogateParent ( ) ;
2009-09-21 06:18:20 -07:00
mode = snapshot - > getMode ( ) ;
originalMode = snapshot - > getOriginalMode ( ) ;
2009-12-23 00:31:48 -08:00
framesetOk = snapshot - > isFramesetOk ( ) ;
2009-09-21 06:18:20 -07:00
needToDropLF = snapshot - > isNeedToDropLF ( ) ;
quirks = snapshot - > isQuirks ( ) ;
}
2012-08-22 08:56:38 -07:00
int32_t
nsHtml5TreeBuilder : : findInArray ( nsHtml5StackNode * node , jArray < nsHtml5StackNode * , int32_t > arr )
2009-09-21 06:18:20 -07:00
{
2012-08-22 08:56:38 -07:00
for ( int32_t i = listPtr ; i > = 0 ; i - - ) {
2009-09-21 06:18:20 -07:00
if ( node = = arr [ i ] ) {
return i ;
}
}
return - 1 ;
}
2014-03-05 11:38:49 -08:00
nsIContentHandle *
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getFormPointer ( )
{
return formPointer ;
}
2014-03-05 11:38:49 -08:00
nsIContentHandle *
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getHeadPointer ( )
{
return headPointer ;
}
2014-03-05 11:38:49 -08:00
nsIContentHandle *
2010-09-06 00:41:26 -07:00
nsHtml5TreeBuilder : : getDeepTreeSurrogateParent ( )
{
return deepTreeSurrogateParent ;
}
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t >
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getListOfActiveFormattingElements ( )
{
return listOfActiveFormattingElements ;
}
2012-08-22 08:56:38 -07:00
jArray < nsHtml5StackNode * , int32_t >
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getStack ( )
{
return stack ;
}
2013-08-12 14:46:12 -07:00
jArray < int32_t , int32_t >
nsHtml5TreeBuilder : : getTemplateModeStack ( )
{
return templateModeStack ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getMode ( )
{
return mode ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getOriginalMode ( )
{
return originalMode ;
}
2011-09-28 23:19:26 -07:00
bool
2009-12-23 00:31:48 -08:00
nsHtml5TreeBuilder : : isFramesetOk ( )
{
return framesetOk ;
}
2011-09-28 23:19:26 -07:00
bool
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : isNeedToDropLF ( )
{
return needToDropLF ;
}
2011-09-28 23:19:26 -07:00
bool
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : isQuirks ( )
{
return quirks ;
}
2012-08-22 08:56:38 -07:00
int32_t
2010-04-16 03:52:06 -07:00
nsHtml5TreeBuilder : : getListOfActiveFormattingElementsLength ( )
2009-09-21 06:18:20 -07:00
{
return listPtr + 1 ;
}
2012-08-22 08:56:38 -07:00
int32_t
2009-09-21 06:18:20 -07:00
nsHtml5TreeBuilder : : getStackLength ( )
{
return currentPtr + 1 ;
}
2013-08-12 14:46:12 -07:00
int32_t
nsHtml5TreeBuilder : : getTemplateModeStackLength ( )
{
return templateModePtr + 1 ;
}
2009-06-28 15:44:22 -07:00
void
nsHtml5TreeBuilder : : initializeStatics ( )
{
}
void
nsHtml5TreeBuilder : : releaseStatics ( )
{
}
# include "nsHtml5TreeBuilderCppSupplement.h"