From e986fc3858b8473f87a23b5d12b2b69752dd0ab7 Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Mon, 17 Apr 2000 06:33:31 +0000 Subject: [PATCH] fixed DTD selection bugs; entity bugs; conditionally enabled Strict DTD git-svn-id: svn://10.0.0.236/trunk@66182 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/htmlparser/src/CNavDTD.cpp | 50 +- mozilla/htmlparser/src/CNavDTD.h | 1 - mozilla/htmlparser/src/COtherDTD.cpp | 2040 +++-------------- mozilla/htmlparser/src/COtherDTD.h | 109 +- mozilla/htmlparser/src/COtherElements.h | 1886 +++++++++++++++ mozilla/htmlparser/src/CParserContext.cpp | 150 +- mozilla/htmlparser/src/CParserContext.h | 1 + mozilla/htmlparser/src/nsDTDUtils.cpp | 2 +- mozilla/htmlparser/src/nsElementTable.cpp | 2 - mozilla/htmlparser/src/nsHTMLTokenizer.cpp | 3 +- mozilla/htmlparser/src/nsHTMLTokenizer.h | 2 +- mozilla/htmlparser/src/nsHTMLTokens.cpp | 8 +- mozilla/htmlparser/src/nsIDTD.h | 2 +- mozilla/htmlparser/src/nsIParser.h | 6 +- mozilla/htmlparser/src/nsParser.cpp | 169 +- mozilla/htmlparser/src/nsViewSourceHTML.cpp | 4 +- mozilla/parser/htmlparser/src/CNavDTD.cpp | 50 +- mozilla/parser/htmlparser/src/CNavDTD.h | 1 - mozilla/parser/htmlparser/src/COtherDTD.cpp | 2040 +++-------------- mozilla/parser/htmlparser/src/COtherDTD.h | 109 +- .../parser/htmlparser/src/COtherElements.h | 1886 +++++++++++++++ .../parser/htmlparser/src/CParserContext.cpp | 150 +- .../parser/htmlparser/src/CParserContext.h | 1 + mozilla/parser/htmlparser/src/nsDTDUtils.cpp | 2 +- .../parser/htmlparser/src/nsElementTable.cpp | 2 - .../parser/htmlparser/src/nsHTMLTokenizer.cpp | 3 +- .../parser/htmlparser/src/nsHTMLTokenizer.h | 2 +- .../parser/htmlparser/src/nsHTMLTokens.cpp | 8 +- mozilla/parser/htmlparser/src/nsIDTD.h | 2 +- mozilla/parser/htmlparser/src/nsIParser.h | 6 +- mozilla/parser/htmlparser/src/nsParser.cpp | 169 +- .../htmlparser/src/nsViewSourceHTML.cpp | 4 +- 32 files changed, 4784 insertions(+), 4086 deletions(-) create mode 100644 mozilla/htmlparser/src/COtherElements.h create mode 100644 mozilla/parser/htmlparser/src/COtherElements.h diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 78b7115204d..ea934d671ba 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -23,6 +23,8 @@ //#define ENABLE_CRC //#define RICKG_DEBUG #define ENABLE_RESIDUALSTYLE +//#define ALLOW_TR_AS_CHILD_OF_TABLE //by setting this to true, TR is allowable directly in TABLE. + #ifdef RICKG_DEBUG #include #endif @@ -155,7 +157,7 @@ CNavDTD::CNavDTD() : nsIDTD(), mExpectedCRC32=0; mDTDState=NS_OK; mStyleHandlingEnabled=PR_TRUE; - mDocType=eHTMLText; + mDocType=eHTML3Text; mRequestedHead=PR_FALSE; mIsFormContainer=PR_FALSE; @@ -369,7 +371,6 @@ PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){ eAutoDetectResult CNavDTD::CanParse(CParserContext& aParserContext,nsString& aBuffer, PRInt32 aVersion) { eAutoDetectResult result=eUnknownDetect; - if(eViewSource==aParserContext.mParserCommand) { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=ePrimaryDetect; @@ -380,7 +381,7 @@ eAutoDetectResult CNavDTD::CanParse(CParserContext& aParserContext,nsString& aBu } else { if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kHTMLTextContentType)) { - result=ePrimaryDetect; + result=(eParseMode_strict==aParserContext.mParseMode) ? eValidDetect : ePrimaryDetect; } else if(PR_TRUE==aParserContext.mMimeType.EqualsWithConversion(kPlainTextContentType)) { result=ePrimaryDetect; @@ -392,7 +393,10 @@ eAutoDetectResult CNavDTD::CanParse(CParserContext& aParserContext,nsString& aBu result = eValidDetect ; if(0==aParserContext.mMimeType.Length()) { aParserContext.SetMimeType(NS_ConvertToString(kHTMLTextContentType)); - result = (theBufHasXML) ? eValidDetect : ePrimaryDetect; + if(!theBufHasXML) { + result=(eParseMode_strict==aParserContext.mParseMode) ? eValidDetect : ePrimaryDetect; + } + else result=eValidDetect; } } } @@ -783,9 +787,6 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ case eToken_attribute: result=HandleAttributeToken(theToken); break; - case eToken_style: - result=HandleStyleToken(theToken); break; - case eToken_instruction: result=HandleProcessingInstructionToken(theToken); break; @@ -1890,21 +1891,6 @@ nsresult CNavDTD::HandleScriptToken(const nsIParserNode *aNode) { return result; } -/** - * This method gets called when a style token has been - * encountered in the parse process. - * - * @update gess 3/25/98 - * @param aToken -- next (start) token to be handled - * @return PR_TRUE if all went well; PR_FALSE if error occured - */ -nsresult CNavDTD::HandleStyleToken(CToken* aToken){ - NS_PRECONDITION(0!=aToken,kNullToken); - -// CStyleToken* st = (CStyleToken*)(aToken); - return NS_OK; -} - /** * This method gets called when an "instruction" token has been @@ -2114,7 +2100,18 @@ nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) { * @return PR_TRUE if parent can contain child */ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { - return gHTMLElements[aParent].CanContain((eHTMLTags)aChild); + PRBool result=gHTMLElements[aParent].CanContain((eHTMLTags)aChild); + +#ifdef ALLOW_TR_AS_CHILD_OF_TABLE + if(!result) { + //XXX This vile hack is here to support bug 30378, which allows + //table to contain tr directly in an html32 document. + if((eHTMLTag_tr==aChild) && (eHTMLTag_table==aParent)) { + result=PR_TRUE; + } + } +#endif + return result; } /** @@ -3485,6 +3482,13 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ if(PR_TRUE==bResult){ while(theLen) { theTag=(eHTMLTags)mScratch[--theLen]; + +#ifdef ALLOW_TR_AS_CHILD_OF_TABLE + if((eHTML3Text==mDocType) && (eHTMLTag_tbody==theTag)) { + //the prev. condition prevents us from emitting tbody in html3.2 docs; fix bug 30378 + continue; + } +#endif CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,theTag); HandleStartToken(theToken); //these should all wind up on contextstack, so don't recycle. } diff --git a/mozilla/htmlparser/src/CNavDTD.h b/mozilla/htmlparser/src/CNavDTD.h index 60554568649..0b5f4d3ea8a 100644 --- a/mozilla/htmlparser/src/CNavDTD.h +++ b/mozilla/htmlparser/src/CNavDTD.h @@ -402,7 +402,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult HandleCommentToken(CToken* aToken); nsresult HandleAttributeToken(CToken* aToken); nsresult HandleScriptToken(const nsIParserNode *aNode); - nsresult HandleStyleToken(CToken* aToken); nsresult HandleProcessingInstructionToken(CToken* aToken); nsresult HandleDocTypeDeclToken(CToken* aToken); diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index 0504c20f150..69fc4355993 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -1,52 +1,53 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* * The contents of this file are subject to the Netscape Public * License Version 1.1 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of + * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ - * + * * Software distributed under the License is distributed on an "AS - * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or + * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. - * - * The Original Code is mozilla.org code. - * + * + * The Original Code is mozilla.org code. + * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All - * Rights Reserved. - * - * Contributor(s): - */ + * Rights Reserved. + * + * Contributor(s): + */ + +//#define ENABLE_CRC +//#define RICKG_DEBUG + -//#define ENABLE_CRC -//#define RICKG_DEBUG -#define ENABLE_RESIDUALSTYLE #ifdef RICKG_DEBUG -#include -#endif - +#include +#endif + #include "nsDebug.h" #include "nsIDTDDebug.h" #include "COtherDTD.h" #include "nsHTMLTokens.h" -#include "nsCRT.h" -#include "nsParser.h" +#include "nsCRT.h" +#include "nsParser.h" #include "nsIParser.h" -#include "nsIHTMLContentSink.h" +#include "nsIHTMLContentSink.h" #include "nsScanner.h" #include "nsIDTDDebug.h" #include "prenv.h" //this is here for debug reasons... #include "prtypes.h" //this is here for debug reasons... #include "prio.h" -#include "plstr.h" +#include "plstr.h" #include "nsDTDUtils.h" -#include "nsTagHandler.h" +#include "nsTagHandler.h" #include "nsHTMLTokenizer.h" #include "nsTime.h" #include "nsIElementObserver.h" -#include "nsViewSourceHTML.h" +#include "nsViewSourceHTML.h" #include "nsParserNode.h" #include "nsHTMLEntities.h" #include "nsLinebreakConverter.h" @@ -68,9 +69,8 @@ static char* kVerificationDir = "c:/temp"; static char gShowCRC; #endif -#include "nsElementTable.h" - - + + #ifdef MOZ_PERF_METRICS # define START_TIMER() \ if(mParser) MOZ_TIMER_START(mParser->mParseTime); \ @@ -85,92 +85,7 @@ static char gShowCRC; #endif - -/*************************************************************** - This the ITagHandler deque deallocator, needed by the - CTagHandlerRegister - ***************************************************************/ -class CTagHandlerDeallocator: public nsDequeFunctor{ -public: - virtual void* operator()(void* aObject) { - nsITagHandler* tagHandler = (nsITagHandler*)aObject; - delete tagHandler; - return 0; - } -}; - -/*************************************************************** - This funtor will be called for each item in the TagHandler que to - check for a Tag name, and setting the current TagHandler when it is reached - ***************************************************************/ -class CTagFinder: public nsDequeFunctor{ - -public: - CTagFinder(){} - void Initialize(const nsString &aTagName) {mTagName.Assign(aTagName);} - - virtual ~CTagFinder() { - } - - virtual void* operator()(void* aObject) { - nsString* theString = ((nsITagHandler*)aObject)->GetString(); - if( theString->Equals(mTagName)){ - return aObject; - } - return(0); - } - - nsAutoString mTagName; -}; - -/*************************************************************** - This a an object that will keep track of TagHandlers in - the DTD. Uses a factory pattern - ***************************************************************/ -class CTagHandlerRegister { -public: - - CTagHandlerRegister(); - - ~CTagHandlerRegister(); - - void RegisterTagHandler(nsITagHandler *aTagHandler){ - mTagHandlerDeque.Push(aTagHandler); - } - - nsITagHandler* FindTagHandler(const nsString &aTagName){ - nsITagHandler* foundHandler = nsnull; - - mTagFinder.Initialize(aTagName); - mTagHandlerDeque.Begin(); - foundHandler = (nsITagHandler*) mTagHandlerDeque.FirstThat(mTagFinder); - return foundHandler; - } - - - nsDeque mTagHandlerDeque; - CTagFinder mTagFinder; -}; - -MOZ_DECL_CTOR_COUNTER(CTagHandlerRegister); - -CTagHandlerRegister::CTagHandlerRegister() : mTagHandlerDeque(new CTagHandlerDeallocator()) -{ - MOZ_COUNT_CTOR(CTagHandlerRegister); -} - -CTagHandlerRegister::~CTagHandlerRegister() -{ - MOZ_COUNT_DTOR(CTagHandlerRegister); -} - -/************************************************************************ - The CTagHandlerRegister for a COtherDTD. - This is where special taghanders for our tags can be managed and called from - Note: This can also be attached to some object so it can be refcounted - and destroyed if you want this to go away when not imbedded. - ************************************************************************/ -//CTagHandlerRegister gTagHandlerRegister; +#include "COtherElements.h" /************************************************************************ @@ -185,10 +100,10 @@ CTagHandlerRegister::~CTagHandlerRegister() * @update gess 4/8/98 * @param nsIID id of object to discover * @param aInstancePtr ptr to newly discovered interface - * @return NS_xxx result code - */ + * @return NS_xxx result code + */ nsresult COtherDTD::QueryInterface(const nsIID& aIID, void** aInstancePtr) -{ +{ if (NULL == aInstancePtr) { return NS_ERROR_NULL_POINTER; } @@ -218,8 +133,8 @@ NS_IMPL_RELEASE(COtherDTD) * * @update gess 4/9/98 * @param - * @return - */ + * @return + */ COtherDTD::COtherDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSharedNodes(0) { NS_INIT_REFCNT(); mSink = 0; @@ -233,17 +148,17 @@ COtherDTD::COtherDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSh mHeadContext=new nsDTDContext(); mBodyContext=new nsDTDContext(); mFormContext=0; - mMapContext=0; - mTempContext=0; mTokenizer=0; mComputedCRC32=0; mExpectedCRC32=0; mDTDState=NS_OK; - mStyleHandlingEnabled=PR_TRUE; mDocType=ePlainText; - if(!gHTMLElements) { - InitializeElementTable(); + char* theEnvString = PR_GetEnv("ENABLE_STRICT"); + mEnableStrict=PRBool(theEnvString!=0); + + if(!gElementTable) { + gElementTable = new CElementTable(); } #ifdef RICKG_DEBUG @@ -266,13 +181,12 @@ COtherDTD::COtherDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSh * @param * @return valid node* */ - nsCParserNode* COtherDTD::CreateNode(void) { nsCParserNode* result=0; if(0QueryInterface(kIHTMLContentSinkIID, (void **)&mSink); } @@ -564,9 +488,7 @@ nsresult COtherDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITo mTokenRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler(); if(mSink) { - - - + if(!mBodyContext->GetCount()) { //if the content model is empty, then begin by opening ... CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_html, NS_ConvertToString("html")); @@ -576,7 +498,7 @@ nsresult COtherDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsITo while(NS_SUCCEEDED(result)){ #if 0 - int n=aTokenizer->GetCount(); + int n=aTokenizer->GetCount(); if(n>50) n=50; for(int i=0;iGetTokenAt(i); @@ -620,8 +542,6 @@ nsresult COtherDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIPar mSkipTarget=eHTMLTag_unknown; //clear this in case we were searching earlier. - mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content - if(ePlainText==mDocType) { CStartToken *theToken=(CStartToken*)mTokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_pre, NS_ConvertToString("pre")); mTokenizer->PushTokenFront(theToken); //this token should get pushed on the context stack, don't recycle it @@ -636,108 +556,52 @@ nsresult COtherDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIPar if(aParser && (NS_OK==result)){ if(aNotifySink){ if((NS_OK==anErrorCode) && (mBodyContext->GetCount()>0)) { - if(mSkipTarget) { - CHTMLToken* theEndToken=nsnull; - theEndToken=(CHTMLToken*)mTokenRecycler->CreateTokenOfType(eToken_end,mSkipTarget); - if(theEndToken) { - result=HandleToken(theEndToken,mParser); + + while(mBodyContext->GetCount() > 0) { + eHTMLTags theTarget = mBodyContext->Last(); + CElement* theElement=gElementTable->mElements[theTarget]; + if(theElement) { + theElement->HandleEndToken(0,theTarget,mBodyContext,mSink); } - } - if(result==NS_OK) { - eHTMLTags theTarget; - - //now let's disable style handling to save time when closing remaining stack members... - mStyleHandlingEnabled=PR_FALSE; - - while(mBodyContext->GetCount() > 0) { - theTarget = mBodyContext->Last(); - CloseContainersTo(theTarget,PR_FALSE); - } - } - } + } + + } else { //If you're here, then an error occured, but we still have nodes on the stack. //At a minimum, we should grab the nodes and recycle them. - //Just to be correct, we'll also recycle the nodes. - - while(mBodyContext->GetCount() > 0) { - + //Just to be correct, we'll also recycle the nodes. + + while(mBodyContext->GetCount() > 0) { + nsEntryStack *theChildStyles=0; nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theChildStyles); theNode->mUseCount=0; RecycleNode(theNode); if(theChildStyles) { delete theChildStyles; - } - } - - } - - STOP_TIMER(); - MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: COtherDTD::DidBuildModel(), this=%p\n", this)); - -#ifdef ENABLE_CRC - - //let's only grab this state once! - if(!gShowCRC) { - gShowCRC=1; //this only indicates we'll not initialize again. - char* theEnvString = PR_GetEnv("RICKG_CRC"); - if(theEnvString){ - if(('1'==theEnvString[0]) || ('Y'==theEnvString[0]) || ('y'==theEnvString[0])){ - gShowCRC=2; //this indicates that the CRC flag was found in the environment. } - } - } - - if(2==gShowCRC) { - if(mComputedCRC32!=mExpectedCRC32) { - if(mExpectedCRC32!=0) { - printf("CRC Computed: %u Expected CRC: %u\n,",mComputedCRC32,mExpectedCRC32); - result = aSink->DidBuildModel(2); - } - else { - printf("Computed CRC: %u.\n",mComputedCRC32); - result = aSink->DidBuildModel(3); - } - } - else result = aSink->DidBuildModel(0); - } - else result=aSink->DidBuildModel(0); -#endif - - MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::DidBuildModel(), this=%p\n", this)); - START_TIMER(); - - //Now make sure the misplaced content list is empty, - //by forcefully recycling any tokens we might find there. - - CToken* theToken=0; - while((theToken=(CToken*)mMisplacedContent.Pop())) { - mTokenRecycler->RecycleToken(theToken); - } - - if(mDTDDebug) { - mDTDDebug->DumpVectorRecord(); - } + } + } + } - } //if aparser + } //if aparser //No matter what, you need to call did build model. result=aSink->DidBuildModel(0); } //if asink - return result; -} + return result; +} -/** +/** * This big dispatch method is used to route token handler calls to the right place. * What's wrong with it? This table, and the dispatch methods themselves need to be * moved over to the delegate. Ah, so much to do... * * @update gess 12/1/99 * @param aToken - * @param aParser - * @return + * @param aParser + * @return */ nsresult COtherDTD::HandleToken(CToken* aToken,nsIParser* aParser){ nsresult result=NS_OK; @@ -750,161 +614,47 @@ nsresult COtherDTD::HandleToken(CToken* aToken,nsIParser* aParser){ theToken->mUseCount=0; //assume every token coming into this system needs recycling. - /* --------------------------------------------------------------------------------- - To understand this little piece of code, you need to look below too. - In essence, this code caches "skipped content" until we find a given skiptarget. - Once we find the skiptarget, we take all skipped content up to that point and - coallate it. Then we push those tokens back onto the tokenizer deque. - --------------------------------------------------------------------------------- - */ - // printf("token: %p\n",aToken); + mParser=(nsParser*)aParser; - if(mSkipTarget){ //handle a preexisting target... - if((theTag==mSkipTarget) && (eToken_end==theType)){ - mSkipTarget=eHTMLTag_unknown; //stop skipping. - //mTokenizer->PushTokenFront(aToken); //push the end token... - execSkipContent=PR_TRUE; - mTokenRecycler->RecycleToken(aToken); - theToken=(CHTMLToken*)mSkippedContent.PopFront(); - theType=eToken_start; - } - else { - mSkippedContent.Push(theToken); - return result; - } - } - - /* --------------------------------------------------------------------------------- - This section of code is used to "move" misplaced content from one location in - our document model to another. (Consider what would happen if we found a

