Bug 740766 - dexpcom nsAccessible::GroupPosition, r=surkov, f=tbsaunde
authorMark Capella <markcapella@twcny.rr.com>
Tue, 29 May 2012 20:51:00 -0400
changeset 95237 cf328c06ce2e7ec153d07b9e33742de7764bad57
parent 95236 7f259a56c7c0bfd29b6b8c363a0fd3d50f7287a8
child 95238 05bd3d79b022dc240eeb63d68e0f0e4791ea5495
push id806
push userdcamp@campd.org
push dateThu, 31 May 2012 02:22:50 +0000
treeherderfx-team@fccdf5c4feda [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssurkov
bugs740766
milestone15.0a1
Bug 740766 - dexpcom nsAccessible::GroupPosition, r=surkov, f=tbsaunde
accessible/src/generic/Accessible.cpp
accessible/src/generic/Accessible.h
accessible/src/generic/ApplicationAccessible.cpp
accessible/src/generic/ApplicationAccessible.h
accessible/src/msaa/AccessibleWrap.cpp
accessible/src/xul/nsXULTreeAccessible.cpp
accessible/src/xul/nsXULTreeAccessible.h
--- a/accessible/src/generic/Accessible.cpp
+++ b/accessible/src/generic/Accessible.cpp
@@ -1263,20 +1263,19 @@ Accessible::GetAttributes(nsIPersistentP
     attributes->SetStringProperty(NS_LITERAL_CSTRING("valuetext"), valuetext, oldValueUnused);
   }
 
   // Expose checkable object attribute if the accessible has checkable state
   if (State() & states::CHECKABLE)
     nsAccUtils::SetAccAttr(attributes, nsGkAtoms::checkable, NS_LITERAL_STRING("true"));
 
   // Group attributes (level/setsize/posinset)
-  PRInt32 level = 0, posInSet = 0, setSize = 0;
-  rv = GroupPosition(&level, &setSize, &posInSet);
-  if (NS_SUCCEEDED(rv))
-    nsAccUtils::SetAccGroupAttrs(attributes, level, setSize, posInSet);
+  GroupPos groupPos = GroupPosition();
+  nsAccUtils::SetAccGroupAttrs(attributes, groupPos.level,
+                               groupPos.setSize, groupPos.posInSet);
 
   // Expose object attributes from ARIA attributes.
   PRUint32 numAttrs = mContent->GetAttrCount();
   for (PRUint32 count = 0; count < numAttrs; count ++) {
     const nsAttrName *attr = mContent->GetAttrNameAt(count);
     if (attr && attr->NamespaceEquals(kNameSpaceID_None)) {
       nsIAtom *attrAtom = attr->Atom();
       nsDependentAtomString attrStr(attrAtom);
@@ -1417,16 +1416,54 @@ Accessible::GetAttributesInternal(nsIPer
 
   // Expose 'margin-bottom' attribute.
   styleInfo.MarginBottom(value);
   nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::marginBottom, value);
 
   return NS_OK;
 }
 
+GroupPos
+Accessible::GroupPosition()
+{
+  GroupPos groupPos;
+
+  // Get group position from ARIA attributes.
+  nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_level, &groupPos.level);
+  nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_setsize, &groupPos.setSize);
+  nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_posinset, &groupPos.posInSet);
+
+  // If ARIA is missed and the accessible is visible then calculate group
+  // position from hierarchy.
+  if (State() & states::INVISIBLE)
+    return groupPos;
+
+  // Calculate group level if ARIA is missed.
+  if (groupPos.level == 0) {
+    PRInt32 level = GetLevelInternal();
+    if (level != 0)
+      groupPos.level = level;
+  }
+
+  // Calculate position in group and group size if ARIA is missed.
+  if (groupPos.posInSet == 0 || groupPos.setSize == 0) {
+    PRInt32 posInSet = 0, setSize = 0;
+    GetPositionAndSizeInternal(&posInSet, &setSize);
+    if (posInSet != 0 && setSize != 0) {
+      if (groupPos.posInSet == 0)
+        groupPos.posInSet = posInSet;
+
+      if (groupPos.setSize == 0)
+        groupPos.setSize = setSize;
+    }
+  }
+
+  return groupPos;
+}
+
 NS_IMETHODIMP
 Accessible::GroupPosition(PRInt32* aGroupLevel,
                           PRInt32* aSimilarItemsInGroup,
                           PRInt32* aPositionInGroup)
 {
   NS_ENSURE_ARG_POINTER(aGroupLevel);
   *aGroupLevel = 0;
 
@@ -1434,48 +1471,21 @@ Accessible::GroupPosition(PRInt32* aGrou
   *aSimilarItemsInGroup = 0;
 
   NS_ENSURE_ARG_POINTER(aPositionInGroup);
   *aPositionInGroup = 0;
 
   if (IsDefunct())
     return NS_ERROR_FAILURE;
 
-  // Get group position from ARIA attributes.
-  nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_level,
-                           aGroupLevel);
-  nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_posinset,
-                           aPositionInGroup);
-  nsCoreUtils::GetUIntAttr(mContent, nsGkAtoms::aria_setsize,
-                           aSimilarItemsInGroup);
-
-  // If ARIA is missed and the accessible is visible then calculate group
-  // position from hierarchy.
-  if (State() & states::INVISIBLE)
-    return NS_OK;
-
-  // Calculate group level if ARIA is missed.
-  if (*aGroupLevel == 0) {
-    PRInt32 level = GetLevelInternal();
-    if (level != 0)
-      *aGroupLevel = level;
-  }
-
-  // Calculate position in group and group size if ARIA is missed.
-  if (*aSimilarItemsInGroup == 0 || *aPositionInGroup == 0) {
-    PRInt32 posInSet = 0, setSize = 0;
-    GetPositionAndSizeInternal(&posInSet, &setSize);
-    if (posInSet != 0 && setSize != 0) {
-      if (*aPositionInGroup == 0)
-        *aPositionInGroup = posInSet;
-
-      if (*aSimilarItemsInGroup == 0)
-        *aSimilarItemsInGroup = setSize;
-    }
-  }
+  GroupPos groupPos = GroupPosition();
+
+  *aGroupLevel = groupPos.level;
+  *aSimilarItemsInGroup = groupPos.setSize;
+  *aPositionInGroup = groupPos.posInSet;
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
 Accessible::GetState(PRUint32* aState, PRUint32* aExtraState)
 {
   NS_ENSURE_ARG_POINTER(aState);
--- a/accessible/src/generic/Accessible.h
+++ b/accessible/src/generic/Accessible.h
@@ -48,16 +48,28 @@ enum ENameValueFlag {
    *  a) present (not empty): !name.IsEmpty()
    *  b) no name (was missed): name.IsVoid()
    *  c) was left empty by the author on demand: name.IsEmpty() && !name.IsVoid()
    */
  eNameOK,
  eNameFromTooltip // Tooltip was used as a name
 };
 
