Commit 08c98946 authored by surkov.alexander@gmail.com's avatar surkov.alexander@gmail.com
Browse files

Bug 385573 - implement IAccessibleTable::getSelected* methods, r=evan.yan, aaronlev, sr=neil

parent 7a634232
Loading
Loading
Loading
Loading
+51 −7
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@

interface nsIAccessible;

[scriptable, uuid(dc13d184-a6df-45a1-92f0-5476fdaebc5a)]
[scriptable, uuid(dcc1e5c3-966e-45b2-b30a-839d35432b24)]
interface nsIAccessibleTable : nsISupports
{
  readonly attribute nsIAccessible       caption;
@@ -65,10 +65,30 @@ interface nsIAccessibleTable : nsISupports
  nsIAccessible cellRefAt(in long row, in long column);

  /**
      * get an index
   * Translates the given row and column indices into the corresponding cell
   * index.
   *
   * @param row - index of the row of the table for which to return the cell
   *              index.
   * @param column - index of the column of the table for which to return
   *                 the cell index.
   */
  long getIndexAt(in long row, in long column);

  /**
   * Translates the given child index into the corresponding column index.
   *
   * @param index - index of the child of the table for which to return
   *                the column index.
   */
  long getColumnAtIndex(in long index);

  /**
   * Translates the given child index into the corresponding row index.
   *
   * @param index - index of the child of the table for which to return
   *                the row index.
   */
  long getRowAtIndex(in long index);

  /**
@@ -136,6 +156,30 @@ interface nsIAccessibleTable : nsISupports
   */
  boolean isCellSelected(in long row, in long column);

  /**
   * Returns the total number of selected cells.
   */
  readonly attribute unsigned long selectedCellsCount;

  /**
   * Returns the total number of selected columns.
   */
  readonly attribute unsigned long selectedColumnsCount;

  /**
   * Returns the total number of selected rows.
   */
  readonly attribute unsigned long selectedRowsCount;

  /**
   * Returns a list of cells indexes currently selected.
   *
   * @param cellsSize - length of array
   * @param cells - array of indexes of selected cells
   */
  void getSelectedCells(out unsigned long cellsSize,
                        [retval, array, size_is(cellsSize)] out long cells);

