Bug 1479039 - Move PersistentPropertiesToArray to nsAccUtils. r=Jamie a=jcristau
authorEitan Isaacson <eitan@monotonous.org>
Mon, 12 Nov 2018 16:41:31 +0000
changeset 501347 2da43796c5bd9154f75673dc1ad64e2f0a5d5094
parent 501346 60b4eadd89fc24f010404fc3c542fa60b60e191a
child 501348 e3c4ebd80791657a3ee5523b5a56aebe45936446
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersJamie, jcristau
bugs1479039
milestone64.0
Bug 1479039 - Move PersistentPropertiesToArray to nsAccUtils. r=Jamie a=jcristau In order to send send attributes in BatchData we will need to convert them to an array. Here we factor out the private function that does that and put it in nsAccUtils. Differential Revision: https://phabricator.services.mozilla.com/D11211
accessible/base/nsAccUtils.cpp
accessible/base/nsAccUtils.h
accessible/ipc/other/DocAccessibleChild.cpp
accessible/ipc/other/DocAccessibleChild.h
--- a/accessible/base/nsAccUtils.cpp
+++ b/accessible/base/nsAccUtils.cpp
@@ -13,16 +13,17 @@
 #include "HyperTextAccessible.h"
 #include "nsIAccessibleTypes.h"
 #include "Role.h"
 #include "States.h"
 #include "TextLeafAccessible.h"
 
 #include "nsIDOMXULContainerElement.h"
 #include "nsIPersistentProperties2.h"
+#include "mozilla/a11y/PDocAccessibleChild.h"
 #include "mozilla/dom/Element.h"
 
 using namespace mozilla;
 using namespace mozilla::a11y;
 
 void
 nsAccUtils::GetAccAttr(nsIPersistentProperties *aAttributes,
                        nsAtom *aAttrName, nsAString& aAttrValue)
@@ -452,8 +453,42 @@ nsAccUtils::MustPrune(Accessible* aAcces
       role == roles::GRAPHIC ||
       role == roles::PROGRESSBAR ||
       role == roles::SEPARATOR
      ) &&
      aAccessible->ContentChildCount() == 1 &&
      aAccessible->ContentChildAt(0)->IsTextLeaf()
     );
 }
+
+bool
+nsAccUtils::PersistentPropertiesToArray(nsIPersistentProperties* aProps,
+                                        nsTArray<Attribute>* aAttributes)
+{
+  if (!aProps) {
+    return true;
+  }
+  nsCOMPtr<nsISimpleEnumerator> propEnum;
+  nsresult rv = aProps->Enumerate(getter_AddRefs(propEnum));
+  NS_ENSURE_SUCCESS(rv, false);
+
+  bool hasMore;
+  while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
+    nsCOMPtr<nsISupports> sup;
+    rv = propEnum->GetNext(getter_AddRefs(sup));
+    NS_ENSURE_SUCCESS(rv, false);
+
+    nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup));
+    NS_ENSURE_TRUE(propElem, false);
+
+    nsAutoCString name;
+    rv = propElem->GetKey(name);
+    NS_ENSURE_SUCCESS(rv, false);
+
+    nsAutoString value;
+    rv = propElem->GetValue(value);
+    NS_ENSURE_SUCCESS(rv, false);
+
+    aAttributes->AppendElement(Attribute(name, value));
+    }
+
+  return true;
+}
--- a/accessible/base/nsAccUtils.h
+++ b/accessible/base/nsAccUtils.h
@@ -20,16 +20,17 @@ namespace mozilla {
 namespace dom {
 class Element;
 }
 
 namespace a11y {
 
 class HyperTextAccessible;
 class DocAccessible;
+class Attribute;
 
 class nsAccUtils
 {
 public:
   /**
    * Returns value of attribute from the given attributes container.
    *
    * @param aAttributes - attributes container
@@ -248,14 +249,18 @@ public:
     return aState | extraState;
   }
 
   /**
    * Return true if the given accessible can't have children. Used when exposing
    * to platform accessibility APIs, should the children be pruned off?
    */
   static bool MustPrune(Accessible* aAccessible);
+
+  static bool PersistentPropertiesToArray(nsIPersistentProperties* aProps,
+                                          nsTArray<Attribute>* aAttributes);
+
 };
 
 } // namespace a11y
 } // namespace mozilla
 
 #endif
