TableCellAccessible.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "TableCellAccessible.h"
  6. #include "Accessible-inl.h"
  7. #include "TableAccessible.h"
  8. using namespace mozilla;
  9. using namespace mozilla::a11y;
  10. void
  11. TableCellAccessible::RowHeaderCells(nsTArray<Accessible*>* aCells)
  12. {
  13. uint32_t rowIdx = RowIdx(), colIdx = ColIdx();
  14. TableAccessible* table = Table();
  15. if (!table)
  16. return;
  17. // Move to the left to find row header cells
  18. for (uint32_t curColIdx = colIdx - 1; curColIdx < colIdx; curColIdx--) {
  19. Accessible* cell = table->CellAt(rowIdx, curColIdx);
  20. if (!cell)
  21. continue;
  22. // CellAt should always return a TableCellAccessible (XXX Bug 587529)
  23. TableCellAccessible* tableCell = cell->AsTableCell();
  24. NS_ASSERTION(tableCell, "cell should be a table cell!");
  25. if (!tableCell)
  26. continue;
  27. // Avoid addding cells multiple times, if this cell spans more columns
  28. // we'll get it later.
  29. if (tableCell->ColIdx() == curColIdx && cell->Role() == roles::ROWHEADER)
  30. aCells->AppendElement(cell);
  31. }
  32. }
  33. void
  34. TableCellAccessible::ColHeaderCells(nsTArray<Accessible*>* aCells)
  35. {
  36. uint32_t rowIdx = RowIdx(), colIdx = ColIdx();
  37. TableAccessible* table = Table();
  38. if (!table)
  39. return;
  40. // Move up to find column header cells
  41. for (uint32_t curRowIdx = rowIdx - 1; curRowIdx < rowIdx; curRowIdx--) {
  42. Accessible* cell = table->CellAt(curRowIdx, colIdx);
  43. if (!cell)
  44. continue;
  45. // CellAt should always return a TableCellAccessible (XXX Bug 587529)
  46. TableCellAccessible* tableCell = cell->AsTableCell();
  47. NS_ASSERTION(tableCell, "cell should be a table cell!");
  48. if (!tableCell)
  49. continue;
  50. // Avoid addding cells multiple times, if this cell spans more rows
  51. // we'll get it later.
  52. if (tableCell->RowIdx() == curRowIdx && cell->Role() == roles::COLUMNHEADER)
  53. aCells->AppendElement(cell);
  54. }
  55. }