From 29ba77b339d875a9a8a641415b55ebb054c3cead Mon Sep 17 00:00:00 2001 From: "rickg%netscape.com" Date: Mon, 23 Nov 1998 23:11:22 +0000 Subject: [PATCH] fixed bug #1513 --- htmlparser/src/CNavDTD.cpp | 84 +++++++++++++++++------------- htmlparser/src/CNavDTD.h | 1 + htmlparser/src/nsParser.cpp | 13 +++-- parser/htmlparser/src/CNavDTD.cpp | 84 +++++++++++++++++------------- parser/htmlparser/src/CNavDTD.h | 1 + parser/htmlparser/src/nsParser.cpp | 13 +++-- 6 files changed, 118 insertions(+), 78 deletions(-) diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 6505cae339ad..8c6cf05088a4 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -508,6 +508,7 @@ CNavDTD::CNavDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { mSink = 0; mDTDDebug=0; mLineNumber=1; + mHasOpenBody=PR_FALSE; mParseMode=eParseMode_navigator; nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers)); mHasOpenForm=PR_FALSE; @@ -630,10 +631,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ nsresult result=NS_OK; mFilename=aFilename; - if((aNotifySink) && (mSink)) { + mHasOpenBody=PR_FALSE; mLineNumber=1; result = mSink->WillBuildModel(); + //CStartToken theToken(eHTMLTag_body); //open the body container... + //result=HandleStartToken(&theToken); } return result; @@ -648,6 +651,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ nsresult result= NS_OK; +/* if((kNoError==anErrorCode) && (!mHasOpenBody)) { + CStartToken theToken(eHTMLTag_body); //open the body container... + result=HandleStartToken(&theToken); + } +*/ + if((kNoError==anErrorCode) && (mBodyContext->mElements.mCount>0)) { result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE); } @@ -727,43 +736,45 @@ PRInt32 CNavDTD::DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag){ PRInt32 result=kNoError; CToken* theNextToken=mParser->PeekToken(); - switch(aChildTag){ - case eHTMLTag_pre: - case eHTMLTag_listing: - { - if(theNextToken) { - eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); - if(eToken_newline==theType){ + if(theNextToken){ + switch(aChildTag){ + case eHTMLTag_pre: + case eHTMLTag_listing: + { + if(theNextToken) { + eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); + if(eToken_newline==theType){ - switch(aChildTag){ - case eHTMLTag_pre: - case eHTMLTag_listing: - //we skip the first newline token inside PRE and LISTING - mParser->PopToken(); - break; - default: - break; - }//switch + switch(aChildTag){ + case eHTMLTag_pre: + case eHTMLTag_listing: + //we skip the first newline token inside PRE and LISTING + mParser->PopToken(); + break; + default: + break; + }//switch + }//if }//if - }//if - } - break; - - case eHTMLTag_plaintext: - case eHTMLTag_xmp: - //grab the skipped content and dump it out as text... - if(theNextToken){ - eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); - if(eToken_skippedcontent==theType){ - nsString& theText=((CAttributeToken*)theNextToken)->GetKey(); - CViewSourceHTML::WriteText(theText,*mSink,PR_TRUE); } - } - break; - default: - break; - }//switch + break; + + case eHTMLTag_plaintext: + case eHTMLTag_xmp: + //grab the skipped content and dump it out as text... + if(theNextToken){ + eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); + if(eToken_skippedcontent==theType){ + nsString& theText=((CAttributeToken*)theNextToken)->GetKey(); + CViewSourceHTML::WriteText(theText,*mSink,PR_TRUE); + } + } + break; + default: + break; + }//switch + } return result; } @@ -1320,7 +1331,7 @@ PRBool CNavDTD::CanContainStyles(eHTMLTags aParent) const { PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { PRBool result=PR_FALSE; - if(!IsContainer(aParent)) + if((!IsContainer(aParent)) && (eHTMLTag_unknown!=aParent)) return result; @@ -2042,7 +2053,7 @@ PRBool CNavDTD::CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild) const { case eHTMLTag_html: case eHTMLTag_body: - result=HasOpenContainer(aChild); //don't bother if they're already open... + result=PR_TRUE; break; case eHTMLTag_newline: @@ -2747,6 +2758,7 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){ result=OpenHTML(aNode); break; case eHTMLTag_body: + mHasOpenBody=PR_TRUE; result=OpenBody(aNode); break; case eHTMLTag_style: diff --git a/htmlparser/src/CNavDTD.h b/htmlparser/src/CNavDTD.h index bd1fe2837b70..c27ec42312ad 100644 --- a/htmlparser/src/CNavDTD.h +++ b/htmlparser/src/CNavDTD.h @@ -619,6 +619,7 @@ protected: PRBool mHasOpenForm; PRBool mHasOpenMap; PRBool mHasOpenHead; + PRBool mHasOpenBody; nsDeque mTokenDeque; nsString mFilename; nsIDTDDebug* mDTDDebug; diff --git a/htmlparser/src/nsParser.cpp b/htmlparser/src/nsParser.cpp index a6aa3d887fee..81ab783f8a15 100644 --- a/htmlparser/src/nsParser.cpp +++ b/htmlparser/src/nsParser.cpp @@ -740,7 +740,10 @@ PRInt32 nsParser::BuildModel() { * @return ptr to token */ CToken* nsParser::PeekToken() { - CToken* theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); + CToken* theToken=0; + if(mParserContext) + if(mParserContext->mCurrentPos) + theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); return theToken; } @@ -752,8 +755,12 @@ CToken* nsParser::PeekToken() { * @return ptr to token or NULL */ CToken* nsParser::PopToken() { - CToken* theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); - ++(*mParserContext->mCurrentPos); + CToken* theToken=0; + if(mParserContext) + if(mParserContext->mCurrentPos) { + theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); + ++(*mParserContext->mCurrentPos); + } return theToken; } diff --git a/parser/htmlparser/src/CNavDTD.cpp b/parser/htmlparser/src/CNavDTD.cpp index 6505cae339ad..8c6cf05088a4 100644 --- a/parser/htmlparser/src/CNavDTD.cpp +++ b/parser/htmlparser/src/CNavDTD.cpp @@ -508,6 +508,7 @@ CNavDTD::CNavDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { mSink = 0; mDTDDebug=0; mLineNumber=1; + mHasOpenBody=PR_FALSE; mParseMode=eParseMode_navigator; nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers)); mHasOpenForm=PR_FALSE; @@ -630,10 +631,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ nsresult result=NS_OK; mFilename=aFilename; - if((aNotifySink) && (mSink)) { + mHasOpenBody=PR_FALSE; mLineNumber=1; result = mSink->WillBuildModel(); + //CStartToken theToken(eHTMLTag_body); //open the body container... + //result=HandleStartToken(&theToken); } return result; @@ -648,6 +651,12 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ nsresult result= NS_OK; +/* if((kNoError==anErrorCode) && (!mHasOpenBody)) { + CStartToken theToken(eHTMLTag_body); //open the body container... + result=HandleStartToken(&theToken); + } +*/ + if((kNoError==anErrorCode) && (mBodyContext->mElements.mCount>0)) { result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE); } @@ -727,43 +736,45 @@ PRInt32 CNavDTD::DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag){ PRInt32 result=kNoError; CToken* theNextToken=mParser->PeekToken(); - switch(aChildTag){ - case eHTMLTag_pre: - case eHTMLTag_listing: - { - if(theNextToken) { - eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); - if(eToken_newline==theType){ + if(theNextToken){ + switch(aChildTag){ + case eHTMLTag_pre: + case eHTMLTag_listing: + { + if(theNextToken) { + eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); + if(eToken_newline==theType){ - switch(aChildTag){ - case eHTMLTag_pre: - case eHTMLTag_listing: - //we skip the first newline token inside PRE and LISTING - mParser->PopToken(); - break; - default: - break; - }//switch + switch(aChildTag){ + case eHTMLTag_pre: + case eHTMLTag_listing: + //we skip the first newline token inside PRE and LISTING + mParser->PopToken(); + break; + default: + break; + }//switch + }//if }//if - }//if - } - break; - - case eHTMLTag_plaintext: - case eHTMLTag_xmp: - //grab the skipped content and dump it out as text... - if(theNextToken){ - eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); - if(eToken_skippedcontent==theType){ - nsString& theText=((CAttributeToken*)theNextToken)->GetKey(); - CViewSourceHTML::WriteText(theText,*mSink,PR_TRUE); } - } - break; - default: - break; - }//switch + break; + + case eHTMLTag_plaintext: + case eHTMLTag_xmp: + //grab the skipped content and dump it out as text... + if(theNextToken){ + eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); + if(eToken_skippedcontent==theType){ + nsString& theText=((CAttributeToken*)theNextToken)->GetKey(); + CViewSourceHTML::WriteText(theText,*mSink,PR_TRUE); + } + } + break; + default: + break; + }//switch + } return result; } @@ -1320,7 +1331,7 @@ PRBool CNavDTD::CanContainStyles(eHTMLTags aParent) const { PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const { PRBool result=PR_FALSE; - if(!IsContainer(aParent)) + if((!IsContainer(aParent)) && (eHTMLTag_unknown!=aParent)) return result; @@ -2042,7 +2053,7 @@ PRBool CNavDTD::CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild) const { case eHTMLTag_html: case eHTMLTag_body: - result=HasOpenContainer(aChild); //don't bother if they're already open... + result=PR_TRUE; break; case eHTMLTag_newline: @@ -2747,6 +2758,7 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){ result=OpenHTML(aNode); break; case eHTMLTag_body: + mHasOpenBody=PR_TRUE; result=OpenBody(aNode); break; case eHTMLTag_style: diff --git a/parser/htmlparser/src/CNavDTD.h b/parser/htmlparser/src/CNavDTD.h index bd1fe2837b70..c27ec42312ad 100644 --- a/parser/htmlparser/src/CNavDTD.h +++ b/parser/htmlparser/src/CNavDTD.h @@ -619,6 +619,7 @@ protected: PRBool mHasOpenForm; PRBool mHasOpenMap; PRBool mHasOpenHead; + PRBool mHasOpenBody; nsDeque mTokenDeque; nsString mFilename; nsIDTDDebug* mDTDDebug; diff --git a/parser/htmlparser/src/nsParser.cpp b/parser/htmlparser/src/nsParser.cpp index a6aa3d887fee..81ab783f8a15 100644 --- a/parser/htmlparser/src/nsParser.cpp +++ b/parser/htmlparser/src/nsParser.cpp @@ -740,7 +740,10 @@ PRInt32 nsParser::BuildModel() { * @return ptr to token */ CToken* nsParser::PeekToken() { - CToken* theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); + CToken* theToken=0; + if(mParserContext) + if(mParserContext->mCurrentPos) + theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); return theToken; } @@ -752,8 +755,12 @@ CToken* nsParser::PeekToken() { * @return ptr to token or NULL */ CToken* nsParser::PopToken() { - CToken* theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); - ++(*mParserContext->mCurrentPos); + CToken* theToken=0; + if(mParserContext) + if(mParserContext->mCurrentPos) { + theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); + ++(*mParserContext->mCurrentPos); + } return theToken; }