+/**
+ * Group position (level, position in set and set size).
+ */
+struct GroupPos
+{
+  GroupPos() : level(0), posInSet(0), setSize(0) { }
+
+  PRInt32 level;
+  PRInt32 posInSet;
+  PRInt32 setSize;
+};
+
 } // namespace a11y
 } // namespace mozilla
 
 class nsXULTreeAccessible;
 
 struct nsRect;
 class nsIContent;
 class nsIFrame;
@@ -223,16 +235,22 @@ public:
 
   /**
    * Returns attributes for accessible without explicitly setted ARIA
    * attributes.
    */
   virtual nsresult GetAttributesInternal(nsIPersistentProperties *aAttributes);
 
   /**
+   * Return group position (level, position in set and set size).
+   */
+  virtual mozilla::a11y::GroupPos GroupPosition();
+
+  /**
+  /**
    * Used by ChildAtPoint() method to get direct or deepest child at point.
    */
   enum EWhichChildAtPoint {
     eDirectChild,
     eDeepestChild
   };
 
   /**
--- a/accessible/src/generic/ApplicationAccessible.cpp
+++ b/accessible/src/generic/ApplicationAccessible.cpp
@@ -1,15 +1,15 @@
 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim:expandtab:shiftwidth=4:tabstop=4:
  */
 /* 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 "ApplicationAccessible.h"
 
 #include "nsAccessibilityService.h"
 #include "nsAccUtils.h"
 #include "Relation.h"
 #include "Role.h"
 #include "States.h"
 
@@ -112,28 +112,20 @@ ApplicationAccessible::State()
 NS_IMETHODIMP
 ApplicationAccessible::GetAttributes(nsIPersistentProperties** aAttributes)
 {
   NS_ENSURE_ARG_POINTER(aAttributes);
   *aAttributes = nsnull;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-ApplicationAccessible::GroupPosition(PRInt32* aGroupLevel,
-                                     PRInt32* aSimilarItemsInGroup,
-                                     PRInt32* aPositionInGroup)
+GroupPos
+ApplicationAccessible::GroupPosition()
 {
-  NS_ENSURE_ARG_POINTER(aGroupLevel);
-  *aGroupLevel = 0;
-  NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
-  *aSimilarItemsInGroup = 0;
-  NS_ENSURE_ARG_POINTER(aPositionInGroup);
-  *aPositionInGroup = 0;
-  return NS_OK;
+  return GroupPos();
 }
 
 Accessible*
 ApplicationAccessible::ChildAtPoint(PRInt32 aX, PRInt32 aY,
                                     EWhichChildAtPoint aWhichChild)
 {
   return nsnull;
 }
--- a/accessible/src/generic/ApplicationAccessible.h
+++ b/accessible/src/generic/ApplicationAccessible.h
@@ -11,17 +11,17 @@
 #include "AccessibleWrap.h"
 #include "nsIAccessibleApplication.h"
 
 #include "nsIMutableArray.h"
 #include "nsIXULAppInfo.h"
 
 namespace mozilla {
 namespace a11y {
- 
+
 /**
  * ApplicationAccessible is for the whole application of Mozilla.
  * Only one instance of ApplicationAccessible exists for one Mozilla instance.
  * And this one should be created when Mozilla Startup (if accessibility
  * feature has been enabled) and destroyed when Mozilla Shutdown.
  *
  * All the accessibility objects for toplevel windows are direct children of
  * the ApplicationAccessible instance.
@@ -43,18 +43,16 @@ public:
   NS_SCRIPTABLE NS_IMETHOD GetRootDocument(nsIAccessibleDocument** aRootDocument);
   NS_SCRIPTABLE NS_IMETHOD ScrollTo(PRUint32 aScrollType);
   NS_SCRIPTABLE NS_IMETHOD ScrollToPoint(PRUint32 aCoordinateType, PRInt32 aX, PRInt32 aY);
   NS_SCRIPTABLE NS_IMETHOD GetLanguage(nsAString& aLanguage);
   NS_IMETHOD GetParent(nsIAccessible **aParent);
   NS_IMETHOD GetNextSibling(nsIAccessible **aNextSibling);
   NS_IMETHOD GetPreviousSibling(nsIAccessible **aPreviousSibling);
   NS_IMETHOD GetAttributes(nsIPersistentProperties **aAttributes);
-  NS_IMETHOD GroupPosition(PRInt32 *aGroupLevel, PRInt32 *aSimilarItemsInGroup,
-                           PRInt32 *aPositionInGroup);
   NS_IMETHOD GetBounds(PRInt32 *aX, PRInt32 *aY,
                        PRInt32 *aWidth, PRInt32 *aHeight);
   NS_IMETHOD SetSelected(bool aIsSelected);
   NS_IMETHOD TakeSelection();
   NS_IMETHOD TakeFocus();
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString &aName);
   NS_IMETHOD GetActionDescription(PRUint8 aIndex, nsAString &aDescription);
   NS_IMETHOD DoAction(PRUint8 aIndex);
@@ -63,17 +61,18 @@ public:
   NS_DECL_NSIACCESSIBLEAPPLICATION
 
   // nsAccessNode
   virtual bool Init();
   virtual void Shutdown();
   virtual bool IsPrimaryForNode() const;
 
   // Accessible
-  virtual mozilla::a11y::ENameValueFlag Name(nsString& aName);
+  virtual GroupPos GroupPosition();
+  virtual ENameValueFlag Name(nsString& aName);
   virtual void ApplyARIAState(PRUint64* aState) const;
   virtual void Description(nsString& aDescription);
   virtual void Value(nsString& aValue);
   virtual mozilla::a11y::role NativeRole();
   virtual PRUint64 State();
   virtual PRUint64 NativeState();
   virtual Relation RelationByType(PRUint32 aRelType);
 
--- a/accessible/src/msaa/AccessibleWrap.cpp
+++ b/accessible/src/msaa/AccessibleWrap.cpp
@@ -1175,34 +1175,27 @@ STDMETHODIMP
 AccessibleWrap::get_groupPosition(long *aGroupLevel,
                                   long *aSimilarItemsInGroup,
                                   long *aPositionInGroup)
 {
 __try {
   if (IsDefunct())
     return CO_E_OBJNOTCONNECTED;
 
-  PRInt32 groupLevel = 0;
-  PRInt32 similarItemsInGroup = 0;
-  PRInt32 positionInGroup = 0;
-
-  nsresult rv = GroupPosition(&groupLevel, &similarItemsInGroup,
-                              &positionInGroup);
-  if (NS_FAILED(rv))
-    return GetHRESULT(rv);
+  GroupPos groupPos = GroupPosition();
 
   // Group information for accessibles having level only (like html headings
   // elements) isn't exposed by this method. AT should look for 'level' object
   // attribute.
-  if (!similarItemsInGroup && !positionInGroup)
+  if (!groupPos.setSize && !groupPos.posInSet)
     return S_FALSE;
 
-  *aGroupLevel = groupLevel;
-  *aSimilarItemsInGroup = similarItemsInGroup;
-  *aPositionInGroup = positionInGroup;
+  *aGroupLevel = groupPos.level;
+  *aSimilarItemsInGroup = groupPos.setSize;
+  *aPositionInGroup = groupPos.posInSet;
 
   return S_OK;
 
 } __except(nsAccessNodeWrap::FilterA11yExceptions(::GetExceptionCode(), GetExceptionInformation())) { }
   return E_FAIL;
 }
 
 STDMETHODIMP
--- a/accessible/src/xul/nsXULTreeAccessible.cpp
+++ b/accessible/src/xul/nsXULTreeAccessible.cpp
@@ -892,73 +892,58 @@ nsXULTreeItemAccessibleBase::IsPrimaryFo
 {
   return false;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // nsXULTreeItemAccessibleBase: Accessible public methods
 
 // nsIAccessible::groupPosition
-nsresult
-nsXULTreeItemAccessibleBase::GroupPosition(PRInt32 *aGroupLevel,
-                                           PRInt32 *aSimilarItemsInGroup,
-                                           PRInt32 *aPositionInGroup)
+GroupPos
+nsXULTreeItemAccessibleBase::GroupPosition()
 {
-  NS_ENSURE_ARG_POINTER(aGroupLevel);
-  *aGroupLevel = 0;
-
-  NS_ENSURE_ARG_POINTER(aSimilarItemsInGroup);
-  *aSimilarItemsInGroup = 0;
-
-  NS_ENSURE_ARG_POINTER(aPositionInGroup);
-  *aPositionInGroup = 0;
-
-  if (IsDefunct() || !mTreeView)
-    return NS_ERROR_FAILURE;
+  GroupPos groupPos;
 
   PRInt32 level;
   nsresult rv = mTreeView->GetLevel(mRow, &level);
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_SUCCESS(rv, groupPos);
 
   PRInt32 topCount = 1;
   for (PRInt32 index = mRow - 1; index >= 0; index--) {
     PRInt32 lvl = -1;
     if (NS_SUCCEEDED(mTreeView->GetLevel(index, &lvl))) {
       if (lvl < level)
         break;
 
       if (lvl == level)
         topCount++;
     }
   }
 
   PRInt32 rowCount = 0;
   rv = mTreeView->GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  NS_ENSURE_SUCCESS(rv, groupPos);
 
   PRInt32 bottomCount = 0;
   for (PRInt32 index = mRow + 1; index < rowCount; index++) {
     PRInt32 lvl = -1;
     if (NS_SUCCEEDED(mTreeView->GetLevel(index, &lvl))) {
       if (lvl < level)
         break;
 
       if (lvl == level)
         bottomCount++;
     }
   }
 
-  PRInt32 setSize = topCount + bottomCount;
-  PRInt32 posInSet = topCount;
+  groupPos.level = level + 1;
+  groupPos.setSize = topCount + bottomCount;
+  groupPos.posInSet = topCount;
 
-  *aGroupLevel = level + 1;
-  *aSimilarItemsInGroup = setSize;
-  *aPositionInGroup = posInSet;
-
-  return NS_OK;
+  return groupPos;
 }
 
 PRUint64
 nsXULTreeItemAccessibleBase::NativeState()
 {
   if (!mTreeView)
     return states::DEFUNCT;
 
--- a/accessible/src/xul/nsXULTreeAccessible.h
+++ b/accessible/src/xul/nsXULTreeAccessible.h
@@ -141,28 +141,25 @@ public:
 
   // nsIAccessible
   NS_IMETHOD GetBounds(PRInt32 *aX, PRInt32 *aY,
                        PRInt32 *aWidth, PRInt32 *aHeight);
 
   NS_IMETHOD SetSelected(bool aSelect); 
   NS_IMETHOD TakeFocus();
 
-  NS_IMETHOD GroupPosition(PRInt32 *aGroupLevel,
-                           PRInt32 *aSimilarItemsInGroup,
-                           PRInt32 *aPositionInGroup);
-
   NS_IMETHOD GetActionName(PRUint8 aIndex, nsAString& aName);
   NS_IMETHOD DoAction(PRUint8 aIndex);
 
   // nsAccessNode
   virtual void Shutdown();
   virtual bool IsPrimaryForNode() const;
 
   // Accessible
+  virtual mozilla::a11y::GroupPos GroupPosition();
   virtual PRUint64 NativeState();
   virtual PRInt32 IndexInParent() const;
   virtual Relation RelationByType(PRUint32 aType);
   virtual Accessible* FocusedChild();
 
   // ActionAccessible
   virtual PRUint8 ActionCount();