From ee0a2e7a8a4076db8c8fb6f783ee122dd5b86096 Mon Sep 17 00:00:00 2001 From: "bzbarsky%mit.edu" Date: Tue, 2 Mar 2004 22:39:46 +0000 Subject: [PATCH] Move CreateCDATASection, CreateProcessingInstruction, and CreateEntityReference up to nsDocument so they're available in XHTML documents. Bug 69840, r+sr=jst git-svn-id: svn://10.0.0.236/trunk@153443 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/content/base/src/nsDocument.cpp | 43 ++++++++++++-- .../html/document/src/nsHTMLDocument.cpp | 12 ++++ .../xml/document/src/nsXMLDocument.cpp | 59 +------------------ .../content/xml/document/src/nsXMLDocument.h | 7 --- 4 files changed, 52 insertions(+), 69 deletions(-) diff --git a/mozilla/content/base/src/nsDocument.cpp b/mozilla/content/base/src/nsDocument.cpp index 8b1539cc2a3..26a669be1ef 100644 --- a/mozilla/content/base/src/nsDocument.cpp +++ b/mozilla/content/base/src/nsDocument.cpp @@ -63,6 +63,8 @@ #include "nsIDOMDocumentXBL.h" #include "nsGenericElement.h" #include "nsIDOMEventGroup.h" +#include "nsIDOMCDATASection.h" +#include "nsIDOMProcessingInstruction.h" #include "nsRange.h" #include "nsIDOMText.h" @@ -2183,8 +2185,25 @@ NS_IMETHODIMP nsDocument::CreateCDATASection(const nsAString& aData, nsIDOMCDATASection** aReturn) { - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_ARG_POINTER(aReturn); + *aReturn = nsnull; + + nsReadingIterator begin; + nsReadingIterator end; + aData.BeginReading(begin); + aData.EndReading(end); + if (FindInReadable(NS_LITERAL_STRING("]]>"),begin,end)) + return NS_ERROR_DOM_INVALID_CHARACTER_ERR; + + nsCOMPtr content; + nsresult rv = NS_NewXMLCDATASection(getter_AddRefs(content)); + + if (NS_SUCCEEDED(rv)) { + rv = CallQueryInterface(content, aReturn); + (*aReturn)->AppendData(aData); + } + + return rv; } NS_IMETHODIMP @@ -2192,8 +2211,18 @@ nsDocument::CreateProcessingInstruction(const nsAString& aTarget, const nsAString& aData, nsIDOMProcessingInstruction** aReturn) { - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; + *aReturn = nsnull; + + nsresult rv = nsContentUtils::CheckQName(aTarget, PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr content; + rv = NS_NewXMLProcessingInstruction(getter_AddRefs(content), aTarget, aData); + if (NS_FAILED(rv)) { + return rv; + } + + return CallQueryInterface(content, aReturn); } NS_IMETHODIMP @@ -2246,8 +2275,10 @@ NS_IMETHODIMP nsDocument::CreateEntityReference(const nsAString& aName, nsIDOMEntityReference** aReturn) { - // Should be implemented by subclass - return NS_ERROR_NOT_IMPLEMENTED; + NS_ENSURE_ARG_POINTER(aReturn); + + *aReturn = nsnull; + return NS_OK; } NS_IMETHODIMP diff --git a/mozilla/content/html/document/src/nsHTMLDocument.cpp b/mozilla/content/html/document/src/nsHTMLDocument.cpp index 866f718e72b..802c8000110 100644 --- a/mozilla/content/html/document/src/nsHTMLDocument.cpp +++ b/mozilla/content/html/document/src/nsHTMLDocument.cpp @@ -1426,6 +1426,10 @@ nsHTMLDocument::CreateProcessingInstruction(const nsAString& aTarget, const nsAString& aData, nsIDOMProcessingInstruction** aReturn) { + if (IsXHTML()) { + return nsDocument::CreateProcessingInstruction(aTarget, aData, aReturn); + } + // There are no PIs for HTML *aReturn = nsnull; @@ -1436,6 +1440,10 @@ NS_IMETHODIMP nsHTMLDocument::CreateCDATASection(const nsAString& aData, nsIDOMCDATASection** aReturn) { + if (IsXHTML()) { + return nsDocument::CreateCDATASection(aData, aReturn); + } + // There are no CDATASections in HTML *aReturn = nsnull; @@ -1446,6 +1454,10 @@ NS_IMETHODIMP nsHTMLDocument::CreateEntityReference(const nsAString& aName, nsIDOMEntityReference** aReturn) { + if (IsXHTML()) { + return nsDocument::CreateEntityReference(aName, aReturn); + } + // There are no EntityReferences in HTML *aReturn = nsnull; diff --git a/mozilla/content/xml/document/src/nsXMLDocument.cpp b/mozilla/content/xml/document/src/nsXMLDocument.cpp index 49930d4685f..d4ebbc76702 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.cpp +++ b/mozilla/content/xml/document/src/nsXMLDocument.cpp @@ -60,8 +60,6 @@ #include "nsIDOMText.h" #include "nsIBaseWindow.h" #include "nsIDOMWindow.h" -#include "nsIDOMCDATASection.h" -#include "nsIDOMProcessingInstruction.h" #include "nsIDOMDocumentType.h" #include "nsINameSpaceManager.h" #include "nsICSSLoader.h" @@ -747,61 +745,8 @@ nsXMLDocument::InternalGetNumberOfStyleSheets() const return count; } -// nsIDOMDocument interface -NS_IMETHODIMP -nsXMLDocument::CreateCDATASection(const nsAString& aData, - nsIDOMCDATASection** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - *aReturn = nsnull; +// nsIDOMNode interface - nsReadingIterator begin; - nsReadingIterator end; - aData.BeginReading(begin); - aData.EndReading(end); - if (FindInReadable(NS_LITERAL_STRING("]]>"),begin,end)) - return NS_ERROR_DOM_INVALID_CHARACTER_ERR; - - nsCOMPtr content; - nsresult rv = NS_NewXMLCDATASection(getter_AddRefs(content)); - - if (NS_SUCCEEDED(rv)) { - rv = CallQueryInterface(content, aReturn); - (*aReturn)->AppendData(aData); - } - - return rv; -} - -NS_IMETHODIMP -nsXMLDocument::CreateEntityReference(const nsAString& aName, - nsIDOMEntityReference** aReturn) -{ - NS_ENSURE_ARG_POINTER(aReturn); - - *aReturn = nsnull; - return NS_OK; -} - -NS_IMETHODIMP -nsXMLDocument::CreateProcessingInstruction(const nsAString& aTarget, - const nsAString& aData, - nsIDOMProcessingInstruction** aReturn) -{ - *aReturn = nsnull; - - nsresult rv = nsContentUtils::CheckQName(aTarget, PR_FALSE); - NS_ENSURE_SUCCESS(rv, rv); - - nsCOMPtr content; - rv = NS_NewXMLProcessingInstruction(getter_AddRefs(content), aTarget, aData); - if (NS_FAILED(rv)) { - return rv; - } - - return CallQueryInterface(content, aReturn); -} - NS_IMETHODIMP nsXMLDocument::CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { @@ -908,6 +853,8 @@ MatchElementId(nsIContent *aContent, const nsACString& aUTF8Id, const nsAString& return result; } +// nsIDOMDocument interface + NS_IMETHODIMP nsXMLDocument::GetElementById(const nsAString& aElementId, nsIDOMElement** aReturn) diff --git a/mozilla/content/xml/document/src/nsXMLDocument.h b/mozilla/content/xml/document/src/nsXMLDocument.h index 01a9dc42bc5..696c0fe0571 100644 --- a/mozilla/content/xml/document/src/nsXMLDocument.h +++ b/mozilla/content/xml/document/src/nsXMLDocument.h @@ -82,13 +82,6 @@ public: NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn); // nsIDOMDocument interface - NS_IMETHOD CreateCDATASection(const nsAString& aData, - nsIDOMCDATASection** aReturn); - NS_IMETHOD CreateEntityReference(const nsAString& aName, - nsIDOMEntityReference** aReturn); - NS_IMETHOD CreateProcessingInstruction(const nsAString& aTarget, - const nsAString& aData, - nsIDOMProcessingInstruction** aReturn); NS_IMETHOD GetElementById(const nsAString& aElementId, nsIDOMElement** aReturn);