bug fixes, warning removal, perf. improvements

This commit is contained in:
rickg%netscape.com 1999-07-16 17:31:38 +00:00
Родитель df4e839971
Коммит bfdb9c587c
26 изменённых файлов: 304 добавлений и 454 удалений

Просмотреть файл

@ -58,6 +58,7 @@ static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static char* kVerificationDir = "c:/temp";
static char gShowCRC=0;
static CTokenRecycler* gRecycler=0;
static eHTMLTags gFormElementTags[]= {
@ -66,20 +67,10 @@ static eHTMLTags gFormElementTags[]= {
eHTMLTag_option, eHTMLTag_optgroup, eHTMLTag_select,
eHTMLTag_textarea};
static eHTMLTags gTableChildTags[]={
eHTMLTag_caption, eHTMLTag_col, eHTMLTag_colgroup,
eHTMLTag_tbody, eHTMLTag_tfoot, eHTMLTag_tr,
eHTMLTag_th, eHTMLTag_thead, eHTMLTag_td};
static eHTMLTags gWhitespaceTags[]={
eHTMLTag_newline, eHTMLTag_whitespace};
static eHTMLTags gHeadChildTags[]={
eHTMLTag_caption, eHTMLTag_col, eHTMLTag_colgroup, eHTMLTag_tbody,
eHTMLTag_tfoot, eHTMLTag_tr, eHTMLTag_thead, eHTMLTag_td};
static eHTMLTags gNonPropagatedTags[]={
eHTMLTag_head, eHTMLTag_html, eHTMLTag_body};
#include "nsElementTable.h"
@ -334,7 +325,7 @@ void CNavDTD::DeleteTokenHandlers(void) {
* @param
* @return
*/
CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0) {
CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSharedNodes(0) {
NS_INIT_REFCNT();
mSink = 0;
mParser=0;
@ -362,7 +353,30 @@ CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0) {
#endif
}
nsCParserNode* CNavDTD::CreateNode(void) {
nsCParserNode* result=0;
if(0<mSharedNodes.GetSize()) {
result=(nsCParserNode*)mSharedNodes.Pop();
}
else{
result=new nsCParserNode();
}
return result;
}
void CNavDTD::RecycleNode(nsCParserNode* aNode) {
if(aNode) {
CToken* theToken=0;
while(theToken=(CToken*)aNode->PopAttributeToken()){
gRecycler->RecycleToken(theToken);
}
mSharedNodes.Push(aNode);
}
}
/**
*
* @update gess1/8/99
@ -386,6 +400,10 @@ CNavDTD::~CNavDTD(){
delete mBodyContext;
if(mTokenizer)
delete (nsHTMLTokenizer*)mTokenizer;
nsCParserNode* theNode=0;
while(theNode=(nsCParserNode*)mSharedNodes.Pop()){
delete theNode;
}
NS_IF_RELEASE(mDTDDebug);
}
@ -498,7 +516,6 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString
return result;
}
CTokenRecycler* gRecycler=0;
/**
* This is called when it's time to read as many tokens from the tokenizer
@ -808,103 +825,6 @@ PRInt32 GetTopmostIndexOf(eHTMLTags aTag,nsEntryStack& aTagStack) {
return kNotFound;
}
/**
* This method is called to determine whether or not a START tag
* can be autoclosed. This means that based on the current
* context, the stack should be closed to the nearest matching
* tag.
*
* @param aTag -- tag enum of child to be tested
* @return index of tag to be closed
*/
static PRInt32 FindAutoCloseTargetForStartTag2(eHTMLTags aChild,nsEntryStack& aTagStack,CNavDTD& aDTD) {
PRInt32 max=aTagStack.GetCount();
if(nsHTMLElement::IsContainer(aChild)){
PRInt32 index=max;
CTagList* theRootTags=gHTMLElements[aChild].GetRootTags();
while(--index>=0){
eHTMLTags thePrevTag=aTagStack.TagAt(index);
if((theRootTags) && (theRootTags->Contains(thePrevTag))) {
return index+1;
}
if(aDTD.CanOmit(thePrevTag,aChild)){
return index+1;
}
if(aDTD.CanContain(thePrevTag,aChild)){
return index+1;
}
}
}
return max; //which means don't close anything...
}
/**
* This method is called to determine whether or not a START tag
* can be autoclosed. This means that based on the current
* context, the stack should be closed to the nearest matching
* tag.
*
* @param aTag -- tag enum of child to be tested
* @return PR_TRUE if autoclosure should occur
*/
static
eHTMLTags FindAutoCloseTargetForStartTag(eHTMLTags aCurrentTag,nsEntryStack& aTagStack) {
int theTopIndex = aTagStack.GetCount();
eHTMLTags thePrevTag=aTagStack.Last();
if(nsHTMLElement::IsContainer(aCurrentTag)){
if(thePrevTag==aCurrentTag) {
return (gHTMLElements[aCurrentTag].CanContainSelf()) ? eHTMLTag_unknown: aCurrentTag;
}
CTagList* theRootTags=gHTMLElements[aCurrentTag].GetRootTags();
PRInt32 theRootIndex=(theRootTags) ? theRootTags->GetTopmostIndexOf(aTagStack) : kNotFound;
if(nsHTMLElement::IsBlockCloser(aCurrentTag)) {
if(theRootTags) {
CTagList* theStartTags=gHTMLElements[aCurrentTag].GetAutoCloseStartTags();
PRInt32 thePeerIndex=kNotFound;
if(theStartTags){
thePeerIndex=theStartTags->GetBottommostIndexOf(aTagStack,theRootIndex+1);
}
else {
//this extra check is need to handle case like this: <DIV><P><DIV>
//the new div can close the P,but doesn't close the top DIV.
thePeerIndex=GetTopmostIndexOf(aCurrentTag,aTagStack);
if(gHTMLElements[aCurrentTag].CanContainSelf()) {
thePeerIndex++;
}
}
if(theRootIndex<thePeerIndex) {
return aTagStack[thePeerIndex]; //return the tag that was used in peer test.
}
}
CTagList* theCloseTags=gHTMLElements[aCurrentTag].GetAutoCloseStartTags();
if(theCloseTags){
PRInt32 thePeerIndex=theCloseTags->GetTopmostIndexOf(aTagStack);
if(kNotFound!=thePeerIndex){
if(thePeerIndex==theTopIndex-1) {
//the guy you can autoclose is on the top of the stack...
return thePrevTag;
} //if
} //if
}//if
} //if isblockcloser
if(kNotFound<theRootIndex) {
//This block handles our fallback cases like: <html><body><center><p> <- <table>
while((theRootIndex<--theTopIndex) && (!gHTMLElements[aTagStack[theTopIndex]].CanContain(aCurrentTag))) {
}
return aTagStack[theTopIndex+1];
//return aTagStack.mTags[theRootIndex+1];
} //else
} //if
return eHTMLTag_unknown;
}
/**
* Call this to find the index of a given child, or (if not found)
@ -1358,25 +1278,28 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
#endif
//Begin by gathering up attributes...
nsCParserNode* theNode=CreateNode();
theNode->Init(aToken,mLineNumber,GetTokenRecycler());
eHTMLTags theChildTag=(eHTMLTags)aToken->GetTypeID();
nsCParserNode attrNode((CHTMLToken*)aToken,mLineNumber,GetTokenRecycler());
PRInt16 attrCount=aToken->GetAttributeCount();
nsresult result=(0==attrCount) ? NS_OK : CollectAttributes(attrNode,theChildTag,attrCount);
nsresult result=(0==attrCount) ? NS_OK : CollectAttributes(*theNode,theChildTag,attrCount);
eHTMLTags theParent=mBodyContext->Last();
if(NS_OK==result) {
result=WillHandleStartTag(aToken,theChildTag,attrNode);
result=WillHandleStartTag(aToken,theChildTag,*theNode);
if(NS_OK==result) {
if(nsHTMLElement::IsSectionTag(theChildTag)){
switch(theChildTag){
case eHTMLTag_body:
if(mHasOpenBody)
return OpenContainer(attrNode,PR_FALSE);
return OpenContainer(*theNode,PR_FALSE);
break;
case eHTMLTag_head:
if(mHadBody || mHadFrameset) {
result=HandleOmittedTag(aToken,theChildTag,theParent,attrNode);
result=HandleOmittedTag(aToken,theChildTag,theParent,*theNode);
if(result == NS_OK)
return result;
}
@ -1391,7 +1314,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
case eHTMLTag_area:
if (mHasOpenMap && mSink)
result=mSink->AddLeaf(attrNode);
result=mSink->AddLeaf(*theNode);
break;
case eHTMLTag_comment:
@ -1405,20 +1328,21 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
default:
{
if(theHeadIsParent)
result=AddHeadLeaf(attrNode);
else result=HandleDefaultStartToken(aToken,theChildTag,attrNode);
result=AddHeadLeaf(*theNode);
else result=HandleDefaultStartToken(aToken,theChildTag,*theNode);
}
break;
} //switch
//now do any post processing necessary on the tag...
if(NS_OK==result)
DidHandleStartTag(attrNode,theChildTag);
DidHandleStartTag(*theNode,theChildTag);
}
} //if
if(eHTMLTag_newline==theChildTag)
mLineNumber++;
RecycleNode(theNode);
return result;
}
@ -1436,7 +1360,7 @@ PRBool HasCloseablePeerAboveRoot(CTagList& aRootTagList,nsEntryStack& aTagStack,
PRInt32 theRootIndex=aRootTagList.GetTopmostIndexOf(aTagStack);
CTagList* theCloseTags=(anEndTag) ? gHTMLElements[aTag].GetAutoCloseEndTags() : gHTMLElements[aTag].GetAutoCloseStartTags();
PRInt32 theChildIndex=-1;
PRBool result=PR_FALSE;
if(theCloseTags) {
theChildIndex=theCloseTags->GetTopmostIndexOf(aTagStack);
}
@ -1627,7 +1551,8 @@ nsresult CNavDTD::HandleSavedTokensAbove(eHTMLTags aTag)
nsDTDContext temp;
// The body context should contain contents only upto the marked position.
for(PRInt32 i=0; i<(theTagCount - theTopIndex); i++)
PRInt32 i=0;
for(i=0; i<(theTagCount - theTopIndex); i++)
temp.Push(mBodyContext->Pop());
// Now flush out all the bad contents.
@ -1638,7 +1563,7 @@ nsresult CNavDTD::HandleSavedTokensAbove(eHTMLTags aTag)
if(theTag != eHTMLTag_unknown) {
attrCount = theToken->GetAttributeCount();
// Put back attributes, which once got popped out, into the tokenizer
for(PRInt32 i=0;i<attrCount; i++){
for(i=0;i<attrCount; i++){
CToken* theAttrToken = mBodyContext->RestoreTokenFrom(theBadContentIndex);
if(theAttrToken) {
mTokenizer->PushTokenFront(theAttrToken);
@ -1676,7 +1601,6 @@ nsresult CNavDTD::HandleSavedTokensAbove(eHTMLTags aTag)
nsresult CNavDTD::HandleEntityToken(CToken* aToken) {
NS_PRECONDITION(0!=aToken,kNullToken);
CEntityToken* et = (CEntityToken*)(aToken);
nsresult result=NS_OK;
if(PR_FALSE==CanOmit(mBodyContext->Last(),eHTMLTag_entity)) {
@ -1757,8 +1681,7 @@ nsresult CNavDTD::HandleAttributeToken(CToken* aToken) {
* @return PR_TRUE if all went well; PR_FALSE if error occured
*/
nsresult CNavDTD::HandleScriptToken(nsCParserNode& aNode) {
PRInt32 pos=GetTopmostIndexOf(eHTMLTag_body);
PRInt32 attrCount=aNode.GetAttributeCount(PR_TRUE);
// PRInt32 attrCount=aNode.GetAttributeCount(PR_TRUE);
nsresult result=AddLeaf(aNode);
return result;
@ -2156,17 +2079,6 @@ eHTMLTags CNavDTD::GetTopNode() const {
return mBodyContext->Last();
}
/**
* Finds the topmost occurance of given tag within context vector stack.
* @update gess5/11/98
* @param tag to be found
* @return index of topmost tag occurance -- may be -1 (kNotFound).
*/
static
PRInt32 GetTopmostIndexOfBelowOffset(eHTMLTags aTag,PRInt32 anOffset){
PRInt32 result=-1;
return result;
}
/**
* Determine whether the given tag is open anywhere
@ -2266,10 +2178,11 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aChildTag){
nsresult CNavDTD::CloseTransientStyles(eHTMLTags aChildTag){
nsresult result=NS_OK;
#ifdef ENABLE_RESIDUALSTYLE
int theTagPos=0;
//now iterate style set, and close the containers...
#ifdef ENABLE_RESIDUALSTYLE
nsDeque* theStyleDeque=mBodyContext->GetStyles();
for(theTagPos=mBodyContext->mOpenStyles;theTagPos>0;theTagPos--){
eHTMLTags theTag=GetTopNode();
@ -2325,10 +2238,11 @@ nsresult CNavDTD::CloseHTML(const nsIParserNode& aNode){
*/
nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
//mBodyContext->Push(eHTMLTag_head);
nsresult result=NS_OK;
if(!mHasOpenHead++) {
nsresult result=(mSink) ? mSink->OpenHead(aNode) : NS_OK;
result=(mSink) ? mSink->OpenHead(aNode) : NS_OK;
}
return NS_OK;
return result;
}
/**
@ -2340,13 +2254,14 @@ nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseHead(const nsIParserNode& aNode){
nsresult result=NS_OK;
if(mHasOpenHead) {
if(0==--mHasOpenHead){
nsresult result=(mSink) ? mSink->CloseHead(aNode) : NS_OK;
result=(mSink) ? mSink->CloseHead(aNode) : NS_OK;
}
}
//mBodyContext->Pop();
return NS_OK;
return result;
}
/**
@ -2843,7 +2758,6 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){
kPropagationStack.Empty();
nsresult result=(nsresult)kContextMismatch;
PRInt32 cnt=0;
eHTMLTags theTop=mBodyContext->Last();
PRBool bResult=ForwardPropagate(kPropagationStack,theTop,aChildTag);

Просмотреть файл

@ -85,6 +85,7 @@
#include "nshtmlpars.h"
#include "nsVoidArray.h"
#include "nsDeque.h"
#include "nsParserNode.h"
#define NS_INAVHTML_DTD_IID \
{0x5c5cce40, 0xcfd6, 0x11d1, \
@ -94,7 +95,6 @@
class nsIHTMLContentSink;
class nsIDTDDebug;
class nsIParserNode;
class nsCParserNode;
class CITokenHandler;
class nsParser;
class nsDTDContext;
@ -490,12 +490,14 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
protected:
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);
nsresult HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode& aNode);
nsresult HandleSavedTokensAbove(eHTMLTags aTag);
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);
nsresult HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode& aNode);
nsresult HandleSavedTokensAbove(eHTMLTags aTag);
nsCParserNode* CreateNode(void);
void RecycleNode(nsCParserNode* aNode);
nsIHTMLContentSink* mSink;
@ -521,6 +523,7 @@ protected:
PRBool mHasOpenScript;
PRBool mSaveBadTokens;
eHTMLTags mSkipTarget;
nsDeque mSharedNodes;
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;

Просмотреть файл

@ -481,18 +481,17 @@ PRInt32 CRTFControlWord::GetTokenType() {
return eRTFToken_controlword;
}
PRInt32 CRTFControlWord::Consume(nsScanner& aScanner){
nsresult CRTFControlWord::Consume(PRUnichar aChar,nsScanner& aScanner) {
static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
static nsAutoString gDigits("-0123456789");
PRInt32 result=aScanner.ReadWhile(mTextValue,gAlphaChars,PR_TRUE,PR_FALSE);
if(NS_OK==result) {
//ok, now look for an option parameter...
PRUnichar ch;
result=aScanner.Peek(ch);
switch(ch) {
result=aScanner.Peek(aChar);
switch(aChar) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case kMinus:
@ -531,7 +530,7 @@ PRBool CRTFGroup::IsGroupStart(){
return mStart;
}
PRInt32 CRTFGroup::Consume(nsScanner& aScanner){
nsresult CRTFGroup::Consume(PRUnichar aChar,nsScanner& aScanner) {
PRInt32 result=NS_OK;
if(PR_FALSE==mStart)
result=aScanner.SkipWhitespace();
@ -561,7 +560,8 @@ PRInt32 CRTFContent::GetTokenType() {
* @return
*/
static nsString textTerminators("\\{}");
PRInt32 CRTFContent::Consume(nsScanner& aScanner){
nsresult CRTFContent::Consume(PRUnichar aChar,nsScanner& aScanner) {
PRInt32 result=aScanner.ReadUntil(mTextValue,textTerminators,PR_FALSE,PR_FALSE);
return result;
}

Просмотреть файл

@ -102,7 +102,7 @@ class CRTFControlWord : public CToken {
public:
CRTFControlWord(char* aKey);
virtual PRInt32 GetTokenType();
virtual PRInt32 Consume(nsScanner& aScanner);
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
protected:
nsString mArgument;
};
@ -120,7 +120,7 @@ public:
virtual PRInt32 GetTokenType();
virtual void SetGroupStart(PRBool aFlag);
virtual PRBool IsGroupStart();
virtual PRInt32 Consume(nsScanner& aScanner);
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
protected:
PRBool mStart;
};
@ -136,7 +136,7 @@ class CRTFContent: public CToken {
public:
CRTFContent(PRUnichar* aValue);
virtual PRInt32 GetTokenType();
virtual PRInt32 Consume(nsScanner& aScanner);
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
};

Просмотреть файл

@ -462,9 +462,11 @@ void CTokenRecycler::RecycleToken(CToken* aToken) {
PRInt32 theType=aToken->GetTokenType();
CTokenFinder finder(aToken);
CToken* theMatch=(CToken*)mTokenCache[theType-1]->FirstThat(finder);
#ifdef NS_DEBUG
if(theMatch) {
int x=5;
}
#endif
mTokenCache[theType-1]->Push(aToken);
}
}

Просмотреть файл

@ -1691,9 +1691,6 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{
}
}
if(mTagID!=eHTMLTag_server){
int x=5;
}
}
return PR_FALSE;

