diff --git a/htmlparser/src/CNavDTD.cpp b/htmlparser/src/CNavDTD.cpp index 51b69f1df0e..e578c7791d4 100644 --- a/htmlparser/src/CNavDTD.cpp +++ b/htmlparser/src/CNavDTD.cpp @@ -22,9 +22,10 @@ //#define ENABLE_CRC //#define RICKG_DEBUG -#define ENABLE_RESIDUALSTYLE //#define ALLOW_TR_AS_CHILD_OF_TABLE //by setting this to true, TR is allowable directly in TABLE. +#define ENABLE_RESIDUALSTYLE + #ifdef RICKG_DEBUG #include #endif @@ -266,12 +267,24 @@ CNavDTD::~CNavDTD(){ /** * Call this method if you want the DTD to construct a fresh * instance of itself. - * @update gess7/23/98 + * @update gess 25May2000 * @param * @return */ nsresult CNavDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){ - return NS_NewNavHTMLDTD(aInstancePtrResult); + + nsresult result=NS_NewNavHTMLDTD(aInstancePtrResult); + + if(aInstancePtrResult) { + CNavDTD *theOtherDTD=(CNavDTD*)*aInstancePtrResult; + if(theOtherDTD) { + theOtherDTD->mDTDMode=mDTDMode; + theOtherDTD->mParserCommand=mParserCommand; + theOtherDTD->mDocType=mDocType; + } + } + + return result; } /** @@ -827,10 +840,9 @@ nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){ { PRInt32 theCount=mBodyContext->GetCount(); eHTMLTags theGrandParentTag=mBodyContext->TagAt(theCount-2); - PRInt32 theCounter=mBodyContext->IncrementCounter(theGrandParentTag); - - nsString theNumber; - theNumber.AppendInt(theCounter); + + nsAutoString theNumber; + PRInt32 theCounter=mBodyContext->IncrementCounter(theGrandParentTag,aNode,theNumber); CTextToken theToken(theNumber); PRInt32 theLineNumber=0; nsCParserNode theNode(&theToken,theLineNumber); @@ -838,6 +850,35 @@ nsresult CNavDTD::DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag){ } break; + case eHTMLTag_meta: + { + //we should only enable user-defined entities in debug builds... + + PRInt32 theCount=aNode.GetAttributeCount(); + const nsString* theNamePtr=0; + const nsString* theValuePtr=0; + + if(theCount) { + PRInt32 theIndex=0; + for(theIndex=0;theIndexRegisterEntity(*theNamePtr,*theValuePtr); + } + } + break; + default: break; }//switch @@ -1846,6 +1887,27 @@ nsresult CNavDTD::HandleEntityToken(CToken* aToken) { NS_PRECONDITION(0!=aToken,kNullToken); nsresult result=NS_OK; + + nsString& theStr=aToken->GetStringValueXXX(); + PRUnichar theChar=theStr.CharAt(0); + if((kHashsign!=theChar) && (-1==nsHTMLEntities::EntityToUnicode(theStr))){ + + //before we just toss this away as a bogus entity, let's check... + CNamedEntity *theEntity=mBodyContext->GetEntity(theStr); + CToken *theToken=0; + if(theEntity) { + theToken=new CTextToken(theEntity->mValue); + } + else { + //if you're here we have a bogus entity. + //convert it into a text token. + nsAutoString temp; temp.AssignWithConversion("&"); + temp.Append(theStr); + theToken=new CTextToken(temp); + } + return HandleStartToken(theToken); + } + eHTMLTags theParentTag=mBodyContext->Last(); nsCParserNode* theNode=mNodeRecycler->CreateNode(); diff --git a/htmlparser/src/COtherDTD.cpp b/htmlparser/src/COtherDTD.cpp index 6392f0ed6f2..32dd63cedf1 100644 --- a/htmlparser/src/COtherDTD.cpp +++ b/htmlparser/src/COtherDTD.cpp @@ -4,24 +4,24 @@ * License Version 1.1 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.mozilla.org/NPL/ - * + * * Software distributed under the License is distributed on an "AS * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or * implied. See the License for the specific language governing * rights and limitations under the License. - * + * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is Netscape * Communications Corporation. Portions created by Netscape are * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. - * + * * Contributor(s): */ //#define ENABLE_CRC -//#define RICKG_DEBUG +//#define RICKG_DEBUG #include "nsDebug.h" @@ -131,7 +131,7 @@ NS_IMPL_RELEASE(COtherDTD) * @param * @return */ -COtherDTD::COtherDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSharedNodes(0) { +COtherDTD::COtherDTD() : nsIDTD(), mSharedNodes(0) { NS_INIT_REFCNT(); mSink = 0; mParser=0; @@ -141,14 +141,17 @@ COtherDTD::COtherDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSh mHasOpenHead=0; mHasOpenForm=PR_FALSE; mHasOpenMap=PR_FALSE; - mHeadContext=new nsDTDContext(); mBodyContext=new nsDTDContext(); - mFormContext=0; mTokenizer=0; mComputedCRC32=0; mExpectedCRC32=0; mDTDState=NS_OK; - mDocType=ePlainText; + mDocType=eHTML4Text; + mHadFrameset=PR_FALSE; + mHadBody=PR_FALSE; + mHasOpenScript=PR_FALSE; + mTokenRecycler=0; + mParserCommand=eViewNormal; char* theEnvString = PR_GetEnv("ENABLE_STRICT"); mEnableStrict=PRBool(theEnvString!=0); @@ -280,7 +283,6 @@ const nsIID& COtherDTD::GetMostDerivedIID(void)const { * @return */ COtherDTD::~COtherDTD(){ - delete mHeadContext; delete mBodyContext; NS_IF_RELEASE(mTokenizer); @@ -336,7 +338,19 @@ NS_HTMLPARS nsresult NS_NewOtherHTMLDTD(nsIDTD** aInstancePtrResult) { * @return */ nsresult COtherDTD::CreateNewInstance(nsIDTD** aInstancePtrResult){ - return NS_NewOtherHTMLDTD(aInstancePtrResult); + nsresult result=NS_NewOtherHTMLDTD(aInstancePtrResult); + + if(aInstancePtrResult) { + COtherDTD *theOtherDTD=(COtherDTD*)*aInstancePtrResult; + if(theOtherDTD) { + theOtherDTD->mDTDMode=mDTDMode; + theOtherDTD->mParserCommand=mParserCommand; + theOtherDTD->mDocType=mDocType; + theOtherDTD->mEnableStrict=mEnableStrict; + } + } + + return result; } /** @@ -608,6 +622,7 @@ nsresult COtherDTD::HandleToken(CToken* aToken,nsIParser* aParser){ case eToken_start: case eToken_whitespace: case eToken_newline: + case eToken_doctypeDecl: result=HandleStartToken(theToken); break; case eToken_end: @@ -722,7 +737,7 @@ nsresult COtherDTD::WillHandleStartTag(CToken* aToken,eHTMLTags aTag,nsCParserNo MOZ_TIMER_DEBUGLOG(("Start: Parse Time: COtherDTD::WillHandleStartTag(), this=%p\n", this)); START_TIMER() - return result; + return result; } @@ -762,20 +777,20 @@ nsresult COtherDTD::HandleStartToken(CToken* aToken) { if(NS_OK==result) { mLineNumber += aToken->mNewlineCount; - + PRBool theTagWasHandled=PR_FALSE; - switch(theChildTag) { - - case eHTMLTag_html: + switch(theChildTag) { + + case eHTMLTag_html: if(!HasOpenContainer(theChildTag)) { mSink->OpenHTML(*theNode); mBodyContext->Push(theNode,0); } theTagWasHandled=PR_TRUE; - break; - - default: + break; + + default: CElement* theElement=gElementTable->mElements[theParent]; if(theElement) { result=theElement->HandleStartToken(theNode,theChildTag,mBodyContext,mSink); @@ -788,7 +803,7 @@ nsresult COtherDTD::HandleStartToken(CToken* aToken) { DidHandleStartTag(*theNode,theChildTag); } - } //if + } //if }//if RecycleNode(theNode); @@ -814,7 +829,7 @@ nsresult COtherDTD::HandleEndToken(CToken* aToken) { nsresult result=NS_OK; eHTMLTags theChildTag=(eHTMLTags)aToken->GetTypeID(); - #ifdef RICKG_DEBUG + #ifdef RICKG_DEBUG WriteTokenToLog(aToken); #endif @@ -825,7 +840,7 @@ nsresult COtherDTD::HandleEndToken(CToken* aToken) { break; case eHTMLTag_script: - mHasOpenScript=PR_FALSE; + mHasOpenScript=PR_FALSE; default: PRInt32 theCount=mBodyContext->GetCount(); @@ -838,7 +853,7 @@ nsresult COtherDTD::HandleEndToken(CToken* aToken) { nsCParserNode theNode((CHTMLToken*)aToken,mLineNumber); result=theElement->HandleEndToken(&theNode,theChildTag,mBodyContext,mSink); } - break; + break; } return result; @@ -857,14 +872,12 @@ nsresult COtherDTD::CollectAttributes(nsCParserNode& aNode,eHTMLTags aTag,PRInt3 int attr=0; nsresult result=NS_OK; - int theAvailTokenCount=mTokenizer->GetCount() + mSkippedContent.GetSize(); + int theAvailTokenCount=mTokenizer->GetCount(); if(aCount<=theAvailTokenCount) { CToken* theToken=0; eHTMLTags theSkipTarget=gElementTable->mElements[aTag]->GetSkipTarget(); for(attr=0;attrPopToken(); + theToken=mTokenizer->PopToken(); if(theToken) { // Sanitize the key for it might contain some non-alpha-non-digit characters // at its end. Ex.