bug 795192 - don't use nsIAccessibleTable in atk/ r=surkov

This commit is contained in:
Trevor Saunders 2012-08-20 10:54:33 -04:00
Родитель 146d817782
Коммит 764ae3ee6a
2 изменённых файлов: 125 добавлений и 279 удалений

Просмотреть файл

@ -406,13 +406,9 @@ AccessibleWrap::CreateMaiInterfaces(void)
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;

Просмотреть файл

@ -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<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
@ -99,16 +72,7 @@ getColumnCountCB(AtkTable *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
@ -118,56 +82,27 @@ getRowCountCB(AtkTable *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*
@ -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<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);
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);
// otherwise get column header for the data cell at the first row.
nsCOMPtr<nsIAccessibleTableCell> accTableCell =
do_QueryInterface(accCell);
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);
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<Accessible*, 10> 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<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);
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);
// otherwise get row header for the data cell at the first column.
nsCOMPtr<nsIAccessibleTableCell> accTableCell =
do_QueryInterface(accCell);
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);
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<Accessible*, 10> 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<nsIAccessibleTable> accTable;
accWrap->QueryInterface(NS_GET_IID(nsIAccessibleTable),
getter_AddRefs(accTable));
NS_ENSURE_TRUE(accTable, 0);
nsAutoTArray<uint32_t, 10> 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<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));
}
}