accessible/src/generic/TableCellAccessible.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/accessible/src/generic/TableCellAccessible.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,67 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "TableCellAccessible.h"
    1.11 +
    1.12 +#include "Accessible-inl.h"
    1.13 +#include "TableAccessible.h"
    1.14 +
    1.15 +using namespace mozilla;
    1.16 +using namespace mozilla::a11y;
    1.17 +
    1.18 +void
    1.19 +TableCellAccessible::RowHeaderCells(nsTArray<Accessible*>* aCells)
    1.20 +{
    1.21 +  uint32_t rowIdx = RowIdx(), colIdx = ColIdx();
    1.22 +  TableAccessible* table = Table();
    1.23 +  if (!table)
    1.24 +    return;
    1.25 +
    1.26 +  // Move to the left to find row header cells
    1.27 +  for (uint32_t curColIdx = colIdx - 1; curColIdx < colIdx; curColIdx--) {
    1.28 +    Accessible* cell = table->CellAt(rowIdx, curColIdx);
    1.29 +    if (!cell)
    1.30 +      continue;
    1.31 +
    1.32 +    // CellAt should always return a TableCellAccessible (XXX Bug 587529)
    1.33 +    TableCellAccessible* tableCell = cell->AsTableCell();
    1.34 +    NS_ASSERTION(tableCell, "cell should be a table cell!");
    1.35 +    if (!tableCell)
    1.36 +      continue;
    1.37 +
    1.38 +    // Avoid addding cells multiple times, if this cell spans more columns
    1.39 +    // we'll get it later.
    1.40 +    if (tableCell->ColIdx() == curColIdx && cell->Role() == roles::ROWHEADER)
    1.41 +      aCells->AppendElement(cell);
    1.42 +  }
    1.43 +}
    1.44 +
    1.45 +void
    1.46 +TableCellAccessible::ColHeaderCells(nsTArray<Accessible*>* aCells)
    1.47 +{
    1.48 +  uint32_t rowIdx = RowIdx(), colIdx = ColIdx();
    1.49 +  TableAccessible* table = Table();
    1.50 +  if (!table)
    1.51 +    return;
    1.52 +
    1.53 +  // Move up to find column header cells
    1.54 +  for (uint32_t curRowIdx = rowIdx - 1; curRowIdx < rowIdx; curRowIdx--) {
    1.55 +    Accessible* cell = table->CellAt(curRowIdx, colIdx);
    1.56 +    if (!cell)
    1.57 +      continue;
    1.58 +
    1.59 +    // CellAt should always return a TableCellAccessible (XXX Bug 587529)
    1.60 +    TableCellAccessible* tableCell = cell->AsTableCell();
    1.61 +    NS_ASSERTION(tableCell, "cell should be a table cell!");
    1.62 +    if (!tableCell)
    1.63 +      continue;
    1.64 +
    1.65 +    // Avoid addding cells multiple times, if this cell spans more rows
    1.66 +    // we'll get it later.
    1.67 +    if (tableCell->RowIdx() == curRowIdx && cell->Role() == roles::COLUMNHEADER)
    1.68 +      aCells->AppendElement(cell);
    1.69 +  }
    1.70 +}

mercurial