bug 795192 - don't use nsIAccessibleTable in atk/ r=surkov
authorTrevor Saunders <trev.saunders@gmail.com>
Mon, 20 Aug 2012 10:54:33 -0400
changeset 109277 6852e80e78c850289ff5cdb6b15b01f2adf92d8a
parent 109276 972c376d08b537e30f8495ee420800cb1f3fe520
child 109278 3f51580af5a62a6e6283529e41d5dff0eb1a44cd
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerssurkov
bugs795192
milestone18.0a1
bug 795192 - don't use nsIAccessibleTable in atk/ r=surkov
accessible/src/atk/AccessibleWrap.cpp
accessible/src/atk/nsMaiInterfaceTable.cpp
--- a/accessible/src/atk/AccessibleWrap.cpp
+++ b/accessible/src/atk/AccessibleWrap.cpp
@@ -401,23 +401,19 @@ AccessibleWrap::CreateMaiInterfaces(void
     interfacesBits |= 1 << MAI_INTERFACE_IMAGE;
 
   // HyperLink interface.
   if (IsLink())
     interfacesBits |= 1 << MAI_INTERFACE_HYPERLINK_IMPL;
 
   if (!nsAccUtils::MustPrune(this)) {  // These interfaces require children
     // Table interface.
-    nsCOMPtr<nsIAccessibleTable> accessInterfaceTable;
-    QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                   getter_AddRefs(accessInterfaceTable));
-    if (accessInterfaceTable) {
+    if (AsTable())
       interfacesBits |= 1 << MAI_INTERFACE_TABLE;
-    }
-      
+ 
     // Selection interface.
     if (IsSelect()) {
       interfacesBits |= 1 << MAI_INTERFACE_SELECTION;
     }
   }
 
   return interfacesBits;
 }