Просмотреть файл

@ -816,7 +816,6 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
if(kMinus==aChar) {
//in this case, we're reading a long-form comment <-- xxx -->
aString+=aChar;
PRBool done=PR_FALSE;
PRInt32 findpos=kNotFound;
result=aScanner.ReadWhile(aString,gMinus,PR_TRUE,PR_TRUE); //get all available '---'
findpos=aString.RFind("-->");
@ -1523,7 +1522,6 @@ PRInt32 CEntityToken::TranslateToUnicodeStr(nsString& aString) {
if(mTextValue.Length()>1) {
PRUnichar theChar0=mTextValue.CharAt(0);
PRBool isDigit0=nsString::IsDigit(theChar0);
if(kHashsign==theChar0) {
PRInt32 err=0;

Просмотреть файл

@ -221,14 +221,14 @@ class nsIParser : public nsISupports {
#define NS_ERROR_HTMLPARSER_CONTINUE NS_OK
const PRInt32 kEOF = NS_ERROR_HTMLPARSER_EOF;
const PRInt32 kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN;
const PRInt32 kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
const PRInt32 kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
const PRInt32 kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME;
const PRInt32 kBadURL = NS_ERROR_HTMLPARSER_BADURL;
const PRInt32 kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
const PRInt32 kBlocked = NS_ERROR_HTMLPARSER_BLOCK;
const PRUint32 kEOF = NS_ERROR_HTMLPARSER_EOF;
const PRUint32 kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN;
const PRUint32 kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
const PRUint32 kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
const PRUint32 kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME;
const PRUint32 kBadURL = NS_ERROR_HTMLPARSER_BADURL;
const PRUint32 kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
const PRUint32 kBlocked = NS_ERROR_HTMLPARSER_BLOCK;
const PRUint32 kNewLine = '\n';
const PRUint32 kCR = '\r';

Просмотреть файл

@ -43,13 +43,21 @@ nsAutoString& GetEmptyString() {
nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler):
nsIParserNode(), mSkippedContent("") {
NS_INIT_REFCNT();
mAttributeCount=0;
static int theNodeCount=0;
theNodeCount++;
mAttributes=0;
mLineNumber=aLineNumber;
mToken=aToken;
memset(mAttributes,0,sizeof(mAttributes));
mRecycler=aRecycler;
}
static void RecycleTokens(nsITokenRecycler* aRecycler,nsDeque& aDeque) {
CToken* theToken=0;
while(theToken=(CToken*)aDeque.Pop()){
aRecycler->RecycleToken(theToken);
}
}
/**
* default destructor
@ -60,11 +68,9 @@ nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler
* @return
*/
nsCParserNode::~nsCParserNode() {
if(mRecycler) {
PRUint32 index=0;
for(index=0;index<mAttributeCount;index++){
mRecycler->RecycleToken(mAttributes[index]);
}
if(mRecycler && mAttributes) {
RecycleTokens(mRecycler,*mAttributes);
delete mAttributes;
}
}
@ -79,10 +85,11 @@ NS_IMPL_RELEASE(nsCParserNode)
* @return
*/
nsresult nsCParserNode::Init(CToken* aToken,PRInt32 aLineNumber)
{
nsresult nsCParserNode::Init(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler) {
mLineNumber=aLineNumber;
mAttributeCount=0;
mRecycler=aRecycler;
if(mAttributes && (mAttributes->GetSize()))
RecycleTokens(mRecycler,*mAttributes);
mToken=aToken;
return NS_OK;
}
@ -130,13 +137,12 @@ nsresult nsCParserNode::QueryInterface(const nsIID& aIID, void** aInstancePtr)
* @return
*/
void nsCParserNode::AddAttribute(CToken* aToken) {
NS_PRECONDITION(mAttributeCount<eMaxAttr, "Buffer overrun!");
NS_PRECONDITION(0!=aToken, "Error: Token shouldn't be null!");
if(mAttributeCount<eMaxAttr) {
if(aToken) {
mAttributes[mAttributeCount++]=aToken;
}
if(!mAttributes)
mAttributes=new nsDeque(0);
if(mAttributes) {
mAttributes->Push(aToken);
}
}
@ -224,9 +230,14 @@ PRInt32 nsCParserNode::GetTokenType(void) const{
* @return int -- representing attribute count
*/
PRInt32 nsCParserNode::GetAttributeCount(PRBool askToken) const{
if(PR_TRUE==askToken)
return mToken->GetAttributeCount();
return mAttributeCount;
PRInt32 result=0;
if(PR_FALSE==askToken) {
if(mAttributes)
result=mAttributes->GetSize();
}
else result=mToken->GetAttributeCount();
return result;
}
/**
@ -238,8 +249,9 @@ PRInt32 nsCParserNode::GetAttributeCount(PRBool askToken) const{
* @return string rep of given attribute text key
*/
const nsString& nsCParserNode::GetKeyAt(PRUint32 anIndex) const {
if(anIndex<mAttributeCount) {
CAttributeToken* tkn=(CAttributeToken*)(mAttributes[anIndex]);
PRInt32 theCount = (mAttributes) ? mAttributes->GetSize() : 0;
if((PRInt32)anIndex<theCount) {
CAttributeToken* tkn=(CAttributeToken*)mAttributes->ObjectAt(anIndex);
return tkn->GetKey();
}
return GetEmptyString();
@ -254,9 +266,13 @@ const nsString& nsCParserNode::GetKeyAt(PRUint32 anIndex) const {
* @return string rep of given attribute text value
*/
const nsString& nsCParserNode::GetValueAt(PRUint32 anIndex) const {
NS_PRECONDITION(anIndex<mAttributeCount, "Bad attr index");
if(anIndex<mAttributeCount){
return (mAttributes[anIndex])->GetStringValueXXX();
PRInt32 theCount = (mAttributes) ? mAttributes->GetSize() : 0;
NS_PRECONDITION(PRInt32(anIndex)<theCount, "Bad attr index");
if(PRInt32(anIndex)<theCount) {
CAttributeToken* tkn=(CAttributeToken*)mAttributes->ObjectAt(anIndex);
return tkn->GetStringValueXXX();
}
return GetEmptyString();
}
@ -286,13 +302,11 @@ PRInt32 nsCParserNode::GetSourceLineNumber(void) const {
* @return token at anIndex
*/
CToken* nsCParserNode::PopAttributeToken()
{
NS_PRECONDITION(mAttributeCount<eMaxAttr, "Buffer overrun!");
if(mAttributeCount > 0) {
CToken* theAttrToken = mAttributes[--mAttributeCount];
mAttributes[mAttributeCount] = nsnull;
return theAttrToken;
CToken* nsCParserNode::PopAttributeToken() {
CToken* result=0;
if(mAttributes) {
result =(CToken*)mAttributes->Pop();
}
return nsnull;
return result;
}

Просмотреть файл

@ -40,11 +40,11 @@
#include "nsToken.h"
#include "nsString.h"
#include "nsParserCIID.h"
#include "nsDeque.h"
class nsITokenRecycler;
class nsCParserNode : public nsIParserNode {
enum {eMaxAttr=20};
public:
@ -67,7 +67,7 @@ class nsCParserNode : public nsIParserNode {
* Init
* @update gess5/11/98
*/
virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1);
virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsITokenRecycler* aRecycler=0);
/**
* Retrieve the name of the node
@ -170,11 +170,11 @@ class nsCParserNode : public nsIParserNode {
virtual CToken* PopAttributeToken();
protected:
PRUint32 mAttributeCount;
PRInt32 mLineNumber;
CToken* mToken;
CToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic!
nsDeque* mAttributes;
nsAutoString mSkippedContent;
nsITokenRecycler* mRecycler;
};

Просмотреть файл

@ -53,7 +53,7 @@ nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharset
mIncremental=PR_TRUE;
mOwnsStream=PR_FALSE;
mOffset=0;
mMarkPos=-1;
mMarkPos=0;
mInputStream=0;
mUnicodeDecoder = 0;
mCharset = "";
@ -75,7 +75,7 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
{
mIncremental=PR_TRUE;
mOffset=0;
mMarkPos=-1;
mMarkPos=0;
mTotalRead=0;
mOwnsStream=aCreateStream;
mInputStream=0;
@ -103,7 +103,7 @@ nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString&
{
mIncremental=PR_TRUE;
mOffset=0;
mMarkPos=-1;
mMarkPos=0;
mTotalRead=0;
mOwnsStream=assumeOwnership;
mInputStream=&aStream;

Просмотреть файл

@ -242,11 +242,10 @@ static void SetStyle(eHTMLTags theTag,PRBool aEnable,nsIContentSink& aSink) {
* @param
* @return
*/
CViewSourceHTML::CViewSourceHTML() : nsIDTD() {
CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mFilename("") {
NS_INIT_REFCNT();
mParser=0;
mSink=0;
mFilename;
mLineNumber=0;
mTokenizer=0;
mIsHTML=PR_FALSE;
@ -605,7 +604,6 @@ nsresult WriteText(const nsString& aTextString,nsIContentSink& aSink,PRBool aPre
PRInt32 theTextOffset=0;
PRInt32 theOffset=-1; //aTextString.FindCharInSet("\t\n\r ",theStartOffset);
PRInt32 theSpaces=0;
PRBool theOutputReady=PR_FALSE;
PRUnichar theChar=0;
PRUnichar theNextChar=0;
@ -877,8 +875,8 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
case eToken_style:
case eToken_skippedcontent:
{
CAttributeToken* theToken=(CAttributeToken*)aToken;
nsString& theText=theToken->GetKey();
CAttributeToken* theAToken=(CAttributeToken*)aToken;
nsString& theText=theAToken->GetKey();
::WriteText(theText,*mSink,PR_FALSE,mIsPlaintext,theContext);
}
break;
@ -922,12 +920,12 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
if(0<attrCount){ //go collect the attributes...
int attr=0;
for(attr=0;attr<attrCount;attr++){
CToken* theToken=mTokenizer->PeekToken();
if(theToken) {
eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType());
if(eToken_attribute==theType){
CToken* theInnerToken=mTokenizer->PeekToken();
if(theInnerToken) {
eHTMLTokenTypes theInnerType=eHTMLTokenTypes(theInnerToken->GetTokenType());
if(eToken_attribute==theInnerType){
mTokenizer->PopToken(); //pop it for real...
theContext.mTokenNode.AddAttribute(theToken);
theContext.mTokenNode.AddAttribute(theInnerToken);
}
}
else return kEOF;

Просмотреть файл

@ -120,11 +120,10 @@ NS_IMPL_RELEASE(CWellFormedDTD)
* @param
* @return
*/
CWellFormedDTD::CWellFormedDTD() : nsIDTD() {
CWellFormedDTD::CWellFormedDTD() : nsIDTD(), mFilename("") {
NS_INIT_REFCNT();
mParser=0;
mSink=0;
mFilename;
mLineNumber=0;
mTokenizer=0;
}
@ -452,12 +451,12 @@ NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
if(0<attrCount){ //go collect the attributes...
int attr=0;
for(attr=0;attr<attrCount;attr++){
CToken* theToken=mTokenizer->PeekToken();
if(theToken) {
eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType());
if(eToken_attribute==theType){
CToken* theInnerToken=mTokenizer->PeekToken();
if(theInnerToken) {
eHTMLTokenTypes theInnerType=eHTMLTokenTypes(theInnerToken->GetTokenType());
if(eToken_attribute==theInnerType){
mTokenizer->PopToken(); //pop it for real...
theNode.AddAttribute(theToken);
theNode.AddAttribute(theInnerToken);
}
}
else return kEOF;

Просмотреть файл

@ -58,6 +58,7 @@ static const char* kNullToken = "Error: Null token given";
static const char* kInvalidTagStackPos = "Error: invalid tag stack position";
static char* kVerificationDir = "c:/temp";
static char gShowCRC=0;
static CTokenRecycler* gRecycler=0;
static eHTMLTags gFormElementTags[]= {
@ -66,20 +67,10 @@ static eHTMLTags gFormElementTags[]= {
eHTMLTag_option, eHTMLTag_optgroup, eHTMLTag_select,
eHTMLTag_textarea};
static eHTMLTags gTableChildTags[]={
eHTMLTag_caption, eHTMLTag_col, eHTMLTag_colgroup,
eHTMLTag_tbody, eHTMLTag_tfoot, eHTMLTag_tr,
eHTMLTag_th, eHTMLTag_thead, eHTMLTag_td};
static eHTMLTags gWhitespaceTags[]={
eHTMLTag_newline, eHTMLTag_whitespace};
static eHTMLTags gHeadChildTags[]={
eHTMLTag_caption, eHTMLTag_col, eHTMLTag_colgroup, eHTMLTag_tbody,
eHTMLTag_tfoot, eHTMLTag_tr, eHTMLTag_thead, eHTMLTag_td};
static eHTMLTags gNonPropagatedTags[]={
eHTMLTag_head, eHTMLTag_html, eHTMLTag_body};
#include "nsElementTable.h"
@ -334,7 +325,7 @@ void CNavDTD::DeleteTokenHandlers(void) {
* @param
* @return
*/
CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0) {
CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0), mSharedNodes(0) {
NS_INIT_REFCNT();
mSink = 0;
mParser=0;
@ -362,7 +353,30 @@ CNavDTD::CNavDTD() : nsIDTD(), mMisplacedContent(0), mSkippedContent(0) {
#endif
}
nsCParserNode* CNavDTD::CreateNode(void) {
nsCParserNode* result=0;
if(0<mSharedNodes.GetSize()) {
result=(nsCParserNode*)mSharedNodes.Pop();
}
else{
result=new nsCParserNode();
}
return result;
}
void CNavDTD::RecycleNode(nsCParserNode* aNode) {
if(aNode) {
CToken* theToken=0;
while(theToken=(CToken*)aNode->PopAttributeToken()){
gRecycler->RecycleToken(theToken);
}
mSharedNodes.Push(aNode);
}
}
/**
*
* @update gess1/8/99
@ -386,6 +400,10 @@ CNavDTD::~CNavDTD(){
delete mBodyContext;
if(mTokenizer)
delete (nsHTMLTokenizer*)mTokenizer;
nsCParserNode* theNode=0;
while(theNode=(nsCParserNode*)mSharedNodes.Pop()){
delete theNode;
}
NS_IF_RELEASE(mDTDDebug);
}
@ -498,7 +516,6 @@ nsresult CNavDTD::WillBuildModel(nsString& aFilename,PRBool aNotifySink,nsString
return result;
}
CTokenRecycler* gRecycler=0;
/**
* This is called when it's time to read as many tokens from the tokenizer
@ -808,103 +825,6 @@ PRInt32 GetTopmostIndexOf(eHTMLTags aTag,nsEntryStack& aTagStack) {
return kNotFound;
}
/**
* This method is called to determine whether or not a START tag
* can be autoclosed. This means that based on the current
* context, the stack should be closed to the nearest matching
* tag.
*
* @param aTag -- tag enum of child to be tested
* @return index of tag to be closed
*/
static PRInt32 FindAutoCloseTargetForStartTag2(eHTMLTags aChild,nsEntryStack& aTagStack,CNavDTD& aDTD) {
PRInt32 max=aTagStack.GetCount();
if(nsHTMLElement::IsContainer(aChild)){
PRInt32 index=max;
CTagList* theRootTags=gHTMLElements[aChild].GetRootTags();
while(--index>=0){
eHTMLTags thePrevTag=aTagStack.TagAt(index);
if((theRootTags) && (theRootTags->Contains(thePrevTag))) {
return index+1;
}
if(aDTD.CanOmit(thePrevTag,aChild)){
return index+1;
}
if(aDTD.CanContain(thePrevTag,aChild)){
return index+1;
}
}
}
return max; //which means don't close anything...
}
/**
* This method is called to determine whether or not a START tag
* can be autoclosed. This means that based on the current
* context, the stack should be closed to the nearest matching
* tag.
*
* @param aTag -- tag enum of child to be tested
* @return PR_TRUE if autoclosure should occur
*/
static
eHTMLTags FindAutoCloseTargetForStartTag(eHTMLTags aCurrentTag,nsEntryStack& aTagStack) {
int theTopIndex = aTagStack.GetCount();
eHTMLTags thePrevTag=aTagStack.Last();
if(nsHTMLElement::IsContainer(aCurrentTag)){
if(thePrevTag==aCurrentTag) {
return (gHTMLElements[aCurrentTag].CanContainSelf()) ? eHTMLTag_unknown: aCurrentTag;
}
CTagList* theRootTags=gHTMLElements[aCurrentTag].GetRootTags();
PRInt32 theRootIndex=(theRootTags) ? theRootTags->GetTopmostIndexOf(aTagStack) : kNotFound;
if(nsHTMLElement::IsBlockCloser(aCurrentTag)) {
if(theRootTags) {
CTagList* theStartTags=gHTMLElements[aCurrentTag].GetAutoCloseStartTags();
PRInt32 thePeerIndex=kNotFound;
if(theStartTags){
thePeerIndex=theStartTags->GetBottommostIndexOf(aTagStack,theRootIndex+1);
}
else {
//this extra check is need to handle case like this: <DIV><P><DIV>
//the new div can close the P,but doesn't close the top DIV.
thePeerIndex=GetTopmostIndexOf(aCurrentTag,aTagStack);
if(gHTMLElements[aCurrentTag].CanContainSelf()) {
thePeerIndex++;
}
}
if(theRootIndex<thePeerIndex) {
return aTagStack[thePeerIndex]; //return the tag that was used in peer test.
}
}
CTagList* theCloseTags=gHTMLElements[aCurrentTag].GetAutoCloseStartTags();
if(theCloseTags){
PRInt32 thePeerIndex=theCloseTags->GetTopmostIndexOf(aTagStack);
if(kNotFound!=thePeerIndex){
if(thePeerIndex==theTopIndex-1) {
//the guy you can autoclose is on the top of the stack...
return thePrevTag;
} //if
} //if
}//if
} //if isblockcloser
if(kNotFound<theRootIndex) {
//This block handles our fallback cases like: <html><body><center><p> <- <table>
while((theRootIndex<--theTopIndex) && (!gHTMLElements[aTagStack[theTopIndex]].CanContain(aCurrentTag))) {
}
return aTagStack[theTopIndex+1];
//return aTagStack.mTags[theRootIndex+1];
} //else
} //if
return eHTMLTag_unknown;
}
/**
* Call this to find the index of a given child, or (if not found)
@ -1358,25 +1278,28 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
#endif
//Begin by gathering up attributes...
nsCParserNode* theNode=CreateNode();
theNode->Init(aToken,mLineNumber,GetTokenRecycler());
eHTMLTags theChildTag=(eHTMLTags)aToken->GetTypeID();
nsCParserNode attrNode((CHTMLToken*)aToken,mLineNumber,GetTokenRecycler());
PRInt16 attrCount=aToken->GetAttributeCount();
nsresult result=(0==attrCount) ? NS_OK : CollectAttributes(attrNode,theChildTag,attrCount);
nsresult result=(0==attrCount) ? NS_OK : CollectAttributes(*theNode,theChildTag,attrCount);
eHTMLTags theParent=mBodyContext->Last();
if(NS_OK==result) {
result=WillHandleStartTag(aToken,theChildTag,attrNode);
result=WillHandleStartTag(aToken,theChildTag,*theNode);
if(NS_OK==result) {
if(nsHTMLElement::IsSectionTag(theChildTag)){
switch(theChildTag){
case eHTMLTag_body:
if(mHasOpenBody)
return OpenContainer(attrNode,PR_FALSE);
return OpenContainer(*theNode,PR_FALSE);
break;
case eHTMLTag_head:
if(mHadBody || mHadFrameset) {
result=HandleOmittedTag(aToken,theChildTag,theParent,attrNode);
result=HandleOmittedTag(aToken,theChildTag,theParent,*theNode);
if(result == NS_OK)
return result;
}
@ -1391,7 +1314,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
case eHTMLTag_area:
if (mHasOpenMap && mSink)
result=mSink->AddLeaf(attrNode);
result=mSink->AddLeaf(*theNode);
break;
case eHTMLTag_comment:
@ -1405,20 +1328,21 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
default:
{
if(theHeadIsParent)
result=AddHeadLeaf(attrNode);
else result=HandleDefaultStartToken(aToken,theChildTag,attrNode);
result=AddHeadLeaf(*theNode);
else result=HandleDefaultStartToken(aToken,theChildTag,*theNode);
}
break;
} //switch
//now do any post processing necessary on the tag...
if(NS_OK==result)
DidHandleStartTag(attrNode,theChildTag);
DidHandleStartTag(*theNode,theChildTag);
}
} //if
if(eHTMLTag_newline==theChildTag)
mLineNumber++;
RecycleNode(theNode);
return result;
}
@ -1436,7 +1360,7 @@ PRBool HasCloseablePeerAboveRoot(CTagList& aRootTagList,nsEntryStack& aTagStack,
PRInt32 theRootIndex=aRootTagList.GetTopmostIndexOf(aTagStack);
CTagList* theCloseTags=(anEndTag) ? gHTMLElements[aTag].GetAutoCloseEndTags() : gHTMLElements[aTag].GetAutoCloseStartTags();
PRInt32 theChildIndex=-1;
PRBool result=PR_FALSE;
if(theCloseTags) {
theChildIndex=theCloseTags->GetTopmostIndexOf(aTagStack);
}
@ -1627,7 +1551,8 @@ nsresult CNavDTD::HandleSavedTokensAbove(eHTMLTags aTag)
nsDTDContext temp;
// The body context should contain contents only upto the marked position.
for(PRInt32 i=0; i<(theTagCount - theTopIndex); i++)
PRInt32 i=0;
for(i=0; i<(theTagCount - theTopIndex); i++)
temp.Push(mBodyContext->Pop());
// Now flush out all the bad contents.
@ -1638,7 +1563,7 @@ nsresult CNavDTD::HandleSavedTokensAbove(eHTMLTags aTag)
if(theTag != eHTMLTag_unknown) {
attrCount = theToken->GetAttributeCount();
// Put back attributes, which once got popped out, into the tokenizer
for(PRInt32 i=0;i<attrCount; i++){
for(i=0;i<attrCount; i++){
CToken* theAttrToken = mBodyContext->RestoreTokenFrom(theBadContentIndex);
if(theAttrToken) {
mTokenizer->PushTokenFront(theAttrToken);
@ -1676,7 +1601,6 @@ nsresult CNavDTD::HandleSavedTokensAbove(eHTMLTags aTag)
nsresult CNavDTD::HandleEntityToken(CToken* aToken) {
NS_PRECONDITION(0!=aToken,kNullToken);
CEntityToken* et = (CEntityToken*)(aToken);
nsresult result=NS_OK;
if(PR_FALSE==CanOmit(mBodyContext->Last(),eHTMLTag_entity)) {
@ -1757,8 +1681,7 @@ nsresult CNavDTD::HandleAttributeToken(CToken* aToken) {
* @return PR_TRUE if all went well; PR_FALSE if error occured
*/
nsresult CNavDTD::HandleScriptToken(nsCParserNode& aNode) {
PRInt32 pos=GetTopmostIndexOf(eHTMLTag_body);
PRInt32 attrCount=aNode.GetAttributeCount(PR_TRUE);
// PRInt32 attrCount=aNode.GetAttributeCount(PR_TRUE);
nsresult result=AddLeaf(aNode);
return result;
@ -2156,17 +2079,6 @@ eHTMLTags CNavDTD::GetTopNode() const {
return mBodyContext->Last();
}
/**
* Finds the topmost occurance of given tag within context vector stack.
* @update gess5/11/98
* @param tag to be found
* @return index of topmost tag occurance -- may be -1 (kNotFound).
*/
static
PRInt32 GetTopmostIndexOfBelowOffset(eHTMLTags aTag,PRInt32 anOffset){
PRInt32 result=-1;
return result;
}
/**
* Determine whether the given tag is open anywhere
@ -2266,10 +2178,11 @@ nsresult CNavDTD::OpenTransientStyles(eHTMLTags aChildTag){
nsresult CNavDTD::CloseTransientStyles(eHTMLTags aChildTag){
nsresult result=NS_OK;
#ifdef ENABLE_RESIDUALSTYLE
int theTagPos=0;
//now iterate style set, and close the containers...
#ifdef ENABLE_RESIDUALSTYLE
nsDeque* theStyleDeque=mBodyContext->GetStyles();
for(theTagPos=mBodyContext->mOpenStyles;theTagPos>0;theTagPos--){
eHTMLTags theTag=GetTopNode();
@ -2325,10 +2238,11 @@ nsresult CNavDTD::CloseHTML(const nsIParserNode& aNode){
*/
nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
//mBodyContext->Push(eHTMLTag_head);
nsresult result=NS_OK;
if(!mHasOpenHead++) {
nsresult result=(mSink) ? mSink->OpenHead(aNode) : NS_OK;
result=(mSink) ? mSink->OpenHead(aNode) : NS_OK;
}
return NS_OK;
return result;
}
/**
@ -2340,13 +2254,14 @@ nsresult CNavDTD::OpenHead(const nsIParserNode& aNode){
* @return TRUE if ok, FALSE if error
*/
nsresult CNavDTD::CloseHead(const nsIParserNode& aNode){
nsresult result=NS_OK;
if(mHasOpenHead) {
if(0==--mHasOpenHead){
nsresult result=(mSink) ? mSink->CloseHead(aNode) : NS_OK;
result=(mSink) ? mSink->CloseHead(aNode) : NS_OK;
}
}
//mBodyContext->Pop();
return NS_OK;
return result;
}
/**
@ -2843,7 +2758,6 @@ nsresult CNavDTD::CreateContextStackFor(eHTMLTags aChildTag){
kPropagationStack.Empty();
nsresult result=(nsresult)kContextMismatch;
PRInt32 cnt=0;
eHTMLTags theTop=mBodyContext->Last();
PRBool bResult=ForwardPropagate(kPropagationStack,theTop,aChildTag);

Просмотреть файл

@ -85,6 +85,7 @@
#include "nshtmlpars.h"
#include "nsVoidArray.h"
#include "nsDeque.h"
#include "nsParserNode.h"
#define NS_INAVHTML_DTD_IID \
{0x5c5cce40, 0xcfd6, 0x11d1, \
@ -94,7 +95,6 @@
class nsIHTMLContentSink;
class nsIDTDDebug;
class nsIParserNode;
class nsCParserNode;
class CITokenHandler;
class nsParser;
class nsDTDContext;
@ -490,12 +490,14 @@ CLASS_EXPORT_HTMLPARS CNavDTD : public nsIDTD {
protected:
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);
nsresult HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode& aNode);
nsresult HandleSavedTokensAbove(eHTMLTags aTag);
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);
nsresult HandleOmittedTag(CToken* aToken,eHTMLTags aChildTag,eHTMLTags aParent,nsIParserNode& aNode);
nsresult HandleSavedTokensAbove(eHTMLTags aTag);
nsCParserNode* CreateNode(void);
void RecycleNode(nsCParserNode* aNode);
nsIHTMLContentSink* mSink;
@ -521,6 +523,7 @@ protected:
PRBool mHasOpenScript;
PRBool mSaveBadTokens;
eHTMLTags mSkipTarget;
nsDeque mSharedNodes;
PRUint32 mComputedCRC32;
PRUint32 mExpectedCRC32;

Просмотреть файл

@ -481,18 +481,17 @@ PRInt32 CRTFControlWord::GetTokenType() {
return eRTFToken_controlword;
}
PRInt32 CRTFControlWord::Consume(nsScanner& aScanner){
nsresult CRTFControlWord::Consume(PRUnichar aChar,nsScanner& aScanner) {
static nsString gAlphaChars("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
static nsAutoString gDigits("-0123456789");
PRInt32 result=aScanner.ReadWhile(mTextValue,gAlphaChars,PR_TRUE,PR_FALSE);
if(NS_OK==result) {
//ok, now look for an option parameter...
PRUnichar ch;
result=aScanner.Peek(ch);
switch(ch) {
result=aScanner.Peek(aChar);
switch(aChar) {
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case kMinus:
@ -531,7 +530,7 @@ PRBool CRTFGroup::IsGroupStart(){
return mStart;
}
PRInt32 CRTFGroup::Consume(nsScanner& aScanner){
nsresult CRTFGroup::Consume(PRUnichar aChar,nsScanner& aScanner) {
PRInt32 result=NS_OK;
if(PR_FALSE==mStart)
result=aScanner.SkipWhitespace();
@ -561,7 +560,8 @@ PRInt32 CRTFContent::GetTokenType() {
* @return
*/
static nsString textTerminators("\\{}");
PRInt32 CRTFContent::Consume(nsScanner& aScanner){
nsresult CRTFContent::Consume(PRUnichar aChar,nsScanner& aScanner) {
PRInt32 result=aScanner.ReadUntil(mTextValue,textTerminators,PR_FALSE,PR_FALSE);
return result;
}

Просмотреть файл

@ -102,7 +102,7 @@ class CRTFControlWord : public CToken {
public:
CRTFControlWord(char* aKey);
virtual PRInt32 GetTokenType();
virtual PRInt32 Consume(nsScanner& aScanner);
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
protected:
nsString mArgument;
};
@ -120,7 +120,7 @@ public:
virtual PRInt32 GetTokenType();
virtual void SetGroupStart(PRBool aFlag);
virtual PRBool IsGroupStart();
virtual PRInt32 Consume(nsScanner& aScanner);
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
protected:
PRBool mStart;
};
@ -136,7 +136,7 @@ class CRTFContent: public CToken {
public:
CRTFContent(PRUnichar* aValue);
virtual PRInt32 GetTokenType();
virtual PRInt32 Consume(nsScanner& aScanner);
virtual nsresult Consume(PRUnichar aChar,nsScanner& aScanner);
};

Просмотреть файл

@ -462,9 +462,11 @@ void CTokenRecycler::RecycleToken(CToken* aToken) {
PRInt32 theType=aToken->GetTokenType();
CTokenFinder finder(aToken);
CToken* theMatch=(CToken*)mTokenCache[theType-1]->FirstThat(finder);
#ifdef NS_DEBUG
if(theMatch) {
int x=5;
}
#endif
mTokenCache[theType-1]->Push(aToken);
}
}

Просмотреть файл

@ -1691,9 +1691,6 @@ PRBool nsHTMLElement::CanContain(eHTMLTags aChild) const{
}
}
if(mTagID!=eHTMLTag_server){
int x=5;
}
}
return PR_FALSE;

Просмотреть файл

@ -816,7 +816,6 @@ nsresult ConsumeComment(PRUnichar aChar, nsScanner& aScanner,nsString& aString)
if(kMinus==aChar) {
//in this case, we're reading a long-form comment <-- xxx -->
aString+=aChar;
PRBool done=PR_FALSE;
PRInt32 findpos=kNotFound;
result=aScanner.ReadWhile(aString,gMinus,PR_TRUE,PR_TRUE); //get all available '---'
findpos=aString.RFind("-->");
@ -1523,7 +1522,6 @@ PRInt32 CEntityToken::TranslateToUnicodeStr(nsString& aString) {
if(mTextValue.Length()>1) {
PRUnichar theChar0=mTextValue.CharAt(0);
PRBool isDigit0=nsString::IsDigit(theChar0);
if(kHashsign==theChar0) {
PRInt32 err=0;

Просмотреть файл

@ -221,14 +221,14 @@ class nsIParser : public nsISupports {
#define NS_ERROR_HTMLPARSER_CONTINUE NS_OK
const PRInt32 kEOF = NS_ERROR_HTMLPARSER_EOF;
const PRInt32 kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN;
const PRInt32 kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
const PRInt32 kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
const PRInt32 kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME;
const PRInt32 kBadURL = NS_ERROR_HTMLPARSER_BADURL;
const PRInt32 kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
const PRInt32 kBlocked = NS_ERROR_HTMLPARSER_BLOCK;
const PRUint32 kEOF = NS_ERROR_HTMLPARSER_EOF;
const PRUint32 kUnknownError = NS_ERROR_HTMLPARSER_UNKNOWN;
const PRUint32 kCantPropagate = NS_ERROR_HTMLPARSER_CANTPROPAGATE;
const PRUint32 kContextMismatch = NS_ERROR_HTMLPARSER_CONTEXTMISMATCH;
const PRUint32 kBadFilename = NS_ERROR_HTMLPARSER_BADFILENAME;
const PRUint32 kBadURL = NS_ERROR_HTMLPARSER_BADURL;
const PRUint32 kInvalidParserContext = NS_ERROR_HTMLPARSER_INVALIDPARSERCONTEXT;
const PRUint32 kBlocked = NS_ERROR_HTMLPARSER_BLOCK;
const PRUint32 kNewLine = '\n';
const PRUint32 kCR = '\r';

Просмотреть файл

@ -43,13 +43,21 @@ nsAutoString& GetEmptyString() {
nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler):
nsIParserNode(), mSkippedContent("") {
NS_INIT_REFCNT();
mAttributeCount=0;
static int theNodeCount=0;
theNodeCount++;
mAttributes=0;
mLineNumber=aLineNumber;
mToken=aToken;
memset(mAttributes,0,sizeof(mAttributes));
mRecycler=aRecycler;
}
static void RecycleTokens(nsITokenRecycler* aRecycler,nsDeque& aDeque) {
CToken* theToken=0;
while(theToken=(CToken*)aDeque.Pop()){
aRecycler->RecycleToken(theToken);
}
}
/**
* default destructor
@ -60,11 +68,9 @@ nsCParserNode::nsCParserNode(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler
* @return
*/
nsCParserNode::~nsCParserNode() {
if(mRecycler) {
PRUint32 index=0;
for(index=0;index<mAttributeCount;index++){
mRecycler->RecycleToken(mAttributes[index]);
}
if(mRecycler && mAttributes) {
RecycleTokens(mRecycler,*mAttributes);
delete mAttributes;
}
}
@ -79,10 +85,11 @@ NS_IMPL_RELEASE(nsCParserNode)
* @return
*/
nsresult nsCParserNode::Init(CToken* aToken,PRInt32 aLineNumber)
{
nsresult nsCParserNode::Init(CToken* aToken,PRInt32 aLineNumber,nsITokenRecycler* aRecycler) {
mLineNumber=aLineNumber;
mAttributeCount=0;
mRecycler=aRecycler;
if(mAttributes && (mAttributes->GetSize()))
RecycleTokens(mRecycler,*mAttributes);
mToken=aToken;
return NS_OK;
}
@ -130,13 +137,12 @@ nsresult nsCParserNode::QueryInterface(const nsIID& aIID, void** aInstancePtr)
* @return
*/
void nsCParserNode::AddAttribute(CToken* aToken) {
NS_PRECONDITION(mAttributeCount<eMaxAttr, "Buffer overrun!");
NS_PRECONDITION(0!=aToken, "Error: Token shouldn't be null!");
if(mAttributeCount<eMaxAttr) {
if(aToken) {
mAttributes[mAttributeCount++]=aToken;
}
if(!mAttributes)
mAttributes=new nsDeque(0);
if(mAttributes) {
mAttributes->Push(aToken);
}
}
@ -224,9 +230,14 @@ PRInt32 nsCParserNode::GetTokenType(void) const{
* @return int -- representing attribute count
*/
PRInt32 nsCParserNode::GetAttributeCount(PRBool askToken) const{
if(PR_TRUE==askToken)
return mToken->GetAttributeCount();
return mAttributeCount;
PRInt32 result=0;
if(PR_FALSE==askToken) {
if(mAttributes)
result=mAttributes->GetSize();
}
else result=mToken->GetAttributeCount();
return result;
}
/**
@ -238,8 +249,9 @@ PRInt32 nsCParserNode::GetAttributeCount(PRBool askToken) const{
* @return string rep of given attribute text key
*/
const nsString& nsCParserNode::GetKeyAt(PRUint32 anIndex) const {
if(anIndex<mAttributeCount) {
CAttributeToken* tkn=(CAttributeToken*)(mAttributes[anIndex]);
PRInt32 theCount = (mAttributes) ? mAttributes->GetSize() : 0;
if((PRInt32)anIndex<theCount) {
CAttributeToken* tkn=(CAttributeToken*)mAttributes->ObjectAt(anIndex);
return tkn->GetKey();
}
return GetEmptyString();
@ -254,9 +266,13 @@ const nsString& nsCParserNode::GetKeyAt(PRUint32 anIndex) const {
* @return string rep of given attribute text value
*/
const nsString& nsCParserNode::GetValueAt(PRUint32 anIndex) const {
NS_PRECONDITION(anIndex<mAttributeCount, "Bad attr index");
if(anIndex<mAttributeCount){
return (mAttributes[anIndex])->GetStringValueXXX();
PRInt32 theCount = (mAttributes) ? mAttributes->GetSize() : 0;
NS_PRECONDITION(PRInt32(anIndex)<theCount, "Bad attr index");
if(PRInt32(anIndex)<theCount) {
CAttributeToken* tkn=(CAttributeToken*)mAttributes->ObjectAt(anIndex);
return tkn->GetStringValueXXX();
}
return GetEmptyString();
}
@ -286,13 +302,11 @@ PRInt32 nsCParserNode::GetSourceLineNumber(void) const {
* @return token at anIndex
*/
CToken* nsCParserNode::PopAttributeToken()
{
NS_PRECONDITION(mAttributeCount<eMaxAttr, "Buffer overrun!");
if(mAttributeCount > 0) {
CToken* theAttrToken = mAttributes[--mAttributeCount];
mAttributes[mAttributeCount] = nsnull;
return theAttrToken;
CToken* nsCParserNode::PopAttributeToken() {
CToken* result=0;
if(mAttributes) {
result =(CToken*)mAttributes->Pop();
}
return nsnull;
return result;
}

Просмотреть файл

@ -40,11 +40,11 @@
#include "nsToken.h"
#include "nsString.h"
#include "nsParserCIID.h"
#include "nsDeque.h"
class nsITokenRecycler;
class nsCParserNode : public nsIParserNode {
enum {eMaxAttr=20};
public:
@ -67,7 +67,7 @@ class nsCParserNode : public nsIParserNode {
* Init
* @update gess5/11/98
*/
virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1);
virtual nsresult Init(CToken* aToken=nsnull,PRInt32 aLineNumber=1,nsITokenRecycler* aRecycler=0);
/**
* Retrieve the name of the node
@ -170,11 +170,11 @@ class nsCParserNode : public nsIParserNode {
virtual CToken* PopAttributeToken();
protected:
PRUint32 mAttributeCount;
PRInt32 mLineNumber;
CToken* mToken;
CToken* mAttributes[eMaxAttr]; // XXX Ack! This needs to be dynamic!
nsDeque* mAttributes;
nsAutoString mSkippedContent;
nsITokenRecycler* mRecycler;
};

Просмотреть файл

@ -53,7 +53,7 @@ nsScanner::nsScanner(nsString& anHTMLString, const nsString& aCharset, nsCharset
mIncremental=PR_TRUE;
mOwnsStream=PR_FALSE;
mOffset=0;
mMarkPos=-1;
mMarkPos=0;
mInputStream=0;
mUnicodeDecoder = 0;
mCharset = "";
@ -75,7 +75,7 @@ nsScanner::nsScanner(nsString& aFilename,PRBool aCreateStream, const nsString& a
{
mIncremental=PR_TRUE;
mOffset=0;
mMarkPos=-1;
mMarkPos=0;
mTotalRead=0;
mOwnsStream=aCreateStream;
mInputStream=0;
@ -103,7 +103,7 @@ nsScanner::nsScanner(nsString& aFilename,nsInputStream& aStream,const nsString&
{
mIncremental=PR_TRUE;
mOffset=0;
mMarkPos=-1;
mMarkPos=0;
mTotalRead=0;
mOwnsStream=assumeOwnership;
mInputStream=&aStream;

Просмотреть файл

@ -242,11 +242,10 @@ static void SetStyle(eHTMLTags theTag,PRBool aEnable,nsIContentSink& aSink) {
* @param
* @return
*/
CViewSourceHTML::CViewSourceHTML() : nsIDTD() {
CViewSourceHTML::CViewSourceHTML() : nsIDTD(), mFilename("") {
NS_INIT_REFCNT();
mParser=0;
mSink=0;
mFilename;
mLineNumber=0;
mTokenizer=0;
mIsHTML=PR_FALSE;
@ -605,7 +604,6 @@ nsresult WriteText(const nsString& aTextString,nsIContentSink& aSink,PRBool aPre
PRInt32 theTextOffset=0;
PRInt32 theOffset=-1; //aTextString.FindCharInSet("\t\n\r ",theStartOffset);
PRInt32 theSpaces=0;
PRBool theOutputReady=PR_FALSE;
PRUnichar theChar=0;
PRUnichar theNextChar=0;
@ -877,8 +875,8 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
case eToken_style:
case eToken_skippedcontent:
{
CAttributeToken* theToken=(CAttributeToken*)aToken;
nsString& theText=theToken->GetKey();
CAttributeToken* theAToken=(CAttributeToken*)aToken;
nsString& theText=theAToken->GetKey();
::WriteText(theText,*mSink,PR_FALSE,mIsPlaintext,theContext);
}
break;
@ -922,12 +920,12 @@ NS_IMETHODIMP CViewSourceHTML::HandleToken(CToken* aToken,nsIParser* aParser) {
if(0<attrCount){ //go collect the attributes...
int attr=0;
for(attr=0;attr<attrCount;attr++){
CToken* theToken=mTokenizer->PeekToken();
if(theToken) {
eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType());
if(eToken_attribute==theType){
CToken* theInnerToken=mTokenizer->PeekToken();
if(theInnerToken) {
eHTMLTokenTypes theInnerType=eHTMLTokenTypes(theInnerToken->GetTokenType());
if(eToken_attribute==theInnerType){
mTokenizer->PopToken(); //pop it for real...
theContext.mTokenNode.AddAttribute(theToken);
theContext.mTokenNode.AddAttribute(theInnerToken);
}
}
else return kEOF;

Просмотреть файл

@ -120,11 +120,10 @@ NS_IMPL_RELEASE(CWellFormedDTD)
* @param
* @return
*/
CWellFormedDTD::CWellFormedDTD() : nsIDTD() {
CWellFormedDTD::CWellFormedDTD() : nsIDTD(), mFilename("") {
NS_INIT_REFCNT();
mParser=0;
mSink=0;
mFilename;
mLineNumber=0;
mTokenizer=0;
}
@ -452,12 +451,12 @@ NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
if(0<attrCount){ //go collect the attributes...
int attr=0;
for(attr=0;attr<attrCount;attr++){
CToken* theToken=mTokenizer->PeekToken();
if(theToken) {
eHTMLTokenTypes theType=eHTMLTokenTypes(theToken->GetTokenType());
if(eToken_attribute==theType){
CToken* theInnerToken=mTokenizer->PeekToken();
if(theInnerToken) {
eHTMLTokenTypes theInnerType=eHTMLTokenTypes(theInnerToken->GetTokenType());
if(eToken_attribute==theInnerType){
mTokenizer->PopToken(); //pop it for real...
theNode.AddAttribute(theToken);
theNode.AddAttribute(theInnerToken);
}
}
else return kEOF;