--- a/accessible/ipc/other/DocAccessibleChild.cpp
+++ b/accessible/ipc/other/DocAccessibleChild.cpp
@@ -163,56 +163,22 @@ DocAccessibleChild::RecvDescription(cons
 mozilla::ipc::IPCResult
 DocAccessibleChild::RecvAttributes(const uint64_t& aID, nsTArray<Attribute>* aAttributes)
 {
   Accessible* acc = IdToAccessible(aID);
   if (!acc)
     return IPC_OK();
 
   nsCOMPtr<nsIPersistentProperties> props = acc->Attributes();
-  if (!PersistentPropertiesToArray(props, aAttributes)) {
+  if (!nsAccUtils::PersistentPropertiesToArray(props, aAttributes)) {
     return IPC_FAIL_NO_REASON(this);
   }
   return IPC_OK();
 }
 
-bool
-DocAccessibleChild::PersistentPropertiesToArray(nsIPersistentProperties* aProps,
-                                                nsTArray<Attribute>* aAttributes)
-{
-  if (!aProps) {
-    return true;
-  }
-  nsCOMPtr<nsISimpleEnumerator> propEnum;
-  nsresult rv = aProps->Enumerate(getter_AddRefs(propEnum));
-  NS_ENSURE_SUCCESS(rv, false);
-
-  bool hasMore;
-  while (NS_SUCCEEDED(propEnum->HasMoreElements(&hasMore)) && hasMore) {
-    nsCOMPtr<nsISupports> sup;
-    rv = propEnum->GetNext(getter_AddRefs(sup));
-    NS_ENSURE_SUCCESS(rv, false);
-
-    nsCOMPtr<nsIPropertyElement> propElem(do_QueryInterface(sup));
-    NS_ENSURE_TRUE(propElem, false);
-
-    nsAutoCString name;
-    rv = propElem->GetKey(name);
-    NS_ENSURE_SUCCESS(rv, false);
-
-    nsAutoString value;
-    rv = propElem->GetValue(value);
-    NS_ENSURE_SUCCESS(rv, false);
-
-    aAttributes->AppendElement(Attribute(name, value));
-    }
-
-  return true;
-}
-
 mozilla::ipc::IPCResult
 DocAccessibleChild::RecvRelationByType(const uint64_t& aID,
                                        const uint32_t& aType,
                                        nsTArray<uint64_t>* aTargets)
 {
   Accessible* acc = IdToAccessible(aID);
   if (!acc)
     return IPC_OK();
@@ -469,33 +435,33 @@ DocAccessibleChild::RecvTextAttributes(c
 {
   HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
   if (!acc || !acc->IsTextRole()) {
     return IPC_OK();
   }
 
   nsCOMPtr<nsIPersistentProperties> props =
     acc->TextAttributes(aIncludeDefAttrs, aOffset, aStartOffset, aEndOffset);
-  if (!PersistentPropertiesToArray(props, aAttributes)) {
+  if (!nsAccUtils::PersistentPropertiesToArray(props, aAttributes)) {
     return IPC_FAIL_NO_REASON(this);
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 DocAccessibleChild::RecvDefaultTextAttributes(const uint64_t& aID,
                                               nsTArray<Attribute> *aAttributes)
 {
   HyperTextAccessible* acc = IdToHyperTextAccessible(aID);
   if (!acc || !acc->IsTextRole()) {
     return IPC_OK();
   }
 
   nsCOMPtr<nsIPersistentProperties> props = acc->DefaultTextAttributes();
-  if (!PersistentPropertiesToArray(props, aAttributes)) {
+  if (!nsAccUtils::PersistentPropertiesToArray(props, aAttributes)) {
     return IPC_FAIL_NO_REASON(this);
   }
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
 DocAccessibleChild::RecvTextBounds(const uint64_t& aID,
                                    const int32_t& aStartOffset,
--- a/accessible/ipc/other/DocAccessibleChild.h
+++ b/accessible/ipc/other/DocAccessibleChild.h
@@ -481,17 +481,14 @@ private:
   Accessible* IdToAccessible(const uint64_t& aID) const;
   Accessible* IdToAccessibleLink(const uint64_t& aID) const;
   Accessible* IdToAccessibleSelect(const uint64_t& aID) const;
   HyperTextAccessible* IdToHyperTextAccessible(const uint64_t& aID) const;
   TextLeafAccessible* IdToTextLeafAccessible(const uint64_t& aID) const;
   ImageAccessible* IdToImageAccessible(const uint64_t& aID) const;
   TableCellAccessible* IdToTableCellAccessible(const uint64_t& aID) const;
   TableAccessible* IdToTableAccessible(const uint64_t& aID) const;
-
-  bool PersistentPropertiesToArray(nsIPersistentProperties* aProps,
-                                   nsTArray<Attribute>* aAttributes);
 };
 
 }
 }
 
 #endif