--- a/accessible/src/atk/nsMaiInterfaceTable.cpp
+++ b/accessible/src/atk/nsMaiInterfaceTable.cpp
@@ -3,443 +3,293 @@
 /* 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 "InterfaceInitFuncs.h"
 
 #include "AccessibleWrap.h"
 #include "nsAccUtils.h"
-#include "nsIAccessibleTable.h"
 #include "TableAccessible.h"
+#include "TableCellAccessible.h"
 #include "nsMai.h"
 
 #include "nsArrayUtils.h"
 
 using namespace mozilla::a11y;
 
 extern "C" {
 static AtkObject*
-refAtCB(AtkTable *aTable, gint aRow, gint aColumn)
+refAtCB(AtkTable* aTable, gint aRowIdx, gint aColIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-  if (!accWrap)
+  if (!accWrap || aRowIdx < 0 || aColIdx < 0)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, nullptr);
+  Accessible* cell = accWrap->AsTable()->CellAt(aRowIdx, aColIdx);
+  if (!cell)
+    return nullptr;
 
-    nsCOMPtr<nsIAccessible> cell;
-    nsresult rv = accTable->GetCellAt(aRow, aColumn,getter_AddRefs(cell));
-    if (NS_FAILED(rv) || !cell)
-        return nullptr;
+  AtkObject* cellAtkObj = AccessibleWrap::GetAtkObject(cell);
+  if (cellAtkObj)
+    g_object_ref(cellAtkObj);
 
-    AtkObject* cellAtkObj = AccessibleWrap::GetAtkObject(cell);
-    if (cellAtkObj) {
-        g_object_ref(cellAtkObj);
-    }
-    return cellAtkObj;
+  return cellAtkObj;
 }
 
 static gint
-getIndexAtCB(AtkTable* aTable, gint aRow, gint aColumn)
+getIndexAtCB(AtkTable* aTable, gint aRowIdx, gint aColIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-  if (!accWrap)
+  if (!accWrap || aRowIdx < 0 || aColIdx < 0)
     return -1;
 
-  TableAccessible* table = accWrap->AsTable();
-  NS_ENSURE_TRUE(table, -1);
-
-  return static_cast<gint>(table->CellIndexAt(aRow, aColumn));
+  return static_cast<gint>(accWrap->AsTable()->CellIndexAt(aRowIdx, aColIdx));
 }
 
 static gint
-getColumnAtIndexCB(AtkTable *aTable, gint aIndex)
+getColumnAtIndexCB(AtkTable *aTable, gint aIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-  if (!accWrap)
+  if (!accWrap || aIdx < 0)
     return -1;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, -1);
-
-    int32_t col;
-    nsresult rv = accTable->GetColumnIndexAt(aIndex, &col);
-    NS_ENSURE_SUCCESS(rv, -1);
-
-    return static_cast<gint>(col);
+    return static_cast<gint>(accWrap->AsTable()->ColIndexAt(aIdx));
 }
 
 static gint
-getRowAtIndexCB(AtkTable *aTable, gint aIndex)
+getRowAtIndexCB(AtkTable *aTable, gint aIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-  if (!accWrap)
+  if (!accWrap || aIdx < 0)
     return -1;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, -1);
-
-    int32_t row;
-    nsresult rv = accTable->GetRowIndexAt(aIndex, &row);
-    NS_ENSURE_SUCCESS(rv, -1);
-
-    return static_cast<gint>(row);
+    return static_cast<gint>(accWrap->AsTable()->RowIndexAt(aIdx));
 }
 
 static gint
 getColumnCountCB(AtkTable *aTable)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return -1;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, -1);
-
-    int32_t count;
-    nsresult rv = accTable->GetColumnCount(&count);
-    NS_ENSURE_SUCCESS(rv, -1);
-
-    return static_cast<gint>(count);
+    return static_cast<gint>(accWrap->AsTable()->ColCount());
 }
 
 static gint
 getRowCountCB(AtkTable *aTable)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return -1;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, -1);
-
-    int32_t count;
-    nsresult rv = accTable->GetRowCount(&count);
-    NS_ENSURE_SUCCESS(rv, -1);
-
-    return static_cast<gint>(count);
+    return static_cast<gint>(accWrap->AsTable()->RowCount());
 }
 
 static gint
-getColumnExtentAtCB(AtkTable *aTable,
-                    gint aRow, gint aColumn)
+getColumnExtentAtCB(AtkTable *aTable, gint aRowIdx, gint aColIdx)
+{
+  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
+  if (!accWrap || aRowIdx < 0 || aColIdx < 0)
+    return -1;
+
+    return static_cast<gint>(accWrap->AsTable()->ColExtentAt(aRowIdx, aColIdx));
+}
+
+static gint
+getRowExtentAtCB(AtkTable *aTable, gint aRowIdx, gint aColIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return -1;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, -1);
-
-    int32_t extent;
-    nsresult rv = accTable->GetColumnExtentAt(aRow, aColumn, &extent);
-    NS_ENSURE_SUCCESS(rv, -1);
-
-    return static_cast<gint>(extent);
-}
-
-static gint
-getRowExtentAtCB(AtkTable *aTable,
-                 gint aRow, gint aColumn)
-{
-  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-  if (!accWrap)
-    return -1;
-
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, -1);
-
-    int32_t extent;
-    nsresult rv = accTable->GetRowExtentAt(aRow, aColumn, &extent);
-    NS_ENSURE_SUCCESS(rv, -1);
-
-    return static_cast<gint>(extent);
+  return static_cast<gint>(accWrap->AsTable()->RowExtentAt(aRowIdx, aColIdx));
 }
 
 static AtkObject*
 getCaptionCB(AtkTable* aTable)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return nullptr;
 
-  TableAccessible* table = accWrap->AsTable();
-  NS_ENSURE_TRUE(table, nullptr);
-
-  Accessible* caption = table->Caption();
+  Accessible* caption = accWrap->AsTable()->Caption();
   return caption ? AccessibleWrap::GetAtkObject(caption) : nullptr;
 }
 
 static const gchar*
 getColumnDescriptionCB(AtkTable *aTable, gint aColumn)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, nullptr);
+  nsAutoString autoStr;
+  accWrap->AsTable()->ColDescription(aColumn, autoStr);
 
-    nsAutoString autoStr;
-    nsresult rv = accTable->GetColumnDescription(aColumn, autoStr);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-    return AccessibleWrap::ReturnString(autoStr);
+  return AccessibleWrap::ReturnString(autoStr);
 }
 
 static AtkObject*
-getColumnHeaderCB(AtkTable *aTable, gint aColumn)
+getColumnHeaderCB(AtkTable *aTable, gint aColIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, nullptr);
+  Accessible* cell = accWrap->AsTable()->CellAt(0, aColIdx);
+  if (!cell)
+    return nullptr;
 
-    nsCOMPtr<nsIAccessible> accCell;
-    accTable->GetCellAt(0, aColumn, getter_AddRefs(accCell));
-    if (!accCell)
-        return nullptr;
-
-    // If the cell at the first row is column header then assume it is column
-    // header for all rows,
-    if (nsAccUtils::Role(accCell) == nsIAccessibleRole::ROLE_COLUMNHEADER)
-        return AccessibleWrap::GetAtkObject(accCell);
+  // If the cell at the first row is column header then assume it is column
+  // header for all rows,
+  if (cell->Role() == roles::COLUMNHEADER)
+    return AccessibleWrap::GetAtkObject(cell);
 
-    // otherwise get column header for the data cell at the first row.
-    nsCOMPtr<nsIAccessibleTableCell> accTableCell =
-        do_QueryInterface(accCell);
+  // otherwise get column header for the data cell at the first row.
+  TableCellAccessible* tableCell = cell->AsTableCell();
+  if (!tableCell)
+    return nullptr;
 
-    if (accTableCell) {
-        nsCOMPtr<nsIArray> headerCells;
-        accTableCell->GetColumnHeaderCells(getter_AddRefs(headerCells));
-        if (headerCells) {
-            nsresult rv;
-            nsCOMPtr<nsIAccessible> accHeaderCell =
-                do_QueryElementAt(headerCells, 0, &rv);
-            NS_ENSURE_SUCCESS(rv, nullptr);
+  nsAutoTArray<Accessible*, 10> headerCells;
+  tableCell->ColHeaderCells(&headerCells);
+  if (headerCells.IsEmpty())
+    return nullptr;
 
-            return AccessibleWrap::GetAtkObject(accHeaderCell);
-        }
-    }
-
-    return nullptr;
+  return AccessibleWrap::GetAtkObject(headerCells[0]);
 }
 
 static const gchar*
 getRowDescriptionCB(AtkTable *aTable, gint aRow)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, nullptr);
+  nsAutoString autoStr;
+  accWrap->AsTable()->RowDescription(aRow, autoStr);
 
-    nsAutoString autoStr;
-    nsresult rv = accTable->GetRowDescription(aRow, autoStr);
-    NS_ENSURE_SUCCESS(rv, nullptr);
-
-    return AccessibleWrap::ReturnString(autoStr);
+  return AccessibleWrap::ReturnString(autoStr);
 }
 
 static AtkObject*
-getRowHeaderCB(AtkTable *aTable, gint aRow)
+getRowHeaderCB(AtkTable *aTable, gint aRowIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return nullptr;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, nullptr);
+  Accessible* cell = accWrap->AsTable()->CellAt(aRowIdx, 0);
+  if (!cell)
+    return nullptr;
 
-    nsCOMPtr<nsIAccessible> accCell;
-    accTable->GetCellAt(aRow, 0, getter_AddRefs(accCell));
-    if (!accCell)
-      return nullptr;
-
-    // If the cell at the first column is row header then assume it is row
-    // header for all columns,
-    if (nsAccUtils::Role(accCell) == nsIAccessibleRole::ROLE_ROWHEADER)
-        return AccessibleWrap::GetAtkObject(accCell);
+  // If the cell at the first column is row header then assume it is row
+  // header for all columns,
+  if (cell->Role() == roles::ROWHEADER)
+    return AccessibleWrap::GetAtkObject(cell);
 
-    // otherwise get row header for the data cell at the first column.
-    nsCOMPtr<nsIAccessibleTableCell> accTableCell =
-        do_QueryInterface(accCell);
+  // otherwise get row header for the data cell at the first column.
+  TableCellAccessible* tableCell = cell->AsTableCell();
+  if (!tableCell)
+    return nullptr;
 
-    if (accTableCell) {
-      nsCOMPtr<nsIArray> headerCells;
-      accTableCell->GetRowHeaderCells(getter_AddRefs(headerCells));
-      if (headerCells) {
-        nsresult rv;
-        nsCOMPtr<nsIAccessible> accHeaderCell =
-            do_QueryElementAt(headerCells, 0, &rv);
-        NS_ENSURE_SUCCESS(rv, nullptr);
+  nsAutoTArray<Accessible*, 10> headerCells;
+  tableCell->RowHeaderCells(&headerCells);
+  if (headerCells.IsEmpty())
+    return nullptr;
 
-        return AccessibleWrap::GetAtkObject(accHeaderCell);
-      }
-    }
-
-    return nullptr;
+  return AccessibleWrap::GetAtkObject(headerCells[0]);
 }
 
 static AtkObject*
 getSummaryCB(AtkTable *aTable)
 {
   // Neither html:table nor xul:tree nor ARIA grid/tree have an ability to
   // link an accessible object to specify a summary. There is closes method
-  // in nsIAccessibleTable::summary to get a summary as a string which is not
+  // in TableAccessible::summary to get a summary as a string which is not
   // mapped directly to ATK.
   return nullptr;
 }
 
 static gint
-getSelectedColumnsCB(AtkTable *aTable, gint **aSelected)
+getSelectedColumnsCB(AtkTable *aTable, gint** aSelected)
 {
+  *aSelected = nullptr;
+
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return 0;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, 0);
-
-    uint32_t size = 0;
-    int32_t *columns = NULL;
-    nsresult rv = accTable->GetSelectedColumnIndices(&size, &columns);
-    if (NS_FAILED(rv) || (size == 0) || !columns) {
-        *aSelected = nullptr;
-        return 0;
-    }
+  nsAutoTArray<uint32_t, 10> cols;
+  accWrap->AsTable()->SelectedColIndices(&cols);
+  if (cols.IsEmpty())
+    return 0;
 
-    gint *atkColumns = g_new(gint, size);
-    if (!atkColumns) {
-        NS_WARNING("OUT OF MEMORY");
-        return 0;
-    }
+  gint* atkColumns = g_new(gint, cols.Length());
+  if (!atkColumns) {
+    NS_WARNING("OUT OF MEMORY");
+    return 0;
+  }
 
-    //copy
-    for (uint32_t index = 0; index < size; ++index)
-        atkColumns[index] = static_cast<gint>(columns[index]);
-    nsMemory::Free(columns);
-
-    *aSelected = atkColumns;
-    return size;
+  memcpy(atkColumns, cols.Elements(), cols.Length() * sizeof(uint32_t));
+  *aSelected = atkColumns;
+  return cols.Length();
 }
 
 static gint
 getSelectedRowsCB(AtkTable *aTable, gint **aSelected)
 {
-    AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    if (!accWrap)
-        return 0;
+  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
+  if (!accWrap)
+    return 0;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, 0);
+  nsAutoTArray<uint32_t, 10> rows;
+  accWrap->AsTable()->SelectedRowIndices(&rows);
 
-    uint32_t size = 0;
-    int32_t *rows = NULL;
-    nsresult rv = accTable->GetSelectedRowIndices(&size, &rows);
-    if (NS_FAILED(rv) || (size == 0) || !rows) {
-        *aSelected = nullptr;
-        return 0;
-    }
+  gint* atkRows = g_new(gint, rows.Length());
+  if (!atkRows) {
+    NS_WARNING("OUT OF MEMORY");
+    return 0;
+  }
 
-    gint *atkRows = g_new(gint, size);
-    if (!atkRows) {
-        NS_WARNING("OUT OF MEMORY");
-        return 0;
-    }
-
-    //copy
-    for (uint32_t index = 0; index < size; ++index)
-        atkRows[index] = static_cast<gint>(rows[index]);
-    nsMemory::Free(rows);
-
-    *aSelected = atkRows;
-    return size;
+  memcpy(atkRows, rows.Elements(), rows.Length() * sizeof(uint32_t));
+  *aSelected = atkRows;
+  return rows.Length();
 }
 
 static gboolean
-isColumnSelectedCB(AtkTable *aTable, gint aColumn)
-{
-    AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
-    if (!accWrap)
-        return FALSE;
-
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, FALSE);
-
-    bool outValue;
-    nsresult rv = accTable->IsColumnSelected(aColumn, &outValue);
-    return NS_FAILED(rv) ? FALSE : static_cast<gboolean>(outValue);
-}
-
-static gboolean
-isRowSelectedCB(AtkTable *aTable, gint aRow)
+isColumnSelectedCB(AtkTable *aTable, gint aColIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return FALSE;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, FALSE);
-
-    bool outValue;
-    nsresult rv = accTable->IsRowSelected(aRow, &outValue);
-    return NS_FAILED(rv) ? FALSE : static_cast<gboolean>(outValue);
+  return static_cast<gboolean>(accWrap->AsTable()->IsColSelected(aColIdx));
 }
 
 static gboolean
-isCellSelectedCB(AtkTable *aTable, gint aRow, gint aColumn)
+isRowSelectedCB(AtkTable *aTable, gint aRowIdx)
 {
   AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
   if (!accWrap)
     return FALSE;
 
-    nsCOMPtr<nsIAccessibleTable> accTable;
-    accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
-                            getter_AddRefs(accTable));
-    NS_ENSURE_TRUE(accTable, FALSE);
+  return static_cast<gboolean>(accWrap->AsTable()->IsRowSelected(aRowIdx));
+}
 
-    bool outValue;
-    nsresult rv = accTable->IsCellSelected(aRow, aColumn, &outValue);
-    return NS_FAILED(rv) ? FALSE : static_cast<gboolean>(outValue);
+static gboolean
+isCellSelectedCB(AtkTable *aTable, gint aRowIdx, gint aColIdx)
+{
+  AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable));
+  if (!accWrap)
+    return FALSE;
+
+    return static_cast<gboolean>(accWrap->AsTable()->
+      IsCellSelected(aRowIdx, aColIdx));
 }
 }
 
 void
 tableInterfaceInitCB(AtkTableIface* aIface)
 {
   NS_ASSERTION(aIface, "no interface!");
   if (NS_UNLIKELY(!aIface))