TableAccessible.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. #ifndef TABLE_ACCESSIBLE_H
  6. #define TABLE_ACCESSIBLE_H
  7. #include "nsString.h"
  8. #include "nsTArray.h"
  9. namespace mozilla {
  10. namespace a11y {
  11. class Accessible;
  12. /**
  13. * Accessible table interface.
  14. */
  15. class TableAccessible
  16. {
  17. public:
  18. /**
  19. * Return the caption accessible if any for this table.
  20. */
  21. virtual Accessible* Caption() const { return nullptr; }
  22. /**
  23. * Get the summary for this table.
  24. */
  25. virtual void Summary(nsString& aSummary) { aSummary.Truncate(); }
  26. /**
  27. * Return the number of columns in the table.
  28. */
  29. virtual uint32_t ColCount() { return 0; }
  30. /**
  31. * Return the number of rows in the table.
  32. */
  33. virtual uint32_t RowCount() { return 0; }
  34. /**
  35. * Return the accessible for the cell at the given row and column indices.
  36. */
  37. virtual Accessible* CellAt(uint32_t aRowIdx, uint32_t aColIdx) { return nullptr; }
  38. /**
  39. * Return the index of the cell at the given row and column.
  40. */
  41. virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx)
  42. { return ColCount() * aRowIdx + aColIdx; }
  43. /**
  44. * Return the column index of the cell with the given index.
  45. */
  46. virtual int32_t ColIndexAt(uint32_t aCellIdx)
  47. { return aCellIdx % ColCount(); }
  48. /**
  49. * Return the row index of the cell with the given index.
  50. */
  51. virtual int32_t RowIndexAt(uint32_t aCellIdx)
  52. { return aCellIdx / ColCount(); }
  53. /**
  54. * Get the row and column indices for the cell at the given index.
  55. */
  56. virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
  57. int32_t* aColIdx)
  58. {
  59. uint32_t colCount = ColCount();
  60. *aRowIdx = aCellIdx / colCount;
  61. *aColIdx = aCellIdx % colCount;
  62. }
  63. /**
  64. * Return the number of columns occupied by the cell at the given row and
  65. * column indices.
  66. */
  67. virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { return 1; }
  68. /**
  69. * Return the number of rows occupied by the cell at the given row and column
  70. * indices.
  71. */
  72. virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { return 1; }
  73. /**
  74. * Get the description of the given column.
  75. */
  76. virtual void ColDescription(uint32_t aColIdx, nsString& aDescription)
  77. { aDescription.Truncate(); }
  78. /**
  79. * Get the description for the given row.
  80. */
  81. virtual void RowDescription(uint32_t aRowIdx, nsString& aDescription)
  82. { aDescription.Truncate(); }
  83. /**
  84. * Return true if the given column is selected.
  85. */
  86. virtual bool IsColSelected(uint32_t aColIdx) { return false; }
  87. /**
  88. * Return true if the given row is selected.
  89. */
  90. virtual bool IsRowSelected(uint32_t aRowIdx) { return false; }
  91. /**
  92. * Return true if the given cell is selected.
  93. */
  94. virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) { return false; }
  95. /**
  96. * Return the number of selected cells.
  97. */
  98. virtual uint32_t SelectedCellCount() { return 0; }
  99. /**
  100. * Return the number of selected columns.
  101. */
  102. virtual uint32_t SelectedColCount() { return 0; }
  103. /**
  104. * Return the number of selected rows.
  105. */
  106. virtual uint32_t SelectedRowCount() { return 0; }
  107. /**
  108. * Get the set of selected cells.
  109. */
  110. virtual void SelectedCells(nsTArray<Accessible*>* aCells) = 0;
  111. /**
  112. * Get the set of selected cell indices.
  113. */
  114. virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) = 0;
  115. /**
  116. * Get the set of selected column indices.
  117. */
  118. virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) = 0;
  119. /**
  120. * Get the set of selected row indices.
  121. */
  122. virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) = 0;
  123. /**
  124. * Select the given column unselecting any other selected columns.
  125. */
  126. virtual void SelectCol(uint32_t aColIdx) {}
  127. /**
  128. * Select the given row unselecting all other previously selected rows.
  129. */
  130. virtual void SelectRow(uint32_t aRowIdx) {}
  131. /**
  132. * Unselect the given column leaving other selected columns selected.
  133. */
  134. virtual void UnselectCol(uint32_t aColIdx) {}
  135. /**
  136. * Unselect the given row leaving other selected rows selected.
  137. */
  138. virtual void UnselectRow(uint32_t aRowIdx) {}
  139. /**
  140. * Return true if the table is probably for layout.
  141. */
  142. virtual bool IsProbablyLayoutTable() { return false; }
  143. /**
  144. * Convert the table to an Accessible*.
  145. */
  146. virtual Accessible* AsAccessible() = 0;
  147. };
  148. } // namespace a11y
  149. } // namespace mozilla
  150. #endif