diff --git a/content/base/src/nsGenericElement.cpp b/content/base/src/nsGenericElement.cpp index fa3a3174005..e4a79d82f0b 100644 --- a/content/base/src/nsGenericElement.cpp +++ b/content/base/src/nsGenericElement.cpp @@ -843,6 +843,209 @@ nsGenericElement::GetElementsByTagName(const nsString& aTagname, return list->QueryInterface(kIDOMNodeListIID, (void **)aReturn); } +nsresult +nsGenericElement::GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) +{ + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + aReturn.Truncate(); + return NS_OK; + } + + mContent->GetAttribute(nsid, name, aReturn); + + return NS_OK; +} + +nsresult +nsGenericElement::SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) +{ + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr ni; + nsresult rv = nimgr->GetNodeInfo(aQualifiedName, aNamespaceURI, + *getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr name; + PRInt32 nsid; + + ni->GetNameAtom(*getter_AddRefs(name)); + ni->GetNamespaceID(nsid); + + return mContent->SetAttribute(nsid, name, aValue, PR_TRUE); +} + +nsresult + +nsGenericElement::RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) +{ + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + return NS_OK; + } + + nsAutoString tmp; + mContent->UnsetAttribute(nsid, name, PR_TRUE); + + return NS_OK; +} + +nsresult +nsGenericElement::GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsIDOMNamedNodeMap* map; + nsresult result = GetAttributes(&map); + + *aReturn = nsnull; + if (NS_OK == result) { + nsIDOMNode* node; + result = map->GetNamedItemNS(aNamespaceURI, aLocalName, &node); + if ((NS_OK == result) && (nsnull != node)) { + result = node->QueryInterface(kIDOMAttrIID, (void **)aReturn); + NS_IF_RELEASE(node); + } + NS_RELEASE(map); + } + + return result; +} + +nsresult +nsGenericElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr, + nsIDOMAttr** aReturn) +{ + return NS_OK; +} + +nsresult +nsGenericElement::GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) +{ + nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nameSpaceId = kNameSpaceID_Unknown; + + nsContentList* list = nsnull; + + if (!aNamespaceURI.EqualsWithConversion("*")) { + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nameSpaceId); + + if (nameSpaceId == kNameSpaceID_Unknown) { + // Unkonwn namespace means no matches, we create an empty list... + list = new nsContentList(mDocument, nsnull, kNameSpaceID_None); + NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); + } + } + + if (!list) { + list = new nsContentList(mDocument, nameAtom, nameSpaceId, mContent); + NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); + } + + return list->QueryInterface(kIDOMNodeListIID, (void **)aReturn); +} + +nsresult +nsGenericElement::HasAttribute(const nsString& aName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name; + PRInt32 nsid; + + nsresult rv = mContent->ParseAttributeString(aName, *getter_AddRefs(name), + nsid); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString tmp; + rv = mContent->GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + +nsresult +nsGenericElement::HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + *aReturn = PR_FALSE; + return NS_OK; + } + + nsAutoString tmp; + nsresult rv = mContent->GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + nsresult nsGenericElement::JoinTextNodes(nsIContent* aFirst, nsIContent* aSecond) diff --git a/content/base/src/nsGenericElement.h b/content/base/src/nsGenericElement.h index fdb448ad430..d835eeabb6d 100644 --- a/content/base/src/nsGenericElement.h +++ b/content/base/src/nsGenericElement.h @@ -155,6 +155,23 @@ public: nsresult RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn); nsresult GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn); + nsresult GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn); + nsresult SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue); + nsresult RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName); + nsresult GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn); + nsresult SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn); + nsresult GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn); + nsresult HasAttribute(const nsString& aName, PRBool* aReturn); + nsresult HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn); // nsIScriptObjectOwner interface nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); @@ -464,6 +481,39 @@ public: NS_IMETHOD GetElementsByTagName(const nsString& aTagname, \ nsIDOMNodeList** aReturn) { \ return _g.GetElementsByTagName(aTagname, aReturn); \ + } \ + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, nsString& aReturn) { \ + return _g.GetAttributeNS(aNamespaceURI, aLocalName, aReturn); \ + } \ + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aQualifiedName, \ + const nsString& aValue) { \ + return _g.SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); \ + } \ + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName) { \ + return _g.RemoveAttributeNS(aNamespaceURI, aLocalName); \ + } \ + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, \ + nsIDOMAttr** aReturn) { \ + return _g.GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); \ + } \ + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { \ + return _g.SetAttributeNodeNS(aNewAttr, aReturn); \ + } \ + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, \ + nsIDOMNodeList** aReturn) { \ + return _g.GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); \ + } \ + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { \ + return _g.HasAttribute(aName, aReturn); \ + } \ + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, PRBool* aReturn) { \ + return _g.HasAttributeNS(aNamespaceURI, aLocalName, aReturn); \ } /** diff --git a/content/html/content/src/nsHTMLInputElement.cpp b/content/html/content/src/nsHTMLInputElement.cpp index ff1f3c1dcde..5f81a323b7d 100644 --- a/content/html/content/src/nsHTMLInputElement.cpp +++ b/content/html/content/src/nsHTMLInputElement.cpp @@ -124,6 +124,39 @@ public: nsIDOMNodeList** aReturn) { return mInner.GetElementsByTagName(aTagname, aReturn); } + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) { + return mInner.GetAttributeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) { + return mInner.SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); + } + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) { + return mInner.RemoveAttributeNS(aNamespaceURI, aLocalName); + } + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) { + return mInner.GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { + return mInner.SetAttributeNodeNS(aNewAttr, aReturn); + } + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) { + return mInner.GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { + return mInner.HasAttribute(aName, aReturn); + } + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) { + return mInner.HasAttributeNS(aNamespaceURI, aLocalName, aReturn); + } // nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) diff --git a/content/html/content/src/nsHTMLLabelElement.cpp b/content/html/content/src/nsHTMLLabelElement.cpp index 8a5ea165681..50c36ea6e41 100644 --- a/content/html/content/src/nsHTMLLabelElement.cpp +++ b/content/html/content/src/nsHTMLLabelElement.cpp @@ -102,6 +102,39 @@ public: nsIDOMNodeList** aReturn) { return mInner.GetElementsByTagName(aTagname, aReturn); } + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) { + return mInner.GetAttributeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) { + return mInner.SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); + } + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) { + return mInner.RemoveAttributeNS(aNamespaceURI, aLocalName); + } + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) { + return mInner.GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { + return mInner.SetAttributeNodeNS(aNewAttr, aReturn); + } + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) { + return mInner.GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { + return HasAttribute(aName, aReturn); + } + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) { + return mInner.HasAttributeNS(aNamespaceURI, aLocalName, aReturn); + } // nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) diff --git a/content/xul/content/src/nsXULElement.cpp b/content/xul/content/src/nsXULElement.cpp index 0f53821c771..99892a8d79b 100644 --- a/content/xul/content/src/nsXULElement.cpp +++ b/content/xul/content/src/nsXULElement.cpp @@ -117,6 +117,7 @@ #include "nsXULRadioElement.h" #include "nsXULRadioGroupElement.h" #include "nsXULMenuListElement.h" +#include "nsXULDocument.h" #include "prlog.h" #include "rdf.h" @@ -1577,6 +1578,180 @@ nsXULElement::GetElementsByTagName(const nsString& aName, nsIDOMNodeList** aRetu return NS_OK; } +NS_IMETHODIMP +nsXULElement::GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) +{ + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + aReturn.Truncate(); + return NS_OK; + } + + GetAttribute(nsid, name, aReturn); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsXULElement::RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) +{ + PRInt32 nameSpaceId; + nsCOMPtr tag = dont_AddRef(NS_NewAtom(aLocalName)); + + if (!aNamespaceURI.EqualsWithConversion("*")) { + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nameSpaceId); + + if (nameSpaceId == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + return NS_OK; + } + } + + nsresult rv = UnsetAttribute(nameSpaceId, tag, PR_TRUE); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove attribute"); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsresult rv; + + nsCOMPtr map; + rv = GetAttributes(getter_AddRefs(map)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr node; + rv = map->GetNamedItemNS(aNamespaceURI, aLocalName, getter_AddRefs(node)); + if (NS_FAILED(rv)) return rv; + + if (node) { + rv = node->QueryInterface(NS_GET_IID(nsIDOMAttr), (void**) aReturn); + } + else { + *aReturn = nsnull; + rv = NS_OK; + } + + return rv; +} + +NS_IMETHODIMP +nsXULElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr, + nsIDOMAttr** aReturn) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsXULElement::GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + PRInt32 nameSpaceId = kNameSpaceID_Unknown; + + nsRDFDOMNodeList* elements; + nsresult rv = nsRDFDOMNodeList::Create(&elements); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr kungFuGrip; + kungFuGrip = dont_AddRef(NS_STATIC_CAST(nsIDOMNodeList *, elements)); + + if (!aNamespaceURI.EqualsWithConversion("*")) { + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nameSpaceId); + + if (nameSpaceId == kNameSpaceID_Unknown) { + // Unkonwn namespace means no matches, we return an empty list... + + *aReturn = elements; + NS_ADDREF(*aReturn); + + return NS_OK; + } + } + + rv = nsXULDocument::GetElementsByTagName(NS_STATIC_CAST(nsIStyledContent *, + this), aLocalName, + nameSpaceId, elements); + NS_ENSURE_SUCCESS(rv, rv); + + *aReturn = elements; + NS_ADDREF(*aReturn); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::HasAttribute(const nsString& aName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name; + PRInt32 nsid; + + nsresult rv = ParseAttributeString(aName, *getter_AddRefs(name), nsid); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString tmp; + rv = GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + *aReturn = PR_FALSE; + return NS_OK; + } + + nsAutoString tmp; + nsresult rv = GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + NS_IMETHODIMP nsXULElement::GetElementsByAttribute(const nsString& aAttribute, const nsString& aValue, diff --git a/content/xul/document/src/nsXULDocument.h b/content/xul/document/src/nsXULDocument.h index 48de7504d47..c11b52b06a9 100644 --- a/content/xul/document/src/nsXULDocument.h +++ b/content/xul/document/src/nsXULDocument.h @@ -402,6 +402,12 @@ public: NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult); NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult); + static nsresult + GetElementsByTagName(nsIContent* aContent, + const nsString& aTagName, + PRInt32 aNamespaceID, + nsRDFDOMNodeList* aElements); + protected: // Implementation methods friend nsresult @@ -431,12 +437,6 @@ protected: nsIContent* aElement, void* aClosure); - static nsresult - GetElementsByTagName(nsIContent* aContent, - const nsString& aTagName, - PRInt32 aNamespaceID, - nsRDFDOMNodeList* aElements); - static nsresult GetElementsByAttribute(nsIDOMNode* aNode, const nsString& aAttribute, diff --git a/dom/public/coreDom/nsIDOMElement.h b/dom/public/coreDom/nsIDOMElement.h index 6540e5e1aec..0f0604b38e4 100644 --- a/dom/public/coreDom/nsIDOMElement.h +++ b/dom/public/coreDom/nsIDOMElement.h @@ -55,6 +55,22 @@ public: NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn)=0; NS_IMETHOD GetElementsByTagName(const nsString& aName, nsIDOMNodeList** aReturn)=0; + + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsString& aReturn)=0; + + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, const nsString& aQualifiedName, const nsString& aValue)=0; + + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName)=0; + + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsIDOMAttr** aReturn)=0; + + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn)=0; + + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsIDOMNodeList** aReturn)=0; + + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn)=0; + + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName, PRBool* aReturn)=0; }; @@ -67,6 +83,14 @@ public: NS_IMETHOD SetAttributeNode(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn); \ NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn); \ NS_IMETHOD GetElementsByTagName(const nsString& aName, nsIDOMNodeList** aReturn); \ + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsString& aReturn); \ + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, const nsString& aQualifiedName, const nsString& aValue); \ + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName); \ + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsIDOMAttr** aReturn); \ + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn); \ + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsIDOMNodeList** aReturn); \ + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn); \ + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName, PRBool* aReturn); \ @@ -79,6 +103,14 @@ public: NS_IMETHOD SetAttributeNode(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { return _to SetAttributeNode(aNewAttr, aReturn); } \ NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn) { return _to RemoveAttributeNode(aOldAttr, aReturn); } \ NS_IMETHOD GetElementsByTagName(const nsString& aName, nsIDOMNodeList** aReturn) { return _to GetElementsByTagName(aName, aReturn); } \ + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsString& aReturn) { return _to GetAttributeNS(aNamespaceURI, aLocalName, aReturn); } \ + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, const nsString& aQualifiedName, const nsString& aValue) { return _to SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); } \ + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName) { return _to RemoveAttributeNS(aNamespaceURI, aLocalName); } \ + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsIDOMAttr** aReturn) { return _to GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); } \ + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { return _to SetAttributeNodeNS(aNewAttr, aReturn); } \ + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, const nsString& aLocalName, nsIDOMNodeList** aReturn) { return _to GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); } \ + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { return _to HasAttribute(aName, aReturn); } \ + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, const nsString& aLocalName, PRBool* aReturn) { return _to HasAttributeNS(aNamespaceURI, aLocalName, aReturn); } \ extern "C" NS_DOM nsresult NS_InitElementClass(nsIScriptContext *aContext, void **aPrototype); diff --git a/dom/public/idl/coreDom/Element.idl b/dom/public/idl/coreDom/Element.idl index 24b2e686134..e69de29bb2d 100644 --- a/dom/public/idl/coreDom/Element.idl +++ b/dom/public/idl/coreDom/Element.idl @@ -1,18 +0,0 @@ - interface Element : Node { - /* IID: { 0xa6cf9078, 0x15b3, 0x11d2, \ - { 0x93, 0x2e, 0x00, 0x80, 0x5f, 0x8a, 0xdd, 0x32 } } */ - - readonly attribute DOMString tagName; - DOMString getAttribute(in DOMString name); - void setAttribute(in DOMString name, - in DOMString value) - raises(DOMException); - void removeAttribute(in DOMString name) - raises(DOMException); - Attr getAttributeNode(in DOMString name); - Attr setAttributeNode(in Attr newAttr) - raises(DOMException); - Attr removeAttributeNode(in Attr oldAttr) - raises(DOMException); - NodeList getElementsByTagName(in DOMString name); - }; diff --git a/dom/public/nsDOMPropEnums.h b/dom/public/nsDOMPropEnums.h index 08919e0e2d0..8190c2821df 100644 --- a/dom/public/nsDOMPropEnums.h +++ b/dom/public/nsDOMPropEnums.h @@ -266,11 +266,19 @@ enum nsDOMProp { NS_DOM_PROP_DOMIMPLEMENTATION_HASFEATURE, NS_DOM_PROP_ELEMENT_GETATTRIBUTE, NS_DOM_PROP_ELEMENT_GETATTRIBUTENODE, + NS_DOM_PROP_ELEMENT_GETATTRIBUTENODENS, + NS_DOM_PROP_ELEMENT_GETATTRIBUTENS, NS_DOM_PROP_ELEMENT_GETELEMENTSBYTAGNAME, + NS_DOM_PROP_ELEMENT_GETELEMENTSBYTAGNAMENS, + NS_DOM_PROP_ELEMENT_HASATTRIBUTE, + NS_DOM_PROP_ELEMENT_HASATTRIBUTENS, NS_DOM_PROP_ELEMENT_REMOVEATTRIBUTE, NS_DOM_PROP_ELEMENT_REMOVEATTRIBUTENODE, + NS_DOM_PROP_ELEMENT_REMOVEATTRIBUTENS, NS_DOM_PROP_ELEMENT_SETATTRIBUTE, NS_DOM_PROP_ELEMENT_SETATTRIBUTENODE, + NS_DOM_PROP_ELEMENT_SETATTRIBUTENODENS, + NS_DOM_PROP_ELEMENT_SETATTRIBUTENS, NS_DOM_PROP_ELEMENT_TAGNAME, NS_DOM_PROP_ENTITY_NOTATIONNAME, NS_DOM_PROP_ENTITY_PUBLICID, diff --git a/dom/public/nsDOMPropNames.h b/dom/public/nsDOMPropNames.h index 200221a7439..6ffb44de3ad 100644 --- a/dom/public/nsDOMPropNames.h +++ b/dom/public/nsDOMPropNames.h @@ -265,11 +265,19 @@ "domimplementation.hasfeature", \ "element.getattribute", \ "element.getattributenode", \ + "element.getattributenodens", \ + "element.getattributens", \ "element.getelementsbytagname", \ + "element.getelementsbytagnamens", \ + "element.hasattribute", \ + "element.hasattributens", \ "element.removeattribute", \ "element.removeattributenode", \ + "element.removeattributens", \ "element.setattribute", \ "element.setattributenode", \ + "element.setattributenodens", \ + "element.setattributens", \ "element.tagname", \ "entity.notationname", \ "entity.publicid", \ diff --git a/dom/src/coreDOM/nsJSElement.cpp b/dom/src/coreDOM/nsJSElement.cpp index fb5d99260b9..60dd27d3ae5 100644 --- a/dom/src/coreDOM/nsJSElement.cpp +++ b/dom/src/coreDOM/nsJSElement.cpp @@ -22,6 +22,7 @@ /* AUTO-GENERATED. DO NOT EDIT!!! */ #include "jsapi.h" +#include "jsnum.h" #include "nsJSUtils.h" #include "nsDOMError.h" #include "nscore.h" @@ -469,6 +470,360 @@ ElementGetElementsByTagName(JSContext *cx, JSObject *obj, uintN argc, jsval *arg } +// +// Native method GetAttributeNS +// +PR_STATIC_CALLBACK(JSBool) +ElementGetAttributeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_GETATTRIBUTENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->GetAttributeNS(b0, b1, nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval); + } + + return JS_TRUE; +} + + +// +// Native method SetAttributeNS +// +PR_STATIC_CALLBACK(JSBool) +ElementSetAttributeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString b0; + nsAutoString b1; + nsAutoString b2; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_SETATTRIBUTENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 3) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + nsJSUtils::nsConvertJSValToString(b2, cx, argv[2]); + + result = nativeThis->SetAttributeNS(b0, b1, b2); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + +// +// Native method RemoveAttributeNS +// +PR_STATIC_CALLBACK(JSBool) +ElementRemoveAttributeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_REMOVEATTRIBUTENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->RemoveAttributeNS(b0, b1); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = JSVAL_VOID; + } + + return JS_TRUE; +} + + +// +// Native method GetAttributeNodeNS +// +PR_STATIC_CALLBACK(JSBool) +ElementGetAttributeNodeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsIDOMAttr* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_GETATTRIBUTENODENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->GetAttributeNodeNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method SetAttributeNodeNS +// +PR_STATIC_CALLBACK(JSBool) +ElementSetAttributeNodeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsIDOMAttr* nativeRet; + nsCOMPtr b0; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_SETATTRIBUTENODENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + if (JS_FALSE == nsJSUtils::nsConvertJSValToObject((nsISupports **)(void**)getter_AddRefs(b0), + kIAttrIID, + NS_ConvertASCIItoUCS2("Attr"), + cx, + argv[0])) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_NOT_OBJECT_ERR); + } + + result = nativeThis->SetAttributeNodeNS(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method GetElementsByTagNameNS +// +PR_STATIC_CALLBACK(JSBool) +ElementGetElementsByTagNameNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + nsIDOMNodeList* nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_GETELEMENTSBYTAGNAMENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->GetElementsByTagNameNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + nsJSUtils::nsConvertObjectToJSVal(nativeRet, cx, obj, rval); + } + + return JS_TRUE; +} + + +// +// Native method HasAttribute +// +PR_STATIC_CALLBACK(JSBool) +ElementHasAttribute(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + PRBool nativeRet; + nsAutoString b0; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_HASATTRIBUTE, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 1) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + + result = nativeThis->HasAttribute(b0, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = BOOLEAN_TO_JSVAL(nativeRet); + } + + return JS_TRUE; +} + + +// +// Native method HasAttributeNS +// +PR_STATIC_CALLBACK(JSBool) +ElementHasAttributeNS(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) +{ + nsIDOMElement *nativeThis = (nsIDOMElement*)nsJSUtils::nsGetNativeThis(cx, obj); + nsresult result = NS_OK; + PRBool nativeRet; + nsAutoString b0; + nsAutoString b1; + // If there's no private data, this must be the prototype, so ignore + if (nsnull == nativeThis) { + return JS_TRUE; + } + + { + *rval = JSVAL_NULL; + nsIScriptSecurityManager *secMan = nsJSUtils::nsGetSecurityManager(cx, obj); + if (!secMan) + return PR_FALSE; + result = secMan->CheckScriptAccess(cx, obj, NS_DOM_PROP_ELEMENT_HASATTRIBUTENS, PR_FALSE); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + if (argc < 2) { + return nsJSUtils::nsReportError(cx, obj, NS_ERROR_DOM_TOO_FEW_PARAMETERS_ERR); + } + + nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]); + nsJSUtils::nsConvertJSValToString(b1, cx, argv[1]); + + result = nativeThis->HasAttributeNS(b0, b1, &nativeRet); + if (NS_FAILED(result)) { + return nsJSUtils::nsReportError(cx, obj, result); + } + + *rval = BOOLEAN_TO_JSVAL(nativeRet); + } + + return JS_TRUE; +} + + /***********************************************************************/ // // class for Element @@ -511,6 +866,14 @@ static JSFunctionSpec ElementMethods[] = {"setAttributeNode", ElementSetAttributeNode, 1}, {"removeAttributeNode", ElementRemoveAttributeNode, 1}, {"getElementsByTagName", ElementGetElementsByTagName, 1}, + {"getAttributeNS", ElementGetAttributeNS, 2}, + {"setAttributeNS", ElementSetAttributeNS, 3}, + {"removeAttributeNS", ElementRemoveAttributeNS, 2}, + {"getAttributeNodeNS", ElementGetAttributeNodeNS, 2}, + {"setAttributeNodeNS", ElementSetAttributeNodeNS, 1}, + {"getElementsByTagNameNS", ElementGetElementsByTagNameNS, 2}, + {"hasAttribute", ElementHasAttribute, 1}, + {"hasAttributeNS", ElementHasAttributeNS, 2}, {0} }; diff --git a/layout/base/src/nsGenericElement.cpp b/layout/base/src/nsGenericElement.cpp index fa3a3174005..e4a79d82f0b 100644 --- a/layout/base/src/nsGenericElement.cpp +++ b/layout/base/src/nsGenericElement.cpp @@ -843,6 +843,209 @@ nsGenericElement::GetElementsByTagName(const nsString& aTagname, return list->QueryInterface(kIDOMNodeListIID, (void **)aReturn); } +nsresult +nsGenericElement::GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) +{ + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + aReturn.Truncate(); + return NS_OK; + } + + mContent->GetAttribute(nsid, name, aReturn); + + return NS_OK; +} + +nsresult +nsGenericElement::SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) +{ + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr ni; + nsresult rv = nimgr->GetNodeInfo(aQualifiedName, aNamespaceURI, + *getter_AddRefs(ni)); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr name; + PRInt32 nsid; + + ni->GetNameAtom(*getter_AddRefs(name)); + ni->GetNamespaceID(nsid); + + return mContent->SetAttribute(nsid, name, aValue, PR_TRUE); +} + +nsresult + +nsGenericElement::RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) +{ + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + return NS_OK; + } + + nsAutoString tmp; + mContent->UnsetAttribute(nsid, name, PR_TRUE); + + return NS_OK; +} + +nsresult +nsGenericElement::GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsIDOMNamedNodeMap* map; + nsresult result = GetAttributes(&map); + + *aReturn = nsnull; + if (NS_OK == result) { + nsIDOMNode* node; + result = map->GetNamedItemNS(aNamespaceURI, aLocalName, &node); + if ((NS_OK == result) && (nsnull != node)) { + result = node->QueryInterface(kIDOMAttrIID, (void **)aReturn); + NS_IF_RELEASE(node); + } + NS_RELEASE(map); + } + + return result; +} + +nsresult +nsGenericElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr, + nsIDOMAttr** aReturn) +{ + return NS_OK; +} + +nsresult +nsGenericElement::GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) +{ + nsCOMPtr nameAtom(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nameSpaceId = kNameSpaceID_Unknown; + + nsContentList* list = nsnull; + + if (!aNamespaceURI.EqualsWithConversion("*")) { + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nameSpaceId); + + if (nameSpaceId == kNameSpaceID_Unknown) { + // Unkonwn namespace means no matches, we create an empty list... + list = new nsContentList(mDocument, nsnull, kNameSpaceID_None); + NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); + } + } + + if (!list) { + list = new nsContentList(mDocument, nameAtom, nameSpaceId, mContent); + NS_ENSURE_TRUE(list, NS_ERROR_OUT_OF_MEMORY); + } + + return list->QueryInterface(kIDOMNodeListIID, (void **)aReturn); +} + +nsresult +nsGenericElement::HasAttribute(const nsString& aName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name; + PRInt32 nsid; + + nsresult rv = mContent->ParseAttributeString(aName, *getter_AddRefs(name), + nsid); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString tmp; + rv = mContent->GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + +nsresult +nsGenericElement::HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + nsCOMPtr nimgr; + mNodeInfo->GetNodeInfoManager(*getter_AddRefs(nimgr)); + NS_ENSURE_TRUE(nimgr, NS_ERROR_FAILURE); + + nsCOMPtr nsmgr; + nimgr->GetNamespaceManager(*getter_AddRefs(nsmgr)); + NS_ENSURE_TRUE(nsmgr, NS_ERROR_FAILURE); + + nsmgr->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + *aReturn = PR_FALSE; + return NS_OK; + } + + nsAutoString tmp; + nsresult rv = mContent->GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + nsresult nsGenericElement::JoinTextNodes(nsIContent* aFirst, nsIContent* aSecond) diff --git a/layout/base/src/nsGenericElement.h b/layout/base/src/nsGenericElement.h index fdb448ad430..d835eeabb6d 100644 --- a/layout/base/src/nsGenericElement.h +++ b/layout/base/src/nsGenericElement.h @@ -155,6 +155,23 @@ public: nsresult RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn); nsresult GetElementsByTagName(const nsString& aTagname, nsIDOMNodeList** aReturn); + nsresult GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn); + nsresult SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue); + nsresult RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName); + nsresult GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn); + nsresult SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn); + nsresult GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn); + nsresult HasAttribute(const nsString& aName, PRBool* aReturn); + nsresult HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn); // nsIScriptObjectOwner interface nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); @@ -464,6 +481,39 @@ public: NS_IMETHOD GetElementsByTagName(const nsString& aTagname, \ nsIDOMNodeList** aReturn) { \ return _g.GetElementsByTagName(aTagname, aReturn); \ + } \ + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, nsString& aReturn) { \ + return _g.GetAttributeNS(aNamespaceURI, aLocalName, aReturn); \ + } \ + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aQualifiedName, \ + const nsString& aValue) { \ + return _g.SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); \ + } \ + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName) { \ + return _g.RemoveAttributeNS(aNamespaceURI, aLocalName); \ + } \ + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, \ + nsIDOMAttr** aReturn) { \ + return _g.GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); \ + } \ + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { \ + return _g.SetAttributeNodeNS(aNewAttr, aReturn); \ + } \ + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, \ + nsIDOMNodeList** aReturn) { \ + return _g.GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); \ + } \ + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { \ + return _g.HasAttribute(aName, aReturn); \ + } \ + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, \ + const nsString& aLocalName, PRBool* aReturn) { \ + return _g.HasAttributeNS(aNamespaceURI, aLocalName, aReturn); \ } /** diff --git a/layout/html/content/src/nsHTMLInputElement.cpp b/layout/html/content/src/nsHTMLInputElement.cpp index ff1f3c1dcde..5f81a323b7d 100644 --- a/layout/html/content/src/nsHTMLInputElement.cpp +++ b/layout/html/content/src/nsHTMLInputElement.cpp @@ -124,6 +124,39 @@ public: nsIDOMNodeList** aReturn) { return mInner.GetElementsByTagName(aTagname, aReturn); } + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) { + return mInner.GetAttributeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) { + return mInner.SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); + } + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) { + return mInner.RemoveAttributeNS(aNamespaceURI, aLocalName); + } + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) { + return mInner.GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { + return mInner.SetAttributeNodeNS(aNewAttr, aReturn); + } + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) { + return mInner.GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { + return mInner.HasAttribute(aName, aReturn); + } + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) { + return mInner.HasAttributeNS(aNamespaceURI, aLocalName, aReturn); + } // nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) diff --git a/layout/html/content/src/nsHTMLLabelElement.cpp b/layout/html/content/src/nsHTMLLabelElement.cpp index 8a5ea165681..50c36ea6e41 100644 --- a/layout/html/content/src/nsHTMLLabelElement.cpp +++ b/layout/html/content/src/nsHTMLLabelElement.cpp @@ -102,6 +102,39 @@ public: nsIDOMNodeList** aReturn) { return mInner.GetElementsByTagName(aTagname, aReturn); } + NS_IMETHOD GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) { + return mInner.GetAttributeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) { + return mInner.SetAttributeNS(aNamespaceURI, aQualifiedName, aValue); + } + NS_IMETHOD RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) { + return mInner.RemoveAttributeNS(aNamespaceURI, aLocalName); + } + NS_IMETHOD GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) { + return mInner.GetAttributeNodeNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn) { + return mInner.SetAttributeNodeNS(aNewAttr, aReturn); + } + NS_IMETHOD GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) { + return mInner.GetElementsByTagNameNS(aNamespaceURI, aLocalName, aReturn); + } + NS_IMETHOD HasAttribute(const nsString& aName, PRBool* aReturn) { + return HasAttribute(aName, aReturn); + } + NS_IMETHOD HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) { + return mInner.HasAttributeNS(aNamespaceURI, aLocalName, aReturn); + } // nsIDOMHTMLElement NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner) diff --git a/rdf/content/src/nsXULDocument.h b/rdf/content/src/nsXULDocument.h index 48de7504d47..c11b52b06a9 100644 --- a/rdf/content/src/nsXULDocument.h +++ b/rdf/content/src/nsXULDocument.h @@ -402,6 +402,12 @@ public: NS_IMETHOD GetAttributeStyleSheet(nsIHTMLStyleSheet** aResult); NS_IMETHOD GetInlineStyleSheet(nsIHTMLCSSStyleSheet** aResult); + static nsresult + GetElementsByTagName(nsIContent* aContent, + const nsString& aTagName, + PRInt32 aNamespaceID, + nsRDFDOMNodeList* aElements); + protected: // Implementation methods friend nsresult @@ -431,12 +437,6 @@ protected: nsIContent* aElement, void* aClosure); - static nsresult - GetElementsByTagName(nsIContent* aContent, - const nsString& aTagName, - PRInt32 aNamespaceID, - nsRDFDOMNodeList* aElements); - static nsresult GetElementsByAttribute(nsIDOMNode* aNode, const nsString& aAttribute, diff --git a/rdf/content/src/nsXULElement.cpp b/rdf/content/src/nsXULElement.cpp index 0f53821c771..99892a8d79b 100644 --- a/rdf/content/src/nsXULElement.cpp +++ b/rdf/content/src/nsXULElement.cpp @@ -117,6 +117,7 @@ #include "nsXULRadioElement.h" #include "nsXULRadioGroupElement.h" #include "nsXULMenuListElement.h" +#include "nsXULDocument.h" #include "prlog.h" #include "rdf.h" @@ -1577,6 +1578,180 @@ nsXULElement::GetElementsByTagName(const nsString& aName, nsIDOMNodeList** aRetu return NS_OK; } +NS_IMETHODIMP +nsXULElement::GetAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, nsString& aReturn) +{ + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + aReturn.Truncate(); + return NS_OK; + } + + GetAttribute(nsid, name, aReturn); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::SetAttributeNS(const nsString& aNamespaceURI, + const nsString& aQualifiedName, + const nsString& aValue) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsXULElement::RemoveAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName) +{ + PRInt32 nameSpaceId; + nsCOMPtr tag = dont_AddRef(NS_NewAtom(aLocalName)); + + if (!aNamespaceURI.EqualsWithConversion("*")) { + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nameSpaceId); + + if (nameSpaceId == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + return NS_OK; + } + } + + nsresult rv = UnsetAttribute(nameSpaceId, tag, PR_TRUE); + NS_ASSERTION(NS_SUCCEEDED(rv), "unable to remove attribute"); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::GetAttributeNodeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMAttr** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsresult rv; + + nsCOMPtr map; + rv = GetAttributes(getter_AddRefs(map)); + if (NS_FAILED(rv)) return rv; + + nsCOMPtr node; + rv = map->GetNamedItemNS(aNamespaceURI, aLocalName, getter_AddRefs(node)); + if (NS_FAILED(rv)) return rv; + + if (node) { + rv = node->QueryInterface(NS_GET_IID(nsIDOMAttr), (void**) aReturn); + } + else { + *aReturn = nsnull; + rv = NS_OK; + } + + return rv; +} + +NS_IMETHODIMP +nsXULElement::SetAttributeNodeNS(nsIDOMAttr* aNewAttr, + nsIDOMAttr** aReturn) +{ + NS_NOTYETIMPLEMENTED("write me!"); + return NS_ERROR_NOT_IMPLEMENTED; +} + +NS_IMETHODIMP +nsXULElement::GetElementsByTagNameNS(const nsString& aNamespaceURI, + const nsString& aLocalName, + nsIDOMNodeList** aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + PRInt32 nameSpaceId = kNameSpaceID_Unknown; + + nsRDFDOMNodeList* elements; + nsresult rv = nsRDFDOMNodeList::Create(&elements); + NS_ENSURE_SUCCESS(rv, rv); + + nsCOMPtr kungFuGrip; + kungFuGrip = dont_AddRef(NS_STATIC_CAST(nsIDOMNodeList *, elements)); + + if (!aNamespaceURI.EqualsWithConversion("*")) { + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nameSpaceId); + + if (nameSpaceId == kNameSpaceID_Unknown) { + // Unkonwn namespace means no matches, we return an empty list... + + *aReturn = elements; + NS_ADDREF(*aReturn); + + return NS_OK; + } + } + + rv = nsXULDocument::GetElementsByTagName(NS_STATIC_CAST(nsIStyledContent *, + this), aLocalName, + nameSpaceId, elements); + NS_ENSURE_SUCCESS(rv, rv); + + *aReturn = elements; + NS_ADDREF(*aReturn); + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::HasAttribute(const nsString& aName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name; + PRInt32 nsid; + + nsresult rv = ParseAttributeString(aName, *getter_AddRefs(name), nsid); + NS_ENSURE_SUCCESS(rv, rv); + + nsAutoString tmp; + rv = GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + +NS_IMETHODIMP +nsXULElement::HasAttributeNS(const nsString& aNamespaceURI, + const nsString& aLocalName, PRBool* aReturn) +{ + NS_ENSURE_ARG_POINTER(aReturn); + + nsCOMPtr name(dont_AddRef(NS_NewAtom(aLocalName))); + PRInt32 nsid; + + gNameSpaceManager->GetNameSpaceID(aNamespaceURI, nsid); + + if (nsid == kNameSpaceID_Unknown) { + // Unkonwn namespace means no attr... + + *aReturn = PR_FALSE; + return NS_OK; + } + + nsAutoString tmp; + nsresult rv = GetAttribute(nsid, name, tmp); + + *aReturn = rv == NS_CONTENT_ATTR_NOT_THERE ? PR_FALSE : PR_TRUE; + + return NS_OK; +} + NS_IMETHODIMP nsXULElement::GetElementsByAttribute(const nsString& aAttribute, const nsString& aValue,