2009-05-18 01:35:21 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
#include "ARIAGridAccessible.h"
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-04-13 07:17:03 -07:00
|
|
|
#include "Accessible-inl.h"
|
2010-06-21 06:08:27 -07:00
|
|
|
#include "AccIterator.h"
|
|
|
|
#include "nsAccUtils.h"
|
2012-01-11 19:07:35 -08:00
|
|
|
#include "Role.h"
|
2011-04-09 16:38:06 -07:00
|
|
|
#include "States.h"
|
2010-04-26 23:52:03 -07:00
|
|
|
|
|
|
|
#include "nsIMutableArray.h"
|
2009-09-10 18:07:56 -07:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
using namespace mozilla;
|
2011-07-27 05:43:01 -07:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2009-05-18 01:35:21 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-09 03:18:03 -07:00
|
|
|
// ARIAGridAccessible
|
2009-05-18 01:35:21 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::
|
2012-05-27 02:01:40 -07:00
|
|
|
ARIAGridAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap(aContent, aDoc), xpcAccessibleTable(this)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(ARIAGridAccessible,
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible,
|
2009-05-18 01:35:21 -07:00
|
|
|
nsIAccessibleTable)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-03-27 17:53:58 -07:00
|
|
|
//nsAccessNode
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-03-27 17:53:58 -07:00
|
|
|
void
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::Shutdown()
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2012-03-27 17:53:58 -07:00
|
|
|
mTable = nsnull;
|
2012-05-28 18:18:45 -07:00
|
|
|
AccessibleWrap::Shutdown();
|
2012-03-27 17:32:49 -07:00
|
|
|
}
|
2012-03-27 15:23:29 -07:00
|
|
|
|
2012-03-27 17:53:58 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessibleTable
|
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRUint32
|
|
|
|
ARIAGridAccessible::ColCount()
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = rowIter.Next();
|
2011-08-05 01:10:41 -07:00
|
|
|
if (!row)
|
2012-04-19 14:32:11 -07:00
|
|
|
return 0;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRUint32 colCount = 0;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next()))
|
2012-04-19 14:32:11 -07:00
|
|
|
colCount++;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
return colCount;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
PRUint32
|
|
|
|
ARIAGridAccessible::RowCount()
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2012-04-19 14:32:11 -07:00
|
|
|
PRUint32 rowCount = 0;
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2011-08-09 18:44:00 -07:00
|
|
|
while (rowIter.Next())
|
2012-04-19 14:32:11 -07:00
|
|
|
rowCount++;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-04-19 14:32:11 -07:00
|
|
|
return rowCount;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-05-22 09:41:01 -07:00
|
|
|
ARIAGridAccessible::CellAt(PRUint32 aRowIndex, PRUint32 aColumnIndex)
|
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = GetRowAt(aRowIndex);
|
2012-05-22 09:41:01 -07:00
|
|
|
if (!row)
|
|
|
|
return nsnull;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-05-22 09:41:01 -07:00
|
|
|
return GetCellInRowAt(row, aColumnIndex);
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetColumnIndexAt(PRInt32 aCellIndex,
|
|
|
|
PRInt32* aColumnIndex)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aColumnIndex);
|
|
|
|
*aColumnIndex = -1;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG(aCellIndex >= 0);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetRowCount(&rowCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 colsCount = 0;
|
|
|
|
GetColumnCount(&colsCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG(aCellIndex < rowCount * colsCount);
|
|
|
|
|
|
|
|
*aColumnIndex = aCellIndex % colsCount;
|
2009-05-18 01:35:21 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetRowIndexAt(PRInt32 aCellIndex, PRInt32* aRowIndex)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRowIndex);
|
|
|
|
*aRowIndex = -1;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG(aCellIndex >= 0);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetRowCount(&rowCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRInt32 colsCount = 0;
|
|
|
|
GetColumnCount(&colsCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
NS_ENSURE_ARG(aCellIndex < rowCount * colsCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
*aRowIndex = aCellIndex / colsCount;
|
2009-05-18 01:35:21 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-02 20:16:52 -07:00
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetRowAndColumnIndicesAt(PRInt32 aCellIndex,
|
|
|
|
PRInt32* aRowIndex,
|
|
|
|
PRInt32* aColumnIndex)
|
2010-07-02 20:16:52 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-06-15 01:03:51 -07:00
|
|
|
bool
|
|
|
|
ARIAGridAccessible::IsColSelected(PRUint32 aColIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = rowIter.Next();
|
2009-06-12 05:52:29 -07:00
|
|
|
if (!row)
|
2012-06-15 01:03:51 -07:00
|
|
|
return false;
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
do {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!nsAccUtils::IsARIASelected(row)) {
|
2012-06-15 01:03:51 -07:00
|
|
|
Accessible* cell = GetCellInRowAt(row, aColIdx);
|
|
|
|
if (!cell || !nsAccUtils::IsARIASelected(cell))
|
|
|
|
return false;
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
} while ((row = rowIter.Next()));
|
2009-06-12 05:52:29 -07:00
|
|
|
|
2012-06-15 01:03:51 -07:00
|
|
|
return true;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:03:51 -07:00
|
|
|
bool
|
|
|
|
ARIAGridAccessible::IsRowSelected(PRUint32 aRowIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2012-06-15 01:03:51 -07:00
|
|
|
Accessible* row = GetRowAt(aRowIdx);
|
|
|
|
if(!row)
|
|
|
|
return false;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!nsAccUtils::IsARIASelected(row)) {
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next())) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!nsAccUtils::IsARIASelected(cell))
|
2012-06-15 01:03:51 -07:00
|
|
|
return false;
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-15 01:03:51 -07:00
|
|
|
return true;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:03:51 -07:00
|
|
|
bool
|
|
|
|
ARIAGridAccessible::IsCellSelected(PRUint32 aRowIdx, PRUint32 aColIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2012-06-15 01:03:51 -07:00
|
|
|
Accessible* row = GetRowAt(aRowIdx);
|
|
|
|
if(!row)
|
|
|
|
return false;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!nsAccUtils::IsARIASelected(row)) {
|
2012-06-15 01:03:51 -07:00
|
|
|
Accessible* cell = GetCellInRowAt(row, aColIdx);
|
|
|
|
if (!cell || !nsAccUtils::IsARIASelected(cell))
|
|
|
|
return false;
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
|
|
|
|
2012-06-15 01:03:51 -07:00
|
|
|
return true;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedCellCount(PRUint32* aCount)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-06-12 05:52:29 -07:00
|
|
|
PRInt32 colCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetColumnCount(&colCount);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((row = rowIter.Next())) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(row)) {
|
2009-06-12 05:52:29 -07:00
|
|
|
(*aCount) += colCount;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next())) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(cell))
|
2009-06-12 05:52:29 -07:00
|
|
|
(*aCount)++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedColumnCount(PRUint32* aCount)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2009-06-12 05:52:29 -07:00
|
|
|
return GetSelectedColumnsArray(aCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedRowCount(PRUint32* aCount)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCount);
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((row = rowIter.Next())) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(row)) {
|
2009-06-12 05:52:29 -07:00
|
|
|
(*aCount)++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = cellIter.Next();
|
2009-06-12 05:52:29 -07:00
|
|
|
if (!cell)
|
|
|
|
continue;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isRowSelected = true;
|
2009-06-12 05:52:29 -07:00
|
|
|
do {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!nsAccUtils::IsARIASelected(cell)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isRowSelected = false;
|
2009-06-12 05:52:29 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
} while ((cell = cellIter.Next()));
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
if (isRowSelected)
|
|
|
|
(*aCount)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedCells(nsIArray** aCells)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCells);
|
|
|
|
*aCells = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIMutableArray> selCells =
|
|
|
|
do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((row = rowIter.Next())) {
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(row)) {
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next()))
|
2011-10-17 07:59:28 -07:00
|
|
|
selCells->AppendElement(static_cast<nsIAccessible *>(cell), false);
|
2009-09-10 18:07:56 -07:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next())) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(cell))
|
2011-10-17 07:59:28 -07:00
|
|
|
selCells->AppendElement(static_cast<nsIAccessible *>(cell), false);
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aCells = selCells);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedCellIndices(PRUint32* aCellsCount,
|
|
|
|
PRInt32** aCells)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aCellsCount);
|
|
|
|
*aCellsCount = 0;
|
|
|
|
NS_ENSURE_ARG_POINTER(aCells);
|
|
|
|
*aCells = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-06-12 05:52:29 -07:00
|
|
|
PRInt32 rowCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetRowCount(&rowCount);
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
PRInt32 colCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetColumnCount(&colCount);
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
nsTArray<PRInt32> selCells(rowCount * colCount);
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
for (PRInt32 rowIdx = 0; (row = rowIter.Next()); rowIdx++) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(row)) {
|
2009-06-12 05:52:29 -07:00
|
|
|
for (PRInt32 colIdx = 0; colIdx < colCount; colIdx++)
|
|
|
|
selCells.AppendElement(rowIdx * colCount + colIdx);
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
for (PRInt32 colIdx = 0; (cell = cellIter.Next()); colIdx++) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(cell))
|
2009-06-12 05:52:29 -07:00
|
|
|
selCells.AppendElement(rowIdx * colCount + colIdx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 selCellsCount = selCells.Length();
|
|
|
|
if (!selCellsCount)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
*aCells = static_cast<PRInt32*>(
|
|
|
|
nsMemory::Clone(selCells.Elements(), selCellsCount * sizeof(PRInt32)));
|
|
|
|
NS_ENSURE_TRUE(*aCells, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
*aCellsCount = selCellsCount;
|
|
|
|
return NS_OK;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedColumnIndices(PRUint32* aColumnCount,
|
|
|
|
PRInt32** aColumns)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumns);
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
return GetSelectedColumnsArray(aColumnCount, aColumns);
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedRowIndices(PRUint32* aRowCount,
|
|
|
|
PRInt32** aRows)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2012-04-09 03:18:03 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRowCount);
|
|
|
|
*aRowCount = 0;
|
2009-05-18 01:35:21 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aRows);
|
|
|
|
*aRows = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2009-06-12 05:52:29 -07:00
|
|
|
PRInt32 rowCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetRowCount(&rowCount);
|
2009-06-12 05:52:29 -07:00
|
|
|
if (!rowCount)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsTArray<PRInt32> selRows(rowCount);
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
for (PRInt32 rowIdx = 0; (row = rowIter.Next()); rowIdx++) {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(row)) {
|
2009-06-12 05:52:29 -07:00
|
|
|
selRows.AppendElement(rowIdx);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = cellIter.Next();
|
2009-06-12 05:52:29 -07:00
|
|
|
if (!cell)
|
|
|
|
continue;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isRowSelected = true;
|
2009-06-12 05:52:29 -07:00
|
|
|
do {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (!nsAccUtils::IsARIASelected(cell)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isRowSelected = false;
|
2009-06-12 05:52:29 -07:00
|
|
|
break;
|
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
} while ((cell = cellIter.Next()));
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
if (isRowSelected)
|
|
|
|
selRows.AppendElement(rowIdx);
|
|
|
|
}
|
|
|
|
|
2009-09-10 18:07:56 -07:00
|
|
|
PRUint32 selrowCount = selRows.Length();
|
|
|
|
if (!selrowCount)
|
2009-06-12 05:52:29 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
*aRows = static_cast<PRInt32*>(
|
2009-09-10 18:07:56 -07:00
|
|
|
nsMemory::Clone(selRows.Elements(), selrowCount * sizeof(PRInt32)));
|
2009-06-12 05:52:29 -07:00
|
|
|
NS_ENSURE_TRUE(*aRows, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
*aRowCount = selrowCount;
|
2009-06-12 05:52:29 -07:00
|
|
|
return NS_OK;
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 22:25:07 -07:00
|
|
|
void
|
|
|
|
ARIAGridAccessible::SelectRow(PRUint32 aRowIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
for (PRInt32 rowIdx = 0; (row = rowIter.Next()); rowIdx++) {
|
2012-06-10 22:25:07 -07:00
|
|
|
nsresult rv = SetARIASelected(row, rowIdx == aRowIdx);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "SetARIASelected() Shouldn't fail!");
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 22:25:07 -07:00
|
|
|
void
|
|
|
|
ARIAGridAccessible::SelectCol(PRUint32 aColIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((row = rowIter.Next())) {
|
2009-06-12 05:52:29 -07:00
|
|
|
// Unselect all cells in the row.
|
2011-10-17 07:59:28 -07:00
|
|
|
nsresult rv = SetARIASelected(row, false);
|
2012-06-10 22:25:07 -07:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "SetARIASelected() Shouldn't fail!");
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
// Select cell at the column index.
|
2012-06-10 22:25:07 -07:00
|
|
|
Accessible* cell = GetCellInRowAt(row, aColIdx);
|
|
|
|
if (cell)
|
|
|
|
SetARIASelected(cell, true);
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:19:59 -07:00
|
|
|
void
|
|
|
|
ARIAGridAccessible::UnselectRow(PRUint32 aRowIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = GetRowAt(aRowIdx);
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2012-04-26 04:19:59 -07:00
|
|
|
if (row)
|
|
|
|
SetARIASelected(row, false);
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
2012-04-26 04:19:59 -07:00
|
|
|
void
|
|
|
|
ARIAGridAccessible::UnselectCol(PRUint32 aColIdx)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((row = rowIter.Next())) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = GetCellInRowAt(row, aColIdx);
|
2012-04-26 04:19:59 -07:00
|
|
|
if (cell)
|
|
|
|
SetARIASelected(cell, false);
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
2009-05-18 01:35:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Protected
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::IsValidRow(PRInt32 aRow)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
if (aRow < 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
PRInt32 rowCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetRowCount(&rowCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
return aRow < rowCount;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::IsValidColumn(PRInt32 aColumn)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
if (aColumn < 0)
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
PRInt32 colCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetColumnCount(&colCount);
|
2009-05-18 01:35:21 -07:00
|
|
|
return aColumn < colCount;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetRowAt(PRInt32 aRow)
|
2009-06-12 05:52:29 -07:00
|
|
|
{
|
|
|
|
PRInt32 rowIdx = aRow;
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2009-06-12 05:52:29 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = rowIter.Next();
|
2011-08-09 18:44:00 -07:00
|
|
|
while (rowIdx != 0 && (row = rowIter.Next()))
|
2010-05-20 00:40:25 -07:00
|
|
|
rowIdx--;
|
2009-06-12 05:52:29 -07:00
|
|
|
|
2010-05-20 00:40:25 -07:00
|
|
|
return row;
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible*
|
|
|
|
ARIAGridAccessible::GetCellInRowAt(Accessible* aRow, PRInt32 aColumn)
|
2009-06-12 05:52:29 -07:00
|
|
|
{
|
2010-05-20 00:40:25 -07:00
|
|
|
PRInt32 colIdx = aColumn;
|
2009-06-12 05:52:29 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(aRow, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = cellIter.Next();
|
2011-08-09 18:44:00 -07:00
|
|
|
while (colIdx != 0 && (cell = cellIter.Next()))
|
2010-05-20 00:40:25 -07:00
|
|
|
colIdx--;
|
2009-06-12 05:52:29 -07:00
|
|
|
|
2010-05-20 00:40:25 -07:00
|
|
|
return cell;
|
2009-06-12 05:52:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-05-28 18:18:45 -07:00
|
|
|
ARIAGridAccessible::SetARIASelected(Accessible* aAccessible,
|
2012-04-09 03:18:03 -07:00
|
|
|
bool aIsSelected, bool aNotify)
|
2009-06-12 05:52:29 -07:00
|
|
|
{
|
2010-06-11 01:23:18 -07:00
|
|
|
nsIContent *content = aAccessible->GetContent();
|
2010-05-20 00:40:25 -07:00
|
|
|
NS_ENSURE_STATE(content);
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
if (aIsSelected)
|
2011-06-03 14:35:17 -07:00
|
|
|
rv = content->SetAttr(kNameSpaceID_None, nsGkAtoms::aria_selected,
|
2009-06-12 05:52:29 -07:00
|
|
|
NS_LITERAL_STRING("true"), aNotify);
|
|
|
|
else
|
|
|
|
rv = content->UnsetAttr(kNameSpaceID_None,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_selected, aNotify);
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// No "smart" select/unselect for internal call.
|
|
|
|
if (!aNotify)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
// If row or cell accessible was selected then we're able to not bother about
|
|
|
|
// selection of its cells or its row because our algorithm is row oriented,
|
|
|
|
// i.e. we check selection on row firstly and then on cells.
|
|
|
|
if (aIsSelected)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = aAccessible->Role();
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
// If the given accessible is row that was unselected then remove
|
|
|
|
// aria-selected from cell accessible.
|
2012-01-11 19:07:35 -08:00
|
|
|
if (role == roles::ROW) {
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(aAccessible, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next())) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = SetARIASelected(cell, false, false);
|
2009-06-12 05:52:29 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the given accessible is cell that was unselected and its row is selected
|
|
|
|
// then remove aria-selected from row and put aria-selected on
|
|
|
|
// siblings cells.
|
2012-01-11 19:07:35 -08:00
|
|
|
if (role == roles::GRID_CELL || role == roles::ROWHEADER ||
|
|
|
|
role == roles::COLUMNHEADER) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = aAccessible->Parent();
|
2009-06-12 05:52:29 -07:00
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (row && row->Role() == roles::ROW &&
|
2009-09-10 18:07:56 -07:00
|
|
|
nsAccUtils::IsARIASelected(row)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = SetARIASelected(row, false, false);
|
2009-06-12 05:52:29 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
while ((cell = cellIter.Next())) {
|
2009-06-12 05:52:29 -07:00
|
|
|
if (cell != aAccessible) {
|
2011-10-17 07:59:28 -07:00
|
|
|
rv = SetARIASelected(cell, true, false);
|
2009-06-12 05:52:29 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridAccessible::GetSelectedColumnsArray(PRUint32* aColumnCount,
|
|
|
|
PRInt32** aColumns)
|
2009-06-12 05:52:29 -07:00
|
|
|
{
|
2012-04-09 03:18:03 -07:00
|
|
|
NS_ENSURE_ARG_POINTER(aColumnCount);
|
|
|
|
*aColumnCount = 0;
|
2009-06-12 05:52:29 -07:00
|
|
|
if (aColumns)
|
|
|
|
*aColumns = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator rowIter(this, filters::GetRow);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = rowIter.Next();
|
2009-06-12 05:52:29 -07:00
|
|
|
if (!row)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 colCount = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
GetColumnCount(&colCount);
|
2009-06-12 05:52:29 -07:00
|
|
|
if (!colCount)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 selColCount = colCount;
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
nsTArray<bool> isColSelArray(selColCount);
|
2009-06-12 05:52:29 -07:00
|
|
|
isColSelArray.AppendElements(selColCount);
|
|
|
|
for (PRInt32 i = 0; i < selColCount; i++)
|
2011-10-17 07:59:28 -07:00
|
|
|
isColSelArray[i] = true;
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
do {
|
2009-09-10 18:07:56 -07:00
|
|
|
if (nsAccUtils::IsARIASelected(row))
|
2009-06-12 05:52:29 -07:00
|
|
|
continue;
|
|
|
|
|
|
|
|
PRInt32 colIdx = 0;
|
2010-05-20 00:40:25 -07:00
|
|
|
|
2010-06-21 06:08:27 -07:00
|
|
|
AccIterator cellIter(row, filters::GetCell);
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = nsnull;
|
2011-08-09 18:44:00 -07:00
|
|
|
for (colIdx = 0; (cell = cellIter.Next()); colIdx++) {
|
2011-10-17 07:59:28 -07:00
|
|
|
if (isColSelArray.SafeElementAt(colIdx, false) &&
|
2009-09-10 18:07:56 -07:00
|
|
|
!nsAccUtils::IsARIASelected(cell)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
isColSelArray[colIdx] = false;
|
2009-06-12 05:52:29 -07:00
|
|
|
selColCount--;
|
|
|
|
}
|
|
|
|
}
|
2011-08-09 18:44:00 -07:00
|
|
|
} while ((row = rowIter.Next()));
|
2009-06-12 05:52:29 -07:00
|
|
|
|
|
|
|
if (!selColCount)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!aColumns) {
|
2012-04-09 03:18:03 -07:00
|
|
|
*aColumnCount = selColCount;
|
2009-06-12 05:52:29 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aColumns = static_cast<PRInt32*>(
|
|
|
|
nsMemory::Alloc(selColCount * sizeof(PRInt32)));
|
|
|
|
NS_ENSURE_TRUE(*aColumns, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
*aColumnCount = selColCount;
|
2009-06-12 05:52:29 -07:00
|
|
|
for (PRInt32 colIdx = 0, idx = 0; colIdx < colCount; colIdx++) {
|
|
|
|
if (isColSelArray[colIdx])
|
|
|
|
(*aColumns)[idx++] = colIdx;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-04-09 03:18:03 -07:00
|
|
|
// ARIAGridCellAccessible
|
2009-05-18 01:35:21 -07:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Constructor
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::
|
2012-05-27 02:01:40 -07:00
|
|
|
ARIAGridCellAccessible(nsIContent* aContent, DocAccessible* aDoc) :
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessibleWrap(aContent, aDoc)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsISupports
|
|
|
|
|
2012-04-09 03:18:03 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(ARIAGridCellAccessible,
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessible,
|
2009-09-10 18:07:56 -07:00
|
|
|
nsIAccessibleTableCell)
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIAccessibleTableCell
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetTable(nsIAccessibleTable** aTable)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aTable);
|
|
|
|
*aTable = nsnull;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* thisRow = Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (!thisRow || thisRow->Role() != roles::ROW)
|
2009-09-10 18:07:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* table = thisRow->Parent();
|
2010-09-06 19:41:53 -07:00
|
|
|
if (!table)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role tableRole = table->Role();
|
|
|
|
if (tableRole != roles::TABLE && tableRole != roles::TREE_TABLE)
|
2009-09-10 18:07:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
CallQueryInterface(table, aTable);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetColumnIndex(PRInt32* aColumnIndex)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aColumnIndex);
|
|
|
|
*aColumnIndex = -1;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = Parent();
|
2010-09-06 19:41:53 -07:00
|
|
|
if (!row)
|
|
|
|
return NS_OK;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2010-09-06 19:41:53 -07:00
|
|
|
*aColumnIndex = 0;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2011-06-13 02:08:40 -07:00
|
|
|
PRInt32 indexInRow = IndexInParent();
|
2010-09-06 19:41:53 -07:00
|
|
|
for (PRInt32 idx = 0; idx < indexInRow; idx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* cell = row->GetChildAt(idx);
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = cell->Role();
|
|
|
|
if (role == roles::GRID_CELL || role == roles::ROWHEADER ||
|
|
|
|
role == roles::COLUMNHEADER)
|
2009-09-10 18:07:56 -07:00
|
|
|
(*aColumnIndex)++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetRowIndex(PRInt32* aRowIndex)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aRowIndex);
|
|
|
|
*aRowIndex = -1;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = Parent();
|
2010-09-06 19:41:53 -07:00
|
|
|
if (!row)
|
|
|
|
return NS_OK;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* table = row->Parent();
|
2010-09-06 19:41:53 -07:00
|
|
|
if (!table)
|
|
|
|
return NS_OK;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
2010-09-06 19:41:53 -07:00
|
|
|
*aRowIndex = 0;
|
|
|
|
|
2011-06-13 02:08:40 -07:00
|
|
|
PRInt32 indexInTable = row->IndexInParent();
|
2010-09-06 19:41:53 -07:00
|
|
|
for (PRInt32 idx = 0; idx < indexInTable; idx++) {
|
|
|
|
row = table->GetChildAt(idx);
|
2012-01-11 19:07:35 -08:00
|
|
|
if (row->Role() == roles::ROW)
|
2010-09-06 19:41:53 -07:00
|
|
|
(*aRowIndex)++;
|
2009-09-10 18:07:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetColumnExtent(PRInt32* aExtentCount)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aExtentCount);
|
|
|
|
*aExtentCount = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aExtentCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetRowExtent(PRInt32* aExtentCount)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aExtentCount);
|
|
|
|
*aExtentCount = 0;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
*aExtentCount = 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetColumnHeaderCells(nsIArray** aHeaderCells)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeaderCells);
|
|
|
|
*aHeaderCells = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleTable> table;
|
|
|
|
GetTable(getter_AddRefs(table));
|
|
|
|
if (!table)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return nsAccUtils::GetHeaderCellsFor(table, this,
|
|
|
|
nsAccUtils::eColumnHeaderCells,
|
|
|
|
aHeaderCells);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetRowHeaderCells(nsIArray** aHeaderCells)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aHeaderCells);
|
|
|
|
*aHeaderCells = nsnull;
|
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAccessibleTable> table;
|
|
|
|
GetTable(getter_AddRefs(table));
|
|
|
|
if (!table)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
return nsAccUtils::GetHeaderCellsFor(table, this,
|
|
|
|
nsAccUtils::eRowHeaderCells,
|
|
|
|
aHeaderCells);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::IsSelected(bool* aIsSelected)
|
2009-09-10 18:07:56 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aIsSelected);
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = false;
|
2009-09-10 18:07:56 -07:00
|
|
|
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (!row || row->Role() != roles::ROW)
|
2009-09-10 18:07:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!nsAccUtils::IsARIASelected(row) && !nsAccUtils::IsARIASelected(this))
|
|
|
|
return NS_OK;
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
*aIsSelected = true;
|
2009-09-10 18:07:56 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-05-18 01:35:21 -07:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-05-28 18:18:45 -07:00
|
|
|
// Accessible
|
2009-05-18 01:35:21 -07:00
|
|
|
|
2011-04-09 16:38:06 -07:00
|
|
|
void
|
2012-05-17 02:37:37 -07:00
|
|
|
ARIAGridCellAccessible::ApplyARIAState(PRUint64* aState) const
|
2009-07-01 01:10:15 -07:00
|
|
|
{
|
2012-05-31 01:04:41 -07:00
|
|
|
HyperTextAccessibleWrap::ApplyARIAState(aState);
|
2009-07-01 01:10:15 -07:00
|
|
|
|
|
|
|
// Return if the gridcell has aria-selected="true".
|
2011-04-09 16:38:06 -07:00
|
|
|
if (*aState & states::SELECTED)
|
|
|
|
return;
|
2009-07-01 01:10:15 -07:00
|
|
|
|
|
|
|
// Check aria-selected="true" on the row.
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* row = Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (!row || row->Role() != roles::ROW)
|
2011-04-09 16:38:06 -07:00
|
|
|
return;
|
2009-07-01 01:10:15 -07:00
|
|
|
|
2010-06-11 21:04:50 -07:00
|
|
|
nsIContent *rowContent = row->GetContent();
|
2009-07-01 01:10:15 -07:00
|
|
|
if (nsAccUtils::HasDefinedARIAToken(rowContent,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_selected) &&
|
2009-07-01 01:10:15 -07:00
|
|
|
!rowContent->AttrValueIs(kNameSpaceID_None,
|
2011-06-03 14:35:17 -07:00
|
|
|
nsGkAtoms::aria_selected,
|
|
|
|
nsGkAtoms::_false, eCaseMatters))
|
2011-04-09 16:38:06 -07:00
|
|
|
*aState |= states::SELECTABLE | states::SELECTED;
|
2009-07-01 01:10:15 -07:00
|
|
|
}
|
|
|
|
|
2009-05-18 01:35:21 -07:00
|
|
|
nsresult
|
2012-04-09 03:18:03 -07:00
|
|
|
ARIAGridCellAccessible::GetAttributesInternal(nsIPersistentProperties* aAttributes)
|
2009-05-18 01:35:21 -07:00
|
|
|
{
|
|
|
|
if (IsDefunct())
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2012-05-31 01:04:41 -07:00
|
|
|
nsresult rv = HyperTextAccessibleWrap::GetAttributesInternal(aAttributes);
|
2009-05-18 01:35:21 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Expose "table-cell-index" attribute.
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* thisRow = Parent();
|
2012-01-11 19:07:35 -08:00
|
|
|
if (!thisRow || thisRow->Role() != roles::ROW)
|
2009-05-18 01:35:21 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 colIdx = 0, colCount = 0;
|
2012-05-25 03:53:45 -07:00
|
|
|
PRUint32 childCount = thisRow->ChildCount();
|
|
|
|
for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = thisRow->GetChildAt(childIdx);
|
2009-05-18 01:35:21 -07:00
|
|
|
if (child == this)
|
|
|
|
colIdx = colCount;
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role role = child->Role();
|
|
|
|
if (role == roles::GRID_CELL || role == roles::ROWHEADER ||
|
|
|
|
role == roles::COLUMNHEADER)
|
2009-05-18 01:35:21 -07:00
|
|
|
colCount++;
|
|
|
|
}
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* table = thisRow->Parent();
|
2010-09-06 19:41:53 -07:00
|
|
|
if (!table)
|
|
|
|
return NS_OK;
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
roles::Role tableRole = table->Role();
|
|
|
|
if (tableRole != roles::TABLE && tableRole != roles::TREE_TABLE)
|
2009-05-18 01:35:21 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
PRInt32 rowIdx = 0;
|
2012-05-25 03:53:45 -07:00
|
|
|
childCount = table->ChildCount();
|
|
|
|
for (PRUint32 childIdx = 0; childIdx < childCount; childIdx++) {
|
2012-05-28 18:18:45 -07:00
|
|
|
Accessible* child = table->GetChildAt(childIdx);
|
2010-05-18 07:03:56 -07:00
|
|
|
if (child == thisRow)
|
|
|
|
break;
|
|
|
|
|
2012-01-11 19:07:35 -08:00
|
|
|
if (child->Role() == roles::ROW)
|
2009-05-18 01:35:21 -07:00
|
|
|
rowIdx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 idx = rowIdx * colCount + colIdx;
|
|
|
|
|
|
|
|
nsAutoString stringIdx;
|
|
|
|
stringIdx.AppendInt(idx);
|
2011-06-03 14:35:17 -07:00
|
|
|
nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::tableCellIndex,
|
2009-05-18 01:35:21 -07:00
|
|
|
stringIdx);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|