More work to fix bug 8607. This is still not enabled at run-time because one of the XML tests isn't displaying properly. XML decls and DOCTYPE decls will be passed up to the content sink once this is enabled.

This commit is contained in:
nisheeth%netscape.com 1999-07-28 01:21:54 +00:00
Родитель 0c457a16d0
Коммит 9a70bf805a
6 изменённых файлов: 96 добавлений и 56 удалений

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

@ -486,19 +486,22 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag,
mTotals[aType-1]++;
#endif
switch(aType){
case eToken_start: result=new CStartToken(aTag); break;
case eToken_end: result=new CEndToken(aTag); break;
case eToken_comment: result=new CCommentToken(); break;
case eToken_entity: result=new CEntityToken(aString); break;
case eToken_whitespace: result=new CWhitespaceToken(); break;
case eToken_newline: result=new CNewlineToken(); break;
case eToken_text: result=new CTextToken(aString); break;
case eToken_attribute: result=new CAttributeToken(); break;
case eToken_script: result=new CScriptToken(); break;
case eToken_style: result=new CStyleToken(); break;
case eToken_skippedcontent: result=new CSkippedContentToken(aString); break;
case eToken_instruction:result=new CInstructionToken(); break;
case eToken_cdatasection:result=new CCDATASectionToken(); break;
case eToken_start: result=new CStartToken(aTag); break;
case eToken_end: result=new CEndToken(aTag); break;
case eToken_comment: result=new CCommentToken(); break;
case eToken_entity: result=new CEntityToken(aString); break;
case eToken_whitespace: result=new CWhitespaceToken(); break;
case eToken_newline: result=new CNewlineToken(); break;
case eToken_text: result=new CTextToken(aString); break;
case eToken_attribute: result=new CAttributeToken(); break;
case eToken_script: result=new CScriptToken(); break;
case eToken_style: result=new CStyleToken(); break;
case eToken_skippedcontent: result=new CSkippedContentToken(aString); break;
case eToken_instruction: result=new CInstructionToken(); break;
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}
@ -539,6 +542,8 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
case eToken_instruction: result=new CInstructionToken(); break;
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}

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

