diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index b3f6f638adc..09e4dce1053 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -25,7 +25,6 @@ #include "nsIParser.h" #include "nsIHTMLContentSink.h" #include "nsScanner.h" -#include "nsTokenHandler.h" #include "nsIDTDDebug.h" #include "prenv.h" //this is here for debug reasons... #include "prtypes.h" //this is here for debug reasons... @@ -59,9 +58,11 @@ static NS_DEFINE_IID(kClassIID, NS_INAVHTML_DTD_IID); static const char* kNullToken = "Error: Null token given"; static const char* kInvalidTagStackPos = "Error: invalid tag stack position"; static char* kVerificationDir = "c:/temp"; -static char gShowCRC=0; static CTokenRecycler* gRecycler=0; - + +#ifdef RICKG_DEBUG +static char gShowCRC=0; +#endif static eHTMLTags gFormElementTags[]= { eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input, @@ -231,112 +232,6 @@ NS_IMPL_ADDREF(CNavDTD) NS_IMPL_RELEASE(CNavDTD) - -/** - * - * - * @update gess 6/9/98 - * @param - * @return - */ -static -PRInt32 NavDispatchTokenHandler(CToken* aToken,nsIDTD* aDTD) { - PRInt32 result=0; - CHTMLToken* theToken= (CHTMLToken*)(aToken); - eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType(); - CNavDTD* theDTD=(CNavDTD*)aDTD; - - if(aDTD) { - switch(theType) { - case eToken_start: - case eToken_whitespace: - case eToken_newline: - case eToken_text: - result=theDTD->HandleStartToken(aToken); break; - case eToken_end: - result=theDTD->HandleEndToken(aToken); break; - case eToken_comment: - result=theDTD->HandleCommentToken(aToken); break; - case eToken_entity: - result=theDTD->HandleEntityToken(aToken); break; - case eToken_attribute: - result=theDTD->HandleAttributeToken(aToken); break; - case eToken_style: - result=theDTD->HandleStyleToken(aToken); break; - case eToken_instruction: - result=theDTD->HandleProcessingInstructionToken(aToken); break; - case eToken_doctypeDecl: - result=theDTD->HandleDocTypeDeclToken(aToken); break; - default: - result=0; - }//switch - }//if - return result; -} - -/** - * Register a handler. - * - * @update gess 4/2/98 - * @param - * @return - */ -CITokenHandler* CNavDTD::AddTokenHandler(CITokenHandler* aHandler) { - NS_ASSERTION(0!=aHandler,"Error: Null handler"); - - if(aHandler) { - eHTMLTokenTypes type=(eHTMLTokenTypes)aHandler->GetTokenType(); - if(typeRecycleToken(aToken); theToken=(CHTMLToken*)mSkippedContent.PopFront(); + theType=eToken_start; // result=HandleStartToken(theToken); } else { @@ -729,6 +628,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ mTokenizer->PushTokenFront(aToken); //put this token back... mTokenizer->PrependTokens(mMisplacedContent); //push misplaced content theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theTag=eHTMLTag_body); + theType=eToken_start; //now open a body... } } @@ -748,30 +648,55 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ } else { - CITokenHandler* theHandler=GetTokenHandler(theType); - if(theHandler) { - mParser=(nsParser*)aParser; - result=(*theHandler)(theToken,this); - if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { - if(theToken->mRecycle) - gRecycler->RecycleToken(theToken); - } - else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) - return 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 (mDTDDebug) { - //mDTDDebug->Verify(this, mParser, mBodyContext->GetCount(), mBodyContext->mStack, mFilename); - } - } //if + mParser=(nsParser*)aParser; + + switch(theType) { + case eToken_start: + case eToken_whitespace: + case eToken_newline: + case eToken_text: + result=HandleStartToken(theToken); break; + case eToken_end: + result=HandleEndToken(theToken); break; + 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(theToken->mRecycle) + gRecycler->RecycleToken(theToken); + } + else if(result==NS_ERROR_HTMLPARSER_STOPPARSING) + return 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 } } @@ -784,7 +709,7 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ * * @update gess 3/25/98 * @param aHandler -- object to receive subsequent tokens... - * @return error code (usually 0) + * @return error code (usually 0) */ nsresult CNavDTD::CaptureTokenPump(nsITagHandler* aHandler) { nsresult result=NS_OK; @@ -796,7 +721,7 @@ nsresult CNavDTD::CaptureTokenPump(nsITagHandler* aHandler) { * * @update gess 3/25/98 * @param aHandler -- object that received tokens... - * @return error code (usually 0) + * @return error code (usually 0) */ nsresult CNavDTD::ReleaseTokenPump(nsITagHandler* aHandler){ nsresult result=NS_OK; @@ -1839,42 +1764,34 @@ nsresult CNavDTD::CollectAttributes(nsCParserNode& aNode,eHTMLTags aTag,PRInt32 * @param holds the number of skipped content elements encountered * @return Error condition. */ -nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount) { +nsresult CNavDTD::CollectSkippedContent(nsCParserNode& aNode,PRInt32 &aCount) { CTokenRecycler* theRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler(); + eHTMLTags theNodeTag=(eHTMLTags)aNode.GetNodeType(); + int aIndex=0; int aMax=mSkippedContent.GetSize(); nsAutoString theTempStr; nsAutoString theStr; + for(aIndex=0;aIndexGetSource(theTempStr); + + eHTMLTokenTypes theTokenType=(eHTMLTokenTypes)theNextToken->GetTokenType(); + + if((eHTMLTag_textarea==theNodeTag) && (eToken_entity==theTokenType)) { + ((CEntityToken*)theNextToken)->TranslateToUnicodeStr(theTempStr); + } + else theNextToken->GetSource(theTempStr); + theStr+=theTempStr; theRecycler->RecycleToken(theNextToken); } + aNode.SetSkippedContent(theStr); return NS_OK; } - - -/** - * Finds a tag handler for the given tag type. - * - * @update gess 4/2/98 - * @param aTagType type of tag to be handled - * @return valid tag handler (if found) or null - */ -CITokenHandler* CNavDTD::GetTokenHandler(eHTMLTokenTypes aType) const { - CITokenHandler* result=0; - if((aType>0) && (aTypeAddLeaf(aNode); +#if 1 + PRBool done=false; + nsCParserNode* theNode=CreateNode(); + while(!done) { + CToken* theToken=mTokenizer->PeekToken(); + if(theToken) { + eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID(); + switch(theTag) { + case eHTMLTag_newline: + mLineNumber++; + case eHTMLTag_text: + case eHTMLTag_whitespace: + { + theToken=mTokenizer->PopToken(); + theNode->Init(theToken,mLineNumber,GetTokenRecycler()); + result=mSink->AddLeaf(*theNode); + } + break; + default: + done=PR_TRUE; + } //switch + }//if + else done=PR_TRUE; + } //while + RecycleNode(theNode); + +#endif + START_TIMER(); } @@ -2932,60 +2876,36 @@ nsresult CNavDTD::AddHeadLeaf(nsIParserNode& aNode){ */ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ - static nsEntryStack kPropagationStack; - kPropagationStack.Empty(); + nsAutoString theSequence; nsresult result=(nsresult)kContextMismatch; eHTMLTags theTop=mBodyContext->Last(); - PRBool bResult=ForwardPropagate(kPropagationStack,theTop,aChildTag); + PRBool bResult=ForwardPropagate(theSequence,theTop,aChildTag); if(PR_FALSE==bResult){ if(eHTMLTag_unknown!=theTop) { if(theTop!=aChildTag) //dont even bother if we're already inside a similar element... - bResult=BackwardPropagate(kPropagationStack,theTop,aChildTag); - - /***************************************************************************** - OH NOOOO!... - - We found a pretty fundamental flaw in the backward propagation code. - The previous version propagated from a child to a target parent, and - then again from the target parent to the root. - Only thing is, that won't work in cases where a container exists that's - not in the usual hiearchy: - - -
- -