De-nsIDOM* nsIContentSerializer methods, r=sicking

This commit is contained in:
Olli Pettay 2010-05-04 11:39:47 +03:00
Родитель 4176cb686d
Коммит 5f229468c1
12 изменённых файлов: 158 добавлений и 189 удалений

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

@ -40,20 +40,15 @@
#include "nsISupports.h" #include "nsISupports.h"
class nsIDOMText; /* forward declaration */ class nsIContent;
class nsIDOMCDATASection; /* forward declaration */ class nsIDocument;
class nsIDOMProcessingInstruction; /* forward declaration */
class nsIDOMComment; /* forward declaration */
class nsIDOMDocumentType; /* forward declaration */
class nsIDOMElement; /* forward declaration */
class nsIDOMDocument; /* forward declaration */
class nsAString; class nsAString;
/* starting interface: nsIContentSerializer */ /* starting interface: nsIContentSerializer */
#define NS_ICONTENTSERIALIZER_IID \ #define NS_ICONTENTSERIALIZER_IID \
{ 0x34769de0, 0x30d0, 0x4cef, \ { 0xb1ee32f2, 0xb8c4, 0x49b9, \
{ 0x89, 0x4a, 0xfc, 0xd8, 0xbb, 0x27, 0xc4, 0xb4 } } { 0x93, 0xdf, 0xb6, 0xfa, 0xb5, 0xd5, 0x46, 0x88 } }
class nsIContentSerializer : public nsISupports { class nsIContentSerializer : public nsISupports {
public: public:
@ -64,29 +59,29 @@ class nsIContentSerializer : public nsISupports {
const char* aCharSet, PRBool aIsCopying, const char* aCharSet, PRBool aIsCopying,
PRBool aIsWholeDocument) = 0; PRBool aIsWholeDocument) = 0;
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, NS_IMETHOD AppendText(nsIContent* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr) = 0; PRInt32 aEndOffset, nsAString& aStr) = 0;
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection, NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
PRInt32 aStartOffset, PRInt32 aEndOffset, PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, NS_IMETHOD AppendProcessingInstruction(nsIContent* aPI,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset, NS_IMETHOD AppendComment(nsIContent* aComment, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr) = 0; PRInt32 aEndOffset, nsAString& aStr) = 0;
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, NS_IMETHOD AppendDoctype(nsIContent *aDoctype,
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIContent *aElement,
nsAString& aStr) = 0; nsAString& aStr) = 0;
NS_IMETHOD Flush(nsAString& aStr) = 0; NS_IMETHOD Flush(nsAString& aStr) = 0;
@ -96,7 +91,7 @@ class nsIContentSerializer : public nsISupports {
* serialized by other methods. XML declaration is the most likely * serialized by other methods. XML declaration is the most likely
* thing this method can produce. * thing this method can produce.
*/ */
NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument, NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr) = 0; nsAString& aStr) = 0;
}; };

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

@ -165,7 +165,7 @@ mozSanitizingHTMLSerializer::Flush(nsAString& aStr)
} }
NS_IMETHODIMP NS_IMETHODIMP
mozSanitizingHTMLSerializer::AppendDocumentStart(nsIDOMDocument *aDocument, mozSanitizingHTMLSerializer::AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr) nsAString& aStr)
{ {
return NS_OK; return NS_OK;
@ -225,7 +225,7 @@ mozSanitizingHTMLSerializer::GetIdForContent(nsIContent* aContent)
} }
NS_IMETHODIMP NS_IMETHODIMP
mozSanitizingHTMLSerializer::AppendText(nsIDOMText* aText, mozSanitizingHTMLSerializer::AppendText(nsIContent* aText,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
@ -241,14 +241,13 @@ mozSanitizingHTMLSerializer::AppendText(nsIDOMText* aText,
} }
NS_IMETHODIMP NS_IMETHODIMP
mozSanitizingHTMLSerializer::AppendElementStart(nsIDOMElement *aElement, mozSanitizingHTMLSerializer::AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
mContent = do_QueryInterface(aElement); mContent = aElement;
NS_ENSURE_TRUE(mContent, NS_ERROR_FAILURE);
mOutputString = &aStr; mOutputString = &aStr;
@ -271,13 +270,12 @@ mozSanitizingHTMLSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
NS_IMETHODIMP NS_IMETHODIMP
mozSanitizingHTMLSerializer::AppendElementEnd(nsIDOMElement *aElement, mozSanitizingHTMLSerializer::AppendElementEnd(nsIContent *aElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
mContent = do_QueryInterface(aElement); mContent = aElement;
NS_ENSURE_TRUE(mContent, NS_ERROR_FAILURE);
mOutputString = &aStr; mOutputString = &aStr;

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

@ -73,29 +73,29 @@ public:
NS_IMETHOD Init(PRUint32 flags, PRUint32 dummy, const char* aCharSet, NS_IMETHOD Init(PRUint32 flags, PRUint32 dummy, const char* aCharSet,
PRBool aIsCopying, PRBool aIsWholeDocument); PRBool aIsCopying, PRBool aIsWholeDocument);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, NS_IMETHOD AppendText(nsIContent* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr); PRInt32 aEndOffset, nsAString& aStr);
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection, NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
PRInt32 aStartOffset, PRInt32 aEndOffset, PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
{ return NS_OK; } { return NS_OK; }
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, NS_IMETHOD AppendProcessingInstruction(nsIContent* aPI,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
{ return NS_OK; } { return NS_OK; }
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset, NS_IMETHOD AppendComment(nsIContent* aComment, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr) PRInt32 aEndOffset, nsAString& aStr)
{ return NS_OK; } { return NS_OK; }
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, nsAString& aStr) NS_IMETHOD AppendDoctype(nsIContent *aDoctype, nsAString& aStr)
{ return NS_OK; } { return NS_OK; }
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, nsAString& aStr); NS_IMETHOD AppendElementEnd(nsIContent *aElement, nsAString& aStr);
NS_IMETHOD Flush(nsAString& aStr); NS_IMETHOD Flush(nsAString& aStr);
NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument, NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr); nsAString& aStr);
// nsIContentSink // nsIContentSink

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

