From 685d8d596e2a07e685cb00d660a9101b167ca380 Mon Sep 17 00:00:00 2001
From: "rickg%netscape.com"
Date: Tue, 5 Oct 1999 04:54:53 +0000
Subject: [PATCH] fixed bug 15290; eliminated a leak; r=kmcclusk
git-svn-id: svn://10.0.0.236/trunk@49805 18797224-902f-48f8-a5cc-f745e15eee43
---
mozilla/htmlparser/src/CNavDTD.cpp | 86 ++++---
mozilla/htmlparser/src/CNavDTD.h | 7 +-
mozilla/htmlparser/src/CRtfDTD.cpp | 2 +-
mozilla/htmlparser/src/CRtfDTD.h | 6 +-
mozilla/htmlparser/src/nsElementTable.cpp | 236 ++++++++----------
mozilla/htmlparser/src/nsElementTable.h | 60 ++---
mozilla/htmlparser/src/nsExpatDTD.cpp | 2 +-
mozilla/htmlparser/src/nsExpatDTD.h | 6 +-
mozilla/htmlparser/src/nsIDTD.h | 14 +-
mozilla/htmlparser/src/nsIParser.h | 10 -
mozilla/htmlparser/src/nsParser.cpp | 7 +-
mozilla/htmlparser/src/nsScanner.cpp | 12 +-
mozilla/htmlparser/src/nsValidDTD.cpp | 2 +-
mozilla/htmlparser/src/nsValidDTD.h | 2 +-
mozilla/htmlparser/src/nsViewSourceHTML.cpp | 2 +-
mozilla/htmlparser/src/nsViewSourceHTML.h | 6 +-
mozilla/htmlparser/src/nsWellFormedDTD.cpp | 2 +-
mozilla/htmlparser/src/nsWellFormedDTD.h | 7 +-
mozilla/htmlparser/src/nsXIFDTD.cpp | 2 +-
mozilla/htmlparser/src/nsXIFDTD.h | 7 +-
mozilla/parser/htmlparser/src/CNavDTD.cpp | 86 ++++---
mozilla/parser/htmlparser/src/CNavDTD.h | 7 +-
mozilla/parser/htmlparser/src/CRtfDTD.cpp | 2 +-
mozilla/parser/htmlparser/src/CRtfDTD.h | 6 +-
.../parser/htmlparser/src/nsElementTable.cpp | 236 ++++++++----------
.../parser/htmlparser/src/nsElementTable.h | 60 ++---
mozilla/parser/htmlparser/src/nsExpatDTD.cpp | 2 +-
mozilla/parser/htmlparser/src/nsExpatDTD.h | 6 +-
mozilla/parser/htmlparser/src/nsIDTD.h | 14 +-
mozilla/parser/htmlparser/src/nsIParser.h | 10 -
mozilla/parser/htmlparser/src/nsParser.cpp | 7 +-
mozilla/parser/htmlparser/src/nsScanner.cpp | 12 +-
mozilla/parser/htmlparser/src/nsValidDTD.cpp | 2 +-
mozilla/parser/htmlparser/src/nsValidDTD.h | 2 +-
.../htmlparser/src/nsViewSourceHTML.cpp | 2 +-
.../parser/htmlparser/src/nsViewSourceHTML.h | 6 +-
.../parser/htmlparser/src/nsWellFormedDTD.cpp | 2 +-
.../parser/htmlparser/src/nsWellFormedDTD.h | 7 +-
mozilla/parser/htmlparser/src/nsXIFDTD.cpp | 2 +-
mozilla/parser/htmlparser/src/nsXIFDTD.h | 7 +-
40 files changed, 480 insertions(+), 476 deletions(-)
diff --git a/mozilla/htmlparser/src/CNavDTD.cpp b/mozilla/htmlparser/src/CNavDTD.cpp
index f952c8c2f15..8388d36d5d1 100644
--- a/mozilla/htmlparser/src/CNavDTD.cpp
+++ b/mozilla/htmlparser/src/CNavDTD.cpp
@@ -386,7 +386,7 @@ eAutoDetectResult CNavDTD::CanParse(nsString& aContentType, nsString& aCommand,
* @param
* @return
*/
-nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink){
+nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,eParseMode aParseMode,nsIContentSink* aSink){
nsresult result=NS_OK;
mFilename=aFilename;
@@ -395,6 +395,8 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString
mHadFrameset=PR_FALSE;
mLineNumber=1;
mHasOpenScript=PR_FALSE;
+ mParseMode=aParseMode;
+
if((aNotifySink) && (aSink)) {
STOP_TIMER();
@@ -790,9 +792,9 @@ static
PRInt32 GetIndexOfChildOrSynonym(nsEntryStack& aTagStack,eHTMLTags aChildTag) {
PRInt32 theChildIndex=aTagStack.GetTopmostIndexOf(aChildTag);
if(kNotFound==theChildIndex) {
- CTagList* theSynTags=gHTMLElements[aChildTag].GetSynonymousTags(); //get the list of tags that THIS tag can close
+ TagList* theSynTags=gHTMLElements[aChildTag].GetSynonymousTags(); //get the list of tags that THIS tag can close
if(theSynTags) {
- theChildIndex=theSynTags->GetTopmostIndexOf(aTagStack);
+ theChildIndex=GetTopmostIndexOf(aTagStack,*theSynTags);
}
else{
theChildIndex=aTagStack.GetCount();
@@ -834,11 +836,11 @@ PRBool CanBeContained(eHTMLTags aChildTag,nsEntryStack& aTagStack) {
PRBool result=PR_TRUE;
if(aTagStack.GetCount()){
- CTagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
- CTagList* theSpecialParents=gHTMLElements[aChildTag].GetSpecialParents();
+ TagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
+ TagList* theSpecialParents=gHTMLElements[aChildTag].GetSpecialParents();
if(theRootTags) {
- PRInt32 theRootIndex=theRootTags->GetTopmostIndexOf(aTagStack);
- PRInt32 theSPIndex=(theSpecialParents) ? theSpecialParents->GetTopmostIndexOf(aTagStack) : kNotFound;
+ PRInt32 theRootIndex=GetTopmostIndexOf(aTagStack,*theRootTags);
+ PRInt32 theSPIndex=(theSpecialParents) ? GetTopmostIndexOf(aTagStack,*theSpecialParents) : kNotFound;
PRInt32 theChildIndex=GetIndexOfChildOrSynonym(aTagStack,aChildTag);
PRInt32 theBaseIndex=(theRootIndex>theSPIndex) ? theRootIndex : theSPIndex;
@@ -1275,13 +1277,13 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
* @return PR_TRUE if given tag can contain other tags
*/
static
-PRBool HasCloseablePeerAboveRoot(CTagList& aRootTagList,nsEntryStack& aTagStack,eHTMLTags aTag,PRBool anEndTag) {
- PRInt32 theRootIndex=aRootTagList.GetTopmostIndexOf(aTagStack);
- CTagList* theCloseTags=(anEndTag) ? gHTMLElements[aTag].GetAutoCloseEndTags() : gHTMLElements[aTag].GetAutoCloseStartTags();
+PRBool HasCloseablePeerAboveRoot(TagList& aRootTagList,nsEntryStack& aTagStack,eHTMLTags aTag,PRBool anEndTag) {
+ PRInt32 theRootIndex=GetTopmostIndexOf(aTagStack,aRootTagList);
+ TagList* theCloseTags=(anEndTag) ? gHTMLElements[aTag].GetAutoCloseEndTags() : gHTMLElements[aTag].GetAutoCloseStartTags();
PRInt32 theChildIndex=-1;
if(theCloseTags) {
- theChildIndex=theCloseTags->GetTopmostIndexOf(aTagStack);
+ theChildIndex=GetTopmostIndexOf(aTagStack,*theCloseTags);
}
else {
if((anEndTag) || (!gHTMLElements[aTag].CanContainSelf()))
@@ -1330,16 +1332,16 @@ eHTMLTags FindAutoCloseTargetForEndTag(eHTMLTags aCurrentTag,nsEntryStack& aTagS
3. Otherwise its non-specified and we simply presume we can close it.
*/
- CTagList* theCloseTags=gHTMLElements[aCurrentTag].GetAutoCloseEndTags();
- CTagList* theRootTags=gHTMLElements[aCurrentTag].GetEndRootTags();
+ TagList* theCloseTags=gHTMLElements[aCurrentTag].GetAutoCloseEndTags();
+ TagList* theRootTags=gHTMLElements[aCurrentTag].GetEndRootTags();
if(theCloseTags){
//at a min., this code is needed for H1..H6
while(theChildIndex<--theTopIndex) {
eHTMLTags theNextTag=aTagStack[theTopIndex];
- if(PR_FALSE==theCloseTags->Contains(theNextTag)) {
- if(PR_TRUE==theRootTags->Contains(theNextTag)) {
+ if(PR_FALSE==Contains(theNextTag,*theCloseTags)) {
+ if(PR_TRUE==Contains(theNextTag,*theRootTags)) {
return eHTMLTag_unknown; //we encountered a tag in root list so fail (because we're gated).
}
//otherwise presume it's something we can simply ignore and continue search...
@@ -1408,8 +1410,12 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
case eHTMLTag_br:
{
- CToken* theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,eHTMLTag_br);
- result=HandleStartToken(theToken);
+ //This is special NAV-QUIRKS code that allows users
+ //to use , even though that isn't a legitimate tag.
+ if(eParseMode_quirks==mParseMode) {
+ CStartToken theToken(eHTMLTag_br);
+ result=HandleStartToken(&theToken);
+ }
}
break;
@@ -1428,8 +1434,14 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
// Oh boy!! we found a "stray" block entity. Nav4.x and IE introduce line break in
// such cases. So, let's simulate that effect for compatibility.
// Ex. Hello
There
+#if 0
+ mTokenizer->PushTokenFront(aToken); //put this end token back...
+ CHTMLToken* theToken = (CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theChildTag);
+ mTokenizer->PushTokenFront(theToken); //put this new token onto stack...
+#endif
CHTMLToken* theToken = (CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theChildTag);
result=HandleToken(theToken,mParser);
+
}
else return result;
}
@@ -1849,8 +1861,8 @@ PRBool CNavDTD::CanPropagate(eHTMLTags aParentTag,eHTMLTags aChildTag) const {
result=PR_TRUE;
break;
}//if
- CTagList* theTagList=gHTMLElements[aChildTag].GetRootTags();
- aChildTag=theTagList->GetTagAt(0);
+ TagList* theTagList=gHTMLElements[aChildTag].GetRootTags();
+ aChildTag=GetTagAt(0,*theTagList);
if(aChildTag==theTempTag) break;
parentCanContain=CanContain(aParentTag,aChildTag);
++thePropLevel;
@@ -1999,9 +2011,9 @@ PRBool CNavDTD::BackwardPropagate(nsString& aSequence,eHTMLTags aParentTag,eHTML
eHTMLTags theParentTag=aParentTag; //just init to get past first condition...
do {
- CTagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
+ TagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
if(theRootTags) {
- theParentTag=theRootTags->GetTagAt(0);
+ theParentTag=GetTagAt(0,*theRootTags);
if(CanContain(theParentTag,aChildTag)) {
//we've found a complete sequence, so push the parent...
aChildTag=theParentTag;
@@ -2716,8 +2728,8 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aClosedByStartTag){
}
nsresult result=NS_OK;
- CTagList* theRootTags=gHTMLElements[aTag].GetRootTags();
- eHTMLTags theParentTag=theRootTags->GetTagAt(0);
+ TagList* theRootTags=gHTMLElements[aTag].GetRootTags();
+ eHTMLTags theParentTag=GetTagAt(0,*theRootTags);
pos=GetTopmostIndexOf(theParentTag);
if(kNotFound!=pos) {
//the parent container is open, so close it instead
@@ -2765,24 +2777,42 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){
result=mSink->AddLeaf(aNode);
-#if 1
PRBool done=PR_FALSE;
nsCParserNode* theNode=CreateNode();
+
+ CTokenRecycler* theRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler();
+
while(!done) {
CToken* theToken=mTokenizer->PeekToken();
if(theToken) {
- eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID();
+ theTag=(eHTMLTags)theToken->GetTypeID();
switch(theTag) {
case eHTMLTag_newline:
mLineNumber++;
- case eHTMLTag_text:
case eHTMLTag_whitespace:
{
theToken=mTokenizer->PopToken();
- theNode->Init(theToken,mLineNumber,GetTokenRecycler());
+ theNode->Init(theToken,mLineNumber,0);
result=mSink->AddLeaf(*theNode);
+ if(theRecycler) {
+ theRecycler->RecycleToken(theToken);
+ }
+ else delete theToken;
}
break;
+ case eHTMLTag_text:
+ if(mHasOpenBody && (!mHasOpenHead)) {
+ theToken=mTokenizer->PopToken();
+ theNode->Init(theToken,mLineNumber);
+ result=mSink->AddLeaf(*theNode);
+ if(theRecycler) {
+ theRecycler->RecycleToken(theToken);
+ }
+ else delete theToken;
+ }
+ else done=PR_TRUE;
+ break;
+
default:
done=PR_TRUE;
} //switch
@@ -2790,8 +2820,6 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){
else done=PR_TRUE;
} //while
RecycleNode(theNode);
-
-#endif
START_TIMER();
diff --git a/mozilla/htmlparser/src/CNavDTD.h b/mozilla/htmlparser/src/CNavDTD.h
index 7fe19edd954..c8fb8e65703 100644
--- a/mozilla/htmlparser/src/CNavDTD.h
+++ b/mozilla/htmlparser/src/CNavDTD.h
@@ -179,7 +179,11 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink=0);
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
@@ -524,6 +528,7 @@ protected:
eHTMLTags mSkipTarget;
nsDeque mSharedNodes;
nsresult mDTDState;
+ eParseMode mParseMode;
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;
diff --git a/mozilla/htmlparser/src/CRtfDTD.cpp b/mozilla/htmlparser/src/CRtfDTD.cpp
index 2d8bce61522..76e19c2759c 100644
--- a/mozilla/htmlparser/src/CRtfDTD.cpp
+++ b/mozilla/htmlparser/src/CRtfDTD.cpp
@@ -257,7 +257,7 @@ eAutoDetectResult CRtfDTD::CanParse(nsString& aContentType, nsString& aCommand,
* @param
* @return
*/
-NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink){
+NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,eParseMode aParseMode,nsIContentSink* aSink){
nsresult result=NS_OK;
return result;
}
diff --git a/mozilla/htmlparser/src/CRtfDTD.h b/mozilla/htmlparser/src/CRtfDTD.h
index 04715e95e3e..0c0a4e32817 100644
--- a/mozilla/htmlparser/src/CRtfDTD.h
+++ b/mozilla/htmlparser/src/CRtfDTD.h
@@ -194,7 +194,11 @@ class CRtfDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink=0);
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
diff --git a/mozilla/htmlparser/src/nsElementTable.cpp b/mozilla/htmlparser/src/nsElementTable.cpp
index 471b854e96f..46faa3a6a55 100644
--- a/mozilla/htmlparser/src/nsElementTable.cpp
+++ b/mozilla/htmlparser/src/nsElementTable.cpp
@@ -32,12 +32,8 @@
* @param
* @return
*/
-PRBool CTagList::Contains(eHTMLTags aTag){
- PRBool result=PR_FALSE;
- if(mTagList) {
- result=FindTagInSet(aTag,mTagList,mCount);
- }
- else result=FindTagInSet(aTag,mTags,mCount);
+PRBool Contains(eHTMLTags aTag,TagList& aTagList){
+ PRBool result=FindTagInSet(aTag,aTagList.mTags,aTagList.mCount);
return result;
}
@@ -47,11 +43,11 @@ PRBool CTagList::Contains(eHTMLTags aTag){
* @param
* @return
*/
-PRInt32 CTagList::GetTopmostIndexOf(nsEntryStack& aTagStack){
+PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack,TagList& aTagList){
int max = aTagStack.GetCount();
- int index;
+ int index=0;
for(index=max-1;index>=0;index--){
- if(Contains(aTagStack[index])) {
+ if(FindTagInSet(aTagStack[index],aTagList.mTags,aTagList.mCount)) {
return index;
}
}
@@ -64,154 +60,120 @@ PRInt32 CTagList::GetTopmostIndexOf(nsEntryStack& aTagStack){
* @param
* @return
*/
-PRInt32 CTagList::GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset){
- int max = aTagStack.GetCount();
- int index;
- for(index=aStartOffset;indexContains(aChild)) {
+ if(Contains(aChild,*mSpecialKids)) {
return PR_FALSE;
}
}
@@ -1654,7 +1616,7 @@ PRBool nsHTMLElement::CanOmitStartTag(eHTMLTags aChild) const{
* @return
*/
PRBool nsHTMLElement::IsChildOfHead(eHTMLTags aChild) {
- PRBool result=FindTagInSet(aChild,gHeadKidList,sizeof(gHeadKidList)/sizeof(eHTMLTag_body));
+ PRBool result=Contains(aChild,gHeadKids);
return result;
}
@@ -1667,10 +1629,10 @@ PRBool nsHTMLElement::IsChildOfHead(eHTMLTags aChild) {
*/
PRBool nsHTMLElement::SectionContains(eHTMLTags aChild,PRBool allowDepthSearch) {
PRBool result=PR_FALSE;
- CTagList* theRootTags=gHTMLElements[aChild].GetRootTags();
+ TagList* theRootTags=gHTMLElements[aChild].GetRootTags();
if(theRootTags){
- if(!theRootTags->Contains(mTagID)){
- eHTMLTags theRootBase=(theRootTags->mTagList) ? theRootTags->mTagList[0] : theRootTags->mTags[0];
+ if(!Contains(mTagID,*theRootTags)){
+ eHTMLTags theRootBase=GetTagAt(0,*theRootTags);
if((eHTMLTag_unknown!=theRootBase) && (allowDepthSearch))
result=SectionContains(theRootBase,allowDepthSearch);
}
@@ -1711,7 +1673,7 @@ PRBool nsHTMLElement::IsStyleTag(eHTMLTags aChild) {
* @return
*/
PRBool nsHTMLElement::IsHeadingTag(eHTMLTags aChild) {
- return gHeadingTags.Contains(aChild);
+ return Contains(aChild,gHeadingTags);
}
@@ -1782,8 +1744,10 @@ PRBool nsHTMLElement::CanContainSelf(void) const {
PRBool nsHTMLElement::CanAutoCloseTag(eHTMLTags aTag) const{
PRBool result=PR_TRUE;
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_userdefined)) {
- CTagList* theTagList=gHTMLElements[mTagID].GetNonAutoCloseEndTags();
- if(theTagList) return !theTagList->Contains(aTag);
+ TagList* theTagList=gHTMLElements[mTagID].GetNonAutoCloseEndTags();
+ if(theTagList) {
+ result=!Contains(aTag,*theTagList);
+ }
}
return result;
}
@@ -1875,9 +1839,9 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{
return CanContainSelf(); //not many tags can contain themselves...
}
- CTagList* theCloseTags=gHTMLElements[aChild].GetAutoCloseStartTags();
+ TagList* theCloseTags=gHTMLElements[aChild].GetAutoCloseStartTags();
if(theCloseTags){
- if(theCloseTags->Contains(mTagID))
+ if(Contains(mTagID,*theCloseTags))
return PR_FALSE;
}
@@ -1911,7 +1875,7 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{
}
if(mSpecialKids) {
- if(mSpecialKids->Contains(aChild)) {
+ if(Contains(aChild,*mSpecialKids)) {
return PR_TRUE;
}
}
diff --git a/mozilla/htmlparser/src/nsElementTable.h b/mozilla/htmlparser/src/nsElementTable.h
index a73677bf80f..17cc356ee22 100644
--- a/mozilla/htmlparser/src/nsElementTable.h
+++ b/mozilla/htmlparser/src/nsElementTable.h
@@ -31,31 +31,15 @@
#include "nsHTMLTokens.h"
#include "nsDTDUtils.h"
-class CTagList {
-public:
- CTagList( int aCount,
- eHTMLTags* aTagList=0,
- eHTMLTags aTag1=eHTMLTag_unknown,
- eHTMLTags aTag2=eHTMLTag_unknown,
- eHTMLTags aTag3=eHTMLTag_unknown,
- eHTMLTags aTag4=eHTMLTag_unknown,
- eHTMLTags aTag5=eHTMLTag_unknown)
- {
- mCount=aCount;
- mTags[0]=aTag1; mTags[1]=aTag2; mTags[2]=aTag3; mTags[3]=aTag4; mTags[4]=aTag5;
- mTagList=aTagList;
- }
-
- PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack);
- PRInt32 GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset);
- PRBool Contains(eHTMLTags aTag);
- eHTMLTags GetTagAt(PRUint32 anIndex) const;
-
- eHTMLTags mTags[5];
- eHTMLTags* mTagList;
+struct TagList {
PRUint32 mCount;
+ eHTMLTags mTags[10];
};
+extern PRBool Contains(eHTMLTags aTag,TagList& aTagList);
+extern PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack,TagList& aTagList);
+extern eHTMLTags GetTagAt(PRUint32 anIndex,TagList& aTagList);
+
//*********************************************************************************************
// The following ints define the standard groups of HTML elements...
//*********************************************************************************************
@@ -81,16 +65,16 @@ struct nsHTMLElement {
static PRBool IsBlockCloser(eHTMLTags aTag);
static int GetSynonymousGroups(int aGroup);
- CTagList* GetSynonymousTags(void) const {return mSynonymousTags;}
- CTagList* GetRootTags(void) const {return mRootNodes;}
- CTagList* GetEndRootTags(void) const {return mEndRootNodes;}
- CTagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;}
- CTagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
- CTagList* GetNonAutoCloseEndTags(void) const {return mDontAutocloseEnd;}
+ TagList* GetSynonymousTags(void) const {return mSynonymousTags;}
+ TagList* GetRootTags(void) const {return mRootNodes;}
+ 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(nsEntryStack& aTagStack,PRInt32 anIndex) const;
- CTagList* GetSpecialChildren(void) const {return mSpecialKids;}
- CTagList* GetSpecialParents(void) const {return mSpecialParents;}
+ TagList* GetSpecialChildren(void) const {return mSpecialKids;}
+ TagList* GetSpecialParents(void) const {return mSpecialParents;}
PRBool IsMemberOf(PRInt32 aType) const;
PRBool CanContainType(PRInt32 aType) const;
@@ -121,19 +105,19 @@ struct nsHTMLElement {
eHTMLTags mTagID;
eHTMLTags mRequiredAncestor;
eHTMLTags mExcludingAncestor; //If set, the presence of the excl-ancestor prevents this from opening.
- CTagList* mRootNodes; //These are the tags above which you many not autoclose a START tag
- CTagList* mEndRootNodes; //These are the tags above which you many not autoclose an END tag
- CTagList* mAutocloseStart; //these are the start tags that you can automatically close with this START tag
- CTagList* mAutocloseEnd; //these are the start tags that you can automatically close with this END tag
- CTagList* mSynonymousTags; //These are morally equivalent; an end tag for one can close a start tag for another (like )
- CTagList* mDontAutocloseEnd; //these are the end tags that you cannot automatically close with this END tag
+ TagList* mRootNodes; //These are the tags above which you many not autoclose a START tag
+ TagList* mEndRootNodes; //These are the tags above which you many not autoclose an END tag
+ 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
int mParentBits; //defines groups that can contain this element
int mInclusionBits; //defines parental and containment rules
int mExclusionBits; //defines things you CANNOT contain
int mSpecialProperties; //used for various special purposes...
int mPropagateRange; //tells us how far a parent is willing to prop. badly formed children
- CTagList* mSpecialParents; //These are the special tags that contain this tag (directly)
- CTagList* mSpecialKids; //These are the extra things you can contain
+ TagList* mSpecialParents; //These are the special tags that contain this tag (directly)
+ TagList* mSpecialKids; //These are the extra things you can contain
eHTMLTags mSkipTarget; //If set, then we skip all content until this tag is seen
};
diff --git a/mozilla/htmlparser/src/nsExpatDTD.cpp b/mozilla/htmlparser/src/nsExpatDTD.cpp
index ddfd4f8ae88..827f7b3d43d 100644
--- a/mozilla/htmlparser/src/nsExpatDTD.cpp
+++ b/mozilla/htmlparser/src/nsExpatDTD.cpp
@@ -196,7 +196,7 @@ eAutoDetectResult nsExpatDTD::CanParse(nsString& aContentType, nsString& aComman
* @param
* @return
*/
-NS_IMETHODIMP nsExpatDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aString,nsIContentSink* aSink){
+NS_IMETHODIMP nsExpatDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,eParseMode aParseMode,nsIContentSink* aSink){
nsresult result=NS_OK;
mFilename=aFilename;
diff --git a/mozilla/htmlparser/src/nsExpatDTD.h b/mozilla/htmlparser/src/nsExpatDTD.h
index 70885e74167..8a407682c5f 100644
--- a/mozilla/htmlparser/src/nsExpatDTD.h
+++ b/mozilla/htmlparser/src/nsExpatDTD.h
@@ -102,7 +102,11 @@ class nsExpatDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aString,nsIContentSink* aSink=0);
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
diff --git a/mozilla/htmlparser/src/nsIDTD.h b/mozilla/htmlparser/src/nsIDTD.h
index 4225fa84a53..eddef4aa93e 100644
--- a/mozilla/htmlparser/src/nsIDTD.h
+++ b/mozilla/htmlparser/src/nsIDTD.h
@@ -46,6 +46,14 @@ enum eAutoDetectResult {
eInvalidDetect
};
+enum eParseMode {
+
+ eParseMode_unknown=0,
+ eParseMode_quirks, //pre 5.0 versions
+ eParseMode_noquirks, //raptor versions...)
+ eParseMode_other,
+ eParseMode_autodetect
+};
class nsIParser;
class CToken;
@@ -94,7 +102,11 @@ class nsIDTD : public nsISupports {
* @param aFilename--string that contains name of file being parsed (if applicable)
* @return
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink=0)=0;
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0)=0;
/**
* Called by the parser after the parsing process has concluded
diff --git a/mozilla/htmlparser/src/nsIParser.h b/mozilla/htmlparser/src/nsIParser.h
index bd080f83626..0e5d49a70e0 100644
--- a/mozilla/htmlparser/src/nsIParser.h
+++ b/mozilla/htmlparser/src/nsIParser.h
@@ -49,16 +49,6 @@ class nsString;
class nsIURI;
-enum eParseMode {
-
- eParseMode_unknown=0,
- eParseMode_raptor, //5.0 version of nav. and greater
- eParseMode_navigator, //pre 5.0 versions
- eParseMode_noquirks, //pre 5.0 without quirks (as best as we can...)
- eParseMode_other,
- eParseMode_autodetect
-};
-
enum eCRCQuality {
eCRCGood = 0,
eCRCFair,
diff --git a/mozilla/htmlparser/src/nsParser.cpp b/mozilla/htmlparser/src/nsParser.cpp
index d9162c2f9cb..0e1db724dae 100644
--- a/mozilla/htmlparser/src/nsParser.cpp
+++ b/mozilla/htmlparser/src/nsParser.cpp
@@ -463,12 +463,12 @@ eParseMode DetermineParseMode(nsParser& aParser) {
theSubIndex=theBufCopy.Find("HTML4.0",PR_TRUE,theIndex+8);
if(kNotFoundkNotFound)
- return eParseMode_navigator;
+ return eParseMode_quirks;
else if((theBufCopy.Find("FRAMESET",PR_TRUE,theSubIndex)>kNotFound) ||
(theBufCopy.Find("LATIN1", PR_TRUE,theSubIndex) >kNotFound) ||
(theBufCopy.Find("SYMBOLS",PR_TRUE,theSubIndex) >kNotFound) ||
(theBufCopy.Find("SPECIAL",PR_TRUE,theSubIndex) >kNotFound))
- return eParseMode_navigator; // XXX -HACK- Set the appropriate mode.
+ return eParseMode_quirks; // XXX -HACK- Set the appropriate mode.
else
return eParseMode_noquirks;
}
@@ -490,7 +490,7 @@ eParseMode DetermineParseMode(nsParser& aParser) {
if(theModeStr)
if(0==nsCRT::strcasecmp(other,theModeStr))
return eParseMode_other;
- return eParseMode_navigator;
+ return eParseMode_quirks;
}
@@ -521,6 +521,7 @@ nsresult nsParser::WillBuildModel(nsString& aFilename,nsIDTD* aDefaultDTD){
mParserContext->mDTD->WillBuildModel( aFilename,
PRBool(0==mParserContext->mPrevContext),
mParserContext->mSourceType,
+ mParserContext->mParseMode,
mSink);
}//if
}//if
diff --git a/mozilla/htmlparser/src/nsScanner.cpp b/mozilla/htmlparser/src/nsScanner.cpp
index 4bbc088d731..aaefe4db7d6 100644
--- a/mozilla/htmlparser/src/nsScanner.cpp
+++ b/mozilla/htmlparser/src/nsScanner.cpp
@@ -566,22 +566,23 @@ nsresult nsScanner::SkipTo(nsString& aValidSet){
return result;
}
-
+#if 0
void DoErrTest(nsString& aString) {
PRInt32 pos=aString.FindChar(0);
if(kNotFoundGetTopmostIndexOf(aTagStack);
+ theChildIndex=GetTopmostIndexOf(aTagStack,*theSynTags);
}
else{
theChildIndex=aTagStack.GetCount();
@@ -834,11 +836,11 @@ PRBool CanBeContained(eHTMLTags aChildTag,nsEntryStack& aTagStack) {
PRBool result=PR_TRUE;
if(aTagStack.GetCount()){
- CTagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
- CTagList* theSpecialParents=gHTMLElements[aChildTag].GetSpecialParents();
+ TagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
+ TagList* theSpecialParents=gHTMLElements[aChildTag].GetSpecialParents();
if(theRootTags) {
- PRInt32 theRootIndex=theRootTags->GetTopmostIndexOf(aTagStack);
- PRInt32 theSPIndex=(theSpecialParents) ? theSpecialParents->GetTopmostIndexOf(aTagStack) : kNotFound;
+ PRInt32 theRootIndex=GetTopmostIndexOf(aTagStack,*theRootTags);
+ PRInt32 theSPIndex=(theSpecialParents) ? GetTopmostIndexOf(aTagStack,*theSpecialParents) : kNotFound;
PRInt32 theChildIndex=GetIndexOfChildOrSynonym(aTagStack,aChildTag);
PRInt32 theBaseIndex=(theRootIndex>theSPIndex) ? theRootIndex : theSPIndex;
@@ -1275,13 +1277,13 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
* @return PR_TRUE if given tag can contain other tags
*/
static
-PRBool HasCloseablePeerAboveRoot(CTagList& aRootTagList,nsEntryStack& aTagStack,eHTMLTags aTag,PRBool anEndTag) {
- PRInt32 theRootIndex=aRootTagList.GetTopmostIndexOf(aTagStack);
- CTagList* theCloseTags=(anEndTag) ? gHTMLElements[aTag].GetAutoCloseEndTags() : gHTMLElements[aTag].GetAutoCloseStartTags();
+PRBool HasCloseablePeerAboveRoot(TagList& aRootTagList,nsEntryStack& aTagStack,eHTMLTags aTag,PRBool anEndTag) {
+ PRInt32 theRootIndex=GetTopmostIndexOf(aTagStack,aRootTagList);
+ TagList* theCloseTags=(anEndTag) ? gHTMLElements[aTag].GetAutoCloseEndTags() : gHTMLElements[aTag].GetAutoCloseStartTags();
PRInt32 theChildIndex=-1;
if(theCloseTags) {
- theChildIndex=theCloseTags->GetTopmostIndexOf(aTagStack);
+ theChildIndex=GetTopmostIndexOf(aTagStack,*theCloseTags);
}
else {
if((anEndTag) || (!gHTMLElements[aTag].CanContainSelf()))
@@ -1330,16 +1332,16 @@ eHTMLTags FindAutoCloseTargetForEndTag(eHTMLTags aCurrentTag,nsEntryStack& aTagS
3. Otherwise its non-specified and we simply presume we can close it.
*/
- CTagList* theCloseTags=gHTMLElements[aCurrentTag].GetAutoCloseEndTags();
- CTagList* theRootTags=gHTMLElements[aCurrentTag].GetEndRootTags();
+ TagList* theCloseTags=gHTMLElements[aCurrentTag].GetAutoCloseEndTags();
+ TagList* theRootTags=gHTMLElements[aCurrentTag].GetEndRootTags();
if(theCloseTags){
//at a min., this code is needed for H1..H6
while(theChildIndex<--theTopIndex) {
eHTMLTags theNextTag=aTagStack[theTopIndex];
- if(PR_FALSE==theCloseTags->Contains(theNextTag)) {
- if(PR_TRUE==theRootTags->Contains(theNextTag)) {
+ if(PR_FALSE==Contains(theNextTag,*theCloseTags)) {
+ if(PR_TRUE==Contains(theNextTag,*theRootTags)) {
return eHTMLTag_unknown; //we encountered a tag in root list so fail (because we're gated).
}
//otherwise presume it's something we can simply ignore and continue search...
@@ -1408,8 +1410,12 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
case eHTMLTag_br:
{
- CToken* theToken=(CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,eHTMLTag_br);
- result=HandleStartToken(theToken);
+ //This is special NAV-QUIRKS code that allows users
+ //to use , even though that isn't a legitimate tag.
+ if(eParseMode_quirks==mParseMode) {
+ CStartToken theToken(eHTMLTag_br);
+ result=HandleStartToken(&theToken);
+ }
}
break;
@@ -1428,8 +1434,14 @@ nsresult CNavDTD::HandleEndToken(CToken* aToken) {
// Oh boy!! we found a "stray" block entity. Nav4.x and IE introduce line break in
// such cases. So, let's simulate that effect for compatibility.
// Ex. HelloThere
+#if 0
+ mTokenizer->PushTokenFront(aToken); //put this end token back...
+ CHTMLToken* theToken = (CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theChildTag);
+ mTokenizer->PushTokenFront(theToken); //put this new token onto stack...
+#endif
CHTMLToken* theToken = (CHTMLToken*)gRecycler->CreateTokenOfType(eToken_start,theChildTag);
result=HandleToken(theToken,mParser);
+
}
else return result;
}
@@ -1849,8 +1861,8 @@ PRBool CNavDTD::CanPropagate(eHTMLTags aParentTag,eHTMLTags aChildTag) const {
result=PR_TRUE;
break;
}//if
- CTagList* theTagList=gHTMLElements[aChildTag].GetRootTags();
- aChildTag=theTagList->GetTagAt(0);
+ TagList* theTagList=gHTMLElements[aChildTag].GetRootTags();
+ aChildTag=GetTagAt(0,*theTagList);
if(aChildTag==theTempTag) break;
parentCanContain=CanContain(aParentTag,aChildTag);
++thePropLevel;
@@ -1999,9 +2011,9 @@ PRBool CNavDTD::BackwardPropagate(nsString& aSequence,eHTMLTags aParentTag,eHTML
eHTMLTags theParentTag=aParentTag; //just init to get past first condition...
do {
- CTagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
+ TagList* theRootTags=gHTMLElements[aChildTag].GetRootTags();
if(theRootTags) {
- theParentTag=theRootTags->GetTagAt(0);
+ theParentTag=GetTagAt(0,*theRootTags);
if(CanContain(theParentTag,aChildTag)) {
//we've found a complete sequence, so push the parent...
aChildTag=theParentTag;
@@ -2716,8 +2728,8 @@ nsresult CNavDTD::CloseContainersTo(eHTMLTags aTag,PRBool aClosedByStartTag){
}
nsresult result=NS_OK;
- CTagList* theRootTags=gHTMLElements[aTag].GetRootTags();
- eHTMLTags theParentTag=theRootTags->GetTagAt(0);
+ TagList* theRootTags=gHTMLElements[aTag].GetRootTags();
+ eHTMLTags theParentTag=GetTagAt(0,*theRootTags);
pos=GetTopmostIndexOf(theParentTag);
if(kNotFound!=pos) {
//the parent container is open, so close it instead
@@ -2765,24 +2777,42 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){
result=mSink->AddLeaf(aNode);
-#if 1
PRBool done=PR_FALSE;
nsCParserNode* theNode=CreateNode();
+
+ CTokenRecycler* theRecycler=(CTokenRecycler*)mTokenizer->GetTokenRecycler();
+
while(!done) {
CToken* theToken=mTokenizer->PeekToken();
if(theToken) {
- eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID();
+ theTag=(eHTMLTags)theToken->GetTypeID();
switch(theTag) {
case eHTMLTag_newline:
mLineNumber++;
- case eHTMLTag_text:
case eHTMLTag_whitespace:
{
theToken=mTokenizer->PopToken();
- theNode->Init(theToken,mLineNumber,GetTokenRecycler());
+ theNode->Init(theToken,mLineNumber,0);
result=mSink->AddLeaf(*theNode);
+ if(theRecycler) {
+ theRecycler->RecycleToken(theToken);
+ }
+ else delete theToken;
}
break;
+ case eHTMLTag_text:
+ if(mHasOpenBody && (!mHasOpenHead)) {
+ theToken=mTokenizer->PopToken();
+ theNode->Init(theToken,mLineNumber);
+ result=mSink->AddLeaf(*theNode);
+ if(theRecycler) {
+ theRecycler->RecycleToken(theToken);
+ }
+ else delete theToken;
+ }
+ else done=PR_TRUE;
+ break;
+
default:
done=PR_TRUE;
} //switch
@@ -2790,8 +2820,6 @@ nsresult CNavDTD::AddLeaf(const nsIParserNode& aNode){
else done=PR_TRUE;
} //while
RecycleNode(theNode);
-
-#endif
START_TIMER();
diff --git a/mozilla/parser/htmlparser/src/CNavDTD.h b/mozilla/parser/htmlparser/src/CNavDTD.h
index 7fe19edd954..c8fb8e65703 100644
--- a/mozilla/parser/htmlparser/src/CNavDTD.h
+++ b/mozilla/parser/htmlparser/src/CNavDTD.h
@@ -179,7 +179,11 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink=0);
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
@@ -524,6 +528,7 @@ protected:
eHTMLTags mSkipTarget;
nsDeque mSharedNodes;
nsresult mDTDState;
+ eParseMode mParseMode;
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;
diff --git a/mozilla/parser/htmlparser/src/CRtfDTD.cpp b/mozilla/parser/htmlparser/src/CRtfDTD.cpp
index 2d8bce61522..76e19c2759c 100644
--- a/mozilla/parser/htmlparser/src/CRtfDTD.cpp
+++ b/mozilla/parser/htmlparser/src/CRtfDTD.cpp
@@ -257,7 +257,7 @@ eAutoDetectResult CRtfDTD::CanParse(nsString& aContentType, nsString& aCommand,
* @param
* @return
*/
-NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFileName,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink){
+NS_IMETHODIMP CRtfDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,eParseMode aParseMode,nsIContentSink* aSink){
nsresult result=NS_OK;
return result;
}
diff --git a/mozilla/parser/htmlparser/src/CRtfDTD.h b/mozilla/parser/htmlparser/src/CRtfDTD.h
index 04715e95e3e..0c0a4e32817 100644
--- a/mozilla/parser/htmlparser/src/CRtfDTD.h
+++ b/mozilla/parser/htmlparser/src/CRtfDTD.h
@@ -194,7 +194,11 @@ class CRtfDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink=0);
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
diff --git a/mozilla/parser/htmlparser/src/nsElementTable.cpp b/mozilla/parser/htmlparser/src/nsElementTable.cpp
index 471b854e96f..46faa3a6a55 100644
--- a/mozilla/parser/htmlparser/src/nsElementTable.cpp
+++ b/mozilla/parser/htmlparser/src/nsElementTable.cpp
@@ -32,12 +32,8 @@
* @param
* @return
*/
-PRBool CTagList::Contains(eHTMLTags aTag){
- PRBool result=PR_FALSE;
- if(mTagList) {
- result=FindTagInSet(aTag,mTagList,mCount);
- }
- else result=FindTagInSet(aTag,mTags,mCount);
+PRBool Contains(eHTMLTags aTag,TagList& aTagList){
+ PRBool result=FindTagInSet(aTag,aTagList.mTags,aTagList.mCount);
return result;
}
@@ -47,11 +43,11 @@ PRBool CTagList::Contains(eHTMLTags aTag){
* @param
* @return
*/
-PRInt32 CTagList::GetTopmostIndexOf(nsEntryStack& aTagStack){
+PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack,TagList& aTagList){
int max = aTagStack.GetCount();
- int index;
+ int index=0;
for(index=max-1;index>=0;index--){
- if(Contains(aTagStack[index])) {
+ if(FindTagInSet(aTagStack[index],aTagList.mTags,aTagList.mCount)) {
return index;
}
}
@@ -64,154 +60,120 @@ PRInt32 CTagList::GetTopmostIndexOf(nsEntryStack& aTagStack){
* @param
* @return
*/
-PRInt32 CTagList::GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset){
- int max = aTagStack.GetCount();
- int index;
- for(index=aStartOffset;indexContains(aChild)) {
+ if(Contains(aChild,*mSpecialKids)) {
return PR_FALSE;
}
}
@@ -1654,7 +1616,7 @@ PRBool nsHTMLElement::CanOmitStartTag(eHTMLTags aChild) const{
* @return
*/
PRBool nsHTMLElement::IsChildOfHead(eHTMLTags aChild) {
- PRBool result=FindTagInSet(aChild,gHeadKidList,sizeof(gHeadKidList)/sizeof(eHTMLTag_body));
+ PRBool result=Contains(aChild,gHeadKids);
return result;
}
@@ -1667,10 +1629,10 @@ PRBool nsHTMLElement::IsChildOfHead(eHTMLTags aChild) {
*/
PRBool nsHTMLElement::SectionContains(eHTMLTags aChild,PRBool allowDepthSearch) {
PRBool result=PR_FALSE;
- CTagList* theRootTags=gHTMLElements[aChild].GetRootTags();
+ TagList* theRootTags=gHTMLElements[aChild].GetRootTags();
if(theRootTags){
- if(!theRootTags->Contains(mTagID)){
- eHTMLTags theRootBase=(theRootTags->mTagList) ? theRootTags->mTagList[0] : theRootTags->mTags[0];
+ if(!Contains(mTagID,*theRootTags)){
+ eHTMLTags theRootBase=GetTagAt(0,*theRootTags);
if((eHTMLTag_unknown!=theRootBase) && (allowDepthSearch))
result=SectionContains(theRootBase,allowDepthSearch);
}
@@ -1711,7 +1673,7 @@ PRBool nsHTMLElement::IsStyleTag(eHTMLTags aChild) {
* @return
*/
PRBool nsHTMLElement::IsHeadingTag(eHTMLTags aChild) {
- return gHeadingTags.Contains(aChild);
+ return Contains(aChild,gHeadingTags);
}
@@ -1782,8 +1744,10 @@ PRBool nsHTMLElement::CanContainSelf(void) const {
PRBool nsHTMLElement::CanAutoCloseTag(eHTMLTags aTag) const{
PRBool result=PR_TRUE;
if((mTagID>=eHTMLTag_unknown) & (mTagID<=eHTMLTag_userdefined)) {
- CTagList* theTagList=gHTMLElements[mTagID].GetNonAutoCloseEndTags();
- if(theTagList) return !theTagList->Contains(aTag);
+ TagList* theTagList=gHTMLElements[mTagID].GetNonAutoCloseEndTags();
+ if(theTagList) {
+ result=!Contains(aTag,*theTagList);
+ }
}
return result;
}
@@ -1875,9 +1839,9 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{
return CanContainSelf(); //not many tags can contain themselves...
}
- CTagList* theCloseTags=gHTMLElements[aChild].GetAutoCloseStartTags();
+ TagList* theCloseTags=gHTMLElements[aChild].GetAutoCloseStartTags();
if(theCloseTags){
- if(theCloseTags->Contains(mTagID))
+ if(Contains(mTagID,*theCloseTags))
return PR_FALSE;
}
@@ -1911,7 +1875,7 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{
}
if(mSpecialKids) {
- if(mSpecialKids->Contains(aChild)) {
+ if(Contains(aChild,*mSpecialKids)) {
return PR_TRUE;
}
}
diff --git a/mozilla/parser/htmlparser/src/nsElementTable.h b/mozilla/parser/htmlparser/src/nsElementTable.h
index a73677bf80f..17cc356ee22 100644
--- a/mozilla/parser/htmlparser/src/nsElementTable.h
+++ b/mozilla/parser/htmlparser/src/nsElementTable.h
@@ -31,31 +31,15 @@
#include "nsHTMLTokens.h"
#include "nsDTDUtils.h"
-class CTagList {
-public:
- CTagList( int aCount,
- eHTMLTags* aTagList=0,
- eHTMLTags aTag1=eHTMLTag_unknown,
- eHTMLTags aTag2=eHTMLTag_unknown,
- eHTMLTags aTag3=eHTMLTag_unknown,
- eHTMLTags aTag4=eHTMLTag_unknown,
- eHTMLTags aTag5=eHTMLTag_unknown)
- {
- mCount=aCount;
- mTags[0]=aTag1; mTags[1]=aTag2; mTags[2]=aTag3; mTags[3]=aTag4; mTags[4]=aTag5;
- mTagList=aTagList;
- }
-
- PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack);
- PRInt32 GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset);
- PRBool Contains(eHTMLTags aTag);
- eHTMLTags GetTagAt(PRUint32 anIndex) const;
-
- eHTMLTags mTags[5];
- eHTMLTags* mTagList;
+struct TagList {
PRUint32 mCount;
+ eHTMLTags mTags[10];
};
+extern PRBool Contains(eHTMLTags aTag,TagList& aTagList);
+extern PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack,TagList& aTagList);
+extern eHTMLTags GetTagAt(PRUint32 anIndex,TagList& aTagList);
+
//*********************************************************************************************
// The following ints define the standard groups of HTML elements...
//*********************************************************************************************
@@ -81,16 +65,16 @@ struct nsHTMLElement {
static PRBool IsBlockCloser(eHTMLTags aTag);
static int GetSynonymousGroups(int aGroup);
- CTagList* GetSynonymousTags(void) const {return mSynonymousTags;}
- CTagList* GetRootTags(void) const {return mRootNodes;}
- CTagList* GetEndRootTags(void) const {return mEndRootNodes;}
- CTagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;}
- CTagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
- CTagList* GetNonAutoCloseEndTags(void) const {return mDontAutocloseEnd;}
+ TagList* GetSynonymousTags(void) const {return mSynonymousTags;}
+ TagList* GetRootTags(void) const {return mRootNodes;}
+ 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(nsEntryStack& aTagStack,PRInt32 anIndex) const;
- CTagList* GetSpecialChildren(void) const {return mSpecialKids;}
- CTagList* GetSpecialParents(void) const {return mSpecialParents;}
+ TagList* GetSpecialChildren(void) const {return mSpecialKids;}
+ TagList* GetSpecialParents(void) const {return mSpecialParents;}
PRBool IsMemberOf(PRInt32 aType) const;
PRBool CanContainType(PRInt32 aType) const;
@@ -121,19 +105,19 @@ struct nsHTMLElement {
eHTMLTags mTagID;
eHTMLTags mRequiredAncestor;
eHTMLTags mExcludingAncestor; //If set, the presence of the excl-ancestor prevents this from opening.
- CTagList* mRootNodes; //These are the tags above which you many not autoclose a START tag
- CTagList* mEndRootNodes; //These are the tags above which you many not autoclose an END tag
- CTagList* mAutocloseStart; //these are the start tags that you can automatically close with this START tag
- CTagList* mAutocloseEnd; //these are the start tags that you can automatically close with this END tag
- CTagList* mSynonymousTags; //These are morally equivalent; an end tag for one can close a start tag for another (like )
- CTagList* mDontAutocloseEnd; //these are the end tags that you cannot automatically close with this END tag
+ TagList* mRootNodes; //These are the tags above which you many not autoclose a START tag
+ TagList* mEndRootNodes; //These are the tags above which you many not autoclose an END tag
+ 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
int mParentBits; //defines groups that can contain this element
int mInclusionBits; //defines parental and containment rules
int mExclusionBits; //defines things you CANNOT contain
int mSpecialProperties; //used for various special purposes...
int mPropagateRange; //tells us how far a parent is willing to prop. badly formed children
- CTagList* mSpecialParents; //These are the special tags that contain this tag (directly)
- CTagList* mSpecialKids; //These are the extra things you can contain
+ TagList* mSpecialParents; //These are the special tags that contain this tag (directly)
+ TagList* mSpecialKids; //These are the extra things you can contain
eHTMLTags mSkipTarget; //If set, then we skip all content until this tag is seen
};
diff --git a/mozilla/parser/htmlparser/src/nsExpatDTD.cpp b/mozilla/parser/htmlparser/src/nsExpatDTD.cpp
index ddfd4f8ae88..827f7b3d43d 100644
--- a/mozilla/parser/htmlparser/src/nsExpatDTD.cpp
+++ b/mozilla/parser/htmlparser/src/nsExpatDTD.cpp
@@ -196,7 +196,7 @@ eAutoDetectResult nsExpatDTD::CanParse(nsString& aContentType, nsString& aComman
* @param
* @return
*/
-NS_IMETHODIMP nsExpatDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aString,nsIContentSink* aSink){
+NS_IMETHODIMP nsExpatDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,eParseMode aParseMode,nsIContentSink* aSink){
nsresult result=NS_OK;
mFilename=aFilename;
diff --git a/mozilla/parser/htmlparser/src/nsExpatDTD.h b/mozilla/parser/htmlparser/src/nsExpatDTD.h
index 70885e74167..8a407682c5f 100644
--- a/mozilla/parser/htmlparser/src/nsExpatDTD.h
+++ b/mozilla/parser/htmlparser/src/nsExpatDTD.h
@@ -102,7 +102,11 @@ class nsExpatDTD : public nsIDTD {
* @param aFilename is the name of the file being parsed.
* @return error code (almost always 0)
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aString,nsIContentSink* aSink=0);
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0);
/**
* The parser uses a code sandwich to wrap the parsing process. Before
diff --git a/mozilla/parser/htmlparser/src/nsIDTD.h b/mozilla/parser/htmlparser/src/nsIDTD.h
index 4225fa84a53..eddef4aa93e 100644
--- a/mozilla/parser/htmlparser/src/nsIDTD.h
+++ b/mozilla/parser/htmlparser/src/nsIDTD.h
@@ -46,6 +46,14 @@ enum eAutoDetectResult {
eInvalidDetect
};
+enum eParseMode {
+
+ eParseMode_unknown=0,
+ eParseMode_quirks, //pre 5.0 versions
+ eParseMode_noquirks, //raptor versions...)
+ eParseMode_other,
+ eParseMode_autodetect
+};
class nsIParser;
class CToken;
@@ -94,7 +102,11 @@ class nsIDTD : public nsISupports {
* @param aFilename--string that contains name of file being parsed (if applicable)
* @return
*/
- NS_IMETHOD WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString& aSourceType,nsIContentSink* aSink=0)=0;
+ NS_IMETHOD WillBuildModel( nsString& aFilename,
+ PRBool aNotifySink,
+ nsString& aSourceType,
+ eParseMode aParseMode,
+ nsIContentSink* aSink=0)=0;
/**
* Called by the parser after the parsing process has concluded
diff --git a/mozilla/parser/htmlparser/src/nsIParser.h b/mozilla/parser/htmlparser/src/nsIParser.h
index bd080f83626..0e5d49a70e0 100644
--- a/mozilla/parser/htmlparser/src/nsIParser.h
+++ b/mozilla/parser/htmlparser/src/nsIParser.h
@@ -49,16 +49,6 @@ class nsString;
class nsIURI;
-enum eParseMode {
-
- eParseMode_unknown=0,
- eParseMode_raptor, //5.0 version of nav. and greater
- eParseMode_navigator, //pre 5.0 versions
- eParseMode_noquirks, //pre 5.0 without quirks (as best as we can...)
- eParseMode_other,
- eParseMode_autodetect
-};
-
enum eCRCQuality {
eCRCGood = 0,
eCRCFair,
diff --git a/mozilla/parser/htmlparser/src/nsParser.cpp b/mozilla/parser/htmlparser/src/nsParser.cpp
index d9162c2f9cb..0e1db724dae 100644
--- a/mozilla/parser/htmlparser/src/nsParser.cpp
+++ b/mozilla/parser/htmlparser/src/nsParser.cpp
@@ -463,12 +463,12 @@ eParseMode DetermineParseMode(nsParser& aParser) {
theSubIndex=theBufCopy.Find("HTML4.0",PR_TRUE,theIndex+8);
if(kNotFoundkNotFound)
- return eParseMode_navigator;
+ return eParseMode_quirks;
else if((theBufCopy.Find("FRAMESET",PR_TRUE,theSubIndex)>kNotFound) ||
(theBufCopy.Find("LATIN1", PR_TRUE,theSubIndex) >kNotFound) ||
(theBufCopy.Find("SYMBOLS",PR_TRUE,theSubIndex) >kNotFound) ||
(theBufCopy.Find("SPECIAL",PR_TRUE,theSubIndex) >kNotFound))
- return eParseMode_navigator; // XXX -HACK- Set the appropriate mode.
+ return eParseMode_quirks; // XXX -HACK- Set the appropriate mode.
else
return eParseMode_noquirks;
}
@@ -490,7 +490,7 @@ eParseMode DetermineParseMode(nsParser& aParser) {
if(theModeStr)
if(0==nsCRT::strcasecmp(other,theModeStr))
return eParseMode_other;
- return eParseMode_navigator;
+ return eParseMode_quirks;
}
@@ -521,6 +521,7 @@ nsresult nsParser::WillBuildModel(nsString& aFilename,nsIDTD* aDefaultDTD){
mParserContext->mDTD->WillBuildModel( aFilename,
PRBool(0==mParserContext->mPrevContext),
mParserContext->mSourceType,
+ mParserContext->mParseMode,
mSink);
}//if
}//if
diff --git a/mozilla/parser/htmlparser/src/nsScanner.cpp b/mozilla/parser/htmlparser/src/nsScanner.cpp
index 4bbc088d731..aaefe4db7d6 100644
--- a/mozilla/parser/htmlparser/src/nsScanner.cpp
+++ b/mozilla/parser/htmlparser/src/nsScanner.cpp
@@ -566,22 +566,23 @@ nsresult nsScanner::SkipTo(nsString& aValidSet){
return result;
}
-
+#if 0
void DoErrTest(nsString& aString) {
PRInt32 pos=aString.FindChar(0);
if(kNotFound