diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 53f2a70e39e..a7f505aa6e2 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -49,7 +49,7 @@ #endif #include "prmem.h" -//#define ENABLE_RESIDUALSTYLE +#define ENABLE_RESIDUALSTYLE //#define RICKG_DEBUG //#define ENABLE_CRC #ifdef RICKG_DEBUG @@ -458,7 +458,8 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename, mLineNumber=1; mHasOpenScript=PR_FALSE; mParseMode=aParseMode; - + mStyleHandlingEnabled=(eParseMode_quirks==mParseMode); + if((aNotifySink) && (aSink)) { STOP_TIMER(); @@ -577,6 +578,24 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse } } } + else { + //If you're here, then an error occured, but we still have nodes on the stack. + //At a minimum, we should grab the nodes and recycle them. + //Just to be correct, we'll also recycle the nodes. + + while(mBodyContext->GetCount() > 0) { + + nsEntryStack *theChildStyles=0; + nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theChildStyles); + theNode->mUseCount=0; + RecycleNode(theNode); + if(theChildStyles) { + delete theChildStyles; + } + } + + } + STOP_TIMER(); MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::DidBuildModel(), this=%p\n", this)); @@ -1006,7 +1025,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI // The safest thing to do is to discard this tag. return result; } - CloseContainersTo(theIndex,theParentTag,PR_TRUE); + CloseContainersTo(theIndex,aChildTag,PR_TRUE); }//if else break; }//if @@ -1609,9 +1628,10 @@ nsresult CNavDTD::HandleSavedTokens(PRInt32 anIndex) { // The body context should contain contents only upto the marked position. PRInt32 i=0; - nsEntryStack *theStack=0; + nsEntryStack* theChildStyleStack=0; + for(i=0; i<(theTagCount - theTopIndex); i++) { - mTempContext->Push((nsCParserNode*)mBodyContext->Pop(theStack)); + mTempContext->Push((nsCParserNode*)mBodyContext->Pop(theChildStyleStack)); } // Now flush out all the bad contents. @@ -1644,7 +1664,7 @@ nsresult CNavDTD::HandleSavedTokens(PRInt32 anIndex) { // Bad-contents were successfully processed. Now, itz time to get // back to the original body context state. for(PRInt32 k=0; k<(theTagCount - theTopIndex); k++) { - mBodyContext->Push((nsCParserNode*)mTempContext->Pop(theStack)); + mBodyContext->Push((nsCParserNode*)mTempContext->Pop(theChildStyleStack)); } STOP_TIMER() @@ -2312,35 +2332,41 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aChildTag){ //later, change this so that transients only open in containers that get leaked in to. + if(mStyleHandlingEnabled) { + #ifdef ENABLE_RESIDUALSTYLE - eHTMLTags theParentTag=mBodyContext->Last(); - if(!gHTMLElements[theParentTag].HasSpecialProperty(kNoStyleLeaksIn)) { - //the following code builds the set of style tags to be opened... - PRUint32 theCount=mBodyContext->GetCount()-1; - PRUint32 theLevel=0; - for(theLevel=0;theLevelGetStylesAt(theLevel); - if(theStack){ + eHTMLTags theParentTag=mBodyContext->Last(); - PRUint32 scount=theStack->mCount; - PRUint32 sindex=0; + if(CanContain(eHTMLTag_font,aChildTag)) { + if(!gHTMLElements[theParentTag].HasSpecialProperty(kNoStyleLeaksIn)) { + //the following code builds the set of style tags to be opened... + PRUint32 theCount=mBodyContext->GetCount(); + PRUint32 theLevel=0; + for(theLevel=0;theLevelGetStylesAt(theLevel); + if(theStack){ - nsTagEntry *theEntry=theStack->mEntries; - for(sindex=0;sindexmLevel) { - theEntry->mLevel=theLevel; - nsIParserNode* theNode=theEntry->mNode; - if(theNode) { - result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE,theLevel); - } - } - theEntry++; + PRUint32 scount=theStack->mCount; + PRUint32 sindex=0; + + nsTagEntry *theEntry=theStack->mEntries; + for(sindex=0;sindexmParent) { + theEntry->mParent=theStack; //we do this too, because this entry differs from the new one we're pushing... + nsIParserNode* theNode=theEntry->mNode; + if(theNode) { + result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE,theStack); + } + } + theEntry++; + } //for + } //if } //for } //if - } //for - } + } #endif + }//if return result; } @@ -2359,21 +2385,24 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aChildTag){ nsresult CNavDTD::CloseTransientStyles(eHTMLTags aChildTag){ nsresult result=NS_OK; + if(mStyleHandlingEnabled) { + #ifdef ENABLE_RESIDUALSTYLE #if 0 - int theTagPos=0; - //now iterate style set, and close the containers... + int theTagPos=0; + //now iterate style set, and close the containers... - nsEntryStack* theStack=mBodyContext->GetStylesAt(); - for(theTagPos=mBodyContext->mOpenStyles;theTagPos>0;theTagPos--){ - eHTMLTags theTag=GetTopNode(); - CStartToken token(theTag); - nsCParserNode theNode(&token,mLineNumber); - token.SetTypeID(theTag); - result=CloseContainer(theNode,theTag,PR_FALSE); - } + nsEntryStack* theStack=mBodyContext->GetStylesAt(); + for(theTagPos=mBodyContext->mOpenStyles;theTagPos>0;theTagPos--){ + eHTMLTags theTag=GetTopNode(); + CStartToken token(theTag); + nsCParserNode theNode(&token,mLineNumber); + token.SetTypeID(theTag); + result=CloseContainer(theNode,theTag,PR_FALSE); + } #endif #endif + } //if return result; } @@ -2388,14 +2417,16 @@ nsresult CNavDTD::CloseTransientStyles(eHTMLTags aChildTag){ nsresult CNavDTD::PopStyle(eHTMLTags aTag){ nsresult result=0; + if(mStyleHandlingEnabled) { #ifdef ENABLE_RESIDUALSTYLE - if(nsHTMLElement::IsStyleTag(aTag)) { - nsCParserNode *theNode=(nsCParserNode*)mBodyContext->PopStyle(aTag); - if(theNode) { - RecycleNode(theNode); + if(nsHTMLElement::IsStyleTag(aTag)) { + nsCParserNode* theNode=(nsCParserNode*)mBodyContext->PopStyle(aTag); + if(theNode) { + RecycleNode(theNode); + } } - } #endif + } //if return result; } @@ -2725,7 +2756,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode *aNode){ * @return TRUE if ok, FALSE if error */ nsresult -CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,PRInt32 aResidualStyleLevel){ +CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,nsEntryStack* aStyleStack){ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos); nsresult result=NS_OK; @@ -2804,7 +2835,7 @@ CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedB MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::OpenContainer(), this=%p\n", this)); START_TIMER(); - mBodyContext->Push(aNode,aResidualStyleLevel); + mBodyContext->Push(aNode,aStyleStack); } return result; @@ -2897,8 +2928,9 @@ nsresult CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTarget, PRBool aC theTag=mBodyContext->Last(); - nsEntryStack *theStyles=0; - nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theStyles); + nsEntryStack *theChildStyleStack=0; + + nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theChildStyleStack); result=CloseContainer(theNode,aTarget,aClosedByStartTag); if(theNode) { @@ -2907,11 +2939,18 @@ nsresult CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTarget, PRBool aC PRBool theTagIsStyle=nsHTMLElement::IsStyleTag(theTag); if(mStyleHandlingEnabled) { - if(aClosedByStartTag) { + if(aClosedByStartTag && (0==theNode->mUseCount)) { + + + /*************************************************************************** + The cases we're handing here: + 1.
// gets pushed onto .mStyles. + ***************************************************************************/ + if(theTagIsStyle) { - if(theStyles) { - theStyles->PushFront(theNode); - mBodyContext->PushStyles(theStyles); + if(theChildStyleStack) { + theChildStyleStack->PushFront(theNode); + mBodyContext->PushStyles(theChildStyleStack); } else mBodyContext->PushStyle(theNode); } @@ -2920,53 +2959,78 @@ nsresult CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTarget, PRBool aC //if you're here, then we're dealing with the closure of tags //caused by a close tag (as opposed to an open tag). //At a minimum, we should consider pushing residual styles up - //up the stack... + //up the stack or popping and recycling displaced nodes. - if(aTarget!=theTag) { - if(theTagIsStyle) { - if(theStyles) { - theStyles->PushFront(theNode); - mBodyContext->PushStyles(theStyles); - } - else mBodyContext->PushStyle(theNode); - } - else if(theStyles) { - mBodyContext->PushStyles(theStyles); + /*************************************************************************** + There are 2 cases: + 1.
text
+ Here the will leak into
(see case given above), and + when
closes the is dropped since it's already residual. + 2.
text
+ Here the will leak out of the
and get pushed onto + the RS stack for the , since it originated in the
. + ***************************************************************************/ + + if(theTagIsStyle) { + if(theChildStyleStack) { + theChildStyleStack->PushFront(theNode); + mBodyContext->PushStyles(theChildStyleStack); } + else if (0==theNode->mUseCount) { + if(theTag!=aTarget) { + mBodyContext->PushStyle(theNode); + } //otherwise just let the node recycle, because it was explicty closed + //and does not live on a style stack. + } + else { + //Ah, at last, the final case. If you're here, then we just popped a + //style tag that got onto that tag stack from a stylestack somewhere. + //The the target==theTag, then pop it from the stylestack. + if(theTag==aTarget) { + nsIParserNode* theNextNode=mBodyContext->PopStyle(theTag); + } + } + } + else if(theChildStyleStack) { + mBodyContext->PushStyles(theChildStyleStack); } } - } + } //if else { //since stylehandling is disabled, let's recycle the associated nodes here... } #endif - RecycleNode(theNode); - } + }//if + RecycleNode(theNode); } + + if(eParseMode_quirks==mParseMode) { + #ifdef ENABLE_RESIDUALSTYLE - //This code takes any nodes in style stack for at this level and reopens - //then where they were originally. + //This code takes any nodes in style stack for at this level and reopens + //then where they were originally. - if(!aClosedByStartTag) { - nsEntryStack* theStack=mBodyContext->GetStylesAt(anIndex-1); - if(theStack){ + if(!aClosedByStartTag) { + nsEntryStack* theStack=mBodyContext->GetStylesAt(anIndex-1); + if(theStack){ - PRUint32 scount=theStack->mCount; - PRUint32 sindex=0; + PRUint32 scount=theStack->mCount; + PRUint32 sindex=0; - for(sindex=0;sindexNodeAt(sindex); - if(theNode) { - ((nsCParserNode*)theNode)->mUseCount--; - result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE); - } - } - theStack->mCount=0; + for(sindex=0;sindexNodeAt(sindex); + if(theNode) { + ((nsCParserNode*)theNode)->mUseCount--; + result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE); + } + } + theStack->mCount=0; + } //if } //if - } //if #endif + }//if } //if return result; diff --git a/mozilla/htmlparser/src/CNavDTD.h b/mozilla/htmlparser/src/CNavDTD.h index 0ac0e39d7c9..ef1050fd413 100644 --- a/mozilla/htmlparser/src/CNavDTD.h +++ b/mozilla/htmlparser/src/CNavDTD.h @@ -448,7 +448,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult OpenForm(const nsIParserNode *aNode); nsresult OpenMap(const nsIParserNode *aNode); nsresult OpenFrameset(const nsIParserNode *aNode); - nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,PRInt32 aResidualStyleLevel=-1); + nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,nsEntryStack* aStyleStack=0); /** * The next set of methods close the given HTML element. diff --git a/mozilla/htmlparser/src/COtherDTD.cpp b/mozilla/htmlparser/src/COtherDTD.cpp index cd656990ee3..224f7d8471f 100644 --- a/mozilla/htmlparser/src/COtherDTD.cpp +++ b/mozilla/htmlparser/src/COtherDTD.cpp @@ -534,8 +534,8 @@ nsresult COtherDTD::CloseFrameset(const nsIParserNode *aNode){ * @param aNode -- next node to be added to model * @return TRUE if ok, FALSE if error */ -nsresult COtherDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTarget,PRBool aUpdateStyleStack,PRInt32 aResidualStyleLevel){ - return CNavDTD::OpenContainer(aNode,aTarget,aUpdateStyleStack,aResidualStyleLevel); +nsresult COtherDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTarget,PRBool aUpdateStyleStack,nsEntryStack* aStyleStack){ + return CNavDTD::OpenContainer(aNode,aTarget,aUpdateStyleStack,aStyleStack); } /** diff --git a/mozilla/htmlparser/src/COtherDTD.h b/mozilla/htmlparser/src/COtherDTD.h index fd1bc877f7c..558db944872 100644 --- a/mozilla/htmlparser/src/COtherDTD.h +++ b/mozilla/htmlparser/src/COtherDTD.h @@ -233,7 +233,7 @@ private: nsresult OpenForm(const nsIParserNode *aNode); nsresult OpenMap(const nsIParserNode *aNode); nsresult OpenFrameset(const nsIParserNode *aNode); - nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aUpdateStyleStack,PRInt32 aResidualStyleLevel=-1); + nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aUpdateStyleStack,nsEntryStack* aStyleStack=0); /** * The next set of methods close the given HTML element. diff --git a/mozilla/htmlparser/src/nsDTDUtils.cpp b/mozilla/htmlparser/src/nsDTDUtils.cpp index ab74d17a48a..459db6744df 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/htmlparser/src/nsDTDUtils.cpp @@ -34,7 +34,18 @@ MOZ_DECL_CTOR_COUNTER(nsDTDContext); MOZ_DECL_CTOR_COUNTER(CTokenRecycler); MOZ_DECL_CTOR_COUNTER(CObserverService); +/************************************************************************************** + A few notes about how residual style handling is performed: + + 1. The style stack contains nsTagEntry elements. + 2. Every tag on the containment stack can have it's own residual style stack. + 3. When a style leaks, it's mParent member is set to the level on the stack where + it originated. A node with an mParent of 0 is not opened on tag stack, + but is open on stylestack. + 4. An easy way to tell that a container on the element stack is a residual style tag + is that it's use count is >1. + **************************************************************************************/ /** * Default constructor @@ -117,7 +128,7 @@ void nsEntryStack::EnsureCapacityFor(PRInt32 aNewMax,PRInt32 aShiftOffset) { * * @update gess 04/22/99 */ -void nsEntryStack::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) { +void nsEntryStack::Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack) { if(aNode) { EnsureCapacityFor(mCount+1); @@ -127,8 +138,7 @@ void nsEntryStack::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) mEntries[mCount].mTag=(eHTMLTags)aNode->GetNodeType(); mEntries[mCount].mNode=(nsIParserNode*)aNode; - mEntries[mCount].mLevel=aResidualStyleLevel; - mEntries[mCount].mParent=0; + mEntries[mCount].mParent=aStyleStack; mEntries[mCount++].mStyles=0; } } @@ -139,7 +149,7 @@ void nsEntryStack::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) * * @update gess 11/10/99 */ -void nsEntryStack::PushFront(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) { +void nsEntryStack::PushFront(const nsIParserNode* aNode,nsEntryStack* aStyleStack) { if(aNode) { if(mCountGetNodeType(); mEntries[0].mNode=(nsIParserNode*)aNode; - mEntries[0].mLevel=aResidualStyleLevel; - mEntries[0].mParent=0; + mEntries[0].mParent=aStyleStack; mEntries[0].mStyles=0; mCount++; } @@ -177,7 +186,7 @@ void nsEntryStack::Append(nsEntryStack *aStack) { PRInt32 theIndex=0; for(theIndex=0;theIndexmEntries[theIndex]; - mEntries[mCount++].mLevel=-1; + mEntries[mCount++].mParent=0; } } } @@ -190,7 +199,7 @@ void nsEntryStack::Append(nsEntryStack *aStack) { */ nsIParserNode* nsEntryStack::Pop(void) { - nsIParserNode *result=0; + nsIParserNode* result=0; if(0mToken->mUseCount--; mEntries[mCount].mNode=0; mEntries[mCount].mStyles=0; + + nsEntryStack* theStyleStack=mEntries[mCount].mParent; + + if(theStyleStack) { + //now we have to tell the residual style stack where this tag + //originated that it's no longer in use. + PRUint32 scount=theStyleStack->mCount; + PRUint32 sindex=0; + + nsTagEntry *theStyleEntry=theStyleStack->mEntries; + for(sindex=scount-1;sindex>=0;sindex--){ + if(theStyleEntry->mTag==mEntries[mCount].mTag) { + theStyleEntry->mParent=0; //this tells us that the style is not open at any level + break; + } + theStyleEntry++; + } //for + } } return result; } @@ -358,7 +385,7 @@ PRInt32 nsDTDContext::GetTopmostIndexOf(eHTMLTags aTag) const { * * @update gess7/9/98 */ -void nsDTDContext::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) { +void nsDTDContext::Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack) { if(aNode) { #ifdef NS_DEBUG @@ -367,7 +394,7 @@ void nsDTDContext::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) if(size< eMaxTags) mXTags[size]=theTag; #endif - mStack.Push((nsIParserNode*)aNode,aResidualStyleLevel); + mStack.Push((nsIParserNode*)aNode,aStyleStack); } } @@ -375,10 +402,10 @@ void nsDTDContext::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) * @update gess 11/11/99, * harishd 04/04/99 */ -nsIParserNode* nsDTDContext::Pop(nsEntryStack *&aStack) { +nsIParserNode* nsDTDContext::Pop(nsEntryStack *&aChildStyleStack) { - PRInt32 theSize=mStack.mCount; - nsIParserNode *result=0; + PRInt32 theSize=mStack.mCount; + nsIParserNode* result=0; if(0mStyles; + aChildStyleStack=theEntry->mStyles; } result=mStack.Pop(); + theEntry->mParent=0; } return result; @@ -457,10 +485,6 @@ void nsDTDContext::PushStyle(const nsIParserNode* aNode){ } if(theStack) { theStack->Push(aNode); - theEntry=&theStack->mEntries[theStack->mCount-1]; - if(theEntry) { - theEntry->mParent=theStack; - } } } //if } @@ -480,6 +504,16 @@ void nsDTDContext::PushStyles(nsEntryStack *aStyles){ nsEntryStack* theStyles=theEntry->mStyles; if(!theStyles) { theEntry->mStyles=aStyles; + + PRUint32 scount=aStyles->mCount; + PRUint32 sindex=0; + + nsTagEntry *theEntry=aStyles->mEntries; + for(sindex=0;sindexmParent=0; //this tells us that the style is not open at any level + theEntry++; + } //for + } else theStyles->Append(aStyles); } //if @@ -492,15 +526,13 @@ void nsDTDContext::PushStyles(nsEntryStack *aStyles){ * @update gess 04/28/99 */ nsIParserNode* nsDTDContext::PopStyle(void){ - nsIParserNode* result=0; + nsIParserNode *result=0; nsTagEntry *theEntry=mStack.EntryAt(mStack.mCount-1); if(theEntry && (theEntry->mNode)) { - if(kNotFoundmLevel){ - nsEntryStack *theStack=mStack.mEntries[theEntry->mLevel].mStyles; - if(theStack) { - result=theStack->Pop(); - } + nsEntryStack* theStyleStack=theEntry->mParent; + if(theStyleStack){ + result=theStyleStack->Pop(); } } //if return result; diff --git a/mozilla/htmlparser/src/nsDTDUtils.h b/mozilla/htmlparser/src/nsDTDUtils.h index 1a37dcc7e40..e8b1700f2c7 100644 --- a/mozilla/htmlparser/src/nsDTDUtils.h +++ b/mozilla/htmlparser/src/nsDTDUtils.h @@ -75,7 +75,6 @@ class nsEntryStack; //forware declare to make compilers happy. struct nsTagEntry { eHTMLTags mTag; //for speedier access to tag id nsIParserNode* mNode; - PRInt32 mLevel; nsEntryStack* mParent; nsEntryStack* mStyles; }; @@ -86,8 +85,8 @@ public: ~nsEntryStack(); void EnsureCapacityFor(PRInt32 aNewMax, PRInt32 aShiftOffset=0); - void Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel=-1); - void PushFront(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel=-1); + void Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack=0); + void PushFront(const nsIParserNode* aNode,nsEntryStack* aStyleStack=0); void Append(nsEntryStack *theStack); nsIParserNode* Pop(void); nsIParserNode* NodeAt(PRInt32 anIndex) const; @@ -132,8 +131,8 @@ public: nsDTDContext(); ~nsDTDContext(); - void Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel=-1); - nsIParserNode* Pop(nsEntryStack*& aStack); + void Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack=0); + nsIParserNode* Pop(nsEntryStack*& aChildStack); eHTMLTags First(void) const; eHTMLTags Last(void) const; eHTMLTags TagAt(PRInt32 anIndex) const; diff --git a/mozilla/htmlparser/src/nsElementTable.cpp b/mozilla/htmlparser/src/nsElementTable.cpp index 526e45e652e..cea8c7f7d6a 100644 --- a/mozilla/htmlparser/src/nsElementTable.cpp +++ b/mozilla/htmlparser/src/nsElementTable.cpp @@ -193,15 +193,11 @@ TagList gDontAutoClose={1,{eHTMLTag_td}}; //********************************************************************************************* -#define FSTYPE kInlineEntity -#define SPECIALTYPE kInlineEntity - const int kNoPropRange=0; const int kDefaultPropRange=1; const int kBodyPropRange=2; - //********************************************************************************************* // // Now let's dynamically build the element table... @@ -213,19 +209,19 @@ nsHTMLElement* gHTMLElements=0; void Initialize(eHTMLTags aTag, eHTMLTags aRequiredAncestor, eHTMLTags aExcludingAncestor, - TagList* aRootNodes, - TagList* aEndRootNodes, - TagList* aAutocloseStart, - TagList* aAutocloseEnd, - TagList* aSynonymousTags, - TagList* aDontAutocloseEnd, + TagList* aRootNodes, + TagList* aEndRootNodes, + TagList* aAutocloseStart, + TagList* aAutocloseEnd, + TagList* aSynonymousTags, + TagList* aDontAutocloseEnd, int aParentBits, int aInclusionBits, int aExclusionBits, int aSpecialProperties, int aPropagateRange, - TagList* aSpecialParents, - TagList* aSpecialKids, + TagList* aSpecialParents, + TagList* aSpecialKids, eHTMLTags aSkipTarget ) { @@ -273,7 +269,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, SPECIALTYPE|kBlockEntity, kNone, + /*parent,incl,exclgroups*/ kSpecial, kInlineEntity, kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -309,7 +305,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE|kFlowEntity), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity|kFlowEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gContainsParam,eHTMLTag_unknown); @@ -327,7 +323,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (FSTYPE|kSelf), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kInlineEntity|kSelf), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -345,7 +341,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, SPECIALTYPE, kNone, + /*parent,incl,exclgroups*/ kSpecial, kInlineEntity, kNone, /*special props, prop-range*/ kNonContainer, kNoPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -354,7 +350,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -372,7 +368,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (FSTYPE|kSelf), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kInlineEntity|kSelf), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -579,7 +575,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial|kFontStyle, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial|kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gFontKids,eHTMLTag_unknown); @@ -697,7 +693,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0, kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -814,7 +810,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gLIRootTags,&gLIRootTags, /*autoclose starttags and endtags*/ &gLIAutoClose,0,0,0, - /*parent,incl,exclgroups*/ kFlowEntity, kFlowEntity, kSelf, + /*parent,incl,exclgroups*/ kBlockEntity, kFlowEntity, kSelf, /*special props, prop-range*/ kNoPropagate, kDefaultPropRange, /*special parents,kids,skip*/ 0,&gLIKids,eHTMLTag_unknown); @@ -841,7 +837,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, SPECIALTYPE|kBlockEntity, kNone, + /*parent,incl,exclgroups*/ kSpecial, kInlineEntity|kBlockEntity, kNone, /*special props, prop-range*/ kOmitWS, kDefaultPropRange, /*special parents,kids,skip*/ 0,&gMapKids,eHTMLTag_unknown); @@ -922,7 +918,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ (kHeadMisc|kSpecial), (kFlowEntity|SPECIALTYPE|kSelf), kNone, + /*parent,incl,exclgroups*/ (kHeadMisc|kSpecial), (kFlowEntity|kInlineEntity|kSelf), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gContainsParam,eHTMLTag_unknown); @@ -1003,7 +999,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1012,7 +1008,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1057,7 +1053,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1106,7 +1102,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1135,7 +1131,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1145,7 +1141,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1235,7 +1231,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1244,7 +1240,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1681,33 +1677,34 @@ PRBool nsHTMLElement::IsStyleTag(eHTMLTags aChild) { PRBool result=PR_FALSE; switch(aChild) { case eHTMLTag_a: - case eHTMLTag_acronym: +// case eHTMLTag_abbr: +// case eHTMLTag_acronym: case eHTMLTag_b: case eHTMLTag_bdo: case eHTMLTag_big: case eHTMLTag_blink: - case eHTMLTag_center: - case eHTMLTag_cite: - case eHTMLTag_code: +// case eHTMLTag_center: +// case eHTMLTag_cite: +// case eHTMLTag_code: case eHTMLTag_del: - case eHTMLTag_dfn: - case eHTMLTag_em: +// case eHTMLTag_dfn: +// case eHTMLTag_em: case eHTMLTag_font: case eHTMLTag_i: case eHTMLTag_ins: - case eHTMLTag_kbd: +// case eHTMLTag_kbd: case eHTMLTag_q: case eHTMLTag_s: - case eHTMLTag_samp: +// case eHTMLTag_samp: case eHTMLTag_small: case eHTMLTag_span: case eHTMLTag_strike: - case eHTMLTag_strong: +// case eHTMLTag_strong: case eHTMLTag_sub: case eHTMLTag_sup: case eHTMLTag_tt: case eHTMLTag_u: - case eHTMLTag_var: +// case eHTMLTag_var: result=PR_TRUE; default: break; @@ -1811,7 +1808,7 @@ PRBool nsHTMLElement::CanContainSelf(void) const { PRBool nsHTMLElement::CanAutoCloseTag(eHTMLTags aTag) const{ PRBool result=PR_TRUE; if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_userdefined)) { - TagList* theTagList=gHTMLElements[mTagID].GetNonAutoCloseEndTags(); + TagList* theTagList=gHTMLElements[mTagID].mDontAutocloseEnd; if(theTagList) { result=!FindTagInSet(aTag,theTagList->mTags,theTagList->mCount); } @@ -1912,6 +1909,11 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{ return PR_FALSE; } + if(nsHTMLElement::IsBlockEntity(aChild)){ + if(nsHTMLElement::IsBlockParent(mTagID)){ + return PR_TRUE; + } + } if(nsHTMLElement::IsInlineEntity(aChild)){ if(nsHTMLElement::IsInlineParent(mTagID)){ @@ -1931,12 +1933,6 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{ } } - if(nsHTMLElement::IsBlockEntity(aChild)){ - if(nsHTMLElement::IsBlockParent(mTagID) || IsStyleTag(mTagID)){ - return PR_TRUE; - } - } - if(CanContainType(gHTMLElements[aChild].mParentBits)) { return PR_TRUE; } diff --git a/mozilla/htmlparser/src/nsElementTable.h b/mozilla/htmlparser/src/nsElementTable.h index 095aad35959..934bcd71a55 100644 --- a/mozilla/htmlparser/src/nsElementTable.h +++ b/mozilla/htmlparser/src/nsElementTable.h @@ -73,7 +73,6 @@ struct nsHTMLElement { TagList* GetEndRootTags(void) const {return mEndRootNodes;} TagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;} TagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;} - TagList* GetNonAutoCloseEndTags(void) const {return mDontAutocloseEnd;} eHTMLTags GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32 anIndex) const; TagList* GetSpecialChildren(void) const {return mSpecialKids;} @@ -114,7 +113,7 @@ struct nsHTMLElement { TagList* mAutocloseStart; //these are the start tags that you can automatically close with this START tag TagList* mAutocloseEnd; //these are the start tags that you can automatically close with this END tag TagList* mSynonymousTags; //These are morally equivalent; an end tag for one can close a start tag for another (like ) - TagList* mDontAutocloseEnd; //these are the end tags that you cannot automatically close with this END tag + TagList* mDontAutocloseEnd; //... int mParentBits; //defines groups that can contain this element int mInclusionBits; //defines parental and containment rules int mExclusionBits; //defines things you CANNOT contain diff --git a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp index 98fdcc68f04..dfc0558a044 100644 --- a/mozilla/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokenizer.cpp @@ -359,8 +359,9 @@ nsresult nsHTMLTokenizer::ConsumeTag(PRUnichar aChar,CToken*& aToken,nsScanner& PRUnichar theNextChar; result=aScanner.Peek(theNextChar); if(NS_OK==result) { - if(theNextChar==kMinus) + if((kMinus==theNextChar) || (kGreaterThan==theNextChar)) { result=ConsumeComment(aChar,aToken,aScanner); + } else result=ConsumeSpecialMarkup(aChar,aToken,aScanner); } diff --git a/mozilla/htmlparser/src/nsHTMLTokens.cpp b/mozilla/htmlparser/src/nsHTMLTokens.cpp index 88dccf4c3a8..53f21540120 100644 --- a/mozilla/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/htmlparser/src/nsHTMLTokens.cpp @@ -770,8 +770,10 @@ nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aSt }//if }//while if(NS_OK==result) { - //if you're here, we're consuming a "short-form" comment - result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + //Read up to the closing '>', unless you already did! (such as ). + if(kGreaterThan!=aChar) { + result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + } } return result; } @@ -864,8 +866,10 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) }//if }//if if(NS_OK==result) { - //Read up to the closing '>' - result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + //Read up to the closing '>', unless you already did! (such as ). + if(kGreaterThan!=aChar) { + result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + } } return result; } diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp index e11e22bd4a3..b200d350b63 100644 --- a/mozilla/htmlparser/src/nsParser.cpp +++ b/mozilla/htmlparser/src/nsParser.cpp @@ -926,7 +926,12 @@ nsresult nsParser::ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITag } theContext.Append(""); //XXXHack! I'll make this better later. nsAutoString theBuffer(theContext); + +#if 0 theBuffer.Append(aSourceBuffer); +#else + theBuffer.Append("text"); +#endif if(theBuffer.Length()){ //now it's time to try to build the model from this fragment diff --git a/mozilla/htmlparser/src/nsParserNode.cpp b/mozilla/htmlparser/src/nsParserNode.cpp index 3d8028284f0..c06b1e3d6e7 100644 --- a/mozilla/htmlparser/src/nsParserNode.cpp +++ b/mozilla/htmlparser/src/nsParserNode.cpp @@ -57,7 +57,6 @@ nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler mToken=aToken; mRecycler=aRecycler; mUseCount=0; - mIsResidual=PR_FALSE; } static void RecycleTokens(nsITokenRecycler* aRecycler,nsDeque& aDeque) { @@ -111,7 +110,6 @@ nsresult nsCParserNode::Init(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler RecycleTokens(mRecycler,*mAttributes); mToken=aToken; mUseCount=0; - mIsResidual=PR_FALSE; mSkippedContent.Truncate(); return NS_OK; } diff --git a/mozilla/htmlparser/src/nsParserNode.h b/mozilla/htmlparser/src/nsParserNode.h index 698a2c592ee..d552af1613d 100644 --- a/mozilla/htmlparser/src/nsParserNode.h +++ b/mozilla/htmlparser/src/nsParserNode.h @@ -179,7 +179,6 @@ class nsCParserNode : public nsIParserNode { nsDeque* mAttributes; nsAutoString mSkippedContent; PRInt32 mUseCount; - PRBool mIsResidual; nsITokenRecycler* mRecycler; }; diff --git a/mozilla/htmlparser/src/nsScanner.cpp b/mozilla/htmlparser/src/nsScanner.cpp index 26eebc81511..9f9b427d4a1 100644 --- a/mozilla/htmlparser/src/nsScanner.cpp +++ b/mozilla/htmlparser/src/nsScanner.cpp @@ -323,7 +323,7 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ */ PRBool nsScanner::Append(const PRUnichar* aBuffer, PRUint32 aLen){ - if(-1==aLen) + if(-1==(PRInt32)aLen) aLen=nsCRT::strlen(aBuffer); CBufDescriptor theDesc(aBuffer,PR_TRUE, aLen+1,aLen); diff --git a/mozilla/parser/htmlparser/src/CNavDTD.cpp b/mozilla/parser/htmlparser/src/CNavDTD.cpp index 53f2a70e39e..a7f505aa6e2 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.cpp +++ b/mozilla/parser/htmlparser/src/CNavDTD.cpp @@ -49,7 +49,7 @@ #endif #include "prmem.h" -//#define ENABLE_RESIDUALSTYLE +#define ENABLE_RESIDUALSTYLE //#define RICKG_DEBUG //#define ENABLE_CRC #ifdef RICKG_DEBUG @@ -458,7 +458,8 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename, mLineNumber=1; mHasOpenScript=PR_FALSE; mParseMode=aParseMode; - + mStyleHandlingEnabled=(eParseMode_quirks==mParseMode); + if((aNotifySink) && (aSink)) { STOP_TIMER(); @@ -577,6 +578,24 @@ nsresult CNavDTD::DidBuildModel(nsresult anErrorCode,PRBool aNotifySink,nsIParse } } } + else { + //If you're here, then an error occured, but we still have nodes on the stack. + //At a minimum, we should grab the nodes and recycle them. + //Just to be correct, we'll also recycle the nodes. + + while(mBodyContext->GetCount() > 0) { + + nsEntryStack *theChildStyles=0; + nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theChildStyles); + theNode->mUseCount=0; + RecycleNode(theNode); + if(theChildStyles) { + delete theChildStyles; + } + } + + } + STOP_TIMER(); MOZ_TIMER_DEBUGLOG(("Stop: Parse Time: CNavDTD::DidBuildModel(), this=%p\n", this)); @@ -1006,7 +1025,7 @@ nsresult CNavDTD::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsI // The safest thing to do is to discard this tag. return result; } - CloseContainersTo(theIndex,theParentTag,PR_TRUE); + CloseContainersTo(theIndex,aChildTag,PR_TRUE); }//if else break; }//if @@ -1609,9 +1628,10 @@ nsresult CNavDTD::HandleSavedTokens(PRInt32 anIndex) { // The body context should contain contents only upto the marked position. PRInt32 i=0; - nsEntryStack *theStack=0; + nsEntryStack* theChildStyleStack=0; + for(i=0; i<(theTagCount - theTopIndex); i++) { - mTempContext->Push((nsCParserNode*)mBodyContext->Pop(theStack)); + mTempContext->Push((nsCParserNode*)mBodyContext->Pop(theChildStyleStack)); } // Now flush out all the bad contents. @@ -1644,7 +1664,7 @@ nsresult CNavDTD::HandleSavedTokens(PRInt32 anIndex) { // Bad-contents were successfully processed. Now, itz time to get // back to the original body context state. for(PRInt32 k=0; k<(theTagCount - theTopIndex); k++) { - mBodyContext->Push((nsCParserNode*)mTempContext->Pop(theStack)); + mBodyContext->Push((nsCParserNode*)mTempContext->Pop(theChildStyleStack)); } STOP_TIMER() @@ -2312,35 +2332,41 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aChildTag){ //later, change this so that transients only open in containers that get leaked in to. + if(mStyleHandlingEnabled) { + #ifdef ENABLE_RESIDUALSTYLE - eHTMLTags theParentTag=mBodyContext->Last(); - if(!gHTMLElements[theParentTag].HasSpecialProperty(kNoStyleLeaksIn)) { - //the following code builds the set of style tags to be opened... - PRUint32 theCount=mBodyContext->GetCount()-1; - PRUint32 theLevel=0; - for(theLevel=0;theLevelGetStylesAt(theLevel); - if(theStack){ + eHTMLTags theParentTag=mBodyContext->Last(); - PRUint32 scount=theStack->mCount; - PRUint32 sindex=0; + if(CanContain(eHTMLTag_font,aChildTag)) { + if(!gHTMLElements[theParentTag].HasSpecialProperty(kNoStyleLeaksIn)) { + //the following code builds the set of style tags to be opened... + PRUint32 theCount=mBodyContext->GetCount(); + PRUint32 theLevel=0; + for(theLevel=0;theLevelGetStylesAt(theLevel); + if(theStack){ - nsTagEntry *theEntry=theStack->mEntries; - for(sindex=0;sindexmLevel) { - theEntry->mLevel=theLevel; - nsIParserNode* theNode=theEntry->mNode; - if(theNode) { - result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE,theLevel); - } - } - theEntry++; + PRUint32 scount=theStack->mCount; + PRUint32 sindex=0; + + nsTagEntry *theEntry=theStack->mEntries; + for(sindex=0;sindexmParent) { + theEntry->mParent=theStack; //we do this too, because this entry differs from the new one we're pushing... + nsIParserNode* theNode=theEntry->mNode; + if(theNode) { + result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE,theStack); + } + } + theEntry++; + } //for + } //if } //for } //if - } //for - } + } #endif + }//if return result; } @@ -2359,21 +2385,24 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aChildTag){ nsresult CNavDTD::CloseTransientStyles(eHTMLTags aChildTag){ nsresult result=NS_OK; + if(mStyleHandlingEnabled) { + #ifdef ENABLE_RESIDUALSTYLE #if 0 - int theTagPos=0; - //now iterate style set, and close the containers... + int theTagPos=0; + //now iterate style set, and close the containers... - nsEntryStack* theStack=mBodyContext->GetStylesAt(); - for(theTagPos=mBodyContext->mOpenStyles;theTagPos>0;theTagPos--){ - eHTMLTags theTag=GetTopNode(); - CStartToken token(theTag); - nsCParserNode theNode(&token,mLineNumber); - token.SetTypeID(theTag); - result=CloseContainer(theNode,theTag,PR_FALSE); - } + nsEntryStack* theStack=mBodyContext->GetStylesAt(); + for(theTagPos=mBodyContext->mOpenStyles;theTagPos>0;theTagPos--){ + eHTMLTags theTag=GetTopNode(); + CStartToken token(theTag); + nsCParserNode theNode(&token,mLineNumber); + token.SetTypeID(theTag); + result=CloseContainer(theNode,theTag,PR_FALSE); + } #endif #endif + } //if return result; } @@ -2388,14 +2417,16 @@ nsresult CNavDTD::CloseTransientStyles(eHTMLTags aChildTag){ nsresult CNavDTD::PopStyle(eHTMLTags aTag){ nsresult result=0; + if(mStyleHandlingEnabled) { #ifdef ENABLE_RESIDUALSTYLE - if(nsHTMLElement::IsStyleTag(aTag)) { - nsCParserNode *theNode=(nsCParserNode*)mBodyContext->PopStyle(aTag); - if(theNode) { - RecycleNode(theNode); + if(nsHTMLElement::IsStyleTag(aTag)) { + nsCParserNode* theNode=(nsCParserNode*)mBodyContext->PopStyle(aTag); + if(theNode) { + RecycleNode(theNode); + } } - } #endif + } //if return result; } @@ -2725,7 +2756,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode *aNode){ * @return TRUE if ok, FALSE if error */ nsresult -CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,PRInt32 aResidualStyleLevel){ +CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,nsEntryStack* aStyleStack){ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos); nsresult result=NS_OK; @@ -2804,7 +2835,7 @@ CNavDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedB MOZ_TIMER_DEBUGLOG(("Start: Parse Time: CNavDTD::OpenContainer(), this=%p\n", this)); START_TIMER(); - mBodyContext->Push(aNode,aResidualStyleLevel); + mBodyContext->Push(aNode,aStyleStack); } return result; @@ -2897,8 +2928,9 @@ nsresult CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTarget, PRBool aC theTag=mBodyContext->Last(); - nsEntryStack *theStyles=0; - nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theStyles); + nsEntryStack *theChildStyleStack=0; + + nsCParserNode* theNode=(nsCParserNode*)mBodyContext->Pop(theChildStyleStack); result=CloseContainer(theNode,aTarget,aClosedByStartTag); if(theNode) { @@ -2907,11 +2939,18 @@ nsresult CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTarget, PRBool aC PRBool theTagIsStyle=nsHTMLElement::IsStyleTag(theTag); if(mStyleHandlingEnabled) { - if(aClosedByStartTag) { + if(aClosedByStartTag && (0==theNode->mUseCount)) { + + + /*************************************************************************** + The cases we're handing here: + 1.
// gets pushed onto .mStyles. + ***************************************************************************/ + if(theTagIsStyle) { - if(theStyles) { - theStyles->PushFront(theNode); - mBodyContext->PushStyles(theStyles); + if(theChildStyleStack) { + theChildStyleStack->PushFront(theNode); + mBodyContext->PushStyles(theChildStyleStack); } else mBodyContext->PushStyle(theNode); } @@ -2920,53 +2959,78 @@ nsresult CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTarget, PRBool aC //if you're here, then we're dealing with the closure of tags //caused by a close tag (as opposed to an open tag). //At a minimum, we should consider pushing residual styles up - //up the stack... + //up the stack or popping and recycling displaced nodes. - if(aTarget!=theTag) { - if(theTagIsStyle) { - if(theStyles) { - theStyles->PushFront(theNode); - mBodyContext->PushStyles(theStyles); - } - else mBodyContext->PushStyle(theNode); - } - else if(theStyles) { - mBodyContext->PushStyles(theStyles); + /*************************************************************************** + There are 2 cases: + 1.
text
+ Here the will leak into
(see case given above), and + when
closes the is dropped since it's already residual. + 2.
text
+ Here the will leak out of the
and get pushed onto + the RS stack for the , since it originated in the
. + ***************************************************************************/ + + if(theTagIsStyle) { + if(theChildStyleStack) { + theChildStyleStack->PushFront(theNode); + mBodyContext->PushStyles(theChildStyleStack); } + else if (0==theNode->mUseCount) { + if(theTag!=aTarget) { + mBodyContext->PushStyle(theNode); + } //otherwise just let the node recycle, because it was explicty closed + //and does not live on a style stack. + } + else { + //Ah, at last, the final case. If you're here, then we just popped a + //style tag that got onto that tag stack from a stylestack somewhere. + //The the target==theTag, then pop it from the stylestack. + if(theTag==aTarget) { + nsIParserNode* theNextNode=mBodyContext->PopStyle(theTag); + } + } + } + else if(theChildStyleStack) { + mBodyContext->PushStyles(theChildStyleStack); } } - } + } //if else { //since stylehandling is disabled, let's recycle the associated nodes here... } #endif - RecycleNode(theNode); - } + }//if + RecycleNode(theNode); } + + if(eParseMode_quirks==mParseMode) { + #ifdef ENABLE_RESIDUALSTYLE - //This code takes any nodes in style stack for at this level and reopens - //then where they were originally. + //This code takes any nodes in style stack for at this level and reopens + //then where they were originally. - if(!aClosedByStartTag) { - nsEntryStack* theStack=mBodyContext->GetStylesAt(anIndex-1); - if(theStack){ + if(!aClosedByStartTag) { + nsEntryStack* theStack=mBodyContext->GetStylesAt(anIndex-1); + if(theStack){ - PRUint32 scount=theStack->mCount; - PRUint32 sindex=0; + PRUint32 scount=theStack->mCount; + PRUint32 sindex=0; - for(sindex=0;sindexNodeAt(sindex); - if(theNode) { - ((nsCParserNode*)theNode)->mUseCount--; - result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE); - } - } - theStack->mCount=0; + for(sindex=0;sindexNodeAt(sindex); + if(theNode) { + ((nsCParserNode*)theNode)->mUseCount--; + result=OpenContainer(theNode,(eHTMLTags)theNode->GetNodeType(),PR_FALSE); + } + } + theStack->mCount=0; + } //if } //if - } //if #endif + }//if } //if return result; diff --git a/mozilla/parser/htmlparser/src/CNavDTD.h b/mozilla/parser/htmlparser/src/CNavDTD.h index 0ac0e39d7c9..ef1050fd413 100644 --- a/mozilla/parser/htmlparser/src/CNavDTD.h +++ b/mozilla/parser/htmlparser/src/CNavDTD.h @@ -448,7 +448,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD { nsresult OpenForm(const nsIParserNode *aNode); nsresult OpenMap(const nsIParserNode *aNode); nsresult OpenFrameset(const nsIParserNode *aNode); - nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,PRInt32 aResidualStyleLevel=-1); + nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aClosedByStartTag,nsEntryStack* aStyleStack=0); /** * The next set of methods close the given HTML element. diff --git a/mozilla/parser/htmlparser/src/COtherDTD.cpp b/mozilla/parser/htmlparser/src/COtherDTD.cpp index cd656990ee3..224f7d8471f 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.cpp +++ b/mozilla/parser/htmlparser/src/COtherDTD.cpp @@ -534,8 +534,8 @@ nsresult COtherDTD::CloseFrameset(const nsIParserNode *aNode){ * @param aNode -- next node to be added to model * @return TRUE if ok, FALSE if error */ -nsresult COtherDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTarget,PRBool aUpdateStyleStack,PRInt32 aResidualStyleLevel){ - return CNavDTD::OpenContainer(aNode,aTarget,aUpdateStyleStack,aResidualStyleLevel); +nsresult COtherDTD::OpenContainer(const nsIParserNode *aNode,eHTMLTags aTarget,PRBool aUpdateStyleStack,nsEntryStack* aStyleStack){ + return CNavDTD::OpenContainer(aNode,aTarget,aUpdateStyleStack,aStyleStack); } /** diff --git a/mozilla/parser/htmlparser/src/COtherDTD.h b/mozilla/parser/htmlparser/src/COtherDTD.h index fd1bc877f7c..558db944872 100644 --- a/mozilla/parser/htmlparser/src/COtherDTD.h +++ b/mozilla/parser/htmlparser/src/COtherDTD.h @@ -233,7 +233,7 @@ private: nsresult OpenForm(const nsIParserNode *aNode); nsresult OpenMap(const nsIParserNode *aNode); nsresult OpenFrameset(const nsIParserNode *aNode); - nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aUpdateStyleStack,PRInt32 aResidualStyleLevel=-1); + nsresult OpenContainer(const nsIParserNode *aNode,eHTMLTags aTag,PRBool aUpdateStyleStack,nsEntryStack* aStyleStack=0); /** * The next set of methods close the given HTML element. diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp index ab74d17a48a..459db6744df 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.cpp +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.cpp @@ -34,7 +34,18 @@ MOZ_DECL_CTOR_COUNTER(nsDTDContext); MOZ_DECL_CTOR_COUNTER(CTokenRecycler); MOZ_DECL_CTOR_COUNTER(CObserverService); +/************************************************************************************** + A few notes about how residual style handling is performed: + + 1. The style stack contains nsTagEntry elements. + 2. Every tag on the containment stack can have it's own residual style stack. + 3. When a style leaks, it's mParent member is set to the level on the stack where + it originated. A node with an mParent of 0 is not opened on tag stack, + but is open on stylestack. + 4. An easy way to tell that a container on the element stack is a residual style tag + is that it's use count is >1. + **************************************************************************************/ /** * Default constructor @@ -117,7 +128,7 @@ void nsEntryStack::EnsureCapacityFor(PRInt32 aNewMax,PRInt32 aShiftOffset) { * * @update gess 04/22/99 */ -void nsEntryStack::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) { +void nsEntryStack::Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack) { if(aNode) { EnsureCapacityFor(mCount+1); @@ -127,8 +138,7 @@ void nsEntryStack::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) mEntries[mCount].mTag=(eHTMLTags)aNode->GetNodeType(); mEntries[mCount].mNode=(nsIParserNode*)aNode; - mEntries[mCount].mLevel=aResidualStyleLevel; - mEntries[mCount].mParent=0; + mEntries[mCount].mParent=aStyleStack; mEntries[mCount++].mStyles=0; } } @@ -139,7 +149,7 @@ void nsEntryStack::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) * * @update gess 11/10/99 */ -void nsEntryStack::PushFront(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) { +void nsEntryStack::PushFront(const nsIParserNode* aNode,nsEntryStack* aStyleStack) { if(aNode) { if(mCountGetNodeType(); mEntries[0].mNode=(nsIParserNode*)aNode; - mEntries[0].mLevel=aResidualStyleLevel; - mEntries[0].mParent=0; + mEntries[0].mParent=aStyleStack; mEntries[0].mStyles=0; mCount++; } @@ -177,7 +186,7 @@ void nsEntryStack::Append(nsEntryStack *aStack) { PRInt32 theIndex=0; for(theIndex=0;theIndexmEntries[theIndex]; - mEntries[mCount++].mLevel=-1; + mEntries[mCount++].mParent=0; } } } @@ -190,7 +199,7 @@ void nsEntryStack::Append(nsEntryStack *aStack) { */ nsIParserNode* nsEntryStack::Pop(void) { - nsIParserNode *result=0; + nsIParserNode* result=0; if(0mToken->mUseCount--; mEntries[mCount].mNode=0; mEntries[mCount].mStyles=0; + + nsEntryStack* theStyleStack=mEntries[mCount].mParent; + + if(theStyleStack) { + //now we have to tell the residual style stack where this tag + //originated that it's no longer in use. + PRUint32 scount=theStyleStack->mCount; + PRUint32 sindex=0; + + nsTagEntry *theStyleEntry=theStyleStack->mEntries; + for(sindex=scount-1;sindex>=0;sindex--){ + if(theStyleEntry->mTag==mEntries[mCount].mTag) { + theStyleEntry->mParent=0; //this tells us that the style is not open at any level + break; + } + theStyleEntry++; + } //for + } } return result; } @@ -358,7 +385,7 @@ PRInt32 nsDTDContext::GetTopmostIndexOf(eHTMLTags aTag) const { * * @update gess7/9/98 */ -void nsDTDContext::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) { +void nsDTDContext::Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack) { if(aNode) { #ifdef NS_DEBUG @@ -367,7 +394,7 @@ void nsDTDContext::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) if(size< eMaxTags) mXTags[size]=theTag; #endif - mStack.Push((nsIParserNode*)aNode,aResidualStyleLevel); + mStack.Push((nsIParserNode*)aNode,aStyleStack); } } @@ -375,10 +402,10 @@ void nsDTDContext::Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel) * @update gess 11/11/99, * harishd 04/04/99 */ -nsIParserNode* nsDTDContext::Pop(nsEntryStack *&aStack) { +nsIParserNode* nsDTDContext::Pop(nsEntryStack *&aChildStyleStack) { - PRInt32 theSize=mStack.mCount; - nsIParserNode *result=0; + PRInt32 theSize=mStack.mCount; + nsIParserNode* result=0; if(0mStyles; + aChildStyleStack=theEntry->mStyles; } result=mStack.Pop(); + theEntry->mParent=0; } return result; @@ -457,10 +485,6 @@ void nsDTDContext::PushStyle(const nsIParserNode* aNode){ } if(theStack) { theStack->Push(aNode); - theEntry=&theStack->mEntries[theStack->mCount-1]; - if(theEntry) { - theEntry->mParent=theStack; - } } } //if } @@ -480,6 +504,16 @@ void nsDTDContext::PushStyles(nsEntryStack *aStyles){ nsEntryStack* theStyles=theEntry->mStyles; if(!theStyles) { theEntry->mStyles=aStyles; + + PRUint32 scount=aStyles->mCount; + PRUint32 sindex=0; + + nsTagEntry *theEntry=aStyles->mEntries; + for(sindex=0;sindexmParent=0; //this tells us that the style is not open at any level + theEntry++; + } //for + } else theStyles->Append(aStyles); } //if @@ -492,15 +526,13 @@ void nsDTDContext::PushStyles(nsEntryStack *aStyles){ * @update gess 04/28/99 */ nsIParserNode* nsDTDContext::PopStyle(void){ - nsIParserNode* result=0; + nsIParserNode *result=0; nsTagEntry *theEntry=mStack.EntryAt(mStack.mCount-1); if(theEntry && (theEntry->mNode)) { - if(kNotFoundmLevel){ - nsEntryStack *theStack=mStack.mEntries[theEntry->mLevel].mStyles; - if(theStack) { - result=theStack->Pop(); - } + nsEntryStack* theStyleStack=theEntry->mParent; + if(theStyleStack){ + result=theStyleStack->Pop(); } } //if return result; diff --git a/mozilla/parser/htmlparser/src/nsDTDUtils.h b/mozilla/parser/htmlparser/src/nsDTDUtils.h index 1a37dcc7e40..e8b1700f2c7 100644 --- a/mozilla/parser/htmlparser/src/nsDTDUtils.h +++ b/mozilla/parser/htmlparser/src/nsDTDUtils.h @@ -75,7 +75,6 @@ class nsEntryStack; //forware declare to make compilers happy. struct nsTagEntry { eHTMLTags mTag; //for speedier access to tag id nsIParserNode* mNode; - PRInt32 mLevel; nsEntryStack* mParent; nsEntryStack* mStyles; }; @@ -86,8 +85,8 @@ public: ~nsEntryStack(); void EnsureCapacityFor(PRInt32 aNewMax, PRInt32 aShiftOffset=0); - void Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel=-1); - void PushFront(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel=-1); + void Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack=0); + void PushFront(const nsIParserNode* aNode,nsEntryStack* aStyleStack=0); void Append(nsEntryStack *theStack); nsIParserNode* Pop(void); nsIParserNode* NodeAt(PRInt32 anIndex) const; @@ -132,8 +131,8 @@ public: nsDTDContext(); ~nsDTDContext(); - void Push(const nsIParserNode* aNode,PRInt32 aResidualStyleLevel=-1); - nsIParserNode* Pop(nsEntryStack*& aStack); + void Push(const nsIParserNode* aNode,nsEntryStack* aStyleStack=0); + nsIParserNode* Pop(nsEntryStack*& aChildStack); eHTMLTags First(void) const; eHTMLTags Last(void) const; eHTMLTags TagAt(PRInt32 anIndex) const; diff --git a/mozilla/parser/htmlparser/src/nsElementTable.cpp b/mozilla/parser/htmlparser/src/nsElementTable.cpp index 526e45e652e..cea8c7f7d6a 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.cpp +++ b/mozilla/parser/htmlparser/src/nsElementTable.cpp @@ -193,15 +193,11 @@ TagList gDontAutoClose={1,{eHTMLTag_td}}; //********************************************************************************************* -#define FSTYPE kInlineEntity -#define SPECIALTYPE kInlineEntity - const int kNoPropRange=0; const int kDefaultPropRange=1; const int kBodyPropRange=2; - //********************************************************************************************* // // Now let's dynamically build the element table... @@ -213,19 +209,19 @@ nsHTMLElement* gHTMLElements=0; void Initialize(eHTMLTags aTag, eHTMLTags aRequiredAncestor, eHTMLTags aExcludingAncestor, - TagList* aRootNodes, - TagList* aEndRootNodes, - TagList* aAutocloseStart, - TagList* aAutocloseEnd, - TagList* aSynonymousTags, - TagList* aDontAutocloseEnd, + TagList* aRootNodes, + TagList* aEndRootNodes, + TagList* aAutocloseStart, + TagList* aAutocloseEnd, + TagList* aSynonymousTags, + TagList* aDontAutocloseEnd, int aParentBits, int aInclusionBits, int aExclusionBits, int aSpecialProperties, int aPropagateRange, - TagList* aSpecialParents, - TagList* aSpecialKids, + TagList* aSpecialParents, + TagList* aSpecialKids, eHTMLTags aSkipTarget ) { @@ -273,7 +269,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, SPECIALTYPE|kBlockEntity, kNone, + /*parent,incl,exclgroups*/ kSpecial, kInlineEntity, kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -309,7 +305,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE|kFlowEntity), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity|kFlowEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gContainsParam,eHTMLTag_unknown); @@ -327,7 +323,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (FSTYPE|kSelf), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kInlineEntity|kSelf), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -345,7 +341,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, SPECIALTYPE, kNone, + /*parent,incl,exclgroups*/ kSpecial, kInlineEntity, kNone, /*special props, prop-range*/ kNonContainer, kNoPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -354,7 +350,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -372,7 +368,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (FSTYPE|kSelf), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kInlineEntity|kSelf), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -579,7 +575,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial|kFontStyle, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial|kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gFontKids,eHTMLTag_unknown); @@ -697,7 +693,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0, kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -814,7 +810,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gLIRootTags,&gLIRootTags, /*autoclose starttags and endtags*/ &gLIAutoClose,0,0,0, - /*parent,incl,exclgroups*/ kFlowEntity, kFlowEntity, kSelf, + /*parent,incl,exclgroups*/ kBlockEntity, kFlowEntity, kSelf, /*special props, prop-range*/ kNoPropagate, kDefaultPropRange, /*special parents,kids,skip*/ 0,&gLIKids,eHTMLTag_unknown); @@ -841,7 +837,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, SPECIALTYPE|kBlockEntity, kNone, + /*parent,incl,exclgroups*/ kSpecial, kInlineEntity|kBlockEntity, kNone, /*special props, prop-range*/ kOmitWS, kDefaultPropRange, /*special parents,kids,skip*/ 0,&gMapKids,eHTMLTag_unknown); @@ -922,7 +918,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ (kHeadMisc|kSpecial), (kFlowEntity|SPECIALTYPE|kSelf), kNone, + /*parent,incl,exclgroups*/ (kHeadMisc|kSpecial), (kFlowEntity|kInlineEntity|kSelf), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,&gContainsParam,eHTMLTag_unknown); @@ -1003,7 +999,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1012,7 +1008,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1057,7 +1053,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1106,7 +1102,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1135,7 +1131,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1145,7 +1141,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kSpecial, (kSelf|SPECIALTYPE), kNone, + /*parent,incl,exclgroups*/ kSpecial, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1235,7 +1231,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1244,7 +1240,7 @@ void InitializeElementTable(void) { /*req-parent excl-parent*/ eHTMLTag_unknown,eHTMLTag_unknown, /*rootnodes,endrootnodes*/ &gRootTags,&gRootTags, /*autoclose starttags and endtags*/ 0,0,0,0, - /*parent,incl,exclgroups*/ kFontStyle, (kSelf|FSTYPE), kNone, + /*parent,incl,exclgroups*/ kFontStyle, (kSelf|kInlineEntity), kNone, /*special props, prop-range*/ 0,kDefaultPropRange, /*special parents,kids,skip*/ 0,0,eHTMLTag_unknown); @@ -1681,33 +1677,34 @@ PRBool nsHTMLElement::IsStyleTag(eHTMLTags aChild) { PRBool result=PR_FALSE; switch(aChild) { case eHTMLTag_a: - case eHTMLTag_acronym: +// case eHTMLTag_abbr: +// case eHTMLTag_acronym: case eHTMLTag_b: case eHTMLTag_bdo: case eHTMLTag_big: case eHTMLTag_blink: - case eHTMLTag_center: - case eHTMLTag_cite: - case eHTMLTag_code: +// case eHTMLTag_center: +// case eHTMLTag_cite: +// case eHTMLTag_code: case eHTMLTag_del: - case eHTMLTag_dfn: - case eHTMLTag_em: +// case eHTMLTag_dfn: +// case eHTMLTag_em: case eHTMLTag_font: case eHTMLTag_i: case eHTMLTag_ins: - case eHTMLTag_kbd: +// case eHTMLTag_kbd: case eHTMLTag_q: case eHTMLTag_s: - case eHTMLTag_samp: +// case eHTMLTag_samp: case eHTMLTag_small: case eHTMLTag_span: case eHTMLTag_strike: - case eHTMLTag_strong: +// case eHTMLTag_strong: case eHTMLTag_sub: case eHTMLTag_sup: case eHTMLTag_tt: case eHTMLTag_u: - case eHTMLTag_var: +// case eHTMLTag_var: result=PR_TRUE; default: break; @@ -1811,7 +1808,7 @@ PRBool nsHTMLElement::CanContainSelf(void) const { PRBool nsHTMLElement::CanAutoCloseTag(eHTMLTags aTag) const{ PRBool result=PR_TRUE; if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_userdefined)) { - TagList* theTagList=gHTMLElements[mTagID].GetNonAutoCloseEndTags(); + TagList* theTagList=gHTMLElements[mTagID].mDontAutocloseEnd; if(theTagList) { result=!FindTagInSet(aTag,theTagList->mTags,theTagList->mCount); } @@ -1912,6 +1909,11 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{ return PR_FALSE; } + if(nsHTMLElement::IsBlockEntity(aChild)){ + if(nsHTMLElement::IsBlockParent(mTagID)){ + return PR_TRUE; + } + } if(nsHTMLElement::IsInlineEntity(aChild)){ if(nsHTMLElement::IsInlineParent(mTagID)){ @@ -1931,12 +1933,6 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{ } } - if(nsHTMLElement::IsBlockEntity(aChild)){ - if(nsHTMLElement::IsBlockParent(mTagID) || IsStyleTag(mTagID)){ - return PR_TRUE; - } - } - if(CanContainType(gHTMLElements[aChild].mParentBits)) { return PR_TRUE; } diff --git a/mozilla/parser/htmlparser/src/nsElementTable.h b/mozilla/parser/htmlparser/src/nsElementTable.h index 095aad35959..934bcd71a55 100644 --- a/mozilla/parser/htmlparser/src/nsElementTable.h +++ b/mozilla/parser/htmlparser/src/nsElementTable.h @@ -73,7 +73,6 @@ struct nsHTMLElement { TagList* GetEndRootTags(void) const {return mEndRootNodes;} TagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;} TagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;} - TagList* GetNonAutoCloseEndTags(void) const {return mDontAutocloseEnd;} eHTMLTags GetCloseTargetForEndTag(nsDTDContext& aContext,PRInt32 anIndex) const; TagList* GetSpecialChildren(void) const {return mSpecialKids;} @@ -114,7 +113,7 @@ struct nsHTMLElement { TagList* mAutocloseStart; //these are the start tags that you can automatically close with this START tag TagList* mAutocloseEnd; //these are the start tags that you can automatically close with this END tag TagList* mSynonymousTags; //These are morally equivalent; an end tag for one can close a start tag for another (like ) - TagList* mDontAutocloseEnd; //these are the end tags that you cannot automatically close with this END tag + TagList* mDontAutocloseEnd; //... int mParentBits; //defines groups that can contain this element int mInclusionBits; //defines parental and containment rules int mExclusionBits; //defines things you CANNOT contain diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp index 98fdcc68f04..dfc0558a044 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokenizer.cpp @@ -359,8 +359,9 @@ nsresult nsHTMLTokenizer::ConsumeTag(PRUnichar aChar,CToken*& aToken,nsScanner& PRUnichar theNextChar; result=aScanner.Peek(theNextChar); if(NS_OK==result) { - if(theNextChar==kMinus) + if((kMinus==theNextChar) || (kGreaterThan==theNextChar)) { result=ConsumeComment(aChar,aToken,aScanner); + } else result=ConsumeSpecialMarkup(aChar,aToken,aScanner); } diff --git a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp index 88dccf4c3a8..53f21540120 100644 --- a/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp +++ b/mozilla/parser/htmlparser/src/nsHTMLTokens.cpp @@ -770,8 +770,10 @@ nsresult ConsumeStrictComment(PRUnichar aChar, nsScanner& aScanner,nsString& aSt }//if }//while if(NS_OK==result) { - //if you're here, we're consuming a "short-form" comment - result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + //Read up to the closing '>', unless you already did! (such as ). + if(kGreaterThan!=aChar) { + result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + } } return result; } @@ -864,8 +866,10 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString) }//if }//if if(NS_OK==result) { - //Read up to the closing '>' - result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + //Read up to the closing '>', unless you already did! (such as ). + if(kGreaterThan!=aChar) { + result=aScanner.ReadUntil(aString,kGreaterThan,PR_TRUE); + } } return result; } diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp index e11e22bd4a3..b200d350b63 100644 --- a/mozilla/parser/htmlparser/src/nsParser.cpp +++ b/mozilla/parser/htmlparser/src/nsParser.cpp @@ -926,7 +926,12 @@ nsresult nsParser::ParseFragment(const nsString& aSourceBuffer,void* aKey,nsITag } theContext.Append(""); //XXXHack! I'll make this better later. nsAutoString theBuffer(theContext); + +#if 0 theBuffer.Append(aSourceBuffer); +#else + theBuffer.Append("text"); +#endif if(theBuffer.Length()){ //now it's time to try to build the model from this fragment diff --git a/mozilla/parser/htmlparser/src/nsParserNode.cpp b/mozilla/parser/htmlparser/src/nsParserNode.cpp index 3d8028284f0..c06b1e3d6e7 100644 --- a/mozilla/parser/htmlparser/src/nsParserNode.cpp +++ b/mozilla/parser/htmlparser/src/nsParserNode.cpp @@ -57,7 +57,6 @@ nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler mToken=aToken; mRecycler=aRecycler; mUseCount=0; - mIsResidual=PR_FALSE; } static void RecycleTokens(nsITokenRecycler* aRecycler,nsDeque& aDeque) { @@ -111,7 +110,6 @@ nsresult nsCParserNode::Init(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler RecycleTokens(mRecycler,*mAttributes); mToken=aToken; mUseCount=0; - mIsResidual=PR_FALSE; mSkippedContent.Truncate(); return NS_OK; } diff --git a/mozilla/parser/htmlparser/src/nsParserNode.h b/mozilla/parser/htmlparser/src/nsParserNode.h index 698a2c592ee..d552af1613d 100644 --- a/mozilla/parser/htmlparser/src/nsParserNode.h +++ b/mozilla/parser/htmlparser/src/nsParserNode.h @@ -179,7 +179,6 @@ class nsCParserNode : public nsIParserNode { nsDeque* mAttributes; nsAutoString mSkippedContent; PRInt32 mUseCount; - PRBool mIsResidual; nsITokenRecycler* mRecycler; }; diff --git a/mozilla/parser/htmlparser/src/nsScanner.cpp b/mozilla/parser/htmlparser/src/nsScanner.cpp index 26eebc81511..9f9b427d4a1 100644 --- a/mozilla/parser/htmlparser/src/nsScanner.cpp +++ b/mozilla/parser/htmlparser/src/nsScanner.cpp @@ -323,7 +323,7 @@ PRBool nsScanner::Append(const char* aBuffer, PRUint32 aLen){ */ PRBool nsScanner::Append(const PRUnichar* aBuffer, PRUint32 aLen){ - if(-1==aLen) + if(-1==(PRInt32)aLen) aLen=nsCRT::strlen(aBuffer); CBufDescriptor theDesc(aBuffer,PR_TRUE, aLen+1,aLen);