diff --git a/content/base/public/nsIAttribute.h b/content/base/public/nsIAttribute.h index edfaed14f242..937c276460dd 100644 --- a/content/base/public/nsIAttribute.h +++ b/content/base/public/nsIAttribute.h @@ -46,8 +46,8 @@ class nsDOMAttributeMap; class nsIContent; #define NS_IATTRIBUTE_IID \ -{ 0x9bb7e4f2, 0xf89d, 0x46ee, \ - { 0xa4, 0x62, 0x68, 0xcb, 0x0b, 0xf5, 0x71, 0x53 } } +{ 0x0330a680, 0x6b05, 0x453b, \ + { 0x84, 0x7a, 0xb0, 0x6c, 0x9c, 0x5d, 0x08, 0x85 } } class nsIAttribute : public nsINode { @@ -76,13 +76,15 @@ public: protected: #ifdef MOZILLA_INTERNAL_API - nsIAttribute(nsDOMAttributeMap *aAttrMap, already_AddRefed aNodeInfo) - : nsINode(aNodeInfo), mAttrMap(aAttrMap) + nsIAttribute(nsDOMAttributeMap *aAttrMap, already_AddRefed aNodeInfo, + PRBool aNsAware) + : nsINode(aNodeInfo), mAttrMap(aAttrMap), mNsAware(aNsAware) { } #endif //MOZILLA_INTERNAL_API nsDOMAttributeMap *mAttrMap; // WEAK + PRBool mNsAware; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIAttribute, NS_IATTRIBUTE_IID) diff --git a/content/base/src/nsDOMAttribute.cpp b/content/base/src/nsDOMAttribute.cpp index 627a7586956b..c9fc9940e168 100644 --- a/content/base/src/nsDOMAttribute.cpp +++ b/content/base/src/nsDOMAttribute.cpp @@ -67,8 +67,8 @@ PRBool nsDOMAttribute::sInitialized; nsDOMAttribute::nsDOMAttribute(nsDOMAttributeMap *aAttrMap, already_AddRefed aNodeInfo, - const nsAString &aValue) - : nsIAttribute(aAttrMap, aNodeInfo), mValue(aValue), mChild(nsnull) + const nsAString &aValue, PRBool aNsAware) + : nsIAttribute(aAttrMap, aNodeInfo, aNsAware), mValue(aValue), mChild(nsnull) { NS_ABORT_IF_FALSE(mNodeInfo, "We must get a nodeinfo here!"); @@ -214,7 +214,8 @@ already_AddRefed nsDOMAttribute::GetNameAtom(nsIContent* aContent) { nsIAtom* result = nsnull; - if (mNodeInfo->NamespaceID() == kNameSpaceID_None && + if (!mNsAware && + mNodeInfo->NamespaceID() == kNameSpaceID_None && aContent->IsInHTMLDocument() && aContent->IsHTML()) { nsAutoString name; @@ -434,7 +435,7 @@ nsDOMAttribute::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const const_cast(this)->GetValue(value); nsCOMPtr ni = aNodeInfo; - *aResult = new nsDOMAttribute(nsnull, ni.forget(), value); + *aResult = new nsDOMAttribute(nsnull, ni.forget(), value, mNsAware); if (!*aResult) { return NS_ERROR_OUT_OF_MEMORY; } diff --git a/content/base/src/nsDOMAttribute.h b/content/base/src/nsDOMAttribute.h index 19aa7f163fda..cd9192606ad9 100644 --- a/content/base/src/nsDOMAttribute.h +++ b/content/base/src/nsDOMAttribute.h @@ -65,7 +65,8 @@ class nsDOMAttribute : public nsIAttribute, public: nsDOMAttribute(nsDOMAttributeMap* aAttrMap, already_AddRefed aNodeInfo, - const nsAString& aValue); + const nsAString& aValue, + PRBool aNsAware); virtual ~nsDOMAttribute(); NS_DECL_CYCLE_COLLECTING_ISUPPORTS diff --git a/content/base/src/nsDOMAttributeMap.cpp b/content/base/src/nsDOMAttributeMap.cpp index c8de7a52590c..83ab3a437542 100644 --- a/content/base/src/nsDOMAttributeMap.cpp +++ b/content/base/src/nsDOMAttributeMap.cpp @@ -181,7 +181,7 @@ nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn) mContent->GetAttr(aNodeInfo->NamespaceID(), aNodeInfo->NameAtom(), value); nsCOMPtr ni = aNodeInfo; nsCOMPtr newAttr = - new nsDOMAttribute(nsnull, ni.forget(), value); + new nsDOMAttribute(nsnull, ni.forget(), value, PR_TRUE); if (!newAttr) { return NS_ERROR_OUT_OF_MEMORY; } @@ -201,7 +201,7 @@ nsDOMAttributeMap::RemoveAttribute(nsINodeInfo* aNodeInfo, nsIDOMNode** aReturn) } nsDOMAttribute* -nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo) +nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo, PRBool aNsAware) { NS_ASSERTION(aNodeInfo, "GetAttribute() called with aNodeInfo == nsnull!"); @@ -211,7 +211,7 @@ nsDOMAttributeMap::GetAttribute(nsINodeInfo* aNodeInfo) if (!node) { nsCOMPtr ni = aNodeInfo; nsRefPtr newAttr = - new nsDOMAttribute(this, ni.forget(), EmptyString()); + new nsDOMAttribute(this, ni.forget(), EmptyString(), aNsAware); if (newAttr && mAttributeCache.Put(attr, newAttr)) { node = newAttr; } @@ -229,7 +229,7 @@ nsDOMAttributeMap::GetNamedItem(const nsAString& aAttrName, nsresult *aResult) nsCOMPtr ni = mContent->GetExistingAttrNameFromQName(aAttrName); if (ni) { - return GetAttribute(ni); + return GetAttribute(ni, PR_FALSE); } } @@ -384,7 +384,7 @@ nsDOMAttributeMap::RemoveNamedItem(const nsAString& aName, return NS_ERROR_DOM_NOT_FOUND_ERR; } - NS_ADDREF(*aReturn = GetAttribute(ni)); + NS_ADDREF(*aReturn = GetAttribute(ni, PR_TRUE)); // This removes the attribute node from the attribute map. rv = mContent->UnsetAttr(ni->NamespaceID(), ni->NameAtom(), PR_TRUE); @@ -409,7 +409,7 @@ nsDOMAttributeMap::GetItemAt(PRUint32 aIndex, nsresult *aResult) ni = mContent->NodeInfo()->NodeInfoManager()-> GetNodeInfo(name->LocalName(), name->GetPrefix(), name->NamespaceID()); if (ni) { - node = GetAttribute(ni); + node = GetAttribute(ni, PR_TRUE); } else { *aResult = NS_ERROR_OUT_OF_MEMORY; @@ -491,7 +491,7 @@ nsDOMAttributeMap::GetNamedItemNSInternal(const nsAString& aNamespaceURI, return RemoveAttribute(ni, aReturn); } - NS_ADDREF(*aReturn = GetAttribute(ni)); + NS_ADDREF(*aReturn = GetAttribute(ni, PR_TRUE)); return NS_OK; } diff --git a/content/base/src/nsDOMAttributeMap.h b/content/base/src/nsDOMAttributeMap.h index 6df0d352e571..805a53028d77 100644 --- a/content/base/src/nsDOMAttributeMap.h +++ b/content/base/src/nsDOMAttributeMap.h @@ -225,7 +225,7 @@ private: nsIDOMNode** aReturn, PRBool aRemove = PR_FALSE); - nsDOMAttribute* GetAttribute(nsINodeInfo* aNodeInfo); + nsDOMAttribute* GetAttribute(nsINodeInfo* aNodeInfo, PRBool aNsAware); /** * Remove an attribute, returns the removed node. diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index a4955809fdc3..446f1eb8452b 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -4601,7 +4601,7 @@ nsDocument::CreateAttribute(const nsAString& aName, getter_AddRefs(nodeInfo)); NS_ENSURE_SUCCESS(rv, rv); - attribute = new nsDOMAttribute(nsnull, nodeInfo.forget(), value); + attribute = new nsDOMAttribute(nsnull, nodeInfo.forget(), value, PR_FALSE); NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY); return CallQueryInterface(attribute, aReturn); @@ -4624,7 +4624,7 @@ nsDocument::CreateAttributeNS(const nsAString & aNamespaceURI, nsAutoString value; nsDOMAttribute* attribute = - new nsDOMAttribute(nsnull, nodeInfo.forget(), value); + new nsDOMAttribute(nsnull, nodeInfo.forget(), value, PR_TRUE); NS_ENSURE_TRUE(attribute, NS_ERROR_OUT_OF_MEMORY); return CallQueryInterface(attribute, aResult); diff --git a/content/base/test/test_bug469304.html b/content/base/test/test_bug469304.html index 1a6091514502..234e90256027 100644 --- a/content/base/test/test_bug469304.html +++ b/content/base/test/test_bug469304.html @@ -163,6 +163,24 @@ is(node.getAttributeNode('myAttrib').name, "myAttrib", "(10)"); is(node.getAttributeNode('myattrib').name, "myAttrib", "(11)"); is(attrib.name, "myAttrib", "(12)"); +var o = document.createElement("div"); +o.setAttribute("myAttrib","htmlattr"); +o.setAttributeNS("","myAttrib","123"); +is(o.getAttributeNodeNS("","myAttrib").nodeName, "myAttrib", "nodeName should be case-sensitive."); +is(o.getAttributeNode("myAttrib").nodeName, "myattrib", "nodeName shouldn't be case-sensitive."); +is(o.getAttributeNodeNS("","myAttrib").value, "123", "Should have got the case-sensitive attribute."); +is(o.attributes.length, 2, "Should have two attributes."); +o.setAttribute("myAttrib2", "htmlattr"); +o.setAttributeNS("", "myAttrib2", "123"); +is(o.attributes.length, 4, "Should have four attributes."); +var an = o.attributes.removeNamedItem("myAttrib2"); +is(o.attributes.length, 3, "An attribute should have been removed."); +is(an.value, "htmlattr", "The removed attribute should have been the case-insensitive attribute."); +is(o.getAttribute("myAttrib2"), null, "Element shouldn't have case-insensitive attribute anymore."); +var an2 = o.attributes.removeNamedItemNS("", "myAttrib2"); +is(an2.localName, "myAttrib2", "The removed attribute should be case-sensitive."); +is(o.attributes.length, 2, "Element should have two attributes."); +