@ -292,45 +292,44 @@ nsDocumentEncoder::SerializeNodeStart(nsINode* aNode,
if (!node) if (!node)
node = aNode; node = aNode;
//XXX Remove QIing to nsIDOM* when fixing bug 562321.
node->GetNodeType(&type); node->GetNodeType(&type);
switch (type) { switch (type) {
case nsIDOMNode::ELEMENT_NODE: case nsIDOMNode::ELEMENT_NODE:
{ {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(node); nsIContent* originalElement =
nsCOMPtr<nsIDOMElement> originalElement = do_QueryInterface(aOriginalNode); aOriginalNode && aOriginalNode->IsElement() ?
mSerializer->AppendElementStart(element, originalElement, aStr); static_cast<nsIContent*>(aOriginalNode) : nsnull;
mSerializer->AppendElementStart(static_cast<nsIContent*>(node),
originalElement, aStr);
break; break;
} }
case nsIDOMNode::TEXT_NODE: case nsIDOMNode::TEXT_NODE:
{ {
nsCOMPtr<nsIDOMText> text = do_QueryInterface(node); mSerializer->AppendText(static_cast<nsIContent*>(node),
mSerializer->AppendText(text, aStartOffset, aEndOffset, aStr); aStartOffset, aEndOffset, aStr);
break; break;
} }
case nsIDOMNode::CDATA_SECTION_NODE: case nsIDOMNode::CDATA_SECTION_NODE:
{ {
nsCOMPtr<nsIDOMCDATASection> cdata = do_QueryInterface(node); mSerializer->AppendCDATASection(static_cast<nsIContent*>(node),
mSerializer->AppendCDATASection(cdata, aStartOffset, aEndOffset, aStr); aStartOffset, aEndOffset, aStr);
break; break;
} }
case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: case nsIDOMNode::PROCESSING_INSTRUCTION_NODE:
{ {
nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(node); mSerializer->AppendProcessingInstruction(static_cast<nsIContent*>(node),
mSerializer->AppendProcessingInstruction(pi, aStartOffset, aEndOffset, aStartOffset, aEndOffset, aStr);
aStr);
break; break;
} }
case nsIDOMNode::COMMENT_NODE: case nsIDOMNode::COMMENT_NODE:
{ {
nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(node); mSerializer->AppendComment(static_cast<nsIContent*>(node),
mSerializer->AppendComment(comment, aStartOffset, aEndOffset, aStr); aStartOffset, aEndOffset, aStr);
break; break;
} }
case nsIDOMNode::DOCUMENT_TYPE_NODE: case nsIDOMNode::DOCUMENT_TYPE_NODE:
{ {
nsCOMPtr<nsIDOMDocumentType> doctype = do_QueryInterface(node); mSerializer->AppendDoctype(static_cast<nsIContent*>(node), aStr);
mSerializer->AppendDoctype(doctype, aStr);
break; break;
} }
} }
@ -342,10 +341,8 @@ nsresult
nsDocumentEncoder::SerializeNodeEnd(nsINode* aNode, nsDocumentEncoder::SerializeNodeEnd(nsINode* aNode,
nsAString& aStr) nsAString& aStr)
{ {
//XXX Remove QIing to nsIDOM* when fixing bug 562321.
if (aNode->IsElement()) { if (aNode->IsElement()) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode); mSerializer->AppendElementEnd(static_cast<nsIContent*>(aNode), aStr);
mSerializer->AppendElementEnd(element, aStr);
} }
return NS_OK; return NS_OK;
} }
@ -953,8 +950,7 @@ nsDocumentEncoder::EncodeToString(nsAString& aOutputString)
rv = SerializeToStringRecursive(mNode, aOutputString, mNodeIsContainer); rv = SerializeToStringRecursive(mNode, aOutputString, mNodeIsContainer);
mNode = nsnull; mNode = nsnull;
} else { } else {
nsCOMPtr<nsIDOMDocument> domdoc(do_QueryInterface(mDocument)); rv = mSerializer->AppendDocumentStart(mDocument, aOutputString);
rv = mSerializer->AppendDocumentStart(domdoc, aOutputString);
if (NS_SUCCEEDED(rv)) { if (NS_SUCCEEDED(rv)) {
rv = SerializeToStringRecursive(mDocument, aOutputString, PR_FALSE); rv = SerializeToStringRecursive(mDocument, aOutputString, PR_FALSE);

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

@ -92,7 +92,7 @@ nsHTMLContentSerializer::~nsHTMLContentSerializer()
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument, nsHTMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr) nsAString& aStr)
{ {
return NS_OK; return NS_OK;
@ -100,7 +100,7 @@ nsHTMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument,
void void
nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent, nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aTagPrefix, nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI, const nsAString& aTagNamespaceURI,
nsIAtom* aTagName, nsIAtom* aTagName,
@ -190,14 +190,13 @@ nsHTMLContentSerializer::SerializeHTMLAttributes(nsIContent* aContent,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, nsHTMLContentSerializer::AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); nsIContent* content = aElement;
if (!content) return NS_ERROR_FAILURE;
PRBool forceFormat = PR_FALSE; PRBool forceFormat = PR_FALSE;
if (!CheckElementStart(content, forceFormat, aStr)) { if (!CheckElementStart(content, forceFormat, aStr)) {
@ -250,7 +249,8 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
// Store its start attribute value in olState->startVal. // Store its start attribute value in olState->startVal.
nsAutoString start; nsAutoString start;
PRInt32 startAttrVal = 0; PRInt32 startAttrVal = 0;
aElement->GetAttribute(NS_LITERAL_STRING("start"), start);
aElement->GetAttr(kNameSpaceID_None, nsGkAtoms::start, start);
if (!start.IsEmpty()){ if (!start.IsEmpty()){
PRInt32 rv = 0; PRInt32 rv = 0;
startAttrVal = start.ToInteger(&rv); startAttrVal = start.ToInteger(&rv);
@ -298,13 +298,12 @@ nsHTMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsHTMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement, nsHTMLContentSerializer::AppendElementEnd(nsIContent *aElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement); nsIContent* content = aElement;
if (!content) return NS_ERROR_FAILURE;
nsIAtom *name = content->Tag(); nsIAtom *name = content->Tag();

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

@ -57,19 +57,19 @@ class nsHTMLContentSerializer : public nsXHTMLContentSerializer {
nsHTMLContentSerializer(); nsHTMLContentSerializer();
virtual ~nsHTMLContentSerializer(); virtual ~nsHTMLContentSerializer();
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIContent *aElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument, NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr); nsAString& aStr);
protected: protected:
virtual void SerializeHTMLAttributes(nsIContent* aContent, virtual void SerializeHTMLAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aTagPrefix, nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI, const nsAString& aTagNamespaceURI,
nsIAtom* aTagName, nsIAtom* aTagName,

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

@ -290,7 +290,7 @@ nsPlainTextSerializer::Initialize(nsAString* aOutString,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AppendText(nsIDOMText* aText, nsPlainTextSerializer::AppendText(nsIContent* aText,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
@ -309,7 +309,7 @@ nsPlainTextSerializer::AppendText(nsIDOMText* aText,
PRInt32 length = 0; PRInt32 length = 0;
nsAutoString textstr; nsAutoString textstr;
nsCOMPtr<nsIContent> content = do_QueryInterface(aText); nsIContent* content = aText;
const nsTextFragment* frag; const nsTextFragment* frag;
if (!content || !(frag = content->GetText())) { if (!content || !(frag = content->GetText())) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -372,7 +372,7 @@ nsPlainTextSerializer::AppendText(nsIDOMText* aText,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AppendCDATASection(nsIDOMCDATASection* aCDATASection, nsPlainTextSerializer::AppendCDATASection(nsIContent* aCDATASection,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
@ -381,14 +381,13 @@ nsPlainTextSerializer::AppendCDATASection(nsIDOMCDATASection* aCDATASection,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AppendElementStart(nsIDOMElement *aElement, nsPlainTextSerializer::AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
mContent = do_QueryInterface(aElement); mContent = aElement;
if (!mContent) return NS_ERROR_FAILURE;
nsresult rv; nsresult rv;
PRInt32 id = GetIdForContent(mContent); PRInt32 id = GetIdForContent(mContent);
@ -415,13 +414,12 @@ nsPlainTextSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AppendElementEnd(nsIDOMElement *aElement, nsPlainTextSerializer::AppendElementEnd(nsIContent *aElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
mContent = do_QueryInterface(aElement); mContent = aElement;
if (!mContent) return NS_ERROR_FAILURE;
nsresult rv; nsresult rv;
PRInt32 id = GetIdForContent(mContent); PRInt32 id = GetIdForContent(mContent);
@ -456,8 +454,8 @@ nsPlainTextSerializer::Flush(nsAString& aStr)
} }
NS_IMETHODIMP NS_IMETHODIMP
nsPlainTextSerializer::AppendDocumentStart(nsIDOMDocument *aDocument, nsPlainTextSerializer::AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr) nsAString& aStr)
{ {
return NS_OK; return NS_OK;
} }

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

@ -71,27 +71,27 @@ public:
const char* aCharSet, PRBool aIsCopying, const char* aCharSet, PRBool aIsCopying,
PRBool aIsWholeDocument); PRBool aIsWholeDocument);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, NS_IMETHOD AppendText(nsIContent* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr); PRInt32 aEndOffset, nsAString& aStr);
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection, NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
PRInt32 aStartOffset, PRInt32 aEndOffset, PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, NS_IMETHOD AppendProcessingInstruction(nsIContent* aPI,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) { return NS_OK; } nsAString& aStr) { return NS_OK; }
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset, NS_IMETHOD AppendComment(nsIContent* aComment, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr) { return NS_OK; } PRInt32 aEndOffset, nsAString& aStr) { return NS_OK; }
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, NS_IMETHOD AppendDoctype(nsIContent *aDoctype,
nsAString& aStr) { return NS_OK; } nsAString& aStr) { return NS_OK; }
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIContent *aElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD Flush(nsAString& aStr); NS_IMETHOD Flush(nsAString& aStr);
NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument, NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr); nsAString& aStr);
// nsIContentSink // nsIContentSink

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

@ -155,7 +155,7 @@ nsXHTMLContentSerializer::HasLongLines(const nsString& text, PRInt32& aLastNewli
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXHTMLContentSerializer::AppendText(nsIDOMText* aText, nsXHTMLContentSerializer::AppendText(nsIContent* aText,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
@ -260,7 +260,7 @@ nsXHTMLContentSerializer::EscapeURI(nsIContent* aContent, const nsAString& aURI,
void void
nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent, nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aTagPrefix, nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI, const nsAString& aTagNamespaceURI,
nsIAtom* aTagName, nsIAtom* aTagName,
@ -306,9 +306,8 @@ nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
else if (aTagName == nsGkAtoms::li) { else if (aTagName == nsGkAtoms::li) {
mIsFirstChildOfOL = IsFirstChildOfOL(aOriginalElement); mIsFirstChildOfOL = IsFirstChildOfOL(aOriginalElement);
if (mIsFirstChildOfOL) { if (mIsFirstChildOfOL) {
nsCOMPtr<nsIDOMElement> element (do_QueryInterface(aContent));
// If OL is parent of this LI, serialize attributes in different manner. // If OL is parent of this LI, serialize attributes in different manner.
SerializeLIValueAttribute(element, aStr); SerializeLIValueAttribute(aContent, aStr);
} }
} }
} }
@ -445,7 +444,7 @@ nsXHTMLContentSerializer::SerializeAttributes(nsIContent* aContent,
void void
nsXHTMLContentSerializer::AppendEndOfElementStart(nsIDOMElement *aOriginalElement, nsXHTMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
nsIAtom * aName, nsIAtom * aName,
PRInt32 aNamespaceID, PRInt32 aNamespaceID,
nsAString& aStr) nsAString& aStr)
@ -460,7 +459,7 @@ nsXHTMLContentSerializer::AppendEndOfElementStart(nsIDOMElement *aOriginalElemen
return; return;
} }
nsCOMPtr<nsIContent> content = do_QueryInterface(aOriginalElement); nsIContent* content = aOriginalElement;
// for non empty elements, even if they are not a container, we always // for non empty elements, even if they are not a container, we always
// serialize their content, because the XHTML element could contain non XHTML // serialize their content, because the XHTML element could contain non XHTML
@ -487,7 +486,7 @@ nsXHTMLContentSerializer::AppendEndOfElementStart(nsIDOMElement *aOriginalElemen
void void
nsXHTMLContentSerializer::AfterElementStart(nsIContent * aContent, nsXHTMLContentSerializer::AfterElementStart(nsIContent * aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
nsIAtom *name = aContent->Tag(); nsIAtom *name = aContent->Tag();
@ -550,7 +549,7 @@ nsXHTMLContentSerializer::AfterElementEnd(nsIContent * aContent,
NS_IMETHODIMP NS_IMETHODIMP
nsXHTMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument, nsXHTMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr) nsAString& aStr)
{ {
if (!mBodyOnly) if (!mBodyOnly)
@ -979,7 +978,7 @@ nsXHTMLContentSerializer::MaybeLeaveFromPreContent(nsIContent* aNode)
} }
void void
nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIDOMElement* aElement, nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIContent* aElement,
nsAString& aStr) nsAString& aStr)
{ {
// We are copying and we are at the "first" LI node of OL in selected range. // We are copying and we are at the "first" LI node of OL in selected range.
@ -1050,7 +1049,7 @@ nsXHTMLContentSerializer::SerializeLIValueAttribute(nsIDOMElement* aElement,
} }
PRBool PRBool
nsXHTMLContentSerializer::IsFirstChildOfOL(nsIDOMElement* aElement) nsXHTMLContentSerializer::IsFirstChildOfOL(nsIContent* aElement)
{ {
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement); nsCOMPtr<nsIDOMNode> node = do_QueryInterface(aElement);
nsAutoString parentName; nsAutoString parentName;

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

@ -62,12 +62,12 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
const char* aCharSet, PRBool aIsCopying, const char* aCharSet, PRBool aIsCopying,
PRBool aRewriteEncodingDeclaration); PRBool aRewriteEncodingDeclaration);
NS_IMETHOD AppendText(nsIDOMText* aText, NS_IMETHOD AppendText(nsIContent* aText,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument, NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr); nsAString& aStr);
protected: protected:
@ -77,13 +77,13 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
PRBool & aForceFormat, PRBool & aForceFormat,
nsAString& aStr); nsAString& aStr);
virtual void AppendEndOfElementStart(nsIDOMElement *aOriginalElement, virtual void AppendEndOfElementStart(nsIContent *aOriginalElement,
nsIAtom * aName, nsIAtom * aName,
PRInt32 aNamespaceID, PRInt32 aNamespaceID,
nsAString& aStr); nsAString& aStr);
virtual void AfterElementStart(nsIContent * aContent, virtual void AfterElementStart(nsIContent * aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr); nsAString& aStr);
virtual PRBool CheckElementEnd(nsIContent * aContent, virtual PRBool CheckElementEnd(nsIContent * aContent,
@ -105,7 +105,7 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
virtual void MaybeLeaveFromPreContent(nsIContent* aNode); virtual void MaybeLeaveFromPreContent(nsIContent* aNode);
virtual void SerializeAttributes(nsIContent* aContent, virtual void SerializeAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aTagPrefix, nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI, const nsAString& aTagNamespaceURI,
nsIAtom* aTagName, nsIAtom* aTagName,
@ -113,9 +113,9 @@ class nsXHTMLContentSerializer : public nsXMLContentSerializer {
PRUint32 aSkipAttr, PRUint32 aSkipAttr,
PRBool aAddNSAttr); PRBool aAddNSAttr);
PRBool IsFirstChildOfOL(nsIDOMElement* aElement); PRBool IsFirstChildOfOL(nsIContent* aElement);
void SerializeLIValueAttribute(nsIDOMElement* aElement, void SerializeLIValueAttribute(nsIContent* aElement,
nsAString& aStr); nsAString& aStr);
PRBool IsShorthandAttr(const nsIAtom* aAttrName, PRBool IsShorthandAttr(const nsIAtom* aAttrName,
const nsIAtom* aElementName); const nsIAtom* aElementName);

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

@ -148,13 +148,13 @@ nsXMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
} }
nsresult nsresult
nsXMLContentSerializer::AppendTextData(nsIDOMNode* aNode, nsXMLContentSerializer::AppendTextData(nsIContent* aNode,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr, nsAString& aStr,
PRBool aTranslateEntities) PRBool aTranslateEntities)
{ {
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode); nsIContent* content = aNode;
const nsTextFragment* frag; const nsTextFragment* frag;
if (!content || !(frag = content->GetText())) { if (!content || !(frag = content->GetText())) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -194,7 +194,7 @@ nsXMLContentSerializer::AppendTextData(nsIDOMNode* aNode,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendText(nsIDOMText* aText, nsXMLContentSerializer::AppendText(nsIContent* aText,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
@ -225,7 +225,7 @@ nsXMLContentSerializer::AppendText(nsIDOMText* aText,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendCDATASection(nsIDOMCDATASection* aCDATASection, nsXMLContentSerializer::AppendCDATASection(nsIContent* aCDATASection,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
@ -260,21 +260,22 @@ nsXMLContentSerializer::AppendCDATASection(nsIDOMCDATASection* aCDATASection,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, nsXMLContentSerializer::AppendProcessingInstruction(nsIContent* aPI,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aPI); nsCOMPtr<nsIDOMProcessingInstruction> pi = do_QueryInterface(aPI);
NS_ENSURE_ARG(pi);
nsresult rv; nsresult rv;
nsAutoString target, data, start; nsAutoString target, data, start;
MaybeAddNewlineForRootNode(aStr); MaybeAddNewlineForRootNode(aStr);
rv = aPI->GetTarget(target); rv = pi->GetTarget(target);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aPI->GetData(data); rv = pi->GetData(data);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
start.AppendLiteral("<?"); start.AppendLiteral("<?");
@ -308,16 +309,17 @@ nsXMLContentSerializer::AppendProcessingInstruction(nsIDOMProcessingInstruction*
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendComment(nsIDOMComment* aComment, nsXMLContentSerializer::AppendComment(nsIContent* aComment,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aComment); nsCOMPtr<nsIDOMComment> comment = do_QueryInterface(aComment);
NS_ENSURE_ARG(comment);
nsresult rv; nsresult rv;
nsAutoString data; nsAutoString data;
rv = aComment->GetData(data); rv = comment->GetData(data);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
if (aStartOffset || (aEndOffset != -1)) { if (aStartOffset || (aEndOffset != -1)) {
@ -360,20 +362,21 @@ nsXMLContentSerializer::AppendComment(nsIDOMComment* aComment,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendDoctype(nsIDOMDocumentType *aDoctype, nsXMLContentSerializer::AppendDoctype(nsIContent* aDocType,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aDoctype); nsCOMPtr<nsIDOMDocumentType> docType = do_QueryInterface(aDocType);
NS_ENSURE_ARG(docType);
nsresult rv; nsresult rv;
nsAutoString name, publicId, systemId, internalSubset; nsAutoString name, publicId, systemId, internalSubset;
rv = aDoctype->GetName(name); rv = docType->GetName(name);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aDoctype->GetPublicId(publicId); rv = docType->GetPublicId(publicId);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aDoctype->GetSystemId(systemId); rv = docType->GetSystemId(systemId);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
rv = aDoctype->GetInternalSubset(internalSubset); rv = docType->GetInternalSubset(internalSubset);
if (NS_FAILED(rv)) return NS_ERROR_FAILURE; if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
MaybeAddNewlineForRootNode(aStr); MaybeAddNewlineForRootNode(aStr);
@ -427,7 +430,7 @@ nsXMLContentSerializer::AppendDoctype(nsIDOMDocumentType *aDoctype,
} }
AppendToString(kGreaterThan, aStr); AppendToString(kGreaterThan, aStr);
MaybeFlagNewlineForRootNode(aDoctype); MaybeFlagNewlineForRootNode(aDocType);
return NS_OK; return NS_OK;
} }
@ -435,7 +438,7 @@ nsXMLContentSerializer::AppendDoctype(nsIDOMDocumentType *aDoctype,
nsresult nsresult
nsXMLContentSerializer::PushNameSpaceDecl(const nsAString& aPrefix, nsXMLContentSerializer::PushNameSpaceDecl(const nsAString& aPrefix,
const nsAString& aURI, const nsAString& aURI,
nsIDOMElement* aOwner) nsIContent* aOwner)
{ {
NameSpaceDecl* decl = mNameSpaceStack.AppendElement(); NameSpaceDecl* decl = mNameSpaceStack.AppendElement();
if (!decl) return NS_ERROR_OUT_OF_MEMORY; if (!decl) return NS_ERROR_OUT_OF_MEMORY;
@ -449,7 +452,7 @@ nsXMLContentSerializer::PushNameSpaceDecl(const nsAString& aPrefix,
} }
void void
nsXMLContentSerializer::PopNameSpaceDeclsFor(nsIDOMElement* aOwner) nsXMLContentSerializer::PopNameSpaceDeclsFor(nsIContent* aOwner)
{ {
PRInt32 index, count; PRInt32 index, count;
@ -465,7 +468,7 @@ nsXMLContentSerializer::PopNameSpaceDeclsFor(nsIDOMElement* aOwner)
PRBool PRBool
nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix, nsXMLContentSerializer::ConfirmPrefix(nsAString& aPrefix,
const nsAString& aURI, const nsAString& aURI,
nsIDOMElement* aElement, nsIContent* aElement,
PRBool aIsAttribute) PRBool aIsAttribute)
{ {
if (aPrefix.EqualsLiteral(kXMLNS)) { if (aPrefix.EqualsLiteral(kXMLNS)) {
@ -716,7 +719,7 @@ nsXMLContentSerializer::SerializeAttr(const nsAString& aPrefix,
PRUint32 PRUint32
nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent, nsXMLContentSerializer::ScanNamespaceDeclarations(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
const nsAString& aTagNamespaceURI) const nsAString& aTagNamespaceURI)
{ {
PRUint32 index, count; PRUint32 index, count;
@ -812,7 +815,7 @@ nsXMLContentSerializer::IsJavaScript(nsIContent * aContent, nsIAtom* aAttrNameAt
void void
nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent, nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aTagPrefix, nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI, const nsAString& aTagNamespaceURI,
nsIAtom* aTagName, nsIAtom* aTagName,
@ -892,14 +895,13 @@ nsXMLContentSerializer::SerializeAttributes(nsIContent* aContent,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement, nsXMLContentSerializer::AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
nsCOMPtr<nsIContent> content(do_QueryInterface(aElement)); nsIContent* content = aElement;
if (!content) return NS_ERROR_FAILURE;
PRBool forceFormat = PR_FALSE; PRBool forceFormat = PR_FALSE;
if (!CheckElementStart(content, forceFormat, aStr)) { if (!CheckElementStart(content, forceFormat, aStr)) {
@ -907,9 +909,9 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI; nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
aElement->GetPrefix(tagPrefix); aElement->NodeInfo()->GetPrefix(tagPrefix);
aElement->GetLocalName(tagLocalName); aElement->NodeInfo()->GetLocalName(tagLocalName);
aElement->GetNamespaceURI(tagNamespaceURI); aElement->NodeInfo()->GetNamespaceURI(tagNamespaceURI);
PRUint32 skipAttr = ScanNamespaceDeclarations(content, PRUint32 skipAttr = ScanNamespaceDeclarations(content,
aOriginalElement, tagNamespaceURI); aOriginalElement, tagNamespaceURI);
@ -979,15 +981,13 @@ nsXMLContentSerializer::AppendElementStart(nsIDOMElement *aElement,
} }
void void
nsXMLContentSerializer::AppendEndOfElementStart(nsIDOMElement *aOriginalElement, nsXMLContentSerializer::AppendEndOfElementStart(nsIContent *aOriginalElement,
nsIAtom * aName, nsIAtom * aName,
PRInt32 aNamespaceID, PRInt32 aNamespaceID,
nsAString& aStr) nsAString& aStr)
{ {
// We don't output a separate end tag for empty elements // We don't output a separate end tag for empty elements
PRBool hasChildren = PR_FALSE; if (!aOriginalElement->GetChildCount()) {
if (NS_FAILED(aOriginalElement->HasChildNodes(&hasChildren)) ||
!hasChildren) {
AppendToString(NS_LITERAL_STRING("/>"), aStr); AppendToString(NS_LITERAL_STRING("/>"), aStr);
} }
else { else {
@ -996,13 +996,12 @@ nsXMLContentSerializer::AppendEndOfElementStart(nsIDOMElement *aOriginalElement,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement, nsXMLContentSerializer::AppendElementEnd(nsIContent *aElement,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG(aElement); NS_ENSURE_ARG(aElement);
nsCOMPtr<nsIContent> content(do_QueryInterface(aElement)); nsIContent* content = aElement;
if (!content) return NS_ERROR_FAILURE;
PRBool forceFormat = PR_FALSE, outputElementEnd; PRBool forceFormat = PR_FALSE, outputElementEnd;
outputElementEnd = CheckElementEnd(content, forceFormat, aStr); outputElementEnd = CheckElementEnd(content, forceFormat, aStr);
@ -1021,9 +1020,9 @@ nsXMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement,
nsAutoString tagPrefix, tagLocalName, tagNamespaceURI; nsAutoString tagPrefix, tagLocalName, tagNamespaceURI;
aElement->GetPrefix(tagPrefix); aElement->NodeInfo()->GetPrefix(tagPrefix);
aElement->GetLocalName(tagLocalName); aElement->NodeInfo()->GetLocalName(tagLocalName);
aElement->GetNamespaceURI(tagNamespaceURI); aElement->NodeInfo()->GetNamespaceURI(tagNamespaceURI);
#ifdef DEBUG #ifdef DEBUG
PRBool debugNeedToPushNamespace = PRBool debugNeedToPushNamespace =
@ -1077,18 +1076,13 @@ nsXMLContentSerializer::AppendElementEnd(nsIDOMElement *aElement,
} }
NS_IMETHODIMP NS_IMETHODIMP
nsXMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument, nsXMLContentSerializer::AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr) nsAString& aStr)
{ {
NS_ENSURE_ARG_POINTER(aDocument); NS_ENSURE_ARG_POINTER(aDocument);
nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDocument));
if (!doc) {
return NS_OK;
}
nsAutoString version, encoding, standalone; nsAutoString version, encoding, standalone;
doc->GetXMLDeclaration(version, encoding, standalone); aDocument->GetXMLDeclaration(version, encoding, standalone);
if (version.IsEmpty()) if (version.IsEmpty())
return NS_OK; // A declaration must have version, or there is no decl return NS_OK; // A declaration must have version, or there is no decl
@ -1134,17 +1128,10 @@ nsXMLContentSerializer::CheckElementEnd(nsIContent * aContent,
nsAString& aStr) nsAString& aStr)
{ {
// We don't output a separate end tag for empty element // We don't output a separate end tag for empty element
nsCOMPtr<nsIDOMNode> node(do_QueryInterface(aContent));
PRBool hasChildren;
aForceFormat = PR_FALSE; aForceFormat = PR_FALSE;
return aContent->GetChildCount() > 0;
if (NS_SUCCEEDED(node->HasChildNodes(&hasChildren)) && !hasChildren) {
return PR_FALSE;
}
return PR_TRUE;
} }
void void
nsXMLContentSerializer::AppendToString(const PRUnichar* aStr, nsXMLContentSerializer::AppendToString(const PRUnichar* aStr,
PRInt32 aLength, PRInt32 aLength,
@ -1245,14 +1232,11 @@ nsXMLContentSerializer::MaybeAddNewlineForRootNode(nsAString& aStr)
} }
void void
nsXMLContentSerializer::MaybeFlagNewlineForRootNode(nsIDOMNode* aNode) nsXMLContentSerializer::MaybeFlagNewlineForRootNode(nsINode* aNode)
{ {
nsCOMPtr<nsIDOMNode> parent; nsINode* parent = aNode->GetNodeParent();
aNode->GetParentNode(getter_AddRefs(parent));
if (parent) { if (parent) {
PRUint16 type; mAddNewlineForRootNode = aNode->IsNodeOfType(nsINode::eDOCUMENT);
parent->GetNodeType(&type);
mAddNewlineForRootNode = type == nsIDOMNode::DOCUMENT_NODE;
} }
} }

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

@ -70,34 +70,34 @@ class nsXMLContentSerializer : public nsIContentSerializer {
const char* aCharSet, PRBool aIsCopying, const char* aCharSet, PRBool aIsCopying,
PRBool aRewriteEncodingDeclaration); PRBool aRewriteEncodingDeclaration);
NS_IMETHOD AppendText(nsIDOMText* aText, PRInt32 aStartOffset, NS_IMETHOD AppendText(nsIContent* aText, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr); PRInt32 aEndOffset, nsAString& aStr);
NS_IMETHOD AppendCDATASection(nsIDOMCDATASection* aCDATASection, NS_IMETHOD AppendCDATASection(nsIContent* aCDATASection,
PRInt32 aStartOffset, PRInt32 aEndOffset, PRInt32 aStartOffset, PRInt32 aEndOffset,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendProcessingInstruction(nsIDOMProcessingInstruction* aPI, NS_IMETHOD AppendProcessingInstruction(nsIContent* aPI,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendComment(nsIDOMComment* aComment, PRInt32 aStartOffset, NS_IMETHOD AppendComment(nsIContent* aComment, PRInt32 aStartOffset,
PRInt32 aEndOffset, nsAString& aStr); PRInt32 aEndOffset, nsAString& aStr);
NS_IMETHOD AppendDoctype(nsIDOMDocumentType *aDoctype, NS_IMETHOD AppendDoctype(nsIContent *aDoctype,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementStart(nsIDOMElement *aElement, NS_IMETHOD AppendElementStart(nsIContent *aElement,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD AppendElementEnd(nsIDOMElement *aElement, NS_IMETHOD AppendElementEnd(nsIContent *aElement,
nsAString& aStr); nsAString& aStr);
NS_IMETHOD Flush(nsAString& aStr) { return NS_OK; } NS_IMETHOD Flush(nsAString& aStr) { return NS_OK; }
NS_IMETHOD AppendDocumentStart(nsIDOMDocument *aDocument, NS_IMETHOD AppendDocumentStart(nsIDocument *aDocument,
nsAString& aStr); nsAString& aStr);
protected: protected:
@ -185,7 +185,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
* retrieve the text content of the node and append it to the given string * retrieve the text content of the node and append it to the given string
* It doesn't increment the column position * It doesn't increment the column position
*/ */
nsresult AppendTextData(nsIDOMNode* aNode, nsresult AppendTextData(nsIContent* aNode,
PRInt32 aStartOffset, PRInt32 aStartOffset,
PRInt32 aEndOffset, PRInt32 aEndOffset,
nsAString& aStr, nsAString& aStr,
@ -193,8 +193,8 @@ class nsXMLContentSerializer : public nsIContentSerializer {
virtual nsresult PushNameSpaceDecl(const nsAString& aPrefix, virtual nsresult PushNameSpaceDecl(const nsAString& aPrefix,
const nsAString& aURI, const nsAString& aURI,
nsIDOMElement* aOwner); nsIContent* aOwner);
void PopNameSpaceDeclsFor(nsIDOMElement* aOwner); void PopNameSpaceDeclsFor(nsIContent* aOwner);
/** /**
* The problem that ConfirmPrefix fixes is that anyone can insert nodes * The problem that ConfirmPrefix fixes is that anyone can insert nodes
@ -216,7 +216,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
*/ */
PRBool ConfirmPrefix(nsAString& aPrefix, PRBool ConfirmPrefix(nsAString& aPrefix,
const nsAString& aURI, const nsAString& aURI,
nsIDOMElement* aElement, nsIContent* aElement,
PRBool aIsAttribute); PRBool aIsAttribute);
/** /**
* GenerateNewPrefix generates a new prefix and writes it to aPrefix * GenerateNewPrefix generates a new prefix and writes it to aPrefix
@ -224,11 +224,11 @@ class nsXMLContentSerializer : public nsIContentSerializer {
void GenerateNewPrefix(nsAString& aPrefix); void GenerateNewPrefix(nsAString& aPrefix);
PRUint32 ScanNamespaceDeclarations(nsIContent* aContent, PRUint32 ScanNamespaceDeclarations(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
const nsAString& aTagNamespaceURI); const nsAString& aTagNamespaceURI);
virtual void SerializeAttributes(nsIContent* aContent, virtual void SerializeAttributes(nsIContent* aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aTagPrefix, nsAString& aTagPrefix,
const nsAString& aTagNamespaceURI, const nsAString& aTagNamespaceURI,
nsIAtom* aTagName, nsIAtom* aTagName,
@ -263,7 +263,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
* this method is responsible to finish the start tag, * this method is responsible to finish the start tag,
* in particulary to append the "greater than" sign * in particulary to append the "greater than" sign
*/ */
virtual void AppendEndOfElementStart(nsIDOMElement *aOriginalElement, virtual void AppendEndOfElementStart(nsIContent *aOriginalElement,
nsIAtom * aName, nsIAtom * aName,
PRInt32 aNamespaceID, PRInt32 aNamespaceID,
nsAString& aStr); nsAString& aStr);
@ -274,7 +274,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
* (called at the end of AppendElementStart) * (called at the end of AppendElementStart)
*/ */
virtual void AfterElementStart(nsIContent * aContent, virtual void AfterElementStart(nsIContent * aContent,
nsIDOMElement *aOriginalElement, nsIContent *aOriginalElement,
nsAString& aStr) { }; nsAString& aStr) { };
/** /**
@ -328,7 +328,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
// Functions to check for newlines that needs to be added between nodes in // Functions to check for newlines that needs to be added between nodes in
// the root of a document. See mAddNewlineForRootNode // the root of a document. See mAddNewlineForRootNode
void MaybeAddNewlineForRootNode(nsAString& aStr); void MaybeAddNewlineForRootNode(nsAString& aStr);
void MaybeFlagNewlineForRootNode(nsIDOMNode* aNode); void MaybeFlagNewlineForRootNode(nsINode* aNode);
// Functions to check if we enter in or leave from a preformated content // Functions to check if we enter in or leave from a preformated content
virtual void MaybeEnterInPreContent(nsIContent* aNode); virtual void MaybeEnterInPreContent(nsIContent* aNode);
@ -339,7 +339,7 @@ class nsXMLContentSerializer : public nsIContentSerializer {
struct NameSpaceDecl { struct NameSpaceDecl {
nsString mPrefix; nsString mPrefix;
nsString mURI; nsString mURI;
nsIDOMElement* mOwner; nsIContent* mOwner;
}; };
nsTArray<NameSpaceDecl> mNameSpaceStack; nsTArray<NameSpaceDecl> mNameSpaceStack;