Bug 765371 - decomtaminate GetSelected-RowCount / ColumnCount / CellCount on accessible tables, r=tbsaunde
authorMark Capella <markcapella@twcny.rr.com>
Wed, 20 Jun 2012 14:05:31 -0400
changeset 99888 01bdb326b1e40cfd1fd9b0f9f152992bcc9ccf40
parent 99887 2bfaccdb27fc87dd8904e8e2c42863ce74f51209
child 99889 bca300e4459c774f54b99acd51b475e1edbf286c
push idunknown
push userunknown
push dateunknown
reviewerstbsaunde
bugs765371
milestone16.0a1
Bug 765371 - decomtaminate GetSelected-RowCount / ColumnCount / CellCount on accessible tables, r=tbsaunde
accessible/src/generic/ARIAGridAccessible.cpp
accessible/src/generic/ARIAGridAccessible.h
accessible/src/html/HTMLTableAccessible.cpp
accessible/src/html/HTMLTableAccessible.h
accessible/src/xpcom/xpcAccessibleTable.cpp
accessible/src/xpcom/xpcAccessibleTable.h
accessible/src/xul/XULListboxAccessible.cpp
accessible/src/xul/XULListboxAccessible.h
accessible/src/xul/XULTreeGridAccessible.cpp
accessible/src/xul/XULTreeGridAccessible.h
--- a/accessible/src/generic/ARIAGridAccessible.cpp
+++ b/accessible/src/generic/ARIAGridAccessible.cpp
@@ -214,70 +214,61 @@ ARIAGridAccessible::IsCellSelected(PRUin
     Accessible* cell = GetCellInRowAt(row, aColIdx);
     if (!cell || !nsAccUtils::IsARIASelected(cell))
       return false;
   }
 
   return true;
 }
 
-NS_IMETHODIMP
-ARIAGridAccessible::GetSelectedCellCount(PRUint32* aCount)
+PRUint32
+ARIAGridAccessible::SelectedCellCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  PRInt32 colCount = 0;
-  GetColumnCount(&colCount);
+  PRUint32 count = 0, colCount = ColCount();
 
   AccIterator rowIter(this, filters::GetRow);
+  Accessible* row = nsnull;
 
-  Accessible* row = nsnull;
   while ((row = rowIter.Next())) {
     if (nsAccUtils::IsARIASelected(row)) {
-      (*aCount) += colCount;
+      count += colCount;
       continue;
     }
 
     AccIterator cellIter(row, filters::GetCell);
     Accessible* cell = nsnull;
 
     while ((cell = cellIter.Next())) {
       if (nsAccUtils::IsARIASelected(cell))
-        (*aCount)++;
+        count++;
     }
   }
 
-  return NS_OK;
+  return count;
 }
 
-NS_IMETHODIMP
-ARIAGridAccessible::GetSelectedColumnCount(PRUint32* aCount)
+PRUint32
+ARIAGridAccessible::SelectedColCount()
 {
-  return GetSelectedColumnsArray(aCount);
+  PRUint32 colCount = 0;
+  GetSelectedColumnsArray(&colCount);
+  return colCount;
 }
 
-NS_IMETHODIMP
-ARIAGridAccessible::GetSelectedRowCount(PRUint32* aCount)
+PRUint32
+ARIAGridAccessible::SelectedRowCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
+  PRUint32 count = 0;
 
   AccIterator rowIter(this, filters::GetRow);
+  Accessible* row = nsnull;
 
