зеркало из https://github.com/mozilla/pjs.git
huge improvements to parser
This commit is contained in:
Родитель
fee218f0dc
Коммит
211dce8234
|
@ -27,6 +27,7 @@
|
|||
#include "nsHTMLTokens.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsParserTypes.h"
|
||||
#include "nsIParser.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
|
@ -98,6 +99,7 @@ NS_IMPL_RELEASE(CNavDTD)
|
|||
* @return
|
||||
*/
|
||||
CNavDTD::CNavDTD() : nsIDTD() {
|
||||
mParser=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +112,36 @@ CNavDTD::CNavDTD() : nsIDTD() {
|
|||
CNavDTD::~CNavDTD(){
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void CNavDTD::SetParser(nsIParser* aParser) {
|
||||
mParser=aParser;
|
||||
}
|
||||
|
||||
|
||||
static char formElementTags[]= {
|
||||
eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input,
|
||||
eHTMLTag_isindex, eHTMLTag_label, eHTMLTag_legend,
|
||||
eHTMLTag_select, eHTMLTag_textarea,0};
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 4/8/98
|
||||
* @param aParent -- tag enum of parent container
|
||||
* @param aChild -- tag enum of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
PRBool CNavDTD::CanContainFormElement(PRInt32 aParent,PRInt32 aChild) const {
|
||||
PRBool result=(mParser) ? mParser->HasOpenForm() : PR_FALSE;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
|
@ -121,6 +153,7 @@ CNavDTD::~CNavDTD(){
|
|||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
||||
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
//tagset1 has 64 members...
|
||||
|
@ -194,6 +227,11 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
if(eHTMLTag_userdefined==aChild) // XXX Hack: For now...
|
||||
result=PR_TRUE;
|
||||
|
||||
//handle form elements (this is very much a WIP!!!)
|
||||
if(0!=strchr(formElementTags,aChild)){
|
||||
return CanContainFormElement(aParent,aChild);
|
||||
}
|
||||
|
||||
switch(aParent) {
|
||||
case eHTMLTag_a:
|
||||
result=PRBool(0!=strchr(gTagSet2,aChild)); break;
|
||||
|
@ -302,7 +340,15 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
case eHTMLTag_h1: case eHTMLTag_h2:
|
||||
case eHTMLTag_h3: case eHTMLTag_h4:
|
||||
case eHTMLTag_h5: case eHTMLTag_h6:
|
||||
result=PRBool(0!=strchr(gTagSet1,aChild)); break;
|
||||
{
|
||||
static char badTags[]={
|
||||
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3,
|
||||
eHTMLTag_h4, eHTMLTag_h5, eHTMLTag_h6, 0};
|
||||
if(0!=strchr(badTags,aChild))
|
||||
result=PR_FALSE;
|
||||
else result=PRBool(0!=strchr(gTagSet1,aChild));
|
||||
}
|
||||
break;
|
||||
|
||||
case eHTMLTag_head:
|
||||
{
|
||||
|
@ -418,7 +464,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
break; //unadorned script text...
|
||||
|
||||
case eHTMLTag_select:
|
||||
result=PRBool(eHTMLTag_option==aChild); break;
|
||||
result=PR_TRUE; break; //for now, allow select to contain anything...
|
||||
|
||||
case eHTMLTag_small:
|
||||
result=PRBool(0!=strchr(gTagSet2,aChild)); break;
|
||||
|
@ -483,7 +529,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
case eHTMLTag_userdefined:
|
||||
result=PR_TRUE; break; //XXX for now...
|
||||
|
||||
case eHTMLTag_xmp:
|
||||
case eHTMLTag_xmp:
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
|
@ -529,6 +575,8 @@ PRBool CNavDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const {
|
|||
}
|
||||
break;
|
||||
|
||||
result=PR_TRUE; break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -546,29 +594,43 @@ PRBool CNavDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const {
|
|||
PRBool CNavDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
switch((eHTMLTags)aParent) {
|
||||
case eHTMLTag_html:
|
||||
case eHTMLTag_body:
|
||||
case eHTMLTag_head:
|
||||
case eHTMLTag_title:
|
||||
|
||||
case eHTMLTag_tr:
|
||||
// case eHTMLTag_td:
|
||||
case eHTMLTag_table:
|
||||
case eHTMLTag_thead:
|
||||
case eHTMLTag_tfoot:
|
||||
case eHTMLTag_tbody:
|
||||
case eHTMLTag_col:
|
||||
case eHTMLTag_colgroup:
|
||||
if((aChild==eHTMLTag_newline) ||
|
||||
(aChild==eHTMLTag_whitespace))
|
||||
result=PR_TRUE;
|
||||
//begin with some simple (and obvious) cases...
|
||||
switch((eHTMLTags)aChild) {
|
||||
|
||||
case eHTMLTag_userdefined:
|
||||
case eHTMLTag_comment:
|
||||
result=PR_TRUE;
|
||||
break;
|
||||
|
||||
case eHTMLTag_button: case eHTMLTag_fieldset:
|
||||
case eHTMLTag_input: case eHTMLTag_isindex:
|
||||
case eHTMLTag_label: case eHTMLTag_legend:
|
||||
case eHTMLTag_select: case eHTMLTag_textarea:
|
||||
if(PR_FALSE==mParser->HasOpenForm())
|
||||
result=PR_TRUE;
|
||||
break;
|
||||
|
||||
case eHTMLTag_newline:
|
||||
case eHTMLTag_whitespace:
|
||||
|
||||
switch((eHTMLTags)aParent) {
|
||||
case eHTMLTag_html: case eHTMLTag_head:
|
||||
case eHTMLTag_title: case eHTMLTag_map:
|
||||
case eHTMLTag_tr: case eHTMLTag_table:
|
||||
case eHTMLTag_thead: case eHTMLTag_tfoot:
|
||||
case eHTMLTag_tbody: case eHTMLTag_col:
|
||||
case eHTMLTag_colgroup: case eHTMLTag_unknown:
|
||||
result=PR_TRUE;
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
break;
|
||||
|
||||
default:
|
||||
result=PR_FALSE;
|
||||
if(eHTMLTag_unknown==aParent)
|
||||
result=PRBool(eHTMLTag_html!=aChild);
|
||||
break;
|
||||
}
|
||||
} //switch
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
{0xaa, 0xda, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}}
|
||||
|
||||
|
||||
class nsIParser;
|
||||
|
||||
class CNavDTD : public nsIDTD {
|
||||
|
||||
|
@ -73,6 +74,15 @@ class CNavDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetParser(nsIParser* aParser);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
|
@ -150,6 +160,11 @@ class CNavDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool BackwardPropagate(nsString& aVector,PRInt32 aParentTag,PRInt32 aChildTag) const;
|
||||
|
||||
protected:
|
||||
|
||||
PRBool CanContainFormElement(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
nsIParser* mParser;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ CNavDelegate::CNavDelegate(CNavDelegate& aDelegate) :
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
eParseMode CNavDelegate::GetParseMode() const {
|
||||
eParseMode CNavDelegate::GetParseMode(void) const {
|
||||
return eParseMode_unknown;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ CToken* CNavDelegate::ConsumeTag(PRUnichar aChar,CScanner& aScanner,PRInt32& anE
|
|||
default:
|
||||
if(nsString::IsAlpha(aChar))
|
||||
return ConsumeStartTag(aChar,aScanner,anErrorCode);
|
||||
else if(kNotFound!=aChar) {
|
||||
else if(kEOF!=aChar) {
|
||||
nsAutoString temp("<");
|
||||
return ConsumeText(temp,aScanner,anErrorCode);
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ class CNavDelegate : public ITokenizerDelegate {
|
|||
CNavDelegate();
|
||||
CNavDelegate(CNavDelegate& aDelegate);
|
||||
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual PRBool WillAddToken(CToken& aToken);
|
||||
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
|
||||
virtual eParseMode GetParseMode() const;
|
||||
virtual eParseMode GetParseMode(void) const;
|
||||
virtual nsIDTD* GetDTD(void) const;
|
||||
static void SelfTest();
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -82,4 +82,3 @@ class CNavDelegate : public ITokenizerDelegate {
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsHTMLTokens.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsParserTypes.h"
|
||||
#include "nsIParser.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
|
@ -98,6 +99,7 @@ NS_IMPL_RELEASE(COtherDTD)
|
|||
* @return
|
||||
*/
|
||||
COtherDTD::COtherDTD() : nsIDTD() {
|
||||
mParser=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +112,18 @@ COtherDTD::COtherDTD() : nsIDTD() {
|
|||
COtherDTD::~COtherDTD(){
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void COtherDTD::SetParser(nsIParser* aParser) {
|
||||
mParser=aParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
|
@ -503,6 +517,8 @@ PRBool COtherDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const {
|
|||
}
|
||||
break;
|
||||
|
||||
result=PR_TRUE; break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
|
||||
|
||||
class nsIParser;
|
||||
|
||||
class COtherDTD : public nsIDTD {
|
||||
|
||||
|
@ -52,7 +53,7 @@ class COtherDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
COtherDTD();
|
||||
COtherDTD();
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -63,6 +64,16 @@ class COtherDTD : public nsIDTD {
|
|||
*/
|
||||
virtual ~COtherDTD();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetParser(nsIParser* aParser);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
|
@ -153,6 +164,8 @@ class COtherDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool BackwardPropagate(nsString& aVector,PRInt32 aParentTag,PRInt32 aChildTag) const;
|
||||
|
||||
protected:
|
||||
nsIParser* mParser;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ COtherDelegate::COtherDelegate(COtherDelegate& aDelegate) :
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
eParseMode COtherDelegate::GetParseMode() const {
|
||||
eParseMode COtherDelegate::GetParseMode(void) const {
|
||||
return eParseMode_unknown;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ CToken* COtherDelegate::ConsumeTag(PRUnichar aChar,CScanner& aScanner,PRInt32& a
|
|||
default:
|
||||
if(nsString::IsAlpha(aChar))
|
||||
return ConsumeStartTag(aChar,aScanner,anErrorCode);
|
||||
else if(kNotFound!=aChar) {
|
||||
else if(kEOF!=aChar) {
|
||||
nsAutoString temp("<");
|
||||
return ConsumeText(temp,aScanner,anErrorCode);
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ class COtherDelegate : public ITokenizerDelegate {
|
|||
COtherDelegate();
|
||||
COtherDelegate(COtherDelegate& aDelegate);
|
||||
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual PRBool WillAddToken(CToken& aToken);
|
||||
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
|
||||
virtual eParseMode GetParseMode() const;
|
||||
virtual eParseMode GetParseMode(void) const;
|
||||
virtual nsIDTD* GetDTD(void) const;
|
||||
static void SelfTest();
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ nsHTMLParser::nsHTMLParser() {
|
|||
nsCRT::zero(mContextStack,sizeof(mContextStack));
|
||||
nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers));
|
||||
mDTD=0;
|
||||
mHasOpenForm=PR_FALSE;
|
||||
mTokenHandlerCount=0;
|
||||
InitializeDefaultTokenHandlers();
|
||||
gVerificationOutputDir = PR_GetEnv("VERIFY_PARSER");
|
||||
|
@ -176,8 +177,20 @@ nsresult nsHTMLParser::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|||
eHTMLTags nsHTMLParser::NodeAt(PRInt32 aPos) const {
|
||||
NS_PRECONDITION(0 <= aPos, "bad nodeAt");
|
||||
if((aPos>-1) && (aPos<mContextStackPos))
|
||||
return mContextStack[aPos];
|
||||
return (eHTMLTags)kNotFound;
|
||||
return (eHTMLTags)mContextStack[aPos];
|
||||
return eHTMLTag_unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows the caller to determine if a form
|
||||
* element is currently open.
|
||||
*
|
||||
* @update gess 4/2/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRBool nsHTMLParser::HasOpenForm() const {
|
||||
return mHasOpenForm;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,10 +203,11 @@ eHTMLTags nsHTMLParser::NodeAt(PRInt32 aPos) const {
|
|||
*/
|
||||
eHTMLTags nsHTMLParser::GetTopNode() const {
|
||||
if(mContextStackPos)
|
||||
return mContextStack[mContextStackPos-1];
|
||||
return (eHTMLTags)kNotFound;
|
||||
return (eHTMLTags)mContextStack[mContextStackPos-1];
|
||||
return eHTMLTag_unknown;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the given tag is open anywhere
|
||||
* in our context stack.
|
||||
|
@ -326,14 +340,13 @@ nsIContentSink* nsHTMLParser::SetContentSink(nsIContentSink* aSink) {
|
|||
* @param aDTD is the DTD we plan to ask for verification
|
||||
* @return TRUE if we know how to handle it, else false
|
||||
*/
|
||||
PRBool VerifyContextVector(eHTMLTags tags[],PRInt32 count,nsIDTD* aDTD) {
|
||||
PRBool VerifyContextVector(PRInt32 aTags[],PRInt32 count,nsIDTD* aDTD) {
|
||||
|
||||
PRBool result=PR_TRUE;
|
||||
|
||||
if(0!=gVerificationOutputDir) {
|
||||
|
||||
if(aDTD){
|
||||
PRInt32 theArray[50];
|
||||
|
||||
#ifdef XP_PC
|
||||
char path[_MAX_PATH+1];
|
||||
|
@ -341,17 +354,16 @@ PRBool VerifyContextVector(eHTMLTags tags[],PRInt32 count,nsIDTD* aDTD) {
|
|||
#endif
|
||||
|
||||
for(int i=0;i<count;i++){
|
||||
theArray[i]=tags[i];
|
||||
|
||||
#ifdef NS_WIN32
|
||||
strcat(path,"/");
|
||||
const char* name=GetTagName(tags[i]);
|
||||
const char* name=GetTagName(aTags[i]);
|
||||
strcat(path,name);
|
||||
mkdir(path);
|
||||
#endif
|
||||
}
|
||||
//ok, now see if we understand this vector
|
||||
result=aDTD->VerifyContextVector(theArray,count);
|
||||
result=aDTD->VerifyContextVector(aTags,count);
|
||||
}
|
||||
if(PR_FALSE==result){
|
||||
//add debugging code here to record the fact that we just encountered
|
||||
|
@ -389,9 +401,12 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
eHTMLTokenTypes type=eHTMLTokenTypes(theToken->GetTokenType());
|
||||
iteration++; //debug purposes...
|
||||
|
||||
switch(eHTMLTokenTypes(type)){
|
||||
switch(type){
|
||||
|
||||
case eToken_start:
|
||||
case eToken_text:
|
||||
case eToken_newline:
|
||||
case eToken_whitespace:
|
||||
result=HandleStartToken(theToken); break;
|
||||
|
||||
case eToken_end:
|
||||
|
@ -399,11 +414,6 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
|
||||
case eToken_entity:
|
||||
result=HandleEntityToken(theToken); break;
|
||||
|
||||
case eToken_text:
|
||||
case eToken_newline:
|
||||
case eToken_whitespace:
|
||||
result=HandleSimpleContentToken(theToken); break;
|
||||
|
||||
case eToken_skippedcontent:
|
||||
//used in cases like <SCRIPT> where we skip over script content.
|
||||
|
@ -412,9 +422,6 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
case eToken_attribute:
|
||||
result=HandleAttributeToken(theToken); break;
|
||||
|
||||
case eToken_script:
|
||||
result=HandleScriptToken(theToken); break;
|
||||
|
||||
case eToken_style:
|
||||
result=HandleStyleToken(theToken); break;
|
||||
|
||||
|
@ -428,7 +435,7 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
}
|
||||
VerifyContextVector(mContextStack,mContextStackPos,mDTD);
|
||||
++(*mCurrentPos);
|
||||
done=PRBool(e==*mCurrentPos);
|
||||
done=PRBool(!(*mCurrentPos<e));
|
||||
}
|
||||
|
||||
//One last thing...close any open containers.
|
||||
|
@ -438,6 +445,7 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is the main controlling routine in the parsing process.
|
||||
* Note that it may get called multiple times for the same scanner,
|
||||
|
@ -454,7 +462,7 @@ PRBool nsHTMLParser::Parse(nsIURL* aURL){
|
|||
char* theModeStr= PR_GetEnv("PARSE_MODE");
|
||||
|
||||
if(theModeStr)
|
||||
if(0!=PL_strncasecmp("nav",theModeStr,3))
|
||||
if(0==strnicmp("other",theModeStr,5))
|
||||
theMode=eParseMode_other;
|
||||
|
||||
return Parse(aURL,theMode);
|
||||
|
@ -501,6 +509,8 @@ PRBool nsHTMLParser::Parse(nsIURL* aURL,eParseMode aMode){
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if(mDTD)
|
||||
mDTD->SetParser(this);
|
||||
mTokenizer=new CTokenizer(aURL, theDelegate, mParseMode);
|
||||
mTokenizer->Tokenize();
|
||||
result=IterateTokens();
|
||||
|
@ -525,6 +535,17 @@ PRBool nsHTMLParser::ResumeParse() {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLParser::GetStack(PRInt32* aStackPtr) {
|
||||
aStackPtr=&mContextStack[0];
|
||||
return mContextStackPos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -537,15 +558,18 @@ PRInt32 nsHTMLParser::CollectAttributes(nsCParserNode& aNode){
|
|||
nsDeque& deque=mTokenizer->GetDeque();
|
||||
nsDequeIterator end=deque.End();
|
||||
|
||||
while((*mCurrentPos!=end) && (eToken_attribute==subtype)) {
|
||||
while((*mCurrentPos<end) && (eToken_attribute==subtype)) {
|
||||
CHTMLToken* tkn=(CHTMLToken*)(++(*mCurrentPos));
|
||||
subtype=eHTMLTokenTypes(tkn->GetTokenType());
|
||||
if(eToken_attribute==subtype) {
|
||||
aNode.AddAttribute(tkn);
|
||||
}
|
||||
else (*mCurrentPos)--;
|
||||
if(tkn){
|
||||
subtype=eHTMLTokenTypes(tkn->GetTokenType());
|
||||
if(eToken_attribute==subtype) {
|
||||
aNode.AddAttribute(tkn);
|
||||
}
|
||||
else (*mCurrentPos)--;
|
||||
}
|
||||
}
|
||||
return aNode.GetAttributeCount();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -601,7 +625,7 @@ PRBool nsHTMLParser::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,
|
|||
//You must determine what container hierarchy you need to hold aToken,
|
||||
//and create that on the parsestack.
|
||||
result=ReduceContextStackFor(aChildTag);
|
||||
if(PR_FALSE==mDTD->CanContain(parentTag,aChildTag)) {
|
||||
if(PR_FALSE==mDTD->CanContain(GetTopNode(),aChildTag)) {
|
||||
//we unwound too far; now we have to recreate a valid context stack.
|
||||
result=CreateContextStackFor(aChildTag);
|
||||
}
|
||||
|
@ -615,35 +639,6 @@ PRBool nsHTMLParser::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,
|
|||
result=AddLeaf(aNode);
|
||||
}
|
||||
return result;
|
||||
|
||||
/*
|
||||
if(kNotFound!=parentTag) {
|
||||
if(PR_FALSE==mDTD->CanContain(parentTag,aTag)){
|
||||
//if you're here, then the new topmost container can't contain aToken.
|
||||
//You must determine what container hierarchy you need to hold aToken,
|
||||
//and create that on the parsestack.
|
||||
ReduceContextStackFor(aTag);
|
||||
if(PR_FALSE==mDTD->CanContain(parentTag,aTag)) {
|
||||
//we unwound too far; now we have to recreate a valid context stack.
|
||||
result=CreateContextStackFor(aTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CreateContextStackFor(aTag);
|
||||
}
|
||||
//now we think the stack is correct, so fall through
|
||||
//and push our newest token onto the stack...
|
||||
|
||||
if(mDTD->IsContainer(aTag)){
|
||||
result=OpenContainer(aNode);
|
||||
}
|
||||
else {
|
||||
result=AddLeaf(aNode);
|
||||
}
|
||||
|
||||
return result;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -672,6 +667,11 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
nsCParserNode attrNode((CHTMLToken*)aToken);
|
||||
PRInt32 attrCount=CollectAttributes(attrNode);
|
||||
|
||||
//now check to see if this token should be omitted...
|
||||
if(PR_TRUE==mDTD->CanOmit(GetTopNode(),tokenTagType)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
switch(tokenTagType) {
|
||||
|
||||
case eHTMLTag_html:
|
||||
|
@ -695,7 +695,7 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
break;
|
||||
|
||||
case eHTMLTag_form:
|
||||
result = mSink->OpenForm(attrNode);
|
||||
result = OpenForm(attrNode);
|
||||
break;
|
||||
|
||||
case eHTMLTag_meta:
|
||||
|
@ -718,6 +718,10 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
}
|
||||
break;
|
||||
|
||||
case eHTMLTag_script:
|
||||
result=HandleScriptToken(st); break;
|
||||
|
||||
|
||||
case eHTMLTag_map:
|
||||
// Put map into the head section
|
||||
result=OpenHead(attrNode);
|
||||
|
@ -727,6 +731,9 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
case eHTMLTag_head:
|
||||
result=PR_TRUE; break; //ignore head tags...
|
||||
|
||||
case eHTMLTag_select:
|
||||
result=PR_FALSE;
|
||||
|
||||
default:
|
||||
result=HandleDefaultStartToken(aToken,tokenTagType,attrNode);
|
||||
break;
|
||||
|
@ -755,6 +762,11 @@ PRBool nsHTMLParser::HandleEndToken(CToken* aToken) {
|
|||
CEndToken* st = (CEndToken*)(aToken);
|
||||
eHTMLTags tokenTagType=st->GetHTMLTag();
|
||||
|
||||
//now check to see if this token should be omitted...
|
||||
if(PR_TRUE==mDTD->CanOmit(GetTopNode(),tokenTagType)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken);
|
||||
switch(tokenTagType) {
|
||||
case eHTMLTag_html:
|
||||
|
@ -780,15 +792,19 @@ PRBool nsHTMLParser::HandleEndToken(CToken* aToken) {
|
|||
case eHTMLTag_form:
|
||||
{
|
||||
nsCParserNode aNode((CHTMLToken*)aToken);
|
||||
result=mSink->CloseForm(aNode);
|
||||
result=CloseForm(aNode);
|
||||
}
|
||||
break;
|
||||
|
||||
case eHTMLTag_script:
|
||||
result=PR_TRUE; break;
|
||||
|
||||
default:
|
||||
if(mDTD->IsContainer(tokenTagType)){
|
||||
result=CloseContainer(theNode);
|
||||
}
|
||||
result=PR_TRUE;
|
||||
//actually, you want to push the start token and ALL it's attributes...
|
||||
//
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
|
@ -826,43 +842,6 @@ PRBool nsHTMLParser::HandleCommentToken(CToken* aToken) {
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a text, whitespace and newline
|
||||
* tokens have been encountered in the parse process. After
|
||||
* verifying that the topmost container can contain this data,
|
||||
* we call AddLeaf to store this token in the top container.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- next (text) token to be handled
|
||||
* @return PR_TRUE if all went well; PR_FALSE if error occured
|
||||
*/
|
||||
PRBool nsHTMLParser::HandleSimpleContentToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,kNullToken);
|
||||
|
||||
CHTMLToken* theToken=(CHTMLToken*)aToken;
|
||||
eHTMLTags type=theToken->GetHTMLTag();
|
||||
PRBool result=PR_TRUE;
|
||||
nsCParserNode aNode(theToken);
|
||||
|
||||
switch(type) {
|
||||
case eHTMLTag_text:
|
||||
result=HandleDefaultStartToken(theToken,type,aNode);
|
||||
break;
|
||||
|
||||
case eHTMLTag_newline:
|
||||
case eHTMLTag_whitespace:
|
||||
if((mContextStackPos>0) &&
|
||||
(PR_FALSE==mDTD->CanOmit(mContextStack[mContextStackPos-1],type))) {
|
||||
result=HandleDefaultStartToken(theToken,type,aNode);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a skippedcontent token has
|
||||
* been encountered in the parse process. After verifying
|
||||
|
@ -996,6 +975,7 @@ PRBool nsHTMLParser::CloseHTML(const nsIParserNode& aNode){
|
|||
* @return TRUE if ok, FALSE if error
|
||||
*/
|
||||
PRBool nsHTMLParser::OpenHead(const nsIParserNode& aNode){
|
||||
mContextStack[mContextStackPos++]=eHTMLTag_head;
|
||||
PRBool result=mSink->OpenHead(aNode);
|
||||
return result;
|
||||
}
|
||||
|
@ -1010,6 +990,7 @@ PRBool nsHTMLParser::OpenHead(const nsIParserNode& aNode){
|
|||
*/
|
||||
PRBool nsHTMLParser::CloseHead(const nsIParserNode& aNode){
|
||||
PRBool result=mSink->CloseHead(aNode);
|
||||
mContextStack[--mContextStackPos]=eHTMLTag_unknown;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1084,10 +1065,10 @@ PRBool nsHTMLParser::CloseBody(const nsIParserNode& aNode){
|
|||
* @return TRUE if ok, FALSE if error
|
||||
*/
|
||||
PRBool nsHTMLParser::OpenForm(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mContextStackPos >= 0, kInvalidTagStackPos);
|
||||
PRBool result=mSink->OpenForm(aNode);
|
||||
mContextStack[mContextStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
return result;
|
||||
if(mHasOpenForm)
|
||||
CloseForm(aNode);
|
||||
mHasOpenForm=PR_TRUE;
|
||||
return mSink->OpenForm(aNode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1099,9 +1080,11 @@ PRBool nsHTMLParser::OpenForm(const nsIParserNode& aNode){
|
|||
* @return TRUE if ok, FALSE if error
|
||||
*/
|
||||
PRBool nsHTMLParser::CloseForm(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mContextStackPos > 0, kInvalidTagStackPos);
|
||||
PRBool result=mSink->CloseContainer(aNode);
|
||||
mContextStack[--mContextStackPos]=eHTMLTag_unknown;
|
||||
PRBool result=PR_TRUE;
|
||||
if(mHasOpenForm) {
|
||||
mHasOpenForm=PR_FALSE;
|
||||
result=mSink->CloseForm(aNode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1230,12 +1213,12 @@ PRBool nsHTMLParser::CloseContainersTo(PRInt32 anIndex){
|
|||
PRBool result=PR_TRUE;
|
||||
|
||||
nsAutoString empty;
|
||||
CHTMLToken aToken(empty);
|
||||
CEndToken aToken(empty);
|
||||
nsCParserNode theNode(&aToken);
|
||||
|
||||
if((anIndex<mContextStackPos) && (anIndex>=0)) {
|
||||
while(mContextStackPos>anIndex) {
|
||||
aToken.SetHTMLTag(mContextStack[mContextStackPos-1]);
|
||||
aToken.SetHTMLTag((eHTMLTags)mContextStack[mContextStackPos-1]);
|
||||
result=CloseContainer(theNode);
|
||||
}
|
||||
}
|
||||
|
@ -1287,7 +1270,7 @@ PRBool nsHTMLParser::CloseTopmostContainer(){
|
|||
|
||||
nsAutoString empty;
|
||||
CEndToken aToken(empty);
|
||||
aToken.SetHTMLTag(mContextStack[mContextStackPos-1]);
|
||||
aToken.SetHTMLTag((eHTMLTags)mContextStack[mContextStackPos-1]);
|
||||
nsCParserNode theNode(&aToken);
|
||||
|
||||
return CloseContainer(theNode);
|
||||
|
@ -1323,14 +1306,17 @@ PRBool nsHTMLParser::CreateContextStackFor(PRInt32 aChildTag){
|
|||
PRBool result=PR_FALSE;
|
||||
PRInt32 pos=0;
|
||||
PRInt32 cnt=0;
|
||||
PRInt32 theTop=GetTopNode();
|
||||
|
||||
if(PR_TRUE==mDTD->ForwardPropagate(theVector,GetTopNode(),aChildTag)){
|
||||
if(PR_TRUE==mDTD->ForwardPropagate(theVector,theTop,aChildTag)){
|
||||
//add code here to build up context stack based on forward propagated context vector...
|
||||
pos=0;
|
||||
cnt=theVector.Length()-1;
|
||||
result=PRBool(mContextStack[mContextStackPos-1]==theVector[cnt]);
|
||||
}
|
||||
else if(PR_TRUE==mDTD->BackwardPropagate(theVector,eHTMLTag_html,aChildTag)) {
|
||||
else if(PR_TRUE==mDTD->BackwardPropagate(theVector,theTop,aChildTag)) {
|
||||
if(theTop!=eHTMLTag_html)
|
||||
mDTD->BackwardPropagate(theVector,eHTMLTag_html,theTop);
|
||||
|
||||
//propagation worked, so pop unwanted containers, push new ones, then exit...
|
||||
pos=0;
|
||||
|
|
|
@ -87,13 +87,15 @@ friend class CTokenHandler;
|
|||
virtual PRBool Parse(nsIURL* aURL);
|
||||
virtual PRBool Parse(nsIURL* aURL,eParseMode aMode);
|
||||
virtual PRBool ResumeParse();
|
||||
virtual PRInt32 GetStack(PRInt32* aStackPtr);
|
||||
virtual PRBool HasOpenForm() const;
|
||||
|
||||
|
||||
PRBool HandleStartToken(CToken* aToken);
|
||||
PRBool HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsCParserNode& aNode);
|
||||
PRBool HandleEndToken(CToken* aToken);
|
||||
PRBool HandleEntityToken(CToken* aToken);
|
||||
PRBool HandleCommentToken(CToken* aToken);
|
||||
PRBool HandleSimpleContentToken(CToken* aToken);
|
||||
PRBool HandleSkippedContentToken(CToken* aToken);
|
||||
PRBool HandleAttributeToken(CToken* aToken);
|
||||
PRBool HandleScriptToken(CToken* aToken);
|
||||
|
@ -140,12 +142,12 @@ friend class CTokenHandler;
|
|||
PRInt32 GetTopmostIndex(eHTMLTags aTag) const;
|
||||
PRBool ReduceContextStackFor(PRInt32 aChildTag);
|
||||
PRBool CreateContextStackFor(PRInt32 aChildTag);
|
||||
PRBool HandleDefaultStartToken(CToken* aToken,eHTMLTags aTag,nsCParserNode& aNode);
|
||||
|
||||
nsIHTMLContentSink* mSink;
|
||||
CTokenizer* mTokenizer;
|
||||
|
||||
eHTMLTags mContextStack[50];
|
||||
// eHTMLTags mContextStack[50];
|
||||
PRInt32 mContextStack[50];
|
||||
PRInt32 mContextStackPos;
|
||||
|
||||
CTokenHandler* mTokenHandlers[100];
|
||||
|
@ -154,6 +156,7 @@ friend class CTokenHandler;
|
|||
|
||||
nsIDTD* mDTD;
|
||||
eParseMode mParseMode;
|
||||
PRBool mHasOpenForm;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -547,6 +547,7 @@ PRInt32 CTextToken::Consume(PRUnichar aChar, CScanner& aScanner) {
|
|||
*------------------------------------------------------*/
|
||||
CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) {
|
||||
mOrdinalValue=eToken_comment;
|
||||
mTagType=eHTMLTag_comment;
|
||||
}
|
||||
|
||||
/**-------------------------------------------------------
|
||||
|
@ -561,11 +562,11 @@ CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) {
|
|||
PRInt32 CCommentToken::Consume(PRUnichar aChar, CScanner& aScanner) {
|
||||
|
||||
PRUnichar ch,ch2;
|
||||
PRInt32 result;
|
||||
|
||||
static nsAutoString terminals(">");
|
||||
|
||||
aScanner.GetChar(ch);
|
||||
PRInt32 result=aScanner.GetChar(ch);
|
||||
mTextValue="<!";
|
||||
if(kMinus==ch) {
|
||||
aScanner.GetChar(ch2);
|
||||
|
@ -1285,7 +1286,7 @@ eHTMLTags DetermineHTMLTagType(const nsString& aString)
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const char* GetTagName(eHTMLTags aTag) {
|
||||
const char* GetTagName(PRInt32 aTag) {
|
||||
const char* result=0;
|
||||
PRInt32 cnt=sizeof(gHTMLTagTable)/sizeof(HTMLTagEntry);
|
||||
|
||||
|
|
|
@ -58,9 +58,10 @@ enum eHTMLTags
|
|||
eHTMLTag_blink, eHTMLTag_blockquote, eHTMLTag_body, eHTMLTag_br,
|
||||
eHTMLTag_button, eHTMLTag_caption, eHTMLTag_center,
|
||||
eHTMLTag_certificate, eHTMLTag_cite,
|
||||
eHTMLTag_code, eHTMLTag_col, eHTMLTag_colgroup, eHTMLTag_dd,
|
||||
eHTMLTag_del, eHTMLTag_dfn, eHTMLTag_div, eHTMLTag_dir,
|
||||
eHTMLTag_dl, eHTMLTag_dt, eHTMLTag_em, eHTMLTag_embed,
|
||||
eHTMLTag_code, eHTMLTag_col, eHTMLTag_colgroup, eHTMLTag_comment,
|
||||
eHTMLTag_dd, eHTMLTag_del, eHTMLTag_dfn, eHTMLTag_div,
|
||||
eHTMLTag_dir, eHTMLTag_dl, eHTMLTag_dt,
|
||||
eHTMLTag_em, eHTMLTag_embed,
|
||||
eHTMLTag_fieldset, eHTMLTag_font, eHTMLTag_footer,
|
||||
eHTMLTag_form, eHTMLTag_frame, eHTMLTag_frameset,
|
||||
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3, eHTMLTag_h4,
|
||||
|
@ -77,7 +78,7 @@ enum eHTMLTags
|
|||
eHTMLTag_option, eHTMLTag_paragraph, eHTMLTag_param, eHTMLTag_plaintext,
|
||||
eHTMLTag_pre, eHTMLTag_quotation, eHTMLTag_strike, eHTMLTag_samp,
|
||||
eHTMLTag_script, eHTMLTag_select,
|
||||
eHTMLTag_server, eHTMLTag_small,
|
||||
eHTMLTag_server, eHTMLTag_small,
|
||||
eHTMLTag_spacer, eHTMLTag_span,
|
||||
eHTMLTag_strong, eHTMLTag_style, eHTMLTag_sub, eHTMLTag_sup,
|
||||
eHTMLTag_table, eHTMLTag_tbody, eHTMLTag_td,
|
||||
|
@ -113,7 +114,7 @@ PRInt32 ConsumeAttributeText(PRUnichar aChar,nsString& aString,CScanner&
|
|||
PRInt32 FindEntityIndex(const char* aBuffer,PRInt32 aBufLen=-1);
|
||||
eHTMLTags DetermineHTMLTagType(const nsString& aString);
|
||||
eHTMLTokenTypes DetermineTokenType(const nsString& aString);
|
||||
const char* GetTagName(eHTMLTags aTag);
|
||||
const char* GetTagName(PRInt32 aTag);
|
||||
|
||||
|
||||
/** -----------------------------------------------------
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
{0xaa, 0xda, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}}
|
||||
|
||||
|
||||
class nsIParser;
|
||||
|
||||
class nsIDTD : public nsISupports {
|
||||
|
||||
|
@ -49,7 +50,18 @@ class nsIDTD : public nsISupports {
|
|||
* @param aChild -- tag enum of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const =0;
|
||||
virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const=0;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- tag enum of parent container
|
||||
* @param aChild -- tag enum of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
virtual void SetParser(nsIParser* aParser)=0;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
|
|
|
@ -54,6 +54,8 @@ class nsIParser : public nsISupports {
|
|||
virtual nsIContentSink* SetContentSink(nsIContentSink* aContentSink)=0;
|
||||
virtual PRBool Parse(nsIURL* aURL)=0;
|
||||
virtual PRBool ResumeParse()=0;
|
||||
virtual PRInt32 GetStack(PRInt32* aStackPtr)=0;
|
||||
virtual PRBool HasOpenForm() const=0;
|
||||
};
|
||||
|
||||
extern NS_HTMLPARS nsresult NS_NewHTMLParser(nsIParser** aInstancePtrResult);
|
||||
|
|
|
@ -48,13 +48,13 @@ class CToken;
|
|||
class ITokenizerDelegate {
|
||||
public:
|
||||
|
||||
virtual PRBool WillTokenize()=0;
|
||||
virtual PRBool DidTokenize()=0;
|
||||
virtual PRBool WillTokenize()=0;
|
||||
virtual PRBool DidTokenize()=0;
|
||||
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode)=0;
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode)=0;
|
||||
virtual PRBool WillAddToken(CToken& aToken)=0;
|
||||
|
||||
virtual eParseMode GetParseMode() const=0;
|
||||
virtual eParseMode GetParseMode(void) const=0;
|
||||
virtual nsIDTD* GetDTD(void) const=0;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,35 +40,34 @@ enum eParseMode {
|
|||
eParseMode_other
|
||||
};
|
||||
|
||||
const PRInt32 kNotFound = -1;
|
||||
const PRInt32 kNoError = 0;
|
||||
const PRInt32 kEOF = 1000;
|
||||
const PRInt32 kNotFound = -1;
|
||||
const PRInt32 kNoError = 0;
|
||||
const PRInt32 kEOF = 1000000L;
|
||||
|
||||
const PRUint32 kNewLine = '\n';
|
||||
const PRUint32 kCR = '\r';
|
||||
const PRUint32 kLF = '\n';
|
||||
const PRUint32 kTab = '\t';
|
||||
const PRUint32 kSpace = ' ';
|
||||
const PRUint32 kQuote = '"';
|
||||
const PRUint32 kApostrophe = '\'';
|
||||
const PRUint32 kLessThan = '<';
|
||||
const PRUint32 kGreaterThan = '>';
|
||||
const PRUint32 kAmpersand = '&';
|
||||
const PRUint32 kNullPRInt8 = '\0';
|
||||
const PRUint32 kForwardSlash = '/';
|
||||
const PRUint32 kEqual = '=';
|
||||
const PRUint32 kMinus = '-';
|
||||
const PRUint32 kPlus = '+';
|
||||
const PRUint32 kExclamation = '!';
|
||||
const PRUint32 kSemicolon = ';';
|
||||
const PRUint32 kHashsign = '#';
|
||||
const PRUint32 kCR = '\r';
|
||||
const PRUint32 kLF = '\n';
|
||||
const PRUint32 kTab = '\t';
|
||||
const PRUint32 kSpace = ' ';
|
||||
const PRUint32 kQuote = '"';
|
||||
const PRUint32 kApostrophe = '\'';
|
||||
const PRUint32 kLessThan = '<';
|
||||
const PRUint32 kGreaterThan = '>';
|
||||
const PRUint32 kAmpersand = '&';
|
||||
const PRUint32 kForwardSlash = '/';
|
||||
const PRUint32 kEqual = '=';
|
||||
const PRUint32 kMinus = '-';
|
||||
const PRUint32 kPlus = '+';
|
||||
const PRUint32 kExclamation = '!';
|
||||
const PRUint32 kSemicolon = ';';
|
||||
const PRUint32 kHashsign = '#';
|
||||
const PRUint32 kAsterisk = '*';
|
||||
const PRUint32 kUnderbar = '_';
|
||||
const PRUint32 kComma = ',';
|
||||
const PRUint32 kLeftParen = '(';
|
||||
const PRUint32 kRightParen = ')';
|
||||
const PRUint32 kLeftBrace = '{';
|
||||
const PRUint32 kRightBrace = '}';
|
||||
const PRUint32 kUnderbar = '_';
|
||||
const PRUint32 kComma = ',';
|
||||
const PRUint32 kLeftParen = '(';
|
||||
const PRUint32 kRightParen = ')';
|
||||
const PRUint32 kLeftBrace = '{';
|
||||
const PRUint32 kRightBrace = '}';
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -325,7 +325,7 @@ CWhitespaceTokenHandler::~CWhitespaceTokenHandler(){
|
|||
PRBool CWhitespaceTokenHandler::operator()(CToken* aToken,nsHTMLParser* aParser){
|
||||
NS_ASSERTION(0!=aParser,kNullParserGiven);
|
||||
if(aParser){
|
||||
return aParser->HandleSimpleContentToken(aToken);
|
||||
return aParser->HandleStartToken(aToken);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ CNewlineTokenHandler::~CNewlineTokenHandler(){
|
|||
PRBool CNewlineTokenHandler::operator()(CToken* aToken,nsHTMLParser* aParser){
|
||||
NS_ASSERTION(0!=aParser,kNullParserGiven);
|
||||
if(aParser){
|
||||
return aParser->HandleSimpleContentToken(aToken);
|
||||
return aParser->HandleStartToken(aToken);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ CTextTokenHandler::~CTextTokenHandler(){
|
|||
PRBool CTextTokenHandler::operator()(CToken* aToken,nsHTMLParser* aParser){
|
||||
NS_ASSERTION(0!=aParser,kNullParserGiven);
|
||||
if(aParser){
|
||||
return aParser->HandleSimpleContentToken(aToken);
|
||||
return aParser->HandleStartToken(aToken);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsHTMLTokens.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsParserTypes.h"
|
||||
#include "nsIParser.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
|
@ -98,6 +99,7 @@ NS_IMPL_RELEASE(CNavDTD)
|
|||
* @return
|
||||
*/
|
||||
CNavDTD::CNavDTD() : nsIDTD() {
|
||||
mParser=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +112,36 @@ CNavDTD::CNavDTD() : nsIDTD() {
|
|||
CNavDTD::~CNavDTD(){
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void CNavDTD::SetParser(nsIParser* aParser) {
|
||||
mParser=aParser;
|
||||
}
|
||||
|
||||
|
||||
static char formElementTags[]= {
|
||||
eHTMLTag_button, eHTMLTag_fieldset, eHTMLTag_input,
|
||||
eHTMLTag_isindex, eHTMLTag_label, eHTMLTag_legend,
|
||||
eHTMLTag_select, eHTMLTag_textarea,0};
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 4/8/98
|
||||
* @param aParent -- tag enum of parent container
|
||||
* @param aChild -- tag enum of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
PRBool CNavDTD::CanContainFormElement(PRInt32 aParent,PRInt32 aChild) const {
|
||||
PRBool result=(mParser) ? mParser->HasOpenForm() : PR_FALSE;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
|
@ -121,6 +153,7 @@ CNavDTD::~CNavDTD(){
|
|||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
||||
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
//tagset1 has 64 members...
|
||||
|
@ -194,6 +227,11 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
if(eHTMLTag_userdefined==aChild) // XXX Hack: For now...
|
||||
result=PR_TRUE;
|
||||
|
||||
//handle form elements (this is very much a WIP!!!)
|
||||
if(0!=strchr(formElementTags,aChild)){
|
||||
return CanContainFormElement(aParent,aChild);
|
||||
}
|
||||
|
||||
switch(aParent) {
|
||||
case eHTMLTag_a:
|
||||
result=PRBool(0!=strchr(gTagSet2,aChild)); break;
|
||||
|
@ -302,7 +340,15 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
case eHTMLTag_h1: case eHTMLTag_h2:
|
||||
case eHTMLTag_h3: case eHTMLTag_h4:
|
||||
case eHTMLTag_h5: case eHTMLTag_h6:
|
||||
result=PRBool(0!=strchr(gTagSet1,aChild)); break;
|
||||
{
|
||||
static char badTags[]={
|
||||
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3,
|
||||
eHTMLTag_h4, eHTMLTag_h5, eHTMLTag_h6, 0};
|
||||
if(0!=strchr(badTags,aChild))
|
||||
result=PR_FALSE;
|
||||
else result=PRBool(0!=strchr(gTagSet1,aChild));
|
||||
}
|
||||
break;
|
||||
|
||||
case eHTMLTag_head:
|
||||
{
|
||||
|
@ -418,7 +464,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
break; //unadorned script text...
|
||||
|
||||
case eHTMLTag_select:
|
||||
result=PRBool(eHTMLTag_option==aChild); break;
|
||||
result=PR_TRUE; break; //for now, allow select to contain anything...
|
||||
|
||||
case eHTMLTag_small:
|
||||
result=PRBool(0!=strchr(gTagSet2,aChild)); break;
|
||||
|
@ -483,7 +529,7 @@ PRBool CNavDTD::CanContain(PRInt32 aParent,PRInt32 aChild) const {
|
|||
case eHTMLTag_userdefined:
|
||||
result=PR_TRUE; break; //XXX for now...
|
||||
|
||||
case eHTMLTag_xmp:
|
||||
case eHTMLTag_xmp:
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
|
@ -529,6 +575,8 @@ PRBool CNavDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const {
|
|||
}
|
||||
break;
|
||||
|
||||
result=PR_TRUE; break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -546,29 +594,43 @@ PRBool CNavDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const {
|
|||
PRBool CNavDTD::CanOmit(PRInt32 aParent,PRInt32 aChild) const {
|
||||
PRBool result=PR_FALSE;
|
||||
|
||||
switch((eHTMLTags)aParent) {
|
||||
case eHTMLTag_html:
|
||||
case eHTMLTag_body:
|
||||
case eHTMLTag_head:
|
||||
case eHTMLTag_title:
|
||||
|
||||
case eHTMLTag_tr:
|
||||
// case eHTMLTag_td:
|
||||
case eHTMLTag_table:
|
||||
case eHTMLTag_thead:
|
||||
case eHTMLTag_tfoot:
|
||||
case eHTMLTag_tbody:
|
||||
case eHTMLTag_col:
|
||||
case eHTMLTag_colgroup:
|
||||
if((aChild==eHTMLTag_newline) ||
|
||||
(aChild==eHTMLTag_whitespace))
|
||||
result=PR_TRUE;
|
||||
//begin with some simple (and obvious) cases...
|
||||
switch((eHTMLTags)aChild) {
|
||||
|
||||
case eHTMLTag_userdefined:
|
||||
case eHTMLTag_comment:
|
||||
result=PR_TRUE;
|
||||
break;
|
||||
|
||||
case eHTMLTag_button: case eHTMLTag_fieldset:
|
||||
case eHTMLTag_input: case eHTMLTag_isindex:
|
||||
case eHTMLTag_label: case eHTMLTag_legend:
|
||||
case eHTMLTag_select: case eHTMLTag_textarea:
|
||||
if(PR_FALSE==mParser->HasOpenForm())
|
||||
result=PR_TRUE;
|
||||
break;
|
||||
|
||||
case eHTMLTag_newline:
|
||||
case eHTMLTag_whitespace:
|
||||
|
||||
switch((eHTMLTags)aParent) {
|
||||
case eHTMLTag_html: case eHTMLTag_head:
|
||||
case eHTMLTag_title: case eHTMLTag_map:
|
||||
case eHTMLTag_tr: case eHTMLTag_table:
|
||||
case eHTMLTag_thead: case eHTMLTag_tfoot:
|
||||
case eHTMLTag_tbody: case eHTMLTag_col:
|
||||
case eHTMLTag_colgroup: case eHTMLTag_unknown:
|
||||
result=PR_TRUE;
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
break;
|
||||
|
||||
default:
|
||||
result=PR_FALSE;
|
||||
if(eHTMLTag_unknown==aParent)
|
||||
result=PRBool(eHTMLTag_html!=aChild);
|
||||
break;
|
||||
}
|
||||
} //switch
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
{0xaa, 0xda, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}}
|
||||
|
||||
|
||||
class nsIParser;
|
||||
|
||||
class CNavDTD : public nsIDTD {
|
||||
|
||||
|
@ -73,6 +74,15 @@ class CNavDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetParser(nsIParser* aParser);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
|
@ -150,6 +160,11 @@ class CNavDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool BackwardPropagate(nsString& aVector,PRInt32 aParentTag,PRInt32 aChildTag) const;
|
||||
|
||||
protected:
|
||||
|
||||
PRBool CanContainFormElement(PRInt32 aParent,PRInt32 aChild) const;
|
||||
|
||||
nsIParser* mParser;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ CNavDelegate::CNavDelegate(CNavDelegate& aDelegate) :
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
eParseMode CNavDelegate::GetParseMode() const {
|
||||
eParseMode CNavDelegate::GetParseMode(void) const {
|
||||
return eParseMode_unknown;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ CToken* CNavDelegate::ConsumeTag(PRUnichar aChar,CScanner& aScanner,PRInt32& anE
|
|||
default:
|
||||
if(nsString::IsAlpha(aChar))
|
||||
return ConsumeStartTag(aChar,aScanner,anErrorCode);
|
||||
else if(kNotFound!=aChar) {
|
||||
else if(kEOF!=aChar) {
|
||||
nsAutoString temp("<");
|
||||
return ConsumeText(temp,aScanner,anErrorCode);
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ class CNavDelegate : public ITokenizerDelegate {
|
|||
CNavDelegate();
|
||||
CNavDelegate(CNavDelegate& aDelegate);
|
||||
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual PRBool WillAddToken(CToken& aToken);
|
||||
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
|
||||
virtual eParseMode GetParseMode() const;
|
||||
virtual eParseMode GetParseMode(void) const;
|
||||
virtual nsIDTD* GetDTD(void) const;
|
||||
static void SelfTest();
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -82,4 +82,3 @@ class CNavDelegate : public ITokenizerDelegate {
|
|||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include "nsHTMLTokens.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsParserTypes.h"
|
||||
#include "nsIParser.h"
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIDTDIID, NS_IDTD_IID);
|
||||
|
@ -98,6 +99,7 @@ NS_IMPL_RELEASE(COtherDTD)
|
|||
* @return
|
||||
*/
|
||||
COtherDTD::COtherDTD() : nsIDTD() {
|
||||
mParser=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -110,6 +112,18 @@ COtherDTD::COtherDTD() : nsIDTD() {
|
|||
COtherDTD::~COtherDTD(){
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void COtherDTD::SetParser(nsIParser* aParser) {
|
||||
mParser=aParser;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
|
@ -503,6 +517,8 @@ PRBool COtherDTD::CanContainIndirect(PRInt32 aParent,PRInt32 aChild) const {
|
|||
}
|
||||
break;
|
||||
|
||||
result=PR_TRUE; break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
|
||||
|
||||
|
||||
class nsIParser;
|
||||
|
||||
class COtherDTD : public nsIDTD {
|
||||
|
||||
|
@ -52,7 +53,7 @@ class COtherDTD : public nsIDTD {
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
COtherDTD();
|
||||
COtherDTD();
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -63,6 +64,16 @@ class COtherDTD : public nsIDTD {
|
|||
*/
|
||||
virtual ~COtherDTD();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetParser(nsIParser* aParser);
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
|
@ -153,6 +164,8 @@ class COtherDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool BackwardPropagate(nsString& aVector,PRInt32 aParentTag,PRInt32 aChildTag) const;
|
||||
|
||||
protected:
|
||||
nsIParser* mParser;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ COtherDelegate::COtherDelegate(COtherDelegate& aDelegate) :
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
eParseMode COtherDelegate::GetParseMode() const {
|
||||
eParseMode COtherDelegate::GetParseMode(void) const {
|
||||
return eParseMode_unknown;
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,7 @@ CToken* COtherDelegate::ConsumeTag(PRUnichar aChar,CScanner& aScanner,PRInt32& a
|
|||
default:
|
||||
if(nsString::IsAlpha(aChar))
|
||||
return ConsumeStartTag(aChar,aScanner,anErrorCode);
|
||||
else if(kNotFound!=aChar) {
|
||||
else if(kEOF!=aChar) {
|
||||
nsAutoString temp("<");
|
||||
return ConsumeText(temp,aScanner,anErrorCode);
|
||||
}
|
||||
|
|
|
@ -49,15 +49,15 @@ class COtherDelegate : public ITokenizerDelegate {
|
|||
COtherDelegate();
|
||||
COtherDelegate(COtherDelegate& aDelegate);
|
||||
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode);
|
||||
virtual PRBool WillAddToken(CToken& aToken);
|
||||
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
virtual PRBool WillTokenize();
|
||||
virtual PRBool DidTokenize();
|
||||
|
||||
virtual eParseMode GetParseMode() const;
|
||||
virtual eParseMode GetParseMode(void) const;
|
||||
virtual nsIDTD* GetDTD(void) const;
|
||||
static void SelfTest();
|
||||
static void SelfTest();
|
||||
|
||||
protected:
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ nsHTMLParser::nsHTMLParser() {
|
|||
nsCRT::zero(mContextStack,sizeof(mContextStack));
|
||||
nsCRT::zero(mTokenHandlers,sizeof(mTokenHandlers));
|
||||
mDTD=0;
|
||||
mHasOpenForm=PR_FALSE;
|
||||
mTokenHandlerCount=0;
|
||||
InitializeDefaultTokenHandlers();
|
||||
gVerificationOutputDir = PR_GetEnv("VERIFY_PARSER");
|
||||
|
@ -176,8 +177,20 @@ nsresult nsHTMLParser::QueryInterface(const nsIID& aIID, void** aInstancePtr)
|
|||
eHTMLTags nsHTMLParser::NodeAt(PRInt32 aPos) const {
|
||||
NS_PRECONDITION(0 <= aPos, "bad nodeAt");
|
||||
if((aPos>-1) && (aPos<mContextStackPos))
|
||||
return mContextStack[aPos];
|
||||
return (eHTMLTags)kNotFound;
|
||||
return (eHTMLTags)mContextStack[aPos];
|
||||
return eHTMLTag_unknown;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method allows the caller to determine if a form
|
||||
* element is currently open.
|
||||
*
|
||||
* @update gess 4/2/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRBool nsHTMLParser::HasOpenForm() const {
|
||||
return mHasOpenForm;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -190,10 +203,11 @@ eHTMLTags nsHTMLParser::NodeAt(PRInt32 aPos) const {
|
|||
*/
|
||||
eHTMLTags nsHTMLParser::GetTopNode() const {
|
||||
if(mContextStackPos)
|
||||
return mContextStack[mContextStackPos-1];
|
||||
return (eHTMLTags)kNotFound;
|
||||
return (eHTMLTags)mContextStack[mContextStackPos-1];
|
||||
return eHTMLTag_unknown;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether the given tag is open anywhere
|
||||
* in our context stack.
|
||||
|
@ -326,14 +340,13 @@ nsIContentSink* nsHTMLParser::SetContentSink(nsIContentSink* aSink) {
|
|||
* @param aDTD is the DTD we plan to ask for verification
|
||||
* @return TRUE if we know how to handle it, else false
|
||||
*/
|
||||
PRBool VerifyContextVector(eHTMLTags tags[],PRInt32 count,nsIDTD* aDTD) {
|
||||
PRBool VerifyContextVector(PRInt32 aTags[],PRInt32 count,nsIDTD* aDTD) {
|
||||
|
||||
PRBool result=PR_TRUE;
|
||||
|
||||
if(0!=gVerificationOutputDir) {
|
||||
|
||||
if(aDTD){
|
||||
PRInt32 theArray[50];
|
||||
|
||||
#ifdef XP_PC
|
||||
char path[_MAX_PATH+1];
|
||||
|
@ -341,17 +354,16 @@ PRBool VerifyContextVector(eHTMLTags tags[],PRInt32 count,nsIDTD* aDTD) {
|
|||
#endif
|
||||
|
||||
for(int i=0;i<count;i++){
|
||||
theArray[i]=tags[i];
|
||||
|
||||
#ifdef NS_WIN32
|
||||
strcat(path,"/");
|
||||
const char* name=GetTagName(tags[i]);
|
||||
const char* name=GetTagName(aTags[i]);
|
||||
strcat(path,name);
|
||||
mkdir(path);
|
||||
#endif
|
||||
}
|
||||
//ok, now see if we understand this vector
|
||||
result=aDTD->VerifyContextVector(theArray,count);
|
||||
result=aDTD->VerifyContextVector(aTags,count);
|
||||
}
|
||||
if(PR_FALSE==result){
|
||||
//add debugging code here to record the fact that we just encountered
|
||||
|
@ -389,9 +401,12 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
eHTMLTokenTypes type=eHTMLTokenTypes(theToken->GetTokenType());
|
||||
iteration++; //debug purposes...
|
||||
|
||||
switch(eHTMLTokenTypes(type)){
|
||||
switch(type){
|
||||
|
||||
case eToken_start:
|
||||
case eToken_text:
|
||||
case eToken_newline:
|
||||
case eToken_whitespace:
|
||||
result=HandleStartToken(theToken); break;
|
||||
|
||||
case eToken_end:
|
||||
|
@ -399,11 +414,6 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
|
||||
case eToken_entity:
|
||||
result=HandleEntityToken(theToken); break;
|
||||
|
||||
case eToken_text:
|
||||
case eToken_newline:
|
||||
case eToken_whitespace:
|
||||
result=HandleSimpleContentToken(theToken); break;
|
||||
|
||||
case eToken_skippedcontent:
|
||||
//used in cases like <SCRIPT> where we skip over script content.
|
||||
|
@ -412,9 +422,6 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
case eToken_attribute:
|
||||
result=HandleAttributeToken(theToken); break;
|
||||
|
||||
case eToken_script:
|
||||
result=HandleScriptToken(theToken); break;
|
||||
|
||||
case eToken_style:
|
||||
result=HandleStyleToken(theToken); break;
|
||||
|
||||
|
@ -428,7 +435,7 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
}
|
||||
VerifyContextVector(mContextStack,mContextStackPos,mDTD);
|
||||
++(*mCurrentPos);
|
||||
done=PRBool(e==*mCurrentPos);
|
||||
done=PRBool(!(*mCurrentPos<e));
|
||||
}
|
||||
|
||||
//One last thing...close any open containers.
|
||||
|
@ -438,6 +445,7 @@ PRBool nsHTMLParser::IterateTokens() {
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This is the main controlling routine in the parsing process.
|
||||
* Note that it may get called multiple times for the same scanner,
|
||||
|
@ -454,7 +462,7 @@ PRBool nsHTMLParser::Parse(nsIURL* aURL){
|
|||
char* theModeStr= PR_GetEnv("PARSE_MODE");
|
||||
|
||||
if(theModeStr)
|
||||
if(0!=PL_strncasecmp("nav",theModeStr,3))
|
||||
if(0==strnicmp("other",theModeStr,5))
|
||||
theMode=eParseMode_other;
|
||||
|
||||
return Parse(aURL,theMode);
|
||||
|
@ -501,6 +509,8 @@ PRBool nsHTMLParser::Parse(nsIURL* aURL,eParseMode aMode){
|
|||
return PR_FALSE;
|
||||
}
|
||||
|
||||
if(mDTD)
|
||||
mDTD->SetParser(this);
|
||||
mTokenizer=new CTokenizer(aURL, theDelegate, mParseMode);
|
||||
mTokenizer->Tokenize();
|
||||
result=IterateTokens();
|
||||
|
@ -525,6 +535,17 @@ PRBool nsHTMLParser::ResumeParse() {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
PRInt32 nsHTMLParser::GetStack(PRInt32* aStackPtr) {
|
||||
aStackPtr=&mContextStack[0];
|
||||
return mContextStackPos;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -537,15 +558,18 @@ PRInt32 nsHTMLParser::CollectAttributes(nsCParserNode& aNode){
|
|||
nsDeque& deque=mTokenizer->GetDeque();
|
||||
nsDequeIterator end=deque.End();
|
||||
|
||||
while((*mCurrentPos!=end) && (eToken_attribute==subtype)) {
|
||||
while((*mCurrentPos<end) && (eToken_attribute==subtype)) {
|
||||
CHTMLToken* tkn=(CHTMLToken*)(++(*mCurrentPos));
|
||||
subtype=eHTMLTokenTypes(tkn->GetTokenType());
|
||||
if(eToken_attribute==subtype) {
|
||||
aNode.AddAttribute(tkn);
|
||||
}
|
||||
else (*mCurrentPos)--;
|
||||
if(tkn){
|
||||
subtype=eHTMLTokenTypes(tkn->GetTokenType());
|
||||
if(eToken_attribute==subtype) {
|
||||
aNode.AddAttribute(tkn);
|
||||
}
|
||||
else (*mCurrentPos)--;
|
||||
}
|
||||
}
|
||||
return aNode.GetAttributeCount();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -601,7 +625,7 @@ PRBool nsHTMLParser::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,
|
|||
//You must determine what container hierarchy you need to hold aToken,
|
||||
//and create that on the parsestack.
|
||||
result=ReduceContextStackFor(aChildTag);
|
||||
if(PR_FALSE==mDTD->CanContain(parentTag,aChildTag)) {
|
||||
if(PR_FALSE==mDTD->CanContain(GetTopNode(),aChildTag)) {
|
||||
//we unwound too far; now we have to recreate a valid context stack.
|
||||
result=CreateContextStackFor(aChildTag);
|
||||
}
|
||||
|
@ -615,35 +639,6 @@ PRBool nsHTMLParser::HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,
|
|||
result=AddLeaf(aNode);
|
||||
}
|
||||
return result;
|
||||
|
||||
/*
|
||||
if(kNotFound!=parentTag) {
|
||||
if(PR_FALSE==mDTD->CanContain(parentTag,aTag)){
|
||||
//if you're here, then the new topmost container can't contain aToken.
|
||||
//You must determine what container hierarchy you need to hold aToken,
|
||||
//and create that on the parsestack.
|
||||
ReduceContextStackFor(aTag);
|
||||
if(PR_FALSE==mDTD->CanContain(parentTag,aTag)) {
|
||||
//we unwound too far; now we have to recreate a valid context stack.
|
||||
result=CreateContextStackFor(aTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CreateContextStackFor(aTag);
|
||||
}
|
||||
//now we think the stack is correct, so fall through
|
||||
//and push our newest token onto the stack...
|
||||
|
||||
if(mDTD->IsContainer(aTag)){
|
||||
result=OpenContainer(aNode);
|
||||
}
|
||||
else {
|
||||
result=AddLeaf(aNode);
|
||||
}
|
||||
|
||||
return result;
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -672,6 +667,11 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
nsCParserNode attrNode((CHTMLToken*)aToken);
|
||||
PRInt32 attrCount=CollectAttributes(attrNode);
|
||||
|
||||
//now check to see if this token should be omitted...
|
||||
if(PR_TRUE==mDTD->CanOmit(GetTopNode(),tokenTagType)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
switch(tokenTagType) {
|
||||
|
||||
case eHTMLTag_html:
|
||||
|
@ -695,7 +695,7 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
break;
|
||||
|
||||
case eHTMLTag_form:
|
||||
result = mSink->OpenForm(attrNode);
|
||||
result = OpenForm(attrNode);
|
||||
break;
|
||||
|
||||
case eHTMLTag_meta:
|
||||
|
@ -718,6 +718,10 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
}
|
||||
break;
|
||||
|
||||
case eHTMLTag_script:
|
||||
result=HandleScriptToken(st); break;
|
||||
|
||||
|
||||
case eHTMLTag_map:
|
||||
// Put map into the head section
|
||||
result=OpenHead(attrNode);
|
||||
|
@ -727,6 +731,9 @@ PRBool nsHTMLParser::HandleStartToken(CToken* aToken) {
|
|||
case eHTMLTag_head:
|
||||
result=PR_TRUE; break; //ignore head tags...
|
||||
|
||||
case eHTMLTag_select:
|
||||
result=PR_FALSE;
|
||||
|
||||
default:
|
||||
result=HandleDefaultStartToken(aToken,tokenTagType,attrNode);
|
||||
break;
|
||||
|
@ -755,6 +762,11 @@ PRBool nsHTMLParser::HandleEndToken(CToken* aToken) {
|
|||
CEndToken* st = (CEndToken*)(aToken);
|
||||
eHTMLTags tokenTagType=st->GetHTMLTag();
|
||||
|
||||
//now check to see if this token should be omitted...
|
||||
if(PR_TRUE==mDTD->CanOmit(GetTopNode(),tokenTagType)) {
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
nsCParserNode theNode((CHTMLToken*)aToken);
|
||||
switch(tokenTagType) {
|
||||
case eHTMLTag_html:
|
||||
|
@ -780,15 +792,19 @@ PRBool nsHTMLParser::HandleEndToken(CToken* aToken) {
|
|||
case eHTMLTag_form:
|
||||
{
|
||||
nsCParserNode aNode((CHTMLToken*)aToken);
|
||||
result=mSink->CloseForm(aNode);
|
||||
result=CloseForm(aNode);
|
||||
}
|
||||
break;
|
||||
|
||||
case eHTMLTag_script:
|
||||
result=PR_TRUE; break;
|
||||
|
||||
default:
|
||||
if(mDTD->IsContainer(tokenTagType)){
|
||||
result=CloseContainer(theNode);
|
||||
}
|
||||
result=PR_TRUE;
|
||||
//actually, you want to push the start token and ALL it's attributes...
|
||||
//
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
|
@ -826,43 +842,6 @@ PRBool nsHTMLParser::HandleCommentToken(CToken* aToken) {
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a text, whitespace and newline
|
||||
* tokens have been encountered in the parse process. After
|
||||
* verifying that the topmost container can contain this data,
|
||||
* we call AddLeaf to store this token in the top container.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- next (text) token to be handled
|
||||
* @return PR_TRUE if all went well; PR_FALSE if error occured
|
||||
*/
|
||||
PRBool nsHTMLParser::HandleSimpleContentToken(CToken* aToken) {
|
||||
NS_PRECONDITION(0!=aToken,kNullToken);
|
||||
|
||||
CHTMLToken* theToken=(CHTMLToken*)aToken;
|
||||
eHTMLTags type=theToken->GetHTMLTag();
|
||||
PRBool result=PR_TRUE;
|
||||
nsCParserNode aNode(theToken);
|
||||
|
||||
switch(type) {
|
||||
case eHTMLTag_text:
|
||||
result=HandleDefaultStartToken(theToken,type,aNode);
|
||||
break;
|
||||
|
||||
case eHTMLTag_newline:
|
||||
case eHTMLTag_whitespace:
|
||||
if((mContextStackPos>0) &&
|
||||
(PR_FALSE==mDTD->CanOmit(mContextStack[mContextStackPos-1],type))) {
|
||||
result=HandleDefaultStartToken(theToken,type,aNode);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
} //switch
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a skippedcontent token has
|
||||
* been encountered in the parse process. After verifying
|
||||
|
@ -996,6 +975,7 @@ PRBool nsHTMLParser::CloseHTML(const nsIParserNode& aNode){
|
|||
* @return TRUE if ok, FALSE if error
|
||||
*/
|
||||
PRBool nsHTMLParser::OpenHead(const nsIParserNode& aNode){
|
||||
mContextStack[mContextStackPos++]=eHTMLTag_head;
|
||||
PRBool result=mSink->OpenHead(aNode);
|
||||
return result;
|
||||
}
|
||||
|
@ -1010,6 +990,7 @@ PRBool nsHTMLParser::OpenHead(const nsIParserNode& aNode){
|
|||
*/
|
||||
PRBool nsHTMLParser::CloseHead(const nsIParserNode& aNode){
|
||||
PRBool result=mSink->CloseHead(aNode);
|
||||
mContextStack[--mContextStackPos]=eHTMLTag_unknown;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1084,10 +1065,10 @@ PRBool nsHTMLParser::CloseBody(const nsIParserNode& aNode){
|
|||
* @return TRUE if ok, FALSE if error
|
||||
*/
|
||||
PRBool nsHTMLParser::OpenForm(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mContextStackPos >= 0, kInvalidTagStackPos);
|
||||
PRBool result=mSink->OpenForm(aNode);
|
||||
mContextStack[mContextStackPos++]=(eHTMLTags)aNode.GetNodeType();
|
||||
return result;
|
||||
if(mHasOpenForm)
|
||||
CloseForm(aNode);
|
||||
mHasOpenForm=PR_TRUE;
|
||||
return mSink->OpenForm(aNode);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1099,9 +1080,11 @@ PRBool nsHTMLParser::OpenForm(const nsIParserNode& aNode){
|
|||
* @return TRUE if ok, FALSE if error
|
||||
*/
|
||||
PRBool nsHTMLParser::CloseForm(const nsIParserNode& aNode){
|
||||
NS_PRECONDITION(mContextStackPos > 0, kInvalidTagStackPos);
|
||||
PRBool result=mSink->CloseContainer(aNode);
|
||||
mContextStack[--mContextStackPos]=eHTMLTag_unknown;
|
||||
PRBool result=PR_TRUE;
|
||||
if(mHasOpenForm) {
|
||||
mHasOpenForm=PR_FALSE;
|
||||
result=mSink->CloseForm(aNode);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1230,12 +1213,12 @@ PRBool nsHTMLParser::CloseContainersTo(PRInt32 anIndex){
|
|||
PRBool result=PR_TRUE;
|
||||
|
||||
nsAutoString empty;
|
||||
CHTMLToken aToken(empty);
|
||||
CEndToken aToken(empty);
|
||||
nsCParserNode theNode(&aToken);
|
||||
|
||||
if((anIndex<mContextStackPos) && (anIndex>=0)) {
|
||||
while(mContextStackPos>anIndex) {
|
||||
aToken.SetHTMLTag(mContextStack[mContextStackPos-1]);
|
||||
aToken.SetHTMLTag((eHTMLTags)mContextStack[mContextStackPos-1]);
|
||||
result=CloseContainer(theNode);
|
||||
}
|
||||
}
|
||||
|
@ -1287,7 +1270,7 @@ PRBool nsHTMLParser::CloseTopmostContainer(){
|
|||
|
||||
nsAutoString empty;
|
||||
CEndToken aToken(empty);
|
||||
aToken.SetHTMLTag(mContextStack[mContextStackPos-1]);
|
||||
aToken.SetHTMLTag((eHTMLTags)mContextStack[mContextStackPos-1]);
|
||||
nsCParserNode theNode(&aToken);
|
||||
|
||||
return CloseContainer(theNode);
|
||||
|
@ -1323,14 +1306,17 @@ PRBool nsHTMLParser::CreateContextStackFor(PRInt32 aChildTag){
|
|||
PRBool result=PR_FALSE;
|
||||
PRInt32 pos=0;
|
||||
PRInt32 cnt=0;
|
||||
PRInt32 theTop=GetTopNode();
|
||||
|
||||
if(PR_TRUE==mDTD->ForwardPropagate(theVector,GetTopNode(),aChildTag)){
|
||||
if(PR_TRUE==mDTD->ForwardPropagate(theVector,theTop,aChildTag)){
|
||||
//add code here to build up context stack based on forward propagated context vector...
|
||||
pos=0;
|
||||
cnt=theVector.Length()-1;
|
||||
result=PRBool(mContextStack[mContextStackPos-1]==theVector[cnt]);
|
||||
}
|
||||
else if(PR_TRUE==mDTD->BackwardPropagate(theVector,eHTMLTag_html,aChildTag)) {
|
||||
else if(PR_TRUE==mDTD->BackwardPropagate(theVector,theTop,aChildTag)) {
|
||||
if(theTop!=eHTMLTag_html)
|
||||
mDTD->BackwardPropagate(theVector,eHTMLTag_html,theTop);
|
||||
|
||||
//propagation worked, so pop unwanted containers, push new ones, then exit...
|
||||
pos=0;
|
||||
|
|
|
@ -87,13 +87,15 @@ friend class CTokenHandler;
|
|||
virtual PRBool Parse(nsIURL* aURL);
|
||||
virtual PRBool Parse(nsIURL* aURL,eParseMode aMode);
|
||||
virtual PRBool ResumeParse();
|
||||
virtual PRInt32 GetStack(PRInt32* aStackPtr);
|
||||
virtual PRBool HasOpenForm() const;
|
||||
|
||||
|
||||
PRBool HandleStartToken(CToken* aToken);
|
||||
PRBool HandleDefaultStartToken(CToken* aToken,eHTMLTags aChildTag,nsCParserNode& aNode);
|
||||
PRBool HandleEndToken(CToken* aToken);
|
||||
PRBool HandleEntityToken(CToken* aToken);
|
||||
PRBool HandleCommentToken(CToken* aToken);
|
||||
PRBool HandleSimpleContentToken(CToken* aToken);
|
||||
PRBool HandleSkippedContentToken(CToken* aToken);
|
||||
PRBool HandleAttributeToken(CToken* aToken);
|
||||
PRBool HandleScriptToken(CToken* aToken);
|
||||
|
@ -140,12 +142,12 @@ friend class CTokenHandler;
|
|||
PRInt32 GetTopmostIndex(eHTMLTags aTag) const;
|
||||
PRBool ReduceContextStackFor(PRInt32 aChildTag);
|
||||
PRBool CreateContextStackFor(PRInt32 aChildTag);
|
||||
PRBool HandleDefaultStartToken(CToken* aToken,eHTMLTags aTag,nsCParserNode& aNode);
|
||||
|
||||
nsIHTMLContentSink* mSink;
|
||||
CTokenizer* mTokenizer;
|
||||
|
||||
eHTMLTags mContextStack[50];
|
||||
// eHTMLTags mContextStack[50];
|
||||
PRInt32 mContextStack[50];
|
||||
PRInt32 mContextStackPos;
|
||||
|
||||
CTokenHandler* mTokenHandlers[100];
|
||||
|
@ -154,6 +156,7 @@ friend class CTokenHandler;
|
|||
|
||||
nsIDTD* mDTD;
|
||||
eParseMode mParseMode;
|
||||
PRBool mHasOpenForm;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -547,6 +547,7 @@ PRInt32 CTextToken::Consume(PRUnichar aChar, CScanner& aScanner) {
|
|||
*------------------------------------------------------*/
|
||||
CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) {
|
||||
mOrdinalValue=eToken_comment;
|
||||
mTagType=eHTMLTag_comment;
|
||||
}
|
||||
|
||||
/**-------------------------------------------------------
|
||||
|
@ -561,11 +562,11 @@ CCommentToken::CCommentToken(const nsString& aName) : CHTMLToken(aName) {
|
|||
PRInt32 CCommentToken::Consume(PRUnichar aChar, CScanner& aScanner) {
|
||||
|
||||
PRUnichar ch,ch2;
|
||||
PRInt32 result;
|
||||
|
||||
static nsAutoString terminals(">");
|
||||
|
||||
aScanner.GetChar(ch);
|
||||
PRInt32 result=aScanner.GetChar(ch);
|
||||
mTextValue="<!";
|
||||
if(kMinus==ch) {
|
||||
aScanner.GetChar(ch2);
|
||||
|
@ -1285,7 +1286,7 @@ eHTMLTags DetermineHTMLTagType(const nsString& aString)
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
const char* GetTagName(eHTMLTags aTag) {
|
||||
const char* GetTagName(PRInt32 aTag) {
|
||||
const char* result=0;
|
||||
PRInt32 cnt=sizeof(gHTMLTagTable)/sizeof(HTMLTagEntry);
|
||||
|
||||
|
|
|
@ -58,9 +58,10 @@ enum eHTMLTags
|
|||
eHTMLTag_blink, eHTMLTag_blockquote, eHTMLTag_body, eHTMLTag_br,
|
||||
eHTMLTag_button, eHTMLTag_caption, eHTMLTag_center,
|
||||
eHTMLTag_certificate, eHTMLTag_cite,
|
||||
eHTMLTag_code, eHTMLTag_col, eHTMLTag_colgroup, eHTMLTag_dd,
|
||||
eHTMLTag_del, eHTMLTag_dfn, eHTMLTag_div, eHTMLTag_dir,
|
||||
eHTMLTag_dl, eHTMLTag_dt, eHTMLTag_em, eHTMLTag_embed,
|
||||
eHTMLTag_code, eHTMLTag_col, eHTMLTag_colgroup, eHTMLTag_comment,
|
||||
eHTMLTag_dd, eHTMLTag_del, eHTMLTag_dfn, eHTMLTag_div,
|
||||
eHTMLTag_dir, eHTMLTag_dl, eHTMLTag_dt,
|
||||
eHTMLTag_em, eHTMLTag_embed,
|
||||
eHTMLTag_fieldset, eHTMLTag_font, eHTMLTag_footer,
|
||||
eHTMLTag_form, eHTMLTag_frame, eHTMLTag_frameset,
|
||||
eHTMLTag_h1, eHTMLTag_h2, eHTMLTag_h3, eHTMLTag_h4,
|
||||
|
@ -77,7 +78,7 @@ enum eHTMLTags
|
|||
eHTMLTag_option, eHTMLTag_paragraph, eHTMLTag_param, eHTMLTag_plaintext,
|
||||
eHTMLTag_pre, eHTMLTag_quotation, eHTMLTag_strike, eHTMLTag_samp,
|
||||
eHTMLTag_script, eHTMLTag_select,
|
||||
eHTMLTag_server, eHTMLTag_small,
|
||||
eHTMLTag_server, eHTMLTag_small,
|
||||
eHTMLTag_spacer, eHTMLTag_span,
|
||||
eHTMLTag_strong, eHTMLTag_style, eHTMLTag_sub, eHTMLTag_sup,
|
||||
eHTMLTag_table, eHTMLTag_tbody, eHTMLTag_td,
|
||||
|
@ -113,7 +114,7 @@ PRInt32 ConsumeAttributeText(PRUnichar aChar,nsString& aString,CScanner&
|
|||
PRInt32 FindEntityIndex(const char* aBuffer,PRInt32 aBufLen=-1);
|
||||
eHTMLTags DetermineHTMLTagType(const nsString& aString);
|
||||
eHTMLTokenTypes DetermineTokenType(const nsString& aString);
|
||||
const char* GetTagName(eHTMLTags aTag);
|
||||
const char* GetTagName(PRInt32 aTag);
|
||||
|
||||
|
||||
/** -----------------------------------------------------
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
{0xaa, 0xda, 0x00, 0x80, 0x5f, 0x8a, 0x3e, 0x14}}
|
||||
|
||||
|
||||
class nsIParser;
|
||||
|
||||
class nsIDTD : public nsISupports {
|
||||
|
||||
|
@ -49,7 +50,18 @@ class nsIDTD : public nsISupports {
|
|||
* @param aChild -- tag enum of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const =0;
|
||||
virtual PRBool CanContain(PRInt32 aParent,PRInt32 aChild) const=0;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
* of one type can contain a tag of another type.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- tag enum of parent container
|
||||
* @param aChild -- tag enum of child container
|
||||
* @return PR_TRUE if parent can contain child
|
||||
*/
|
||||
virtual void SetParser(nsIParser* aParser)=0;
|
||||
|
||||
/**
|
||||
* This method is called to determine whether or not a tag
|
||||
|
|
|
@ -54,6 +54,8 @@ class nsIParser : public nsISupports {
|
|||
virtual nsIContentSink* SetContentSink(nsIContentSink* aContentSink)=0;
|
||||
virtual PRBool Parse(nsIURL* aURL)=0;
|
||||
virtual PRBool ResumeParse()=0;
|
||||
virtual PRInt32 GetStack(PRInt32* aStackPtr)=0;
|
||||
virtual PRBool HasOpenForm() const=0;
|
||||
};
|
||||
|
||||
extern NS_HTMLPARS nsresult NS_NewHTMLParser(nsIParser** aInstancePtrResult);
|
||||
|
|
|
@ -48,13 +48,13 @@ class CToken;
|
|||
class ITokenizerDelegate {
|
||||
public:
|
||||
|
||||
virtual PRBool WillTokenize()=0;
|
||||
virtual PRBool DidTokenize()=0;
|
||||
virtual PRBool WillTokenize()=0;
|
||||
virtual PRBool DidTokenize()=0;
|
||||
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode)=0;
|
||||
virtual CToken* GetToken(CScanner& aScanner,PRInt32& anErrorCode)=0;
|
||||
virtual PRBool WillAddToken(CToken& aToken)=0;
|
||||
|
||||
virtual eParseMode GetParseMode() const=0;
|
||||
virtual eParseMode GetParseMode(void) const=0;
|
||||
virtual nsIDTD* GetDTD(void) const=0;
|
||||
};
|
||||
|
||||
|
|
|
@ -40,35 +40,34 @@ enum eParseMode {
|
|||
eParseMode_other
|
||||
};
|
||||
|
||||
const PRInt32 kNotFound = -1;
|
||||
const PRInt32 kNoError = 0;
|
||||
const PRInt32 kEOF = 1000;
|
||||
const PRInt32 kNotFound = -1;
|
||||
const PRInt32 kNoError = 0;
|
||||
const PRInt32 kEOF = 1000000L;
|
||||
|
||||
const PRUint32 kNewLine = '\n';
|
||||
const PRUint32 kCR = '\r';
|
||||
const PRUint32 kLF = '\n';
|
||||
const PRUint32 kTab = '\t';
|
||||
const PRUint32 kSpace = ' ';
|
||||
const PRUint32 kQuote = '"';
|
||||
const PRUint32 kApostrophe = '\'';
|
||||
const PRUint32 kLessThan = '<';
|
||||
const PRUint32 kGreaterThan = '>';
|
||||
const PRUint32 kAmpersand = '&';
|
||||
const PRUint32 kNullPRInt8 = '\0';
|
||||
const PRUint32 kForwardSlash = '/';
|
||||
const PRUint32 kEqual = '=';
|
||||
const PRUint32 kMinus = '-';
|
||||
const PRUint32 kPlus = '+';
|
||||
const PRUint32 kExclamation = '!';
|
||||
const PRUint32 kSemicolon = ';';
|
||||
const PRUint32 kHashsign = '#';
|
||||
const PRUint32 kCR = '\r';
|
||||
const PRUint32 kLF = '\n';
|
||||
const PRUint32 kTab = '\t';
|
||||
const PRUint32 kSpace = ' ';
|
||||
const PRUint32 kQuote = '"';
|
||||
const PRUint32 kApostrophe = '\'';
|
||||
const PRUint32 kLessThan = '<';
|
||||
const PRUint32 kGreaterThan = '>';
|
||||
const PRUint32 kAmpersand = '&';
|
||||
const PRUint32 kForwardSlash = '/';
|
||||
const PRUint32 kEqual = '=';
|
||||
const PRUint32 kMinus = '-';
|
||||
const PRUint32 kPlus = '+';
|
||||
const PRUint32 kExclamation = '!';
|
||||
const PRUint32 kSemicolon = ';';
|
||||
const PRUint32 kHashsign = '#';
|
||||
const PRUint32 kAsterisk = '*';
|
||||
const PRUint32 kUnderbar = '_';
|
||||
const PRUint32 kComma = ',';
|
||||
const PRUint32 kLeftParen = '(';
|
||||
const PRUint32 kRightParen = ')';
|
||||
const PRUint32 kLeftBrace = '{';
|
||||
const PRUint32 kRightBrace = '}';
|
||||
const PRUint32 kUnderbar = '_';
|
||||
const PRUint32 kComma = ',';
|
||||
const PRUint32 kLeftParen = '(';
|
||||
const PRUint32 kRightParen = ')';
|
||||
const PRUint32 kLeftBrace = '{';
|
||||
const PRUint32 kRightBrace = '}';
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -325,7 +325,7 @@ CWhitespaceTokenHandler::~CWhitespaceTokenHandler(){
|
|||
PRBool CWhitespaceTokenHandler::operator()(CToken* aToken,nsHTMLParser* aParser){
|
||||
NS_ASSERTION(0!=aParser,kNullParserGiven);
|
||||
if(aParser){
|
||||
return aParser->HandleSimpleContentToken(aToken);
|
||||
return aParser->HandleStartToken(aToken);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
@ -375,7 +375,7 @@ CNewlineTokenHandler::~CNewlineTokenHandler(){
|
|||
PRBool CNewlineTokenHandler::operator()(CToken* aToken,nsHTMLParser* aParser){
|
||||
NS_ASSERTION(0!=aParser,kNullParserGiven);
|
||||
if(aParser){
|
||||
return aParser->HandleSimpleContentToken(aToken);
|
||||
return aParser->HandleStartToken(aToken);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
@ -424,7 +424,7 @@ CTextTokenHandler::~CTextTokenHandler(){
|
|||
PRBool CTextTokenHandler::operator()(CToken* aToken,nsHTMLParser* aParser){
|
||||
NS_ASSERTION(0!=aParser,kNullParserGiven);
|
||||
if(aParser){
|
||||
return aParser->HandleSimpleContentToken(aToken);
|
||||
return aParser->HandleStartToken(aToken);
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче