From e369dd9f777475a0a4b5184688b723899b9ded26 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Tue, 14 Jun 2011 16:25:51 +0200 Subject: [PATCH] Bug 664123 - Backout bugs 659053 and 659539 (changesets 9c49f69d8bab-1b11c64ffcdf) --- accessible/src/base/nsCoreUtils.cpp | 1 + content/base/public/nsContentUtils.h | 15 +- content/base/public/nsIContent.h | 6 + content/base/public/nsINode.h | 69 +- content/base/public/nsINodeInfo.h | 69 +- content/base/src/nsCommentNode.cpp | 35 +- content/base/src/nsContentList.cpp | 1 + content/base/src/nsContentUtils.cpp | 6 +- content/base/src/nsDOMAttribute.cpp | 94 +-- content/base/src/nsDOMAttribute.h | 5 +- content/base/src/nsDOMAttributeMap.cpp | 9 +- content/base/src/nsDOMDocumentType.cpp | 54 +- content/base/src/nsDOMDocumentType.h | 38 +- content/base/src/nsDocument.cpp | 106 +-- content/base/src/nsDocument.h | 5 +- content/base/src/nsDocumentEncoder.cpp | 4 +- content/base/src/nsDocumentFragment.cpp | 87 ++- content/base/src/nsGenericDOMDataNode.cpp | 17 +- content/base/src/nsGenericDOMDataNode.h | 115 ++- content/base/src/nsGenericElement.cpp | 733 ++++++++++-------- content/base/src/nsGenericElement.h | 13 +- content/base/src/nsGkAtomList.h | 1 - content/base/src/nsNodeInfo.cpp | 66 +- content/base/src/nsNodeInfo.h | 42 +- content/base/src/nsNodeInfoManager.cpp | 52 +- content/base/src/nsNodeInfoManager.h | 9 +- content/base/src/nsNodeUtils.cpp | 4 +- content/base/src/nsTextNode.cpp | 28 +- content/base/src/nsTextNode.h | 7 +- content/base/src/nsTraversal.cpp | 33 +- content/base/test/test_bug352728.html | 2 +- content/base/test/test_bug352728.xhtml | 6 +- .../html/content/src/nsHTMLAudioElement.cpp | 3 +- .../html/content/src/nsHTMLImageElement.cpp | 3 +- .../html/content/src/nsHTMLOptionElement.cpp | 3 +- .../html/content/src/nsTextEditorState.cpp | 6 +- content/html/content/test/test_bug389797.html | 3 +- content/html/document/src/ImageDocument.cpp | 3 +- content/html/document/src/MediaDocument.cpp | 9 +- content/html/document/src/PluginDocument.cpp | 3 +- content/html/document/src/VideoDocument.cpp | 3 +- .../html/document/src/nsHTMLContentSink.cpp | 16 +- .../src/nsHTMLFragmentContentSink.cpp | 20 +- content/svg/content/src/nsSVGElement.cpp | 3 +- content/svg/content/src/nsSVGUseElement.cpp | 4 +- content/test/unit/head_content.js | 1 + content/test/unit/test_isequalnode.js | 7 + content/test/unit/test_range.js | 7 +- content/xbl/src/nsXBLContentSink.cpp | 3 +- content/xbl/src/nsXBLService.cpp | 63 +- content/xml/content/src/nsXMLCDATASection.cpp | 38 +- .../src/nsXMLProcessingInstruction.cpp | 51 +- .../content/src/nsXMLProcessingInstruction.h | 10 +- content/xml/content/src/nsXMLStylesheetPI.cpp | 7 +- content/xml/document/src/nsXMLContentSink.cpp | 3 +- .../document/src/nsXMLFragmentContentSink.cpp | 29 +- content/xslt/src/xpath/nsXPathExpression.cpp | 7 +- content/xslt/src/xpath/nsXPathNSResolver.cpp | 2 +- content/xslt/src/xpath/nsXPathNSResolver.h | 3 +- .../src/xpath/txMozillaXPathTreeWalker.cpp | 35 +- content/xslt/src/xslt/txMozillaTextOutput.cpp | 3 +- content/xslt/src/xslt/txMozillaXMLOutput.cpp | 6 +- content/xtf/src/nsXTFElementWrapper.cpp | 4 +- content/xul/content/src/nsXULElement.cpp | 9 +- content/xul/document/src/nsXULContentSink.cpp | 6 +- content/xul/document/src/nsXULDocument.cpp | 3 +- .../document/src/nsXULPrototypeDocument.cpp | 7 +- .../xul/templates/src/nsXULContentBuilder.cpp | 3 +- dom/base/nsDOMClassInfo.cpp | 23 + dom/base/nsFocusManager.cpp | 10 +- dom/interfaces/base/Makefile.in | 1 + .../base/nsIDOMNSFeatureFactory.idl | 64 ++ dom/interfaces/core/Makefile.in | 1 + dom/interfaces/core/nsIDOM3Node.idl | 87 +++ dom/interfaces/core/nsIDOMNode.idl | 43 +- editor/libeditor/html/nsHTMLEditRules.cpp | 1 + editor/txtsvc/src/nsTextServicesDocument.cpp | 23 +- .../activex/src/common/IEHtmlElement.cpp | 11 +- .../webBrowser/nsDocShellTreeOwner.cpp | 3 +- .../src/nsWebBrowserPersist.cpp | 4 +- .../tests/js1_5/extensions/regress-375344.js | 4 +- js/src/xpconnect/src/dom_quickstubs.qsconf | 76 +- layout/base/nsCSSFrameConstructor.cpp | 8 +- layout/base/nsPresShell.cpp | 16 +- layout/build/nsContentDLF.cpp | 9 +- layout/forms/nsComboboxControlFrame.cpp | 3 +- layout/forms/nsFileControlFrame.cpp | 9 +- layout/forms/nsIsIndexFrame.cpp | 9 +- layout/forms/nsProgressFrame.cpp | 3 +- layout/generic/nsGfxScrollFrame.cpp | 9 +- layout/generic/nsVideoFrame.cpp | 6 +- layout/inspector/src/inCSSValueSearch.cpp | 17 +- layout/style/Loader.cpp | 1 + layout/xul/base/src/nsDocElementBoxFrame.cpp | 6 +- .../test/test_default_index_handler.js | 8 +- parser/html/nsHtml5TreeOperation.cpp | 6 +- widget/src/xpwidgets/GfxInfoBase.cpp | 7 +- 97 files changed, 1439 insertions(+), 1147 deletions(-) create mode 100644 dom/interfaces/base/nsIDOMNSFeatureFactory.idl create mode 100644 dom/interfaces/core/nsIDOM3Node.idl diff --git a/accessible/src/base/nsCoreUtils.cpp b/accessible/src/base/nsCoreUtils.cpp index 4db09eeb8cf1..8b986a47240c 100644 --- a/accessible/src/base/nsCoreUtils.cpp +++ b/accessible/src/base/nsCoreUtils.cpp @@ -43,6 +43,7 @@ #include "nsAccessNode.h" #include "nsIDocument.h" +#include "nsIDOM3Node.h" #include "nsIDOMDocument.h" #include "nsIDOMHTMLDocument.h" #include "nsIDOMHTMLElement.h" diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index 89c42f9cf9fc..4ec4428b4ffa 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -69,6 +69,7 @@ static fp_except_t oldmask = fpsetmask(~allmask); #include "nsContentList.h" #include "nsDOMClassInfoID.h" #include "nsIXPCScriptable.h" +#include "nsIDOM3Node.h" #include "nsDataHashtable.h" #include "nsIScriptRuntime.h" #include "nsIScriptGlobalObject.h" @@ -302,10 +303,10 @@ public: static PRBool PositionIsBefore(nsINode* aNode1, nsINode* aNode2) { - return (aNode2->CompareDocPosition(aNode1) & - (nsIDOMNode::DOCUMENT_POSITION_PRECEDING | - nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED)) == - nsIDOMNode::DOCUMENT_POSITION_PRECEDING; + return (aNode2->CompareDocumentPosition(aNode1) & + (nsIDOM3Node::DOCUMENT_POSITION_PRECEDING | + nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED)) == + nsIDOM3Node::DOCUMENT_POSITION_PRECEDING; } /** @@ -341,6 +342,7 @@ public: * @return The reversed document position flags. * * @see nsIDOMNode + * @see nsIDOM3Node */ static PRUint16 ReverseDocumentPosition(PRUint16 aDocumentPosition); @@ -546,7 +548,6 @@ public: static nsresult GetNodeInfoFromQName(const nsAString& aNamespaceURI, const nsAString& aQualifiedName, nsNodeInfoManager* aNodeInfoManager, - PRUint16 aNodeType, nsINodeInfo** aNodeInfo); static void SplitExpatName(const PRUnichar *aExpatName, nsIAtom **aPrefix, @@ -690,9 +691,7 @@ public: nsNodeInfoManager *niMgr = aNodeInfo->NodeInfoManager(); *aResult = niMgr->GetNodeInfo(aName, aNodeInfo->GetPrefixAtom(), - aNodeInfo->NamespaceID(), - aNodeInfo->NodeType(), - aNodeInfo->GetExtraName()).get(); + aNodeInfo->NamespaceID()).get(); return *aResult ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } diff --git a/content/base/public/nsIContent.h b/content/base/public/nsIContent.h index 5ed61b7b6bd3..6143a046c180 100644 --- a/content/base/public/nsIContent.h +++ b/content/base/public/nsIContent.h @@ -928,6 +928,12 @@ public: nsresult LookupNamespaceURI(const nsAString& aNamespacePrefix, nsAString& aNamespaceURI) const; + nsIAtom* LookupPrefix(const nsAString& aNamespaceURI); + + PRBool IsEqual(nsIContent *aOther); + + virtual PRBool IsEqualNode(nsINode* aOther); + /** * If this content has independent selection, e.g., if this is input field * or textarea, this return TRUE. Otherwise, false. diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h index 8e768214e072..cafde14d1d4b 100644 --- a/content/base/public/nsINode.h +++ b/content/base/public/nsINode.h @@ -436,22 +436,7 @@ public: return IsInDoc() ? GetOwnerDoc() : nsnull; } - /** - * The values returned by this function are the ones defined for - * nsIDOMNode.nodeType - */ - PRUint16 NodeType() const - { - return mNodeInfo->NodeType(); - } - const nsString& NodeName() const - { - return mNodeInfo->NodeName(); - } - const nsString& LocalName() const - { - return mNodeInfo->LocalName(); - } + NS_IMETHOD GetNodeType(PRUint16* aNodeType) = 0; nsINode* InsertBefore(nsINode *aNewChild, nsINode *aRefChild, nsresult *aReturn) @@ -984,16 +969,13 @@ public: */ virtual already_AddRefed GetBaseURI() const = 0; - nsresult GetDOMBaseURI(nsAString &aURI) const; + void GetBaseURI(nsAString &aURI) const; - // Note! This function must never fail. It only return an nsresult so that - // we can use it to implement nsIDOMNode - NS_IMETHOD GetTextContent(nsAString &aTextContent) + virtual void GetTextContent(nsAString &aTextContent) { SetDOMStringToNull(aTextContent); - return NS_OK; } - NS_IMETHOD SetTextContent(const nsAString& aTextContent) + virtual nsresult SetTextContent(const nsAString& aTextContent) { return NS_OK; } @@ -1033,13 +1015,9 @@ public: return static_cast(GetProperty(DOM_USER_DATA, key)); } - nsresult GetUserData(const nsAString& aKey, nsIVariant** aResult) - { - NS_IF_ADDREF(*aResult = GetUserData(aKey)); - - return NS_OK; - } - + nsresult GetFeature(const nsAString& aFeature, + const nsAString& aVersion, + nsISupports** aReturn); /** * Compares the document position of a node to this node. @@ -1051,33 +1029,34 @@ public: * DOCUMENT_POSITION_PRECEDING will be set. * * @see nsIDOMNode + * @see nsIDOM3Node */ - PRUint16 CompareDocPosition(nsINode* aOtherNode); - nsresult CompareDocPosition(nsINode* aOtherNode, PRUint16* aReturn) + PRUint16 CompareDocumentPosition(nsINode* aOtherNode); + nsresult CompareDocumentPosition(nsINode* aOtherNode, PRUint16* aResult) { NS_ENSURE_ARG(aOtherNode); - *aReturn = CompareDocPosition(aOtherNode); + + *aResult = CompareDocumentPosition(aOtherNode); + return NS_OK; } - nsresult CompareDocumentPosition(nsIDOMNode* aOther, - PRUint16* aReturn); - nsresult IsSameNode(nsIDOMNode* aOther, - PRBool* aReturn); + PRBool IsSameNode(nsINode *aOtherNode) + { + return aOtherNode == this; + } - nsresult LookupPrefix(const nsAString& aNamespaceURI, nsAString& aPrefix); - nsresult IsDefaultNamespace(const nsAString& aNamespaceURI, PRBool* aResult) + virtual PRBool IsEqualNode(nsINode *aOtherNode) = 0; + + void LookupPrefix(const nsAString& aNamespaceURI, nsAString& aPrefix); + PRBool IsDefaultNamespace(const nsAString& aNamespaceURI) { nsAutoString defaultNamespace; LookupNamespaceURI(EmptyString(), defaultNamespace); - *aResult = aNamespaceURI.Equals(defaultNamespace); - return NS_OK; + return aNamespaceURI.Equals(defaultNamespace); } - nsresult LookupNamespaceURI(const nsAString& aNamespacePrefix, - nsAString& aNamespaceURI); - - nsresult IsEqualNode(nsIDOMNode* aOther, PRBool* aReturn); - PRBool IsEqualTo(nsINode* aOther); + void LookupNamespaceURI(const nsAString& aNamespacePrefix, + nsAString& aNamespaceURI); nsIContent* GetNextSibling() const { return mNextSibling; } nsIContent* GetPreviousSibling() const { return mPreviousSibling; } diff --git a/content/base/public/nsINodeInfo.h b/content/base/public/nsINodeInfo.h index 981e368b3b2c..2520899cbfc1 100644 --- a/content/base/public/nsINodeInfo.h +++ b/content/base/public/nsINodeInfo.h @@ -81,7 +81,7 @@ public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_INODEINFO_IID) nsINodeInfo() - : mInner(nsnull, nsnull, kNameSpaceID_None, 0, nsnull), + : mInner(nsnull, nsnull, kNameSpaceID_None), mOwnerManager(nsnull) { } @@ -121,17 +121,12 @@ public: } /* - * Returns the node's nodeName as defined in DOM Core + * As above, but return the qualified name in corrected case as + * needed. For example, for HTML elements in HTML documents, this + * will return an ASCII-uppercased version of the qualified name. */ - const nsString& NodeName() const { - return mNodeName; - } - - /* - * Returns the node's localName as defined in DOM Core - */ - const nsString& LocalName() const { - return mLocalName; + const nsString& QualifiedNameCorrectedCase() const { + return mQualifiedNameCorrectedCase; } #ifdef MOZILLA_INTERNAL_API @@ -164,35 +159,30 @@ public: /* * Get the namespace URI for a node, if the node has a namespace URI. + * + * For the HTML element "" in a HTML document this will return a null + * string and for the XML element "" (assuming that this element, + * or one of its ancestors has an + * xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return + * the string "http://www.w3.org/1999/xhtml". */ virtual nsresult GetNamespaceURI(nsAString& aNameSpaceURI) const = 0; /* * Get the namespace ID for a node if the node has a namespace, if not this * returns kNameSpaceID_None. + * + * For the HTML element "" in a HTML document this will return + * kNameSpaceID_None and for the XML element "" (assuming that + * this element, or one of its ancestors has an + * xmlns:html='http://www.w3.org/1999/xhtml' attribute) this will return + * the namespace ID for "http://www.w3.org/1999/xhtml". */ PRInt32 NamespaceID() const { return mInner.mNamespaceID; } - /* - * Get the nodetype for the node. Returns the values specified in nsIDOMNode - * for nsIDOMNode.nodeType - */ - PRUint16 NodeType() const - { - return mInner.mNodeType; - } - - /* - * Get the extra name, used by PIs and DocTypes, for the node. - */ - nsIAtom* GetExtraName() const - { - return mInner.mExtraName; - } - /* * Get and set the ID attribute atom for this node. * See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types @@ -332,28 +322,24 @@ protected: public: nsNodeInfoInner() : mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_Unknown), - mNodeType(0), mNameString(nsnull), mExtraName(nsnull) + mNameString(nsnull) { } - nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, - PRUint16 aNodeType, nsIAtom* aExtraName) + nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID) : mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID), - mNodeType(aNodeType), mNameString(nsnull), mExtraName(aExtraName) + mNameString(nsnull) { } - nsNodeInfoInner(const nsAString& aTmpName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, PRUint16 aNodeType) + nsNodeInfoInner(const nsAString& aTmpName, nsIAtom *aPrefix, PRInt32 aNamespaceID) : mName(nsnull), mPrefix(aPrefix), mNamespaceID(aNamespaceID), - mNodeType(aNodeType), mNameString(&aTmpName), mExtraName(nsnull) + mNameString(&aTmpName) { } nsIAtom* mName; nsIAtom* mPrefix; PRInt32 mNamespaceID; - PRUint16 mNodeType; // As defined by nsIDOMNode.nodeType const nsAString* mNameString; - nsIAtom* mExtraName; // Only used by PIs and DocTypes }; // nsNodeInfoManager needs to pass mInner to the hash table. @@ -372,12 +358,9 @@ protected: // Qualified name nsString mQualifiedName; - // nodeName for the node. - nsString mNodeName; - - // localName for the node. This is either equal to mInner.mName, or a - // void string, depending on mInner.mNodeType. - nsString mLocalName; + // Qualified name in "corrected case"; this will depend on our + // document and on mNamespaceID. + nsString mQualifiedNameCorrectedCase; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsINodeInfo, NS_INODEINFO_IID) diff --git a/content/base/src/nsCommentNode.cpp b/content/base/src/nsCommentNode.cpp index f4f9eda7b966..dbdda1a98cc2 100644 --- a/content/base/src/nsCommentNode.cpp +++ b/content/base/src/nsCommentNode.cpp @@ -55,7 +55,7 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA // nsIDOMCharacterData NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::) @@ -63,12 +63,9 @@ public: // nsIDOMComment // Empty interface - // nsINode + // nsIContent virtual PRBool IsNodeOfType(PRUint32 aFlags) const; - virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo, - PRBool aCloneText) const; - virtual nsXPCClassInfo* GetClassInfo(); #ifdef DEBUG virtual void List(FILE* out, PRInt32 aIndent) const; @@ -104,8 +101,6 @@ NS_NewCommentNode(nsIContent** aInstancePtrResult, nsCommentNode::nsCommentNode(already_AddRefed aNodeInfo) : nsGenericDOMDataNode(aNodeInfo) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE, - "Bad NodeType in aNodeInfo"); } nsCommentNode::~nsCommentNode() @@ -132,6 +127,32 @@ nsCommentNode::IsNodeOfType(PRUint32 aFlags) const return !(aFlags & ~(eCONTENT | eCOMMENT | eDATA_NODE)); } +NS_IMETHODIMP +nsCommentNode::GetNodeName(nsAString& aNodeName) +{ + aNodeName.AssignLiteral("#comment"); + return NS_OK; +} + +NS_IMETHODIMP +nsCommentNode::GetNodeValue(nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::GetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsCommentNode::SetNodeValue(const nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::SetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsCommentNode::GetNodeType(PRUint16* aNodeType) +{ + *aNodeType = (PRUint16)nsIDOMNode::COMMENT_NODE; + return NS_OK; +} + nsGenericDOMDataNode* nsCommentNode::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { diff --git a/content/base/src/nsContentList.cpp b/content/base/src/nsContentList.cpp index 2b890d140868..7d8bd46b6723 100644 --- a/content/base/src/nsContentList.cpp +++ b/content/base/src/nsContentList.cpp @@ -45,6 +45,7 @@ #include "nsContentList.h" #include "nsIContent.h" #include "nsIDOMNode.h" +#include "nsIDOM3Node.h" #include "nsIDocument.h" #include "nsGenericElement.h" diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 5f320b75744f..77d7b103395e 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -64,6 +64,7 @@ #include "nsIDOMDocument.h" #include "nsIDOMNodeList.h" #include "nsIDOMNode.h" +#include "nsIDOM3Node.h" #include "nsIIOService.h" #include "nsNetCID.h" #include "nsNetUtil.h" @@ -2088,7 +2089,6 @@ nsresult nsContentUtils::GetNodeInfoFromQName(const nsAString& aNamespaceURI, const nsAString& aQualifiedName, nsNodeInfoManager* aNodeInfoManager, - PRUint16 aNodeType, nsINodeInfo** aNodeInfo) { nsIParserService* parserService = GetParserService(); @@ -2108,11 +2108,11 @@ nsContentUtils::GetNodeInfoFromQName(const nsAString& aNamespaceURI, nsCOMPtr prefix = do_GetAtom(Substring(qName.get(), colon)); rv = aNodeInfoManager->GetNodeInfo(Substring(colon + 1, end), prefix, - nsID, aNodeType, aNodeInfo); + nsID, aNodeInfo); } else { rv = aNodeInfoManager->GetNodeInfo(aQualifiedName, nsnull, nsID, - aNodeType, aNodeInfo); + aNodeInfo); } NS_ENSURE_SUCCESS(rv, rv); diff --git a/content/base/src/nsDOMAttribute.cpp b/content/base/src/nsDOMAttribute.cpp index 9d5d182b741c..87caf077b866 100644 --- a/content/base/src/nsDOMAttribute.cpp +++ b/content/base/src/nsDOMAttribute.cpp @@ -72,8 +72,7 @@ nsDOMAttribute::nsDOMAttribute(nsDOMAttributeMap *aAttrMap, : nsIAttribute(aAttrMap, aNodeInfo, aNsAware), mValue(aValue), mChild(nsnull) { NS_ABORT_IF_FALSE(mNodeInfo, "We must get a nodeinfo here!"); - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::ATTRIBUTE_NODE, - "Wrong nodeType"); + // We don't add a reference to our content. It will tell us // to drop our reference when it goes away. @@ -141,6 +140,7 @@ NS_INTERFACE_TABLE_HEAD(nsDOMAttribute) nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSEventTarget, nsDOMEventRTTearoff::Create(this)) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver, new nsNode3Tearoff(this)) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Attr) @@ -193,8 +193,7 @@ nsDOMAttribute::SetOwnerDocument(nsIDocument* aDocument) nsCOMPtr newNodeInfo; newNodeInfo = aDocument->NodeInfoManager()-> GetNodeInfo(mNodeInfo->NameAtom(), mNodeInfo->GetPrefixAtom(), - mNodeInfo->NamespaceID(), - nsIDOMNode::ATTRIBUTE_NODE); + mNodeInfo->NamespaceID()); NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); NS_ASSERTION(newNodeInfo, "GetNodeInfo lies"); mNodeInfo.swap(newNodeInfo); @@ -205,7 +204,7 @@ nsDOMAttribute::SetOwnerDocument(nsIDocument* aDocument) NS_IMETHODIMP nsDOMAttribute::GetName(nsAString& aName) { - aName = NodeName(); + aName = mNodeInfo->QualifiedName(); return NS_OK; } @@ -500,81 +499,40 @@ nsDOMAttribute::GetBaseURI() const return parent ? parent->GetBaseURI() : nsnull; } -NS_IMETHODIMP -nsDOMAttribute::GetDOMBaseURI(nsAString &aURI) +PRBool +nsDOMAttribute::IsEqualNode(nsINode* aOther) { - return nsINode::GetDOMBaseURI(aURI); + if (!aOther || !aOther->IsNodeOfType(eATTRIBUTE)) + return PR_FALSE; + + nsDOMAttribute *other = static_cast(aOther); + + // Prefix, namespace URI, local name, node name check. + if (!mNodeInfo->Equals(other->NodeInfo())) { + return PR_FALSE; + } + + // Value check + // Checks not needed: Child nodes, attributes. + nsAutoString ourValue, otherValue; + GetValue(ourValue); + other->GetValue(otherValue); + + return ourValue.Equals(otherValue); } -NS_IMETHODIMP -nsDOMAttribute::CompareDocumentPosition(nsIDOMNode *other, - PRUint16 *aResult) -{ - return nsINode::CompareDocumentPosition(other, aResult); -} - -NS_IMETHODIMP -nsDOMAttribute::IsEqualNode(nsIDOMNode* aOther, PRBool* aResult) -{ - return nsINode::IsEqualNode(aOther, aResult); -} - -NS_IMETHODIMP +void nsDOMAttribute::GetTextContent(nsAString &aTextContent) { - return GetNodeValue(aTextContent); + GetNodeValue(aTextContent); } -NS_IMETHODIMP +nsresult nsDOMAttribute::SetTextContent(const nsAString& aTextContent) { return SetNodeValue(aTextContent); } -NS_IMETHODIMP -nsDOMAttribute::IsSameNode(nsIDOMNode *other, PRBool *aResult) -{ - *aResult = other == this; - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::LookupPrefix(const nsAString & namespaceURI, - nsAString & aResult) -{ - SetDOMStringToNull(aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::IsDefaultNamespace(const nsAString & namespaceURI, - PRBool *aResult) -{ - *aResult = namespaceURI.IsEmpty(); - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::LookupNamespaceURI(const nsAString & prefix, - nsAString & aResult) -{ - SetDOMStringToNull(aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsDOMAttribute::SetUserData(const nsAString & key, - nsIVariant *data, nsIDOMUserDataHandler *handler, - nsIVariant **aResult) -{ - return nsINode::SetUserData(key, data, handler, aResult); -} - -NS_IMETHODIMP -nsDOMAttribute::GetUserData(const nsAString & key, nsIVariant **aResult) -{ - return nsINode::GetUserData(key, aResult); -} NS_IMETHODIMP nsDOMAttribute::GetIsId(PRBool* aReturn) diff --git a/content/base/src/nsDOMAttribute.h b/content/base/src/nsDOMAttribute.h index 346856654116..b2381fe012ec 100644 --- a/content/base/src/nsDOMAttribute.h +++ b/content/base/src/nsDOMAttribute.h @@ -56,7 +56,7 @@ #include "nsStubMutationObserver.h" // Attribute helper class used to wrap up an attribute with a dom -// object that implements nsIDOMAttr, nsIDOM3Attr, nsIDOMNode +// object that implements nsIDOMAttr, nsIDOM3Attr, nsIDOMNode, nsIDOM3Node class nsDOMAttribute : public nsIAttribute, public nsIDOMAttr, public nsIDOM3Attr, @@ -112,6 +112,9 @@ public: } virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const; virtual already_AddRefed GetBaseURI() const; + virtual PRBool IsEqualNode(nsINode *aOtherNode); + virtual void GetTextContent(nsAString &aTextContent); + virtual nsresult SetTextContent(const nsAString& aTextContent); static void Initialize(); static void Shutdown(); diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp index c8c0618de730..99ea25bb2951 100644 --- a/content/base/src/nsDOMAttributeMap.cpp +++ b/content/base/src/nsDOMAttributeMap.cpp @@ -341,8 +341,7 @@ nsDOMAttributeMap::SetNamedItemInternal(nsIDOMNode *aNode, } rv = mContent->NodeInfo()->NodeInfoManager()-> - GetNodeInfo(name, nsnull, kNameSpaceID_None, - nsIDOMNode::ATTRIBUTE_NODE, getter_AddRefs(ni)); + GetNodeInfo(name, nsnull, kNameSpaceID_None, getter_AddRefs(ni)); NS_ENSURE_SUCCESS(rv, rv); // value is already empty } @@ -408,8 +407,7 @@ nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult) // have the wrong owner document. nsCOMPtr ni; ni = mContent->NodeInfo()->NodeInfoManager()-> - GetNodeInfo(name->LocalName(), name->GetPrefix(), name->NamespaceID(), - nsIDOMNode::ATTRIBUTE_NODE); + GetNodeInfo(name->LocalName(), name->GetPrefix(), name->NamespaceID()); if (ni) { node = GetAttribute(ni, PR_TRUE); } @@ -486,8 +484,7 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI, nameAtom->Equals(aLocalName)) { nsCOMPtr ni; ni = mContent->NodeInfo()->NodeInfoManager()-> - GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID, - nsIDOMNode::ATTRIBUTE_NODE); + GetNodeInfo(nameAtom, name->GetPrefix(), nameSpaceID); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); if (aRemove) { diff --git a/content/base/src/nsDOMDocumentType.cpp b/content/base/src/nsDOMDocumentType.cpp index 1c1ef068e162..d61c9415f936 100644 --- a/content/base/src/nsDOMDocumentType.cpp +++ b/content/base/src/nsDOMDocumentType.cpp @@ -46,6 +46,7 @@ #include "nsCOMPtr.h" #include "nsContentUtils.h" #include "nsDOMString.h" +#include "nsIDOM3Node.h" #include "nsNodeInfoManager.h" #include "nsIDocument.h" #include "nsIXPConnect.h" @@ -78,14 +79,12 @@ NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, nimgr->SetDocumentPrincipal(aPrincipal); } - nsCOMPtr ni = - nimgr->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nsnull, - kNameSpaceID_None, - nsIDOMNode::DOCUMENT_TYPE_NODE, - aName); + nsCOMPtr ni; + ni = nimgr->GetNodeInfo(nsGkAtoms::documentTypeNodeName, nsnull, + kNameSpaceID_None); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); - *aDocType = new nsDOMDocumentType(ni.forget(), aPublicId, aSystemId, + *aDocType = new nsDOMDocumentType(ni.forget(), aName, aPublicId, aSystemId, aInternalSubset); NS_ADDREF(*aDocType); @@ -93,16 +92,16 @@ NS_NewDOMDocumentType(nsIDOMDocumentType** aDocType, } nsDOMDocumentType::nsDOMDocumentType(already_AddRefed aNodeInfo, + nsIAtom *aName, const nsAString& aPublicId, const nsAString& aSystemId, const nsAString& aInternalSubset) : - nsDOMDocumentTypeForward(aNodeInfo), + nsGenericDOMDataNode(aNodeInfo), + mName(aName), mPublicId(aPublicId), mSystemId(aSystemId), mInternalSubset(aInternalSubset) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE, - "Bad NodeType in aNodeInfo"); } nsDOMDocumentType::~nsDOMDocumentType() @@ -141,7 +140,7 @@ nsDOMDocumentType::GetText() NS_IMETHODIMP nsDOMDocumentType::GetName(nsAString& aName) { - aName = NodeName(); + mName->ToString(aName); return NS_OK; } @@ -168,11 +167,40 @@ nsDOMDocumentType::GetInternalSubset(nsAString& aInternalSubset) return NS_OK; } +NS_IMETHODIMP +nsDOMDocumentType::GetNodeName(nsAString& aNodeName) +{ + mName->ToString(aNodeName); + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDocumentType::GetNodeValue(nsAString& aNodeValue) +{ + SetDOMStringToNull(aNodeValue); + + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDocumentType::SetNodeValue(const nsAString& aNodeValue) +{ + return NS_OK; +} + +NS_IMETHODIMP +nsDOMDocumentType::GetNodeType(PRUint16* aNodeType) +{ + *aNodeType = nsIDOMNode::DOCUMENT_TYPE_NODE; + + return NS_OK; +} + nsGenericDOMDataNode* nsDOMDocumentType::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { nsCOMPtr ni = aNodeInfo; - return new nsDOMDocumentType(ni.forget(), mPublicId, mSystemId, + return new nsDOMDocumentType(ni.forget(), mName, mPublicId, mSystemId, mInternalSubset); } @@ -198,9 +226,7 @@ nsDOMDocumentType::BindToTree(nsIDocument *aDocument, nsIContent *aParent, nsCOMPtr newNodeInfo; newNodeInfo = nimgr->GetNodeInfo(mNodeInfo->NameAtom(), mNodeInfo->GetPrefixAtom(), - mNodeInfo->NamespaceID(), - nsIDOMNode::DOCUMENT_TYPE_NODE, - mNodeInfo->GetExtraName()); + mNodeInfo->NamespaceID()); NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); mNodeInfo.swap(newNodeInfo); diff --git a/content/base/src/nsDOMDocumentType.h b/content/base/src/nsDOMDocumentType.h index 49e9f93d190b..015f0130cd95 100644 --- a/content/base/src/nsDOMDocumentType.h +++ b/content/base/src/nsDOMDocumentType.h @@ -53,23 +53,12 @@ // data. This is done simply for convenience and should be changed if // this restricts what should be done for character data. -class nsDOMDocumentTypeForward : public nsGenericDOMDataNode, - public nsIDOMDocumentType -{ -public: - nsDOMDocumentTypeForward(already_AddRefed aNodeInfo) - : nsGenericDOMDataNode(aNodeInfo) - { - } - - // nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::) -}; - -class nsDOMDocumentType : public nsDOMDocumentTypeForward +class nsDOMDocumentType : public nsGenericDOMDataNode, + public nsIDOMDocumentType { public: nsDOMDocumentType(already_AddRefed aNodeInfo, + nsIAtom *aName, const nsAString& aPublicId, const nsAString& aSystemId, const nsAString& aInternalSubset); @@ -80,36 +69,21 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - // Forwarded by base class + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA // nsIDOMDocumentType NS_DECL_NSIDOMDOCUMENTTYPE - NS_IMETHODIMP GetNodeValue(nsAString& aNodeValue) - { - SetDOMStringToNull(aNodeValue); - - return NS_OK; - } - NS_IMETHODIMP SetNodeValue(const nsAString& aNodeValue) - { - return NS_OK; - } - - // nsINode - virtual PRBool IsNodeOfType(PRUint32 aFlags) const; - // nsIContent overrides + virtual PRBool IsNodeOfType(PRUint32 aFlags) const; virtual const nsTextFragment* GetText(); virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent, nsIContent *aBindingParent, PRBool aCompileEventHandlers); - virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo, - PRBool aCloneText) const; - virtual nsXPCClassInfo* GetClassInfo(); protected: + nsCOMPtr mName; nsString mPublicId; nsString mSystemId; nsString mInternalSubset; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index b63a76de08c1..908b6a4ad0ce 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -1702,6 +1702,7 @@ NS_INTERFACE_TABLE_HEAD(nsDocument) NS_OFFSET_AND_INTERFACE_TABLE_END NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsDocument) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver, new nsNode3Tearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNodeSelector, @@ -1997,8 +1998,6 @@ nsDocument::Init() mNodeInfo = mNodeInfoManager->GetDocumentNodeInfo(); NS_ENSURE_TRUE(mNodeInfo, NS_ERROR_OUT_OF_MEMORY); - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_NODE, - "Bad NodeType in aNodeInfo"); NS_ASSERTION(GetOwnerDoc() == this, "Our nodeinfo is busted!"); @@ -3384,18 +3383,6 @@ nsDocument::IsNodeOfType(PRUint32 aFlags) const return !(aFlags & ~eDOCUMENT); } -PRUint16 -nsDocument::NodeType() -{ - return (PRUint16)nsIDOMNode::DOCUMENT_NODE; -} - -void -nsDocument::NodeName(nsAString& aNodeName) -{ - aNodeName.AssignLiteral("#document"); -} - Element* nsDocument::GetRootElementInternal() const { @@ -4386,7 +4373,6 @@ nsDocument::CreateElementNS(const nsAString& aNamespaceURI, nsresult rv = nsContentUtils::GetNodeInfoFromQName(aNamespaceURI, aQualifiedName, mNodeInfoManager, - nsIDOMNode::ELEMENT_NODE, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); @@ -4519,7 +4505,6 @@ nsDocument::CreateAttribute(const nsAString& aName, nsCOMPtr nodeInfo; rv = mNodeInfoManager->GetNodeInfo(aName, nsnull, kNameSpaceID_None, - nsIDOMNode::ATTRIBUTE_NODE, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); @@ -4541,7 +4526,6 @@ nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI, nsresult rv = nsContentUtils::GetNodeInfoFromQName(aNamespaceURI, aQualifiedName, mNodeInfoManager, - nsIDOMNode::ATTRIBUTE_NODE, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); @@ -5204,8 +5188,7 @@ nsDocument::SetTitle(const nsAString& aTitle) { nsCOMPtr titleInfo; titleInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::title, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); if (!titleInfo) return NS_OK; title = NS_NewHTMLTitleElement(titleInfo.forget()); @@ -5782,81 +5765,35 @@ nsDocument::IsSupported(const nsAString& aFeature, const nsAString& aVersion, aFeature, aVersion, aReturn); } -NS_IMETHODIMP -nsDocument::GetDOMBaseURI(nsAString &aURI) -{ - return nsIDocument::GetDOMBaseURI(aURI); -} - -NS_IMETHODIMP +void nsDocument::GetTextContent(nsAString &aTextContent) { SetDOMStringToNull(aTextContent); - return NS_OK; } -NS_IMETHODIMP -nsDocument::IsEqualNode(nsIDOMNode* aOther, PRBool* aResult) +PRBool +nsDocument::IsEqualNode(nsINode* aOther) { - return nsINode::IsEqualNode(aOther, aResult); -} + if (!aOther || !aOther->IsNodeOfType(eDOCUMENT)) + return PR_FALSE; -NS_IMETHODIMP -nsDocument::CompareDocumentPosition(nsIDOMNode *other, - PRUint16 *aResult) -{ - return nsINode::CompareDocumentPosition(other, aResult); -} + // Child nodes check. + PRUint32 childCount = GetChildCount(); + if (childCount != aOther->GetChildCount()) { + return PR_FALSE; + } -NS_IMETHODIMP -nsDocument::SetTextContent(const nsAString & aTextContent) -{ - return nsINode::SetTextContent(aTextContent); -} + for (PRUint32 i = 0; i < childCount; i++) { + if (!GetChildAt(i)->IsEqual(aOther->GetChildAt(i))) { + return PR_FALSE; + } + } -NS_IMETHODIMP -nsDocument::IsSameNode(nsIDOMNode *other, PRBool *aResult) -{ - *aResult = other == this; - return NS_OK; -} + /* Checks not needed: Prefix, namespace URI, local name, node name, + node value, attributes. + */ -NS_IMETHODIMP -nsDocument::LookupPrefix(const nsAString & namespaceURI, nsAString & aResult) -{ - SetDOMStringToNull(aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::IsDefaultNamespace(const nsAString & namespaceURI, - PRBool *aResult) -{ - *aResult = namespaceURI.IsEmpty(); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::LookupNamespaceURI(const nsAString & prefix, - nsAString & aResult) -{ - SetDOMStringToNull(aResult); - return NS_OK; -} - -NS_IMETHODIMP -nsDocument::SetUserData(const nsAString & key, - nsIVariant *data, nsIDOMUserDataHandler *handler, - nsIVariant **aResult) -{ - return nsINode::SetUserData(key, data, handler, aResult); -} - -NS_IMETHODIMP -nsDocument::GetUserData(const nsAString & key, - nsIVariant **aResult) -{ - return nsINode::GetUserData(key, aResult); + return PR_TRUE; } NS_IMETHODIMP @@ -6935,7 +6872,6 @@ nsDocument::CreateElem(const nsAString& aName, nsIAtom *aPrefix, PRInt32 aNamesp nsCOMPtr nodeInfo; mNodeInfoManager->GetNodeInfo(aName, aPrefix, aNamespaceID, - nsIDOMNode::ELEMENT_NODE, getter_AddRefs(nodeInfo)); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); diff --git a/content/base/src/nsDocument.h b/content/base/src/nsDocument.h index 07a8e103c3a5..4571b2b8c2c8 100644 --- a/content/base/src/nsDocument.h +++ b/content/base/src/nsDocument.h @@ -61,6 +61,7 @@ #include "nsIDOMEventTarget.h" #include "nsIContent.h" #include "nsIEventListenerManager.h" +#include "nsIDOM3Node.h" #include "nsIDOMNodeSelector.h" #include "nsIPrincipal.h" #include "nsIParser.h" @@ -718,8 +719,6 @@ public: // nsINode virtual PRBool IsNodeOfType(PRUint32 aFlags) const; - virtual PRUint16 NodeType(); - virtual void NodeName(nsAString& aNodeName); virtual nsIContent *GetChildAt(PRUint32 aIndex) const; virtual nsIContent * const * GetChildArray(PRUint32* aChildCount) const; virtual PRInt32 IndexOf(nsINode* aPossibleChild) const; @@ -747,6 +746,8 @@ public: { return NS_ERROR_NOT_IMPLEMENTED; } + virtual PRBool IsEqualNode(nsINode* aOther); + virtual void GetTextContent(nsAString &aTextContent); // nsIRadioGroupContainer NS_IMETHOD WalkRadioGroup(const nsAString& aName, diff --git a/content/base/src/nsDocumentEncoder.cpp b/content/base/src/nsDocumentEncoder.cpp index 425926110195..f76846a42603 100644 --- a/content/base/src/nsDocumentEncoder.cpp +++ b/content/base/src/nsDocumentEncoder.cpp @@ -377,7 +377,9 @@ nsDocumentEncoder::SerializeNodeStart(nsINode* aNode, return NS_OK; } - switch (node->NodeType()) { + PRUint16 type; + node->GetNodeType(&type); + switch (type) { case nsIDOMNode::TEXT_NODE: { mSerializer->AppendText(static_cast(node), diff --git a/content/base/src/nsDocumentFragment.cpp b/content/base/src/nsDocumentFragment.cpp index 2d86f8f49210..2d8ddc91a9f6 100644 --- a/content/base/src/nsDocumentFragment.cpp +++ b/content/base/src/nsDocumentFragment.cpp @@ -50,6 +50,7 @@ #include "nsIDOMDocument.h" #include "nsIDOMAttr.h" #include "nsDOMError.h" +#include "nsIDOM3Node.h" #include "nsGkAtoms.h" #include "nsDOMString.h" #include "nsIDOMUserDataHandler.h" @@ -58,19 +59,71 @@ class nsDocumentFragment : public nsGenericElement, public nsIDOMDocumentFragment { public: + nsDocumentFragment(already_AddRefed aNodeInfo); + virtual ~nsDocumentFragment(); + // nsISupports NS_DECL_ISUPPORTS_INHERITED - // interface nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericElement::) - // interface nsIDOMDocumentFragment - // NS_DECL_NSIDOCUMENTFRAGMENT Empty - - nsDocumentFragment(already_AddRefed aNodeInfo); - virtual ~nsDocumentFragment() + NS_IMETHOD GetNodeName(nsAString& aNodeName) + { return nsGenericElement::GetNodeName(aNodeName); } + NS_IMETHOD GetNodeValue(nsAString& aNodeValue) + { return nsGenericElement::GetNodeValue(aNodeValue); } + NS_IMETHOD SetNodeValue(const nsAString& aNodeValue) + { return nsGenericElement::SetNodeValue(aNodeValue); } + NS_IMETHOD GetNodeType(PRUint16* aNodeType); + NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) + { return nsGenericElement::GetParentNode(aParentNode); } + NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) + { return nsGenericElement::GetChildNodes(aChildNodes); } + NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) + { return nsGenericElement::GetFirstChild(aFirstChild); } + NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) + { return nsGenericElement::GetLastChild(aLastChild); } + NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) + { return nsGenericElement::GetPreviousSibling(aPreviousSibling); } + NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) + { return nsGenericElement::GetNextSibling(aNextSibling); } + NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) + { + *aAttributes = nsnull; + return NS_OK; + } + NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) + { return nsGenericElement::GetOwnerDocument(aOwnerDocument); } + NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, + nsIDOMNode** aReturn) + { return nsGenericElement::InsertBefore(aNewChild, aRefChild, aReturn); } + NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, + nsIDOMNode** aReturn) + { return nsGenericElement::ReplaceChild(aNewChild, aOldChild, aReturn); } + NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) + { return nsGenericElement::RemoveChild(aOldChild, aReturn); } + NS_IMETHOD AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn) + { return nsGenericElement::AppendChild(aNewChild, aReturn); } + NS_IMETHOD HasChildNodes(PRBool* aReturn) + { return nsGenericElement::HasChildNodes(aReturn); } + NS_IMETHOD HasAttributes(PRBool* aReturn) + { return nsGenericElement::HasAttributes(aReturn); } + NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn) + { return nsGenericElement::CloneNode(aDeep, aReturn); } + NS_IMETHOD GetPrefix(nsAString& aPrefix) + { return nsGenericElement::GetPrefix(aPrefix); } + NS_IMETHOD SetPrefix(const nsAString& aPrefix); + NS_IMETHOD GetNamespaceURI(nsAString& aNamespaceURI) + { return nsGenericElement::GetNamespaceURI(aNamespaceURI); } + NS_IMETHOD GetLocalName(nsAString& aLocalName) { + SetDOMStringToNull(aLocalName); + return NS_OK; } + NS_IMETHOD Normalize() + { return nsGenericElement::Normalize(); } + NS_IMETHOD IsSupported(const nsAString& aFeature, + const nsAString& aVersion, + PRBool* aReturn) + { return nsGenericElement::IsSupported(aFeature, aVersion, aReturn); } // nsIContent nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, @@ -118,8 +171,7 @@ NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult, nsCOMPtr nodeInfo; nodeInfo = aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName, - nsnull, kNameSpaceID_None, - nsIDOMNode::DOCUMENT_FRAGMENT_NODE); + nsnull, kNameSpaceID_None); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); nsDocumentFragment *it = new nsDocumentFragment(nodeInfo.forget()); @@ -138,6 +190,10 @@ nsDocumentFragment::nsDocumentFragment(already_AddRefed aNodeInfo) ClearIsElement(); } +nsDocumentFragment::~nsDocumentFragment() +{ +} + PRBool nsDocumentFragment::IsNodeOfType(PRUint32 aFlags) const { @@ -169,4 +225,17 @@ NS_INTERFACE_MAP_END_INHERITING(nsGenericElement) NS_IMPL_ADDREF_INHERITED(nsDocumentFragment, nsGenericElement) NS_IMPL_RELEASE_INHERITED(nsDocumentFragment, nsGenericElement) +NS_IMETHODIMP +nsDocumentFragment::GetNodeType(PRUint16* aNodeType) +{ + *aNodeType = (PRUint16)nsIDOMNode::DOCUMENT_FRAGMENT_NODE; + return NS_OK; +} + +NS_IMETHODIMP +nsDocumentFragment::SetPrefix(const nsAString& aPrefix) +{ + return NS_ERROR_DOM_NAMESPACE_ERR; +} + NS_IMPL_ELEMENT_CLONE(nsDocumentFragment) diff --git a/content/base/src/nsGenericDOMDataNode.cpp b/content/base/src/nsGenericDOMDataNode.cpp index ebc63469ca84..b1c91309c3aa 100644 --- a/content/base/src/nsGenericDOMDataNode.cpp +++ b/content/base/src/nsGenericDOMDataNode.cpp @@ -48,6 +48,7 @@ #include "nsReadableUtils.h" #include "nsMutationEvent.h" #include "nsINameSpaceManager.h" +#include "nsIDOM3Node.h" #include "nsIURI.h" #include "nsIPrivateDOMEvent.h" #include "nsIDOMEvent.h" @@ -72,13 +73,6 @@ namespace css = mozilla::css; nsGenericDOMDataNode::nsGenericDOMDataNode(already_AddRefed aNodeInfo) : nsIContent(aNodeInfo) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE || - mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE || - mNodeInfo->NodeType() == nsIDOMNode::COMMENT_NODE || - mNodeInfo->NodeType() == - nsIDOMNode::PROCESSING_INSTRUCTION_NODE || - mNodeInfo->NodeType() == nsIDOMNode::DOCUMENT_TYPE_NODE, - "Bad NodeType in aNodeInfo"); } nsGenericDOMDataNode::~nsGenericDOMDataNode() @@ -135,6 +129,7 @@ NS_INTERFACE_MAP_BEGIN(nsGenericDOMDataNode) nsDOMEventRTTearoff::Create(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference, new nsNodeSupportsWeakRefTearoff(this)) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMXPathNSResolver, new nsNode3Tearoff(this)) // nsNodeSH::PreCreate() depends on the identity pointer being the @@ -178,6 +173,14 @@ nsGenericDOMDataNode::GetPrefix(nsAString& aPrefix) return NS_OK; } +nsresult +nsGenericDOMDataNode::GetLocalName(nsAString& aLocalName) +{ + SetDOMStringToNull(aLocalName); + + return NS_OK; +} + nsresult nsGenericDOMDataNode::Normalize() { diff --git a/content/base/src/nsGenericDOMDataNode.h b/content/base/src/nsGenericDOMDataNode.h index 345176b18501..68ef37e75358 100644 --- a/content/base/src/nsGenericDOMDataNode.h +++ b/content/base/src/nsGenericDOMDataNode.h @@ -89,16 +89,6 @@ public: virtual ~nsGenericDOMDataNode(); // Implementation for nsIDOMNode - nsresult GetNodeName(nsAString& aNodeName) - { - aNodeName = NodeName(); - return NS_OK; - } - nsresult GetNodeType(PRUint16* aNodeType) - { - *aNodeType = NodeType(); - return NS_OK; - } nsresult GetNodeValue(nsAString& aNodeValue); nsresult SetNodeValue(const nsAString& aNodeValue); nsresult GetAttributes(nsIDOMNamedNodeMap** aAttributes) @@ -138,20 +128,12 @@ public: return InsertBefore(aNewChild, nsnull, aReturn); } nsresult GetNamespaceURI(nsAString& aNamespaceURI); - nsresult GetLocalName(nsAString& aLocalName) - { - aLocalName = LocalName(); - return NS_OK; - } + nsresult GetLocalName(nsAString& aLocalName); nsresult GetPrefix(nsAString& aPrefix); nsresult Normalize(); nsresult IsSupported(const nsAString& aFeature, const nsAString& aVersion, PRBool* aReturn); - nsresult CloneNode(PRBool aDeep, nsIDOMNode** aReturn) - { - return nsNodeUtils::CloneNodeImpl(this, aDeep, PR_TRUE, aReturn); - } // Implementation for nsIDOMCharacterData nsresult GetData(nsAString& aData) const; @@ -188,13 +170,15 @@ public: { return nsContentUtils::GetContextForEventHandlers(this, aRv); } - NS_IMETHOD GetTextContent(nsAString &aTextContent) + virtual void GetTextContent(nsAString &aTextContent) { - nsresult rv = GetNodeValue(aTextContent); +#ifdef DEBUG + nsresult rv = +#endif + GetNodeValue(aTextContent); NS_ASSERTION(NS_SUCCEEDED(rv), "GetNodeValue() failed?"); - return rv; } - NS_IMETHOD SetTextContent(const nsAString& aTextContent) + virtual nsresult SetTextContent(const nsAString& aTextContent) { // Batch possible DOMSubtreeModified events. mozAutoSubtreeModified subtree(GetOwnerDoc(), nsnull); @@ -383,4 +367,89 @@ private: already_AddRefed GetCurrentValueAtom(); }; +//---------------------------------------------------------------------- + +/** + * Mostly implement the nsIDOMNode API by forwarding the methods to + * nsGenericDOMDataNode + * + * Note that classes using this macro will need to implement: + * NS_IMETHOD GetNodeType(PRUint16* aNodeType); + * nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo, + * PRBool aCloneText) const; + */ +#define NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA \ + NS_IMETHOD GetNodeName(nsAString& aNodeName); \ + NS_IMETHOD GetLocalName(nsAString& aLocalName) { \ + return nsGenericDOMDataNode::GetLocalName(aLocalName); \ + } \ + NS_IMETHOD GetNodeValue(nsAString& aNodeValue); \ + NS_IMETHOD SetNodeValue(const nsAString& aNodeValue); \ + NS_IMETHOD GetNodeType(PRUint16* aNodeType); \ + NS_IMETHOD GetParentNode(nsIDOMNode** aParentNode) { \ + return nsGenericDOMDataNode::GetParentNode(aParentNode); \ + } \ + NS_IMETHOD GetChildNodes(nsIDOMNodeList** aChildNodes) { \ + return nsGenericDOMDataNode::GetChildNodes(aChildNodes); \ + } \ + NS_IMETHOD HasChildNodes(PRBool* aHasChildNodes) { \ + return nsGenericDOMDataNode::HasChildNodes(aHasChildNodes); \ + } \ + NS_IMETHOD HasAttributes(PRBool* aHasAttributes) { \ + return nsGenericDOMDataNode::HasAttributes(aHasAttributes); \ + } \ + NS_IMETHOD GetFirstChild(nsIDOMNode** aFirstChild) { \ + return nsGenericDOMDataNode::GetFirstChild(aFirstChild); \ + } \ + NS_IMETHOD GetLastChild(nsIDOMNode** aLastChild) { \ + return nsGenericDOMDataNode::GetLastChild(aLastChild); \ + } \ + NS_IMETHOD GetPreviousSibling(nsIDOMNode** aPreviousSibling) { \ + return nsGenericDOMDataNode::GetPreviousSibling(aPreviousSibling); \ + } \ + NS_IMETHOD GetNextSibling(nsIDOMNode** aNextSibling) { \ + return nsGenericDOMDataNode::GetNextSibling(aNextSibling); \ + } \ + NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes) { \ + return nsGenericDOMDataNode::GetAttributes(aAttributes); \ + } \ + NS_IMETHOD InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild, \ + nsIDOMNode** aReturn) { \ + return nsGenericDOMDataNode::InsertBefore(aNewChild, aRefChild, \ + aReturn); \ + } \ + NS_IMETHOD AppendChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \ + return nsGenericDOMDataNode::AppendChild(aOldChild, aReturn); \ + } \ + NS_IMETHOD ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild, \ + nsIDOMNode** aReturn) { \ + return nsGenericDOMDataNode::ReplaceChild(aNewChild, aOldChild, \ + aReturn); \ + } \ + NS_IMETHOD RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) { \ + return nsGenericDOMDataNode::RemoveChild(aOldChild, aReturn); \ + } \ + NS_IMETHOD GetOwnerDocument(nsIDOMDocument** aOwnerDocument) { \ + return nsGenericDOMDataNode::GetOwnerDocument(aOwnerDocument); \ + } \ + NS_IMETHOD GetNamespaceURI(nsAString& aNamespaceURI) { \ + return nsGenericDOMDataNode::GetNamespaceURI(aNamespaceURI); \ + } \ + NS_IMETHOD GetPrefix(nsAString& aPrefix) { \ + return nsGenericDOMDataNode::GetPrefix(aPrefix); \ + } \ + NS_IMETHOD Normalize() { \ + return NS_OK; \ + } \ + NS_IMETHOD IsSupported(const nsAString& aFeature, \ + const nsAString& aVersion, \ + PRBool* aReturn) { \ + return nsGenericDOMDataNode::IsSupported(aFeature, aVersion, aReturn); \ + } \ + NS_IMETHOD CloneNode(PRBool aDeep, nsIDOMNode** aReturn) { \ + return nsNodeUtils::CloneNodeImpl(this, aDeep, PR_TRUE, aReturn); \ + } \ + virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo, \ + PRBool aCloneText) const; + #endif /* nsGenericDOMDataNode_h___ */ diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index ca65e2889f32..e20c80ad801d 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -112,6 +112,7 @@ #include "nsNodeInfoManager.h" #include "nsICategoryManager.h" +#include "nsIDOMNSFeatureFactory.h" #include "nsIDOMDocumentType.h" #include "nsIDOMUserDataHandler.h" #include "nsGenericHTMLElement.h" @@ -573,8 +574,8 @@ nsINode::RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn) return rv; } -nsresult -nsINode::GetDOMBaseURI(nsAString &aURI) const +void +nsINode::GetBaseURI(nsAString &aURI) const { nsCOMPtr baseURI = GetBaseURI(); @@ -584,49 +585,19 @@ nsINode::GetDOMBaseURI(nsAString &aURI) const } CopyUTF8toUTF16(spec, aURI); - - return NS_OK; } -nsresult +void nsINode::LookupPrefix(const nsAString& aNamespaceURI, nsAString& aPrefix) { Element *element = GetNameSpaceElement(); - if (element) { - // XXX Waiting for DOM spec to list error codes. - - // Trace up the content parent chain looking for the namespace - // declaration that defines the aNamespaceURI namespace. Once found, - // return the prefix (i.e. the attribute localName). - for (nsIContent* content = element; content; - content = content->GetParent()) { - PRUint32 attrCount = content->GetAttrCount(); - - for (PRUint32 i = 0; i < attrCount; ++i) { - const nsAttrName* name = content->GetAttrNameAt(i); - - if (name->NamespaceEquals(kNameSpaceID_XMLNS) && - content->AttrValueIs(kNameSpaceID_XMLNS, name->LocalName(), - aNamespaceURI, eCaseMatters)) { - // If the localName is "xmlns", the prefix we output should be - // null. - nsIAtom *localName = name->LocalName(); - - if (localName != nsGkAtoms::xmlns) { - localName->ToString(aPrefix); - } - else { - SetDOMStringToNull(aPrefix); - } - return NS_OK; - } - } - } + nsIAtom *prefix = element ? element->LookupPrefix(aNamespaceURI) : nsnull; + if (prefix) { + prefix->ToString(aPrefix); + } + else { + SetDOMStringToNull(aPrefix); } - - SetDOMStringToNull(aPrefix); - - return NS_OK; } static nsresult @@ -689,7 +660,7 @@ nsINode::SetUserData(const nsAString &aKey, nsIVariant *aData, } PRUint16 -nsINode::CompareDocPosition(nsINode* aOtherNode) +nsINode::CompareDocumentPosition(nsINode* aOtherNode) { NS_PRECONDITION(aOtherNode, "don't pass null"); @@ -726,16 +697,16 @@ nsINode::CompareDocPosition(nsINode* aOtherNode) if (attrName->Equals(attr1->NodeInfo())) { NS_ASSERTION(!attrName->Equals(attr2->NodeInfo()), "Different attrs at same position"); - return nsIDOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | - nsIDOMNode::DOCUMENT_POSITION_PRECEDING; + return nsIDOM3Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | + nsIDOM3Node::DOCUMENT_POSITION_PRECEDING; } if (attrName->Equals(attr2->NodeInfo())) { - return nsIDOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | - nsIDOMNode::DOCUMENT_POSITION_FOLLOWING; + return nsIDOM3Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | + nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING; } } NS_NOTREACHED("neither attribute in the element"); - return nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED; + return nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED; } if (elem) { @@ -766,12 +737,12 @@ nsINode::CompareDocPosition(nsINode* aOtherNode) nsINode* top2 = parents2.ElementAt(--pos2); if (top1 != top2) { return top1 < top2 ? - (nsIDOMNode::DOCUMENT_POSITION_PRECEDING | - nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED | - nsIDOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC) : - (nsIDOMNode::DOCUMENT_POSITION_FOLLOWING | - nsIDOMNode::DOCUMENT_POSITION_DISCONNECTED | - nsIDOMNode::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC); + (nsIDOM3Node::DOCUMENT_POSITION_PRECEDING | + nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED | + nsIDOM3Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC) : + (nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING | + nsIDOM3Node::DOCUMENT_POSITION_DISCONNECTED | + nsIDOM3Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC); } // Find where the parent chain differs and check indices in the parent. @@ -785,8 +756,8 @@ nsINode::CompareDocPosition(nsINode* aOtherNode) // IndexOf will return -1 for the attribute making the attribute be // considered before any child. return parent->IndexOf(child1) < parent->IndexOf(child2) ? - static_cast(nsIDOMNode::DOCUMENT_POSITION_PRECEDING) : - static_cast(nsIDOMNode::DOCUMENT_POSITION_FOLLOWING); + static_cast(nsIDOM3Node::DOCUMENT_POSITION_PRECEDING) : + static_cast(nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING); } parent = child1; } @@ -795,191 +766,13 @@ nsINode::CompareDocPosition(nsINode* aOtherNode) // between the chains. That must mean that one node is an ancestor of the // other. The one with the shortest chain must be the ancestor. return pos1 < pos2 ? - (nsIDOMNode::DOCUMENT_POSITION_PRECEDING | - nsIDOMNode::DOCUMENT_POSITION_CONTAINS) : - (nsIDOMNode::DOCUMENT_POSITION_FOLLOWING | - nsIDOMNode::DOCUMENT_POSITION_CONTAINED_BY); + (nsIDOM3Node::DOCUMENT_POSITION_PRECEDING | + nsIDOM3Node::DOCUMENT_POSITION_CONTAINS) : + (nsIDOM3Node::DOCUMENT_POSITION_FOLLOWING | + nsIDOM3Node::DOCUMENT_POSITION_CONTAINED_BY); } -PRBool -nsINode::IsEqualTo(nsINode* aOther) -{ - if (!aOther) { - return PR_FALSE; - } - - nsAutoString string1, string2; - - nsINode* node1 = this; - nsINode* node2 = aOther; - do { - PRUint16 nodeType = node1->NodeType(); - if (nodeType != node2->NodeType()) { - return PR_FALSE; - } - - if (!node1->mNodeInfo->Equals(node2->mNodeInfo)) { - return PR_FALSE; - } - - switch(nodeType) { - case nsIDOMNode::ELEMENT_NODE: - { - // Both are elements (we checked that their nodeinfos are equal). Do the - // check on attributes. - Element* element1 = node1->AsElement(); - Element* element2 = node2->AsElement(); - PRUint32 attrCount = element1->GetAttrCount(); - if (attrCount != element2->GetAttrCount()) { - return PR_FALSE; - } - - // Iterate over attributes. - for (PRUint32 i = 0; i < attrCount; ++i) { - const nsAttrName* attrName = element1->GetAttrNameAt(i); -#ifdef DEBUG - PRBool hasAttr = -#endif - element1->GetAttr(attrName->NamespaceID(), attrName->LocalName(), - string1); - NS_ASSERTION(hasAttr, "Why don't we have an attr?"); - - if (!element2->AttrValueIs(attrName->NamespaceID(), - attrName->LocalName(), - string1, - eCaseMatters)) { - return PR_FALSE; - } - } - break; - } - case nsIDOMNode::TEXT_NODE: - case nsIDOMNode::COMMENT_NODE: - case nsIDOMNode::CDATA_SECTION_NODE: - case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: - { - string1.Truncate(); - static_cast(node1)->AppendTextTo(string1); - string2.Truncate(); - static_cast(node2)->AppendTextTo(string2); - - if (!string1.Equals(string2)) { - return PR_FALSE; - } - - if (nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE) { - nsCOMPtr domNode1 = do_QueryInterface(node1); - nsCOMPtr domNode2 = do_QueryInterface(node2); - domNode1->GetNodeName(string1); - domNode2->GetNodeName(string2); - if (!string1.Equals(string2)) { - return PR_FALSE; - } - } - - break; - } - case nsIDOMNode::DOCUMENT_NODE: - case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: - break; - case nsIDOMNode::ATTRIBUTE_NODE: - { - NS_ASSERTION(node1 == this && node2 == aOther, - "Did we come upon an attribute node while walking a " - "subtree?"); - nsCOMPtr domNode1 = do_QueryInterface(node1); - nsCOMPtr domNode2 = do_QueryInterface(node2); - domNode1->GetNodeValue(string1); - domNode2->GetNodeValue(string2); - - // Returning here as to not bother walking subtree. And there is no - // risk that we're half way through walking some other subtree since - // attribute nodes doesn't appear in subtrees. - return string1.Equals(string2); - } - case nsIDOMNode::DOCUMENT_TYPE_NODE: - { - nsCOMPtr docType1 = do_QueryInterface(this); - nsCOMPtr docType2 = do_QueryInterface(aOther); - - NS_ASSERTION(docType1 && docType2, "Why don't we have a document type node?"); - - // Node name - docType1->GetNodeName(string1); - docType2->GetNodeName(string2); - if (!string1.Equals(string2)) { - return PR_FALSE; - } - - // Public ID - docType1->GetPublicId(string1); - docType2->GetPublicId(string2); - if (!string1.Equals(string2)) { - return PR_FALSE; - } - - // System ID - docType1->GetSystemId(string1); - docType2->GetSystemId(string2); - if (!string1.Equals(string2)) { - return PR_FALSE; - } - - // Internal subset - docType1->GetInternalSubset(string1); - docType2->GetInternalSubset(string2); - if (!string1.Equals(string2)) { - return PR_FALSE; - } - - break; - } - default: - NS_ABORT_IF_FALSE(PR_FALSE, "Unknown node type"); - } - - nsINode* nextNode = node1->GetFirstChild(); - if (nextNode) { - node1 = nextNode; - node2 = node2->GetFirstChild(); - } - else { - if (node2->GetFirstChild()) { - // node2 has a firstChild, but node1 doesn't - return PR_FALSE; - } - - // Find next sibling, possibly walking parent chain. - while (1) { - if (node1 == this) { - NS_ASSERTION(node2 == aOther, "Should have reached the start node " - "for both trees at the same time"); - return PR_TRUE; - } - - nextNode = node1->GetNextSibling(); - if (nextNode) { - node1 = nextNode; - node2 = node2->GetNextSibling(); - break; - } - - if (node2->GetNextSibling()) { - // node2 has a nextSibling, but node1 doesn't - return PR_FALSE; - } - - node1 = node1->GetNodeParent(); - node2 = node2->GetNodeParent(); - NS_ASSERTION(node1 && node2, "no parent while walking subtree"); - } - } - } while(node2); - - return PR_FALSE; -} - -nsresult +void nsINode::LookupNamespaceURI(const nsAString& aNamespacePrefix, nsAString& aNamespaceURI) { @@ -988,8 +781,6 @@ nsINode::LookupNamespaceURI(const nsAString& aNamespacePrefix, aNamespaceURI))) { SetDOMStringToNull(aNamespaceURI); } - - return NS_OK; } //---------------------------------------------------------------------- @@ -1348,17 +1139,249 @@ nsChildContentList::IndexOf(nsIContent* aContent) NS_IMPL_CYCLE_COLLECTION_1(nsNode3Tearoff, mNode) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsNode3Tearoff) + NS_INTERFACE_MAP_ENTRY(nsIDOM3Node) NS_INTERFACE_MAP_ENTRY(nsIDOMXPathNSResolver) NS_INTERFACE_MAP_END_AGGREGATED(mNode) NS_IMPL_CYCLE_COLLECTING_ADDREF(nsNode3Tearoff) NS_IMPL_CYCLE_COLLECTING_RELEASE(nsNode3Tearoff) +NS_IMETHODIMP +nsNode3Tearoff::GetBaseURI(nsAString& aURI) +{ + mNode->GetBaseURI(aURI); + + return NS_OK; +} + +NS_IMETHODIMP +nsNode3Tearoff::GetTextContent(nsAString &aTextContent) +{ + mNode->GetTextContent(aTextContent); + + return NS_OK; +} + +NS_IMETHODIMP +nsNode3Tearoff::SetTextContent(const nsAString &aTextContent) +{ + return mNode->SetTextContent(aTextContent); +} + +NS_IMETHODIMP +nsNode3Tearoff::CompareDocumentPosition(nsIDOMNode* aOther, + PRUint16* aReturn) +{ + nsCOMPtr other = do_QueryInterface(aOther); + + return mNode->CompareDocumentPosition(other, aReturn); +} + +NS_IMETHODIMP +nsNode3Tearoff::IsSameNode(nsIDOMNode* aOther, + PRBool* aReturn) +{ + nsCOMPtr other = do_QueryInterface(aOther); + *aReturn = mNode->IsSameNode(other); + + return NS_OK; +} + +PRBool +nsIContent::IsEqual(nsIContent* aOther) +{ + // We use nsIContent instead of nsINode for the attributes of elements. + + NS_PRECONDITION(aOther, "Who called IsEqual?"); + + nsAutoString string1, string2; + + // Prefix, namespace URI, local name, node name check. + if (!NodeInfo()->Equals(aOther->NodeInfo())) { + return PR_FALSE; + } + + if (Tag() == nsGkAtoms::documentTypeNodeName) { + nsCOMPtr docType1 = do_QueryInterface(this); + nsCOMPtr docType2 = do_QueryInterface(aOther); + + NS_ASSERTION(docType1 && docType2, "Why don't we have a document type node?"); + + // Public ID + docType1->GetPublicId(string1); + docType2->GetPublicId(string2); + + if (!string1.Equals(string2)) { + return PR_FALSE; + } + + // System ID + docType1->GetSystemId(string1); + docType2->GetSystemId(string2); + + if (!string1.Equals(string2)) { + return PR_FALSE; + } + + // Internal subset + docType1->GetInternalSubset(string1); + docType2->GetInternalSubset(string2); + + if (!string1.Equals(string2)) { + return PR_FALSE; + } + } + + if (IsElement()) { + // Both are elements (we checked that their nodeinfos are equal). Do the + // check on attributes. + Element* element2 = aOther->AsElement(); + PRUint32 attrCount = GetAttrCount(); + if (attrCount != element2->GetAttrCount()) { + return PR_FALSE; + } + + // Iterate over attributes. + for (PRUint32 i = 0; i < attrCount; ++i) { + const nsAttrName* attrName1 = GetAttrNameAt(i); +#ifdef DEBUG + PRBool hasAttr = +#endif + GetAttr(attrName1->NamespaceID(), attrName1->LocalName(), string1); + NS_ASSERTION(hasAttr, "Why don't we have an attr?"); + + if (!element2->AttrValueIs(attrName1->NamespaceID(), + attrName1->LocalName(), + string1, + eCaseMatters)) { + return PR_FALSE; + } + } + } else { + // Node value check. + nsCOMPtr domNode1 = do_QueryInterface(this); + nsCOMPtr domNode2 = do_QueryInterface(aOther); + NS_ASSERTION(domNode1 && domNode2, "How'd we get nsIContent without nsIDOMNode?"); + domNode1->GetNodeValue(string1); + domNode2->GetNodeValue(string2); + if (!string1.Equals(string2)) { + return PR_FALSE; + } + } + + // Child nodes count. + PRUint32 childCount = GetChildCount(); + if (childCount != aOther->GetChildCount()) { + return PR_FALSE; + } + + // Iterate over child nodes. + for (PRUint32 i = 0; i < childCount; ++i) { + if (!GetChildAt(i)->IsEqual(aOther->GetChildAt(i))) { + return PR_FALSE; + } + } + return PR_TRUE; +} + +PRBool +nsIContent::IsEqualNode(nsINode* aOther) +{ + if (!aOther || !aOther->IsNodeOfType(eCONTENT)) + return PR_FALSE; + + return IsEqual(static_cast(aOther)); +} + +NS_IMETHODIMP +nsNode3Tearoff::IsEqualNode(nsIDOMNode* aOther, PRBool* aReturn) +{ + // Since we implement nsINode, aOther must as well. + nsCOMPtr other = do_QueryInterface(aOther); + + *aReturn = other && mNode->IsEqualNode(other); + + return NS_OK; +} + +NS_IMETHODIMP +nsNode3Tearoff::GetFeature(const nsAString& aFeature, + const nsAString& aVersion, + nsISupports** aReturn) +{ + return mNode->GetFeature(aFeature, aVersion, aReturn); +} + +NS_IMETHODIMP +nsNode3Tearoff::SetUserData(const nsAString& aKey, + nsIVariant* aData, + nsIDOMUserDataHandler* aHandler, + nsIVariant** aResult) +{ + return mNode->SetUserData(aKey, aData, aHandler, aResult); +} + +NS_IMETHODIMP +nsNode3Tearoff::GetUserData(const nsAString& aKey, + nsIVariant** aResult) +{ + NS_IF_ADDREF(*aResult = mNode->GetUserData(aKey)); + + return NS_OK; +} + +nsIAtom* +nsIContent::LookupPrefix(const nsAString& aNamespaceURI) +{ + // XXX Waiting for DOM spec to list error codes. + + // Trace up the content parent chain looking for the namespace + // declaration that defines the aNamespaceURI namespace. Once found, + // return the prefix (i.e. the attribute localName). + for (nsIContent* content = this; content; + content = content->GetParent()) { + PRUint32 attrCount = content->GetAttrCount(); + + for (PRUint32 i = 0; i < attrCount; ++i) { + const nsAttrName* name = content->GetAttrNameAt(i); + + if (name->NamespaceEquals(kNameSpaceID_XMLNS) && + content->AttrValueIs(kNameSpaceID_XMLNS, name->LocalName(), + aNamespaceURI, eCaseMatters)) { + // If the localName is "xmlns", the prefix we output should be + // null. + nsIAtom *localName = name->LocalName(); + + return localName == nsGkAtoms::xmlns ? nsnull : localName; + } + } + } + + return nsnull; +} + +NS_IMETHODIMP +nsNode3Tearoff::LookupPrefix(const nsAString& aNamespaceURI, + nsAString& aPrefix) +{ + mNode->LookupPrefix(aNamespaceURI, aPrefix); + return NS_OK; +} + NS_IMETHODIMP nsNode3Tearoff::LookupNamespaceURI(const nsAString& aNamespacePrefix, nsAString& aNamespaceURI) { - return mNode->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI); + mNode->LookupNamespaceURI(aNamespacePrefix, aNamespaceURI); + return NS_OK; +} + +NS_IMETHODIMP +nsNode3Tearoff::IsDefaultNamespace(const nsAString& aNamespaceURI, + PRBool* aReturn) +{ + *aReturn = mNode->IsDefaultNamespace(aNamespaceURI); + return NS_OK; } nsIContent* @@ -2223,13 +2246,6 @@ nsGenericElement::nsDOMSlots::~nsDOMSlots() nsGenericElement::nsGenericElement(already_AddRefed aNodeInfo) : Element(aNodeInfo) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::ELEMENT_NODE || - (mNodeInfo->NodeType() == - nsIDOMNode::DOCUMENT_FRAGMENT_NODE && - mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName, - kNameSpaceID_None)), - "Bad NodeType in aNodeInfo"); - // Set the default scriptID to JS - but skip SetScriptTypeID as it // does extra work we know isn't necessary here... SetFlags((nsIProgrammingLanguage::JAVASCRIPT << NODE_SCRIPT_TYPE_OFFSET)); @@ -2245,14 +2261,14 @@ nsGenericElement::~nsGenericElement() NS_IMETHODIMP nsGenericElement::GetNodeName(nsAString& aNodeName) { - aNodeName = NodeName(); + aNodeName = mNodeInfo->QualifiedNameCorrectedCase(); return NS_OK; } NS_IMETHODIMP nsGenericElement::GetLocalName(nsAString& aLocalName) { - aLocalName = LocalName(); + mNodeInfo->GetName(aLocalName); return NS_OK; } @@ -2275,7 +2291,7 @@ nsGenericElement::SetNodeValue(const nsAString& aNodeValue) NS_IMETHODIMP nsGenericElement::GetNodeType(PRUint16* aNodeType) { - *aNodeType = NodeType(); + *aNodeType = (PRUint16)nsIDOMNode::ELEMENT_NODE; return NS_OK; } @@ -2292,6 +2308,26 @@ nsGenericElement::GetPrefix(nsAString& aPrefix) return NS_OK; } +static already_AddRefed +GetDOMFeatureFactory(const nsAString& aFeature, const nsAString& aVersion) +{ + nsIDOMNSFeatureFactory *factory = nsnull; + nsCOMPtr categoryManager = + do_GetService(NS_CATEGORYMANAGER_CONTRACTID); + if (categoryManager) { + nsCAutoString featureCategory(NS_DOMNS_FEATURE_PREFIX); + AppendUTF16toUTF8(aFeature, featureCategory); + nsXPIDLCString contractID; + nsresult rv = categoryManager->GetCategoryEntry(featureCategory.get(), + NS_ConvertUTF16toUTF8(aVersion).get(), + getter_Copies(contractID)); + if (NS_SUCCEEDED(rv)) { + CallGetService(contractID.get(), &factory); // addrefs + } + } + return factory; +} + nsresult nsGenericElement::InternalIsSupported(nsISupports* aObject, const nsAString& aFeature, @@ -2354,6 +2390,29 @@ nsGenericElement::InternalIsSupported(nsISupports* aObject, } } #endif /* MOZ_SMIL */ + else { + nsCOMPtr factory = + GetDOMFeatureFactory(aFeature, aVersion); + + if (factory) { + factory->HasFeature(aObject, aFeature, aVersion, aReturn); + } + } + return NS_OK; +} + +nsresult +nsINode::GetFeature(const nsAString& aFeature, + const nsAString& aVersion, + nsISupports** aReturn) +{ + *aReturn = nsnull; + nsCOMPtr factory = + GetDOMFeatureFactory(aFeature, aVersion); + + if (factory) { + factory->GetFeature(this, aFeature, aVersion, aReturn); + } return NS_OK; } @@ -2379,15 +2438,14 @@ nsGenericElement::HasAttributes(PRBool* aReturn) NS_IMETHODIMP nsGenericElement::GetAttributes(nsIDOMNamedNodeMap** aAttributes) { - if (!IsElement()) { - *aAttributes = nsnull; - return NS_OK; - } - + NS_ENSURE_ARG_POINTER(aAttributes); nsDOMSlots *slots = DOMSlots(); if (!slots->mAttributeMap) { slots->mAttributeMap = new nsDOMAttributeMap(this); + if (!slots->mAttributeMap) { + return NS_ERROR_OUT_OF_MEMORY; + } if (!slots->mAttributeMap->Init()) { slots->mAttributeMap = nsnull; return NS_ERROR_FAILURE; @@ -2410,7 +2468,7 @@ nsGenericElement::HasChildNodes(PRBool* aReturn) NS_IMETHODIMP nsGenericElement::GetTagName(nsAString& aTagName) { - aTagName = NodeName(); + aTagName = mNodeInfo->QualifiedNameCorrectedCase(); return NS_OK; } @@ -2591,7 +2649,6 @@ nsGenericElement::SetAttributeNS(const nsAString& aNamespaceURI, nsresult rv = nsContentUtils::GetNodeInfoFromQName(aNamespaceURI, aQualifiedName, mNodeInfo->NodeInfoManager(), - nsIDOMNode::ATTRIBUTE_NODE, getter_AddRefs(ni)); NS_ENSURE_SUCCESS(rv, rv); @@ -2764,56 +2821,69 @@ nsGenericElement::Normalize() for (index = 0; (index < count) && (NS_OK == result); index++) { nsIContent *child = GetChildAt(index); - switch (child->NodeType()) { - case nsIDOMNode::TEXT_NODE: + nsCOMPtr node = do_QueryInterface(child); + if (node) { + PRUint16 nodeType; + node->GetNodeType(&nodeType); - // ensure that if the text node is empty, it is removed - if (0 == child->TextLength()) { - if (hasRemoveListeners) { - nsContentUtils::MaybeFireNodeRemoved(child, this, doc); - } - result = RemoveChildAt(index, PR_TRUE); - if (NS_FAILED(result)) { - return result; - } + switch (nodeType) { + case nsIDOMNode::TEXT_NODE: - count--; - index--; - break; - } - - if (index+1 < count) { - // Get the sibling. If it's also a text node, then - // remove it from the tree and join the two text - // nodes. - nsCOMPtr sibling = GetChildAt(index + 1); - - if (sibling->NodeType() == nsIDOMNode::TEXT_NODE) { + // ensure that if the text node is empty, it is removed + if (0 == child->TextLength()) { if (hasRemoveListeners) { - nsContentUtils::MaybeFireNodeRemoved(sibling, this, doc); + nsContentUtils::MaybeFireNodeRemoved(child, this, doc); } - result = RemoveChildAt(index+1, PR_TRUE); + result = RemoveChildAt(index, PR_TRUE); if (NS_FAILED(result)) { return result; } - result = JoinTextNodes(child, sibling); - if (NS_FAILED(result)) { - return result; - } count--; index--; + break; } - } - break; + + if (index+1 < count) { + // Get the sibling. If it's also a text node, then + // remove it from the tree and join the two text + // nodes. + nsCOMPtr sibling = GetChildAt(index + 1); - case nsIDOMNode::ELEMENT_NODE: - nsCOMPtr element = do_QueryInterface(child); + nsCOMPtr siblingNode = do_QueryInterface(sibling); - if (element) { - result = element->Normalize(); - } - break; + if (siblingNode) { + PRUint16 siblingNodeType; + siblingNode->GetNodeType(&siblingNodeType); + + if (siblingNodeType == nsIDOMNode::TEXT_NODE) { + if (hasRemoveListeners) { + nsContentUtils::MaybeFireNodeRemoved(sibling, this, doc); + } + result = RemoveChildAt(index+1, PR_TRUE); + if (NS_FAILED(result)) { + return result; + } + + result = JoinTextNodes(child, sibling); + if (NS_FAILED(result)) { + return result; + } + count--; + index--; + } + } + } + break; + + case nsIDOMNode::ELEMENT_NODE: + nsCOMPtr element = do_QueryInterface(child); + + if (element) { + result = element->Normalize(); + } + break; + } } } @@ -3455,9 +3525,8 @@ nsGenericElement::GetExistingAttrNameFromQName(const nsAString& aStr) const nsINodeInfo* nodeInfo; if (name->IsAtom()) { - nodeInfo = mNodeInfo->NodeInfoManager()-> - GetNodeInfo(name->Atom(), nsnull, kNameSpaceID_None, - nsIDOMNode::ATTRIBUTE_NODE).get(); + nodeInfo = mNodeInfo->NodeInfoManager()->GetNodeInfo(name->Atom(), nsnull, + kNameSpaceID_None).get(); } else { NS_ADDREF(nodeInfo = name->NodeInfo()); @@ -3594,11 +3663,18 @@ nsINode::doInsertChildAt(nsIContent* aKid, PRUint32 aIndex, mozAutoDocUpdate updateBatch(doc, UPDATE_CONTENT_MODEL, aNotify); if (!HasSameOwnerDoc(aKid)) { + nsCOMPtr kid = do_QueryInterface(aKid, &rv); + NS_ENSURE_SUCCESS(rv, rv); + + PRUint16 nodeType = 0; + rv = kid->GetNodeType(&nodeType); + NS_ENSURE_SUCCESS(rv, rv); + // DocumentType nodes are the only nodes that can have a null // ownerDocument according to the DOM spec, and we need to allow // inserting them w/o calling AdoptNode(). - if (aKid->NodeType() != nsIDOMNode::DOCUMENT_TYPE_NODE || - aKid->GetOwnerDoc()) { + + if (nodeType != nsIDOMNode::DOCUMENT_TYPE_NODE || aKid->GetOwnerDoc()) { rv = AdoptNodeIntoOwnerDoc(this, aKid); NS_ENSURE_SUCCESS(rv, rv); } @@ -3812,8 +3888,9 @@ nsGenericElement::SaveSubtreeState() // inserting it's the content before which we're inserting. In the // latter case it may be null. static -PRBool IsAllowedAsChild(nsIContent* aNewChild, nsINode* aParent, - PRBool aIsReplace, nsIContent* aRefContent) +PRBool IsAllowedAsChild(nsIContent* aNewChild, PRUint16 aNewNodeType, + nsINode* aParent, PRBool aIsReplace, + nsIContent* aRefContent) { NS_PRECONDITION(aNewChild, "Must have new child"); NS_PRECONDITION(!aIsReplace || aRefContent, @@ -3823,13 +3900,21 @@ PRBool IsAllowedAsChild(nsIContent* aNewChild, nsINode* aParent, aParent->IsElement(), "Nodes that are not documents, document fragments or " "elements can't be parents!"); +#ifdef DEBUG + PRUint16 debugNodeType = 0; + nsCOMPtr debugNode(do_QueryInterface(aNewChild)); + nsresult debugRv = debugNode->GetNodeType(&debugNodeType); + + NS_PRECONDITION(NS_SUCCEEDED(debugRv) && debugNodeType == aNewNodeType, + "Bogus node type passed"); +#endif if (aParent && nsContentUtils::ContentIsDescendantOf(aParent, aNewChild)) { return PR_FALSE; } // The allowed child nodes differ for documents and elements - switch (aNewChild->NodeType()) { + switch (aNewNodeType) { case nsIDOMNode::COMMENT_NODE : case nsIDOMNode::PROCESSING_INSTRUCTION_NODE : // OK in both cases @@ -3945,7 +4030,10 @@ PRBool IsAllowedAsChild(nsIContent* aNewChild, nsINode* aParent, } // If we can put this content at the the right place, we might be ok; // if not, we bail out. - if (!IsAllowedAsChild(childContent, aParent, aIsReplace, + nsCOMPtr childNode(do_QueryInterface(childContent)); + PRUint16 type; + childNode->GetNodeType(&type); + if (!IsAllowedAsChild(childContent, type, aParent, aIsReplace, aRefContent)) { return PR_FALSE; } @@ -3999,7 +4087,9 @@ nsINode::ReplaceOrInsertBefore(PRBool aReplace, nsINode* aNewChild, return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; } - PRUint16 nodeType = aNewChild->NodeType(); + PRUint16 nodeType = 0; + nsresult res = aNewChild->GetNodeType(&nodeType); + NS_ENSURE_SUCCESS(res, res); // Before we do anything else, fire all DOMNodeRemoved mutation events // We do this up front as to avoid having to deal with script running @@ -4065,12 +4155,10 @@ nsINode::ReplaceOrInsertBefore(PRBool aReplace, nsINode* aNewChild, } // Make sure that the inserted node is allowed as a child of its new parent. - if (!IsAllowedAsChild(newContent, this, aReplace, refContent)) { + if (!IsAllowedAsChild(newContent, nodeType, this, aReplace, refContent)) { return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR; } - nsresult res; - // If we're replacing if (aReplace) { refContent = GetChildAt(insPos + 1); @@ -4194,34 +4282,7 @@ nsINode::ReplaceOrInsertBefore(PRBool aReplace, nsINode* aNewChild, NS_ENSURE_SUCCESS(res, res); } - return NS_OK; -} - -nsresult -nsINode::CompareDocumentPosition(nsIDOMNode* aOther, PRUint16* aReturn) -{ - nsCOMPtr other = do_QueryInterface(aOther); - if (!other) { - return NS_ERROR_NULL_POINTER; - } - *aReturn = CompareDocPosition(other); - return NS_OK; -} - -nsresult -nsINode::IsEqualNode(nsIDOMNode* aOther, PRBool* aReturn) -{ - nsCOMPtr other = do_QueryInterface(aOther); - *aReturn = IsEqualTo(other); - return NS_OK; -} - -nsresult -nsINode::IsSameNode(nsIDOMNode* aOther, PRBool* aReturn) -{ - nsCOMPtr other = do_QueryInterface(aOther); - *aReturn = other == this; - return NS_OK; + return res; } //---------------------------------------------------------------------- @@ -4402,6 +4463,7 @@ NS_INTERFACE_MAP_BEGIN(nsGenericElement) NS_INTERFACE_MAP_ENTRY(nsIContent) NS_INTERFACE_MAP_ENTRY(nsINode) NS_INTERFACE_MAP_ENTRY(nsPIDOMEventTarget) + NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Node, new nsNode3Tearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNSElement, new nsNSElementTearoff(this)) NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMEventTarget, nsDOMEventRTTearoff::Create(this)) @@ -4665,8 +4727,7 @@ nsGenericElement::SetAttrAndNotify(PRInt32 aNamespaceID, else { nsCOMPtr ni; ni = mNodeInfo->NodeInfoManager()->GetNodeInfo(aName, aPrefix, - aNamespaceID, - nsIDOMNode::ATTRIBUTE_NODE); + aNamespaceID); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); rv = mAttrsAndChildren.SetAndTakeAttr(ni, aParsedValue); diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index 99ec2f446e93..96c34bcc514c 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -51,6 +51,7 @@ #include "nsIDOMDocumentFragment.h" #include "nsIDOMEventTarget.h" #include "nsIDOM3EventTarget.h" +#include "nsIDOM3Node.h" #include "nsIDOMNSEventTarget.h" #include "nsIDOMNSElement.h" #include "nsILinkHandler.h" @@ -80,6 +81,7 @@ class nsIDOMCSSStyleDeclaration; class nsIURI; class nsINodeInfo; class nsIControllers; +class nsIDOMNSFeatureFactory; class nsIEventListenerManager; class nsIScrollableFrame; class nsContentList; @@ -129,14 +131,14 @@ private: /** * A tearoff class for nsGenericElement to implement additional interfaces */ -class nsNode3Tearoff : public nsIDOMXPathNSResolver +class nsNode3Tearoff : public nsIDOM3Node, public nsIDOMXPathNSResolver { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS - NS_DECL_CYCLE_COLLECTION_CLASS(nsNode3Tearoff) + NS_DECL_NSIDOM3NODE - NS_DECL_NSIDOMXPATHNSRESOLVER + NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsNode3Tearoff, nsIDOM3Node) nsNode3Tearoff(nsINode *aNode) : mNode(aNode) { @@ -343,12 +345,11 @@ public: { return nsContentUtils::GetContextForEventHandlers(this, aRv); } - NS_IMETHOD GetTextContent(nsAString &aTextContent) + virtual void GetTextContent(nsAString &aTextContent) { nsContentUtils::GetNodeTextContent(this, PR_TRUE, aTextContent); - return NS_OK; } - NS_IMETHOD SetTextContent(const nsAString& aTextContent) + virtual nsresult SetTextContent(const nsAString& aTextContent) { return nsContentUtils::SetNodeTextContent(this, aTextContent, PR_FALSE); } diff --git a/content/base/src/nsGkAtomList.h b/content/base/src/nsGkAtomList.h index a2957ee06962..8697ca62c343 100644 --- a/content/base/src/nsGkAtomList.h +++ b/content/base/src/nsGkAtomList.h @@ -1089,7 +1089,6 @@ GK_ATOM(headerCSP, "x-content-security-policy") GK_ATOM(headerCSPReportOnly, "x-content-security-policy-report-only") GK_ATOM(headerXFO, "x-frame-options") GK_ATOM(xml, "xml") -GK_ATOM(xml_stylesheet, "xml-stylesheet") GK_ATOM(xmlns, "xmlns") GK_ATOM(xmp, "xmp") GK_ATOM(xulcontentsgenerated, "xulcontentsgenerated") diff --git a/content/base/src/nsNodeInfo.cpp b/content/base/src/nsNodeInfo.cpp index 8004e51915b4..911363322903 100644 --- a/content/base/src/nsNodeInfo.cpp +++ b/content/base/src/nsNodeInfo.cpp @@ -69,7 +69,6 @@ nsFixedSizeAllocator* nsNodeInfo::sNodeInfoPool = nsnull; // static nsNodeInfo* nsNodeInfo::Create(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, - PRUint16 aNodeType, nsIAtom *aExtraName, nsNodeInfoManager *aOwnerManager) { if (!sNodeInfoPool) { @@ -89,8 +88,7 @@ nsNodeInfo::Create(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, // Create a new one void* place = sNodeInfoPool->Alloc(sizeof(nsNodeInfo)); return place ? - new (place) nsNodeInfo(aName, aPrefix, aNamespaceID, aNodeType, aExtraName, - aOwnerManager) : + new (place) nsNodeInfo(aName, aPrefix, aNamespaceID, aOwnerManager) : nsnull; } @@ -101,66 +99,44 @@ nsNodeInfo::~nsNodeInfo() NS_RELEASE(mInner.mName); NS_IF_RELEASE(mInner.mPrefix); - NS_IF_RELEASE(mInner.mExtraName); } nsNodeInfo::nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, - PRUint16 aNodeType, nsIAtom* aExtraName, nsNodeInfoManager *aOwnerManager) { - CHECK_VALID_NODEINFO(aNodeType, aName, aNamespaceID, aExtraName); - NS_ABORT_IF_FALSE(aOwnerManager, "Invalid aOwnerManager"); + NS_ABORT_IF_FALSE(aName, "Must have a name"); + NS_ABORT_IF_FALSE(aOwnerManager, "Must have an owner manager"); + + mInner.mName = aName; + NS_ADDREF(mInner.mName); + + mInner.mPrefix = aPrefix; + NS_IF_ADDREF(mInner.mPrefix); - // Initialize mInner - NS_ADDREF(mInner.mName = aName); - NS_IF_ADDREF(mInner.mPrefix = aPrefix); mInner.mNamespaceID = aNamespaceID; - mInner.mNodeType = aNodeType; - NS_ADDREF(mOwnerManager = aOwnerManager); - NS_IF_ADDREF(mInner.mExtraName = aExtraName); + + mOwnerManager = aOwnerManager; + NS_ADDREF(mOwnerManager); // Now compute our cached members. // Qualified name. If we have no prefix, use ToString on // mInner.mName so that we get to share its buffer. if (aPrefix) { - mQualifiedName = nsDependentAtomString(mInner.mPrefix) + - NS_LITERAL_STRING(":") + - nsDependentAtomString(mInner.mName); + aPrefix->ToString(mQualifiedName); + mQualifiedName.Append(PRUnichar(':')); + mQualifiedName.Append(nsDependentAtomString(mInner.mName)); } else { mInner.mName->ToString(mQualifiedName); } - switch (aNodeType) { - case nsIDOMNode::ELEMENT_NODE: - case nsIDOMNode::ATTRIBUTE_NODE: - // Correct the case for HTML - if (aNodeType == nsIDOMNode::ELEMENT_NODE && - aNamespaceID == kNameSpaceID_XHTML && GetDocument() && - GetDocument()->IsHTML()) { - nsContentUtils::ASCIIToUpper(mQualifiedName, mNodeName); - } else { - mNodeName = mQualifiedName; - } - mInner.mName->ToString(mLocalName); - break; - case nsIDOMNode::TEXT_NODE: - case nsIDOMNode::CDATA_SECTION_NODE: - case nsIDOMNode::COMMENT_NODE: - case nsIDOMNode::DOCUMENT_NODE: - case nsIDOMNode::DOCUMENT_FRAGMENT_NODE: - mInner.mName->ToString(mNodeName); - SetDOMStringToNull(mLocalName); - break; - case nsIDOMNode::PROCESSING_INSTRUCTION_NODE: - case nsIDOMNode::DOCUMENT_TYPE_NODE: - mInner.mExtraName->ToString(mNodeName); - SetDOMStringToNull(mLocalName); - break; - default: - NS_ABORT_IF_FALSE(aNodeType == PR_UINT16_MAX, - "Unknown node type"); + // Qualified name in corrected case + if (aNamespaceID == kNameSpaceID_XHTML && GetDocument() && + GetDocument()->IsHTML()) { + nsContentUtils::ASCIIToUpper(mQualifiedName, mQualifiedNameCorrectedCase); + } else { + mQualifiedNameCorrectedCase = mQualifiedName; } } diff --git a/content/base/src/nsNodeInfo.h b/content/base/src/nsNodeInfo.h index f9103e105d8a..cee6d8df9914 100644 --- a/content/base/src/nsNodeInfo.h +++ b/content/base/src/nsNodeInfo.h @@ -69,14 +69,12 @@ public: * aName and aOwnerManager may not be null. */ static nsNodeInfo *Create(nsIAtom *aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, PRUint16 aNodeType, - nsIAtom *aExtraName, + PRInt32 aNamespaceID, nsNodeInfoManager *aOwnerManager); private: nsNodeInfo(); // Unimplemented nsNodeInfo(const nsNodeInfo& aOther); // Unimplemented nsNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID, - PRUint16 aNodeType, nsIAtom *aExtraName, nsNodeInfoManager *aOwnerManager); protected: virtual ~nsNodeInfo(); @@ -98,42 +96,4 @@ private: void LastRelease(); }; -#define CHECK_VALID_NODEINFO(_nodeType, _name, _namespaceID, _extraName) \ -NS_ABORT_IF_FALSE(_nodeType == nsIDOMNode::ELEMENT_NODE || \ - _nodeType == nsIDOMNode::ATTRIBUTE_NODE || \ - _nodeType == nsIDOMNode::TEXT_NODE || \ - _nodeType == nsIDOMNode::CDATA_SECTION_NODE || \ - _nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE || \ - _nodeType == nsIDOMNode::COMMENT_NODE || \ - _nodeType == nsIDOMNode::DOCUMENT_NODE || \ - _nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE || \ - _nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE || \ - _nodeType == PR_UINT16_MAX, \ - "Invalid nodeType"); \ -NS_ABORT_IF_FALSE((_nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE || \ - _nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) == \ - (_extraName != nsnull), \ - "Supply aExtraName for and only for PIs and doctypes"); \ -NS_ABORT_IF_FALSE(_nodeType == nsIDOMNode::ELEMENT_NODE || \ - _nodeType == nsIDOMNode::ATTRIBUTE_NODE || \ - _nodeType == PR_UINT16_MAX || \ - aNamespaceID == kNameSpaceID_None, \ - "Only attributes and elements can be in a namespace"); \ -NS_ABORT_IF_FALSE(_name && _name != nsGkAtoms::_empty, "Invalid localName");\ -NS_ABORT_IF_FALSE(((_nodeType == nsIDOMNode::TEXT_NODE) == \ - (_name == nsGkAtoms::textTagName)) && \ - ((_nodeType == nsIDOMNode::CDATA_SECTION_NODE) == \ - (_name == nsGkAtoms::cdataTagName)) && \ - ((_nodeType == nsIDOMNode::COMMENT_NODE) == \ - (_name == nsGkAtoms::commentTagName)) && \ - ((_nodeType == nsIDOMNode::DOCUMENT_NODE) == \ - (_name == nsGkAtoms::documentNodeName)) && \ - ((_nodeType == nsIDOMNode::DOCUMENT_FRAGMENT_NODE) == \ - (_name == nsGkAtoms::documentFragmentNodeName)) && \ - ((_nodeType == nsIDOMNode::DOCUMENT_TYPE_NODE) == \ - (_name == nsGkAtoms::documentTypeNodeName)) && \ - ((_nodeType == nsIDOMNode::PROCESSING_INSTRUCTION_NODE) ==\ - (_name == nsGkAtoms::processingInstructionTagName)), \ - "Wrong localName for nodeType"); - #endif /* nsNodeInfo_h___ */ diff --git a/content/base/src/nsNodeInfoManager.cpp b/content/base/src/nsNodeInfoManager.cpp index c57556451454..5b701e568868 100644 --- a/content/base/src/nsNodeInfoManager.cpp +++ b/content/base/src/nsNodeInfoManager.cpp @@ -91,9 +91,7 @@ nsNodeInfoManager::NodeInfoInnerKeyCompare(const void *key1, const void *key2) reinterpret_cast(key2); if (node1->mPrefix != node2->mPrefix || - node1->mNamespaceID != node2->mNamespaceID || - node1->mNodeType != node2->mNodeType || - node1->mExtraName != node2->mExtraName) { + node1->mNamespaceID != node2->mNamespaceID) { return 0; } @@ -207,13 +205,13 @@ nsNodeInfoManager::DropDocumentReference() already_AddRefed nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, PRUint16 aNodeType, - nsIAtom* aExtraName /* = nsnull */) + PRInt32 aNamespaceID) { - CHECK_VALID_NODEINFO(aNodeType, aName, aNamespaceID, aExtraName); + NS_ENSURE_TRUE(aName, nsnull); + NS_ASSERTION(!aName->Equals(EmptyString()), + "Don't pass an empty string to GetNodeInfo, fix caller."); - nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType, - aExtraName); + nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID); void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey); @@ -226,8 +224,7 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, } nsRefPtr newNodeInfo = - nsNodeInfo::Create(aName, aPrefix, aNamespaceID, aNodeType, aExtraName, - this); + nsNodeInfo::Create(aName, aPrefix, aNamespaceID, this); NS_ENSURE_TRUE(newNodeInfo, nsnull); PLHashEntry *he; @@ -245,17 +242,12 @@ nsNodeInfoManager::GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, nsresult nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, PRUint16 aNodeType, - nsINodeInfo** aNodeInfo) + PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo) { -#ifdef DEBUG - { - nsCOMPtr nameAtom = do_GetAtom(aName); - CHECK_VALID_NODEINFO(aNodeType, nameAtom, aNamespaceID, nsnull); - } -#endif + NS_ASSERTION(!aName.IsEmpty(), + "Don't pass an empty string to GetNodeInfo, fix caller."); - nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID, aNodeType); + nsINodeInfo::nsNodeInfoInner tmpKey(aName, aPrefix, aNamespaceID); void *node = PL_HashTableLookup(mNodeInfoHash, &tmpKey); @@ -272,8 +264,7 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY); nsRefPtr newNodeInfo = - nsNodeInfo::Create(nameAtom, aPrefix, aNamespaceID, aNodeType, nsnull, - this); + nsNodeInfo::Create(nameAtom, aPrefix, aNamespaceID, this); NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); PLHashEntry *he; @@ -289,9 +280,11 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, nsresult nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, const nsAString& aNamespaceURI, - PRUint16 aNodeType, nsINodeInfo** aNodeInfo) { + nsCOMPtr nameAtom = do_GetAtom(aName); + NS_ENSURE_TRUE(nameAtom, NS_ERROR_OUT_OF_MEMORY); + PRInt32 nsid = kNameSpaceID_None; if (!aNamespaceURI.IsEmpty()) { @@ -300,16 +293,15 @@ nsNodeInfoManager::GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, NS_ENSURE_SUCCESS(rv, rv); } - return GetNodeInfo(aName, aPrefix, nsid, aNodeType, aNodeInfo); + *aNodeInfo = GetNodeInfo(nameAtom, aPrefix, nsid).get(); + return *aNodeInfo ? NS_OK : NS_ERROR_OUT_OF_MEMORY; } already_AddRefed nsNodeInfoManager::GetTextNodeInfo() { if (!mTextNodeInfo) { - mTextNodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nsnull, - kNameSpaceID_None, - nsIDOMNode::TEXT_NODE, nsnull).get(); + mTextNodeInfo = GetNodeInfo(nsGkAtoms::textTagName, nsnull, kNameSpaceID_None).get(); } else { NS_ADDREF(mTextNodeInfo); @@ -322,9 +314,7 @@ already_AddRefed nsNodeInfoManager::GetCommentNodeInfo() { if (!mCommentNodeInfo) { - mCommentNodeInfo = GetNodeInfo(nsGkAtoms::commentTagName, nsnull, - kNameSpaceID_None, - nsIDOMNode::COMMENT_NODE, nsnull).get(); + mCommentNodeInfo = GetNodeInfo(nsGkAtoms::commentTagName, nsnull, kNameSpaceID_None).get(); } else { NS_ADDREF(mCommentNodeInfo); @@ -337,9 +327,7 @@ already_AddRefed nsNodeInfoManager::GetDocumentNodeInfo() { if (!mDocumentNodeInfo) { - mDocumentNodeInfo = GetNodeInfo(nsGkAtoms::documentNodeName, nsnull, - kNameSpaceID_None, - nsIDOMNode::DOCUMENT_NODE, nsnull).get(); + mDocumentNodeInfo = GetNodeInfo(nsGkAtoms::documentNodeName, nsnull, kNameSpaceID_None).get(); } else { NS_ADDREF(mDocumentNodeInfo); diff --git a/content/base/src/nsNodeInfoManager.h b/content/base/src/nsNodeInfoManager.h index 02a23d8dc57f..2d7d8ca5211f 100644 --- a/content/base/src/nsNodeInfoManager.h +++ b/content/base/src/nsNodeInfoManager.h @@ -85,14 +85,11 @@ public: * Methods for creating nodeinfo's from atoms and/or strings. */ already_AddRefed GetNodeInfo(nsIAtom *aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, - PRUint16 aNodeType, - nsIAtom* aExtraName = nsnull); + PRInt32 aNamespaceID); nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, - PRInt32 aNamespaceID, PRUint16 aNodeType, - nsINodeInfo** aNodeInfo); + PRInt32 aNamespaceID, nsINodeInfo** aNodeInfo); nsresult GetNodeInfo(const nsAString& aName, nsIAtom *aPrefix, - const nsAString& aNamespaceURI, PRUint16 aNodeType, + const nsAString& aNamespaceURI, nsINodeInfo** aNodeInfo); /** diff --git a/content/base/src/nsNodeUtils.cpp b/content/base/src/nsNodeUtils.cpp index 965e004e3c8b..aaba6a7d229d 100644 --- a/content/base/src/nsNodeUtils.cpp +++ b/content/base/src/nsNodeUtils.cpp @@ -502,9 +502,7 @@ nsNodeUtils::CloneAndAdopt(nsINode *aNode, PRBool aClone, PRBool aDeep, newNodeInfo = nodeInfoManager->GetNodeInfo(nodeInfo->NameAtom(), nodeInfo->GetPrefixAtom(), - nodeInfo->NamespaceID(), - nodeInfo->NodeType(), - nodeInfo->GetExtraName()); + nodeInfo->NamespaceID()); NS_ENSURE_TRUE(newNodeInfo, NS_ERROR_OUT_OF_MEMORY); nodeInfo = newNodeInfo; diff --git a/content/base/src/nsTextNode.cpp b/content/base/src/nsTextNode.cpp index ad5ac110db28..919f321bcac3 100644 --- a/content/base/src/nsTextNode.cpp +++ b/content/base/src/nsTextNode.cpp @@ -143,8 +143,6 @@ NS_NewTextNode(nsIContent** aInstancePtrResult, nsTextNode::nsTextNode(already_AddRefed aNodeInfo) : nsGenericDOMDataNode(aNodeInfo) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::TEXT_NODE, - "Bad NodeType in aNodeInfo"); } nsTextNode::~nsTextNode() @@ -164,6 +162,32 @@ NS_INTERFACE_TABLE_HEAD(nsTextNode) NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Text) NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode) +NS_IMETHODIMP +nsTextNode::GetNodeName(nsAString& aNodeName) +{ + aNodeName.AssignLiteral("#text"); + return NS_OK; +} + +NS_IMETHODIMP +nsTextNode::GetNodeValue(nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::GetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsTextNode::SetNodeValue(const nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::SetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsTextNode::GetNodeType(PRUint16* aNodeType) +{ + *aNodeType = (PRUint16)nsIDOMNode::TEXT_NODE; + return NS_OK; +} + PRBool nsTextNode::IsNodeOfType(PRUint32 aFlags) const { diff --git a/content/base/src/nsTextNode.h b/content/base/src/nsTextNode.h index 4dcfa243860f..c37107a9f8e7 100644 --- a/content/base/src/nsTextNode.h +++ b/content/base/src/nsTextNode.h @@ -63,7 +63,7 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA // nsIDOMCharacterData NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::) @@ -71,12 +71,9 @@ public: // nsIDOMText NS_FORWARD_NSIDOMTEXT(nsGenericDOMDataNode::) - // nsINode + // nsIContent virtual PRBool IsNodeOfType(PRUint32 aFlags) const; - virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo, - PRBool aCloneText) const; - nsresult BindToAttribute(nsIAttribute* aAttr); nsresult UnbindFromAttribute(); diff --git a/content/base/src/nsTraversal.cpp b/content/base/src/nsTraversal.cpp index eac7f0a42c5b..af68f77036f5 100644 --- a/content/base/src/nsTraversal.cpp +++ b/content/base/src/nsTraversal.cpp @@ -80,14 +80,43 @@ nsresult nsTraversal::TestNode(nsINode* aNode, PRInt16* _filtered) *_filtered = nsIDOMNodeFilter::FILTER_SKIP; - PRUint16 nodeType = aNode->NodeType(); + PRUint16 nodeType = 0; + // Check the most common cases + if (aNode->IsElement()) { + nodeType = nsIDOMNode::ELEMENT_NODE; + } + else if (aNode->IsNodeOfType(nsINode::eCONTENT)) { + nsIAtom* tag = static_cast(aNode)->Tag(); + if (tag == nsGkAtoms::textTagName) { + nodeType = nsIDOMNode::TEXT_NODE; + } + else if (tag == nsGkAtoms::cdataTagName) { + nodeType = nsIDOMNode::CDATA_SECTION_NODE; + } + else if (tag == nsGkAtoms::commentTagName) { + nodeType = nsIDOMNode::COMMENT_NODE; + } + else if (tag == nsGkAtoms::processingInstructionTagName) { + nodeType = nsIDOMNode::PROCESSING_INSTRUCTION_NODE; + } + } + + nsCOMPtr domNode; + if (!nodeType) { + domNode = do_QueryInterface(aNode); + rv = domNode->GetNodeType(&nodeType); + NS_ENSURE_SUCCESS(rv, rv); + } if (nodeType <= 12 && !((1 << (nodeType-1)) & mWhatToShow)) { return NS_OK; } if (mFilter) { - nsCOMPtr domNode = do_QueryInterface(aNode); + if (!domNode) { + domNode = do_QueryInterface(aNode); + } + mInAcceptNode = PR_TRUE; rv = mFilter->AcceptNode(domNode, _filtered); mInAcceptNode = PR_FALSE; diff --git a/content/base/test/test_bug352728.html b/content/base/test/test_bug352728.html index b0e9018ee92c..4f95988afdb4 100644 --- a/content/base/test/test_bug352728.html +++ b/content/base/test/test_bug352728.html @@ -53,7 +53,7 @@ function testComment(aText, aShouldSucceed) checkTypes(comment, "comment", types); var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode", - "nsIDOMEventTarget" ]; + "nsIDOM3Node", "nsIDOMEventTarget" ]; checkInterfaces(comment, "comment", interfaces); testCharacterData(comment, aText); diff --git a/content/base/test/test_bug352728.xhtml b/content/base/test/test_bug352728.xhtml index 4342a4800031..f6676c8af36e 100644 --- a/content/base/test/test_bug352728.xhtml +++ b/content/base/test/test_bug352728.xhtml @@ -77,7 +77,7 @@ function testComment(aText, aShouldSucceed) checkTypes(comment, "comment", types); var interfaces = [ "nsIDOMComment", "nsIDOMCharacterData", "nsIDOMNode", - "nsIDOMEventTarget" ]; + "nsIDOM3Node", "nsIDOMEventTarget" ]; checkInterfaces(comment, "comment", interfaces); testCharacterData(comment, aText); @@ -105,7 +105,7 @@ function testCDATASection(aText, aShouldSucceed) checkTypes(cdataSection, "CDATA section", types); var interfaces = [ "nsIDOMCDATASection", "nsIDOMCharacterData", - "nsIDOMNode", "nsIDOMEventTarget" ]; + "nsIDOMNode", "nsIDOM3Node", "nsIDOMEventTarget" ]; checkInterfaces(cdataSection, "CDATA section", interfaces); testCharacterData(cdataSection, aText); @@ -136,7 +136,7 @@ function testPI(aTarget, aData, aShouldSucceed, aReason) checkTypes(pi, "processing instruction", types); var interfaces = [ "nsIDOMProcessingInstruction", "nsIDOMNode", - "nsIDOMEventTarget" ]; + "nsIDOM3Node", "nsIDOMEventTarget" ]; checkInterfaces(pi, "processing instruction", interfaces); is(pi.target, aTarget, "Check target"); diff --git a/content/html/content/src/nsHTMLAudioElement.cpp b/content/html/content/src/nsHTMLAudioElement.cpp index 78b0104da0fc..470e715234d1 100644 --- a/content/html/content/src/nsHTMLAudioElement.cpp +++ b/content/html/content/src/nsHTMLAudioElement.cpp @@ -84,8 +84,7 @@ NS_NewHTMLAudioElement(already_AddRefed aNodeInfo, NS_ENSURE_TRUE(doc, nsnull); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::audio, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, nsnull); } diff --git a/content/html/content/src/nsHTMLImageElement.cpp b/content/html/content/src/nsHTMLImageElement.cpp index 5b1dacd1463c..be7925be1acc 100644 --- a/content/html/content/src/nsHTMLImageElement.cpp +++ b/content/html/content/src/nsHTMLImageElement.cpp @@ -170,8 +170,7 @@ NS_NewHTMLImageElement(already_AddRefed aNodeInfo, NS_ENSURE_TRUE(doc, nsnull); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::img, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, nsnull); } diff --git a/content/html/content/src/nsHTMLOptionElement.cpp b/content/html/content/src/nsHTMLOptionElement.cpp index 261d294ab9c9..c3aa360dde70 100644 --- a/content/html/content/src/nsHTMLOptionElement.cpp +++ b/content/html/content/src/nsHTMLOptionElement.cpp @@ -107,8 +107,7 @@ NS_NewHTMLOptionElement(already_AddRefed aNodeInfo, NS_ENSURE_TRUE(doc, nsnull); nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::option, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, nsnull); } diff --git a/content/html/content/src/nsTextEditorState.cpp b/content/html/content/src/nsTextEditorState.cpp index 275902008898..aa282933fc9b 100644 --- a/content/html/content/src/nsTextEditorState.cpp +++ b/content/html/content/src/nsTextEditorState.cpp @@ -1562,8 +1562,7 @@ nsTextEditorState::CreateRootNode() // Now create a DIV and add it to the anonymous content child list. nsCOMPtr nodeInfo; nodeInfo = doc->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); nsresult rv = NS_NewHTMLElement(getter_AddRefs(mRootNode), nodeInfo.forget(), @@ -1640,8 +1639,7 @@ be called if @placeholder is the empty string when trimmed from line breaks"); // and add it to the anonymous content child list nsCOMPtr nodeInfo; nodeInfo = pNodeInfoManager->GetNodeInfo(nsGkAtoms::div, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); rv = NS_NewHTMLElement(getter_AddRefs(mPlaceholderDiv), nodeInfo.forget(), diff --git a/content/html/content/test/test_bug389797.html b/content/html/content/test/test_bug389797.html index 27404c4e5964..b15a9e2bc098 100644 --- a/content/html/content/test/test_bug389797.html +++ b/content/html/content/test/test_bug389797.html @@ -32,7 +32,8 @@ function HTML_TAG(aTagName, aImplClass) { allTags.push(aTagName); classInfos[aTagName] = aImplClass; interfaces[aTagName] = - [ "nsIDOMNSElement", + [ "nsIDOM3Node", + "nsIDOMNSElement", "nsIDOMEventTarget", "nsIDOMNSEventTarget", "nsIDOMNSHTMLElement", diff --git a/content/html/document/src/ImageDocument.cpp b/content/html/document/src/ImageDocument.cpp index e75f24207db2..a98244448ed8 100644 --- a/content/html/document/src/ImageDocument.cpp +++ b/content/html/document/src/ImageDocument.cpp @@ -651,8 +651,7 @@ ImageDocument::CreateSyntheticDocument() nsCOMPtr nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::img, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); mImageContent = NS_NewHTMLImageElement(nodeInfo.forget()); diff --git a/content/html/document/src/MediaDocument.cpp b/content/html/document/src/MediaDocument.cpp index 3e32f539bcc8..c99db0b4eeeb 100644 --- a/content/html/document/src/MediaDocument.cpp +++ b/content/html/document/src/MediaDocument.cpp @@ -237,8 +237,7 @@ MediaDocument::CreateSyntheticDocument() nsCOMPtr nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::html, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); nsRefPtr root = NS_NewHTMLHtmlElement(nodeInfo.forget()); @@ -251,8 +250,7 @@ MediaDocument::CreateSyntheticDocument() NS_ENSURE_SUCCESS(rv, rv); nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); // Create a so our title has somewhere to live @@ -264,8 +262,7 @@ MediaDocument::CreateSyntheticDocument() root->AppendChildTo(head, PR_FALSE); nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::body, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); nsRefPtr body = NS_NewHTMLBodyElement(nodeInfo.forget()); diff --git a/content/html/document/src/PluginDocument.cpp b/content/html/document/src/PluginDocument.cpp index 1e26d39f4c84..09e8e9192add 100644 --- a/content/html/document/src/PluginDocument.cpp +++ b/content/html/document/src/PluginDocument.cpp @@ -298,8 +298,7 @@ PluginDocument::CreateSyntheticPluginDocument() // make plugin content nsCOMPtr nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::embed, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); rv = NS_NewHTMLElement(getter_AddRefs(mPluginContent), nodeInfo.forget(), NOT_FROM_PARSER); diff --git a/content/html/document/src/VideoDocument.cpp b/content/html/document/src/VideoDocument.cpp index 22c96424b0a3..0550d1bba490 100644 --- a/content/html/document/src/VideoDocument.cpp +++ b/content/html/document/src/VideoDocument.cpp @@ -112,8 +112,7 @@ VideoDocument::CreateSyntheticVideoDocument(nsIChannel* aChannel, // make content nsCOMPtr nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::video, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_FAILURE); nsRefPtr element = diff --git a/content/html/document/src/nsHTMLContentSink.cpp b/content/html/document/src/nsHTMLContentSink.cpp index 3c7a695e34df..b01ed8b00676 100644 --- a/content/html/document/src/nsHTMLContentSink.cpp +++ b/content/html/document/src/nsHTMLContentSink.cpp @@ -534,8 +534,7 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, nsAutoString lower; nsContentUtils::ASCIIToLower(aNode.GetText(), lower); nsCOMPtr name = do_GetAtom(lower); - nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML); } else if (mNodeInfoCache[aNodeType]) { nodeInfo = mNodeInfoCache[aNodeType]; @@ -548,8 +547,7 @@ HTMLContentSink::CreateContentObject(const nsIParserNode& aNode, nsIAtom *name = parserService->HTMLIdToAtomTag(aNodeType); NS_ASSERTION(name, "What? Reverse mapping of id to string broken!!!"); - nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, kNameSpaceID_XHTML); NS_IF_ADDREF(mNodeInfoCache[aNodeType] = nodeInfo); } @@ -1604,8 +1602,7 @@ HTMLContentSink::Init(nsIDocument* aDoc, nsCOMPtr nodeInfo; nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::html, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); // Make root part @@ -1621,8 +1618,7 @@ HTMLContentSink::Init(nsIDocument* aDoc, // Make head part nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::head, - nsnull, kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + nsnull, kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); mHead = NS_NewHTMLHeadElement(nodeInfo.forget()); @@ -2599,9 +2595,7 @@ HTMLContentSink::ProcessLINKTag(const nsIParserNode& aNode) // Create content object nsCOMPtr element; nsCOMPtr nodeInfo; - nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::link, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + nodeInfo = mNodeInfoManager->GetNodeInfo(nsGkAtoms::link, nsnull, kNameSpaceID_XHTML); result = NS_NewHTMLElement(getter_AddRefs(element), nodeInfo.forget(), NOT_FROM_PARSER); diff --git a/content/html/document/src/nsHTMLFragmentContentSink.cpp b/content/html/document/src/nsHTMLFragmentContentSink.cpp index eccfb779323c..235e3d4d1ee3 100644 --- a/content/html/document/src/nsHTMLFragmentContentSink.cpp +++ b/content/html/document/src/nsHTMLFragmentContentSink.cpp @@ -367,8 +367,7 @@ nsHTMLFragmentContentSink::OpenContainer(const nsIParserNode& aNode) nsCOMPtr name = do_GetAtom(lower); nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); } else if (mNodeInfoCache[nodeType]) { @@ -384,8 +383,7 @@ nsHTMLFragmentContentSink::OpenContainer(const nsIParserNode& aNode) nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(mNodeInfoCache[nodeType] = nodeInfo); @@ -463,8 +461,7 @@ nsHTMLFragmentContentSink::AddLeaf(const nsIParserNode& aNode) nsContentUtils::ASCIIToLower(aNode.GetText(), lower); nsCOMPtr name = do_GetAtom(lower); nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); } else if (mNodeInfoCache[nodeType]) { @@ -475,8 +472,7 @@ nsHTMLFragmentContentSink::AddLeaf(const nsIParserNode& aNode) NS_ASSERTION(name, "This should not happen!"); nodeInfo = mNodeInfoManager->GetNodeInfo(name, nsnull, - kNameSpaceID_XHTML, - nsIDOMNode::ELEMENT_NODE); + kNameSpaceID_XHTML); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); NS_ADDREF(mNodeInfoCache[nodeType] = nodeInfo); } @@ -948,7 +944,13 @@ nsHTMLParanoidFragmentSink::NameFromNode(const nsIParserNode& aNode, *aResult = nsnull; if (type == eHTMLTag_userdefined) { - *aResult = NS_NewAtom(aNode.GetText()); + nsCOMPtr nodeInfo; + rv = + mNodeInfoManager->GetNodeInfo(aNode.GetText(), nsnull, + kNameSpaceID_XHTML, + getter_AddRefs(nodeInfo)); + NS_ENSURE_SUCCESS(rv, rv); + NS_IF_ADDREF(*aResult = nodeInfo->NameAtom()); } else { rv = NameFromType(type, aResult); } diff --git a/content/svg/content/src/nsSVGElement.cpp b/content/svg/content/src/nsSVGElement.cpp index 79696aab3239..e885ef81906c 100644 --- a/content/svg/content/src/nsSVGElement.cpp +++ b/content/svg/content/src/nsSVGElement.cpp @@ -1364,8 +1364,7 @@ nsSVGElement::AddMappedSVGValue(nsIAtom* aName, nsISupports* aValue, else { nsCOMPtr ni; ni = mNodeInfo->NodeInfoManager()->GetNodeInfo(aName, nsnull, - aNamespaceID, - nsIDOMNode::ATTRIBUTE_NODE); + aNamespaceID); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); rv = mMappedAttributes.SetAndTakeAttr(ni, attrVal); diff --git a/content/svg/content/src/nsSVGUseElement.cpp b/content/svg/content/src/nsSVGUseElement.cpp index 68b97539cb46..90602756b994 100644 --- a/content/svg/content/src/nsSVGUseElement.cpp +++ b/content/svg/content/src/nsSVGUseElement.cpp @@ -339,9 +339,7 @@ nsSVGUseElement::CreateAnonymousContent() return nsnull; nsCOMPtr nodeInfo; - nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::svg, nsnull, - kNameSpaceID_SVG, - nsIDOMNode::ELEMENT_NODE); + nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::svg, nsnull, kNameSpaceID_SVG); if (!nodeInfo) return nsnull; diff --git a/content/test/unit/head_content.js b/content/test/unit/head_content.js index 5bff187014af..e133da4116db 100644 --- a/content/test/unit/head_content.js +++ b/content/test/unit/head_content.js @@ -50,6 +50,7 @@ const nsIDOMSerializer = I.nsIDOMSerializer; const nsIDOMDocument = I.nsIDOMDocument; const nsIDOMElement = I.nsIDOMElement; const nsIDOMNode = I.nsIDOMNode; +const nsIDOM3Node = I.nsIDOM3Node; const nsIDOMCharacterData = I.nsIDOMCharacterData; const nsIDOMAttr = I.nsIDOMAttr; const nsIDOMNodeList = I.nsIDOMNodeList; diff --git a/content/test/unit/test_isequalnode.js b/content/test/unit/test_isequalnode.js index 2e8529fa6cf2..5bd7a3127757 100644 --- a/content/test/unit/test_isequalnode.js +++ b/content/test/unit/test_isequalnode.js @@ -404,6 +404,7 @@ function test_isEqualNode_null() // UTILITY FUNCTIONS function n(node) { return node ? node.QueryInterface(nsIDOMNode) : null; } +function n3(node) { return node ? node.QueryInterface(nsIDOM3Node) : null; } function el(node) { return node ? node.QueryInterface(nsIDOMElement) : null; } function at(node) { return node ? node.QueryInterface(nsIDOMAttr) : null; } @@ -433,6 +434,9 @@ function equality_check_kids(parentId, areEqual) function check_eq_nodes(n1, n2) { + n1 = n3(n1); + n2 = n3(n2); + if (n1 && !n1.isEqualNode(n2)) do_throw(n1 + " should be equal to " + n2); if (n2 && !n2.isEqualNode(n1)) @@ -443,6 +447,9 @@ function check_eq_nodes(n1, n2) function check_neq_nodes(n1, n2) { + n1 = n3(n1); + n2 = n3(n2); + if (n1 && n1.isEqualNode(n2)) do_throw(n1 + " should not be equal to " + n2); if (n2 && n2.isEqualNode(n1)) diff --git a/content/test/unit/test_range.js b/content/test/unit/test_range.js index 240f1b472c43..de47f5e982fe 100644 --- a/content/test/unit/test_range.js +++ b/content/test/unit/test_range.js @@ -66,6 +66,7 @@ function isWhitespace(aNode) { */ function getFragment(aNode) { var frag = aNode.ownerDocument.createDocumentFragment(); + do_check_true(frag instanceof C_i.nsIDOM3Node); for (var i = 0; i < aNode.childNodes.length; i++) { frag.appendChild(aNode.childNodes.item(i).cloneNode(true)); } @@ -279,7 +280,7 @@ function run_extract_test() { them. After the range's extraction or deletion is done, we use - nsIDOMNode.isEqualNode() between the altered source fragment and the + nsIDOM3Node.isEqualNode() between the altered source fragment and the result fragment. We also run isEqualNode() between the extracted fragment and the fragment from the baseExtract node. If they are not equal, we have failed a test. @@ -320,6 +321,8 @@ function run_extract_test() { var foundStart = false; var foundEnd = false; do { + do_check_true(walker.currentNode instanceof C_i.nsIDOM3Node); + if (walker.currentNode.isSameNode(startContainer)) { foundStart = true; } @@ -354,6 +357,8 @@ function run_extract_test() { foundStart = false; foundEnd = false; do { + do_check_true(walker.currentNode instanceof C_i.nsIDOM3Node); + if (walker.currentNode.isSameNode(startContainer)) { foundStart = true; } diff --git a/content/xbl/src/nsXBLContentSink.cpp b/content/xbl/src/nsXBLContentSink.cpp index e5fc73697bd2..16d2a44a0174 100644 --- a/content/xbl/src/nsXBLContentSink.cpp +++ b/content/xbl/src/nsXBLContentSink.cpp @@ -954,8 +954,7 @@ nsXBLContentSink::AddAttributesToXULPrototype(const PRUnichar **aAtts, } else { nsCOMPtr ni; - ni = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID, - nsIDOMNode::ATTRIBUTE_NODE); + ni = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID); attrs[i].mName.SetTo(ni); } diff --git a/content/xbl/src/nsXBLService.cpp b/content/xbl/src/nsXBLService.cpp index f5bf6297956c..767e9eabc236 100644 --- a/content/xbl/src/nsXBLService.cpp +++ b/content/xbl/src/nsXBLService.cpp @@ -73,6 +73,7 @@ #include "nsCRT.h" #include "nsContentUtils.h" #include "nsSyncLoadService.h" +#include "nsIDOM3Node.h" #include "nsContentPolicyUtils.h" #include "nsTArray.h" #include "nsContentErrors.h" @@ -950,36 +951,42 @@ nsXBLService::GetBinding(nsIContent* aBoundElement, nsIURI* aURI, nsAutoString nameSpace; if (!prefix.IsEmpty()) { - child->LookupNamespaceURI(prefix, nameSpace); + nsCOMPtr prefixAtom = do_GetAtom(prefix); - if (!nameSpace.IsEmpty()) { - if (!hasDisplay) { - // We extend some widget/frame. We don't really have a - // base binding. - protoBinding->SetHasBasePrototype(PR_FALSE); - //child->UnsetAttr(kNameSpaceID_None, nsGkAtoms::extends, PR_FALSE); + nsCOMPtr node(do_QueryInterface(child)); + + if (node) { + node->LookupNamespaceURI(prefix, nameSpace); + + if (!nameSpace.IsEmpty()) { + if (!hasDisplay) { + // We extend some widget/frame. We don't really have a + // base binding. + protoBinding->SetHasBasePrototype(PR_FALSE); + //child->UnsetAttr(kNameSpaceID_None, nsGkAtoms::extends, PR_FALSE); + } + + PRInt32 nameSpaceID = + nsContentUtils::NameSpaceManager()->GetNameSpaceID(nameSpace); + + nsCOMPtr tagName = do_GetAtom(display); + // Check the white list + if (!CheckTagNameWhiteList(nameSpaceID, tagName)) { + const PRUnichar* params[] = { display.get() }; + nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES, + "InvalidExtendsBinding", + params, NS_ARRAY_LENGTH(params), + nsnull, + EmptyString(), 0, 0, + nsIScriptError::errorFlag, + "XBL", doc); + NS_ASSERTION(!IsChromeOrResourceURI(aURI), + "Invalid extends value"); + return NS_ERROR_ILLEGAL_VALUE; + } + + protoBinding->SetBaseTag(nameSpaceID, tagName); } - - PRInt32 nameSpaceID = - nsContentUtils::NameSpaceManager()->GetNameSpaceID(nameSpace); - - nsCOMPtr tagName = do_GetAtom(display); - // Check the white list - if (!CheckTagNameWhiteList(nameSpaceID, tagName)) { - const PRUnichar* params[] = { display.get() }; - nsContentUtils::ReportToConsole(nsContentUtils::eXBL_PROPERTIES, - "InvalidExtendsBinding", - params, NS_ARRAY_LENGTH(params), - nsnull, - EmptyString(), 0, 0, - nsIScriptError::errorFlag, - "XBL", doc); - NS_ASSERTION(!IsChromeOrResourceURI(aURI), - "Invalid extends value"); - return NS_ERROR_ILLEGAL_VALUE; - } - - protoBinding->SetBaseTag(nameSpaceID, tagName); } } diff --git a/content/xml/content/src/nsXMLCDATASection.cpp b/content/xml/content/src/nsXMLCDATASection.cpp index 81e9b810f2ec..071b0d8729b2 100644 --- a/content/xml/content/src/nsXMLCDATASection.cpp +++ b/content/xml/content/src/nsXMLCDATASection.cpp @@ -53,7 +53,7 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA // nsIDOMCharacterData NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::) @@ -64,12 +64,9 @@ public: // nsIDOMCDATASection // Empty interface - // nsINode + // nsIContent virtual PRBool IsNodeOfType(PRUint32 aFlags) const; - virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo, - PRBool aCloneText) const; - virtual nsXPCClassInfo* GetClassInfo(); #ifdef DEBUG virtual void List(FILE* out, PRInt32 aIndent) const; @@ -87,8 +84,7 @@ NS_NewXMLCDATASection(nsIContent** aInstancePtrResult, nsCOMPtr ni; ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::cdataTagName, - nsnull, kNameSpaceID_None, - nsIDOMNode::CDATA_SECTION_NODE); + nsnull, kNameSpaceID_None); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); nsXMLCDATASection *instance = new nsXMLCDATASection(ni.forget()); @@ -104,8 +100,6 @@ NS_NewXMLCDATASection(nsIContent** aInstancePtrResult, nsXMLCDATASection::nsXMLCDATASection(already_AddRefed aNodeInfo) : nsGenericDOMDataNode(aNodeInfo) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == nsIDOMNode::CDATA_SECTION_NODE, - "Bad NodeType in aNodeInfo"); } nsXMLCDATASection::~nsXMLCDATASection() @@ -132,6 +126,32 @@ nsXMLCDATASection::IsNodeOfType(PRUint32 aFlags) const return !(aFlags & ~(eCONTENT | eTEXT | eDATA_NODE)); } +NS_IMETHODIMP +nsXMLCDATASection::GetNodeName(nsAString& aNodeName) +{ + aNodeName.AssignLiteral("#cdata-section"); + return NS_OK; +} + +NS_IMETHODIMP +nsXMLCDATASection::GetNodeValue(nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::GetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsXMLCDATASection::SetNodeValue(const nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::SetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsXMLCDATASection::GetNodeType(PRUint16* aNodeType) +{ + *aNodeType = (PRUint16)nsIDOMNode::CDATA_SECTION_NODE; + return NS_OK; +} + nsGenericDOMDataNode* nsXMLCDATASection::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const { diff --git a/content/xml/content/src/nsXMLProcessingInstruction.cpp b/content/xml/content/src/nsXMLProcessingInstruction.cpp index 741fe43a7fe2..bc9fa8ec7769 100644 --- a/content/xml/content/src/nsXMLProcessingInstruction.cpp +++ b/content/xml/content/src/nsXMLProcessingInstruction.cpp @@ -50,10 +50,7 @@ NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult, { NS_PRECONDITION(aNodeInfoManager, "Missing nodeinfo manager"); - nsCOMPtr target = do_GetAtom(aTarget); - NS_ENSURE_TRUE(target, NS_ERROR_OUT_OF_MEMORY); - - if (target == nsGkAtoms::xml_stylesheet) { + if (aTarget.EqualsLiteral("xml-stylesheet")) { return NS_NewXMLStylesheetProcessingInstruction(aInstancePtrResult, aNodeInfoManager, aData); } @@ -62,13 +59,11 @@ NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult, nsCOMPtr ni; ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName, - nsnull, kNameSpaceID_None, - nsIDOMNode::PROCESSING_INSTRUCTION_NODE, - target); + nsnull, kNameSpaceID_None); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); nsXMLProcessingInstruction *instance = - new nsXMLProcessingInstruction(ni.forget(), aData); + new nsXMLProcessingInstruction(ni.forget(), aTarget, aData); if (!instance) { return NS_ERROR_OUT_OF_MEMORY; } @@ -79,13 +74,11 @@ NS_NewXMLProcessingInstruction(nsIContent** aInstancePtrResult, } nsXMLProcessingInstruction::nsXMLProcessingInstruction(already_AddRefed aNodeInfo, + const nsAString& aTarget, const nsAString& aData) - : nsGenericDOMDataNode(aNodeInfo) + : nsGenericDOMDataNode(aNodeInfo), + mTarget(aTarget) { - NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == - nsIDOMNode::PROCESSING_INSTRUCTION_NODE, - "Bad NodeType in aNodeInfo"); - SetTextInternal(0, mText.GetLength(), aData.BeginReading(), aData.Length(), PR_FALSE); // Don't notify (bug 420429). @@ -117,7 +110,7 @@ NS_IMPL_RELEASE_INHERITED(nsXMLProcessingInstruction, nsGenericDOMDataNode) NS_IMETHODIMP nsXMLProcessingInstruction::GetTarget(nsAString& aTarget) { - aTarget = NodeName(); + aTarget.Assign(mTarget); return NS_OK; } @@ -149,6 +142,32 @@ nsXMLProcessingInstruction::IsNodeOfType(PRUint32 aFlags) const return !(aFlags & ~(eCONTENT | ePROCESSING_INSTRUCTION | eDATA_NODE)); } +NS_IMETHODIMP +nsXMLProcessingInstruction::GetNodeName(nsAString& aNodeName) +{ + aNodeName.Assign(mTarget); + return NS_OK; +} + +NS_IMETHODIMP +nsXMLProcessingInstruction::GetNodeValue(nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::GetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsXMLProcessingInstruction::SetNodeValue(const nsAString& aNodeValue) +{ + return nsGenericDOMDataNode::SetNodeValue(aNodeValue); +} + +NS_IMETHODIMP +nsXMLProcessingInstruction::GetNodeType(PRUint16* aNodeType) +{ + *aNodeType = (PRUint16)nsIDOMNode::PROCESSING_INSTRUCTION_NODE; + return NS_OK; +} + nsGenericDOMDataNode* nsXMLProcessingInstruction::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const @@ -156,7 +175,7 @@ nsXMLProcessingInstruction::CloneDataNode(nsINodeInfo *aNodeInfo, nsAutoString data; nsGenericDOMDataNode::GetData(data); nsCOMPtr ni = aNodeInfo; - return new nsXMLProcessingInstruction(ni.forget(), data); + return new nsXMLProcessingInstruction(ni.forget(), mTarget, data); } #ifdef DEBUG @@ -170,7 +189,7 @@ nsXMLProcessingInstruction::List(FILE* out, PRInt32 aIndent) const nsAutoString tmp; ToCString(tmp, 0, mText.GetLength()); - tmp.Insert(nsDependentAtomString(NodeInfo()->GetExtraName()).get(), 0); + tmp.Insert(mTarget.get(), 0); fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out); fputs(">\n", out); diff --git a/content/xml/content/src/nsXMLProcessingInstruction.h b/content/xml/content/src/nsXMLProcessingInstruction.h index a3908cc0109f..f32f231f1b63 100644 --- a/content/xml/content/src/nsXMLProcessingInstruction.h +++ b/content/xml/content/src/nsXMLProcessingInstruction.h @@ -50,6 +50,7 @@ class nsXMLProcessingInstruction : public nsGenericDOMDataNode, { public: nsXMLProcessingInstruction(already_AddRefed aNodeInfo, + const nsAString& aTarget, const nsAString& aData); virtual ~nsXMLProcessingInstruction(); @@ -57,17 +58,14 @@ public: NS_DECL_ISUPPORTS_INHERITED // nsIDOMNode - NS_FORWARD_NSIDOMNODE(nsGenericDOMDataNode::) + NS_IMPL_NSIDOMNODE_USING_GENERIC_DOM_DATA // nsIDOMProcessingInstruction NS_DECL_NSIDOMPROCESSINGINSTRUCTION - // nsINode + // nsIContent virtual PRBool IsNodeOfType(PRUint32 aFlags) const; - virtual nsGenericDOMDataNode* CloneDataNode(nsINodeInfo *aNodeInfo, - PRBool aCloneText) const; - #ifdef DEBUG virtual void List(FILE* out, PRInt32 aIndent) const; virtual void DumpContent(FILE* out, PRInt32 aIndent, PRBool aDumpAll) const; @@ -86,6 +84,8 @@ protected: * aAttribute. Empty if the attribute isn't present. */ PRBool GetAttrValue(nsIAtom *aName, nsAString& aValue); + + nsString mTarget; }; #endif //nsIXMLProcessingInstruction_h___ diff --git a/content/xml/content/src/nsXMLStylesheetPI.cpp b/content/xml/content/src/nsXMLStylesheetPI.cpp index 96e9e5c0e906..2f3524371c66 100644 --- a/content/xml/content/src/nsXMLStylesheetPI.cpp +++ b/content/xml/content/src/nsXMLStylesheetPI.cpp @@ -105,7 +105,8 @@ NS_IMPL_RELEASE_INHERITED(nsXMLStylesheetPI, nsXMLProcessingInstruction) nsXMLStylesheetPI::nsXMLStylesheetPI(already_AddRefed aNodeInfo, const nsAString& aData) - : nsXMLProcessingInstruction(aNodeInfo, aData) + : nsXMLProcessingInstruction(aNodeInfo, NS_LITERAL_STRING("xml-stylesheet"), + aData) { } @@ -265,9 +266,7 @@ NS_NewXMLStylesheetProcessingInstruction(nsIContent** aInstancePtrResult, nsCOMPtr ni; ni = aNodeInfoManager->GetNodeInfo(nsGkAtoms::processingInstructionTagName, - nsnull, kNameSpaceID_None, - nsIDOMNode::PROCESSING_INSTRUCTION_NODE, - nsGkAtoms::xml_stylesheet); + nsnull, kNameSpaceID_None); NS_ENSURE_TRUE(ni, NS_ERROR_OUT_OF_MEMORY); nsXMLStylesheetPI *instance = new nsXMLStylesheetPI(ni.forget(), aData); diff --git a/content/xml/document/src/nsXMLContentSink.cpp b/content/xml/document/src/nsXMLContentSink.cpp index a2c1c88daaf9..71c0e08205d8 100644 --- a/content/xml/document/src/nsXMLContentSink.cpp +++ b/content/xml/document/src/nsXMLContentSink.cpp @@ -1012,8 +1012,7 @@ nsXMLContentSink::HandleStartElement(const PRUnichar *aName, } nsCOMPtr nodeInfo; - nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID, - nsIDOMNode::ELEMENT_NODE); + nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID); NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); result = CreateElement(aAtts, aAttsCount, nodeInfo, aLineNumber, diff --git a/content/xml/document/src/nsXMLFragmentContentSink.cpp b/content/xml/document/src/nsXMLFragmentContentSink.cpp index 715896458ac1..fc27165c8a2b 100644 --- a/content/xml/document/src/nsXMLFragmentContentSink.cpp +++ b/content/xml/document/src/nsXMLFragmentContentSink.cpp @@ -641,6 +641,7 @@ nsXHTMLParanoidFragmentSink::AddAttributes(const PRUnichar** aAtts, nsTArray allowedAttrs; PRInt32 nameSpaceID; nsCOMPtr prefix, localName; + nsCOMPtr nodeInfo; if (!mNullPrincipal) { mNullPrincipal = do_CreateInstance(NS_NULLPRINCIPAL_CONTRACTID, &rv); @@ -650,8 +651,10 @@ nsXHTMLParanoidFragmentSink::AddAttributes(const PRUnichar** aAtts, while (*aAtts) { nsContentUtils::SplitExpatName(aAtts[0], getter_AddRefs(prefix), getter_AddRefs(localName), &nameSpaceID); + nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID); + NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); // check the attributes we allow that contain URIs - if (IsAttrURI(localName)) { + if (IsAttrURI(nodeInfo->NameAtom())) { if (!aAtts[1]) rv = NS_ERROR_FAILURE; if (!baseURI) @@ -693,16 +696,21 @@ nsXHTMLParanoidFragmentSink::HandleStartElement(const PRUnichar *aName, if (nameSpaceID != kNameSpaceID_XHTML) return NS_OK; + nsCOMPtr nodeInfo; + nodeInfo = mNodeInfoManager->GetNodeInfo(localName, prefix, nameSpaceID); + NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY); + // bounce it if it's not on the whitelist or we're inside //