-  Accessible* row = nsnull;
   while ((row = rowIter.Next())) {
     if (nsAccUtils::IsARIASelected(row)) {
-      (*aCount)++;
+      count++;
       continue;
     }
 
     AccIterator cellIter(row, filters::GetCell);
     Accessible* cell = cellIter.Next();
     if (!cell)
       continue;
 
@@ -285,20 +276,20 @@ ARIAGridAccessible::GetSelectedRowCount(
     do {
       if (!nsAccUtils::IsARIASelected(cell)) {
         isRowSelected = false;
         break;
       }
     } while ((cell = cellIter.Next()));
 
     if (isRowSelected)
-      (*aCount)++;
+      count++;
   }
 
-  return NS_OK;
+  return count;
 }
 
 NS_IMETHODIMP
 ARIAGridAccessible::GetSelectedCells(nsIArray** aCells)
 {
   NS_ENSURE_ARG_POINTER(aCells);
   *aCells = nsnull;
 
--- a/accessible/src/generic/ARIAGridAccessible.h
+++ b/accessible/src/generic/ARIAGridAccessible.h
@@ -40,16 +40,19 @@ public:
 
   // TableAccessible
   virtual PRUint32 ColCount();
   virtual PRUint32 RowCount();
   virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
   virtual bool IsColSelected(PRUint32 aColIdx);
   virtual bool IsRowSelected(PRUint32 aRowIdx);
   virtual bool IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual PRUint32 SelectedCellCount();
+  virtual PRUint32 SelectedColCount();
+  virtual PRUint32 SelectedRowCount();
   virtual void SelectCol(PRUint32 aColIdx);
   virtual void SelectRow(PRUint32 aRowIdx);
   virtual void UnselectCol(PRUint32 aColIdx);
   virtual void UnselectRow(PRUint32 aRowIdx);
 
 protected:
   /**
    * Return true if the given row index is valid.
--- a/accessible/src/html/HTMLTableAccessible.cpp
+++ b/accessible/src/html/HTMLTableAccessible.cpp
@@ -549,103 +549,70 @@ HTMLTableAccessible::RowCount()
   if (!tableLayout)
     return 0;
 
   PRInt32 rowCount = 0, colCount = 0;
   tableLayout->GetTableSize(rowCount, colCount);
   return rowCount;
 }
 
-NS_IMETHODIMP
-HTMLTableAccessible::GetSelectedCellCount(PRUint32* aCount)
+PRUint32
+HTMLTableAccessible::SelectedCellCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
+  nsITableLayout *tableLayout = GetTableLayout();
+  if (!tableLayout)
+    return 0;
 
-  PRInt32 rowCount = 0;
-  nsresult rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsITableLayout *tableLayout = GetTableLayout();
-  NS_ENSURE_STATE(tableLayout);
+  PRUint32 count = 0, rowCount = RowCount(), colCount = ColCount();
 
   nsCOMPtr<nsIDOMElement> domElement;
   PRInt32 startRowIndex = 0, startColIndex = 0,
     rowSpan, colSpan, actualRowSpan, actualColSpan;
   bool isSelected = false;
 
-  PRInt32 rowIndex;
-  for (rowIndex = 0; rowIndex < rowCount; rowIndex++) {
-    PRInt32 columnIndex;
-    for (columnIndex = 0; columnIndex < columnCount; columnIndex++) {
-      rv = tableLayout->GetCellDataAt(rowIndex, columnIndex,
-                                      *getter_AddRefs(domElement),
-                                      startRowIndex, startColIndex,
-                                      rowSpan, colSpan,
-                                      actualRowSpan, actualColSpan,
-                                      isSelected);
+  for (PRUint32 rowIdx = 0; rowIdx < rowCount; rowIdx++) {
+    for (PRUint32 colIdx = 0; colIdx < colCount; colIdx++) {
+      nsresult rv = tableLayout->GetCellDataAt(rowIdx, colIdx,
+                                               *getter_AddRefs(domElement),
+                                               startRowIndex, startColIndex,
+                                               rowSpan, colSpan,
+                                               actualRowSpan, actualColSpan,
+                                               isSelected);
 
-      if (NS_SUCCEEDED(rv) && startRowIndex == rowIndex &&
-          startColIndex == columnIndex && isSelected) {
-        (*aCount)++;
-      }
+      if (NS_SUCCEEDED(rv) && startRowIndex == rowIdx &&
+          startColIndex == colIdx && isSelected)
+        count++;
     }
   }
 
-  return NS_OK;
+  return count;
 }
 
-NS_IMETHODIMP
-HTMLTableAccessible::GetSelectedColumnCount(PRUint32* aCount)
+PRUint32
+HTMLTableAccessible::SelectedColCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  PRInt32 count = 0;
-  nsresult rv = GetColumnCount(&count);
-  NS_ENSURE_SUCCESS(rv, rv);
+  PRUint32 count = 0, colCount = ColCount();
 
-  PRInt32 index;
-  for (index = 0; index < count; index++) {
-    bool state = false;
-    rv = IsColumnSelected(index, &state);
-    NS_ENSURE_SUCCESS(rv, rv);
+  for (PRUint32 colIdx = 0; colIdx < colCount; colIdx++)
+    if (IsColSelected(colIdx))
+      count++;
 
-    if (state)
-      (*aCount)++;
-  }
-
-  return NS_OK;
+  return count;
 }
 
-NS_IMETHODIMP
-HTMLTableAccessible::GetSelectedRowCount(PRUint32* aCount)
+PRUint32
+HTMLTableAccessible::SelectedRowCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  PRInt32 count = 0;
-  nsresult rv = GetRowCount(&count);
-  NS_ENSURE_SUCCESS(rv, rv);
+  PRUint32 count = 0, rowCount = RowCount();
 
-  PRInt32 index;
-  for (index = 0; index < count; index++) {
-    bool state = false;
-    rv = IsRowSelected(index, &state);
-    NS_ENSURE_SUCCESS(rv, rv);
+  for (PRUint32 rowIdx = 0; rowIdx < rowCount; rowIdx++)
+    if (IsRowSelected(rowIdx))
+      count++;
 
-    if (state)
-      (*aCount)++;
-  }
-
-  return NS_OK;
+  return count;
 }
 
 NS_IMETHODIMP
 HTMLTableAccessible::GetSelectedCells(nsIArray** aCells)
 {
   NS_ENSURE_ARG_POINTER(aCells);
   *aCells = nsnull;
 
--- a/accessible/src/html/HTMLTableAccessible.h
+++ b/accessible/src/html/HTMLTableAccessible.h
@@ -104,16 +104,19 @@ public:
   virtual PRUint32 RowCount();
   virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
   virtual PRInt32 CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx);
   virtual PRUint32 ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
   virtual PRUint32 RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
   virtual bool IsColSelected(PRUint32 aColIdx);
   virtual bool IsRowSelected(PRUint32 aRowIdx);
   virtual bool IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual PRUint32 SelectedCellCount();
+  virtual PRUint32 SelectedColCount();
+  virtual PRUint32 SelectedRowCount();
   virtual void SelectCol(PRUint32 aColIdx);
   virtual void SelectRow(PRUint32 aRowIdx);
   virtual void UnselectCol(PRUint32 aColIdx);
   virtual void UnselectRow(PRUint32 aRowIdx);
   virtual bool IsProbablyLayoutTable();
 
   // nsAccessNode
   virtual void Shutdown();
--- a/accessible/src/xpcom/xpcAccessibleTable.cpp
+++ b/accessible/src/xpcom/xpcAccessibleTable.cpp
@@ -198,16 +198,55 @@ xpcAccessibleTable::IsCellSelected(PRInt
       aColIdx < 0 || static_cast<PRUint32>(aColIdx) >= mTable->ColCount())
     return NS_ERROR_INVALID_ARG;
 
   *aIsSelected = mTable->IsCellSelected(aRowIdx, aColIdx);
   return NS_OK;
 }
 
 nsresult
+xpcAccessibleTable::GetSelectedCellCount(PRUint32* aSelectedCellCount)
+{
+  NS_ENSURE_ARG_POINTER(aSelectedCellCount);
+  *aSelectedCellCount = 0;
+
+  if (!mTable)
+    return NS_ERROR_FAILURE;
+
+  *aSelectedCellCount = mTable->SelectedCellCount();
+  return NS_OK;
+}
+
+nsresult
+xpcAccessibleTable::GetSelectedColumnCount(PRUint32* aSelectedColumnCount)
+{
+  NS_ENSURE_ARG_POINTER(aSelectedColumnCount);
+  *aSelectedColumnCount = 0;
+
+  if (!mTable)
+    return NS_ERROR_FAILURE;
+
+  *aSelectedColumnCount = mTable->SelectedColCount();
+  return NS_OK;
+}
+
+nsresult
+xpcAccessibleTable::GetSelectedRowCount(PRUint32* aSelectedRowCount)
+{
+  NS_ENSURE_ARG_POINTER(aSelectedRowCount);
+  *aSelectedRowCount = 0;
+
+  if (!mTable)
+    return NS_ERROR_FAILURE;
+
+  *aSelectedRowCount = mTable->SelectedRowCount();
+  return NS_OK;
+}
+
+nsresult
 xpcAccessibleTable::GetSummary(nsAString& aSummary)
 {
   if (!mTable)
     return NS_ERROR_FAILURE;
 
   nsAutoString summary;
   mTable->Summary(summary);
   aSummary.Assign(summary);
--- a/accessible/src/xpcom/xpcAccessibleTable.h
+++ b/accessible/src/xpcom/xpcAccessibleTable.h
@@ -34,16 +34,19 @@ public:
                              PRInt32* aColumnExtent);
   nsresult GetRowExtentAt(PRInt32 row, PRInt32 column,
                           PRInt32* aRowExtent);
   nsresult GetColumnDescription(PRInt32 aColIdx, nsAString& aDescription);
   nsresult GetRowDescription(PRInt32 aRowIdx, nsAString& aDescription);
   nsresult IsColumnSelected(PRInt32 aColIdx, bool* _retval);
   nsresult IsRowSelected(PRInt32 aRowIdx, bool* _retval);
   nsresult IsCellSelected(PRInt32 aRowIdx, PRInt32 aColIdx, bool* _retval);
+  nsresult GetSelectedCellCount(PRUint32* aSelectedCellCount);
+  nsresult GetSelectedColumnCount(PRUint32* aSelectedColumnCount);
+  nsresult GetSelectedRowCount(PRUint32* aSelectedRowCount);
   nsresult SelectColumn(PRInt32 aColIdx);
   nsresult SelectRow(PRInt32 aRowIdx);
   nsresult UnselectColumn(PRInt32 aColIdx);
   nsresult UnselectRow(PRInt32 aRowIdx);
   nsresult IsProbablyForLayout(bool* aIsForLayout);
 
 protected:
   mozilla::a11y::TableAccessible* mTable;
@@ -74,19 +77,22 @@ protected:
   NS_SCRIPTABLE NS_IMETHOD GetRowDescription(PRInt32 rowIndex, nsAString& _retval NS_OUTPARAM) \
     { return xpcAccessibleTable::GetRowDescription(rowIndex, _retval); } \
   NS_SCRIPTABLE NS_IMETHOD IsColumnSelected(PRInt32 colIdx, bool* _retval NS_OUTPARAM) \
     { return xpcAccessibleTable::IsColumnSelected(colIdx, _retval); } \
   NS_SCRIPTABLE NS_IMETHOD IsRowSelected(PRInt32 rowIdx, bool* _retval NS_OUTPARAM) \
     { return xpcAccessibleTable::IsRowSelected(rowIdx, _retval); } \
   NS_SCRIPTABLE NS_IMETHOD IsCellSelected(PRInt32 rowIdx, PRInt32 colIdx, bool* _retval NS_OUTPARAM) \
     { return xpcAccessibleTable::IsCellSelected(rowIdx, colIdx, _retval); } \
-  NS_SCRIPTABLE NS_IMETHOD GetSelectedCellCount(PRUint32 *aSelectedCellCount); \
-  NS_SCRIPTABLE NS_IMETHOD GetSelectedColumnCount(PRUint32 *aSelectedColumnCount); \
-  NS_SCRIPTABLE NS_IMETHOD GetSelectedRowCount(PRUint32 *aSelectedRowCount); \
+  NS_SCRIPTABLE NS_IMETHOD GetSelectedCellCount(PRUint32* aSelectedCellCount) \
+    { return xpcAccessibleTable::GetSelectedCellCount(aSelectedCellCount); } \
+  NS_SCRIPTABLE NS_IMETHOD GetSelectedColumnCount(PRUint32* aSelectedColumnCount) \
+    { return xpcAccessibleTable::GetSelectedColumnCount(aSelectedColumnCount); } \
+  NS_SCRIPTABLE NS_IMETHOD GetSelectedRowCount(PRUint32* aSelectedRowCount) \
+    { return xpcAccessibleTable::GetSelectedRowCount(aSelectedRowCount); } \
   NS_SCRIPTABLE NS_IMETHOD GetSelectedCells(nsIArray * *aSelectedCells); \
   NS_SCRIPTABLE NS_IMETHOD GetSelectedCellIndices(PRUint32 *cellsArraySize NS_OUTPARAM, PRInt32 **cellsArray NS_OUTPARAM); \
   NS_SCRIPTABLE NS_IMETHOD GetSelectedColumnIndices(PRUint32 *rowsArraySize NS_OUTPARAM, PRInt32 **rowsArray NS_OUTPARAM); \
   NS_SCRIPTABLE NS_IMETHOD GetSelectedRowIndices(PRUint32 *rowsArraySize NS_OUTPARAM, PRInt32 **rowsArray NS_OUTPARAM); \
   NS_SCRIPTABLE NS_IMETHOD SelectRow(PRInt32 aRowIdx) \
     { return xpcAccessibleTable::SelectRow(aRowIdx); } \
   NS_SCRIPTABLE NS_IMETHOD SelectColumn(PRInt32 aColIdx) \
     { return xpcAccessibleTable::SelectColumn(aColIdx); } \
--- a/accessible/src/xul/XULListboxAccessible.cpp
+++ b/accessible/src/xul/XULListboxAccessible.cpp
@@ -349,100 +349,64 @@ XULListboxAccessible::IsRowSelected(PRUi
 }
 
 bool
 XULListboxAccessible::IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx)
 {
   return IsRowSelected(aRowIdx);
 }
 
-NS_IMETHODIMP
-XULListboxAccessible::GetSelectedCellCount(PRUint32* aCount)
+PRUint32
+XULListboxAccessible::SelectedCellCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
   nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
     do_QueryInterface(mContent);
   NS_ASSERTION(control,
                "Doesn't implement nsIDOMXULMultiSelectControlElement.");
 
   nsCOMPtr<nsIDOMNodeList> selectedItems;
   control->GetSelectedItems(getter_AddRefs(selectedItems));
   if (!selectedItems)
-    return NS_OK;
+    return 0;
 
   PRUint32 selectedItemsCount = 0;
   nsresult rv = selectedItems->GetLength(&selectedItemsCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!selectedItemsCount)
-    return NS_OK;
+  NS_ENSURE_SUCCESS(rv, 0);
 
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aCount = selectedItemsCount * columnCount;
-  return NS_OK;
+  return selectedItemsCount * ColCount();
 }
 
-NS_IMETHODIMP
-XULListboxAccessible::GetSelectedColumnCount(PRUint32* aCount)
+PRUint32
+XULListboxAccessible::SelectedColCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
   nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
     do_QueryInterface(mContent);
   NS_ASSERTION(control,
                "Doesn't implement nsIDOMXULMultiSelectControlElement.");
 
-  PRInt32 selectedrowCount = 0;
-  nsresult rv = control->GetSelectedCount(&selectedrowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 rowCount = 0;
-  rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  PRInt32 selectedRowCount = 0;
+  nsresult rv = control->GetSelectedCount(&selectedRowCount);
+  NS_ENSURE_SUCCESS(rv, 0);
 
-  if (selectedrowCount != rowCount)
-    return NS_OK;
-
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aCount = columnCount;
-  return NS_OK;
+  return selectedRowCount > 0 && selectedRowCount == RowCount() ? ColCount() : 0;
 }
 
-NS_IMETHODIMP
-XULListboxAccessible::GetSelectedRowCount(PRUint32* aCount)
+PRUint32
+XULListboxAccessible::SelectedRowCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
   nsCOMPtr<nsIDOMXULMultiSelectControlElement> control =
     do_QueryInterface(mContent);
   NS_ASSERTION(control,
                "Doesn't implement nsIDOMXULMultiSelectControlElement.");
 
-  PRInt32 selectedrowCount = 0;
-  nsresult rv = control->GetSelectedCount(&selectedrowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  PRInt32 selectedRowCount = 0;
+  nsresult rv = control->GetSelectedCount(&selectedRowCount);
+  NS_ENSURE_SUCCESS(rv, 0);
 
-  *aCount = selectedrowCount;
-  return NS_OK;
+  return selectedRowCount >= 0 ? selectedRowCount : 0;
 }
 
 NS_IMETHODIMP
 XULListboxAccessible::GetSelectedCells(nsIArray** aCells)
 {
   NS_ENSURE_ARG_POINTER(aCells);
   *aCells = nsnull;
 
--- a/accessible/src/xul/XULListboxAccessible.h
+++ b/accessible/src/xul/XULListboxAccessible.h
@@ -74,16 +74,19 @@ public:
 
   // TableAccessible
   virtual PRUint32 ColCount();
   virtual PRUint32 RowCount();
   virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
   virtual bool IsColSelected(PRUint32 aColIdx);
   virtual bool IsRowSelected(PRUint32 aRowIdx);
   virtual bool IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual PRUint32 SelectedCellCount();
+  virtual PRUint32 SelectedColCount();
+  virtual PRUint32 SelectedRowCount();
   virtual void SelectRow(PRUint32 aRowIdx);
   virtual void UnselectRow(PRUint32 aRowIdx);
 
   // nsAccessNode
   virtual void Shutdown();
 
   // Accessible
   virtual void Value(nsString& aValue);
--- a/accessible/src/xul/XULTreeGridAccessible.cpp
+++ b/accessible/src/xul/XULTreeGridAccessible.cpp
@@ -51,80 +51,43 @@ XULTreeGridAccessible::RowCount()
   if (!mTreeView)
     return 0;
 
   PRInt32 rowCount = 0;
   mTreeView->GetRowCount(&rowCount);
   return rowCount >= 0 ? rowCount : 0;
 }
 
-NS_IMETHODIMP
-XULTreeGridAccessible::GetSelectedCellCount(PRUint32* aCount)
+PRUint32
+XULTreeGridAccessible::SelectedCellCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  PRUint32 selectedrowCount = 0;
-  nsresult rv = GetSelectedRowCount(&selectedrowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 columnCount = 0;
-  rv = GetColumnCount(&columnCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aCount = selectedrowCount * columnCount;
-  return NS_OK;
+  return SelectedRowCount() * ColCount();
 }
 
-NS_IMETHODIMP
-XULTreeGridAccessible::GetSelectedColumnCount(PRUint32* aCount)
+PRUint32
+XULTreeGridAccessible::SelectedColCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
-
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
   // If all the row has been selected, then all the columns are selected,
   // because we can't select a column alone.
 
-  PRInt32 rowCount = 0;
-  nsresult rv = GetRowCount(&rowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  PRInt32 selectedrowCount = 0;
-  rv = GetSelectionCount(&selectedrowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
+  PRInt32 selectedRowCount = 0;
+  nsresult rv = GetSelectionCount(&selectedRowCount);
+  NS_ENSURE_SUCCESS(rv, 0);
 
-  if (rowCount == selectedrowCount) {
-    PRInt32 columnCount = 0;
-    rv = GetColumnCount(&columnCount);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    *aCount = columnCount;
-  }
-
-  return NS_OK;
+  return selectedRowCount > 0 && selectedRowCount == RowCount() ? ColCount() : 0;
 }
 
-NS_IMETHODIMP
-XULTreeGridAccessible::GetSelectedRowCount(PRUint32* aCount)
+PRUint32
+XULTreeGridAccessible::SelectedRowCount()
 {
-  NS_ENSURE_ARG_POINTER(aCount);
-  *aCount = 0;
+  PRInt32 selectedRowCount = 0;
+  nsresult rv = GetSelectionCount(&selectedRowCount);
+  NS_ENSURE_SUCCESS(rv, 0);
 
-  if (IsDefunct())
-    return NS_ERROR_FAILURE;
-
-  PRInt32 selectedrowCount = 0;
-  nsresult rv = GetSelectionCount(&selectedrowCount);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  *aCount = selectedrowCount;
-  return NS_OK;
+  return selectedRowCount >= 0 ? selectedRowCount : 0;
 }
 
 NS_IMETHODIMP
 XULTreeGridAccessible::GetSelectedCells(nsIArray** aCells)
 {
   NS_ENSURE_ARG_POINTER(aCells);
   *aCells = nsnull;
 
--- a/accessible/src/xul/XULTreeGridAccessible.h
+++ b/accessible/src/xul/XULTreeGridAccessible.h
@@ -33,16 +33,19 @@ public:
   // TableAccessible
   virtual PRUint32 ColCount();
   virtual PRUint32 RowCount();
   virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
   virtual void ColDescription(PRUint32 aColIdx, nsString& aDescription);
   virtual bool IsColSelected(PRUint32 aColIdx);
   virtual bool IsRowSelected(PRUint32 aRowIdx);
   virtual bool IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx);
+  virtual PRUint32 SelectedCellCount();
+  virtual PRUint32 SelectedColCount();
+  virtual PRUint32 SelectedRowCount();
   virtual void SelectRow(PRUint32 aRowIdx);
   virtual void UnselectRow(PRUint32 aRowIdx);
 
   // nsAccessNode
   virtual void Shutdown();
 
   // Accessible
   virtual TableAccessible* AsTable() { return this; }