- *
- *
- *
- *
- * In this case, the bottom is "gated" from closing the bottommost
- * table.
- *
- * HOW THIS CODE WORKS:
- *
- * This block of code compares all the members of the default parent
- * hierarchy for the childtag against the open containers on our stack.
- * If they ever match, then the given child should be gated.
- ***************************************************************************/
-
- int theIndex;
- int theTopIndex=mBodyContext->mElements.mCount-1;
-
- eHTMLTags theParent=GetDefaultParentTagFor(aChildTag);
- while(eHTMLTag_unknown!=theParent) {
- for(theIndex=theTopIndex;theIndex>tagPos;theIndex--){
- if(mBodyContext->mElements.mTags[theIndex]==theParent){
- theGatePos=theIndex;
- break;
- }
- }
- theParent=GetDefaultParentTagFor(theParent);
- }
- }
- break;
-
- default:
- break;
- }
- }
- if(kNotFound!=theGatePos)
- if(kNotFound!=tagPos)
- result=PRBool(theGatePos>tagPos);
- return result;
-}
-
/**
* This method retrieves the HTMLTag type of the topmost
* container on the stack.
@@ -2397,7 +1689,7 @@ PRBool CNavDTD::IsGatedFromClosing(eHTMLTags aChildTag) const {
* @return tag id of topmost node in contextstack
*/
eHTMLTags CNavDTD::GetTopNode() const {
- return mBodyContext->mElements.Last();
+ return mBodyContext->Last();
}
/**
@@ -2409,10 +1701,10 @@ eHTMLTags CNavDTD::GetTopNode() const {
* @return topmost index of tag on stack
*/
PRInt32 CNavDTD::GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const {
- int i=0;
- for(i=mBodyContext->mElements.mCount-1;i>=0;i--){
- if(FindTagInSet(mBodyContext->mElements.mTags[i],aTagSet,aCount)) {
- return i;
+ int theIndex=0;
+ for(theIndex=mBodyContext->GetCount()-1;theIndex>=0;theIndex--){
+ if(FindTagInSet((*mBodyContext)[theIndex],aTagSet,aCount)) {
+ return theIndex;
}
}
return kNotFound;
@@ -2427,12 +1719,7 @@ PRInt32 CNavDTD::GetTopmostIndexOf(eHTMLTags aTagSet[],PRInt32 aCount) const {
* @return topmost index of tag on stack
*/
PRInt32 CNavDTD::GetTopmostIndexOf(eHTMLTags aTag) const {
- int i=0;
- for(i=mBodyContext->mElements.mCount-1;i>=0;i--){
- if(mBodyContext->mElements.mTags[i]==aTag)
- return i;
- }
- return kNotFound;
+ return ::GetTopmostIndexOf(aTag,mBodyContext->mTags);
}
/*********************************************
@@ -2455,34 +1742,34 @@ PRInt32 CNavDTD::GetTopmostIndexOf(eHTMLTags aTag) const {
nsresult CNavDTD::OpenTransientStyles(eHTMLTags aTag){
nsresult result=NS_OK;
- if(!FindTagInSet(aTag,gWhitespaceTags,sizeof(gWhitespaceTags)/sizeof(eHTMLTag_unknown))) {
- PRInt32 pos=0;
+ if(!FindTagInSet(aTag,gWhitespaceTags,sizeof(gWhitespaceTags)/sizeof(aTag))){
+ //the following code builds the set of style tags to be opened...
+ eHTMLTags theStyles[50];
+ int theCount=0;
- eHTMLTags parentTag=mBodyContext->mElements.Last();
- if(CanContainStyles(parentTag)) {
- for(pos=0;posmStyles->mCount;pos++) {
- eHTMLTags theTag=mBodyContext->mStyles->mTags[pos];
- if(PR_FALSE==HasOpenContainer(theTag)) {
-
- CStartToken token(theTag);
- nsCParserNode theNode(&token,mLineNumber);
-
- switch(theTag) {
- case eHTMLTag_secret_h1style: case eHTMLTag_secret_h2style:
- case eHTMLTag_secret_h3style: case eHTMLTag_secret_h4style:
- case eHTMLTag_secret_h5style: case eHTMLTag_secret_h6style:
- break;
- default:
- token.SetTypeID(theTag); //open the html container...
- result=OpenContainer(theNode,PR_FALSE);
- mBodyContext->mElements.mBits[mBodyContext->mElements.mCount-1]=PR_TRUE;
- } //switch
+ int theStackPos=0;
+ for(theStackPos=0;theStackPosGetCount();theStackPos++){
+ nsTagStack* theStyleStack=mBodyContext->mStyles[theStackPos];
+ if(theStyleStack) {
+ int theTagPos=0;
+ for(theTagPos=0;theTagPosmCount;theTagPos++){
+ if((0==theCount) || (!FindTagInSet(theStyleStack->mTags[theTagPos],theStyles,theCount))) {
+ theStyles[theCount++]=theStyleStack->mTags[theTagPos];
+ }
}
- if(NS_OK!=result)
- break;
- }//for
+ }
}
- }//if
+ theStyles[theCount]=eHTMLTag_unknown;
+
+ //now iterate style set, and open the containers...
+ for(theStackPos=0;theStackPosmOpenStyles=theCount;
+ }
return result;
}
@@ -2501,13 +1788,17 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aTag){
nsresult CNavDTD::CloseTransientStyles(eHTMLTags aTag){
nsresult result=NS_OK;
- if((mBodyContext->mStyles->mCount>0) && (mBodyContext->mElements.mBits[mBodyContext->mElements.mCount-1])) {
- if(!FindTagInSet(aTag,gWhitespaceTags,sizeof(gWhitespaceTags)/sizeof(eHTMLTag_unknown))) {
- result=CloseContainersTo(mBodyContext->mStyles->mTags[0],PR_FALSE);
- mBodyContext->mElements.mBits[mBodyContext->mElements.mCount-1]=PR_FALSE;
+ int theTagPos=0;
- }//if
- }//if
+ //now iterate style set, and close the containers...
+ 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);
+ }
+ mBodyContext->mOpenStyles=0;
return result;
}
@@ -2520,10 +1811,10 @@ nsresult CNavDTD::CloseTransientStyles(eHTMLTags aTag){
* @param aNode -- next node to be added to model
*/
nsresult CNavDTD::OpenHTML(const nsIParserNode& aNode){
- NS_PRECONDITION(mBodyContext->mElements.mCount >= 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos);
nsresult result=mSink->OpenHTML(aNode);
- mBodyContext->mElements.Push((eHTMLTags)aNode.GetNodeType());
+ mBodyContext->Push((eHTMLTags)aNode.GetNodeType());
return result;
}
@@ -2537,9 +1828,9 @@ nsresult CNavDTD::OpenHTML(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseHTML(const nsIParserNode& aNode){
- NS_PRECONDITION(mBodyContext->mElements.mCount > 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
nsresult result=mSink->CloseHTML(aNode);
- mBodyContext->mElements.Pop();
+ mBodyContext->Pop();
return result;
}
@@ -2553,8 +1844,9 @@ nsresult CNavDTD::CloseHTML(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
- mBodyContext->mElements.Push(eHTMLTag_head);
+ mBodyContext->Push(eHTMLTag_head);
nsresult result=mSink->OpenHead(aNode);
+ mHasOpenHead=PR_TRUE;
return result;
}
@@ -2568,7 +1860,8 @@ nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
*/
nsresult CNavDTD::CloseHead(const nsIParserNode& aNode){
nsresult result=mSink->CloseHead(aNode);
- mBodyContext->mElements.Pop();
+ mBodyContext->Pop();
+ mHasOpenHead=PR_FALSE;
return result;
}
@@ -2581,10 +1874,10 @@ nsresult CNavDTD::CloseHead(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::OpenBody(const nsIParserNode& aNode){
- NS_PRECONDITION(mBodyContext->mElements.mCount >= 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos);
nsresult result=NS_OK;
- eHTMLTags topTag=mBodyContext->mElements.Last();
+ eHTMLTags topTag=mBodyContext->Last();
if(eHTMLTag_html!=topTag) {
@@ -2611,7 +1904,7 @@ nsresult CNavDTD::OpenBody(const nsIParserNode& aNode){
if(NS_OK==result) {
result=mSink->OpenBody(aNode);
- mBodyContext->mElements.Push((eHTMLTags)aNode.GetNodeType());
+ mBodyContext->Push((eHTMLTags)aNode.GetNodeType());
}
return result;
}
@@ -2625,9 +1918,9 @@ nsresult CNavDTD::OpenBody(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseBody(const nsIParserNode& aNode){
- NS_PRECONDITION(mBodyContext->mElements.mCount >= 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos);
nsresult result=mSink->CloseBody(aNode);
- mBodyContext->mElements.Pop();
+ mBodyContext->Pop();
return result;
}
@@ -2708,9 +2001,9 @@ nsresult CNavDTD::CloseMap(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::OpenFrameset(const nsIParserNode& aNode){
- NS_PRECONDITION(mBodyContext->mElements.mCount >= 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos);
nsresult result=mSink->OpenFrameset(aNode);
- mBodyContext->mElements.Push((eHTMLTags)aNode.GetNodeType());
+ mBodyContext->Push((eHTMLTags)aNode.GetNodeType());
return result;
}
@@ -2723,9 +2016,9 @@ nsresult CNavDTD::OpenFrameset(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseFrameset(const nsIParserNode& aNode){
- NS_PRECONDITION(mBodyContext->mElements.mCount > 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
nsresult result=mSink->CloseFrameset(aNode);
- mBodyContext->mElements.Pop();
+ mBodyContext->Pop();
return result;
}
@@ -2740,7 +2033,7 @@ nsresult CNavDTD::CloseFrameset(const nsIParserNode& aNode){
*/
nsresult
CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
- NS_PRECONDITION(mBodyContext->mElements.mCount >= 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() >= 0, kInvalidTagStackPos);
nsresult result=NS_OK;
eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType();
@@ -2755,7 +2048,6 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
result=OpenBody(aNode); break;
case eHTMLTag_style:
- case eHTMLTag_head:
case eHTMLTag_title:
break;
@@ -2785,9 +2077,13 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
}
break;
+ case eHTMLTag_head:
+ result=OpenHead(aNode); //open the head...
+ break;
+
default:
result=mSink->OpenContainer(aNode);
- mBodyContext->mElements.Push((eHTMLTags)aNode.GetNodeType());
+ mBodyContext->Push((eHTMLTags)aNode.GetNodeType());
break;
}
@@ -2809,7 +2105,7 @@ CNavDTD::OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack){
nsresult
CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
PRBool aUpdateStyles){
- NS_PRECONDITION(mBodyContext->mElements.mCount > 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
nsresult result=NS_OK;
eHTMLTags nodeType=(eHTMLTags)aNode.GetNodeType();
@@ -2825,7 +2121,7 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
break;
case eHTMLTag_head:
- //result=CloseHead(aNode);
+ result=CloseHead(aNode);
break;
case eHTMLTag_body:
@@ -2844,11 +2140,10 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
case eHTMLTag_title:
default:
result=mSink->CloseContainer(aNode);
- mBodyContext->mElements.Pop();
+ mBodyContext->Pop();
break;
}
- mBodyContext->mElements.mBits[mBodyContext->mElements.mCount]=PR_FALSE;
if((NS_OK==result) && (PR_TRUE==aUpdateStyles)){
UpdateStyleStackForCloseTag(nodeType,aTag);
}
@@ -2867,15 +2162,15 @@ CNavDTD::CloseContainer(const nsIParserNode& aNode,eHTMLTags aTag,
nsresult
CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTag,
PRBool aUpdateStyles){
- NS_PRECONDITION(mBodyContext->mElements.mCount > 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
nsresult result=NS_OK;
static CEndToken aToken(gEmpty);
nsCParserNode theNode(&aToken,mLineNumber);
- if((anIndexmElements.mCount) && (anIndex>=0)) {
- while(mBodyContext->mElements.mCount>anIndex) {
- eHTMLTags theTag=mBodyContext->mElements.Last();
+ if((anIndexGetCount()) && (anIndex>=0)) {
+ while(mBodyContext->GetCount()>anIndex) {
+ eHTMLTags theTag=mBodyContext->Last();
aToken.SetTypeID(theTag);
result=CloseContainer(theNode,aTag,aUpdateStyles);
}
@@ -2892,7 +2187,7 @@ CNavDTD::CloseContainersTo(PRInt32 anIndex,eHTMLTags aTag,
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles){
- NS_PRECONDITION(mBodyContext->mElements.mCount > 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
PRInt32 pos=GetTopmostIndexOf(aTag);
@@ -2901,7 +2196,7 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles){
return CloseContainersTo(pos,aTag,aUpdateStyles);
}
- eHTMLTags theTopTag=mBodyContext->mElements.Last();
+ eHTMLTags theTopTag=mBodyContext->Last();
if(IsCompatibleTag(aTag,theTopTag)) {
//if you're here, it's because we're trying to close one style tag,
//but a different one is actually open. Because this is NAV4x
@@ -2915,7 +2210,8 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles){
}
nsresult result=NS_OK;
- eHTMLTags theParentTag=GetDefaultParentTagFor(aTag);
+ CTagList* theTagList=gHTMLElements[aTag].GetRootTags();
+ eHTMLTags theParentTag=theTagList->mTags[0];
pos=GetTopmostIndexOf(theParentTag);
if(kNotFound!=pos) {
//the parent container is open, so close it instead
@@ -2933,10 +2229,10 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseTopmostContainer(){
- NS_PRECONDITION(mBodyContext->mElements.mCount > 0, kInvalidTagStackPos);
+ NS_PRECONDITION(mBodyContext->GetCount() > 0, kInvalidTagStackPos);
CEndToken aToken(gEmpty);
- eHTMLTags theTag=mBodyContext->mElements.Last();
+ eHTMLTags theTag=mBodyContext->Last();
aToken.SetTypeID(theTag);
nsCParserNode theNode(&aToken,mLineNumber);
return CloseContainer(theNode,theTag,PR_TRUE);
@@ -2964,17 +2260,20 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){
* @return error code; 0 means OK
*/
nsresult CNavDTD::AddHeadLeaf(const nsIParserNode& aNode){
-
+ nsresult result=NS_OK;
+
static eHTMLTags gNoXTags[]={eHTMLTag_noframes,eHTMLTag_nolayer,eHTMLTag_noscript};
//this code has been added to prevent tags from being processed inside
//the document if the tag itself was found in a , , or |