Bug 757503 - decomtaminate GetColumnIndexAt/GetRowIndexAt/GetRowAndColumnIndicesAt on accessible tables, r=tbsaunde

This commit is contained in:
Mark Capella 2012-06-23 18:34:48 -04:00
parent 0f515c37e2
commit f7907a1429
8 changed files with 110 additions and 233 deletions

View File

@ -90,81 +90,6 @@ ARIAGridAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
return GetCellInRowAt(row, aColumnIndex);
}
NS_IMETHODIMP
ARIAGridAccessible::GetColumnIndexAt(PRInt32 aCellIndex,
PRInt32* aColumnIndex)
{
NS_ENSURE_ARG_POINTER(aColumnIndex);
*aColumnIndex = -1;
if (IsDefunct())
return NS_ERROR_FAILURE;
NS_ENSURE_ARG(aCellIndex >= 0);
PRInt32 rowCount = 0;
GetRowCount(&rowCount);
PRInt32 colsCount = 0;
GetColumnCount(&colsCount);
NS_ENSURE_ARG(aCellIndex < rowCount * colsCount);
*aColumnIndex = aCellIndex % colsCount;
return NS_OK;
}
NS_IMETHODIMP
ARIAGridAccessible::GetRowIndexAt(PRInt32 aCellIndex, PRInt32* aRowIndex)
{
NS_ENSURE_ARG_POINTER(aRowIndex);
*aRowIndex = -1;
if (IsDefunct())
return NS_ERROR_FAILURE;
NS_ENSURE_ARG(aCellIndex >= 0);
PRInt32 rowCount = 0;
GetRowCount(&rowCount);
PRInt32 colsCount = 0;
GetColumnCount(&colsCount);
NS_ENSURE_ARG(aCellIndex < rowCount * colsCount);
*aRowIndex = aCellIndex / colsCount;
return NS_OK;
}
NS_IMETHODIMP
ARIAGridAccessible::GetRowAndColumnIndicesAt(PRInt32 aCellIndex,
PRInt32* aRowIndex,
PRInt32* aColumnIndex)
{
NS_ENSURE_ARG_POINTER(aRowIndex);
*aRowIndex = -1;
NS_ENSURE_ARG_POINTER(aColumnIndex);
*aColumnIndex = -1;
if (IsDefunct())
return NS_ERROR_FAILURE;
NS_ENSURE_ARG(aCellIndex >= 0);
PRInt32 rowCount = 0;
GetRowCount(&rowCount);
PRInt32 colsCount = 0;
GetColumnCount(&colsCount);
NS_ENSURE_ARG(aCellIndex < rowCount * colsCount);
*aColumnIndex = aCellIndex % colsCount;
*aRowIndex = aCellIndex / colsCount;
return NS_OK;
}
bool
ARIAGridAccessible::IsColSelected(PRUint32 aColIdx)
{

View File

@ -57,18 +57,25 @@ public:
/**
* Return the column index of the cell with the given index.
*/
virtual PRInt32 ColIndexAt(PRUint32 aCellIdx) { return -1; }
virtual PRInt32 ColIndexAt(PRUint32 aCellIdx)
{ return aCellIdx % ColCount(); }
/**
* Return the row index of the cell with the given index.
*/
virtual PRInt32 RowIndexAt(PRUint32 aCellIdx) { return -1; }
virtual PRInt32 RowIndexAt(PRUint32 aCellIdx)
{ return aCellIdx / ColCount(); }
/**
* Get the row and column indices for the cell at the given index.
*/
virtual void RowAndColIndicesAt(PRUint32 aCellIdx, PRInt32* aRowIdx,
PRInt32* aColIdx) {}
PRInt32* aColIdx)
{
PRUint32 colCount = ColCount();
*aRowIdx = aCellIdx / colCount;
*aColIdx = aCellIdx % colCount;
}
/**
* Return the number of columns occupied by the cell at the given row and

View File

@ -737,60 +737,38 @@ HTMLTableAccessible::CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx)
return index;
}
NS_IMETHODIMP
HTMLTableAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32* aColumn)
PRInt32
HTMLTableAccessible::ColIndexAt(PRUint32 aCellIdx)
{
NS_ENSURE_ARG_POINTER(aColumn);
if (IsDefunct())
return NS_ERROR_FAILURE;
nsITableLayout *tableLayout = GetTableLayout();
NS_ENSURE_STATE(tableLayout);
PRInt32 row;
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, &row, aColumn);
NS_ENSURE_SUCCESS(rv, rv);
return (row == -1 || *aColumn == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
}
NS_IMETHODIMP
HTMLTableAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32* aRow)
{
NS_ENSURE_ARG_POINTER(aRow);
if (IsDefunct())
return NS_ERROR_FAILURE;
nsITableLayout *tableLayout = GetTableLayout();
NS_ENSURE_STATE(tableLayout);
PRInt32 column;
nsresult rv = tableLayout->GetRowAndColumnByIndex(aIndex, aRow, &column);
NS_ENSURE_SUCCESS(rv, rv);
return (*aRow == -1 || column == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
}
NS_IMETHODIMP
HTMLTableAccessible::GetRowAndColumnIndicesAt(PRInt32 aIndex,
PRInt32* aRowIdx,
PRInt32* aColumnIdx)
{
NS_ENSURE_ARG_POINTER(aRowIdx);
*aRowIdx = -1;
NS_ENSURE_ARG_POINTER(aColumnIdx);
*aColumnIdx = -1;
if (IsDefunct())
return NS_ERROR_FAILURE;
nsITableLayout* tableLayout = GetTableLayout();
if (tableLayout)
tableLayout->GetRowAndColumnByIndex(aIndex, aRowIdx, aColumnIdx);
if (!tableLayout)
return -1;
return (*aRowIdx == -1 || *aColumnIdx == -1) ? NS_ERROR_INVALID_ARG : NS_OK;
PRInt32 rowIdx = -1, colIdx = -1;
tableLayout->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx);
return colIdx;
}
PRInt32
HTMLTableAccessible::RowIndexAt(PRUint32 aCellIdx)
{
nsITableLayout* tableLayout = GetTableLayout();
if (!tableLayout)
return -1;
PRInt32 rowIdx = -1, colIdx = -1;
tableLayout->GetRowAndColumnByIndex(aCellIdx, &rowIdx, &colIdx);
return rowIdx;
}
void
HTMLTableAccessible::RowAndColIndicesAt(PRUint32 aCellIdx, PRInt32* aRowIdx,
PRInt32* aColIdx)
{
nsITableLayout* tableLayout = GetTableLayout();
if (tableLayout)
tableLayout->GetRowAndColumnByIndex(aCellIdx, aRowIdx, aColIdx);
}
PRUint32

View File

@ -104,6 +104,10 @@ public:
virtual PRUint32 RowCount();
virtual Accessible* CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex);
virtual PRInt32 CellIndexAt(PRUint32 aRowIdx, PRUint32 aColIdx);
virtual PRInt32 ColIndexAt(PRUint32 aCellIdx);
virtual PRInt32 RowIndexAt(PRUint32 aCellIdx);
virtual void RowAndColIndicesAt(PRUint32 aCellIdx, PRInt32* aRowIdx,
PRInt32* aColIdx);
virtual PRUint32 ColExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
virtual PRUint32 RowExtentAt(PRUint32 aRowIdx, PRUint32 aColIdx);
virtual bool IsColSelected(PRUint32 aColIdx);

View File

@ -318,6 +318,63 @@ xpcAccessibleTable::GetSelectedRowIndices(PRUint32* aRowsArraySize,
return NS_OK;
}
nsresult
xpcAccessibleTable::GetColumnIndexAt(PRInt32 aCellIdx, PRInt32* aColIdx)
{
NS_ENSURE_ARG_POINTER(aColIdx);
*aColIdx = -1;
if (!mTable)
return NS_ERROR_FAILURE;
if (aCellIdx < 0
|| static_cast<PRUint32>(aCellIdx)
>= mTable->RowCount() * mTable->ColCount())
return NS_ERROR_INVALID_ARG;
*aColIdx = mTable->ColIndexAt(aCellIdx);
return NS_OK;
}
nsresult
xpcAccessibleTable::GetRowIndexAt(PRInt32 aCellIdx, PRInt32* aRowIdx)
{
NS_ENSURE_ARG_POINTER(aRowIdx);
*aRowIdx = -1;
if (!mTable)
return NS_ERROR_FAILURE;
if (aCellIdx < 0
|| static_cast<PRUint32>(aCellIdx)
>= mTable->RowCount() * mTable->ColCount())
return NS_ERROR_INVALID_ARG;
*aRowIdx = mTable->RowIndexAt(aCellIdx);
return NS_OK;
}
nsresult
xpcAccessibleTable::GetRowAndColumnIndicesAt(PRInt32 aCellIdx, PRInt32* aRowIdx,
PRInt32* aColIdx)
{
NS_ENSURE_ARG_POINTER(aRowIdx);
*aRowIdx = -1;
NS_ENSURE_ARG_POINTER(aColIdx);
*aColIdx = -1;
if (!mTable)
return NS_ERROR_FAILURE;
if (aCellIdx < 0
|| static_cast<PRUint32>(aCellIdx)
>= mTable->RowCount() * mTable->ColCount())
return NS_ERROR_INVALID_ARG;
mTable->RowAndColIndicesAt(aCellIdx, aRowIdx, aColIdx);
return NS_OK;
}
nsresult
xpcAccessibleTable::GetSummary(nsAString& aSummary)
{

View File

@ -30,6 +30,10 @@ public:
nsIAccessible** aCell);
nsresult GetCellIndexAt(PRInt32 aRowIndex, PRInt32 aColumnIndex,
PRInt32* aCellIndex);
nsresult GetColumnIndexAt(PRInt32 aCellIndex, PRInt32* aColumnIndex);
nsresult GetRowIndexAt(PRInt32 aCellIndex, PRInt32* aRowIndex);
nsresult GetRowAndColumnIndicesAt(PRInt32 aCellIndex, PRInt32* aRowIndex,
PRInt32* aColumnIndex);
nsresult GetColumnExtentAt(PRInt32 row, PRInt32 column,
PRInt32* aColumnExtent);
nsresult GetRowExtentAt(PRInt32 row, PRInt32 column,
@ -71,9 +75,12 @@ protected:
{ return xpcAccessibleTable::GetCellAt(rowIndex, columnIndex, _retval); } \
NS_SCRIPTABLE NS_IMETHOD GetCellIndexAt(PRInt32 rowIndex, PRInt32 columnIndex, PRInt32 *_retval NS_OUTPARAM) \
{ return xpcAccessibleTable::GetCellIndexAt(rowIndex, columnIndex, _retval); } \
NS_SCRIPTABLE NS_IMETHOD GetColumnIndexAt(PRInt32 cellIndex, PRInt32 *_retval NS_OUTPARAM); \
NS_SCRIPTABLE NS_IMETHOD GetRowIndexAt(PRInt32 cellIndex, PRInt32 *_retval NS_OUTPARAM); \
NS_SCRIPTABLE NS_IMETHOD GetRowAndColumnIndicesAt(PRInt32 cellIndex, PRInt32 *rowIndex NS_OUTPARAM, PRInt32 *columnIndex NS_OUTPARAM); \
NS_SCRIPTABLE NS_IMETHOD GetColumnIndexAt(PRInt32 cellIndex, PRInt32 *_retval NS_OUTPARAM) \
{ return xpcAccessibleTable::GetColumnIndexAt(cellIndex, _retval); } \
NS_SCRIPTABLE NS_IMETHOD GetRowIndexAt(PRInt32 cellIndex, PRInt32 *_retval NS_OUTPARAM) \
{ return xpcAccessibleTable::GetRowIndexAt(cellIndex, _retval); } \
NS_SCRIPTABLE NS_IMETHOD GetRowAndColumnIndicesAt(PRInt32 cellIndex, PRInt32 *rowIndex NS_OUTPARAM, PRInt32 *columnIndex NS_OUTPARAM) \
{ return xpcAccessibleTable::GetRowAndColumnIndicesAt(cellIndex, rowIndex, columnIndex); } \
NS_SCRIPTABLE NS_IMETHOD GetColumnExtentAt(PRInt32 row, PRInt32 column, PRInt32* _retval NS_OUTPARAM) \
{ return xpcAccessibleTable::GetColumnExtentAt(row, column, _retval); } \
NS_SCRIPTABLE NS_IMETHOD GetRowExtentAt(PRInt32 row, PRInt32 column, PRInt32* _retval NS_OUTPARAM) \

View File

@ -266,56 +266,6 @@ XULListboxAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
return row->GetChildAt(aColumnIndex);
}
NS_IMETHODIMP
XULListboxAccessible::GetColumnIndexAt(PRInt32 aIndex, PRInt32* aColumn)
{
NS_ENSURE_ARG_POINTER(aColumn);
*aColumn = -1;
PRInt32 columnCount = 0;
nsresult rv = GetColumnCount(&columnCount);
NS_ENSURE_SUCCESS(rv, rv);
*aColumn = aIndex % columnCount;
return NS_OK;
}
NS_IMETHODIMP
XULListboxAccessible::GetRowIndexAt(PRInt32 aIndex, PRInt32* aRow)
{
NS_ENSURE_ARG_POINTER(aRow);
*aRow = -1;
PRInt32 columnCount = 0;
nsresult rv = GetColumnCount(&columnCount);
NS_ENSURE_SUCCESS(rv, rv);
*aRow = aIndex / columnCount;
return NS_OK;
}
NS_IMETHODIMP
XULListboxAccessible::GetRowAndColumnIndicesAt(PRInt32 aCellIndex,
PRInt32* aRowIndex,
PRInt32* aColumnIndex)
{
NS_ENSURE_ARG_POINTER(aRowIndex);
*aRowIndex = -1;
NS_ENSURE_ARG_POINTER(aColumnIndex);
*aColumnIndex = -1;
if (IsDefunct())
return NS_ERROR_FAILURE;
PRInt32 columnCount = 0;
nsresult rv = GetColumnCount(&columnCount);
NS_ENSURE_SUCCESS(rv, rv);
*aColumnIndex = aCellIndex % columnCount;
*aRowIndex = aCellIndex / columnCount;
return NS_OK;
}
bool
XULListboxAccessible::IsColSelected(PRUint32 aColIdx)
{

View File

@ -180,57 +180,6 @@ XULTreeGridAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
return rowAcc->GetCellAccessible(column);
}
NS_IMETHODIMP
XULTreeGridAccessible::GetColumnIndexAt(PRInt32 aCellIndex,
PRInt32* aColumnIndex)
{
NS_ENSURE_ARG_POINTER(aColumnIndex);
*aColumnIndex = -1;
PRInt32 columnCount = 0;
nsresult rv = GetColumnCount(&columnCount);
NS_ENSURE_SUCCESS(rv, rv);
*aColumnIndex = aCellIndex % columnCount;
return NS_OK;
}
NS_IMETHODIMP
XULTreeGridAccessible::GetRowIndexAt(PRInt32 aCellIndex, PRInt32* aRowIndex)
{
NS_ENSURE_ARG_POINTER(aRowIndex);
*aRowIndex = -1;
PRInt32 columnCount;
nsresult rv = GetColumnCount(&columnCount);
NS_ENSURE_SUCCESS(rv, rv);
*aRowIndex = aCellIndex / columnCount;
return NS_OK;
}
NS_IMETHODIMP
XULTreeGridAccessible::GetRowAndColumnIndicesAt(PRInt32 aCellIndex,
PRInt32* aRowIndex,
PRInt32* aColumnIndex)
{
NS_ENSURE_ARG_POINTER(aRowIndex);
*aRowIndex = -1;
NS_ENSURE_ARG_POINTER(aColumnIndex);
*aColumnIndex = -1;
if (IsDefunct())
return NS_ERROR_FAILURE;
PRInt32 columnCount = 0;
nsresult rv = GetColumnCount(&columnCount);
NS_ENSURE_SUCCESS(rv, rv);
*aColumnIndex = aCellIndex % columnCount;
*aRowIndex = aCellIndex / columnCount;
return NS_OK;
}
void
XULTreeGridAccessible::ColDescription(PRUint32 aColIdx, nsString& aDescription)
{