@ -127,7 +127,7 @@ void nsExpatTokenizer::SetupExpatCallbacks(void) {
XML_SetElementHandler(mExpatParser, HandleStartElement, HandleEndElement);
XML_SetCharacterDataHandler(mExpatParser, HandleCharacterData);
XML_SetProcessingInstructionHandler(mExpatParser, HandleProcessingInstruction);
XML_SetDefaultHandler(mExpatParser, NULL);
XML_SetDefaultHandlerExpand(mExpatParser, NULL);
XML_SetUnparsedEntityDeclHandler(mExpatParser, HandleUnparsedEntityDecl);
XML_SetNotationDeclHandler(mExpatParser, HandleNotationDecl);
XML_SetExternalEntityRefHandler(mExpatParser, HandleExternalEntityRef);
@ -476,26 +476,36 @@ void nsExpatTokenizer::HandleProcessingInstruction(void *userData, const XML_Cha
void nsExpatTokenizer::HandleDefault(void *userData, const XML_Char *s, int len) {
nsString str = (PRUnichar*) s;
CToken* token = nsnull;
CToken* token = (CToken*) userData;
PRBool ProcessingDocTypeDecl = (token != nsnull);
str.StripWhitespace();
if (0 == str.Find(kXMLDeclPrefix)) {
// Create the XML decl token
token = gTokenRecycler->CreateTokenOfType(eToken_xmlDecl, eHTMLTag_unknown);
str.Truncate(len);
if (ProcessingDocTypeDecl) {
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append((PRUnichar*) s);
tokenStr.Append(str);
if (str == "]") {
tokenStr.Append(">");
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
XML_SetUserData(gExpatParser, nsnull);
}
}
else if (0 == str.Find(kDocTypeDeclPrefix)) {
else if (0 == str.Find(kXMLDeclPrefix)) {
str.CompressWhitespace(PR_TRUE, PR_TRUE);
if (nsString::IsSpace(str[nsCRT::strlen(kXMLDeclPrefix)])) {
// Create the XML decl token
token = gTokenRecycler->CreateTokenOfType(eToken_xmlDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
}
}
else if (0 == str.Find(kDocTypeDeclPrefix)) {
// Create the DOCTYPE decl token
token = gTokenRecycler->CreateTokenOfType(eToken_doctypeDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append((PRUnichar*) s);
tokenStr.Append(str);
XML_SetUserData(gExpatParser, (void*) token);
}
// If a token was created, add it to the token queue
if (token)
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
}
void nsExpatTokenizer::HandleUnparsedEntityDecl(void *userData,

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

@ -34,6 +34,7 @@
#include "nsDTDUtils.h"
#include "nsIContentSink.h"
#include "nsIHTMLContentSink.h"
#include "nsIXMLContentSink.h"
#include "nsHTMLTokenizer.h"
#include "nsExpatTokenizer.h"
@ -566,7 +567,11 @@ NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
}
break;
case eToken_xmlDecl:
// result = mSink->AddXMLDecl(theNode);
{
nsCOMPtr<nsIXMLContentSink> xmlSink(do_QueryInterface(mSink, &result));
if (NS_SUCCEEDED(result))
result = xmlSink->AddXMLDecl(theNode);
}
break;
case eToken_doctypeDecl:
result = mSink->AddDocTypeDecl(theNode);

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

@ -486,19 +486,22 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag,
mTotals[aType-1]++;
#endif
switch(aType){
case eToken_start: result=new CStartToken(aTag); break;
case eToken_end: result=new CEndToken(aTag); break;
case eToken_comment: result=new CCommentToken(); break;
case eToken_entity: result=new CEntityToken(aString); break;
case eToken_whitespace: result=new CWhitespaceToken(); break;
case eToken_newline: result=new CNewlineToken(); break;
case eToken_text: result=new CTextToken(aString); break;
case eToken_attribute: result=new CAttributeToken(); break;
case eToken_script: result=new CScriptToken(); break;
case eToken_style: result=new CStyleToken(); break;
case eToken_skippedcontent: result=new CSkippedContentToken(aString); break;
case eToken_instruction:result=new CInstructionToken(); break;
case eToken_cdatasection:result=new CCDATASectionToken(); break;
case eToken_start: result=new CStartToken(aTag); break;
case eToken_end: result=new CEndToken(aTag); break;
case eToken_comment: result=new CCommentToken(); break;
case eToken_entity: result=new CEntityToken(aString); break;
case eToken_whitespace: result=new CWhitespaceToken(); break;
case eToken_newline: result=new CNewlineToken(); break;
case eToken_text: result=new CTextToken(aString); break;
case eToken_attribute: result=new CAttributeToken(); break;
case eToken_script: result=new CScriptToken(); break;
case eToken_style: result=new CStyleToken(); break;
case eToken_skippedcontent: result=new CSkippedContentToken(aString); break;
case eToken_instruction: result=new CInstructionToken(); break;
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}
@ -539,6 +542,8 @@ CToken* CTokenRecycler::CreateTokenOfType(eHTMLTokenTypes aType,eHTMLTags aTag)
case eToken_instruction: result=new CInstructionToken(); break;
case eToken_cdatasection: result=new CCDATASectionToken(); break;
case eToken_error: result=new CErrorToken(); break;
case eToken_doctypeDecl: result=new CDoctypeDeclToken(); break;
case eToken_xmlDecl: result=new CXMLDeclToken(); break;
default:
break;
}

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

@ -127,7 +127,7 @@ void nsExpatTokenizer::SetupExpatCallbacks(void) {
XML_SetElementHandler(mExpatParser, HandleStartElement, HandleEndElement);
XML_SetCharacterDataHandler(mExpatParser, HandleCharacterData);
XML_SetProcessingInstructionHandler(mExpatParser, HandleProcessingInstruction);
XML_SetDefaultHandler(mExpatParser, NULL);
XML_SetDefaultHandlerExpand(mExpatParser, NULL);
XML_SetUnparsedEntityDeclHandler(mExpatParser, HandleUnparsedEntityDecl);
XML_SetNotationDeclHandler(mExpatParser, HandleNotationDecl);
XML_SetExternalEntityRefHandler(mExpatParser, HandleExternalEntityRef);
@ -476,26 +476,36 @@ void nsExpatTokenizer::HandleProcessingInstruction(void *userData, const XML_Cha
void nsExpatTokenizer::HandleDefault(void *userData, const XML_Char *s, int len) {
nsString str = (PRUnichar*) s;
CToken* token = nsnull;
CToken* token = (CToken*) userData;
PRBool ProcessingDocTypeDecl = (token != nsnull);
str.StripWhitespace();
if (0 == str.Find(kXMLDeclPrefix)) {
// Create the XML decl token
token = gTokenRecycler->CreateTokenOfType(eToken_xmlDecl, eHTMLTag_unknown);
str.Truncate(len);
if (ProcessingDocTypeDecl) {
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append((PRUnichar*) s);
tokenStr.Append(str);
if (str == "]") {
tokenStr.Append(">");
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
XML_SetUserData(gExpatParser, nsnull);
}
}
else if (0 == str.Find(kDocTypeDeclPrefix)) {
else if (0 == str.Find(kXMLDeclPrefix)) {
str.CompressWhitespace(PR_TRUE, PR_TRUE);
if (nsString::IsSpace(str[nsCRT::strlen(kXMLDeclPrefix)])) {
// Create the XML decl token
token = gTokenRecycler->CreateTokenOfType(eToken_xmlDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append(str);
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
}
}
else if (0 == str.Find(kDocTypeDeclPrefix)) {
// Create the DOCTYPE decl token
token = gTokenRecycler->CreateTokenOfType(eToken_doctypeDecl, eHTMLTag_unknown);
nsString& tokenStr = token->GetStringValueXXX();
tokenStr.Append((PRUnichar*) s);
tokenStr.Append(str);
XML_SetUserData(gExpatParser, (void*) token);
}
// If a token was created, add it to the token queue
if (token)
AddToken(token, NS_OK, *gTokenDeque, gTokenRecycler);
}
void nsExpatTokenizer::HandleUnparsedEntityDecl(void *userData,

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

@ -34,6 +34,7 @@
#include "nsDTDUtils.h"
#include "nsIContentSink.h"
#include "nsIHTMLContentSink.h"
#include "nsIXMLContentSink.h"
#include "nsHTMLTokenizer.h"
#include "nsExpatTokenizer.h"
@ -566,7 +567,11 @@ NS_IMETHODIMP CWellFormedDTD::HandleToken(CToken* aToken,nsIParser* aParser) {
}
break;
case eToken_xmlDecl:
// result = mSink->AddXMLDecl(theNode);
{
nsCOMPtr<nsIXMLContentSink> xmlSink(do_QueryInterface(mSink, &result));
if (NS_SUCCEEDED(result))
result = xmlSink->AddXMLDecl(theNode);
}
break;
case eToken_doctypeDecl:
result = mSink->AddDocTypeDecl(theNode);