diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp index 60e023c157b..9a12ab32b7f 100644 --- a/mozilla/htmlparser/src/CNavDTD.cpp +++ b/mozilla/htmlparser/src/CNavDTD.cpp @@ -140,6 +140,14 @@ CTagStack::~CTagStack() { mSize=mCount=0; } +/** + * Resets state of stack to be empty. + * @update gess7/9/98 + */ +void CTagStack::Empty(void) { + mCount=0; +} + /** * * @update gess7/9/98 @@ -1013,8 +1021,11 @@ nsresult CNavDTD::HandleScriptToken(CToken* aToken, nsCParserNode& aNode) { if(NS_OK==result) { CollectSkippedContent(aNode,attrCount); if(NS_OK==result) { + //Boy is this an evil hack... + mContextStack.Pop(); result=AddLeaf(aNode); - if(NS_OK==result) + mContextStack.Push(eHTMLTag_head); + if(NS_OK==result) result=CloseHead(aNode); } } @@ -1997,7 +2008,7 @@ eHTMLTags CNavDTD::GetDefaultParentTagFor(eHTMLTags aTag) const{ * @param aChild -- tag type of child * @return TRUE if propagation closes; false otherwise */ -PRBool CNavDTD::ForwardPropagate(nsString& aVector,eHTMLTags aParentTag,eHTMLTags aChildTag) { +PRBool CNavDTD::ForwardPropagate(CTagStack& aStack,eHTMLTags aParentTag,eHTMLTags aChildTag) { PRBool result=PR_FALSE; switch(aParentTag) { @@ -2006,15 +2017,15 @@ PRBool CNavDTD::ForwardPropagate(nsString& aVector,eHTMLTags aParentTag,eHTMLTag static char tableTags[]={eHTMLTag_tr,eHTMLTag_td,0}; if(strchr(tableTags,aChildTag)) { //if you're here, we know we can correctly backward propagate. - return BackwardPropagate(aVector,aParentTag,aChildTag); + return BackwardPropagate(aStack,aParentTag,aChildTag); } } //otherwise, intentionally fall through... case eHTMLTag_tr: if(PR_TRUE==CanContain((PRInt32)eHTMLTag_td,(PRInt32)aChildTag)) { - aVector.Append((PRUnichar)eHTMLTag_td); - result=BackwardPropagate(aVector,aParentTag,eHTMLTag_td); + aStack.Push(eHTMLTag_td); + result=BackwardPropagate(aStack,aParentTag,eHTMLTag_td); // result=PR_TRUE; } @@ -2041,20 +2052,14 @@ PRBool CNavDTD::ForwardPropagate(nsString& aVector,eHTMLTags aParentTag,eHTMLTag * @param aChild -- tag type of child * @return TRUE if propagation closes; false otherwise */ -PRBool CNavDTD::BackwardPropagate(nsString& aVector,eHTMLTags aParentTag,eHTMLTags aChildTag) const { +PRBool CNavDTD::BackwardPropagate(CTagStack& aStack,eHTMLTags aParentTag,eHTMLTags aChildTag) const { - eHTMLTags theParentTag=(eHTMLTags)aChildTag; + eHTMLTags theParentTag=aChildTag; -// aVector.Truncate(); - - //create the necessary stack of parent tags... - //continue your search until you run out of known parents, - //or you find the specific parent you were given (aParentTag). -// aVector.Append((PRUnichar)aChildTag); do { theParentTag=(eHTMLTags)GetDefaultParentTagFor(theParentTag); if(theParentTag!=eHTMLTag_unknown) { - aVector.Append((PRUnichar)theParentTag); + aStack.Push(theParentTag); } } while((theParentTag!=eHTMLTag_unknown) && (theParentTag!=aParentTag)); @@ -2350,11 +2355,9 @@ nsresult CNavDTD::OpenBody(const nsIParserNode& aNode){ result=CloseContainersTo(0,eHTMLTag_html,PR_TRUE); //close current stack containers. - CHTMLToken token(gEmpty); + CHTMLToken token(gEmpty,eHTMLTag_html); nsCParserNode htmlNode(&token,mLineNumber); - - token.SetTypeID(eHTMLTag_html); //open the html container... - result=OpenHTML(htmlNode); + result=OpenHTML(htmlNode); //open the html container... } } @@ -2682,6 +2685,8 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){ return result; } +CTagStack kPropagationStack; + /** * This method gets called to create a valid context stack * for the given child. We compare the current stack to the @@ -2694,60 +2699,58 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){ * @return true if we succeeded, otherwise false */ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){ - nsAutoString theVector; - nsresult result=NS_OK; - PRInt32 pos=0; + kPropagationStack.Empty(); + + nsresult result=(nsresult)kContextMismatch; PRInt32 cnt=0; eHTMLTags theTop=GetTopNode(); + PRBool bResult=ForwardPropagate(kPropagationStack,theTop,aChildTag); - if(PR_TRUE==ForwardPropagate(theVector,theTop,aChildTag)){ - //add code here to build up context stack based on forward propagated context vector... - pos=0; - cnt=theVector.Length()-1; - if(mContextStack.Last()==(eHTMLTags)theVector[cnt]) - result=NS_OK; - else result=(nsresult)kContextMismatch; - } - else { - PRBool tempResult; + if(PR_FALSE==bResult){ + if(eHTMLTag_unknown!=theTop) { - tempResult=BackwardPropagate(theVector,theTop,aChildTag); - if(eHTMLTag_html!=theTop) - BackwardPropagate(theVector,eHTMLTag_html,theTop); - } - else tempResult=BackwardPropagate(theVector,eHTMLTag_html,aChildTag); + bResult=BackwardPropagate(kPropagationStack,theTop,aChildTag); - if(PR_TRUE==tempResult) { + /***************************************************************************** + OH NOOOO!... - //propagation worked, so pop unwanted containers, push new ones, then exit... - pos=0; - cnt=theVector.Length(); - result=NS_OK; - while(pos +
+ +