  /**
   * Returns a list of column indexes currently selected.
   *
+50 −0
Original line number Diff line number Diff line
@@ -129,6 +129,31 @@ NS_IMETHODIMP nsXULTreeAccessibleWrap::GetRowHeader(nsIAccessibleTable **aRowHea
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeAccessibleWrap::GetSelectedCellsCount(PRUint32* aCount)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeAccessibleWrap::GetSelectedColumnsCount(PRUint32* aCount)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeAccessibleWrap::GetSelectedRowsCount(PRUint32* aCount)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeAccessibleWrap::GetSelectedCells(PRUint32 *aNumCells,
                                          PRInt32 **aCells)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsXULTreeAccessibleWrap::GetSelectedColumns(PRUint32 *aNumColumns, PRInt32 **aColumns)
{
  // If all the row has been selected, then all the columns are selected.
@@ -452,6 +477,31 @@ NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::GetRowHeader(nsIAccessibleTable *
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeColumnsAccessibleWrap::GetSelectedCellsCount(PRUint32* aCount)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeColumnsAccessibleWrap::GetSelectedColumnsCount(PRUint32* aCount)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeColumnsAccessibleWrap::GetSelectedRowsCount(PRUint32* aCount)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsXULTreeColumnsAccessibleWrap::GetSelectedCells(PRUint32 *aNumCells,
                                                 PRInt32 **aCells)
{
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP nsXULTreeColumnsAccessibleWrap::GetSelectedColumns(PRUint32 *columnsSize, PRInt32 **columns)
{
  // Header can not be selected.
+129 −0
Original line number Diff line number Diff line
@@ -306,6 +306,135 @@ nsHTMLTableAccessible::GetRowHeader(nsIAccessibleTable **aRowHeader)
  return NS_ERROR_NOT_IMPLEMENTED;
}

NS_IMETHODIMP
nsHTMLTableAccessible::GetSelectedCellsCount(PRUint32* aCount)
{
  NS_ENSURE_ARG_POINTER(aCount);
  *aCount = 0;

  PRInt32 rowsCount = 0;
  nsresult rv = GetRows(&rowsCount);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 columnsCount = 0;
  rv = GetColumns(&columnsCount);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 rowIndex;
  for (rowIndex = 0; rowIndex < rowsCount; rowIndex++) {
    PRInt32 columnIndex;
    for (columnIndex = 0; columnIndex < columnsCount; columnIndex++) {
      PRBool state = PR_FALSE;
      rv = IsCellSelected(rowIndex, columnIndex, &state);
      NS_ENSURE_SUCCESS(rv, rv);

      if (state)
        (*aCount)++;
    }
  }

  return NS_OK;
}

NS_IMETHODIMP
nsHTMLTableAccessible::GetSelectedColumnsCount(PRUint32* aCount)
{
  NS_ENSURE_ARG_POINTER(aCount);
  *aCount = 0;

  PRInt32 count = 0;
  nsresult rv = GetColumns(&count);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 index;
  for (index = 0; index < count; index++) {
    PRBool state = PR_FALSE;
    rv = IsColumnSelected(index, &state);
    NS_ENSURE_SUCCESS(rv, rv);

    if (state)
      (*aCount)++;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsHTMLTableAccessible::GetSelectedRowsCount(PRUint32* aCount)
{
  NS_ENSURE_ARG_POINTER(aCount);
  *aCount = 0;

  PRInt32 count = 0;
  nsresult rv = GetRows(&count);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 index;
  for (index = 0; index < count; index++) {
    PRBool state = PR_FALSE;
    rv = IsRowSelected(index, &state);
    NS_ENSURE_SUCCESS(rv, rv);

    if (state)
      (*aCount)++;
  }

  return NS_OK;
}

NS_IMETHODIMP
nsHTMLTableAccessible::GetSelectedCells(PRUint32 *aNumCells,
                                        PRInt32 **aCells)
{
  NS_ENSURE_ARG_POINTER(aNumCells);
  *aNumCells = 0;
  NS_ENSURE_ARG_POINTER(aCells);
  *aCells = nsnull;

  PRInt32 rowsCount = 0;
  nsresult rv = GetRows(&rowsCount);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 columnsCount = 0;
  rv = GetColumns(&columnsCount);
  NS_ENSURE_SUCCESS(rv, rv);

  PRInt32 cellsCount = columnsCount * rowsCount;
  nsAutoArrayPtr<PRBool> states(new PRBool[cellsCount]);
  NS_ENSURE_TRUE(states, NS_ERROR_OUT_OF_MEMORY);

  PRInt32 rowIndex, index;
  for (rowIndex = 0, index = 0; rowIndex < rowsCount; rowIndex++) {
    PRInt32 columnIndex;
    for (columnIndex = 0; columnIndex < columnsCount; columnIndex++, index++) {
      rv = IsCellSelected(rowIndex, columnIndex, &states[index]);
      NS_ENSURE_SUCCESS(rv, rv);

      if (states[index])
        (*aNumCells)++;
    }
  }

  PRInt32 *cellsArray =
    (PRInt32 *)nsMemory::Alloc((*aNumCells) * sizeof(PRInt32));
  NS_ENSURE_TRUE(cellsArray, NS_ERROR_OUT_OF_MEMORY);

  PRInt32 curr = 0;
  for (rowIndex = 0, index = 0; rowIndex < rowsCount; rowIndex++) {
    PRInt32 columnIndex;
    for (columnIndex = 0; columnIndex < columnsCount; columnIndex++, index++) {
      if (states[index]) {
        PRInt32 cellIndex = -1;
        GetIndexAt(rowIndex, columnIndex, &cellIndex);
        cellsArray[curr++] = cellIndex;
      }
    }
  }

  *aCells = cellsArray;
  return NS_OK;
}

NS_IMETHODIMP
nsHTMLTableAccessible::GetSelectedColumns(PRUint32 *aNumColumns,
                                          PRInt32 **aColumns)
+84 −13
Original line number Diff line number Diff line
@@ -267,21 +267,51 @@ STDMETHODIMP
CAccessibleTable::get_nSelectedChildren(long *aChildCount)
{
  *aChildCount = 0;
  return E_NOTIMPL;

  nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
  NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
  if (!tableAcc)
    return E_FAIL;

  PRUint32 count = 0;
  nsresult rv = tableAcc->GetSelectedCellsCount(&count);
  *aChildCount = count;

  return NS_FAILED(rv) ? E_FAIL : S_OK;
}

STDMETHODIMP
CAccessibleTable::get_nSelectedColumns(long *aColumnCount)
{
  *aColumnCount = 0;
  return E_NOTIMPL;

  nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
  NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
  if (!tableAcc)
    return E_FAIL;

  PRUint32 count = 0;
  nsresult rv = tableAcc->GetSelectedColumnsCount(&count);
  *aColumnCount = count;

  return NS_FAILED(rv) ? E_FAIL : S_OK;
}

STDMETHODIMP
CAccessibleTable::get_nSelectedRows(long *aRowCount)
{
  *aRowCount = 0;
  return E_NOTIMPL;

  nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
  NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
  if (!tableAcc)
    return E_FAIL;

  PRUint32 count = 0;
  nsresult rv = tableAcc->GetSelectedRowsCount(&count);
  *aRowCount = count;

  return NS_FAILED(rv) ? E_FAIL : S_OK;
}

STDMETHODIMP
@@ -371,28 +401,22 @@ CAccessibleTable::get_rowIndex(long aChildIndex, long *aRowIndex)

STDMETHODIMP
CAccessibleTable::get_selectedChildren(long aMaxChildren, long **aChildren,
                                       long *nChildren)
                                       long *aNChildren)
{
  *aChildren = NULL;
  *nChildren = 0;
  return E_NOTIMPL;
  return GetSelectedItems(aMaxChildren, aChildren, aNChildren, ITEMSTYPE_CELLS);
}

STDMETHODIMP
CAccessibleTable::get_selectedColumns(long aMaxColumns, long **aColumns,
                                      long *aNColumns)
{
  *aColumns = NULL;
  *aNColumns = 0;
  return E_NOTIMPL;
  return GetSelectedItems(aMaxColumns, aColumns, aNColumns, ITEMSTYPE_COLUMNS);
}

STDMETHODIMP
CAccessibleTable::get_selectedRows(long aMaxRows, long **aRows, long *aNRows)
{
  *aRows = NULL;
  *aNRows = 0;
  return E_NOTIMPL;
  return GetSelectedItems(aMaxRows, aRows, aNRows, ITEMSTYPE_ROWS);
}

STDMETHODIMP
@@ -517,3 +541,50 @@ CAccessibleTable::get_modelChange(IA2TableModelChange *aModelChange)
  return E_NOTIMPL;
}

// CAccessibleTable

HRESULT
CAccessibleTable::GetSelectedItems(long aMaxItems, long **aItems,
                                   long *aItemsCount, eItemsType aType)
{
  *aItemsCount = 0;

  nsCOMPtr<nsIAccessibleTable> tableAcc(do_QueryInterface(this));
  NS_ASSERTION(tableAcc, CANT_QUERY_ASSERTION_MSG);
  if (!tableAcc)
    return E_FAIL;

  PRUint32 size = 0;
  PRInt32 *items = NULL;

  nsresult rv = NS_OK;
  switch (aType) {
    case ITEMSTYPE_CELLS:
      rv = tableAcc->GetSelectedCells(&size, &items);
      break;
    case ITEMSTYPE_COLUMNS:
      rv = tableAcc->GetSelectedColumns(&size, &items);
      break;
    case ITEMSTYPE_ROWS:
      rv = tableAcc->GetSelectedRows(&size, &items);
      break;
    default:
      return E_FAIL;
  }

  if (NS_FAILED(rv))
    return E_FAIL;

  if (size == 0 || !items)
    return S_OK;

  PRUint32 maxSize = size < (PRUint32)aMaxItems ? size : aMaxItems;
  *aItemsCount = maxSize;

  for (PRUint32 index = 0; index < maxSize; ++index)
    (*aItems)[index] = items[index];

  nsMemory::Free(items);
  return S_OK;
}
+10 −0
Original line number Diff line number Diff line
@@ -169,6 +169,16 @@ public:

  virtual /* [propget] */ HRESULT STDMETHODCALLTYPE get_modelChange(
      /* [retval][out] */ IA2TableModelChange *modelChange);

private:
  enum eItemsType {
    ITEMSTYPE_CELLS,
    ITEMSTYPE_COLUMNS,
    ITEMSTYPE_ROWS
  };

  HRESULT GetSelectedItems(long aMaxItems, long **aItems, long *aItemsCount,
                           eItemsType aType);
};

#endif