tag - and text in the head.) To move content, we throw it onto the misplacedcontent - deque until we can deal with it. - --------------------------------------------------------------------------------- - */ - if(!execSkipContent) { - - switch(theTag) { - case eHTMLTag_html: - case eHTMLTag_comment: - case eHTMLTag_script: - case eHTMLTag_markupDecl: - case eHTMLTag_userdefined: - break; //simply pass these through to token handler without further ado... - - default: - if(!gHTMLElements[eHTMLTag_html].SectionContains(theTag,PR_FALSE)) { - if((!mHadBody) && (!mHadFrameset)){ - - //For bug examples from this code, see bugs: 18928, 20989. - - //At this point we know the body/frameset aren't open. - //If the child belongs in the head, then handle it (which may open the head); - //otherwise, push it onto the misplaced stack. - - PRBool theExclusive=PR_FALSE; - PRBool theChildBelongsInHead=gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag,theExclusive); - if(!theChildBelongsInHead) { - - //If you're here then we found a child of the body that was out of place. - //We're going to move it to the body by storing it temporarily on the misplaced stack. - mMisplacedContent.Push(aToken); - aToken->mUseCount++; - return result; - } - - } //if - } //if - }//switch - - } //if - - if(theToken){ - //Before dealing with the token normally, we need to deal with skip targets - if((!execSkipContent) && - (theType!=eToken_end) && - (eHTMLTag_unknown==mSkipTarget) && - (gHTMLElements[theTag].mSkipTarget)){ //create a new target - // Ref: Bug# 19977 - // For optimization, determine if the skipped content is well - // placed. This would avoid unnecessary node creation and - // extra string append. BTW, watch out in handling the head - // children ( especially the TITLE tag). - - PRBool theExclusive=PR_FALSE; - if(!gHTMLElements[eHTMLTag_head].IsChildOfHead(theTag,theExclusive)) { - eHTMLTags theParentTag = mBodyContext->Last(); - PRBool theParentContains = -1; - if(CanOmit(theParentTag,theTag,theParentContains)) { - result=HandleOmittedTag(theToken,theTag,theParentTag,nsnull); - return result; - } - } - mSkipTarget=gHTMLElements[theTag].mSkipTarget; - mSkippedContent.Push(theToken); - } - else { - - mParser=(nsParser*)aParser; - - switch(theType) { - case eToken_text: - case eToken_start: - case eToken_whitespace: - case eToken_newline: - result=HandleStartToken(theToken); break; - - case eToken_end: - result=HandleEndToken(theToken); break; - - case eToken_cdatasection: - case eToken_comment: - result=HandleCommentToken(theToken); break; - - case eToken_entity: - result=HandleEntityToken(theToken); break; - - case eToken_attribute: - result=HandleAttributeToken(theToken); break; - - case eToken_style: - result=HandleStyleToken(theToken); break; - - case eToken_instruction: - result=HandleProcessingInstructionToken(theToken); break; - - case eToken_doctypeDecl: - result=HandleDocTypeDeclToken(theToken); break; - - default: - break; - }//switch - - - if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { - if(0>=theToken->mUseCount) - mTokenRecycler->RecycleToken(theToken); - } - else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) - mDTDState=result; - else return NS_OK; - - /*************************************************************/ - // CAUTION: Here we are forgetting to push the ATTRIBUTE Tokens. - // So, before you uncomment this part please make sure - // that the attribute tokens are also accounted for. - - //else if(NS_ERROR_HTMLPARSER_MISPLACED!=result) - // mTokenizer->PushTokenFront(theToken); - //else result=NS_OK; - /***************************************************************/ -#if 0 - if (mDTDDebug) { - mDTDDebug->Verify(this, mParser, mBodyContext->GetCount(), mBodyContext->mStack, mFilename); - } -#endif - } + switch(theType) { + case eToken_text: + case eToken_start: + case eToken_whitespace: + case eToken_newline: + result=HandleStartToken(theToken); break; + + case eToken_end: + result=HandleEndToken(theToken); break; + + case eToken_cdatasection: + case eToken_comment: + result=HandleCommentToken(theToken); break; + + case eToken_entity: + result=HandleEntityToken(theToken); break; + + case eToken_attribute: + result=HandleAttributeToken(theToken); break; + + case eToken_instruction: + result=HandleProcessingInstructionToken(theToken); break; + + case eToken_doctypeDecl: + result=HandleDocTypeDeclToken(theToken); break; + + default: + break; + }//switch + + + if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { + if(0>=theToken->mUseCount) + mTokenRecycler->RecycleToken(theToken); } + else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) + mDTDState=result; + else return NS_OK; }//if return result; @@ -958,215 +708,6 @@ nsresult COtherDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){ return result; } -/** - * Determine whether the given tag is open anywhere - * in our context stack. - * - * @update gess 4/2/98 - * @param eHTMLTags tag to be searched for in stack - * @return topmost index of tag on stack - */ -PRInt32 COtherDTD::LastOf(eHTMLTags aTagSet[],PRInt32 aCount) const { - int theIndex=0; - for(theIndex=mBodyContext->GetCount()-1;theIndex>=0;theIndex--){ - if(FindTagInSet((*mBodyContext)[theIndex],aTagSet,aCount)) { - return theIndex; - } - } - return kNotFound; -} - -/** - * Call this to find the index of a given child, or (if not found) - * the index of its nearest synonym. - * - * @update gess 3/25/98 - * @param aTagStack -- list of open tags - * @param aTag -- tag to test for containership - * @return index of kNotFound - */ -static -PRInt32 GetIndexOfChildOrSynonym(nsDTDContext& aContext,eHTMLTags aChildTag) { - PRInt32 theChildIndex=aContext.LastOf(aChildTag); - if(kNotFound==theChildIndex) { - TagList* theSynTags=gHTMLElements[aChildTag].GetSynonymousTags(); //get the list of tags that THIS tag can close - if(theSynTags) { - theChildIndex=LastOf(aContext,*theSynTags); - } - else{ - PRInt32 theGroup=nsHTMLElement::GetSynonymousGroups(aChildTag); - if(theGroup) { - theChildIndex=aContext.GetCount(); - while(-1<--theChildIndex) { - eHTMLTags theTag=aContext[theChildIndex]; - if(gHTMLElements[theTag].IsMemberOf(theGroup)) { - break; - } - } - } - } - } - return theChildIndex; -} - -/** - * This method is called to determine whether or not the child - * tag is happy being OPENED in the context of the current - * tag stack. This is only called if the current parent thinks - * it wants to contain the given childtag. - * - * @param aChildTag -- tag enum of child to be opened - * @param aTagStack -- ref to current tag stack in DTD. - * @return PR_TRUE if child agrees to be opened here. - */ -static -PRBool CanBeContained(eHTMLTags aChildTag,nsDTDContext& aContext) { - - /* # Interesting test cases: Result: - * 1.