diff --git a/mozilla/htmlparser/robot/nsDebugRobot.cpp b/mozilla/htmlparser/robot/nsDebugRobot.cpp index 08ec927cd77..c452bd8a0f0 100644 --- a/mozilla/htmlparser/robot/nsDebugRobot.cpp +++ b/mozilla/htmlparser/robot/nsDebugRobot.cpp @@ -238,7 +238,7 @@ extern "C" NS_EXPORT int DebugRobot( sink->AddObserver(myObserver); parser->SetContentSink(sink); - g_bReadyForNextUrl = PR_FALSE; + g_bReadyForNextUrl = PR_FALSE; parser->Parse(url, pl,PR_TRUE);/* XXX hook up stream listener here! */ while (!g_bReadyForNextUrl) { diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 304fd13f294..792e294e6f4 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -439,6 +439,9 @@ PRInt32 NavDispatchTokenHandler(CToken* aToken,nsIDTD* 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; @@ -446,12 +449,6 @@ PRInt32 NavDispatchTokenHandler(CToken* aToken,nsIDTD* aDTD) { result=theDTD->HandleCommentToken(aToken); break; case eToken_entity: result=theDTD->HandleEntityToken(aToken); break; - case eToken_whitespace: - result=theDTD->HandleStartToken(aToken); break; - case eToken_newline: - result=theDTD->HandleStartToken(aToken); break; - case eToken_text: - result=theDTD->HandleStartToken(aToken); break; case eToken_attribute: result=theDTD->HandleAttributeToken(aToken); break; case eToken_style: @@ -504,12 +501,11 @@ static CTokenDeallocator gTokenKiller; */ CNavDTD::CNavDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { NS_INIT_REFCNT(); - mParser=0; mSink = 0; + mParser=0; mDTDDebug=0; mLineNumber=1; mHasOpenBody=PR_FALSE; - mParseMode=eParseMode_navigator; nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers)); mHasOpenForm=PR_FALSE; mHasOpenMap=PR_FALSE; @@ -566,7 +562,7 @@ nsITokenRecycler* CNavDTD::GetTokenRecycler(void){ * @param * @return */ -PRBool CNavDTD::Verify(nsString& aURLRef){ +PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool result=PR_TRUE; if(!mDTDDebug){; @@ -578,7 +574,7 @@ PRBool CNavDTD::Verify(nsString& aURLRef){ else mDTDDebug->SetVerificationDirectory(kVerificationDir); } if(mDTDDebug) { - mDTDDebug->Verify(this,mParser,mBodyContext->mElements.mCount,mBodyContext->mElements.mTags,aURLRef); + mDTDDebug->Verify(this,aParser,mBodyContext->mElements.mCount,mBodyContext->mElements.mTags,aURLRef); } return result; } @@ -627,18 +623,20 @@ eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aTy * @param * @return */ -nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ 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); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + 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,7 +646,7 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ * @param * @return */ -nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result= NS_OK; /* if((kNoError==anErrorCode) && (!mHasOpenBody)) { @@ -657,16 +655,20 @@ nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ } */ - if((kNoError==anErrorCode) && (mBodyContext->mElements.mCount>0)) { - result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE); - } + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); - if((aNotifySink) && (mSink)) { - result = mSink->DidBuildModel(1); - } + if((kNoError==anErrorCode) && (mBodyContext->mElements.mCount>0)) { + result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE); + } - if(mDTDDebug) { - mDTDDebug->DumpVectorRecord(); + if((aNotifySink) && (mSink)) { + result = mSink->DidBuildModel(1); + } + + if(mDTDDebug) { + mDTDDebug->DumpVectorRecord(); + } } return result; } @@ -683,7 +685,7 @@ nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ * @param aParser * @return */ -nsresult CNavDTD::HandleToken(CToken* aToken){ +nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ nsresult result=NS_OK; if(aToken) { @@ -692,6 +694,8 @@ nsresult CNavDTD::HandleToken(CToken* aToken){ CITokenHandler* theHandler=GetTokenHandler(theType); if(theHandler) { + mParser=(nsParser*)aParser; + mSink=(nsIHTMLContentSink*)mParser->GetContentSink(); result=(*theHandler)(theToken,this); if (mDTDDebug) mDTDDebug->Verify(this, mParser, mBodyContext->mElements.mCount, mBodyContext->mElements.mTags, mFilename); @@ -1262,36 +1266,6 @@ CITokenHandler* CNavDTD::AddTokenHandler(CITokenHandler* aHandler) { return 0; } -/** - * The parser calls this method after it's selected - * an constructed a DTD. - * - * @update gess 3/25/98 - * @param aParser is a ptr to the controlling parser. - * @return nada - */ -void CNavDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; - if(aParser) - mParseMode=aParser->GetParseMode(); -// mParseMode=eParseMode_noquirks; -} - - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CNavDTD::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=(nsIHTMLContentSink*)aSink; - return old; -} - /** * This method is called to determine whether or not a tag @@ -3510,13 +3484,14 @@ nsresult CNavDTD::ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& aTo * @param anErrorCode: arg that will hold error condition * @return new token or null */ -nsresult CNavDTD::ConsumeToken(CToken*& aToken){ +nsresult CNavDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser){ aToken=0; if(mTokenDeque.GetSize()>0) { aToken=(CToken*)mTokenDeque.Pop(); return NS_OK; } + mParser=(nsParser*)aParser; nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ diff --git a/mozilla/htmlparser/src/CNavDTD.h b/mozilla/htmlparser/src/CNavDTD.h index c27ec42312a..d23f87244db 100644 --- a/mozilla/htmlparser/src/CNavDTD.h +++ b/mozilla/htmlparser/src/CNavDTD.h @@ -178,7 +178,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** @@ -189,7 +189,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -199,7 +199,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * This method is called by the parser, once for each token @@ -208,7 +208,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -228,17 +228,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * Set parser is called to notify the DTD which parser is driving - * the DTD. This is needed by the DTD later, for various parser - * callback methods. - * - * @update gess 3/25/98 - * @param aParser pts to the controlling parser - * @return nada. - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -247,7 +236,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -266,15 +255,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); - /** * This method is called to determine whether or not a tag * of one type can contain a tag of another type. @@ -437,29 +417,9 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const; - /** - * The following set of methods are used to partially construct - * the content model (via the sink) according to the type of token. - * @update gess5/11/98 - * @param aToken is the token (of a given type) to be handled - * @return error code representing construction state; usually 0. - */ - nsresult HandleStartToken(CToken* aToken); - nsresult HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode); - nsresult HandleEndToken(CToken* aToken); - nsresult HandleEntityToken(CToken* aToken); - nsresult HandleCommentToken(CToken* aToken); - nsresult HandleSkippedContentToken(CToken* aToken); - nsresult HandleAttributeToken(CToken* aToken); - nsresult HandleScriptToken(nsCParserNode& aNode); - nsresult HandleStyleToken(CToken* aToken); - nsresult HandleProcessingInstructionToken(CToken* aToken); virtual nsITokenRecycler* GetTokenRecycler(void); - -protected: - /** * The following methods are use to create and manage * the dynamic set of token handlers. @@ -471,6 +431,25 @@ protected: void DeleteTokenHandlers(void); + /** + * The following set of methods are used to partially construct + * the content model (via the sink) according to the type of token. + * @update gess5/11/98 + * @param aToken is the token (of a given type) to be handled + * @return error code representing construction state; usually 0. + */ + nsresult HandleStartToken(CToken* aToken); + nsresult HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode); + nsresult HandleEndToken(CToken* aToken); + nsresult HandleEntityToken(CToken* aToken); + nsresult HandleCommentToken(CToken* aToken); + nsresult HandleSkippedContentToken(CToken* aToken); + nsresult HandleAttributeToken(CToken* aToken); + nsresult HandleScriptToken(nsCParserNode& aNode); + nsresult HandleStyleToken(CToken* aToken); + nsresult HandleProcessingInstructionToken(CToken* aToken); + + //************************************************* //these cover methods mimic the sink, and are used //by the parser to manage its context-stack. @@ -606,7 +585,7 @@ protected: PRInt32 CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount); PRInt32 DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag); - nsParser* mParser; + nsIHTMLContentSink* mSink; CITokenHandler* mTokenHandlers[eToken_last]; @@ -624,7 +603,7 @@ protected: nsString mFilename; nsIDTDDebug* mDTDDebug; PRInt32 mLineNumber; - eParseMode mParseMode; + nsParser* mParser; }; extern NS_HTMLPARS nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult); diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index 260b6151b0e..f19a24f85eb 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -183,43 +183,6 @@ eAutoDetectResult COtherDTD::AutoDetectContentType(nsString& aBuffer,nsString& a } -/** - * - * @update gess5/18/98 - * @param - * @return - */ -NS_IMETHODIMP COtherDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink) { - return CNavDTD::WillBuildModel(aFilename, aNotifySink); -} - -/** - * - * @update gess5/18/98 - * @param - * @return - */ -NS_IMETHODIMP COtherDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ - return CNavDTD::DidBuildModel(anErrorCode, aNotifySink); -} - -/** - * 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 5/21/98 - * @param aType - * @param aToken - * @param aParser - * @return - */ -NS_IMETHODIMP COtherDTD::HandleToken(CToken* aToken){ - return CNavDTD::HandleToken(aToken); -} - - - /** * This method gets called when a start token has been * encountered in the parse process. If the current container @@ -863,22 +826,6 @@ nsresult COtherDTD::ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& a return CNavDTD::ConsumeNewline(aChar,aScanner,aToken); } -/** - * This method repeatedly called by the tokenizer. - * Each time, we determine the kind of token were about to - * read, and then we call the appropriate method to handle - * that token type. - * - * @update gess 3/25/98 - * @param aChar: last char read - * @param aScanner: see nsScanner.h - * @param anErrorCode: arg that will hold error condition - * @return new token or null - */ -nsresult COtherDTD::ConsumeToken(CToken*& aToken){ - return CNavDTD::ConsumeToken(aToken); -} - /** * diff --git a/mozilla/htmlparser/src/COtherDTD.h b/mozilla/htmlparser/src/COtherDTD.h index af8b7d129dc..e3ccac7099e 100644 --- a/mozilla/htmlparser/src/COtherDTD.h +++ b/mozilla/htmlparser/src/COtherDTD.h @@ -89,44 +89,6 @@ class COtherDTD : public CNavDTD { */ virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType); - /** - * The parser uses a code sandwich to wrap the parsing process. Before - * the process begins, WillBuildModel() is called. Afterwards the parser - * calls DidBuildModel(). - * @update gess5/18/98 - * @param aFilename is the name of the file being parsed. - * @return error code (almost always 0) - */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); - - /** - * The parser uses a code sandwich to wrap the parsing process. Before - * the process begins, WillBuildModel() is called. Afterwards the parser - * calls DidBuildModel(). - * @update gess5/18/98 - * @param anErrorCode contans the last error that occured - * @return error code - */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); - - /** - * - * @update gess 3/25/98 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ - NS_IMETHOD HandleToken(CToken* aToken); - - /** - * Cause the tokenizer to consume the next token, and - * return an error result. - * - * @update gess 3/25/98 - * @param anError -- ref to error code - * @return new token or null - */ - NS_IMETHOD ConsumeToken(CToken*& aToken); - /** * diff --git a/mozilla/htmlparser/src/CParserContext.cpp b/mozilla/htmlparser/src/CParserContext.cpp index 35eeff728d0..90b2cf9226a 100644 --- a/mozilla/htmlparser/src/CParserContext.cpp +++ b/mozilla/htmlparser/src/CParserContext.cpp @@ -78,7 +78,7 @@ CParserContext::~CParserContext(){ if(mTransferBuffer) delete [] mTransferBuffer; - NS_RELEASE(mDTD); + NS_IF_RELEASE(mDTD); //Remember that it's ok to simply ingore the PrevContext. diff --git a/mozilla/htmlparser/src/CRtfDTD.cpp b/mozilla/htmlparser/src/CRtfDTD.cpp index 5cec5b6eada..222cd980740 100644 --- a/mozilla/htmlparser/src/CRtfDTD.cpp +++ b/mozilla/htmlparser/src/CRtfDTD.cpp @@ -256,7 +256,7 @@ eAutoDetectResult CRtfDTD::AutoDetectContentType(nsString& aBuffer,nsString& aTy * @param * @return */ -NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel){ +NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel,nsIParser* aParser){ nsresult result=NS_OK; return result; } @@ -267,34 +267,12 @@ NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel){ * @param * @return */ -NS_IMETHODIMP CRtfDTD::DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel){ +NS_IMETHODIMP CRtfDTD::DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel,nsIParser* aParser){ nsresult result=NS_OK; return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CRtfDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CRtfDTD::SetContentSink(nsIContentSink* aSink) { - return 0; -} /******************************************************************* @@ -376,8 +354,9 @@ PRInt32 CRtfDTD::ConsumeContent(PRUnichar aChar,CToken*& aToken){ * @param anErrorCode: arg that will hold error condition * @return new token or null */ -nsresult CRtfDTD::ConsumeToken(CToken*& aToken){ - +nsresult CRtfDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser){ + + mParser=(nsParser*)aParser; CScanner* theScanner=mParser->GetScanner(); PRUnichar aChar; @@ -446,8 +425,9 @@ nsresult CRtfDTD::WillInterruptParse(void){ * @param * @return */ -PRBool CRtfDTD::Verify(nsString& aURLRef){ +PRBool CRtfDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -527,9 +507,10 @@ PRInt32 CRtfDTD::HandleContent(CToken* aToken){ * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -nsresult CRtfDTD::HandleToken(CToken* aToken) { +nsresult CRtfDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; + mParser=(nsParser*)aParser; if(aToken) { eRTFTokenTypes theType=eRTFTokenTypes(aToken->GetTokenType()); diff --git a/mozilla/htmlparser/src/CRtfDTD.h b/mozilla/htmlparser/src/CRtfDTD.h index cda5bacc648..55ffb3b4050 100644 --- a/mozilla/htmlparser/src/CRtfDTD.h +++ b/mozilla/htmlparser/src/CRtfDTD.h @@ -200,7 +200,7 @@ class CRtfDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRInt32 aLevel); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRInt32 aLevel,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -210,7 +210,7 @@ class CRtfDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel,nsIParser* aParser); /** * @@ -242,7 +242,7 @@ class CRtfDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -262,15 +262,7 @@ class CRtfDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - + /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -309,7 +301,7 @@ class CRtfDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -328,13 +320,6 @@ class CRtfDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); /** * Called by the parser to initiate dtd verification of the @@ -343,7 +328,7 @@ class CRtfDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its diff --git a/mozilla/htmlparser/src/nsDTDDebug.cpp b/mozilla/htmlparser/src/nsDTDDebug.cpp index 4f8b753b582..3e9a37f69da 100644 --- a/mozilla/htmlparser/src/nsDTDDebug.cpp +++ b/mozilla/htmlparser/src/nsDTDDebug.cpp @@ -67,7 +67,7 @@ public: void SetVerificationDirectory(char * verify_dir); void SetRecordStatistics(PRBool bval); - PRBool Verify(nsIDTD * aDTD, nsParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef); + PRBool Verify(nsIDTD * aDTD, nsIParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef); void DumpVectorRecord(void); // global table for storing vector statistics and the size @@ -469,12 +469,14 @@ void CDTDDebug::DumpVectorRecord(void) * @return TRUE if we know how to handle it, else false */ -PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsParser * aParser, int aContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) +PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsIParser * aParser, int aContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) { PRBool result=PR_TRUE; //ok, now see if we understand this vector + nsParser* theParser=(nsParser*)aParser; + if(0!=mVerificationDir || mRecordingStatistics) { if(aDTD && aContextStackPos>1) { @@ -536,8 +538,8 @@ PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsParser * aParser, int aContextStackPo // dump the html source into the newly created file. PRofstream ps; ps.attach(debugFile); - if (aParser) - aParser->DebugDumpSource(ps); + if (theParser) + theParser->DebugDumpSource(ps); PR_Close(debugFile); } } diff --git a/mozilla/htmlparser/src/nsIDTD.h b/mozilla/htmlparser/src/nsIDTD.h index a22dc0d92f7..b53ff24d8e3 100644 --- a/mozilla/htmlparser/src/nsIDTD.h +++ b/mozilla/htmlparser/src/nsIDTD.h @@ -39,7 +39,6 @@ class nsIParser; class CToken; -class nsIContentSink; class nsIDTDDebug; class nsIURL; class nsString; @@ -73,23 +72,6 @@ class nsIDTD : public nsISupports { */ virtual nsresult CreateNewInstance(nsIDTD** aInstancePtrResult)=0; - /** - * This method informs the DTD about the parser being used to drive the parse process - * - * @update gess 3/25/98 - * @param aParse -- ptr to parser object - * @return nada - */ - virtual void SetParser(nsIParser* aParser)=0; - - /** - * Select given content sink into DTD for output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink)=0; - /** * This method is called to determine if the given DTD can parse * a document in a given source-type. @@ -118,7 +100,7 @@ class nsIDTD : public nsISupports { * @param aFilename--string that contains name of file being parsed (if applicable) * @return */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink)=0; + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser)=0; /** * Called by the parser after the parsing process has concluded @@ -126,7 +108,7 @@ class nsIDTD : public nsISupports { * @param anErrorCode - contains error code resulting from parse process * @return */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink)=0; + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser)=0; /** * Called during model building phase of parse process. Each token created during @@ -137,7 +119,7 @@ class nsIDTD : public nsISupports { * @param aToken -- token object to be put into content model * @return error code (usually 0) */ - NS_IMETHOD HandleToken(CToken* aToken)=0; + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser)=0; /** * Cause the tokenizer to consume and create the next token, and @@ -147,7 +129,7 @@ class nsIDTD : public nsISupports { * @param aToken -- will contain newly created and consumed token * @return error code (usually 0) */ - NS_IMETHOD ConsumeToken(CToken*& aToken)=0; + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser)=0; /** * This method causes all tokens to be dispatched to the given tag handler. @@ -211,7 +193,7 @@ class nsIDTD : public nsISupports { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef)=0; + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser)=0; /** * Retrieve a ptr to the global token recycler... diff --git a/mozilla/htmlparser/src/nsIDTDDebug.h b/mozilla/htmlparser/src/nsIDTDDebug.h index 36d431d9858..390989d65a0 100644 --- a/mozilla/htmlparser/src/nsIDTDDebug.h +++ b/mozilla/htmlparser/src/nsIDTDDebug.h @@ -36,7 +36,7 @@ class nsIDTD; -class nsParser; +class nsIParser; class nsVoidArray; class nsIDTDDebug : public nsISupports { @@ -47,7 +47,7 @@ public: virtual void SetRecordStatistics(PRBool bval) = 0; - virtual PRBool Verify(nsIDTD * aDTD, nsParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) = 0; + virtual PRBool Verify(nsIDTD * aDTD, nsIParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) = 0; virtual void DumpVectorRecord(void) = 0; diff --git a/mozilla/htmlparser/src/nsIParser.h b/mozilla/htmlparser/src/nsIParser.h index 2c1d1dc6a3b..3c039101d8e 100644 --- a/mozilla/htmlparser/src/nsIParser.h +++ b/mozilla/htmlparser/src/nsIParser.h @@ -76,15 +76,23 @@ class nsIParser : public nsISupports { */ virtual void RegisterDTD(nsIDTD* aDTD)=0; + /** - * Call this method once you've created a parser, and want to instruct it - * where to send its output. - * - * @update gess 3/25/98 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * Select given content sink into parser for parser output + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aContentSink)=0; + virtual nsIContentSink* SetContentSink(nsIContentSink* aSink)=0; + + + /** + * retrive the sink set into the parser + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL + */ + virtual nsIContentSink* GetContentSink(void)=0; /** * Call this method once you've created a parser, and want to instruct it diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index 9c20c4ddc6a..10cdf055c8c 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -186,7 +186,7 @@ MakeConversionTable() * @param * @return */ -nsParser::nsParser() : mCommand() { +nsParser::nsParser() : mCommand("") { NS_INIT_REFCNT(); mStreamListenerState=eNone; mParserFilter = 0; @@ -309,6 +309,16 @@ nsIContentSink* nsParser::SetContentSink(nsIContentSink* aSink) { return old; } +/** + * retrive the sink set into the parser + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL + */ +nsIContentSink* nsParser::GetContentSink(void){ + return mSink; +} + /** * Call this static method when you want to * register your dynamic DTD's with the parser. @@ -367,8 +377,9 @@ eParseMode nsParser::GetParseMode(void){ PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand) { //Let's start by tring the defaultDTD, if one exists... - if(aParserContext.mDTD && (aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,0))) - return PR_TRUE; + if(aParserContext.mDTD) + if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,0)) + return PR_TRUE; PRBool result=PR_FALSE; @@ -475,17 +486,17 @@ eParseMode DetermineParseMode(nsParser& aParser) { * @param * @return error code -- 0 if ok, non-zero if error. */ -PRInt32 nsParser::WillBuildModel(nsString& aFilename){ +PRInt32 nsParser::WillBuildModel(nsString& aFilename,nsIDTD* aDefaultDTD){ mMajorIteration=-1; mMinorIteration=-1; PRInt32 result=kNoError; if(mParserContext){ mParserContext->mParseMode=DetermineParseMode(*this); + mParserContext->mDTD=aDefaultDTD; if(PR_TRUE==FindSuitableDTD(*mParserContext,mCommand)) { - mParserContext->mDTD->SetParser(this); - mParserContext->mDTD->SetContentSink(mSink); - mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext)); + //mParserContext->mDTD->SetContentSink(mSink); + mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext),this); } } else result=kInvalidParserContext; @@ -493,7 +504,9 @@ PRInt32 nsParser::WillBuildModel(nsString& aFilename){ } /** - * + * This gets called when the parser is done with its input. + * Note that the parser may have been called recursively, so we + * have to check for a prev. context before closing out the DTD/sink. * @update gess5/18/98 * @param * @return error code -- 0 if ok, non-zero if error. @@ -501,8 +514,9 @@ PRInt32 nsParser::WillBuildModel(nsString& aFilename){ PRInt32 nsParser::DidBuildModel(PRInt32 anErrorCode) { //One last thing...close any open containers. PRInt32 result=anErrorCode; - if(mParserContext->mDTD) { - result=mParserContext->mDTD->DidBuildModel(anErrorCode,PRBool(0==mParserContext->mPrevContext)); + + if((!mParserContext->mPrevContext) && (mParserContext->mDTD)) { + result=mParserContext->mDTD->DidBuildModel(anErrorCode,PRBool(0==mParserContext->mPrevContext),this); //Now recycle any tokens that are still hanging around. //Come to think of it, there really shouldn't be any. @@ -570,9 +584,6 @@ PRBool nsParser::EnableParser(PRBool aState){ * not have been consumed by the scanner during a given invocation * of this method. * - * NOTE: We don't call willbuildmodel here, because it will happen - * as a result of calling OnStartBinding later on. - * * @update gess 3/25/98 * @param aFilename -- const char* containing file to be parsed. * @return error code -- 0 if ok, non-zero if error. @@ -611,7 +622,7 @@ PRInt32 nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ mParserContext->mScanner->Eof(); if(eValidDetect==AutoDetectContentType(mParserContext->mScanner->GetBuffer(), mParserContext->mSourceType)) { - WillBuildModel(mParserContext->mScanner->GetFilename()); + WillBuildModel(mParserContext->mScanner->GetFilename(),0); status=ResumeParse(); DidBuildModel(status); } //if @@ -640,14 +651,17 @@ PRInt32 nsParser::Parse(nsString& aSourceBuffer,PRBool anHTMLString,PRBool aVeri if(0mDTD: 0; + PushContext(*pc); if(PR_TRUE==anHTMLString) pc->mSourceType="text/html"; if(eValidDetect==AutoDetectContentType(aSourceBuffer,mParserContext->mSourceType)) { - WillBuildModel(mParserContext->mScanner->GetFilename()); + WillBuildModel(mParserContext->mScanner->GetFilename(),thePrevDTD); result=ResumeParse(); DidBuildModel(result); } + mParserContext->mDTD=0; pc=PopContext(); delete pc; } @@ -707,9 +721,9 @@ PRInt32 nsParser::BuildModel() { CToken* theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); theMarkPos=*mParserContext->mCurrentPos; ++(*mParserContext->mCurrentPos); - result=theRootDTD->HandleToken(theToken); + result=theRootDTD->HandleToken(theToken,this); if(mDTDVerification) - theRootDTD->Verify(kEmptyString); + theRootDTD->Verify(kEmptyString,this); } //Now it's time to recycle our used tokens. @@ -906,7 +920,7 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt if(eUnknownDetect==mParserContext->mAutoDetectStatus) { if(eValidDetect==AutoDetectContentType(mParserContext->mScanner->GetBuffer(),mParserContext->mSourceType)) { - WillBuildModel(mParserContext->mScanner->GetFilename()); + WillBuildModel(mParserContext->mScanner->GetFilename(),0); } //if } } //if @@ -969,7 +983,7 @@ PRInt32 nsParser::Tokenize(){ WillTokenize(); while(kNoError==result) { mParserContext->mScanner->Mark(); - result=mParserContext->mDTD->ConsumeToken(theToken); + result=mParserContext->mDTD->ConsumeToken(theToken,this); if(kNoError==result) { if(theToken) { diff --git a/mozilla/htmlparser/src/nsParser.h b/mozilla/htmlparser/src/nsParser.h index bf491af9bba..f1366bf142d 100644 --- a/mozilla/htmlparser/src/nsParser.h +++ b/mozilla/htmlparser/src/nsParser.h @@ -98,6 +98,14 @@ friend class CTokenHandler; * @return old sink, or NULL */ virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); + + /** + * retrive the sink set into the parser + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL + */ + virtual nsIContentSink* GetContentSink(void); /** * Call this method once you've created a parser, and want to instruct it @@ -209,7 +217,7 @@ protected: * @param * @return */ - PRInt32 WillBuildModel(nsString& aFilename); + PRInt32 WillBuildModel(nsString& aFilename,nsIDTD* mDefaultDTD=0); /** * diff --git a/mozilla/htmlparser/src/nsValidDTD.cpp b/mozilla/htmlparser/src/nsValidDTD.cpp index acfafde44ae..1e4a8bf02c9 100644 --- a/mozilla/htmlparser/src/nsValidDTD.cpp +++ b/mozilla/htmlparser/src/nsValidDTD.cpp @@ -201,7 +201,7 @@ eAutoDetectResult CValidDTD::AutoDetectContentType(nsString& aBuffer,nsString& a * @param * @return */ -NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; return result; } @@ -212,35 +212,12 @@ NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ * @param * @return */ -NS_IMETHODIMP CValidDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +NS_IMETHODIMP CValidDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CValidDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CValidDTD::SetContentSink(nsIContentSink* aSink) { - return 0; -} - /******************************************************************* These methods use to be hidden in the tokenizer-delegate. @@ -260,8 +237,9 @@ nsIContentSink* CValidDTD::SetContentSink(nsIContentSink* aSink) { * @param anErrorCode: arg that will hold error condition * @return new token or null */ -NS_IMETHODIMP CValidDTD::ConsumeToken(CToken*& aToken){ - +NS_IMETHODIMP CValidDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser){ + + mParser=(nsParser*)aParser; CScanner* theScanner=mParser->GetScanner(); PRUnichar aChar; @@ -316,8 +294,9 @@ NS_IMETHODIMP CValidDTD::WillInterruptParse(void){ * @param * @return */ -PRBool CValidDTD::Verify(nsString& aURLRef){ +PRBool CValidDTD::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -364,8 +343,9 @@ PRBool CValidDTD::IsContainer(PRInt32 aTag) const{ * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -NS_IMETHODIMP CValidDTD::HandleToken(CToken* aToken) { +NS_IMETHODIMP CValidDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; + mParser=(nsParser*)aParser; return result; } diff --git a/mozilla/htmlparser/src/nsValidDTD.h b/mozilla/htmlparser/src/nsValidDTD.h index 6dd2b2aa7f3..e9778ae5ca8 100644 --- a/mozilla/htmlparser/src/nsValidDTD.h +++ b/mozilla/htmlparser/src/nsValidDTD.h @@ -118,7 +118,7 @@ class CValidDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -128,7 +128,7 @@ class CValidDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * @@ -136,7 +136,7 @@ class CValidDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** @@ -157,16 +157,6 @@ class CValidDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -175,7 +165,7 @@ class CValidDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -194,13 +184,6 @@ class CValidDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); /** * Called by the parser to initiate dtd verification of the @@ -209,7 +192,7 @@ class CValidDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/htmlparser/src/nsViewSourceHTML.cpp index b24d371d147..010884c2ba0 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/htmlparser/src/nsViewSourceHTML.cpp @@ -256,34 +256,33 @@ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsStr * @param * @return */ -NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; mFilename=aFilename; - if((aNotifySink) && (mSink)) { - mLineNumber=0; - result = mSink->WillBuildModel(); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { + mLineNumber=0; + result = mSink->WillBuildModel(); - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ - mIsHTML=(0OpenHTML(theHTMLNode); + mSink->OpenHTML(theHTMLNode); //now let's automatically open the body... CStartToken theBodyToken(eHTMLTag_body); nsCParserNode theBodyNode(&theBodyToken,0); - theSink->OpenBody(theBodyNode); + mSink->OpenBody(theBodyNode); + + SetFont("courier","-1",PR_TRUE,*mSink); + } - - SetFont("courier","-1",PR_TRUE,*mSink); - } - return result; } @@ -293,61 +292,33 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify * @param * @return */ -NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result= NS_OK; //ADD CODE HERE TO CLOSE OPEN CONTAINERS... - if((aNotifySink) && (mSink)) { - - { - nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink; - + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { //now let's automatically close the pre... SetStyle(eHTMLTag_font,PR_FALSE,*mSink); - + //now let's automatically close the body... CEndToken theBodyToken(eHTMLTag_body); nsCParserNode theBodyNode(&theBodyToken,0); - theSink->CloseBody(theBodyNode); + mSink->CloseBody(theBodyNode); //now let's automatically close the html... CEndToken theHTMLToken(eHTMLTag_html); nsCParserNode theHTMLNode(&theBodyToken,0); - theSink->CloseHTML(theBodyNode); + mSink->CloseHTML(theBodyNode); + result = mSink->DidBuildModel(1); } - - result = mSink->DidBuildModel(1); - } return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CViewSourceHTML::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CViewSourceHTML::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=aSink; - return old; -} static eHTMLTags gSkippedContentTags[]={ eHTMLTag_script, eHTMLTag_style, eHTMLTag_title, eHTMLTag_textarea}; @@ -626,13 +597,15 @@ NS_IMETHODIMP CViewSourceHTML::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CTo * @param anErrorCode: arg that will hold error condition * @return new token or null */ -NS_IMETHODIMP CViewSourceHTML::ConsumeToken(CToken*& aToken){ +NS_IMETHODIMP CViewSourceHTML::ConsumeToken(CToken*& aToken,nsIParser* aParser) { aToken=0; if(mTokenDeque.GetSize()>0) { aToken=(CToken*)mTokenDeque.Pop(); return NS_OK; } + mParser=(nsParser*)aParser; + nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ @@ -721,8 +694,9 @@ NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(void){ * @param * @return */ -PRBool CViewSourceHTML::Verify(nsString& aURLRef){ +PRBool CViewSourceHTML::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -930,12 +904,14 @@ PRBool WriteTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken,PRB * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken) { +NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType(); PRBool theEndTag=PR_TRUE; + mParser=(nsParser*)aParser; + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); nsCParserNode theNode(theToken,mLineNumber); switch(theType) { diff --git a/mozilla/htmlparser/src/nsViewSourceHTML.h b/mozilla/htmlparser/src/nsViewSourceHTML.h index 40cc5dbf25f..0f656b5136a 100644 --- a/mozilla/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/htmlparser/src/nsViewSourceHTML.h @@ -33,13 +33,13 @@ #include "nshtmlpars.h" #include "nsVoidArray.h" #include "nsDeque.h" +#include "nsIHTMLContentSink.h" #define NS_VIEWSOURCE_HTML_IID \ {0xb6003010, 0x7932, 0x11d2, \ {0x80, 0x1b, 0x0, 0x60, 0x8, 0xbf, 0xc4, 0x89 }} -class nsIHTMLContentSink; class nsIDTDDebug; class nsIParserNode; class CITokenHandler; @@ -108,7 +108,7 @@ class CViewSourceHTML: public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -118,7 +118,7 @@ class CViewSourceHTML: public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * @@ -126,16 +126,7 @@ class CViewSourceHTML: public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); - - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * Cause the tokenizer to consume the next token, and @@ -145,7 +136,7 @@ class CViewSourceHTML: public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -181,13 +172,6 @@ class CViewSourceHTML: public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); /** * Called by the parser to initiate dtd verification of the @@ -196,7 +180,7 @@ class CViewSourceHTML: public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its @@ -249,7 +233,7 @@ protected: NS_IMETHODIMP ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken); nsParser* mParser; - nsIContentSink* mSink; + nsIHTMLContentSink* mSink; nsString mFilename; PRInt32 mLineNumber; nsDeque mTokenDeque; diff --git a/mozilla/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/htmlparser/src/nsWellFormedDTD.cpp index e0fd2c45b47..8f89f460699 100644 --- a/mozilla/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/htmlparser/src/nsWellFormedDTD.cpp @@ -196,31 +196,33 @@ eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsStri * @param * @return */ -NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; mFilename=aFilename; - if((aNotifySink) && (mSink)) { - mLineNumber=0; - result = mSink->WillBuildModel(); + if(aParser){ + mSink=aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { + mLineNumber=0; + result = mSink->WillBuildModel(); -#if 0 - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ - { - nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink; + #if 0 + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + { - //now let's automatically open the html... - CStartToken theHTMLToken(eHTMLTag_html); - nsCParserNode theHTMLNode(&theHTMLToken,0); - theSink->OpenHTML(theHTMLNode); + //now let's automatically open the html... + CStartToken theHTMLToken(eHTMLTag_html); + nsCParserNode theHTMLNode(&theHTMLToken,0); + mSink->OpenHTML(theHTMLNode); - //now let's automatically open the body... - CStartToken theBodyToken(eHTMLTag_body); - nsCParserNode theBodyNode(&theBodyToken,0); - theSink->OpenBody(theBodyNode); + //now let's automatically open the body... + CStartToken theBodyToken(eHTMLTag_body); + nsCParserNode theBodyNode(&theBodyToken,0); + mSink->OpenBody(theBodyNode); + } + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + #endif } - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ -#endif } return result; @@ -232,61 +234,39 @@ NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifyS * @param * @return */ -NS_IMETHODIMP CWellFormedDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +NS_IMETHODIMP CWellFormedDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result= NS_OK; //ADD CODE HERE TO CLOSE OPEN CONTAINERS... - if((aNotifySink) && (mSink)) { - result = mSink->DidBuildModel(1); + if(aParser){ + mSink=aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { + result = mSink->DidBuildModel(1); -#if 0 - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ - { - nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink; + #if 0 + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + { + nsIHTMLContentSink* mSink=(nsIHTMLContentSink*)mSink; - //now let's automatically open the body... - CEndToken theBodyToken(eHTMLTag_body); - nsCParserNode theBodyNode(&theBodyToken,0); - theSink->CloseBody(theBodyNode); + //now let's automatically open the body... + CEndToken theBodyToken(eHTMLTag_body); + nsCParserNode theBodyNode(&theBodyToken,0); + mSink->CloseBody(theBodyNode); - //now let's automatically open the html... - CEndToken theHTMLToken(eHTMLTag_html); - nsCParserNode theHTMLNode(&theBodyToken,0); - theSink->CloseHTML(theBodyNode); + //now let's automatically open the html... + CEndToken theHTMLToken(eHTMLTag_html); + nsCParserNode theHTMLNode(&theBodyToken,0); + mSink->CloseHTML(theBodyNode); + } + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + #endif } - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ -#endif } return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CWellFormedDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CWellFormedDTD::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=aSink; - return old; -} - static eHTMLTags gSkippedContentTags[]={ eHTMLTag_script, eHTMLTag_style, eHTMLTag_title, eHTMLTag_textarea}; @@ -339,6 +319,7 @@ NS_IMETHODIMP CWellFormedDTD::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner */ NS_IMETHODIMP CWellFormedDTD::ConsumeText(const nsString& aString,CScanner& aScanner,CToken*& aToken){ nsresult result=NS_OK; + aToken=gTokenRecycler.CreateTokenOfType(eToken_text,eHTMLTag_text,aString); if(aToken) { PRUnichar ch=0; @@ -632,13 +613,14 @@ NS_IMETHODIMP CWellFormedDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CTok * @param anErrorCode: arg that will hold error condition * @return new token or null */ -NS_IMETHODIMP CWellFormedDTD::ConsumeToken(CToken*& aToken){ +NS_IMETHODIMP CWellFormedDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser) { aToken=0; if(mTokenDeque.GetSize()>0) { aToken=(CToken*)mTokenDeque.Pop(); return NS_OK; } + mParser=(nsParser*)aParser; nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ @@ -727,8 +709,9 @@ NS_IMETHODIMP CWellFormedDTD::WillInterruptParse(void){ * @param * @return */ -PRBool CWellFormedDTD::Verify(nsString& aURLRef){ +PRBool CWellFormedDTD::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -775,11 +758,14 @@ PRBool CWellFormedDTD::IsContainer(PRInt32 aTag) const{ * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken) { +NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType(); + mParser=(nsParser*)aParser; + mSink=aParser->GetContentSink(); + nsCParserNode theNode(theToken,mLineNumber); switch(theType) { diff --git a/mozilla/htmlparser/src/nsWellFormedDTD.h b/mozilla/htmlparser/src/nsWellFormedDTD.h index 6707d74d7e5..171d3b99fe6 100644 --- a/mozilla/htmlparser/src/nsWellFormedDTD.h +++ b/mozilla/htmlparser/src/nsWellFormedDTD.h @@ -33,13 +33,13 @@ #include "nshtmlpars.h" #include "nsVoidArray.h" #include "nsDeque.h" +#include "nsIContentSink.h" #define NS_WELLFORMED_DTD_IID \ {0xa39c6bfd, 0x15f0, 0x11d2, \ {0x80, 0x41, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4}} -class nsIHTMLContentSink; class nsIDTDDebug; class nsIParserNode; class CITokenHandler; @@ -108,7 +108,7 @@ class CWellFormedDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -118,7 +118,7 @@ class CWellFormedDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * @@ -126,7 +126,7 @@ class CWellFormedDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -146,15 +146,6 @@ class CWellFormedDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -163,7 +154,7 @@ class CWellFormedDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -182,14 +173,6 @@ class CWellFormedDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); - /** * Called by the parser to initiate dtd verification of the * internal context stack. @@ -197,7 +180,7 @@ class CWellFormedDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its diff --git a/mozilla/htmlparser/src/nsXIFDTD.cpp b/mozilla/htmlparser/src/nsXIFDTD.cpp index 77867a5b530..2c80cfbb40d 100644 --- a/mozilla/htmlparser/src/nsXIFDTD.cpp +++ b/mozilla/htmlparser/src/nsXIFDTD.cpp @@ -407,14 +407,15 @@ eAutoDetectResult nsXIFDTD::AutoDetectContentType(nsString& aBuffer,nsString& aT * @param * @return */ -nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink){ +nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; - if(mSink) - { - mSink->WillBuildModel(); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if(mSink) { + mSink->WillBuildModel(); + } } - return result; } @@ -424,12 +425,14 @@ nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink){ * @param * @return */ -nsresult nsXIFDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +nsresult nsXIFDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; - if(mSink) - { - result = mSink->DidBuildModel(anErrorCode); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if(mSink) { + mSink->DidBuildModel(anErrorCode); + } } return result; @@ -447,9 +450,12 @@ nsresult nsXIFDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ * @param aParser * @return */ -nsresult nsXIFDTD::HandleToken(CToken* aToken){ +nsresult nsXIFDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; + mParser=(nsParser*)aParser; + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); //this can change in the parser between calls. + if(aToken) { CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType()); @@ -796,33 +802,6 @@ CTokenHandler* nsXIFDTD::AddTokenHandler(CTokenHandler* aHandler) { return 0; } -/** - * - * - * @update gpk 06/18/98 - * @param - * @return - */ -void nsXIFDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gpk 06/18/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* nsXIFDTD::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=(nsIHTMLContentSink*)aSink; - - - return old; -} - /** * This method gets called to determine whether a given @@ -1658,7 +1637,7 @@ PRInt32 nsXIFDTD::ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& aTo * @param anErrorCode: arg that will hold error condition * @return new token or null */ -nsresult nsXIFDTD::ConsumeToken(CToken*& aToken){ +nsresult nsXIFDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser) { aToken=0; if(mTokenDeque.GetSize()>0) { @@ -1666,6 +1645,8 @@ nsresult nsXIFDTD::ConsumeToken(CToken*& aToken){ return kNoError; } + mParser=(nsParser*)aParser; + nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ @@ -1854,8 +1835,9 @@ void nsXIFDTD::SetVerification(PRBool aEnabled){ * @param * @return */ -PRBool nsXIFDTD::Verify(nsString& aURLRef){ +PRBool nsXIFDTD::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } diff --git a/mozilla/htmlparser/src/nsXIFDTD.h b/mozilla/htmlparser/src/nsXIFDTD.h index 454fd1a7126..949150d75f7 100644 --- a/mozilla/htmlparser/src/nsXIFDTD.h +++ b/mozilla/htmlparser/src/nsXIFDTD.h @@ -161,7 +161,7 @@ class nsXIFDTD : public nsIDTD { * @param * @return */ - NS_IMETHOD WillBuildModel(nsString& aFileName,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsIParser* aParser); /** * @@ -169,7 +169,7 @@ class nsXIFDTD : public nsIDTD { * @param * @return */ - NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel,PRBool aNotifySink,nsIParser* aParser); /** * @@ -177,7 +177,7 @@ class nsXIFDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -197,15 +197,6 @@ class nsXIFDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * - * - * @update gpk 06/18/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -214,7 +205,7 @@ class nsXIFDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -267,7 +258,7 @@ class nsXIFDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its @@ -278,14 +269,6 @@ class nsXIFDTD : public nsIDTD { */ virtual void SetVerification(PRBool aEnable); - /** - * Select given content sink into parser for parser output - * @update gpk 06/18/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); - /** * This method is called to determine whether or not a tag diff --git a/mozilla/parser/htmlparser/robot/nsDebugRobot.cpp b/mozilla/parser/htmlparser/robot/nsDebugRobot.cpp index 08ec927cd77..c452bd8a0f0 100644 --- a/mozilla/parser/htmlparser/robot/nsDebugRobot.cpp +++ b/mozilla/parser/htmlparser/robot/nsDebugRobot.cpp @@ -238,7 +238,7 @@ extern "C" NS_EXPORT int DebugRobot( sink->AddObserver(myObserver); parser->SetContentSink(sink); - g_bReadyForNextUrl = PR_FALSE; + g_bReadyForNextUrl = PR_FALSE; parser->Parse(url, pl,PR_TRUE);/* XXX hook up stream listener here! */ while (!g_bReadyForNextUrl) { diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index 304fd13f294..792e294e6f4 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -439,6 +439,9 @@ PRInt32 NavDispatchTokenHandler(CToken* aToken,nsIDTD* 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; @@ -446,12 +449,6 @@ PRInt32 NavDispatchTokenHandler(CToken* aToken,nsIDTD* aDTD) { result=theDTD->HandleCommentToken(aToken); break; case eToken_entity: result=theDTD->HandleEntityToken(aToken); break; - case eToken_whitespace: - result=theDTD->HandleStartToken(aToken); break; - case eToken_newline: - result=theDTD->HandleStartToken(aToken); break; - case eToken_text: - result=theDTD->HandleStartToken(aToken); break; case eToken_attribute: result=theDTD->HandleAttributeToken(aToken); break; case eToken_style: @@ -504,12 +501,11 @@ static CTokenDeallocator gTokenKiller; */ CNavDTD::CNavDTD() : nsIDTD(), mTokenDeque(gTokenKiller) { NS_INIT_REFCNT(); - mParser=0; mSink = 0; + mParser=0; mDTDDebug=0; mLineNumber=1; mHasOpenBody=PR_FALSE; - mParseMode=eParseMode_navigator; nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers)); mHasOpenForm=PR_FALSE; mHasOpenMap=PR_FALSE; @@ -566,7 +562,7 @@ nsITokenRecycler* CNavDTD::GetTokenRecycler(void){ * @param * @return */ -PRBool CNavDTD::Verify(nsString& aURLRef){ +PRBool CNavDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool result=PR_TRUE; if(!mDTDDebug){; @@ -578,7 +574,7 @@ PRBool CNavDTD::Verify(nsString& aURLRef){ else mDTDDebug->SetVerificationDirectory(kVerificationDir); } if(mDTDDebug) { - mDTDDebug->Verify(this,mParser,mBodyContext->mElements.mCount,mBodyContext->mElements.mTags,aURLRef); + mDTDDebug->Verify(this,aParser,mBodyContext->mElements.mCount,mBodyContext->mElements.mTags,aURLRef); } return result; } @@ -627,18 +623,20 @@ eAutoDetectResult CNavDTD::AutoDetectContentType(nsString& aBuffer,nsString& aTy * @param * @return */ -nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ 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); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + 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,7 +646,7 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ * @param * @return */ -nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result= NS_OK; /* if((kNoError==anErrorCode) && (!mHasOpenBody)) { @@ -657,16 +655,20 @@ nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ } */ - if((kNoError==anErrorCode) && (mBodyContext->mElements.mCount>0)) { - result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE); - } + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); - if((aNotifySink) && (mSink)) { - result = mSink->DidBuildModel(1); - } + if((kNoError==anErrorCode) && (mBodyContext->mElements.mCount>0)) { + result = CloseContainersTo(0,eHTMLTag_unknown,PR_FALSE); + } - if(mDTDDebug) { - mDTDDebug->DumpVectorRecord(); + if((aNotifySink) && (mSink)) { + result = mSink->DidBuildModel(1); + } + + if(mDTDDebug) { + mDTDDebug->DumpVectorRecord(); + } } return result; } @@ -683,7 +685,7 @@ nsresult CNavDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ * @param aParser * @return */ -nsresult CNavDTD::HandleToken(CToken* aToken){ +nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){ nsresult result=NS_OK; if(aToken) { @@ -692,6 +694,8 @@ nsresult CNavDTD::HandleToken(CToken* aToken){ CITokenHandler* theHandler=GetTokenHandler(theType); if(theHandler) { + mParser=(nsParser*)aParser; + mSink=(nsIHTMLContentSink*)mParser->GetContentSink(); result=(*theHandler)(theToken,this); if (mDTDDebug) mDTDDebug->Verify(this, mParser, mBodyContext->mElements.mCount, mBodyContext->mElements.mTags, mFilename); @@ -1262,36 +1266,6 @@ CITokenHandler* CNavDTD::AddTokenHandler(CITokenHandler* aHandler) { return 0; } -/** - * The parser calls this method after it's selected - * an constructed a DTD. - * - * @update gess 3/25/98 - * @param aParser is a ptr to the controlling parser. - * @return nada - */ -void CNavDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; - if(aParser) - mParseMode=aParser->GetParseMode(); -// mParseMode=eParseMode_noquirks; -} - - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CNavDTD::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=(nsIHTMLContentSink*)aSink; - return old; -} - /** * This method is called to determine whether or not a tag @@ -3510,13 +3484,14 @@ nsresult CNavDTD::ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& aTo * @param anErrorCode: arg that will hold error condition * @return new token or null */ -nsresult CNavDTD::ConsumeToken(CToken*& aToken){ +nsresult CNavDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser){ aToken=0; if(mTokenDeque.GetSize()>0) { aToken=(CToken*)mTokenDeque.Pop(); return NS_OK; } + mParser=(nsParser*)aParser; nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ diff --git a/mozilla/parser/htmlparser/src/CNavDTD.h b/mozilla/parser/htmlparser/src/CNavDTD.h index c27ec42312a..d23f87244db 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.h +++ b/mozilla/parser/htmlparser/src/CNavDTD.h @@ -178,7 +178,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** @@ -189,7 +189,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -199,7 +199,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * This method is called by the parser, once for each token @@ -208,7 +208,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -228,17 +228,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * Set parser is called to notify the DTD which parser is driving - * the DTD. This is needed by the DTD later, for various parser - * callback methods. - * - * @update gess 3/25/98 - * @param aParser pts to the controlling parser - * @return nada. - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -247,7 +236,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -266,15 +255,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); - /** * This method is called to determine whether or not a tag * of one type can contain a tag of another type. @@ -437,29 +417,9 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { */ virtual PRInt32 GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const; - /** - * The following set of methods are used to partially construct - * the content model (via the sink) according to the type of token. - * @update gess5/11/98 - * @param aToken is the token (of a given type) to be handled - * @return error code representing construction state; usually 0. - */ - nsresult HandleStartToken(CToken* aToken); - nsresult HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode); - nsresult HandleEndToken(CToken* aToken); - nsresult HandleEntityToken(CToken* aToken); - nsresult HandleCommentToken(CToken* aToken); - nsresult HandleSkippedContentToken(CToken* aToken); - nsresult HandleAttributeToken(CToken* aToken); - nsresult HandleScriptToken(nsCParserNode& aNode); - nsresult HandleStyleToken(CToken* aToken); - nsresult HandleProcessingInstructionToken(CToken* aToken); virtual nsITokenRecycler* GetTokenRecycler(void); - -protected: - /** * The following methods are use to create and manage * the dynamic set of token handlers. @@ -471,6 +431,25 @@ protected: void DeleteTokenHandlers(void); + /** + * The following set of methods are used to partially construct + * the content model (via the sink) according to the type of token. + * @update gess5/11/98 + * @param aToken is the token (of a given type) to be handled + * @return error code representing construction state; usually 0. + */ + nsresult HandleStartToken(CToken* aToken); + nsresult HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsIParserNode& aNode); + nsresult HandleEndToken(CToken* aToken); + nsresult HandleEntityToken(CToken* aToken); + nsresult HandleCommentToken(CToken* aToken); + nsresult HandleSkippedContentToken(CToken* aToken); + nsresult HandleAttributeToken(CToken* aToken); + nsresult HandleScriptToken(nsCParserNode& aNode); + nsresult HandleStyleToken(CToken* aToken); + nsresult HandleProcessingInstructionToken(CToken* aToken); + + //************************************************* //these cover methods mimic the sink, and are used //by the parser to manage its context-stack. @@ -606,7 +585,7 @@ protected: PRInt32 CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount); PRInt32 DidHandleStartTag(CToken* aToken,eHTMLTags aChildTag); - nsParser* mParser; + nsIHTMLContentSink* mSink; CITokenHandler* mTokenHandlers[eToken_last]; @@ -624,7 +603,7 @@ protected: nsString mFilename; nsIDTDDebug* mDTDDebug; PRInt32 mLineNumber; - eParseMode mParseMode; + nsParser* mParser; }; extern NS_HTMLPARS nsresult NS_NewNavHTMLDTD(nsIDTD** aInstancePtrResult); diff --git a/mozilla/parser/htmlparser/src/COtherDTD.cpp b/mozilla/parser/htmlparser/src/COtherDTD.cpp index 260b6151b0e..f19a24f85eb 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.cpp +++ b/mozilla/parser/htmlparser/src/COtherDTD.cpp @@ -183,43 +183,6 @@ eAutoDetectResult COtherDTD::AutoDetectContentType(nsString& aBuffer,nsString& a } -/** - * - * @update gess5/18/98 - * @param - * @return - */ -NS_IMETHODIMP COtherDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink) { - return CNavDTD::WillBuildModel(aFilename, aNotifySink); -} - -/** - * - * @update gess5/18/98 - * @param - * @return - */ -NS_IMETHODIMP COtherDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ - return CNavDTD::DidBuildModel(anErrorCode, aNotifySink); -} - -/** - * 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 5/21/98 - * @param aType - * @param aToken - * @param aParser - * @return - */ -NS_IMETHODIMP COtherDTD::HandleToken(CToken* aToken){ - return CNavDTD::HandleToken(aToken); -} - - - /** * This method gets called when a start token has been * encountered in the parse process. If the current container @@ -863,22 +826,6 @@ nsresult COtherDTD::ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& a return CNavDTD::ConsumeNewline(aChar,aScanner,aToken); } -/** - * This method repeatedly called by the tokenizer. - * Each time, we determine the kind of token were about to - * read, and then we call the appropriate method to handle - * that token type. - * - * @update gess 3/25/98 - * @param aChar: last char read - * @param aScanner: see nsScanner.h - * @param anErrorCode: arg that will hold error condition - * @return new token or null - */ -nsresult COtherDTD::ConsumeToken(CToken*& aToken){ - return CNavDTD::ConsumeToken(aToken); -} - /** * diff --git a/mozilla/parser/htmlparser/src/COtherDTD.h b/mozilla/parser/htmlparser/src/COtherDTD.h index af8b7d129dc..e3ccac7099e 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.h +++ b/mozilla/parser/htmlparser/src/COtherDTD.h @@ -89,44 +89,6 @@ class COtherDTD : public CNavDTD { */ virtual eAutoDetectResult AutoDetectContentType(nsString& aBuffer,nsString& aType); - /** - * The parser uses a code sandwich to wrap the parsing process. Before - * the process begins, WillBuildModel() is called. Afterwards the parser - * calls DidBuildModel(). - * @update gess5/18/98 - * @param aFilename is the name of the file being parsed. - * @return error code (almost always 0) - */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); - - /** - * The parser uses a code sandwich to wrap the parsing process. Before - * the process begins, WillBuildModel() is called. Afterwards the parser - * calls DidBuildModel(). - * @update gess5/18/98 - * @param anErrorCode contans the last error that occured - * @return error code - */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); - - /** - * - * @update gess 3/25/98 - * @param aToken -- token object to be put into content model - * @return 0 if all is well; non-zero is an error - */ - NS_IMETHOD HandleToken(CToken* aToken); - - /** - * Cause the tokenizer to consume the next token, and - * return an error result. - * - * @update gess 3/25/98 - * @param anError -- ref to error code - * @return new token or null - */ - NS_IMETHOD ConsumeToken(CToken*& aToken); - /** * diff --git a/mozilla/parser/htmlparser/src/CParserContext.cpp b/mozilla/parser/htmlparser/src/CParserContext.cpp index 35eeff728d0..90b2cf9226a 100644 --- a/mozilla/parser/htmlparser/src/CParserContext.cpp +++ b/mozilla/parser/htmlparser/src/CParserContext.cpp @@ -78,7 +78,7 @@ CParserContext::~CParserContext(){ if(mTransferBuffer) delete [] mTransferBuffer; - NS_RELEASE(mDTD); + NS_IF_RELEASE(mDTD); //Remember that it's ok to simply ingore the PrevContext. diff --git a/mozilla/parser/htmlparser/src/CRtfDTD.cpp b/mozilla/parser/htmlparser/src/CRtfDTD.cpp index 5cec5b6eada..222cd980740 100644 --- a/mozilla/parser/htmlparser/src/CRtfDTD.cpp +++ b/mozilla/parser/htmlparser/src/CRtfDTD.cpp @@ -256,7 +256,7 @@ eAutoDetectResult CRtfDTD::AutoDetectContentType(nsString& aBuffer,nsString& aTy * @param * @return */ -NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel){ +NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel,nsIParser* aParser){ nsresult result=NS_OK; return result; } @@ -267,34 +267,12 @@ NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRInt32 aLevel){ * @param * @return */ -NS_IMETHODIMP CRtfDTD::DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel){ +NS_IMETHODIMP CRtfDTD::DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel,nsIParser* aParser){ nsresult result=NS_OK; return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CRtfDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CRtfDTD::SetContentSink(nsIContentSink* aSink) { - return 0; -} /******************************************************************* @@ -376,8 +354,9 @@ PRInt32 CRtfDTD::ConsumeContent(PRUnichar aChar,CToken*& aToken){ * @param anErrorCode: arg that will hold error condition * @return new token or null */ -nsresult CRtfDTD::ConsumeToken(CToken*& aToken){ - +nsresult CRtfDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser){ + + mParser=(nsParser*)aParser; CScanner* theScanner=mParser->GetScanner(); PRUnichar aChar; @@ -446,8 +425,9 @@ nsresult CRtfDTD::WillInterruptParse(void){ * @param * @return */ -PRBool CRtfDTD::Verify(nsString& aURLRef){ +PRBool CRtfDTD::Verify(nsString& aURLRef,nsIParser* aParser){ PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -527,9 +507,10 @@ PRInt32 CRtfDTD::HandleContent(CToken* aToken){ * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -nsresult CRtfDTD::HandleToken(CToken* aToken) { +nsresult CRtfDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; + mParser=(nsParser*)aParser; if(aToken) { eRTFTokenTypes theType=eRTFTokenTypes(aToken->GetTokenType()); diff --git a/mozilla/parser/htmlparser/src/CRtfDTD.h b/mozilla/parser/htmlparser/src/CRtfDTD.h index cda5bacc648..55ffb3b4050 100644 --- a/mozilla/parser/htmlparser/src/CRtfDTD.h +++ b/mozilla/parser/htmlparser/src/CRtfDTD.h @@ -200,7 +200,7 @@ class CRtfDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRInt32 aLevel); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRInt32 aLevel,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -210,7 +210,7 @@ class CRtfDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRInt32 aLevel,nsIParser* aParser); /** * @@ -242,7 +242,7 @@ class CRtfDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -262,15 +262,7 @@ class CRtfDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - + /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -309,7 +301,7 @@ class CRtfDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -328,13 +320,6 @@ class CRtfDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); /** * Called by the parser to initiate dtd verification of the @@ -343,7 +328,7 @@ class CRtfDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its diff --git a/mozilla/parser/htmlparser/src/nsDTDDebug.cpp b/mozilla/parser/htmlparser/src/nsDTDDebug.cpp index 4f8b753b582..3e9a37f69da 100644 --- a/mozilla/parser/htmlparser/src/nsDTDDebug.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDDebug.cpp @@ -67,7 +67,7 @@ public: void SetVerificationDirectory(char * verify_dir); void SetRecordStatistics(PRBool bval); - PRBool Verify(nsIDTD * aDTD, nsParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef); + PRBool Verify(nsIDTD * aDTD, nsIParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef); void DumpVectorRecord(void); // global table for storing vector statistics and the size @@ -469,12 +469,14 @@ void CDTDDebug::DumpVectorRecord(void) * @return TRUE if we know how to handle it, else false */ -PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsParser * aParser, int aContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) +PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsIParser * aParser, int aContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) { PRBool result=PR_TRUE; //ok, now see if we understand this vector + nsParser* theParser=(nsParser*)aParser; + if(0!=mVerificationDir || mRecordingStatistics) { if(aDTD && aContextStackPos>1) { @@ -536,8 +538,8 @@ PRBool CDTDDebug::Verify(nsIDTD * aDTD, nsParser * aParser, int aContextStackPo // dump the html source into the newly created file. PRofstream ps; ps.attach(debugFile); - if (aParser) - aParser->DebugDumpSource(ps); + if (theParser) + theParser->DebugDumpSource(ps); PR_Close(debugFile); } } diff --git a/mozilla/parser/htmlparser/src/nsIDTD.h b/mozilla/parser/htmlparser/src/nsIDTD.h index a22dc0d92f7..b53ff24d8e3 100644 --- a/mozilla/parser/htmlparser/src/nsIDTD.h +++ b/mozilla/parser/htmlparser/src/nsIDTD.h @@ -39,7 +39,6 @@ class nsIParser; class CToken; -class nsIContentSink; class nsIDTDDebug; class nsIURL; class nsString; @@ -73,23 +72,6 @@ class nsIDTD : public nsISupports { */ virtual nsresult CreateNewInstance(nsIDTD** aInstancePtrResult)=0; - /** - * This method informs the DTD about the parser being used to drive the parse process - * - * @update gess 3/25/98 - * @param aParse -- ptr to parser object - * @return nada - */ - virtual void SetParser(nsIParser* aParser)=0; - - /** - * Select given content sink into DTD for output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink)=0; - /** * This method is called to determine if the given DTD can parse * a document in a given source-type. @@ -118,7 +100,7 @@ class nsIDTD : public nsISupports { * @param aFilename--string that contains name of file being parsed (if applicable) * @return */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink)=0; + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser)=0; /** * Called by the parser after the parsing process has concluded @@ -126,7 +108,7 @@ class nsIDTD : public nsISupports { * @param anErrorCode - contains error code resulting from parse process * @return */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink)=0; + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser)=0; /** * Called during model building phase of parse process. Each token created during @@ -137,7 +119,7 @@ class nsIDTD : public nsISupports { * @param aToken -- token object to be put into content model * @return error code (usually 0) */ - NS_IMETHOD HandleToken(CToken* aToken)=0; + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser)=0; /** * Cause the tokenizer to consume and create the next token, and @@ -147,7 +129,7 @@ class nsIDTD : public nsISupports { * @param aToken -- will contain newly created and consumed token * @return error code (usually 0) */ - NS_IMETHOD ConsumeToken(CToken*& aToken)=0; + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser)=0; /** * This method causes all tokens to be dispatched to the given tag handler. @@ -211,7 +193,7 @@ class nsIDTD : public nsISupports { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef)=0; + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser)=0; /** * Retrieve a ptr to the global token recycler... diff --git a/mozilla/parser/htmlparser/src/nsIDTDDebug.h b/mozilla/parser/htmlparser/src/nsIDTDDebug.h index 36d431d9858..390989d65a0 100644 --- a/mozilla/parser/htmlparser/src/nsIDTDDebug.h +++ b/mozilla/parser/htmlparser/src/nsIDTDDebug.h @@ -36,7 +36,7 @@ class nsIDTD; -class nsParser; +class nsIParser; class nsVoidArray; class nsIDTDDebug : public nsISupports { @@ -47,7 +47,7 @@ public: virtual void SetRecordStatistics(PRBool bval) = 0; - virtual PRBool Verify(nsIDTD * aDTD, nsParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) = 0; + virtual PRBool Verify(nsIDTD * aDTD, nsIParser * aParser, int ContextStackPos, eHTMLTags aContextStack[], nsString& aURLRef) = 0; virtual void DumpVectorRecord(void) = 0; diff --git a/mozilla/parser/htmlparser/src/nsIParser.h b/mozilla/parser/htmlparser/src/nsIParser.h index 2c1d1dc6a3b..3c039101d8e 100644 --- a/mozilla/parser/htmlparser/src/nsIParser.h +++ b/mozilla/parser/htmlparser/src/nsIParser.h @@ -76,15 +76,23 @@ class nsIParser : public nsISupports { */ virtual void RegisterDTD(nsIDTD* aDTD)=0; + /** - * Call this method once you've created a parser, and want to instruct it - * where to send its output. - * - * @update gess 3/25/98 - * @param aContentSink -- ptr to content sink that will receive output - * @return ptr to previously set contentsink (usually null) + * Select given content sink into parser for parser output + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aContentSink)=0; + virtual nsIContentSink* SetContentSink(nsIContentSink* aSink)=0; + + + /** + * retrive the sink set into the parser + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL + */ + virtual nsIContentSink* GetContentSink(void)=0; /** * Call this method once you've created a parser, and want to instruct it diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index 9c20c4ddc6a..10cdf055c8c 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -186,7 +186,7 @@ MakeConversionTable() * @param * @return */ -nsParser::nsParser() : mCommand() { +nsParser::nsParser() : mCommand("") { NS_INIT_REFCNT(); mStreamListenerState=eNone; mParserFilter = 0; @@ -309,6 +309,16 @@ nsIContentSink* nsParser::SetContentSink(nsIContentSink* aSink) { return old; } +/** + * retrive the sink set into the parser + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL + */ +nsIContentSink* nsParser::GetContentSink(void){ + return mSink; +} + /** * Call this static method when you want to * register your dynamic DTD's with the parser. @@ -367,8 +377,9 @@ eParseMode nsParser::GetParseMode(void){ PRBool FindSuitableDTD( CParserContext& aParserContext,nsString& aCommand) { //Let's start by tring the defaultDTD, if one exists... - if(aParserContext.mDTD && (aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,0))) - return PR_TRUE; + if(aParserContext.mDTD) + if(aParserContext.mDTD->CanParse(aParserContext.mSourceType,aCommand,0)) + return PR_TRUE; PRBool result=PR_FALSE; @@ -475,17 +486,17 @@ eParseMode DetermineParseMode(nsParser& aParser) { * @param * @return error code -- 0 if ok, non-zero if error. */ -PRInt32 nsParser::WillBuildModel(nsString& aFilename){ +PRInt32 nsParser::WillBuildModel(nsString& aFilename,nsIDTD* aDefaultDTD){ mMajorIteration=-1; mMinorIteration=-1; PRInt32 result=kNoError; if(mParserContext){ mParserContext->mParseMode=DetermineParseMode(*this); + mParserContext->mDTD=aDefaultDTD; if(PR_TRUE==FindSuitableDTD(*mParserContext,mCommand)) { - mParserContext->mDTD->SetParser(this); - mParserContext->mDTD->SetContentSink(mSink); - mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext)); + //mParserContext->mDTD->SetContentSink(mSink); + mParserContext->mDTD->WillBuildModel(aFilename,PRBool(0==mParserContext->mPrevContext),this); } } else result=kInvalidParserContext; @@ -493,7 +504,9 @@ PRInt32 nsParser::WillBuildModel(nsString& aFilename){ } /** - * + * This gets called when the parser is done with its input. + * Note that the parser may have been called recursively, so we + * have to check for a prev. context before closing out the DTD/sink. * @update gess5/18/98 * @param * @return error code -- 0 if ok, non-zero if error. @@ -501,8 +514,9 @@ PRInt32 nsParser::WillBuildModel(nsString& aFilename){ PRInt32 nsParser::DidBuildModel(PRInt32 anErrorCode) { //One last thing...close any open containers. PRInt32 result=anErrorCode; - if(mParserContext->mDTD) { - result=mParserContext->mDTD->DidBuildModel(anErrorCode,PRBool(0==mParserContext->mPrevContext)); + + if((!mParserContext->mPrevContext) && (mParserContext->mDTD)) { + result=mParserContext->mDTD->DidBuildModel(anErrorCode,PRBool(0==mParserContext->mPrevContext),this); //Now recycle any tokens that are still hanging around. //Come to think of it, there really shouldn't be any. @@ -570,9 +584,6 @@ PRBool nsParser::EnableParser(PRBool aState){ * not have been consumed by the scanner during a given invocation * of this method. * - * NOTE: We don't call willbuildmodel here, because it will happen - * as a result of calling OnStartBinding later on. - * * @update gess 3/25/98 * @param aFilename -- const char* containing file to be parsed. * @return error code -- 0 if ok, non-zero if error. @@ -611,7 +622,7 @@ PRInt32 nsParser::Parse(fstream& aStream,PRBool aVerifyEnabled){ mParserContext->mScanner->Eof(); if(eValidDetect==AutoDetectContentType(mParserContext->mScanner->GetBuffer(), mParserContext->mSourceType)) { - WillBuildModel(mParserContext->mScanner->GetFilename()); + WillBuildModel(mParserContext->mScanner->GetFilename(),0); status=ResumeParse(); DidBuildModel(status); } //if @@ -640,14 +651,17 @@ PRInt32 nsParser::Parse(nsString& aSourceBuffer,PRBool anHTMLString,PRBool aVeri if(0mDTD: 0; + PushContext(*pc); if(PR_TRUE==anHTMLString) pc->mSourceType="text/html"; if(eValidDetect==AutoDetectContentType(aSourceBuffer,mParserContext->mSourceType)) { - WillBuildModel(mParserContext->mScanner->GetFilename()); + WillBuildModel(mParserContext->mScanner->GetFilename(),thePrevDTD); result=ResumeParse(); DidBuildModel(result); } + mParserContext->mDTD=0; pc=PopContext(); delete pc; } @@ -707,9 +721,9 @@ PRInt32 nsParser::BuildModel() { CToken* theToken=(CToken*)mParserContext->mCurrentPos->GetCurrent(); theMarkPos=*mParserContext->mCurrentPos; ++(*mParserContext->mCurrentPos); - result=theRootDTD->HandleToken(theToken); + result=theRootDTD->HandleToken(theToken,this); if(mDTDVerification) - theRootDTD->Verify(kEmptyString); + theRootDTD->Verify(kEmptyString,this); } //Now it's time to recycle our used tokens. @@ -906,7 +920,7 @@ nsresult nsParser::OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt if(eUnknownDetect==mParserContext->mAutoDetectStatus) { if(eValidDetect==AutoDetectContentType(mParserContext->mScanner->GetBuffer(),mParserContext->mSourceType)) { - WillBuildModel(mParserContext->mScanner->GetFilename()); + WillBuildModel(mParserContext->mScanner->GetFilename(),0); } //if } } //if @@ -969,7 +983,7 @@ PRInt32 nsParser::Tokenize(){ WillTokenize(); while(kNoError==result) { mParserContext->mScanner->Mark(); - result=mParserContext->mDTD->ConsumeToken(theToken); + result=mParserContext->mDTD->ConsumeToken(theToken,this); if(kNoError==result) { if(theToken) { diff --git a/mozilla/parser/htmlparser/src/nsParser.h b/mozilla/parser/htmlparser/src/nsParser.h index bf491af9bba..f1366bf142d 100644 --- a/mozilla/parser/htmlparser/src/nsParser.h +++ b/mozilla/parser/htmlparser/src/nsParser.h @@ -98,6 +98,14 @@ friend class CTokenHandler; * @return old sink, or NULL */ virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); + + /** + * retrive the sink set into the parser + * @update gess5/11/98 + * @param aSink is the new sink to be used by parser + * @return old sink, or NULL + */ + virtual nsIContentSink* GetContentSink(void); /** * Call this method once you've created a parser, and want to instruct it @@ -209,7 +217,7 @@ protected: * @param * @return */ - PRInt32 WillBuildModel(nsString& aFilename); + PRInt32 WillBuildModel(nsString& aFilename,nsIDTD* mDefaultDTD=0); /** * diff --git a/mozilla/parser/htmlparser/src/nsValidDTD.cpp b/mozilla/parser/htmlparser/src/nsValidDTD.cpp index acfafde44ae..1e4a8bf02c9 100644 --- a/mozilla/parser/htmlparser/src/nsValidDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsValidDTD.cpp @@ -201,7 +201,7 @@ eAutoDetectResult CValidDTD::AutoDetectContentType(nsString& aBuffer,nsString& a * @param * @return */ -NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; return result; } @@ -212,35 +212,12 @@ NS_IMETHODIMP CValidDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ * @param * @return */ -NS_IMETHODIMP CValidDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +NS_IMETHODIMP CValidDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CValidDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CValidDTD::SetContentSink(nsIContentSink* aSink) { - return 0; -} - /******************************************************************* These methods use to be hidden in the tokenizer-delegate. @@ -260,8 +237,9 @@ nsIContentSink* CValidDTD::SetContentSink(nsIContentSink* aSink) { * @param anErrorCode: arg that will hold error condition * @return new token or null */ -NS_IMETHODIMP CValidDTD::ConsumeToken(CToken*& aToken){ - +NS_IMETHODIMP CValidDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser){ + + mParser=(nsParser*)aParser; CScanner* theScanner=mParser->GetScanner(); PRUnichar aChar; @@ -316,8 +294,9 @@ NS_IMETHODIMP CValidDTD::WillInterruptParse(void){ * @param * @return */ -PRBool CValidDTD::Verify(nsString& aURLRef){ +PRBool CValidDTD::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -364,8 +343,9 @@ PRBool CValidDTD::IsContainer(PRInt32 aTag) const{ * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -NS_IMETHODIMP CValidDTD::HandleToken(CToken* aToken) { +NS_IMETHODIMP CValidDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; + mParser=(nsParser*)aParser; return result; } diff --git a/mozilla/parser/htmlparser/src/nsValidDTD.h b/mozilla/parser/htmlparser/src/nsValidDTD.h index 6dd2b2aa7f3..e9778ae5ca8 100644 --- a/mozilla/parser/htmlparser/src/nsValidDTD.h +++ b/mozilla/parser/htmlparser/src/nsValidDTD.h @@ -118,7 +118,7 @@ class CValidDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -128,7 +128,7 @@ class CValidDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * @@ -136,7 +136,7 @@ class CValidDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** @@ -157,16 +157,6 @@ class CValidDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -175,7 +165,7 @@ class CValidDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -194,13 +184,6 @@ class CValidDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); /** * Called by the parser to initiate dtd verification of the @@ -209,7 +192,7 @@ class CValidDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp index b24d371d147..010884c2ba0 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.cpp @@ -256,34 +256,33 @@ eAutoDetectResult CViewSourceHTML::AutoDetectContentType(nsString& aBuffer,nsStr * @param * @return */ -NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; mFilename=aFilename; - if((aNotifySink) && (mSink)) { - mLineNumber=0; - result = mSink->WillBuildModel(); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { + mLineNumber=0; + result = mSink->WillBuildModel(); - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ - mIsHTML=(0OpenHTML(theHTMLNode); + mSink->OpenHTML(theHTMLNode); //now let's automatically open the body... CStartToken theBodyToken(eHTMLTag_body); nsCParserNode theBodyNode(&theBodyToken,0); - theSink->OpenBody(theBodyNode); + mSink->OpenBody(theBodyNode); + + SetFont("courier","-1",PR_TRUE,*mSink); + } - - SetFont("courier","-1",PR_TRUE,*mSink); - } - return result; } @@ -293,61 +292,33 @@ NS_IMETHODIMP CViewSourceHTML::WillBuildModel(nsString& aFilename,PRBool aNotify * @param * @return */ -NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +NS_IMETHODIMP CViewSourceHTML::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result= NS_OK; //ADD CODE HERE TO CLOSE OPEN CONTAINERS... - if((aNotifySink) && (mSink)) { - - { - nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink; - + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { //now let's automatically close the pre... SetStyle(eHTMLTag_font,PR_FALSE,*mSink); - + //now let's automatically close the body... CEndToken theBodyToken(eHTMLTag_body); nsCParserNode theBodyNode(&theBodyToken,0); - theSink->CloseBody(theBodyNode); + mSink->CloseBody(theBodyNode); //now let's automatically close the html... CEndToken theHTMLToken(eHTMLTag_html); nsCParserNode theHTMLNode(&theBodyToken,0); - theSink->CloseHTML(theBodyNode); + mSink->CloseHTML(theBodyNode); + result = mSink->DidBuildModel(1); } - - result = mSink->DidBuildModel(1); - } return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CViewSourceHTML::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CViewSourceHTML::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=aSink; - return old; -} static eHTMLTags gSkippedContentTags[]={ eHTMLTag_script, eHTMLTag_style, eHTMLTag_title, eHTMLTag_textarea}; @@ -626,13 +597,15 @@ NS_IMETHODIMP CViewSourceHTML::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CTo * @param anErrorCode: arg that will hold error condition * @return new token or null */ -NS_IMETHODIMP CViewSourceHTML::ConsumeToken(CToken*& aToken){ +NS_IMETHODIMP CViewSourceHTML::ConsumeToken(CToken*& aToken,nsIParser* aParser) { aToken=0; if(mTokenDeque.GetSize()>0) { aToken=(CToken*)mTokenDeque.Pop(); return NS_OK; } + mParser=(nsParser*)aParser; + nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ @@ -721,8 +694,9 @@ NS_IMETHODIMP CViewSourceHTML::WillInterruptParse(void){ * @param * @return */ -PRBool CViewSourceHTML::Verify(nsString& aURLRef){ +PRBool CViewSourceHTML::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -930,12 +904,14 @@ PRBool WriteTag(nsCParserNode& aNode,nsIContentSink& aSink,PRBool anEndToken,PRB * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken) { +NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType(); PRBool theEndTag=PR_TRUE; + mParser=(nsParser*)aParser; + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); nsCParserNode theNode(theToken,mLineNumber); switch(theType) { diff --git a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h index 40cc5dbf25f..0f656b5136a 100644 --- a/mozilla/parser/htmlparser/src/nsViewSourceHTML.h +++ b/mozilla/parser/htmlparser/src/nsViewSourceHTML.h @@ -33,13 +33,13 @@ #include "nshtmlpars.h" #include "nsVoidArray.h" #include "nsDeque.h" +#include "nsIHTMLContentSink.h" #define NS_VIEWSOURCE_HTML_IID \ {0xb6003010, 0x7932, 0x11d2, \ {0x80, 0x1b, 0x0, 0x60, 0x8, 0xbf, 0xc4, 0x89 }} -class nsIHTMLContentSink; class nsIDTDDebug; class nsIParserNode; class CITokenHandler; @@ -108,7 +108,7 @@ class CViewSourceHTML: public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -118,7 +118,7 @@ class CViewSourceHTML: public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * @@ -126,16 +126,7 @@ class CViewSourceHTML: public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); - - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * Cause the tokenizer to consume the next token, and @@ -145,7 +136,7 @@ class CViewSourceHTML: public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -181,13 +172,6 @@ class CViewSourceHTML: public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); /** * Called by the parser to initiate dtd verification of the @@ -196,7 +180,7 @@ class CViewSourceHTML: public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its @@ -249,7 +233,7 @@ protected: NS_IMETHODIMP ConsumeAttributes(PRUnichar aChar,CScanner& aScanner,CStartToken* aToken); nsParser* mParser; - nsIContentSink* mSink; + nsIHTMLContentSink* mSink; nsString mFilename; PRInt32 mLineNumber; nsDeque mTokenDeque; diff --git a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp index e0fd2c45b47..8f89f460699 100644 --- a/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsWellFormedDTD.cpp @@ -196,31 +196,33 @@ eAutoDetectResult CWellFormedDTD::AutoDetectContentType(nsString& aBuffer,nsStri * @param * @return */ -NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink){ +NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; mFilename=aFilename; - if((aNotifySink) && (mSink)) { - mLineNumber=0; - result = mSink->WillBuildModel(); + if(aParser){ + mSink=aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { + mLineNumber=0; + result = mSink->WillBuildModel(); -#if 0 - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ - { - nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink; + #if 0 + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + { - //now let's automatically open the html... - CStartToken theHTMLToken(eHTMLTag_html); - nsCParserNode theHTMLNode(&theHTMLToken,0); - theSink->OpenHTML(theHTMLNode); + //now let's automatically open the html... + CStartToken theHTMLToken(eHTMLTag_html); + nsCParserNode theHTMLNode(&theHTMLToken,0); + mSink->OpenHTML(theHTMLNode); - //now let's automatically open the body... - CStartToken theBodyToken(eHTMLTag_body); - nsCParserNode theBodyNode(&theBodyToken,0); - theSink->OpenBody(theBodyNode); + //now let's automatically open the body... + CStartToken theBodyToken(eHTMLTag_body); + nsCParserNode theBodyNode(&theBodyToken,0); + mSink->OpenBody(theBodyNode); + } + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + #endif } - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ -#endif } return result; @@ -232,61 +234,39 @@ NS_IMETHODIMP CWellFormedDTD::WillBuildModel(nsString& aFilename,PRBool aNotifyS * @param * @return */ -NS_IMETHODIMP CWellFormedDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +NS_IMETHODIMP CWellFormedDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result= NS_OK; //ADD CODE HERE TO CLOSE OPEN CONTAINERS... - if((aNotifySink) && (mSink)) { - result = mSink->DidBuildModel(1); + if(aParser){ + mSink=aParser->GetContentSink(); + if((aNotifySink) && (mSink)) { + result = mSink->DidBuildModel(1); -#if 0 - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ - { - nsIHTMLContentSink* theSink=(nsIHTMLContentSink*)mSink; + #if 0 + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + { + nsIHTMLContentSink* mSink=(nsIHTMLContentSink*)mSink; - //now let's automatically open the body... - CEndToken theBodyToken(eHTMLTag_body); - nsCParserNode theBodyNode(&theBodyToken,0); - theSink->CloseBody(theBodyNode); + //now let's automatically open the body... + CEndToken theBodyToken(eHTMLTag_body); + nsCParserNode theBodyNode(&theBodyToken,0); + mSink->CloseBody(theBodyNode); - //now let's automatically open the html... - CEndToken theHTMLToken(eHTMLTag_html); - nsCParserNode theHTMLNode(&theBodyToken,0); - theSink->CloseHTML(theBodyNode); + //now let's automatically open the html... + CEndToken theHTMLToken(eHTMLTag_html); + nsCParserNode theHTMLNode(&theBodyToken,0); + mSink->CloseHTML(theBodyNode); + } + /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ + #endif } - /* COMMENT OUT THIS BLOCK IF: you aren't using an nsHTMLContentSink...*/ -#endif } return result; } -/** - * - * - * @update gess 3/25/98 - * @param - * @return - */ -void CWellFormedDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gess 3/25/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* CWellFormedDTD::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=aSink; - return old; -} - static eHTMLTags gSkippedContentTags[]={ eHTMLTag_script, eHTMLTag_style, eHTMLTag_title, eHTMLTag_textarea}; @@ -339,6 +319,7 @@ NS_IMETHODIMP CWellFormedDTD::ConsumeStartTag(PRUnichar aChar,CScanner& aScanner */ NS_IMETHODIMP CWellFormedDTD::ConsumeText(const nsString& aString,CScanner& aScanner,CToken*& aToken){ nsresult result=NS_OK; + aToken=gTokenRecycler.CreateTokenOfType(eToken_text,eHTMLTag_text,aString); if(aToken) { PRUnichar ch=0; @@ -632,13 +613,14 @@ NS_IMETHODIMP CWellFormedDTD::ConsumeTag(PRUnichar aChar,CScanner& aScanner,CTok * @param anErrorCode: arg that will hold error condition * @return new token or null */ -NS_IMETHODIMP CWellFormedDTD::ConsumeToken(CToken*& aToken){ +NS_IMETHODIMP CWellFormedDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser) { aToken=0; if(mTokenDeque.GetSize()>0) { aToken=(CToken*)mTokenDeque.Pop(); return NS_OK; } + mParser=(nsParser*)aParser; nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ @@ -727,8 +709,9 @@ NS_IMETHODIMP CWellFormedDTD::WillInterruptParse(void){ * @param * @return */ -PRBool CWellFormedDTD::Verify(nsString& aURLRef){ +PRBool CWellFormedDTD::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } @@ -775,11 +758,14 @@ PRBool CWellFormedDTD::IsContainer(PRInt32 aTag) const{ * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ -NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken) { +NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType= (eHTMLTokenTypes)theToken->GetTokenType(); + mParser=(nsParser*)aParser; + mSink=aParser->GetContentSink(); + nsCParserNode theNode(theToken,mLineNumber); switch(theType) { diff --git a/mozilla/parser/htmlparser/src/nsWellFormedDTD.h b/mozilla/parser/htmlparser/src/nsWellFormedDTD.h index 6707d74d7e5..171d3b99fe6 100644 --- a/mozilla/parser/htmlparser/src/nsWellFormedDTD.h +++ b/mozilla/parser/htmlparser/src/nsWellFormedDTD.h @@ -33,13 +33,13 @@ #include "nshtmlpars.h" #include "nsVoidArray.h" #include "nsDeque.h" +#include "nsIContentSink.h" #define NS_WELLFORMED_DTD_IID \ {0xa39c6bfd, 0x15f0, 0x11d2, \ {0x80, 0x41, 0x0, 0x10, 0x4b, 0x98, 0x3f, 0xd4}} -class nsIHTMLContentSink; class nsIDTDDebug; class nsIParserNode; class CITokenHandler; @@ -108,7 +108,7 @@ class CWellFormedDTD : public nsIDTD { * @param aFilename is the name of the file being parsed. * @return error code (almost always 0) */ - NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsIParser* aParser); /** * The parser uses a code sandwich to wrap the parsing process. Before @@ -118,7 +118,7 @@ class CWellFormedDTD : public nsIDTD { * @param anErrorCode contans the last error that occured * @return error code */ - NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser); /** * @@ -126,7 +126,7 @@ class CWellFormedDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -146,15 +146,6 @@ class CWellFormedDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * - * - * @update gess 3/25/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -163,7 +154,7 @@ class CWellFormedDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -182,14 +173,6 @@ class CWellFormedDTD : public nsIDTD { */ NS_IMETHOD WillInterruptParse(void); - /** - * Select given content sink into parser for parser output - * @update gess5/11/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); - /** * Called by the parser to initiate dtd verification of the * internal context stack. @@ -197,7 +180,7 @@ class CWellFormedDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its diff --git a/mozilla/parser/htmlparser/src/nsXIFDTD.cpp b/mozilla/parser/htmlparser/src/nsXIFDTD.cpp index 77867a5b530..2c80cfbb40d 100644 --- a/mozilla/parser/htmlparser/src/nsXIFDTD.cpp +++ b/mozilla/parser/htmlparser/src/nsXIFDTD.cpp @@ -407,14 +407,15 @@ eAutoDetectResult nsXIFDTD::AutoDetectContentType(nsString& aBuffer,nsString& aT * @param * @return */ -nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink){ +nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; - if(mSink) - { - mSink->WillBuildModel(); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if(mSink) { + mSink->WillBuildModel(); + } } - return result; } @@ -424,12 +425,14 @@ nsresult nsXIFDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink){ * @param * @return */ -nsresult nsXIFDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ +nsresult nsXIFDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink,nsIParser* aParser){ nsresult result=NS_OK; - if(mSink) - { - result = mSink->DidBuildModel(anErrorCode); + if(aParser){ + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); + if(mSink) { + mSink->DidBuildModel(anErrorCode); + } } return result; @@ -447,9 +450,12 @@ nsresult nsXIFDTD::DidBuildModel(PRInt32 anErrorCode,PRBool aNotifySink){ * @param aParser * @return */ -nsresult nsXIFDTD::HandleToken(CToken* aToken){ +nsresult nsXIFDTD::HandleToken(CToken* aToken,nsIParser* aParser) { nsresult result=NS_OK; + mParser=(nsParser*)aParser; + mSink=(nsIHTMLContentSink*)aParser->GetContentSink(); //this can change in the parser between calls. + if(aToken) { CHTMLToken* theToken= (CHTMLToken*)(aToken); eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType()); @@ -796,33 +802,6 @@ CTokenHandler* nsXIFDTD::AddTokenHandler(CTokenHandler* aHandler) { return 0; } -/** - * - * - * @update gpk 06/18/98 - * @param - * @return - */ -void nsXIFDTD::SetParser(nsIParser* aParser) { - mParser=(nsParser*)aParser; -} - -/** - * This method gets called in order to set the content - * sink for this parser to dump nodes to. - * - * @update gpk 06/18/98 - * @param nsIContentSink interface for node receiver - * @return - */ -nsIContentSink* nsXIFDTD::SetContentSink(nsIContentSink* aSink) { - nsIContentSink* old=mSink; - mSink=(nsIHTMLContentSink*)aSink; - - - return old; -} - /** * This method gets called to determine whether a given @@ -1658,7 +1637,7 @@ PRInt32 nsXIFDTD::ConsumeNewline(PRUnichar aChar,CScanner& aScanner,CToken*& aTo * @param anErrorCode: arg that will hold error condition * @return new token or null */ -nsresult nsXIFDTD::ConsumeToken(CToken*& aToken){ +nsresult nsXIFDTD::ConsumeToken(CToken*& aToken,nsIParser* aParser) { aToken=0; if(mTokenDeque.GetSize()>0) { @@ -1666,6 +1645,8 @@ nsresult nsXIFDTD::ConsumeToken(CToken*& aToken){ return kNoError; } + mParser=(nsParser*)aParser; + nsresult result=NS_OK; CScanner* theScanner=mParser->GetScanner(); if(NS_OK==result){ @@ -1854,8 +1835,9 @@ void nsXIFDTD::SetVerification(PRBool aEnabled){ * @param * @return */ -PRBool nsXIFDTD::Verify(nsString& aURLRef){ +PRBool nsXIFDTD::Verify(nsString& aURLRef,nsIParser* aParser) { PRBool result=PR_TRUE; + mParser=(nsParser*)aParser; return result; } diff --git a/mozilla/parser/htmlparser/src/nsXIFDTD.h b/mozilla/parser/htmlparser/src/nsXIFDTD.h index 454fd1a7126..949150d75f7 100644 --- a/mozilla/parser/htmlparser/src/nsXIFDTD.h +++ b/mozilla/parser/htmlparser/src/nsXIFDTD.h @@ -161,7 +161,7 @@ class nsXIFDTD : public nsIDTD { * @param * @return */ - NS_IMETHOD WillBuildModel(nsString& aFileName,PRBool aNotifySink); + NS_IMETHOD WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsIParser* aParser); /** * @@ -169,7 +169,7 @@ class nsXIFDTD : public nsIDTD { * @param * @return */ - NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel,PRBool aNotifySink); + NS_IMETHOD DidBuildModel(PRInt32 aQualityLevel,PRBool aNotifySink,nsIParser* aParser); /** * @@ -177,7 +177,7 @@ class nsXIFDTD : public nsIDTD { * @param aToken -- token object to be put into content model * @return 0 if all is well; non-zero is an error */ - NS_IMETHOD HandleToken(CToken* aToken); + NS_IMETHOD HandleToken(CToken* aToken,nsIParser* aParser); /** * This method causes all tokens to be dispatched to the given tag handler. @@ -197,15 +197,6 @@ class nsXIFDTD : public nsIDTD { */ NS_IMETHOD ReleaseTokenPump(nsITagHandler* aHandler); - /** - * - * - * @update gpk 06/18/98 - * @param - * @return - */ - virtual void SetParser(nsIParser* aParser); - /** * Cause the tokenizer to consume the next token, and * return an error result. @@ -214,7 +205,7 @@ class nsXIFDTD : public nsIDTD { * @param anError -- ref to error code * @return new token or null */ - NS_IMETHOD ConsumeToken(CToken*& aToken); + NS_IMETHOD ConsumeToken(CToken*& aToken,nsIParser* aParser); /** @@ -267,7 +258,7 @@ class nsXIFDTD : public nsIDTD { * @param * @return */ - virtual PRBool Verify(nsString& aURLRef); + virtual PRBool Verify(nsString& aURLRef,nsIParser* aParser); /** * Set this to TRUE if you want the DTD to verify its @@ -278,14 +269,6 @@ class nsXIFDTD : public nsIDTD { */ virtual void SetVerification(PRBool aEnable); - /** - * Select given content sink into parser for parser output - * @update gpk 06/18/98 - * @param aSink is the new sink to be used by parser - * @return old sink, or NULL - */ - virtual nsIContentSink* SetContentSink(nsIContentSink* aSink); - /** * This method is called to determine whether or not a tag