final features for parsing engine (WIP); lots of bug fixes
This commit is contained in:
Родитель
078c814261
Коммит
0c01b8c899
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -296,17 +296,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This is called to determine if the given parent can omit the
|
||||
* given child (end tag).
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- tag type of parent
|
||||
* @param aChild -- tag type of child
|
||||
* @return PR_TRUE if given tag can contain omit child (end tag)
|
||||
*/
|
||||
virtual PRBool CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
|
@ -405,7 +394,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
nsresult HandleEndToken(CToken* aToken);
|
||||
nsresult HandleEntityToken(CToken* aToken);
|
||||
nsresult HandleCommentToken(CToken* aToken);
|
||||
nsresult HandleSkippedContentToken(CToken* aToken);
|
||||
nsresult HandleAttributeToken(CToken* aToken);
|
||||
nsresult HandleScriptToken(nsCParserNode& aNode);
|
||||
nsresult HandleStyleToken(CToken* aToken);
|
||||
|
@ -431,7 +419,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
nsresult OpenForm(const nsIParserNode& aNode);
|
||||
nsresult OpenMap(const nsIParserNode& aNode);
|
||||
nsresult OpenFrameset(const nsIParserNode& aNode);
|
||||
nsresult OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack);
|
||||
nsresult OpenContainer(const nsIParserNode& aNode,PRBool aClosedByStartTag);
|
||||
|
||||
/**
|
||||
* The next set of methods close the given HTML element.
|
||||
|
@ -446,7 +434,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
nsresult CloseForm(const nsIParserNode& aNode);
|
||||
nsresult CloseMap(const nsIParserNode& aNode);
|
||||
nsresult CloseFrameset(const nsIParserNode& aNode);
|
||||
nsresult CloseContainer(const nsIParserNode& aNode,eHTMLTags anActualTag,PRBool aUpdateStyles);
|
||||
nsresult CloseContainer(const nsIParserNode& aNode,eHTMLTags anActualTag,PRBool aClosedByStartTag);
|
||||
|
||||
/**
|
||||
* The special purpose methods automatically close
|
||||
|
@ -455,8 +443,8 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* @return error code - 0 if all went well.
|
||||
*/
|
||||
nsresult CloseTopmostContainer();
|
||||
nsresult CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles);
|
||||
nsresult CloseContainersTo(PRInt32 anIndex,eHTMLTags aTag,PRBool aUpdateStyles);
|
||||
nsresult CloseContainersTo(eHTMLTags aTag,PRBool aClosedByStartTag);
|
||||
nsresult CloseContainersTo(PRInt32 anIndex,eHTMLTags aTag,PRBool aClosedByStartTag);
|
||||
|
||||
/**
|
||||
* Causes leaf to be added to sink at current vector pos.
|
||||
|
@ -465,7 +453,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* @return error code - 0 if all went well.
|
||||
*/
|
||||
nsresult AddLeaf(const nsIParserNode& aNode);
|
||||
nsresult AddHeadLeaf(const nsIParserNode& aNode);
|
||||
nsresult AddHeadLeaf(nsIParserNode& aNode);
|
||||
|
||||
/**
|
||||
* Causes auto-closures of context vector stack in order to find a
|
||||
|
@ -495,17 +483,16 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* @param aTag -- represents the transient style tag to be handled.
|
||||
* @return error code -- usually 0
|
||||
*/
|
||||
nsresult OpenTransientStyles(eHTMLTags aTag);
|
||||
nsresult CloseTransientStyles(eHTMLTags aTag);
|
||||
nsresult OpenTransientStyles(eHTMLTags aChildTag);
|
||||
nsresult CloseTransientStyles(eHTMLTags aChildTag);
|
||||
nsresult UpdateStyleStackForOpenTag(eHTMLTags aTag,eHTMLTags aActualTag);
|
||||
nsresult UpdateStyleStackForCloseTag(eHTMLTags aTag,eHTMLTags aActualTag);
|
||||
PRBool CanContainStyles(eHTMLTags aTag) const;
|
||||
|
||||
nsresult DoFragment(PRBool aFlag);
|
||||
|
||||
protected:
|
||||
|
||||
nsresult CollectAttributes(nsCParserNode& aNode,PRInt32 aCount);
|
||||
nsresult CollectAttributes(nsCParserNode& aNode,eHTMLTags aTag,PRInt32 aCount);
|
||||
nsresult CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount);
|
||||
nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsCParserNode& aNode);
|
||||
nsresult DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag);
|
||||
|
@ -531,8 +518,10 @@ protected:
|
|||
nsParser* mParser;
|
||||
nsITokenizer* mTokenizer;
|
||||
nsDeque mMisplacedContent;
|
||||
nsDeque mSkippedContent;
|
||||
PRBool mHasOpenScript;
|
||||
PRBool mSaveBadTokens;
|
||||
eHTMLTags mSkipTarget;
|
||||
|
||||
PRUint32 mComputedCRC32;
|
||||
PRUint32 mExpectedCRC32;
|
||||
|
|
|
@ -254,20 +254,6 @@ nsresult COtherDTD::HandleCommentToken(CToken* aToken) {
|
|||
return CNavDTD::HandleCommentToken(aToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a skippedcontent token has
|
||||
* been encountered in the parse process. After verifying
|
||||
* that the topmost container can contain text, we call
|
||||
* AddLeaf to store this token in the top container.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- next (start) token to be handled
|
||||
* @return PR_TRUE if all went well; PR_FALSE if error occured
|
||||
*/
|
||||
nsresult COtherDTD::HandleSkippedContentToken(CToken* aToken) {
|
||||
return CNavDTD::HandleSkippedContentToken(aToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an attribute token has been
|
||||
* encountered in the parse process. This is an error, since
|
||||
|
@ -334,19 +320,6 @@ PRBool COtherDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* ENDtag can be omitted. Admittedly,this is a gross simplification.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
PRBool COtherDTD::CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild) const {
|
||||
return CNavDTD::CanOmitEndTag(aParent,aChild);
|
||||
}
|
||||
|
||||
|
||||
/*********************************************
|
||||
Here comes code that handles the interface
|
||||
to our content sink.
|
||||
|
|
|
@ -121,17 +121,6 @@ class COtherDTD : public CNavDTD {
|
|||
*/
|
||||
virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag can contain newlines. Most do not.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- tag type of parent
|
||||
* @param aChild -- tag type of child
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
virtual PRBool CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This method gets called when a start token has been consumed and needs
|
||||
* to be handled (possibly added to content model via sink).
|
||||
|
@ -181,15 +170,6 @@ class COtherDTD : public CNavDTD {
|
|||
*/
|
||||
nsresult HandleCommentToken(CToken* aToken);
|
||||
|
||||
/**
|
||||
* This method gets called when a skipped-content token has been consumed and needs
|
||||
* to be handled (possibly added to content model via sink).
|
||||
* @update gess5/11/98
|
||||
* @param aToken is the skipped-content token to be handled
|
||||
* @return TRUE if the token was handled.
|
||||
*/
|
||||
nsresult HandleSkippedContentToken(CToken* aToken);
|
||||
|
||||
/**
|
||||
* This method gets called when an attribute token has been consumed and needs
|
||||
* to be handled (possibly added to content model via sink).
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
#include "nsDTDUtils.h"
|
||||
#include "CNavDTD.h"
|
||||
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIElementObserver.h"
|
||||
|
||||
static NS_DEFINE_IID(kIObserverServiceIID, NS_IOBSERVERSERVICE_IID);
|
||||
static NS_DEFINE_IID(kObserverServiceCID, NS_OBSERVERSERVICE_CID);
|
||||
|
@ -51,6 +51,8 @@ nsEntryStack::nsEntryStack() {
|
|||
nsEntryStack::~nsEntryStack() {
|
||||
if(mEntries)
|
||||
delete [] mEntries;
|
||||
mCount=mCapacity=0;
|
||||
mEntries=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,7 +184,6 @@ PRInt32 nsEntryStack::GetTopmostIndexOf(eHTMLTags aTag) const {
|
|||
/**
|
||||
*
|
||||
* @update gess9/10/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
nsDTDContext::nsDTDContext() : mStack(), mSkipped(0), mStyles(0) {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -194,7 +195,6 @@ nsDTDContext::nsDTDContext() : mStack(), mSkipped(0), mStyles(0) {
|
|||
/**
|
||||
*
|
||||
* @update gess9/10/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
nsDTDContext::~nsDTDContext() {
|
||||
}
|
||||
|
@ -202,16 +202,14 @@ nsDTDContext::~nsDTDContext() {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98, harishd 04/04/99
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
PRInt32 nsDTDContext::GetCount(void) {
|
||||
return mStack.GetSize();
|
||||
return mStack.GetCount();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/9/98, harishd 04/04/99
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
void nsDTDContext::Push(eHTMLTags aTag) {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -224,7 +222,6 @@ void nsDTDContext::Push(eHTMLTags aTag) {
|
|||
|
||||
/**
|
||||
* @update gess7/9/98, harishd 04/04/99
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::Pop() {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -232,6 +229,14 @@ eHTMLTags nsDTDContext::Pop() {
|
|||
mTags[mStack.mCount-1]=eHTMLTag_unknown;
|
||||
#endif
|
||||
|
||||
nsEntryStack* theStyles=0;
|
||||
nsTagEntry& theEntry=mStack.EntryAt(mStack.mCount-1);
|
||||
PRInt32 theIndex=theEntry.mStyleIndex;
|
||||
if(-1<theIndex){
|
||||
theStyles=(nsEntryStack*)mStyles.ObjectAt(theIndex);
|
||||
delete theStyles;
|
||||
}
|
||||
|
||||
eHTMLTags result=mStack.Pop();
|
||||
return result;
|
||||
}
|
||||
|
@ -239,7 +244,6 @@ eHTMLTags nsDTDContext::Pop() {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::First() const {
|
||||
return mStack.First();
|
||||
|
@ -248,7 +252,6 @@ eHTMLTags nsDTDContext::First() const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::TagAt(PRInt32 anIndex) const {
|
||||
return mStack.TagAt(anIndex);
|
||||
|
@ -258,7 +261,6 @@ eHTMLTags nsDTDContext::TagAt(PRInt32 anIndex) const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::operator[](PRInt32 anIndex) const {
|
||||
return mStack[anIndex];
|
||||
|
@ -267,7 +269,6 @@ eHTMLTags nsDTDContext::operator[](PRInt32 anIndex) const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::Last() const {
|
||||
return mStack.Last();
|
||||
|
@ -276,12 +277,12 @@ eHTMLTags nsDTDContext::Last() const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
nsEntryStack* nsDTDContext::GetStyles(void) const {
|
||||
nsEntryStack* nsDTDContext::GetStylesAt(PRUint32 anIndex) const {
|
||||
nsEntryStack* result=0;
|
||||
if(0<mStack.mCount){
|
||||
PRInt32 theIndex=mStack.mEntries[mStack.mCount-1].mStyleIndex;
|
||||
if(anIndex<mStack.mCount){
|
||||
nsTagEntry& theEntry=mStack.EntryAt(anIndex);
|
||||
PRInt32 theIndex=theEntry.mStyleIndex;
|
||||
if(-1<theIndex){
|
||||
result=(nsEntryStack*)mStyles.ObjectAt(theIndex);
|
||||
}
|
||||
|
@ -289,6 +290,46 @@ nsEntryStack* nsDTDContext::GetStyles(void) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 04/28/99
|
||||
*/
|
||||
void nsDTDContext::PushStyle(eHTMLTags aTag){
|
||||
|
||||
nsTagEntry& theEntry=mStack.EntryAt(mStack.mCount-1);
|
||||
//ok, now go get the right tokenbank deque...
|
||||
nsEntryStack* theStack=0;
|
||||
if(-1<theEntry.mStyleIndex)
|
||||
theStack=(nsEntryStack*)mStyles.ObjectAt(theEntry.mStyleIndex);
|
||||
if(!theStack){
|
||||
//time to make a databank for this element...
|
||||
theStack=new nsEntryStack();
|
||||
mStyles.Push(theStack);
|
||||
theEntry.mStyleIndex=mStyles.GetSize()-1;
|
||||
}
|
||||
if(theStack){
|
||||
theStack->Push(aTag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 04/28/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::PopStyle(void){
|
||||
eHTMLTags result=eHTMLTag_unknown;
|
||||
nsTagEntry& theEntry=mStack.EntryAt(mStack.mCount-1);
|
||||
//ok, now go get the right tokenbank deque...
|
||||
nsEntryStack* theStack=0;
|
||||
if(-1<theEntry.mStyleIndex)
|
||||
theStack=(nsEntryStack*)mStyles.ObjectAt(theEntry.mStyleIndex);
|
||||
if(theStack){
|
||||
result=theStack->Pop();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update harishd 04/04/99
|
||||
|
@ -296,7 +337,7 @@ nsEntryStack* nsDTDContext::GetStyles(void) const {
|
|||
*/
|
||||
void nsDTDContext::SaveToken(CToken* aToken, PRInt32 aID)
|
||||
{
|
||||
NS_PRECONDITION(aID <= mStack.GetSize() && aID > -1,"Out of bounds");
|
||||
NS_PRECONDITION(aID <= mStack.GetCount() && aID > -1,"Out of bounds");
|
||||
|
||||
if(aToken) {
|
||||
nsTagEntry& theEntry=mStack.EntryAt(aID);
|
||||
|
@ -321,9 +362,9 @@ void nsDTDContext::SaveToken(CToken* aToken, PRInt32 aID)
|
|||
*/
|
||||
CToken* nsDTDContext::RestoreTokenFrom(PRInt32 aID)
|
||||
{
|
||||
NS_PRECONDITION(aID <= mStack.GetSize() && aID > -1,"Out of bounds");
|
||||
NS_PRECONDITION(aID <= mStack.GetCount() && aID > -1,"Out of bounds");
|
||||
CToken* result=0;
|
||||
if(0<mStack.GetSize()) {
|
||||
if(0<mStack.GetCount()) {
|
||||
nsTagEntry theEntry=mStack.EntryAt(aID);
|
||||
nsDeque* theDeque=(nsDeque*)mSkipped.ObjectAt(theEntry.mBankIndex);
|
||||
if(theDeque){
|
||||
|
@ -340,7 +381,7 @@ CToken* nsDTDContext::RestoreTokenFrom(PRInt32 aID)
|
|||
*/
|
||||
PRInt32 nsDTDContext::TokenCountAt(PRInt32 aID)
|
||||
{
|
||||
NS_PRECONDITION(aID <= mStack.GetSize(),"Out of bounds");
|
||||
NS_PRECONDITION(aID <= mStack.GetCount(),"Out of bounds");
|
||||
|
||||
nsTagEntry theEntry=mStack.EntryAt(aID);
|
||||
nsDeque* theDeque=(nsDeque*)mSkipped.ObjectAt(theEntry.mBankIndex);
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <fstream.h>
|
||||
#include "nsITokenizer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIElementObserver.h"
|
||||
|
||||
/***************************************************************
|
||||
Before digging into the NavDTD, we'll define a helper
|
||||
|
@ -79,7 +80,7 @@ public:
|
|||
eHTMLTags operator[](PRUint32 anIndex) const;
|
||||
eHTMLTags Last() const;
|
||||
void Empty(void);
|
||||
PRInt32 GetSize(void) const {return mCount;}
|
||||
PRInt32 GetCount(void) const {return mCount;}
|
||||
|
||||
nsTagEntry* mEntries;
|
||||
PRUint32 mCount;
|
||||
|
@ -106,7 +107,9 @@ public:
|
|||
eHTMLTags Last() const;
|
||||
void Empty(void);
|
||||
PRInt32 GetCount(void);
|
||||
nsEntryStack* GetStyles(void) const;
|
||||
nsEntryStack* GetStylesAt(PRUint32 anIndex) const;
|
||||
void PushStyle(eHTMLTags aTag);
|
||||
eHTMLTags PopStyle(void);
|
||||
|
||||
void SaveToken(CToken* aToken, PRInt32 aID);
|
||||
CToken* RestoreTokenFrom(PRInt32 aID);
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -46,13 +46,14 @@ public:
|
|||
mTagList=aTagList;
|
||||
}
|
||||
|
||||
PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack);
|
||||
PRInt32 GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset);
|
||||
PRBool Contains(eHTMLTags aTag);
|
||||
PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack);
|
||||
PRInt32 GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset);
|
||||
PRBool Contains(eHTMLTags aTag);
|
||||
eHTMLTags GetTagAt(PRUint32 anIndex) const;
|
||||
|
||||
eHTMLTags mTags[5];
|
||||
eHTMLTags* mTagList;
|
||||
int mCount;
|
||||
PRUint32 mCount;
|
||||
};
|
||||
|
||||
//*********************************************************************************************
|
||||
|
@ -68,11 +69,13 @@ public:
|
|||
*/
|
||||
struct nsHTMLElement {
|
||||
|
||||
static PRBool IsContainerType(eHTMLTags aTag,int aType);
|
||||
static void DebugDumpMembership(const char* aFilename);
|
||||
static void DebugDumpContainment(const char* aFilename,const char* aTitle);
|
||||
static void DebugDumpContainType(const char* aFilename);
|
||||
|
||||
static PRBool IsBlockElement(eHTMLTags aTag);
|
||||
static PRBool IsInlineElement(eHTMLTags aTag);
|
||||
static PRBool IsFlowElement(eHTMLTags aTag);
|
||||
static PRBool IsBlockEntity(eHTMLTags aTag);
|
||||
static PRBool IsInlineEntity(eHTMLTags aTag);
|
||||
static PRBool IsFlowEntity(eHTMLTags aTag);
|
||||
static PRBool IsBlockCloser(eHTMLTags aTag);
|
||||
|
||||
CTagList* GetRootTags(void) const {return mRootNodes;}
|
||||
|
@ -80,6 +83,7 @@ struct nsHTMLElement {
|
|||
CTagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;}
|
||||
CTagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
|
||||
CTagList* GetSynonymousTags(void) const {return mSynonymousTags;}
|
||||
eHTMLTags GetCloseTargetForEndTag(nsEntryStack& aTagStack,PRInt32 anIndex) const;
|
||||
|
||||
CTagList* GetSpecialChildren(void) const {return mSpecialKids;}
|
||||
CTagList* GetSpecialParents(void) const {return mSpecialParents;}
|
||||
|
@ -89,9 +93,10 @@ struct nsHTMLElement {
|
|||
|
||||
eHTMLTags GetTag(void) const {return mTagID;}
|
||||
PRBool CanContain(eHTMLTags aChild) const;
|
||||
PRBool CanExclude(eHTMLTags aChild) const;
|
||||
PRBool CanOmitStartTag(eHTMLTags aChild) const;
|
||||
PRBool CanOmitEndTag(eHTMLTags aParent) const;
|
||||
PRBool CanContainSelf() const;
|
||||
PRBool CanOmitEndTag(void) const;
|
||||
PRBool CanContainSelf(void) const;
|
||||
PRBool HasSpecialProperty(PRInt32 aProperty) const;
|
||||
PRBool SectionContains(eHTMLTags aTag,PRBool allowDepthSearch);
|
||||
|
||||
|
@ -120,6 +125,7 @@ struct nsHTMLElement {
|
|||
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
|
||||
eHTMLTags mSkipTarget; //If set, then we skip all content until this tag is seen
|
||||
|
@ -134,7 +140,10 @@ static const int kDiscardTag = 0x0001; //tells us to toss this tag
|
|||
static const int kOmitEndTag = 0x0002; //safely ignore end tag
|
||||
static const int kLegalOpen = 0x0004; //Lets BODY, TITLE, SCRIPT to reopen
|
||||
static const int kOmitWS = 0x0008; //If set, the tag can omit all ws and newlines
|
||||
static const int kBadContentWatch = 0x0014; //Used in handling illegal contents
|
||||
static const int kNoPropagate = 0x0010; //If set, this tag won't propagate as a child
|
||||
static const int kBadContentWatch = 0x0020;
|
||||
static const int kNoStyleLeaksIn = 0x0040;
|
||||
static const int kNoStyleLeaksOut = 0x0080;
|
||||
|
||||
//*********************************************************************************************
|
||||
// The following ints define the standard groups of HTML elements...
|
||||
|
@ -150,21 +159,23 @@ static const int kSpecial = 0x0008; // A, IMG, APPLET, OBJECT, FONT,
|
|||
// MAP, Q, SUB, SUP, SPAN, BDO, IFRAME
|
||||
|
||||
static const int kFormControl = 0x0010; // INPUT SELECT TEXTAREA LABEL BUTTON
|
||||
static const int kPreformatted = 0x0011; // PRE
|
||||
static const int kPreExclusion = 0x0012; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT
|
||||
static const int kFontStyle = 0x0014; // TT, I, B, U, S, STRIKE, BIG, SMALL
|
||||
static const int kPhrase = 0x0018; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
|
||||
static const int kHeading = 0x0020; // H1..H6
|
||||
static const int kBlockMisc = 0x0021; // P, DL, DIV, CENTER, NOSCRIPT, NOFRAMES, BLOCKQUOTE
|
||||
// FORM, ISINDEX, HR, TABLE, FIELDSET, ADDRESS
|
||||
static const int kPreformatted = 0x0020; // PRE
|
||||
static const int kPreExclusion = 0x0040; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT
|
||||
static const int kFontStyle = 0x0080; // TT, I, B, U, S, STRIKE, BIG, SMALL, BLINK
|
||||
static const int kPhrase = 0x0100; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
|
||||
static const int kHeading = 0x0200; // H1..H6
|
||||
static const int kBlockMisc = 0x0400; // OBJECT, SCRIPT
|
||||
static const int kBlock = 0x0800; // ADDRESS, BLOCKQUOTE, CENTER, DIV, DL, FIELDSET, FORM,
|
||||
// ISINDEX, HR, NOSCRIPT, NOFRAMES, P, TABLE
|
||||
static const int kList = 0x1000; // UL, OL, DIR, MENU
|
||||
static const int kPCDATA = 0x2000; // just plain text...
|
||||
static const int kSelf = 0x4000; // whatever THIS tag is...
|
||||
static const int kExtensions = 0x8000; // BGSOUND, WBR, NOBR
|
||||
static const int kTable = 0x10000;// TR,TD,THEAD,TBODY,TFOOT,CAPTION,TH
|
||||
|
||||
static const int kList = 0x0024; // UL, OL, DIR, MENU
|
||||
static const int kPCDATA = 0x0028; // just plain text...
|
||||
static const int kSelf = 0x0040; // whatever THIS tag is...
|
||||
|
||||
static const int kInline = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl); // #PCDATA, %fontstyle, %phrase, %special, %formctrl
|
||||
static const int kBlock = (kHeading|kList|kPreformatted|kBlockMisc); // %heading, %list, %preformatted, %blockmisc
|
||||
static const int kFlow = (kBlock|kInline); // %block, %inline
|
||||
static const int kInlineEntity = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl|kExtensions); // #PCDATA, %fontstyle, %phrase, %special, %formctrl
|
||||
static const int kBlockEntity = (kHeading|kList|kPreformatted|kBlock); // %heading, %list, %preformatted, %blockmisc
|
||||
static const int kFlowEntity = (kBlockEntity|kInlineEntity); // %block, %inline
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -101,7 +101,7 @@ NS_IMPL_RELEASE(nsHTMLTokenizer)
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(new CTokenDeallocator()){
|
||||
nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(0){
|
||||
NS_INIT_REFCNT();
|
||||
mDoXMLEmptyTags=PR_FALSE;
|
||||
}
|
||||
|
@ -114,6 +114,10 @@ nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(new CTokenDeall
|
|||
* @return
|
||||
*/
|
||||
nsHTMLTokenizer::~nsHTMLTokenizer(){
|
||||
if(mTokenDeque.GetSize()){
|
||||
CTokenDeallocator theDeallocator;
|
||||
mTokenDeque.ForEach(theDeallocator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -277,10 +281,10 @@ nsresult nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner) {
|
|||
|
||||
case kNotFound:
|
||||
break;
|
||||
|
||||
|
||||
case 0: //preceeds a EOF...
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if(!nsString::IsSpace(theChar)) {
|
||||
nsAutoString temp(theChar);
|
||||
|
@ -411,66 +415,15 @@ nsresult nsHTMLTokenizer::ConsumeAttributes(PRUnichar aChar,CStartToken* aToken,
|
|||
}
|
||||
|
||||
/**
|
||||
* This is a special case method. It's job is to consume
|
||||
* all of the given tag up to an including the end tag.
|
||||
*
|
||||
* @param aChar: last char read
|
||||
* @param aScanner: see nsScanner.h
|
||||
* @param anErrorCode: arg that will hold error condition
|
||||
* @return new token or null
|
||||
*/
|
||||
nsresult nsHTMLTokenizer::ConsumeContentToEndTag(PRUnichar aChar,
|
||||
eHTMLTags aChildTag,
|
||||
nsScanner& aScanner,
|
||||
CToken*& aToken){
|
||||
|
||||
//In the case that we just read the given tag, we should go and
|
||||
//consume all the input until we find a matching end tag.
|
||||
|
||||
nsAutoString endTag("</");
|
||||
endTag.Append(NS_EnumToTag(aChildTag));
|
||||
endTag.Append(">");
|
||||
|
||||
CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
aToken=theRecycler->CreateTokenOfType(eToken_skippedcontent,aChildTag,endTag);
|
||||
return aToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* In the case that we just read the given tag, we should go and
|
||||
* consume all the input until we find a matching end tag.
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult nsHTMLTokenizer::HandleSkippedContent(nsScanner& aScanner,CToken*& aToken) {
|
||||
nsresult nsHTMLTokenizer::ConsumeScriptContent(nsScanner& aScanner,CToken*& aToken) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
eHTMLTags theTag=(eHTMLTags)aToken->GetTypeID();
|
||||
if(eHTMLTag_unknown!=gHTMLElements[theTag].mSkipTarget) {
|
||||
|
||||
//Do special case handling for <script>, <style>, <title> or <textarea>...
|
||||
CToken* skippedToken=0;
|
||||
PRUnichar theChar=0;
|
||||
result=ConsumeContentToEndTag(theChar,gHTMLElements[theTag].mSkipTarget,aScanner,skippedToken);
|
||||
|
||||
CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
AddToken(skippedToken,result,mTokenDeque,theRecycler);
|
||||
|
||||
if(NS_SUCCEEDED(result) && skippedToken){
|
||||
//In the case that we just read a given tag, we should go and
|
||||
//consume all the tag content itself (and throw it all away).
|
||||
|
||||
nsString& theTagStr=skippedToken->GetStringValueXXX();
|
||||
CToken* endtoken=theRecycler->CreateTokenOfType(eToken_end,theTag,theTagStr);
|
||||
if(endtoken){
|
||||
nsAutoString temp;
|
||||
theTagStr.Mid(temp,2,theTagStr.Length()-3);
|
||||
//now strip the leading and trailing delimiters...
|
||||
endtoken->Reinitialize(theTag,temp);
|
||||
AddToken(endtoken,result,mTokenDeque,theRecycler);
|
||||
}
|
||||
} //if
|
||||
} //if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -498,11 +451,18 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
|
|||
result=ConsumeAttributes(aChar,(CStartToken*)aToken,aScanner);
|
||||
}
|
||||
|
||||
//now that that's over with, we have one more problem to solve.
|
||||
//In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
//consume all the content itself.
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
result=HandleSkippedContent(aScanner,aToken);
|
||||
/* Now that that's over with, we have one more problem to solve.
|
||||
In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
consume all the content itself.
|
||||
*/
|
||||
if(NS_SUCCEEDED(result) && (eHTMLTag_script==theTag)) {
|
||||
nsAutoString endTag("</script>");
|
||||
CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
CToken* textToken=theRecycler->CreateTokenOfType(eToken_text,theTag,endTag);
|
||||
result=((CTextToken*)textToken)->ConsumeUntil(0,aScanner,endTag); //tell new token to finish consuming text...
|
||||
AddToken(textToken,result,mTokenDeque,theRecycler);
|
||||
CToken* endToken=theRecycler->CreateTokenOfType(eToken_end,theTag);
|
||||
AddToken(endToken,result,mTokenDeque,theRecycler);
|
||||
}
|
||||
|
||||
//EEEEECCCCKKKK!!!
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual nsresult HandleSkippedContent(nsScanner& aScanner,CToken*& aToken);
|
||||
virtual nsresult ConsumeScriptContent(nsScanner& aScanner,CToken*& aToken);
|
||||
virtual nsresult ConsumeTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeEndTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
|
@ -79,7 +79,6 @@ protected:
|
|||
virtual nsresult ConsumeComment(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeText(const nsString& aString,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeContentToEndTag(PRUnichar aChar,eHTMLTags aChildTag,nsScanner& aScanner,CToken*& aToken);
|
||||
virtual nsresult ConsumeProcessingInstruction(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
|
||||
static void AddToken(CToken*& aToken,nsresult aResult,nsDeque& aDeque,CTokenRecycler* aRecycler);
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "nsHTMLTags.h"
|
||||
#include "nsHTMLEntities.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsStr.h"
|
||||
|
||||
//#define GESS_MACHINE
|
||||
#ifdef GESS_MACHINE
|
||||
|
@ -79,7 +78,6 @@ void CHTMLToken::SetStringValue(const char* name){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* constructor from tag id
|
||||
*
|
||||
|
@ -272,6 +270,19 @@ void CStartToken::DebugDumpSource(ostream& out) {
|
|||
out << ">";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CStartToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="<";
|
||||
anOutputString+=mTextValue;
|
||||
if(!mAttributed)
|
||||
anOutputString+=">";
|
||||
}
|
||||
|
||||
/*
|
||||
* constructor from tag id
|
||||
|
@ -303,7 +314,6 @@ CEndToken::CEndToken(const nsString& aName) : CHTMLToken(aName) {
|
|||
* @return error result
|
||||
*/
|
||||
nsresult CEndToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
||||
|
||||
//if you're here, we've already Consumed the <! chars, and are
|
||||
//ready to Consume the rest of the open tag identifier.
|
||||
//Stop consuming as soon as you see a space or a '>'.
|
||||
|
@ -388,6 +398,19 @@ void CEndToken::DebugDumpSource(ostream& out) {
|
|||
out << "</" << buffer << ">";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CEndToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="</";
|
||||
anOutputString+=mTextValue;
|
||||
anOutputString+=">";
|
||||
}
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
*
|
||||
|
@ -474,6 +497,70 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consume as much clear text from scanner as possible.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aChar -- last char consumed from stream
|
||||
* @param aScanner -- controller of underlying input source
|
||||
* @return error result
|
||||
*/
|
||||
nsresult CTextToken::ConsumeUntil(PRUnichar aChar,nsScanner& aScanner,nsString& aTerminalString){
|
||||
PRBool done=PR_FALSE;
|
||||
nsresult result=NS_OK;
|
||||
nsString temp;
|
||||
PRUnichar theChar;
|
||||
|
||||
//We're going to try a new algorithm here. Rather than scan for the matching
|
||||
//end tag like we used to do, we're now going to scan for whitespace and comments.
|
||||
//If we find either, just eat them. If we find text or a tag, then go to the
|
||||
//target endtag, or the start of another comment.
|
||||
|
||||
static nsAutoString theWhitespace2("\b\t ");
|
||||
|
||||
while((!done) && (NS_OK==result)) {
|
||||
result=aScanner.GetChar(aChar);
|
||||
if((NS_OK==result) && (kLessThan==aChar)) {
|
||||
//we're reading a tag or a comment...
|
||||
result=aScanner.GetChar(theChar);
|
||||
if((NS_OK==result) && (kExclamation==theChar)) {
|
||||
//read a comment...
|
||||
static CCommentToken theComment;
|
||||
result=theComment.Consume(aChar,aScanner);
|
||||
if(NS_OK==result) {
|
||||
//result=aScanner.SkipWhitespace();
|
||||
//temp.Append("<!");
|
||||
temp.Append(theComment.GetStringValueXXX());
|
||||
//temp.Append(">");
|
||||
}
|
||||
} else {
|
||||
//read a tag...
|
||||
temp+=aChar;
|
||||
temp+=theChar;
|
||||
result=aScanner.ReadUntil(temp,kGreaterThan,PR_TRUE);
|
||||
}
|
||||
}
|
||||
else if(0<=theWhitespace2.BinarySearch(aChar)) {
|
||||
static CWhitespaceToken theWS;
|
||||
result=theWS.Consume(aChar,aScanner);
|
||||
if(NS_OK==result) {
|
||||
temp.Append(theWS.GetStringValueXXX());
|
||||
}
|
||||
}
|
||||
else {
|
||||
temp+=aChar;
|
||||
result=aScanner.ReadUntil(temp,kLessThan,PR_FALSE);
|
||||
}
|
||||
nsAutoString theRight;
|
||||
temp.Right(theRight,aTerminalString.Length());
|
||||
done=PRBool(0==theRight.Compare(aTerminalString,PR_TRUE));
|
||||
} //while
|
||||
int len=temp.Length();
|
||||
temp.Truncate(len-aTerminalString.Length());
|
||||
mTextValue=temp;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
*
|
||||
|
@ -759,14 +846,16 @@ nsresult CCommentToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
|||
PRBool theStrictForm=PR_FALSE;
|
||||
nsresult result=(theStrictForm) ? ConsumeStrictComment(aChar,aScanner,mTextValue) : ConsumeComment(aChar,aScanner,mTextValue);
|
||||
|
||||
/*
|
||||
//this change is here to make the editor teams' life easier.
|
||||
//I'm removing the leading and trailing markup...
|
||||
/*
|
||||
|
||||
if(0==mTextValue.Find("<!"))
|
||||
mTextValue.Cut(0,2); //trim off 1st 2 chars...
|
||||
if(kGreaterThan==mTextValue.Last())
|
||||
mTextValue.Truncate(mTextValue.Length()-1); //trim off last char
|
||||
*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -860,21 +949,21 @@ nsresult CNewlineToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
|||
mTextValue=aChar;
|
||||
|
||||
//we already read the \r or \n, let's see what's next!
|
||||
PRUnichar nextChar;
|
||||
nsresult result=aScanner.Peek(nextChar);
|
||||
PRUnichar theChar;
|
||||
nsresult result=aScanner.Peek(theChar);
|
||||
|
||||
if(NS_OK==result) {
|
||||
switch(aChar) {
|
||||
case kNewLine:
|
||||
if(kCR==nextChar) {
|
||||
result=aScanner.GetChar(nextChar);
|
||||
mTextValue+=nextChar;
|
||||
if(kCR==theChar) {
|
||||
result=aScanner.GetChar(theChar);
|
||||
mTextValue+=theChar;
|
||||
}
|
||||
break;
|
||||
case kCR:
|
||||
if(kNewLine==nextChar) {
|
||||
result=aScanner.GetChar(nextChar);
|
||||
mTextValue+=nextChar;
|
||||
if(kNewLine==theChar) {
|
||||
result=aScanner.GetChar(theChar);
|
||||
mTextValue+=theChar;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -968,6 +1057,19 @@ void CAttributeToken::DebugDumpToken(ostream& out) {
|
|||
out << buffer << ": " << mTypeID << endl;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CAttributeToken::GetSource(nsString& anOutputString){
|
||||
anOutputString=mTextKey;
|
||||
anOutputString+="=";
|
||||
anOutputString+=mTextValue;
|
||||
anOutputString+=";";
|
||||
}
|
||||
|
||||
/*
|
||||
* This general purpose method is used when you want to
|
||||
|
@ -997,8 +1099,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
|
|||
PRUnichar ch=aString.Last();
|
||||
if(ch!=aChar)
|
||||
aString+=aChar;
|
||||
// aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' '));
|
||||
aString.StripChars("\r"); //per the HTML spec, ignore linefeeds...
|
||||
//aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' '));
|
||||
aString.StripChars("\r\n"); //per the HTML spec, ignore linefeeds...
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1270,6 +1372,7 @@ const char* CEntityToken::GetClassName(void) {
|
|||
return "&entity";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
|
@ -1439,6 +1542,19 @@ void CEntityToken::DebugDumpSource(ostream& out) {
|
|||
delete[] cp;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CEntityToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="&";
|
||||
anOutputString+=anOutputString;
|
||||
anOutputString+=";";
|
||||
}
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
*
|
||||
|
@ -1591,9 +1707,9 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) {
|
|||
temp+=aChar;
|
||||
result=aScanner.ReadUntil(temp,kLessThan,PR_FALSE);
|
||||
}
|
||||
nsAutoString temp2;
|
||||
temp.Right(temp2,mTextValue.Length());
|
||||
done=PRBool(0==temp2.Compare(mTextValue.GetUnicode(),PR_TRUE,mTextValue.Length()));
|
||||
nsAutoString theRight;
|
||||
temp.Right(theRight,mTextValue.Length());
|
||||
done=PRBool(0==theRight.Compare(mTextValue,PR_TRUE));
|
||||
}
|
||||
int len=temp.Length();
|
||||
temp.Truncate(len-mTextValue.Length());
|
||||
|
@ -1616,6 +1732,16 @@ void CSkippedContentToken::DebugDumpSource(ostream& out) {
|
|||
out<<">";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CSkippedContentToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="$skipped-content";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsHTMLTags.h"
|
||||
#include "nsParserError.h"
|
||||
#include <iostream.h>
|
||||
#include "nsString.h"
|
||||
|
||||
class nsScanner;
|
||||
|
||||
|
@ -121,6 +122,8 @@ class CStartToken: public CHTMLToken {
|
|||
PRBool IsEmpty(void);
|
||||
void SetEmpty(PRBool aValue);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
|
||||
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
|
||||
|
||||
protected:
|
||||
|
@ -145,6 +148,7 @@ class CEndToken: public CHTMLToken {
|
|||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
};
|
||||
|
||||
|
||||
|
@ -184,11 +188,8 @@ class CEntityToken : public CHTMLToken {
|
|||
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
|
||||
static PRInt32 ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner& aScanner);
|
||||
static PRInt32 TranslateToUnicodeStr(PRInt32 aValue,nsString& aString);
|
||||
// static PRInt32 FindEntityIndex(nsString& aString);
|
||||
// static PRInt32 FindEntityIndexMax(const char* aBuffer,PRInt32 aCount=-1);
|
||||
// static PRBool VerifyEntityTable(void);
|
||||
// static PRInt32 ReduceEntities(nsString& aString);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
};
|
||||
|
||||
|
||||
|
@ -220,6 +221,7 @@ class CTextToken: public CHTMLToken {
|
|||
CTextToken();
|
||||
CTextToken(const nsString& aString);
|
||||
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
|
||||
nsresult ConsumeUntil(PRUnichar aChar,nsScanner& aScanner,nsString& aTerminalString);
|
||||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
};
|
||||
|
@ -261,6 +263,7 @@ class CAttributeToken: public CHTMLToken {
|
|||
virtual PRInt32 GetTokenType(void);
|
||||
virtual nsString& GetKey(void) {return mTextKey;}
|
||||
virtual void DebugDumpToken(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
PRBool mLastAttribute;
|
||||
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
|
||||
|
@ -337,6 +340,7 @@ class CSkippedContentToken: public CAttributeToken {
|
|||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
protected:
|
||||
};
|
||||
|
||||
|
|
|
@ -186,6 +186,7 @@ class nsIParser : public nsISupports {
|
|||
* @return ptr to scanner
|
||||
*/
|
||||
virtual eParseMode GetParseMode(void)=0;
|
||||
|
||||
};
|
||||
|
||||
/* ===========================================================*
|
||||
|
|
|
@ -47,16 +47,8 @@ static const char* kNullURL = "Error: Null URL given";
|
|||
static const char* kOnStartNotCalled = "Error: OnStartBinding() must be called before OnDataAvailable()";
|
||||
static const char* kBadListenerInit = "Error: Parser's IStreamListener API was not setup correctly in constructor.";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class CTokenDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
CToken* aToken = (CToken*)anObject;
|
||||
delete aToken;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CDTDDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
|
@ -67,6 +59,8 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class CDTDFinder: public nsDequeFunctor{
|
||||
public:
|
||||
CDTDFinder(nsIDTD* aDTD) {
|
||||
|
@ -83,6 +77,8 @@ public:
|
|||
nsIDTD* mTargetDTD;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class CSharedParserObjects {
|
||||
public:
|
||||
|
||||
|
@ -128,14 +124,6 @@ public:
|
|||
nsString nsParser::gHackMetaCharset = "";
|
||||
nsString nsParser::gHackMetaCharsetURL = "";
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
CSharedParserObjects& GetSharedObjects() {
|
||||
static CSharedParserObjects gSharedParserObjects;
|
||||
return gSharedParserObjects;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
This class is used as an interface between an external agent (like the DOM) and
|
||||
the parser. It will contain a stack full of tagnames, which is used in our
|
||||
|
@ -173,8 +161,13 @@ public:
|
|||
nsDeque mTags; //will hold a deque of prunichars...
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
CSharedParserObjects& GetSharedObjects() {
|
||||
static CSharedParserObjects gSharedParserObjects;
|
||||
return gSharedParserObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
|
@ -429,18 +422,28 @@ eParseMode DetermineParseMode(nsParser& aParser) {
|
|||
|
||||
nsScanner* theScanner=aParser.GetScanner();
|
||||
if(theScanner){
|
||||
nsString theBufCopy;
|
||||
nsString& theBuffer=theScanner->GetBuffer();
|
||||
PRInt32 theIndex=theBuffer.Find("HTML 4.0");
|
||||
if(kNotFound==theIndex)
|
||||
theIndex=theBuffer.Find("html 4.0");
|
||||
if(kNotFound<theIndex)
|
||||
return eParseMode_raptor;
|
||||
else {
|
||||
PRInt32 theIndex=theBuffer.Find("noquirks");
|
||||
if(kNotFound==theIndex)
|
||||
theIndex=theBuffer.Find("NOQUIRKS");
|
||||
if(kNotFound<theIndex)
|
||||
return eParseMode_noquirks;
|
||||
theBuffer.Left(theBufCopy,300);
|
||||
theBufCopy.ToUpperCase();
|
||||
PRInt32 theIndex=theBufCopy.Find("<!DOCTYPE");
|
||||
if(kNotFound==theIndex){
|
||||
theIndex=theBufCopy.Find("<DOCTYPE");
|
||||
}
|
||||
|
||||
if(kNotFound<theIndex) {
|
||||
//good, we found "DOCTYPE" -- now go find it's end delimiter '>'
|
||||
PRInt32 theSubIndex=theBufCopy.Find(kGreaterThan,theIndex+1);
|
||||
theBufCopy.Truncate(theSubIndex);
|
||||
theSubIndex=theBufCopy.Find("HTML 4.0");
|
||||
if(kNotFound<theSubIndex) {
|
||||
return eParseMode_raptor;
|
||||
}
|
||||
}
|
||||
|
||||
theIndex=theBufCopy.Find("NOQUIRKS");
|
||||
if(kNotFound<theIndex) {
|
||||
return eParseMode_noquirks;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -712,7 +715,7 @@ nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled, void* aK
|
|||
* @param aContentType tells us what type of content to expect in the given string
|
||||
* @return error code -- 0 if ok, non-zero if error.
|
||||
*/
|
||||
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall){
|
||||
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aVerifyEnabled,PRBool aLastCall){
|
||||
|
||||
#ifdef _rickgdebug
|
||||
{
|
||||
|
@ -751,7 +754,7 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aCon
|
|||
// till we're completely done.
|
||||
NS_ADDREF(me);
|
||||
if(aSourceBuffer.Length() || mUnusedInput.Length()) {
|
||||
mDTDVerification=aEnableVerify;
|
||||
mDTDVerification=aVerifyEnabled;
|
||||
CParserContext* pc=0;
|
||||
|
||||
if((!mParserContext) || (mParserContext->mKey!=aKey)) {
|
||||
|
@ -1176,6 +1179,7 @@ void nsParser::DebugDumpSource(ostream& aStream) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call this to get a newly constructed tagstack
|
||||
* @update gess 5/05/99
|
||||
|
@ -1188,3 +1192,4 @@ nsresult nsParser::CreateTagStack(nsITagStack** aTagStack){
|
|||
return NS_OK;
|
||||
return NS_ERROR_HTMLPARSER_MEMORYFAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class nsIHTMLContentSink;
|
|||
class nsIDTD;
|
||||
class nsScanner;
|
||||
class nsIParserFilter;
|
||||
class nsTagStack;
|
||||
|
||||
|
||||
#include <fstream.h>
|
||||
|
||||
|
@ -165,7 +165,7 @@ friend class CTokenHandler;
|
|||
* @param aListener is a listener to forward notifications to
|
||||
* @return TRUE if all went well -- FALSE otherwise
|
||||
*/
|
||||
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aEnableVerify=PR_FALSE, void* aKey=0);
|
||||
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aEnableVerify=PR_FALSE,void* aKey=0);
|
||||
|
||||
/**
|
||||
* Cause parser to parse input from given stream
|
||||
|
@ -173,7 +173,7 @@ friend class CTokenHandler;
|
|||
* @param aStream is the i/o source
|
||||
* @return TRUE if all went well -- FALSE otherwise
|
||||
*/
|
||||
virtual nsresult Parse(nsIInputStream& aStream,PRBool aEnableVerify=PR_FALSE, void* aKey=0);
|
||||
virtual nsresult Parse(nsIInputStream& aStream,PRBool aEnableVerify=PR_FALSE,void* aKey=0);
|
||||
|
||||
/**
|
||||
* @update gess5/11/98
|
||||
|
@ -183,7 +183,6 @@ friend class CTokenHandler;
|
|||
*/
|
||||
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
|
||||
|
||||
|
||||
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
virtual nsresult ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
|
||||
|
|
|
@ -40,13 +40,13 @@ nsAutoString& GetEmptyString() {
|
|||
* @param aToken -- token to init internal token
|
||||
* @return
|
||||
*/
|
||||
nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler): nsIParserNode() {
|
||||
nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler):
|
||||
nsIParserNode(), mSkippedContent("") {
|
||||
NS_INIT_REFCNT();
|
||||
mAttributeCount=0;
|
||||
mLineNumber=aLineNumber;
|
||||
mToken=aToken;
|
||||
memset(mAttributes,0,sizeof(mAttributes));
|
||||
mSkippedContent=0;
|
||||
mRecycler=aRecycler;
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,6 @@ nsCParserNode::~nsCParserNode() {
|
|||
for(index=0;index<mAttributeCount;index++){
|
||||
mRecycler->RecycleToken(mAttributes[index]);
|
||||
}
|
||||
if(mSkippedContent)
|
||||
mRecycler->RecycleToken(mSkippedContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,21 +139,6 @@ void nsCParserNode::AddAttribute(CToken* aToken) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the parser encounters
|
||||
* skipped content after a start token.
|
||||
*
|
||||
* @update gess 3/26/98
|
||||
* @param aToken -- really a skippedcontent token
|
||||
* @return nada
|
||||
*/
|
||||
void nsCParserNode::SetSkippedContent(CToken* aToken){
|
||||
if(aToken) {
|
||||
NS_ASSERTION(eToken_skippedcontent == aToken->GetTokenType(), "not a skipped content token");
|
||||
mSkippedContent = aToken;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of this node. Currently unused.
|
||||
|
@ -191,10 +174,19 @@ const nsString& nsCParserNode::GetText() const {
|
|||
* @return string ref of text from internal token
|
||||
*/
|
||||
const nsString& nsCParserNode::GetSkippedContent() const {
|
||||
if (nsnull != mSkippedContent) {
|
||||
return ((CSkippedContentToken*)mSkippedContent)->GetKey();
|
||||
}
|
||||
return GetEmptyString();
|
||||
return mSkippedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text value of this node, which translates into
|
||||
* getting the text value of the underlying token
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return string ref of text from internal token
|
||||
*/
|
||||
void nsCParserNode::SetSkippedContent(nsString& aString) {
|
||||
mSkippedContent=aString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -303,5 +295,3 @@ CToken* nsCParserNode::PopAttributeToken()
|
|||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -90,6 +90,13 @@ class nsCParserNode : public nsIParserNode {
|
|||
*/
|
||||
virtual const nsString& GetSkippedContent() const;
|
||||
|
||||
/**
|
||||
* Retrieve skipped context from node
|
||||
* @update gess5/11/98
|
||||
* @return string containing skipped content
|
||||
*/
|
||||
virtual void SetSkippedContent(nsString& aString);
|
||||
|
||||
/**
|
||||
* Retrieve the type of the parser node.
|
||||
* @update gess5/11/98
|
||||
|
@ -148,14 +155,6 @@ class nsCParserNode : public nsIParserNode {
|
|||
*/
|
||||
virtual void AddAttribute(CToken* aToken);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetSkippedContent(CToken* aToken);
|
||||
|
||||
/**
|
||||
* This getter retrieves the line number from the input source where
|
||||
* the token occured. Lines are interpreted as occuring between \n characters.
|
||||
|
@ -169,15 +168,14 @@ class nsCParserNode : public nsIParserNode {
|
|||
* @return token at anIndex
|
||||
*/
|
||||
virtual CToken* PopAttributeToken();
|
||||
|
||||
protected:
|
||||
PRUint32 mAttributeCount;
|
||||
PRInt32 mLineNumber;
|
||||
CToken* mToken;
|
||||
CToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic!
|
||||
CToken* mSkippedContent;
|
||||
nsITokenRecycler* mRecycler;
|
||||
|
||||
protected:
|
||||
PRUint32 mAttributeCount;
|
||||
PRInt32 mLineNumber;
|
||||
CToken* mToken;
|
||||
CToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic!
|
||||
nsAutoString mSkippedContent;
|
||||
nsITokenRecycler* mRecycler;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -153,6 +153,16 @@ nsString& CToken::GetStringValueXXX(void) {
|
|||
return mTextValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string of full contents, suitable for debug dump.
|
||||
* It should look exactly like the input source.
|
||||
* @update gess5/11/98
|
||||
* @return reference to string containing string value
|
||||
*/
|
||||
void CToken::GetSource(nsString& anOutputString){
|
||||
anOutputString=mTextValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves the value of this internal string
|
||||
* as a cstring.
|
||||
|
|
|
@ -98,6 +98,14 @@ class CToken {
|
|||
*/
|
||||
virtual nsString& GetStringValueXXX(void);
|
||||
|
||||
/**
|
||||
* Get string of full contents, suitable for debug dump.
|
||||
* It should look exactly like the input source.
|
||||
* @update gess5/11/98
|
||||
* @return reference to string containing string value
|
||||
*/
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
|
||||
/**
|
||||
* Setter method that changes the string value of this token
|
||||
* @update gess5/11/98
|
||||
|
|
|
@ -526,14 +526,15 @@ nsresult CViewSourceHTML::WriteText(const nsString& aTextString,nsIContentSink&
|
|||
temp="";
|
||||
break;
|
||||
case kSpace:
|
||||
if((PR_TRUE==aPreserveSpace) && (kSpace==aTextString.CharAt(theOffset+1))) {
|
||||
if(temp.Length())
|
||||
result=aSink.AddLeaf(theTextNode); //just dump the whole string...
|
||||
WriteNBSP(1,aSink);
|
||||
temp="";
|
||||
break;
|
||||
}
|
||||
//fall through...
|
||||
if((PR_TRUE==aPreserveSpace)) {
|
||||
if(aTextString.Length() > theOffset+1 && (kSpace==aTextString.CharAt(theOffset+1))) {
|
||||
if(temp.Length())
|
||||
result=aSink.AddLeaf(theTextNode); //just dump the whole string...
|
||||
WriteNBSP(1,aSink);
|
||||
temp="";
|
||||
break;
|
||||
}
|
||||
} //fall through...
|
||||
default:
|
||||
//scan ahead looking for valid chars...
|
||||
temp+=aTextString.CharAt(theOffset);
|
||||
|
@ -751,7 +752,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
|
|||
case eToken_text:
|
||||
{
|
||||
nsString& theText=aToken->GetStringValueXXX();
|
||||
WriteText(theText,*mSink,PR_FALSE);
|
||||
WriteText(theText,*mSink,PR_TRUE);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -801,8 +802,8 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
|
|||
CToken* theNextToken = mTokenizer->PopToken();
|
||||
if(theNextToken) {
|
||||
theType=eHTMLTokenTypes(theNextToken->GetTokenType());
|
||||
if(eToken_skippedcontent==theType) {
|
||||
attrNode.SetSkippedContent(theNextToken);
|
||||
if(eToken_text==theType) {
|
||||
attrNode.SetSkippedContent(theNextToken->GetStringValueXXX());
|
||||
}
|
||||
}
|
||||
result= OpenHead(attrNode);
|
||||
|
@ -813,7 +814,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
|
|||
if(NS_OK==result)
|
||||
result=CloseHead(attrNode);
|
||||
}
|
||||
nsString& theText=((CAttributeToken*)theNextToken)->GetKey();
|
||||
const nsString& theText=attrNode.GetSkippedContent();
|
||||
WriteText(theText,*mSink,PR_FALSE);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -114,8 +114,6 @@ NS_IMPL_ADDREF(CWellFormedDTD)
|
|||
NS_IMPL_RELEASE(CWellFormedDTD)
|
||||
|
||||
|
||||
//static CTokenDeallocator gTokenKiller;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
|
|
|
@ -1736,11 +1736,7 @@ void nsXIFDTD::EndCSSStyleSheet(const nsIParserNode& aNode)
|
|||
mBuffer.Append("</");
|
||||
mBuffer.Append(tagName);
|
||||
mBuffer.Append(">");
|
||||
CSkippedContentToken* skipped = new CSkippedContentToken(mBuffer);
|
||||
nsString& key = skipped->GetKey();
|
||||
key = mBuffer;
|
||||
|
||||
startNode.SetSkippedContent(skipped);
|
||||
startNode.SetSkippedContent(mBuffer);
|
||||
mSink->AddLeaf(startNode);
|
||||
|
||||
}
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -296,17 +296,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
*/
|
||||
virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This is called to determine if the given parent can omit the
|
||||
* given child (end tag).
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- tag type of parent
|
||||
* @param aChild -- tag type of child
|
||||
* @return PR_TRUE if given tag can contain omit child (end tag)
|
||||
*/
|
||||
virtual PRBool CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag is itself a container
|
||||
|
@ -405,7 +394,6 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
nsresult HandleEndToken(CToken* aToken);
|
||||
nsresult HandleEntityToken(CToken* aToken);
|
||||
nsresult HandleCommentToken(CToken* aToken);
|
||||
nsresult HandleSkippedContentToken(CToken* aToken);
|
||||
nsresult HandleAttributeToken(CToken* aToken);
|
||||
nsresult HandleScriptToken(nsCParserNode& aNode);
|
||||
nsresult HandleStyleToken(CToken* aToken);
|
||||
|
@ -431,7 +419,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
nsresult OpenForm(const nsIParserNode& aNode);
|
||||
nsresult OpenMap(const nsIParserNode& aNode);
|
||||
nsresult OpenFrameset(const nsIParserNode& aNode);
|
||||
nsresult OpenContainer(const nsIParserNode& aNode,PRBool aUpdateStyleStack);
|
||||
nsresult OpenContainer(const nsIParserNode& aNode,PRBool aClosedByStartTag);
|
||||
|
||||
/**
|
||||
* The next set of methods close the given HTML element.
|
||||
|
@ -446,7 +434,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
nsresult CloseForm(const nsIParserNode& aNode);
|
||||
nsresult CloseMap(const nsIParserNode& aNode);
|
||||
nsresult CloseFrameset(const nsIParserNode& aNode);
|
||||
nsresult CloseContainer(const nsIParserNode& aNode,eHTMLTags anActualTag,PRBool aUpdateStyles);
|
||||
nsresult CloseContainer(const nsIParserNode& aNode,eHTMLTags anActualTag,PRBool aClosedByStartTag);
|
||||
|
||||
/**
|
||||
* The special purpose methods automatically close
|
||||
|
@ -455,8 +443,8 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* @return error code - 0 if all went well.
|
||||
*/
|
||||
nsresult CloseTopmostContainer();
|
||||
nsresult CloseContainersTo(eHTMLTags aTag,PRBool aUpdateStyles);
|
||||
nsresult CloseContainersTo(PRInt32 anIndex,eHTMLTags aTag,PRBool aUpdateStyles);
|
||||
nsresult CloseContainersTo(eHTMLTags aTag,PRBool aClosedByStartTag);
|
||||
nsresult CloseContainersTo(PRInt32 anIndex,eHTMLTags aTag,PRBool aClosedByStartTag);
|
||||
|
||||
/**
|
||||
* Causes leaf to be added to sink at current vector pos.
|
||||
|
@ -465,7 +453,7 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* @return error code - 0 if all went well.
|
||||
*/
|
||||
nsresult AddLeaf(const nsIParserNode& aNode);
|
||||
nsresult AddHeadLeaf(const nsIParserNode& aNode);
|
||||
nsresult AddHeadLeaf(nsIParserNode& aNode);
|
||||
|
||||
/**
|
||||
* Causes auto-closures of context vector stack in order to find a
|
||||
|
@ -495,17 +483,16 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
|
|||
* @param aTag -- represents the transient style tag to be handled.
|
||||
* @return error code -- usually 0
|
||||
*/
|
||||
nsresult OpenTransientStyles(eHTMLTags aTag);
|
||||
nsresult CloseTransientStyles(eHTMLTags aTag);
|
||||
nsresult OpenTransientStyles(eHTMLTags aChildTag);
|
||||
nsresult CloseTransientStyles(eHTMLTags aChildTag);
|
||||
nsresult UpdateStyleStackForOpenTag(eHTMLTags aTag,eHTMLTags aActualTag);
|
||||
nsresult UpdateStyleStackForCloseTag(eHTMLTags aTag,eHTMLTags aActualTag);
|
||||
PRBool CanContainStyles(eHTMLTags aTag) const;
|
||||
|
||||
nsresult DoFragment(PRBool aFlag);
|
||||
|
||||
protected:
|
||||
|
||||
nsresult CollectAttributes(nsCParserNode& aNode,PRInt32 aCount);
|
||||
nsresult CollectAttributes(nsCParserNode& aNode,eHTMLTags aTag,PRInt32 aCount);
|
||||
nsresult CollectSkippedContent(nsCParserNode& aNode,PRInt32& aCount);
|
||||
nsresult WillHandleStartTag(CToken* aToken,eHTMLTags aChildTag,nsCParserNode& aNode);
|
||||
nsresult DidHandleStartTag(nsCParserNode& aNode,eHTMLTags aChildTag);
|
||||
|
@ -531,8 +518,10 @@ protected:
|
|||
nsParser* mParser;
|
||||
nsITokenizer* mTokenizer;
|
||||
nsDeque mMisplacedContent;
|
||||
nsDeque mSkippedContent;
|
||||
PRBool mHasOpenScript;
|
||||
PRBool mSaveBadTokens;
|
||||
eHTMLTags mSkipTarget;
|
||||
|
||||
PRUint32 mComputedCRC32;
|
||||
PRUint32 mExpectedCRC32;
|
||||
|
|
|
@ -254,20 +254,6 @@ nsresult COtherDTD::HandleCommentToken(CToken* aToken) {
|
|||
return CNavDTD::HandleCommentToken(aToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when a skippedcontent token has
|
||||
* been encountered in the parse process. After verifying
|
||||
* that the topmost container can contain text, we call
|
||||
* AddLeaf to store this token in the top container.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aToken -- next (start) token to be handled
|
||||
* @return PR_TRUE if all went well; PR_FALSE if error occured
|
||||
*/
|
||||
nsresult COtherDTD::HandleSkippedContentToken(CToken* aToken) {
|
||||
return CNavDTD::HandleSkippedContentToken(aToken);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when an attribute token has been
|
||||
* encountered in the parse process. This is an error, since
|
||||
|
@ -334,19 +320,6 @@ PRBool COtherDTD::CanOmit(eHTMLTags aParent,eHTMLTags aChild) const {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* ENDtag can be omitted. Admittedly,this is a gross simplification.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aTag -- tag to test for containership
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
PRBool COtherDTD::CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild) const {
|
||||
return CNavDTD::CanOmitEndTag(aParent,aChild);
|
||||
}
|
||||
|
||||
|
||||
/*********************************************
|
||||
Here comes code that handles the interface
|
||||
to our content sink.
|
||||
|
|
|
@ -121,17 +121,6 @@ class COtherDTD : public CNavDTD {
|
|||
*/
|
||||
virtual PRBool CanOmit(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This method gets called to determine whether a given
|
||||
* tag can contain newlines. Most do not.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aParent -- tag type of parent
|
||||
* @param aChild -- tag type of child
|
||||
* @return PR_TRUE if given tag can contain other tags
|
||||
*/
|
||||
virtual PRBool CanOmitEndTag(eHTMLTags aParent,eHTMLTags aChild)const;
|
||||
|
||||
/**
|
||||
* This method gets called when a start token has been consumed and needs
|
||||
* to be handled (possibly added to content model via sink).
|
||||
|
@ -181,15 +170,6 @@ class COtherDTD : public CNavDTD {
|
|||
*/
|
||||
nsresult HandleCommentToken(CToken* aToken);
|
||||
|
||||
/**
|
||||
* This method gets called when a skipped-content token has been consumed and needs
|
||||
* to be handled (possibly added to content model via sink).
|
||||
* @update gess5/11/98
|
||||
* @param aToken is the skipped-content token to be handled
|
||||
* @return TRUE if the token was handled.
|
||||
*/
|
||||
nsresult HandleSkippedContentToken(CToken* aToken);
|
||||
|
||||
/**
|
||||
* This method gets called when an attribute token has been consumed and needs
|
||||
* to be handled (possibly added to content model via sink).
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
#include "nsDTDUtils.h"
|
||||
#include "CNavDTD.h"
|
||||
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIElementObserver.h"
|
||||
|
||||
static NS_DEFINE_IID(kIObserverServiceIID, NS_IOBSERVERSERVICE_IID);
|
||||
static NS_DEFINE_IID(kObserverServiceCID, NS_OBSERVERSERVICE_CID);
|
||||
|
@ -51,6 +51,8 @@ nsEntryStack::nsEntryStack() {
|
|||
nsEntryStack::~nsEntryStack() {
|
||||
if(mEntries)
|
||||
delete [] mEntries;
|
||||
mCount=mCapacity=0;
|
||||
mEntries=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -182,7 +184,6 @@ PRInt32 nsEntryStack::GetTopmostIndexOf(eHTMLTags aTag) const {
|
|||
/**
|
||||
*
|
||||
* @update gess9/10/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
nsDTDContext::nsDTDContext() : mStack(), mSkipped(0), mStyles(0) {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -194,7 +195,6 @@ nsDTDContext::nsDTDContext() : mStack(), mSkipped(0), mStyles(0) {
|
|||
/**
|
||||
*
|
||||
* @update gess9/10/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
nsDTDContext::~nsDTDContext() {
|
||||
}
|
||||
|
@ -202,16 +202,14 @@ nsDTDContext::~nsDTDContext() {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98, harishd 04/04/99
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
PRInt32 nsDTDContext::GetCount(void) {
|
||||
return mStack.GetSize();
|
||||
return mStack.GetCount();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess7/9/98, harishd 04/04/99
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
void nsDTDContext::Push(eHTMLTags aTag) {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -224,7 +222,6 @@ void nsDTDContext::Push(eHTMLTags aTag) {
|
|||
|
||||
/**
|
||||
* @update gess7/9/98, harishd 04/04/99
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::Pop() {
|
||||
#ifdef NS_DEBUG
|
||||
|
@ -232,6 +229,14 @@ eHTMLTags nsDTDContext::Pop() {
|
|||
mTags[mStack.mCount-1]=eHTMLTag_unknown;
|
||||
#endif
|
||||
|
||||
nsEntryStack* theStyles=0;
|
||||
nsTagEntry& theEntry=mStack.EntryAt(mStack.mCount-1);
|
||||
PRInt32 theIndex=theEntry.mStyleIndex;
|
||||
if(-1<theIndex){
|
||||
theStyles=(nsEntryStack*)mStyles.ObjectAt(theIndex);
|
||||
delete theStyles;
|
||||
}
|
||||
|
||||
eHTMLTags result=mStack.Pop();
|
||||
return result;
|
||||
}
|
||||
|
@ -239,7 +244,6 @@ eHTMLTags nsDTDContext::Pop() {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::First() const {
|
||||
return mStack.First();
|
||||
|
@ -248,7 +252,6 @@ eHTMLTags nsDTDContext::First() const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::TagAt(PRInt32 anIndex) const {
|
||||
return mStack.TagAt(anIndex);
|
||||
|
@ -258,7 +261,6 @@ eHTMLTags nsDTDContext::TagAt(PRInt32 anIndex) const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::operator[](PRInt32 anIndex) const {
|
||||
return mStack[anIndex];
|
||||
|
@ -267,7 +269,6 @@ eHTMLTags nsDTDContext::operator[](PRInt32 anIndex) const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::Last() const {
|
||||
return mStack.Last();
|
||||
|
@ -276,12 +277,12 @@ eHTMLTags nsDTDContext::Last() const {
|
|||
/**
|
||||
*
|
||||
* @update gess7/9/98
|
||||
* @update gess 4/26/99
|
||||
*/
|
||||
nsEntryStack* nsDTDContext::GetStyles(void) const {
|
||||
nsEntryStack* nsDTDContext::GetStylesAt(PRUint32 anIndex) const {
|
||||
nsEntryStack* result=0;
|
||||
if(0<mStack.mCount){
|
||||
PRInt32 theIndex=mStack.mEntries[mStack.mCount-1].mStyleIndex;
|
||||
if(anIndex<mStack.mCount){
|
||||
nsTagEntry& theEntry=mStack.EntryAt(anIndex);
|
||||
PRInt32 theIndex=theEntry.mStyleIndex;
|
||||
if(-1<theIndex){
|
||||
result=(nsEntryStack*)mStyles.ObjectAt(theIndex);
|
||||
}
|
||||
|
@ -289,6 +290,46 @@ nsEntryStack* nsDTDContext::GetStyles(void) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 04/28/99
|
||||
*/
|
||||
void nsDTDContext::PushStyle(eHTMLTags aTag){
|
||||
|
||||
nsTagEntry& theEntry=mStack.EntryAt(mStack.mCount-1);
|
||||
//ok, now go get the right tokenbank deque...
|
||||
nsEntryStack* theStack=0;
|
||||
if(-1<theEntry.mStyleIndex)
|
||||
theStack=(nsEntryStack*)mStyles.ObjectAt(theEntry.mStyleIndex);
|
||||
if(!theStack){
|
||||
//time to make a databank for this element...
|
||||
theStack=new nsEntryStack();
|
||||
mStyles.Push(theStack);
|
||||
theEntry.mStyleIndex=mStyles.GetSize()-1;
|
||||
}
|
||||
if(theStack){
|
||||
theStack->Push(aTag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess 04/28/99
|
||||
*/
|
||||
eHTMLTags nsDTDContext::PopStyle(void){
|
||||
eHTMLTags result=eHTMLTag_unknown;
|
||||
nsTagEntry& theEntry=mStack.EntryAt(mStack.mCount-1);
|
||||
//ok, now go get the right tokenbank deque...
|
||||
nsEntryStack* theStack=0;
|
||||
if(-1<theEntry.mStyleIndex)
|
||||
theStack=(nsEntryStack*)mStyles.ObjectAt(theEntry.mStyleIndex);
|
||||
if(theStack){
|
||||
result=theStack->Pop();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update harishd 04/04/99
|
||||
|
@ -296,7 +337,7 @@ nsEntryStack* nsDTDContext::GetStyles(void) const {
|
|||
*/
|
||||
void nsDTDContext::SaveToken(CToken* aToken, PRInt32 aID)
|
||||
{
|
||||
NS_PRECONDITION(aID <= mStack.GetSize() && aID > -1,"Out of bounds");
|
||||
NS_PRECONDITION(aID <= mStack.GetCount() && aID > -1,"Out of bounds");
|
||||
|
||||
if(aToken) {
|
||||
nsTagEntry& theEntry=mStack.EntryAt(aID);
|
||||
|
@ -321,9 +362,9 @@ void nsDTDContext::SaveToken(CToken* aToken, PRInt32 aID)
|
|||
*/
|
||||
CToken* nsDTDContext::RestoreTokenFrom(PRInt32 aID)
|
||||
{
|
||||
NS_PRECONDITION(aID <= mStack.GetSize() && aID > -1,"Out of bounds");
|
||||
NS_PRECONDITION(aID <= mStack.GetCount() && aID > -1,"Out of bounds");
|
||||
CToken* result=0;
|
||||
if(0<mStack.GetSize()) {
|
||||
if(0<mStack.GetCount()) {
|
||||
nsTagEntry theEntry=mStack.EntryAt(aID);
|
||||
nsDeque* theDeque=(nsDeque*)mSkipped.ObjectAt(theEntry.mBankIndex);
|
||||
if(theDeque){
|
||||
|
@ -340,7 +381,7 @@ CToken* nsDTDContext::RestoreTokenFrom(PRInt32 aID)
|
|||
*/
|
||||
PRInt32 nsDTDContext::TokenCountAt(PRInt32 aID)
|
||||
{
|
||||
NS_PRECONDITION(aID <= mStack.GetSize(),"Out of bounds");
|
||||
NS_PRECONDITION(aID <= mStack.GetCount(),"Out of bounds");
|
||||
|
||||
nsTagEntry theEntry=mStack.EntryAt(aID);
|
||||
nsDeque* theDeque=(nsDeque*)mSkipped.ObjectAt(theEntry.mBankIndex);
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include <fstream.h>
|
||||
#include "nsITokenizer.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIElementObserver.h"
|
||||
|
||||
/***************************************************************
|
||||
Before digging into the NavDTD, we'll define a helper
|
||||
|
@ -79,7 +80,7 @@ public:
|
|||
eHTMLTags operator[](PRUint32 anIndex) const;
|
||||
eHTMLTags Last() const;
|
||||
void Empty(void);
|
||||
PRInt32 GetSize(void) const {return mCount;}
|
||||
PRInt32 GetCount(void) const {return mCount;}
|
||||
|
||||
nsTagEntry* mEntries;
|
||||
PRUint32 mCount;
|
||||
|
@ -106,7 +107,9 @@ public:
|
|||
eHTMLTags Last() const;
|
||||
void Empty(void);
|
||||
PRInt32 GetCount(void);
|
||||
nsEntryStack* GetStyles(void) const;
|
||||
nsEntryStack* GetStylesAt(PRUint32 anIndex) const;
|
||||
void PushStyle(eHTMLTags aTag);
|
||||
eHTMLTags PopStyle(void);
|
||||
|
||||
void SaveToken(CToken* aToken, PRInt32 aID);
|
||||
CToken* RestoreTokenFrom(PRInt32 aID);
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -46,13 +46,14 @@ public:
|
|||
mTagList=aTagList;
|
||||
}
|
||||
|
||||
PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack);
|
||||
PRInt32 GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset);
|
||||
PRBool Contains(eHTMLTags aTag);
|
||||
PRInt32 GetTopmostIndexOf(nsEntryStack& aTagStack);
|
||||
PRInt32 GetBottommostIndexOf(nsEntryStack& aTagStack,PRInt32 aStartOffset);
|
||||
PRBool Contains(eHTMLTags aTag);
|
||||
eHTMLTags GetTagAt(PRUint32 anIndex) const;
|
||||
|
||||
eHTMLTags mTags[5];
|
||||
eHTMLTags* mTagList;
|
||||
int mCount;
|
||||
PRUint32 mCount;
|
||||
};
|
||||
|
||||
//*********************************************************************************************
|
||||
|
@ -68,11 +69,13 @@ public:
|
|||
*/
|
||||
struct nsHTMLElement {
|
||||
|
||||
static PRBool IsContainerType(eHTMLTags aTag,int aType);
|
||||
static void DebugDumpMembership(const char* aFilename);
|
||||
static void DebugDumpContainment(const char* aFilename,const char* aTitle);
|
||||
static void DebugDumpContainType(const char* aFilename);
|
||||
|
||||
static PRBool IsBlockElement(eHTMLTags aTag);
|
||||
static PRBool IsInlineElement(eHTMLTags aTag);
|
||||
static PRBool IsFlowElement(eHTMLTags aTag);
|
||||
static PRBool IsBlockEntity(eHTMLTags aTag);
|
||||
static PRBool IsInlineEntity(eHTMLTags aTag);
|
||||
static PRBool IsFlowEntity(eHTMLTags aTag);
|
||||
static PRBool IsBlockCloser(eHTMLTags aTag);
|
||||
|
||||
CTagList* GetRootTags(void) const {return mRootNodes;}
|
||||
|
@ -80,6 +83,7 @@ struct nsHTMLElement {
|
|||
CTagList* GetAutoCloseStartTags(void) const {return mAutocloseStart;}
|
||||
CTagList* GetAutoCloseEndTags(void) const {return mAutocloseEnd;}
|
||||
CTagList* GetSynonymousTags(void) const {return mSynonymousTags;}
|
||||
eHTMLTags GetCloseTargetForEndTag(nsEntryStack& aTagStack,PRInt32 anIndex) const;
|
||||
|
||||
CTagList* GetSpecialChildren(void) const {return mSpecialKids;}
|
||||
CTagList* GetSpecialParents(void) const {return mSpecialParents;}
|
||||
|
@ -89,9 +93,10 @@ struct nsHTMLElement {
|
|||
|
||||
eHTMLTags GetTag(void) const {return mTagID;}
|
||||
PRBool CanContain(eHTMLTags aChild) const;
|
||||
PRBool CanExclude(eHTMLTags aChild) const;
|
||||
PRBool CanOmitStartTag(eHTMLTags aChild) const;
|
||||
PRBool CanOmitEndTag(eHTMLTags aParent) const;
|
||||
PRBool CanContainSelf() const;
|
||||
PRBool CanOmitEndTag(void) const;
|
||||
PRBool CanContainSelf(void) const;
|
||||
PRBool HasSpecialProperty(PRInt32 aProperty) const;
|
||||
PRBool SectionContains(eHTMLTags aTag,PRBool allowDepthSearch);
|
||||
|
||||
|
@ -120,6 +125,7 @@ struct nsHTMLElement {
|
|||
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
|
||||
eHTMLTags mSkipTarget; //If set, then we skip all content until this tag is seen
|
||||
|
@ -134,7 +140,10 @@ static const int kDiscardTag = 0x0001; //tells us to toss this tag
|
|||
static const int kOmitEndTag = 0x0002; //safely ignore end tag
|
||||
static const int kLegalOpen = 0x0004; //Lets BODY, TITLE, SCRIPT to reopen
|
||||
static const int kOmitWS = 0x0008; //If set, the tag can omit all ws and newlines
|
||||
static const int kBadContentWatch = 0x0014; //Used in handling illegal contents
|
||||
static const int kNoPropagate = 0x0010; //If set, this tag won't propagate as a child
|
||||
static const int kBadContentWatch = 0x0020;
|
||||
static const int kNoStyleLeaksIn = 0x0040;
|
||||
static const int kNoStyleLeaksOut = 0x0080;
|
||||
|
||||
//*********************************************************************************************
|
||||
// The following ints define the standard groups of HTML elements...
|
||||
|
@ -150,21 +159,23 @@ static const int kSpecial = 0x0008; // A, IMG, APPLET, OBJECT, FONT,
|
|||
// MAP, Q, SUB, SUP, SPAN, BDO, IFRAME
|
||||
|
||||
static const int kFormControl = 0x0010; // INPUT SELECT TEXTAREA LABEL BUTTON
|
||||
static const int kPreformatted = 0x0011; // PRE
|
||||
static const int kPreExclusion = 0x0012; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT
|
||||
static const int kFontStyle = 0x0014; // TT, I, B, U, S, STRIKE, BIG, SMALL
|
||||
static const int kPhrase = 0x0018; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
|
||||
static const int kHeading = 0x0020; // H1..H6
|
||||
static const int kBlockMisc = 0x0021; // P, DL, DIV, CENTER, NOSCRIPT, NOFRAMES, BLOCKQUOTE
|
||||
// FORM, ISINDEX, HR, TABLE, FIELDSET, ADDRESS
|
||||
static const int kPreformatted = 0x0020; // PRE
|
||||
static const int kPreExclusion = 0x0040; // IMG, OBJECT, APPLET, BIG, SMALL, SUB, SUP, FONT, BASEFONT
|
||||
static const int kFontStyle = 0x0080; // TT, I, B, U, S, STRIKE, BIG, SMALL, BLINK
|
||||
static const int kPhrase = 0x0100; // EM, STRONG, DFN, CODE, SAMP, KBD, VAR, CITE, ABBR, ACRONYM
|
||||
static const int kHeading = 0x0200; // H1..H6
|
||||
static const int kBlockMisc = 0x0400; // OBJECT, SCRIPT
|
||||
static const int kBlock = 0x0800; // ADDRESS, BLOCKQUOTE, CENTER, DIV, DL, FIELDSET, FORM,
|
||||
// ISINDEX, HR, NOSCRIPT, NOFRAMES, P, TABLE
|
||||
static const int kList = 0x1000; // UL, OL, DIR, MENU
|
||||
static const int kPCDATA = 0x2000; // just plain text...
|
||||
static const int kSelf = 0x4000; // whatever THIS tag is...
|
||||
static const int kExtensions = 0x8000; // BGSOUND, WBR, NOBR
|
||||
static const int kTable = 0x10000;// TR,TD,THEAD,TBODY,TFOOT,CAPTION,TH
|
||||
|
||||
static const int kList = 0x0024; // UL, OL, DIR, MENU
|
||||
static const int kPCDATA = 0x0028; // just plain text...
|
||||
static const int kSelf = 0x0040; // whatever THIS tag is...
|
||||
|
||||
static const int kInline = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl); // #PCDATA, %fontstyle, %phrase, %special, %formctrl
|
||||
static const int kBlock = (kHeading|kList|kPreformatted|kBlockMisc); // %heading, %list, %preformatted, %blockmisc
|
||||
static const int kFlow = (kBlock|kInline); // %block, %inline
|
||||
static const int kInlineEntity = (kPCDATA|kFontStyle|kPhrase|kSpecial|kFormControl|kExtensions); // #PCDATA, %fontstyle, %phrase, %special, %formctrl
|
||||
static const int kBlockEntity = (kHeading|kList|kPreformatted|kBlock); // %heading, %list, %preformatted, %blockmisc
|
||||
static const int kFlowEntity = (kBlockEntity|kInlineEntity); // %block, %inline
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -101,7 +101,7 @@ NS_IMPL_RELEASE(nsHTMLTokenizer)
|
|||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(new CTokenDeallocator()){
|
||||
nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(0){
|
||||
NS_INIT_REFCNT();
|
||||
mDoXMLEmptyTags=PR_FALSE;
|
||||
}
|
||||
|
@ -114,6 +114,10 @@ nsHTMLTokenizer::nsHTMLTokenizer() : nsITokenizer(), mTokenDeque(new CTokenDeall
|
|||
* @return
|
||||
*/
|
||||
nsHTMLTokenizer::~nsHTMLTokenizer(){
|
||||
if(mTokenDeque.GetSize()){
|
||||
CTokenDeallocator theDeallocator;
|
||||
mTokenDeque.ForEach(theDeallocator);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -277,10 +281,10 @@ nsresult nsHTMLTokenizer::ConsumeToken(nsScanner& aScanner) {
|
|||
|
||||
case kNotFound:
|
||||
break;
|
||||
|
||||
|
||||
case 0: //preceeds a EOF...
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
if(!nsString::IsSpace(theChar)) {
|
||||
nsAutoString temp(theChar);
|
||||
|
@ -411,66 +415,15 @@ nsresult nsHTMLTokenizer::ConsumeAttributes(PRUnichar aChar,CStartToken* aToken,
|
|||
}
|
||||
|
||||
/**
|
||||
* This is a special case method. It's job is to consume
|
||||
* all of the given tag up to an including the end tag.
|
||||
*
|
||||
* @param aChar: last char read
|
||||
* @param aScanner: see nsScanner.h
|
||||
* @param anErrorCode: arg that will hold error condition
|
||||
* @return new token or null
|
||||
*/
|
||||
nsresult nsHTMLTokenizer::ConsumeContentToEndTag(PRUnichar aChar,
|
||||
eHTMLTags aChildTag,
|
||||
nsScanner& aScanner,
|
||||
CToken*& aToken){
|
||||
|
||||
//In the case that we just read the given tag, we should go and
|
||||
//consume all the input until we find a matching end tag.
|
||||
|
||||
nsAutoString endTag("</");
|
||||
endTag.Append(NS_EnumToTag(aChildTag));
|
||||
endTag.Append(">");
|
||||
|
||||
CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
aToken=theRecycler->CreateTokenOfType(eToken_skippedcontent,aChildTag,endTag);
|
||||
return aToken->Consume(aChar,aScanner); //tell new token to finish consuming text...
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* In the case that we just read the given tag, we should go and
|
||||
* consume all the input until we find a matching end tag.
|
||||
* @update gess12/28/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsresult nsHTMLTokenizer::HandleSkippedContent(nsScanner& aScanner,CToken*& aToken) {
|
||||
nsresult nsHTMLTokenizer::ConsumeScriptContent(nsScanner& aScanner,CToken*& aToken) {
|
||||
nsresult result=NS_OK;
|
||||
|
||||
eHTMLTags theTag=(eHTMLTags)aToken->GetTypeID();
|
||||
if(eHTMLTag_unknown!=gHTMLElements[theTag].mSkipTarget) {
|
||||
|
||||
//Do special case handling for <script>, <style>, <title> or <textarea>...
|
||||
CToken* skippedToken=0;
|
||||
PRUnichar theChar=0;
|
||||
result=ConsumeContentToEndTag(theChar,gHTMLElements[theTag].mSkipTarget,aScanner,skippedToken);
|
||||
|
||||
CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
AddToken(skippedToken,result,mTokenDeque,theRecycler);
|
||||
|
||||
if(NS_SUCCEEDED(result) && skippedToken){
|
||||
//In the case that we just read a given tag, we should go and
|
||||
//consume all the tag content itself (and throw it all away).
|
||||
|
||||
nsString& theTagStr=skippedToken->GetStringValueXXX();
|
||||
CToken* endtoken=theRecycler->CreateTokenOfType(eToken_end,theTag,theTagStr);
|
||||
if(endtoken){
|
||||
nsAutoString temp;
|
||||
theTagStr.Mid(temp,2,theTagStr.Length()-3);
|
||||
//now strip the leading and trailing delimiters...
|
||||
endtoken->Reinitialize(theTag,temp);
|
||||
AddToken(endtoken,result,mTokenDeque,theRecycler);
|
||||
}
|
||||
} //if
|
||||
} //if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -498,11 +451,18 @@ nsresult nsHTMLTokenizer::ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScan
|
|||
result=ConsumeAttributes(aChar,(CStartToken*)aToken,aScanner);
|
||||
}
|
||||
|
||||
//now that that's over with, we have one more problem to solve.
|
||||
//In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
//consume all the content itself.
|
||||
if(NS_SUCCEEDED(result)) {
|
||||
result=HandleSkippedContent(aScanner,aToken);
|
||||
/* Now that that's over with, we have one more problem to solve.
|
||||
In the case that we just read a <SCRIPT> or <STYLE> tags, we should go and
|
||||
consume all the content itself.
|
||||
*/
|
||||
if(NS_SUCCEEDED(result) && (eHTMLTag_script==theTag)) {
|
||||
nsAutoString endTag("</script>");
|
||||
CTokenRecycler* theRecycler=(CTokenRecycler*)GetTokenRecycler();
|
||||
CToken* textToken=theRecycler->CreateTokenOfType(eToken_text,theTag,endTag);
|
||||
result=((CTextToken*)textToken)->ConsumeUntil(0,aScanner,endTag); //tell new token to finish consuming text...
|
||||
AddToken(textToken,result,mTokenDeque,theRecycler);
|
||||
CToken* endToken=theRecycler->CreateTokenOfType(eToken_end,theTag);
|
||||
AddToken(endToken,result,mTokenDeque,theRecycler);
|
||||
}
|
||||
|
||||
//EEEEECCCCKKKK!!!
|
||||
|
|
|
@ -69,7 +69,7 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
virtual nsresult HandleSkippedContent(nsScanner& aScanner,CToken*& aToken);
|
||||
virtual nsresult ConsumeScriptContent(nsScanner& aScanner,CToken*& aToken);
|
||||
virtual nsresult ConsumeTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeStartTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeEndTag(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
|
@ -79,7 +79,6 @@ protected:
|
|||
virtual nsresult ConsumeComment(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeNewline(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeText(const nsString& aString,CToken*& aToken,nsScanner& aScanner);
|
||||
virtual nsresult ConsumeContentToEndTag(PRUnichar aChar,eHTMLTags aChildTag,nsScanner& aScanner,CToken*& aToken);
|
||||
virtual nsresult ConsumeProcessingInstruction(PRUnichar aChar,CToken*& aToken,nsScanner& aScanner);
|
||||
|
||||
static void AddToken(CToken*& aToken,nsresult aResult,nsDeque& aDeque,CTokenRecycler* aRecycler);
|
||||
|
|
|
@ -29,7 +29,6 @@
|
|||
#include "nsHTMLTags.h"
|
||||
#include "nsHTMLEntities.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsStr.h"
|
||||
|
||||
//#define GESS_MACHINE
|
||||
#ifdef GESS_MACHINE
|
||||
|
@ -79,7 +78,6 @@ void CHTMLToken::SetStringValue(const char* name){
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* constructor from tag id
|
||||
*
|
||||
|
@ -272,6 +270,19 @@ void CStartToken::DebugDumpSource(ostream& out) {
|
|||
out << ">";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CStartToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="<";
|
||||
anOutputString+=mTextValue;
|
||||
if(!mAttributed)
|
||||
anOutputString+=">";
|
||||
}
|
||||
|
||||
/*
|
||||
* constructor from tag id
|
||||
|
@ -303,7 +314,6 @@ CEndToken::CEndToken(const nsString& aName) : CHTMLToken(aName) {
|
|||
* @return error result
|
||||
*/
|
||||
nsresult CEndToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
||||
|
||||
//if you're here, we've already Consumed the <! chars, and are
|
||||
//ready to Consume the rest of the open tag identifier.
|
||||
//Stop consuming as soon as you see a space or a '>'.
|
||||
|
@ -388,6 +398,19 @@ void CEndToken::DebugDumpSource(ostream& out) {
|
|||
out << "</" << buffer << ">";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CEndToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="</";
|
||||
anOutputString+=mTextValue;
|
||||
anOutputString+=">";
|
||||
}
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
*
|
||||
|
@ -474,6 +497,70 @@ nsresult CTextToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* Consume as much clear text from scanner as possible.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aChar -- last char consumed from stream
|
||||
* @param aScanner -- controller of underlying input source
|
||||
* @return error result
|
||||
*/
|
||||
nsresult CTextToken::ConsumeUntil(PRUnichar aChar,nsScanner& aScanner,nsString& aTerminalString){
|
||||
PRBool done=PR_FALSE;
|
||||
nsresult result=NS_OK;
|
||||
nsString temp;
|
||||
PRUnichar theChar;
|
||||
|
||||
//We're going to try a new algorithm here. Rather than scan for the matching
|
||||
//end tag like we used to do, we're now going to scan for whitespace and comments.
|
||||
//If we find either, just eat them. If we find text or a tag, then go to the
|
||||
//target endtag, or the start of another comment.
|
||||
|
||||
static nsAutoString theWhitespace2("\b\t ");
|
||||
|
||||
while((!done) && (NS_OK==result)) {
|
||||
result=aScanner.GetChar(aChar);
|
||||
if((NS_OK==result) && (kLessThan==aChar)) {
|
||||
//we're reading a tag or a comment...
|
||||
result=aScanner.GetChar(theChar);
|
||||
if((NS_OK==result) && (kExclamation==theChar)) {
|
||||
//read a comment...
|
||||
static CCommentToken theComment;
|
||||
result=theComment.Consume(aChar,aScanner);
|
||||
if(NS_OK==result) {
|
||||
//result=aScanner.SkipWhitespace();
|
||||
//temp.Append("<!");
|
||||
temp.Append(theComment.GetStringValueXXX());
|
||||
//temp.Append(">");
|
||||
}
|
||||
} else {
|
||||
//read a tag...
|
||||
temp+=aChar;
|
||||
temp+=theChar;
|
||||
result=aScanner.ReadUntil(temp,kGreaterThan,PR_TRUE);
|
||||
}
|
||||
}
|
||||
else if(0<=theWhitespace2.BinarySearch(aChar)) {
|
||||
static CWhitespaceToken theWS;
|
||||
result=theWS.Consume(aChar,aScanner);
|
||||
if(NS_OK==result) {
|
||||
temp.Append(theWS.GetStringValueXXX());
|
||||
}
|
||||
}
|
||||
else {
|
||||
temp+=aChar;
|
||||
result=aScanner.ReadUntil(temp,kLessThan,PR_FALSE);
|
||||
}
|
||||
nsAutoString theRight;
|
||||
temp.Right(theRight,aTerminalString.Length());
|
||||
done=PRBool(0==theRight.Compare(aTerminalString,PR_TRUE));
|
||||
} //while
|
||||
int len=temp.Length();
|
||||
temp.Truncate(len-aTerminalString.Length());
|
||||
mTextValue=temp;
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
*
|
||||
|
@ -759,14 +846,16 @@ nsresult CCommentToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
|||
PRBool theStrictForm=PR_FALSE;
|
||||
nsresult result=(theStrictForm) ? ConsumeStrictComment(aChar,aScanner,mTextValue) : ConsumeComment(aChar,aScanner,mTextValue);
|
||||
|
||||
/*
|
||||
//this change is here to make the editor teams' life easier.
|
||||
//I'm removing the leading and trailing markup...
|
||||
/*
|
||||
|
||||
if(0==mTextValue.Find("<!"))
|
||||
mTextValue.Cut(0,2); //trim off 1st 2 chars...
|
||||
if(kGreaterThan==mTextValue.Last())
|
||||
mTextValue.Truncate(mTextValue.Length()-1); //trim off last char
|
||||
*/
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -860,21 +949,21 @@ nsresult CNewlineToken::Consume(PRUnichar aChar, nsScanner& aScanner) {
|
|||
mTextValue=aChar;
|
||||
|
||||
//we already read the \r or \n, let's see what's next!
|
||||
PRUnichar nextChar;
|
||||
nsresult result=aScanner.Peek(nextChar);
|
||||
PRUnichar theChar;
|
||||
nsresult result=aScanner.Peek(theChar);
|
||||
|
||||
if(NS_OK==result) {
|
||||
switch(aChar) {
|
||||
case kNewLine:
|
||||
if(kCR==nextChar) {
|
||||
result=aScanner.GetChar(nextChar);
|
||||
mTextValue+=nextChar;
|
||||
if(kCR==theChar) {
|
||||
result=aScanner.GetChar(theChar);
|
||||
mTextValue+=theChar;
|
||||
}
|
||||
break;
|
||||
case kCR:
|
||||
if(kNewLine==nextChar) {
|
||||
result=aScanner.GetChar(nextChar);
|
||||
mTextValue+=nextChar;
|
||||
if(kNewLine==theChar) {
|
||||
result=aScanner.GetChar(theChar);
|
||||
mTextValue+=theChar;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
@ -968,6 +1057,19 @@ void CAttributeToken::DebugDumpToken(ostream& out) {
|
|||
out << buffer << ": " << mTypeID << endl;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CAttributeToken::GetSource(nsString& anOutputString){
|
||||
anOutputString=mTextKey;
|
||||
anOutputString+="=";
|
||||
anOutputString+=mTextValue;
|
||||
anOutputString+=";";
|
||||
}
|
||||
|
||||
/*
|
||||
* This general purpose method is used when you want to
|
||||
|
@ -997,8 +1099,8 @@ nsresult ConsumeQuotedString(PRUnichar aChar,nsString& aString,nsScanner& aScann
|
|||
PRUnichar ch=aString.Last();
|
||||
if(ch!=aChar)
|
||||
aString+=aChar;
|
||||
// aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' '));
|
||||
aString.StripChars("\r"); //per the HTML spec, ignore linefeeds...
|
||||
//aString.ReplaceChar(PRUnichar('\n'),PRUnichar(' '));
|
||||
aString.StripChars("\r\n"); //per the HTML spec, ignore linefeeds...
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -1270,6 +1372,7 @@ const char* CEntityToken::GetClassName(void) {
|
|||
return "&entity";
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
|
@ -1439,6 +1542,19 @@ void CEntityToken::DebugDumpSource(ostream& out) {
|
|||
delete[] cp;
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CEntityToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="&";
|
||||
anOutputString+=anOutputString;
|
||||
anOutputString+=";";
|
||||
}
|
||||
|
||||
/*
|
||||
* default constructor
|
||||
*
|
||||
|
@ -1591,9 +1707,9 @@ nsresult CSkippedContentToken::Consume(PRUnichar aChar,nsScanner& aScanner) {
|
|||
temp+=aChar;
|
||||
result=aScanner.ReadUntil(temp,kLessThan,PR_FALSE);
|
||||
}
|
||||
nsAutoString temp2;
|
||||
temp.Right(temp2,mTextValue.Length());
|
||||
done=PRBool(0==temp2.Compare(mTextValue.GetUnicode(),PR_TRUE,mTextValue.Length()));
|
||||
nsAutoString theRight;
|
||||
temp.Right(theRight,mTextValue.Length());
|
||||
done=PRBool(0==theRight.Compare(mTextValue,PR_TRUE));
|
||||
}
|
||||
int len=temp.Length();
|
||||
temp.Truncate(len-mTextValue.Length());
|
||||
|
@ -1616,6 +1732,16 @@ void CSkippedContentToken::DebugDumpSource(ostream& out) {
|
|||
out<<">";
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param anOutputString will recieve the result
|
||||
* @return nada
|
||||
*/
|
||||
void CSkippedContentToken::GetSource(nsString& anOutputString){
|
||||
anOutputString="$skipped-content";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include "nsHTMLTags.h"
|
||||
#include "nsParserError.h"
|
||||
#include <iostream.h>
|
||||
#include "nsString.h"
|
||||
|
||||
class nsScanner;
|
||||
|
||||
|
@ -121,6 +122,8 @@ class CStartToken: public CHTMLToken {
|
|||
PRBool IsEmpty(void);
|
||||
void SetEmpty(PRBool aValue);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
|
||||
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
|
||||
|
||||
protected:
|
||||
|
@ -145,6 +148,7 @@ class CEndToken: public CHTMLToken {
|
|||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
};
|
||||
|
||||
|
||||
|
@ -184,11 +188,8 @@ class CEntityToken : public CHTMLToken {
|
|||
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
|
||||
static PRInt32 ConsumeEntity(PRUnichar aChar,nsString& aString,nsScanner& aScanner);
|
||||
static PRInt32 TranslateToUnicodeStr(PRInt32 aValue,nsString& aString);
|
||||
// static PRInt32 FindEntityIndex(nsString& aString);
|
||||
// static PRInt32 FindEntityIndexMax(const char* aBuffer,PRInt32 aCount=-1);
|
||||
// static PRBool VerifyEntityTable(void);
|
||||
// static PRInt32 ReduceEntities(nsString& aString);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
};
|
||||
|
||||
|
||||
|
@ -220,6 +221,7 @@ class CTextToken: public CHTMLToken {
|
|||
CTextToken();
|
||||
CTextToken(const nsString& aString);
|
||||
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
|
||||
nsresult ConsumeUntil(PRUnichar aChar,nsScanner& aScanner,nsString& aTerminalString);
|
||||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
};
|
||||
|
@ -261,6 +263,7 @@ class CAttributeToken: public CHTMLToken {
|
|||
virtual PRInt32 GetTokenType(void);
|
||||
virtual nsString& GetKey(void) {return mTextKey;}
|
||||
virtual void DebugDumpToken(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
PRBool mLastAttribute;
|
||||
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
|
||||
|
@ -337,6 +340,7 @@ class CSkippedContentToken: public CAttributeToken {
|
|||
virtual const char* GetClassName(void);
|
||||
virtual PRInt32 GetTokenType(void);
|
||||
virtual void DebugDumpSource(ostream& out);
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
protected:
|
||||
};
|
||||
|
||||
|
|
|
@ -186,6 +186,7 @@ class nsIParser : public nsISupports {
|
|||
* @return ptr to scanner
|
||||
*/
|
||||
virtual eParseMode GetParseMode(void)=0;
|
||||
|
||||
};
|
||||
|
||||
/* ===========================================================*
|
||||
|
|
|
@ -47,16 +47,8 @@ static const char* kNullURL = "Error: Null URL given";
|
|||
static const char* kOnStartNotCalled = "Error: OnStartBinding() must be called before OnDataAvailable()";
|
||||
static const char* kBadListenerInit = "Error: Parser's IStreamListener API was not setup correctly in constructor.";
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class CTokenDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
virtual void* operator()(void* anObject) {
|
||||
CToken* aToken = (CToken*)anObject;
|
||||
delete aToken;
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CDTDDeallocator: public nsDequeFunctor{
|
||||
public:
|
||||
|
@ -67,6 +59,8 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class CDTDFinder: public nsDequeFunctor{
|
||||
public:
|
||||
CDTDFinder(nsIDTD* aDTD) {
|
||||
|
@ -83,6 +77,8 @@ public:
|
|||
nsIDTD* mTargetDTD;
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
class CSharedParserObjects {
|
||||
public:
|
||||
|
||||
|
@ -128,14 +124,6 @@ public:
|
|||
nsString nsParser::gHackMetaCharset = "";
|
||||
nsString nsParser::gHackMetaCharsetURL = "";
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
CSharedParserObjects& GetSharedObjects() {
|
||||
static CSharedParserObjects gSharedParserObjects;
|
||||
return gSharedParserObjects;
|
||||
}
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
This class is used as an interface between an external agent (like the DOM) and
|
||||
the parser. It will contain a stack full of tagnames, which is used in our
|
||||
|
@ -173,8 +161,13 @@ public:
|
|||
nsDeque mTags; //will hold a deque of prunichars...
|
||||
};
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
|
||||
CSharedParserObjects& GetSharedObjects() {
|
||||
static CSharedParserObjects gSharedParserObjects;
|
||||
return gSharedParserObjects;
|
||||
}
|
||||
|
||||
/**
|
||||
* default constructor
|
||||
|
@ -429,18 +422,28 @@ eParseMode DetermineParseMode(nsParser& aParser) {
|
|||
|
||||
nsScanner* theScanner=aParser.GetScanner();
|
||||
if(theScanner){
|
||||
nsString theBufCopy;
|
||||
nsString& theBuffer=theScanner->GetBuffer();
|
||||
PRInt32 theIndex=theBuffer.Find("HTML 4.0");
|
||||
if(kNotFound==theIndex)
|
||||
theIndex=theBuffer.Find("html 4.0");
|
||||
if(kNotFound<theIndex)
|
||||
return eParseMode_raptor;
|
||||
else {
|
||||
PRInt32 theIndex=theBuffer.Find("noquirks");
|
||||
if(kNotFound==theIndex)
|
||||
theIndex=theBuffer.Find("NOQUIRKS");
|
||||
if(kNotFound<theIndex)
|
||||
return eParseMode_noquirks;
|
||||
theBuffer.Left(theBufCopy,300);
|
||||
theBufCopy.ToUpperCase();
|
||||
PRInt32 theIndex=theBufCopy.Find("<!DOCTYPE");
|
||||
if(kNotFound==theIndex){
|
||||
theIndex=theBufCopy.Find("<DOCTYPE");
|
||||
}
|
||||
|
||||
if(kNotFound<theIndex) {
|
||||
//good, we found "DOCTYPE" -- now go find it's end delimiter '>'
|
||||
PRInt32 theSubIndex=theBufCopy.Find(kGreaterThan,theIndex+1);
|
||||
theBufCopy.Truncate(theSubIndex);
|
||||
theSubIndex=theBufCopy.Find("HTML 4.0");
|
||||
if(kNotFound<theSubIndex) {
|
||||
return eParseMode_raptor;
|
||||
}
|
||||
}
|
||||
|
||||
theIndex=theBufCopy.Find("NOQUIRKS");
|
||||
if(kNotFound<theIndex) {
|
||||
return eParseMode_noquirks;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -712,7 +715,7 @@ nsresult nsParser::Parse(nsIInputStream& aStream,PRBool aVerifyEnabled, void* aK
|
|||
* @param aContentType tells us what type of content to expect in the given string
|
||||
* @return error code -- 0 if ok, non-zero if error.
|
||||
*/
|
||||
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify,PRBool aLastCall){
|
||||
nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aVerifyEnabled,PRBool aLastCall){
|
||||
|
||||
#ifdef _rickgdebug
|
||||
{
|
||||
|
@ -751,7 +754,7 @@ nsresult nsParser::Parse(nsString& aSourceBuffer,void* aKey,const nsString& aCon
|
|||
// till we're completely done.
|
||||
NS_ADDREF(me);
|
||||
if(aSourceBuffer.Length() || mUnusedInput.Length()) {
|
||||
mDTDVerification=aEnableVerify;
|
||||
mDTDVerification=aVerifyEnabled;
|
||||
CParserContext* pc=0;
|
||||
|
||||
if((!mParserContext) || (mParserContext->mKey!=aKey)) {
|
||||
|
@ -1176,6 +1179,7 @@ void nsParser::DebugDumpSource(ostream& aStream) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Call this to get a newly constructed tagstack
|
||||
* @update gess 5/05/99
|
||||
|
@ -1188,3 +1192,4 @@ nsresult nsParser::CreateTagStack(nsITagStack** aTagStack){
|
|||
return NS_OK;
|
||||
return NS_ERROR_HTMLPARSER_MEMORYFAILURE;
|
||||
}
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ class nsIHTMLContentSink;
|
|||
class nsIDTD;
|
||||
class nsScanner;
|
||||
class nsIParserFilter;
|
||||
class nsTagStack;
|
||||
|
||||
|
||||
#include <fstream.h>
|
||||
|
||||
|
@ -165,7 +165,7 @@ friend class CTokenHandler;
|
|||
* @param aListener is a listener to forward notifications to
|
||||
* @return TRUE if all went well -- FALSE otherwise
|
||||
*/
|
||||
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aEnableVerify=PR_FALSE, void* aKey=0);
|
||||
virtual nsresult Parse(nsIURL* aURL,nsIStreamObserver* aListener,PRBool aEnableVerify=PR_FALSE,void* aKey=0);
|
||||
|
||||
/**
|
||||
* Cause parser to parse input from given stream
|
||||
|
@ -173,7 +173,7 @@ friend class CTokenHandler;
|
|||
* @param aStream is the i/o source
|
||||
* @return TRUE if all went well -- FALSE otherwise
|
||||
*/
|
||||
virtual nsresult Parse(nsIInputStream& aStream,PRBool aEnableVerify=PR_FALSE, void* aKey=0);
|
||||
virtual nsresult Parse(nsIInputStream& aStream,PRBool aEnableVerify=PR_FALSE,void* aKey=0);
|
||||
|
||||
/**
|
||||
* @update gess5/11/98
|
||||
|
@ -183,7 +183,6 @@ friend class CTokenHandler;
|
|||
*/
|
||||
virtual nsresult Parse(nsString& aSourceBuffer,void* aKey,const nsString& aContentType,PRBool aEnableVerify=PR_FALSE,PRBool aLastCall=PR_FALSE);
|
||||
|
||||
|
||||
virtual PRBool IsValidFragment(const nsString& aSourceBuffer,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
virtual nsresult ParseFragment(nsString& aSourceBuffer,void* aKey,nsITagStack& aStack,PRUint32 anInsertPos,const nsString& aContentType);
|
||||
|
||||
|
|
|
@ -40,13 +40,13 @@ nsAutoString& GetEmptyString() {
|
|||
* @param aToken -- token to init internal token
|
||||
* @return
|
||||
*/
|
||||
nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler): nsIParserNode() {
|
||||
nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler):
|
||||
nsIParserNode(), mSkippedContent("") {
|
||||
NS_INIT_REFCNT();
|
||||
mAttributeCount=0;
|
||||
mLineNumber=aLineNumber;
|
||||
mToken=aToken;
|
||||
memset(mAttributes,0,sizeof(mAttributes));
|
||||
mSkippedContent=0;
|
||||
mRecycler=aRecycler;
|
||||
}
|
||||
|
||||
|
@ -65,8 +65,6 @@ nsCParserNode::~nsCParserNode() {
|
|||
for(index=0;index<mAttributeCount;index++){
|
||||
mRecycler->RecycleToken(mAttributes[index]);
|
||||
}
|
||||
if(mSkippedContent)
|
||||
mRecycler->RecycleToken(mSkippedContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,21 +139,6 @@ void nsCParserNode::AddAttribute(CToken* aToken) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the parser encounters
|
||||
* skipped content after a start token.
|
||||
*
|
||||
* @update gess 3/26/98
|
||||
* @param aToken -- really a skippedcontent token
|
||||
* @return nada
|
||||
*/
|
||||
void nsCParserNode::SetSkippedContent(CToken* aToken){
|
||||
if(aToken) {
|
||||
NS_ASSERTION(eToken_skippedcontent == aToken->GetTokenType(), "not a skipped content token");
|
||||
mSkippedContent = aToken;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the name of this node. Currently unused.
|
||||
|
@ -191,10 +174,19 @@ const nsString& nsCParserNode::GetText() const {
|
|||
* @return string ref of text from internal token
|
||||
*/
|
||||
const nsString& nsCParserNode::GetSkippedContent() const {
|
||||
if (nsnull != mSkippedContent) {
|
||||
return ((CSkippedContentToken*)mSkippedContent)->GetKey();
|
||||
}
|
||||
return GetEmptyString();
|
||||
return mSkippedContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get text value of this node, which translates into
|
||||
* getting the text value of the underlying token
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param
|
||||
* @return string ref of text from internal token
|
||||
*/
|
||||
void nsCParserNode::SetSkippedContent(nsString& aString) {
|
||||
mSkippedContent=aString;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -303,5 +295,3 @@ CToken* nsCParserNode::PopAttributeToken()
|
|||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -90,6 +90,13 @@ class nsCParserNode : public nsIParserNode {
|
|||
*/
|
||||
virtual const nsString& GetSkippedContent() const;
|
||||
|
||||
/**
|
||||
* Retrieve skipped context from node
|
||||
* @update gess5/11/98
|
||||
* @return string containing skipped content
|
||||
*/
|
||||
virtual void SetSkippedContent(nsString& aString);
|
||||
|
||||
/**
|
||||
* Retrieve the type of the parser node.
|
||||
* @update gess5/11/98
|
||||
|
@ -148,14 +155,6 @@ class nsCParserNode : public nsIParserNode {
|
|||
*/
|
||||
virtual void AddAttribute(CToken* aToken);
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess5/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
virtual void SetSkippedContent(CToken* aToken);
|
||||
|
||||
/**
|
||||
* This getter retrieves the line number from the input source where
|
||||
* the token occured. Lines are interpreted as occuring between \n characters.
|
||||
|
@ -169,15 +168,14 @@ class nsCParserNode : public nsIParserNode {
|
|||
* @return token at anIndex
|
||||
*/
|
||||
virtual CToken* PopAttributeToken();
|
||||
|
||||
protected:
|
||||
PRUint32 mAttributeCount;
|
||||
PRInt32 mLineNumber;
|
||||
CToken* mToken;
|
||||
CToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic!
|
||||
CToken* mSkippedContent;
|
||||
nsITokenRecycler* mRecycler;
|
||||
|
||||
protected:
|
||||
PRUint32 mAttributeCount;
|
||||
PRInt32 mLineNumber;
|
||||
CToken* mToken;
|
||||
CToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic!
|
||||
nsAutoString mSkippedContent;
|
||||
nsITokenRecycler* mRecycler;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -153,6 +153,16 @@ nsString& CToken::GetStringValueXXX(void) {
|
|||
return mTextValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get string of full contents, suitable for debug dump.
|
||||
* It should look exactly like the input source.
|
||||
* @update gess5/11/98
|
||||
* @return reference to string containing string value
|
||||
*/
|
||||
void CToken::GetSource(nsString& anOutputString){
|
||||
anOutputString=mTextValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method retrieves the value of this internal string
|
||||
* as a cstring.
|
||||
|
|
|
@ -98,6 +98,14 @@ class CToken {
|
|||
*/
|
||||
virtual nsString& GetStringValueXXX(void);
|
||||
|
||||
/**
|
||||
* Get string of full contents, suitable for debug dump.
|
||||
* It should look exactly like the input source.
|
||||
* @update gess5/11/98
|
||||
* @return reference to string containing string value
|
||||
*/
|
||||
virtual void GetSource(nsString& anOutputString);
|
||||
|
||||
/**
|
||||
* Setter method that changes the string value of this token
|
||||
* @update gess5/11/98
|
||||
|
|
|
@ -526,14 +526,15 @@ nsresult CViewSourceHTML::WriteText(const nsString& aTextString,nsIContentSink&
|
|||
temp="";
|
||||
break;
|
||||
case kSpace:
|
||||
if((PR_TRUE==aPreserveSpace) && (kSpace==aTextString.CharAt(theOffset+1))) {
|
||||
if(temp.Length())
|
||||
result=aSink.AddLeaf(theTextNode); //just dump the whole string...
|
||||
WriteNBSP(1,aSink);
|
||||
temp="";
|
||||
break;
|
||||
}
|
||||
//fall through...
|
||||
if((PR_TRUE==aPreserveSpace)) {
|
||||
if(aTextString.Length() > theOffset+1 && (kSpace==aTextString.CharAt(theOffset+1))) {
|
||||
if(temp.Length())
|
||||
result=aSink.AddLeaf(theTextNode); //just dump the whole string...
|
||||
WriteNBSP(1,aSink);
|
||||
temp="";
|
||||
break;
|
||||
}
|
||||
} //fall through...
|
||||
default:
|
||||
//scan ahead looking for valid chars...
|
||||
temp+=aTextString.CharAt(theOffset);
|
||||
|
@ -751,7 +752,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
|
|||
case eToken_text:
|
||||
{
|
||||
nsString& theText=aToken->GetStringValueXXX();
|
||||
WriteText(theText,*mSink,PR_FALSE);
|
||||
WriteText(theText,*mSink,PR_TRUE);
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -801,8 +802,8 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
|
|||
CToken* theNextToken = mTokenizer->PopToken();
|
||||
if(theNextToken) {
|
||||
theType=eHTMLTokenTypes(theNextToken->GetTokenType());
|
||||
if(eToken_skippedcontent==theType) {
|
||||
attrNode.SetSkippedContent(theNextToken);
|
||||
if(eToken_text==theType) {
|
||||
attrNode.SetSkippedContent(theNextToken->GetStringValueXXX());
|
||||
}
|
||||
}
|
||||
result= OpenHead(attrNode);
|
||||
|
@ -813,7 +814,7 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
|
|||
if(NS_OK==result)
|
||||
result=CloseHead(attrNode);
|
||||
}
|
||||
nsString& theText=((CAttributeToken*)theNextToken)->GetKey();
|
||||
const nsString& theText=attrNode.GetSkippedContent();
|
||||
WriteText(theText,*mSink,PR_FALSE);
|
||||
}
|
||||
break;
|
||||
|
|
|
@ -114,8 +114,6 @@ NS_IMPL_ADDREF(CWellFormedDTD)
|
|||
NS_IMPL_RELEASE(CWellFormedDTD)
|
||||
|
||||
|
||||
//static CTokenDeallocator gTokenKiller;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*
|
||||
|
|
|
@ -1736,11 +1736,7 @@ void nsXIFDTD::EndCSSStyleSheet(const nsIParserNode& aNode)
|
|||
mBuffer.Append("</");
|
||||
mBuffer.Append(tagName);
|
||||
mBuffer.Append(">");
|
||||
CSkippedContentToken* skipped = new CSkippedContentToken(mBuffer);
|
||||
nsString& key = skipped->GetKey();
|
||||
key = mBuffer;
|
||||
|
||||
startNode.SetSkippedContent(skipped);
|
||||
startNode.SetSkippedContent(mBuffer);
|
||||
mSink->AddLeaf(startNode);
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче