Bug 957652 - Replace the Attr element getters by something that returns an Element; r=bzbarsky
authorEhsan Akhgari <ehsan.akhgari@gmail.com>
Thu, 09 Jan 2014 09:07:22 -0500
changeset 178706 9d405c64a7bf0e5ce7bf8c11379bdbd29ee28526
parent 178705 434667e5fdeece1c6e8e0287eb0762cdb0a9831e
child 178707 92efd61cfca57a72d9a9a037b6d5316732530335
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbzbarsky
bugs957652
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 957652 - Replace the Attr element getters by something that returns an Element; r=bzbarsky
content/base/public/nsIAttribute.h
content/base/src/Attr.cpp
content/base/src/Attr.h
content/base/src/nsINode.cpp
dom/xslt/xpath/nsXPathResult.cpp
dom/xslt/xpath/txMozillaXPathTreeWalker.cpp
--- a/content/base/public/nsIAttribute.h
+++ b/content/base/public/nsIAttribute.h
@@ -7,18 +7,18 @@
 #define nsIAttribute_h___
 
 #include "nsINode.h"
 
 class nsDOMAttributeMap;
 class nsIContent;
 
 #define NS_IATTRIBUTE_IID  \
-{ 0x8d9d7dbf, 0xc42d, 0x4715, \
-  { 0x95, 0xcf, 0x7a, 0x5e, 0xd5, 0xa4, 0x47, 0x70 } }
+{ 0x727dc139, 0xf516, 0x46ff, \
+  { 0x86, 0x11, 0x18, 0xea, 0xee, 0x4a, 0x3e, 0x6a } }
 
 class nsIAttribute : public nsINode
 {
 public:
   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IATTRIBUTE_IID)
 
   virtual void SetMap(nsDOMAttributeMap *aMap) = 0;
   
@@ -27,18 +27,16 @@ public:
     return mAttrMap;
   }
 
   nsINodeInfo *NodeInfo() const
   {
     return mNodeInfo;
   }
 
-  virtual nsIContent* GetContent() const = 0;
-
   /**
    * Called when our ownerElement is moved into a new document.
    * Updates the nodeinfo of this node.
    */
   virtual nsresult SetOwnerDocument(nsIDocument* aDocument) = 0;
 
 protected:
 #ifdef MOZILLA_INTERNAL_API
--- a/content/base/src/Attr.cpp
+++ b/content/base/src/Attr.cpp
@@ -72,17 +72,17 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
 NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(Attr)
 
 NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(Attr)
   nsINode::Unlink(tmp);
   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAttrMap)
 NS_IMPL_CYCLE_COLLECTION_UNLINK_END
 
 NS_IMPL_CYCLE_COLLECTION_CAN_SKIP_BEGIN(Attr)
-  Element* ownerElement = tmp->GetContentInternal();
+  Element* ownerElement = tmp->GetElement();
   if (tmp->IsBlack()) {
     if (ownerElement) {
       // The attribute owns the element via attribute map so we can
       // mark it when the attribute is certainly alive.
       mozilla::dom::FragmentOrElement::MarkNodeChildren(ownerElement);
     }
     return true;
   }
@@ -123,26 +123,20 @@ Attr::SetMap(nsDOMAttributeMap *aMap)
     // We're breaking a relationship with content and not getting a new one,
     // need to locally cache value. GetValue() does that.
     GetValue(mValue);
   }
 
   mAttrMap = aMap;
 }
 
-nsIContent*
-Attr::GetContent() const
-{
-  return GetContentInternal();
-}
-
 Element*
 Attr::GetElement() const
 {
-  nsIContent* content = GetContent();
+  nsIContent* content = mAttrMap ? mAttrMap->GetContent() : nullptr;
   return content ? content->AsElement() : nullptr;
 }
 
 nsresult
 Attr::SetOwnerDocument(nsIDocument* aDocument)
 {
   NS_ASSERTION(aDocument, "Missing document");
 
@@ -183,32 +177,32 @@ Attr::GetNameAtom(nsIContent* aContent)
   }
   nsCOMPtr<nsIAtom> nameAtom = mNodeInfo->NameAtom();
   return nameAtom.forget();
 }
 
 NS_IMETHODIMP
 Attr::GetValue(nsAString& aValue)
 {
-  nsIContent* content = GetContentInternal();
+  nsIContent* content = GetElement();
   if (content) {
     nsCOMPtr<nsIAtom> nameAtom = GetNameAtom(content);
     content->GetAttr(mNodeInfo->NamespaceID(), nameAtom, aValue);
   }
   else {
     aValue = mValue;
   }
 
   return NS_OK;
 }
 
 void
 Attr::SetValue(const nsAString& aValue, ErrorResult& aRv)
 {
-  nsIContent* content = GetContentInternal();
+  nsIContent* content = GetElement();
   if (!content) {
     mValue = aValue;
     return;
   }
 
   nsCOMPtr<nsIAtom> nameAtom = GetNameAtom(content);
   aRv = content->SetAttr(mNodeInfo->NamespaceID(),
                          nameAtom,
@@ -271,17 +265,17 @@ Attr::Clone(nsINodeInfo *aNodeInfo, nsIN
   NS_ADDREF(*aResult);
 
   return NS_OK;
 }
 
 already_AddRefed<nsIURI>
 Attr::GetBaseURI() const
 {
-  nsINode *parent = GetContentInternal();
+  nsINode *parent = GetElement();
 
   return parent ? parent->GetBaseURI() : nullptr;
 }
 
 void
 Attr::GetTextContentInternal(nsAString& aTextContent)
 {
   OwnerDoc()->WarnOnceAbout(nsIDocument::eTextContent);
@@ -296,17 +290,17 @@ Attr::SetTextContentInternal(const nsASt
   OwnerDoc()->WarnOnceAbout(nsIDocument::eTextContent);
 
   SetNodeValueInternal(aTextContent, aError);
 }
 
 NS_IMETHODIMP
 Attr::GetIsId(bool* aReturn)
 {
-  nsIContent* content = GetContentInternal();
+  nsIContent* content = GetElement();
   if (!content)
   {
     *aReturn = false;
     return NS_OK;
   }
 
   nsIAtom* idAtom = content->GetIDAttributeName();
   if (!idAtom)
@@ -382,16 +376,10 @@ Attr::Shutdown()
 }
 
 JSObject*
 Attr::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aScope)
 {
   return AttrBinding::Wrap(aCx, aScope, this);
 }
 
-Element*
-Attr::GetContentInternal() const
-{
-  return mAttrMap ? mAttrMap->GetContent() : nullptr;
-}
-
 } // namespace dom
 } // namespace mozilla
--- a/content/base/src/Attr.h
+++ b/content/base/src/Attr.h
@@ -49,17 +49,16 @@ public:
 
   // nsIDOMAttr interface
   NS_DECL_NSIDOMATTR
 
   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
 
   // nsIAttribute interface
   void SetMap(nsDOMAttributeMap *aMap) MOZ_OVERRIDE;
-  nsIContent *GetContent() const MOZ_OVERRIDE;
   Element *GetElement() const;
   nsresult SetOwnerDocument(nsIDocument* aDocument) MOZ_OVERRIDE;
 
   // nsINode interface
   virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE;
   virtual uint32_t GetChildCount() const MOZ_OVERRIDE;
   virtual nsIContent *GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE;
   virtual nsIContent * const * GetChildArray(uint32_t* aChildCount) const MOZ_OVERRIDE;
@@ -91,24 +90,23 @@ public:
 
   // XPCOM GetNamespaceURI() is OK
   // XPCOM GetPrefix() is OK
   // XPCOM GetLocalName() is OK
 
 protected:
   virtual Element* GetNameSpaceElement()
   {
-    return GetContentInternal();
+    return GetElement();
   }
 
   static bool sInitialized;
 
 private:
   already_AddRefed<nsIAtom> GetNameAtom(nsIContent* aContent);
-  Element* GetContentInternal() const;
 
   nsString mValue;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif /* mozilla_dom_Attr_h */
--- a/content/base/src/nsINode.cpp
+++ b/content/base/src/nsINode.cpp
@@ -769,30 +769,30 @@ nsINode::CompareDocumentPosition(nsINode
     return static_cast<uint16_t>(nsIDOMNode::DOCUMENT_POSITION_FOLLOWING);
   }
 
   nsAutoTArray<const nsINode*, 32> parents1, parents2;
 
   const nsINode *node1 = &aOtherNode, *node2 = this;
 
   // Check if either node is an attribute
-  const nsIAttribute* attr1 = nullptr;
+  const Attr* attr1 = nullptr;
   if (node1->IsNodeOfType(nsINode::eATTRIBUTE)) {
-    attr1 = static_cast<const nsIAttribute*>(node1);
-    const nsIContent* elem = attr1->GetContent();
+    attr1 = static_cast<const Attr*>(node1);
+    const nsIContent* elem = attr1->GetElement();
     // If there is an owner element add the attribute
     // to the chain and walk up to the element
     if (elem) {
       node1 = elem;
       parents1.AppendElement(attr1);
     }
   }
   if (node2->IsNodeOfType(nsINode::eATTRIBUTE)) {
-    const nsIAttribute* attr2 = static_cast<const nsIAttribute*>(node2);
-    const nsIContent* elem = attr2->GetContent();
+    const Attr* attr2 = static_cast<const Attr*>(node2);
+    const nsIContent* elem = attr2->GetElement();
     if (elem == node1 && attr1) {
       // Both nodes are attributes on the same element.
       // Compare position between the attributes.
 
       uint32_t i;
       const nsAttrName* attrName;
       for (i = 0; (attrName = elem->GetAttrNameAt(i)); ++i) {
         if (attrName->Equals(attr1->NodeInfo())) {
--- a/dom/xslt/xpath/nsXPathResult.cpp
+++ b/dom/xslt/xpath/nsXPathResult.cpp
@@ -2,18 +2,18 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsXPathResult.h"
 #include "txExprResult.h"
 #include "txNodeSet.h"
 #include "nsError.h"
+#include "mozilla/dom/Attr.h"
 #include "mozilla/dom/Element.h"
-#include "nsIAttribute.h"
 #include "nsDOMClassInfoID.h"
 #include "nsIDOMNode.h"
 #include "nsIDOMDocument.h"
 #include "nsDOMString.h"
 #include "txXPathTreeWalker.h"
 #include "nsCycleCollectionParticipant.h"
 
 using namespace mozilla::dom;
@@ -357,17 +357,17 @@ nsXPathResult::Invalidate(const nsIConte
         // invalidation should happen.
         nsIContent* ctxBindingParent = nullptr;
         if (contextNode->IsNodeOfType(nsINode::eCONTENT)) {
             ctxBindingParent =
                 static_cast<nsIContent*>(contextNode.get())
                     ->GetBindingParent();
         } else if (contextNode->IsNodeOfType(nsINode::eATTRIBUTE)) {
             nsIContent* parent =
-              static_cast<nsIAttribute*>(contextNode.get())->GetContent();
+              static_cast<Attr*>(contextNode.get())->GetElement();
             if (parent) {
                 ctxBindingParent = parent->GetBindingParent();
             }
         }
         if (ctxBindingParent != aChangeRoot->GetBindingParent()) {
           return;
         }
     }
--- a/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp
+++ b/dom/xslt/xpath/txMozillaXPathTreeWalker.cpp
@@ -16,20 +16,23 @@
 #include "nsReadableUtils.h"
 #include "nsString.h"
 #include "nsTextFragment.h"
 #include "txXMLUtils.h"
 #include "txLog.h"
 #include "nsUnicharUtils.h"
 #include "nsAttrName.h"
 #include "nsTArray.h"
+#include "mozilla/dom/Attr.h"
 #include "mozilla/dom/Element.h"
 #include <stdint.h>
 #include <algorithm>
 
+using mozilla::dom::Attr;
+
 const uint32_t kUnknownIndex = uint32_t(-1);
 
 txXPathTreeWalker::txXPathTreeWalker(const txXPathTreeWalker& aOther)
     : mPosition(aOther.mPosition),
       mCurrentIndex(aOther.mCurrentIndex)
 {
 }
 
@@ -685,17 +688,17 @@ txXPathNativeNode::createXPathNode(nsIDO
     uint16_t nodeType;
     aNode->GetNodeType(&nodeType);
 
     if (nodeType == nsIDOMNode::ATTRIBUTE_NODE) {
         nsCOMPtr<nsIAttribute> attr = do_QueryInterface(aNode);
         NS_ASSERTION(attr, "doesn't implement nsIAttribute");
 
         nsINodeInfo *nodeInfo = attr->NodeInfo();
-        nsIContent *parent = attr->GetContent();
+        nsIContent *parent = static_cast<Attr*>(attr.get())->GetElement();
         if (!parent) {
             return nullptr;
         }
 
         nsINode* root = aKeepRootAlive ? txXPathNode::RootOf(parent) : nullptr;
 
         uint32_t i, total = parent->GetAttrCount();
         for (i = 0; i < total; ++i) {