From 764ae3ee6af4657dca04eb20dc4eeb529929ef61 Mon Sep 17 00:00:00 2001 From: Trevor Saunders Date: Mon, 20 Aug 2012 10:54:33 -0400 Subject: [PATCH] bug 795192 - don't use nsIAccessibleTable in atk/ r=surkov --- accessible/src/atk/AccessibleWrap.cpp | 8 +- accessible/src/atk/nsMaiInterfaceTable.cpp | 396 +++++++-------------- 2 files changed, 125 insertions(+), 279 deletions(-) diff --git a/accessible/src/atk/AccessibleWrap.cpp b/accessible/src/atk/AccessibleWrap.cpp index 6c3c24e0e1e8..e35da5db9f72 100644 --- a/accessible/src/atk/AccessibleWrap.cpp +++ b/accessible/src/atk/AccessibleWrap.cpp @@ -406,13 +406,9 @@ AccessibleWrap::CreateMaiInterfaces(void) if (!nsAccUtils::MustPrune(this)) { // These interfaces require children // Table interface. - nsCOMPtr 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; diff --git a/accessible/src/atk/nsMaiInterfaceTable.cpp b/accessible/src/atk/nsMaiInterfaceTable.cpp index 6674612e280e..da52ba19af53 100644 --- a/accessible/src/atk/nsMaiInterfaceTable.cpp +++ b/accessible/src/atk/nsMaiInterfaceTable.cpp @@ -8,8 +8,8 @@ #include "AccessibleWrap.h" #include "nsAccUtils.h" -#include "nsIAccessibleTable.h" #include "TableAccessible.h" +#include "TableCellAccessible.h" #include "nsMai.h" #include "nsArrayUtils.h" @@ -18,78 +18,51 @@ 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 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 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(table->CellIndexAt(aRow, aColumn)); + return static_cast(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 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(col); + return static_cast(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 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(row); + return static_cast(accWrap->AsTable()->RowIndexAt(aIdx)); } static gint @@ -99,16 +72,7 @@ getColumnCountCB(AtkTable *aTable) if (!accWrap) return -1; - nsCOMPtr 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(count); + return static_cast(accWrap->AsTable()->ColCount()); } static gint @@ -118,56 +82,27 @@ getRowCountCB(AtkTable *aTable) if (!accWrap) return -1; - nsCOMPtr 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(count); + return static_cast(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(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 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(extent); -} - -static gint -getRowExtentAtCB(AtkTable *aTable, - gint aRow, gint aColumn) -{ - AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable)); - if (!accWrap) - return -1; - - nsCOMPtr 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(extent); + return static_cast(accWrap->AsTable()->RowExtentAt(aRowIdx, aColIdx)); } static AtkObject* @@ -177,10 +112,7 @@ getCaptionCB(AtkTable* 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; } @@ -191,58 +123,39 @@ getColumnDescriptionCB(AtkTable *aTable, gint aColumn) if (!accWrap) return nullptr; - nsCOMPtr 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 accTable; - accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable), - getter_AddRefs(accTable)); - NS_ENSURE_TRUE(accTable, nullptr); - - nsCOMPtr 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); - - // otherwise get column header for the data cell at the first row. - nsCOMPtr accTableCell = - do_QueryInterface(accCell); - - if (accTableCell) { - nsCOMPtr headerCells; - accTableCell->GetColumnHeaderCells(getter_AddRefs(headerCells)); - if (headerCells) { - nsresult rv; - nsCOMPtr accHeaderCell = - do_QueryElementAt(headerCells, 0, &rv); - NS_ENSURE_SUCCESS(rv, nullptr); - - return AccessibleWrap::GetAtkObject(accHeaderCell); - } - } - + Accessible* cell = accWrap->AsTable()->CellAt(0, aColIdx); + if (!cell) return nullptr; + + // 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. + TableCellAccessible* tableCell = cell->AsTableCell(); + if (!tableCell) + return nullptr; + + nsAutoTArray headerCells; + tableCell->ColHeaderCells(&headerCells); + if (headerCells.IsEmpty()) + return nullptr; + + return AccessibleWrap::GetAtkObject(headerCells[0]); } static const gchar* @@ -252,58 +165,39 @@ getRowDescriptionCB(AtkTable *aTable, gint aRow) if (!accWrap) return nullptr; - nsCOMPtr 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 accTable; - accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable), - getter_AddRefs(accTable)); - NS_ENSURE_TRUE(accTable, nullptr); - - nsCOMPtr 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); - - // otherwise get row header for the data cell at the first column. - nsCOMPtr accTableCell = - do_QueryInterface(accCell); - - if (accTableCell) { - nsCOMPtr headerCells; - accTableCell->GetRowHeaderCells(getter_AddRefs(headerCells)); - if (headerCells) { - nsresult rv; - nsCOMPtr accHeaderCell = - do_QueryElementAt(headerCells, 0, &rv); - NS_ENSURE_SUCCESS(rv, nullptr); - - return AccessibleWrap::GetAtkObject(accHeaderCell); - } - } - + Accessible* cell = accWrap->AsTable()->CellAt(aRowIdx, 0); + if (!cell) return nullptr; + + // 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. + TableCellAccessible* tableCell = cell->AsTableCell(); + if (!tableCell) + return nullptr; + + nsAutoTArray headerCells; + tableCell->RowHeaderCells(&headerCells); + if (headerCells.IsEmpty()) + return nullptr; + + return AccessibleWrap::GetAtkObject(headerCells[0]); } static AtkObject* @@ -311,130 +205,86 @@ 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 accTable; - accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable), - getter_AddRefs(accTable)); - NS_ENSURE_TRUE(accTable, 0); + nsAutoTArray cols; + accWrap->AsTable()->SelectedColIndices(&cols); + if (cols.IsEmpty()) + return 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; - } + gint* atkColumns = g_new(gint, cols.Length()); + if (!atkColumns) { + NS_WARNING("OUT OF MEMORY"); + return 0; + } - gint *atkColumns = g_new(gint, size); - if (!atkColumns) { - NS_WARNING("OUT OF MEMORY"); - return 0; - } - - //copy - for (uint32_t index = 0; index < size; ++index) - atkColumns[index] = static_cast(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 accTable; - accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable), - getter_AddRefs(accTable)); - NS_ENSURE_TRUE(accTable, 0); + nsAutoTArray 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(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 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(outValue); -} - -static gboolean -isRowSelectedCB(AtkTable *aTable, gint aRow) +isColumnSelectedCB(AtkTable *aTable, gint aColIdx) { AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable)); if (!accWrap) return FALSE; - nsCOMPtr 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(outValue); + return static_cast(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 accTable; - accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable), - getter_AddRefs(accTable)); - NS_ENSURE_TRUE(accTable, FALSE); + return static_cast(accWrap->AsTable()->IsRowSelected(aRowIdx)); +} - bool outValue; - nsresult rv = accTable->IsCellSelected(aRow, aColumn, &outValue); - return NS_FAILED(rv) ? FALSE : static_cast(outValue); +static gboolean +isCellSelectedCB(AtkTable *aTable, gint aRowIdx, gint aColIdx) +{ + AccessibleWrap* accWrap = GetAccessibleWrap(ATK_OBJECT(aTable)); + if (!accWrap) + return FALSE; + + return static_cast(accWrap->AsTable()-> + IsCellSelected(aRowIdx, aColIdx)); } }