Bug 1760738 [wpt PR 33295] - Remove subresource loading with WebBundles's WPT of...
[gecko.git] / accessible / generic / TableAccessible.h
blob977a4e7b4398881beee20398b3b663adad2e474b
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef TABLE_ACCESSIBLE_H
8 #define TABLE_ACCESSIBLE_H
10 #include "TableCellAccessible.h"
11 #include "nsPointerHashKeys.h"
12 #include "nsRefPtrHashtable.h"
13 #include "nsString.h"
14 #include "nsTArray.h"
16 namespace mozilla {
17 namespace a11y {
19 class LocalAccessible;
21 /**
22 * Accessible table interface.
24 class TableAccessible {
25 public:
26 /**
27 * Return the caption accessible if any for this table.
29 virtual LocalAccessible* Caption() const { return nullptr; }
31 /**
32 * Get the summary for this table.
34 virtual void Summary(nsString& aSummary) { aSummary.Truncate(); }
36 /**
37 * Return the number of columns in the table.
39 virtual uint32_t ColCount() const { return 0; }
41 /**
42 * Return the number of rows in the table.
44 virtual uint32_t RowCount() { return 0; }
46 /**
47 * Return the accessible for the cell at the given row and column indices.
49 virtual LocalAccessible* CellAt(uint32_t aRowIdx, uint32_t aColIdx) {
50 return nullptr;
53 /**
54 * Return the index of the cell at the given row and column.
56 virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx) {
57 return ColCount() * aRowIdx + aColIdx;
60 /**
61 * Return the column index of the cell with the given index.
62 * This returns -1 if the column count is 0 or an invalid index is being
63 * passed in.
65 virtual int32_t ColIndexAt(uint32_t aCellIdx);
67 /**
68 * Return the row index of the cell with the given index.
69 * This returns -1 if the column count is 0 or an invalid index is being
70 * passed in.
72 virtual int32_t RowIndexAt(uint32_t aCellIdx);
74 /**
75 * Get the row and column indices for the cell at the given index.
76 * This returns -1 for both output parameters if the column count is 0 or an
77 * invalid index is being passed in.
79 virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
80 int32_t* aColIdx);
82 /**
83 * Return the number of columns occupied by the cell at the given row and
84 * column indices.
86 virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { return 1; }
88 /**
89 * Return the number of rows occupied by the cell at the given row and column
90 * indices.
92 virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { return 1; }
94 /**
95 * Get the description of the given column.
97 virtual void ColDescription(uint32_t aColIdx, nsString& aDescription) {
98 aDescription.Truncate();
102 * Get the description for the given row.
104 virtual void RowDescription(uint32_t aRowIdx, nsString& aDescription) {
105 aDescription.Truncate();
109 * Return true if the given column is selected.
111 virtual bool IsColSelected(uint32_t aColIdx) { return false; }
114 * Return true if the given row is selected.
116 virtual bool IsRowSelected(uint32_t aRowIdx) { return false; }
119 * Return true if the given cell is selected.
121 virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) {
122 return false;
126 * Return the number of selected cells.
128 virtual uint32_t SelectedCellCount() { return 0; }
131 * Return the number of selected columns.
133 virtual uint32_t SelectedColCount() { return 0; }
136 * Return the number of selected rows.
138 virtual uint32_t SelectedRowCount() { return 0; }
141 * Get the set of selected cells.
143 virtual void SelectedCells(nsTArray<LocalAccessible*>* aCells) = 0;
146 * Get the set of selected cell indices.
148 virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) = 0;
151 * Get the set of selected column indices.
153 virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) = 0;
156 * Get the set of selected row indices.
158 virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) = 0;
161 * Select the given column unselecting any other selected columns.
163 virtual void SelectCol(uint32_t aColIdx) {}
166 * Select the given row unselecting all other previously selected rows.
168 virtual void SelectRow(uint32_t aRowIdx) {}
171 * Unselect the given column leaving other selected columns selected.
173 virtual void UnselectCol(uint32_t aColIdx) {}
176 * Unselect the given row leaving other selected rows selected.
178 virtual void UnselectRow(uint32_t aRowIdx) {}
181 * Return true if the table is probably for layout.
183 virtual bool IsProbablyLayoutTable();
186 * Convert the table to an Accessible*.
188 virtual LocalAccessible* AsAccessible() = 0;
190 typedef nsRefPtrHashtable<nsPtrHashKey<const TableCellAccessible>,
191 LocalAccessible>
192 HeaderCache;
195 * Get the header cache, which maps a TableCellAccessible to its previous
196 * header.
197 * Although this data is only used in TableCellAccessible, it is stored on
198 * TableAccessible so the cache can be easily invalidated when the table
199 * is mutated.
201 HeaderCache& GetHeaderCache() { return mHeaderCache; }
203 protected:
205 * Return row accessible at the given row index.
207 LocalAccessible* RowAt(int32_t aRow);
210 * Return cell accessible at the given column index in the row.
212 LocalAccessible* CellInRowAt(LocalAccessible* aRow, int32_t aColumn);
214 private:
215 HeaderCache mHeaderCache;
218 } // namespace a11y
219 } // namespace mozilla
221 #endif