bug 307797: Fix line counting regressions resulting from the checkin for bug 272702, as well as an old bug where document.write('\n') would cause line numbers in the rest of the HTML to be offset. Also fix a regression where userdefined tags are forced to be in the head (as opposed to appearing in either the head or the body). r+sr=jst

This commit is contained in:
mrbkap%gmail.com 2005-09-10 00:12:21 +00:00
Родитель e39b2e6672
Коммит d5a752d6a5
3 изменённых файлов: 30 добавлений и 11 удалений

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

@ -469,12 +469,12 @@ nsresult CNavDTD::BuildModel(nsIParser* aParser,nsITokenizer* aTokenizer,nsIToke
// The mParser->CanInterrupt will return TRUE if BuildModel was called // The mParser->CanInterrupt will return TRUE if BuildModel was called
// from a place in the parser where it prepared to handle a return value of // from a place in the parser where it prepared to handle a return value of
// NS_ERROR_HTMLPARSER_INTERRUPTED. // NS_ERROR_HTMLPARSER_INTERRUPTED.
// If the parser has mPrevContext then it may be processing // If the parser is processing a script's document.write we should not
// Script so we should not allow it to be interrupted. // allow it to be interrupted.
// We also need to make sure that an interruption does not override // We also need to make sure that an interruption does not override
// a request to block the parser. // a request to block the parser.
if (mParser->CanInterrupt() && if (mParser->CanInterrupt() &&
!mParser->PeekContext()->mPrevContext && !IsParserInDocWrite() &&
NS_SUCCEEDED(result)) { NS_SUCCEEDED(result)) {
result = NS_ERROR_HTMLPARSER_INTERRUPTED; result = NS_ERROR_HTMLPARSER_INTERRUPTED;
break; break;
@ -683,8 +683,10 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID(); eHTMLTags theTag=(eHTMLTags)theToken->GetTypeID();
aToken->SetLineNumber(mLineNumber); aToken->SetLineNumber(mLineNumber);
mLineNumber += aToken->GetNewlineCount(); if (!IsParserInDocWrite()) {
mLineNumber += aToken->GetNewlineCount();
}
if(mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) { if(mFlags & NS_DTD_FLAG_MISPLACED_CONTENT) {
// Included TD & TH to fix Bug# 20797 // Included TD & TH to fix Bug# 20797
@ -854,7 +856,6 @@ nsresult CNavDTD::HandleToken(CToken* aToken,nsIParser* aParser){
break; break;
}//switch }//switch
if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) { if(NS_SUCCEEDED(result) || (NS_ERROR_HTMLPARSER_BLOCK==result)) {
IF_FREE(theToken, mTokenAllocator); IF_FREE(theToken, mTokenAllocator);
} }
@ -889,7 +890,9 @@ nsresult CNavDTD::DidHandleStartTag(nsIParserNode& aNode,eHTMLTags aChildTag){
if(theNextToken) { if(theNextToken) {
eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType()); eHTMLTokenTypes theType=eHTMLTokenTypes(theNextToken->GetTokenType());
if(eToken_newline==theType){ if(eToken_newline==theType){
mLineNumber += theNextToken->GetNewlineCount(); if (!IsParserInDocWrite()) {
mLineNumber += theNextToken->GetNewlineCount();
}
theNextToken=mTokenizer->PopToken(); //skip 1st newline inside PRE and LISTING theNextToken=mTokenizer->PopToken(); //skip 1st newline inside PRE and LISTING
IF_FREE(theNextToken, mTokenAllocator); // fix for Bug 29379 IF_FREE(theNextToken, mTokenAllocator); // fix for Bug 29379
}//if }//if
@ -1506,7 +1509,7 @@ nsresult CNavDTD::HandleStartToken(CToken* aToken) {
theHeadIsParent = theHeadIsParent && theHeadIsParent = theHeadIsParent &&
(isExclusive || (isExclusive ||
(prefersBody (prefersBody
? (mFlags & NS_DTD_FLAG_HAS_EXPLICIT_HEAD) ? (mFlags & NS_DTD_FLAG_HAS_EXPLICIT_HEAD) && (mFlags & NS_DTD_FLAG_HAS_OPEN_HEAD)
: !(mFlags & NS_DTD_FLAG_HAD_BODY))); : !(mFlags & NS_DTD_FLAG_HAD_BODY)));
if(theHeadIsParent) { if(theHeadIsParent) {
@ -2062,7 +2065,9 @@ nsresult CNavDTD::HandleDocTypeDeclToken(CToken* aToken){
CDoctypeDeclToken* theToken = NS_STATIC_CAST(CDoctypeDeclToken*,aToken); CDoctypeDeclToken* theToken = NS_STATIC_CAST(CDoctypeDeclToken*,aToken);
nsAutoString docTypeStr(theToken->GetStringValue()); nsAutoString docTypeStr(theToken->GetStringValue());
mLineNumber += docTypeStr.CountChar(kNewLine); if (!IsParserInDocWrite()) {
mLineNumber += docTypeStr.CountChar(kNewLine);
}
PRInt32 len=docTypeStr.Length(); PRInt32 len=docTypeStr.Length();
PRInt32 pos=docTypeStr.RFindChar(kGreaterThan); PRInt32 pos=docTypeStr.RFindChar(kGreaterThan);
@ -2117,7 +2122,9 @@ nsresult CNavDTD::CollectAttributes(nsIParserNode *aNode,eHTMLTags aTag,PRInt32
break; break;
} }
mLineNumber += theToken->GetNewlineCount(); if (IsParserInDocWrite()) {
mLineNumber += theToken->GetNewlineCount();
}
if(aNode) { if(aNode) {
// Sanitize the key for it might contain some non-alpha-non-digit characters // Sanitize the key for it might contain some non-alpha-non-digit characters

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

@ -106,6 +106,7 @@
#include "nsParserCIID.h" #include "nsParserCIID.h"
#include "nsTime.h" #include "nsTime.h"
#include "nsDTDUtils.h" #include "nsDTDUtils.h"
#include "nsParser.h"
#define NS_INAVHTML_DTD_IID \ #define NS_INAVHTML_DTD_IID \
{0x5c5cce40, 0xcfd6, 0x11d1, \ {0x5c5cce40, 0xcfd6, 0x11d1, \
@ -114,7 +115,6 @@
class nsIHTMLContentSink; class nsIHTMLContentSink;
class nsIParserNode; class nsIParserNode;
class nsParser;
class nsDTDContext; class nsDTDContext;
class nsEntryStack; class nsEntryStack;
class nsITokenizer; class nsITokenizer;
@ -373,6 +373,14 @@ protected:
PRBool IsAlternateTag(eHTMLTags aTag); PRBool IsAlternateTag(eHTMLTags aTag);
PRBool IsBlockElement(PRInt32 aTagID, PRInt32 aParentID) const; PRBool IsBlockElement(PRInt32 aTagID, PRInt32 aParentID) const;
PRBool IsInlineElement(PRInt32 aTagID, PRInt32 aParentID) const; PRBool IsInlineElement(PRInt32 aTagID, PRInt32 aParentID) const;
PRBool IsParserInDocWrite() const
{
NS_ASSERTION(mParser && mParser->PeekContext(),
"Parser must be parsing to use this function");
return mParser->PeekContext()->mPrevContext != nsnull;
}
nsDeque mMisplacedContent; nsDeque mMisplacedContent;

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

@ -781,6 +781,10 @@ nsresult CTextToken::ConsumeCharacterData(PRBool aConservativeConsume,
} }
} }
if (result == NS_OK) {
mNewlineCount = mTextValue.CountChar(kNewLine);
}
return result; return result;
} }