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/. */ 6 7 #ifndef TABLE_ACCESSIBLE_H 8 #define TABLE_ACCESSIBLE_H 9 10 #include "TableCellAccessible.h" 11 #include "nsPointerHashKeys.h" 12 #include "nsRefPtrHashtable.h" 13 #include "nsString.h" 14 #include "nsTArray.h" 15 16 namespace mozilla { 17 namespace a11y { 18 19 class LocalAccessible; 20 21 /** 22 * Accessible table interface. 23 */ 24 class TableAccessible { 25 public: 26 /** 27 * Return the caption accessible if any for this table. 28 */ Caption()29 virtual LocalAccessible* Caption() const { return nullptr; } 30 31 /** 32 * Get the summary for this table. 33 */ Summary(nsString & aSummary)34 virtual void Summary(nsString& aSummary) { aSummary.Truncate(); } 35 36 /** 37 * Return the number of columns in the table. 38 */ ColCount()39 virtual uint32_t ColCount() const { return 0; } 40 41 /** 42 * Return the number of rows in the table. 43 */ RowCount()44 virtual uint32_t RowCount() { return 0; } 45 46 /** 47 * Return the accessible for the cell at the given row and column indices. 48 */ CellAt(uint32_t aRowIdx,uint32_t aColIdx)49 virtual LocalAccessible* CellAt(uint32_t aRowIdx, uint32_t aColIdx) { 50 return nullptr; 51 } 52 53 /** 54 * Return the index of the cell at the given row and column. 55 */ CellIndexAt(uint32_t aRowIdx,uint32_t aColIdx)56 virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx) { 57 return ColCount() * aRowIdx + aColIdx; 58 } 59 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. 64 */ 65 virtual int32_t ColIndexAt(uint32_t aCellIdx); 66 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. 71 */ 72 virtual int32_t RowIndexAt(uint32_t aCellIdx); 73 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. 78 */ 79 virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx, 80 int32_t* aColIdx); 81 82 /** 83 * Return the number of columns occupied by the cell at the given row and 84 * column indices. 85 */ ColExtentAt(uint32_t aRowIdx,uint32_t aColIdx)86 virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { return 1; } 87 88 /** 89 * Return the number of rows occupied by the cell at the given row and column 90 * indices. 91 */ RowExtentAt(uint32_t aRowIdx,uint32_t aColIdx)92 virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx) { return 1; } 93 94 /** 95 * Get the description of the given column. 96 */ ColDescription(uint32_t aColIdx,nsString & aDescription)97 virtual void ColDescription(uint32_t aColIdx, nsString& aDescription) { 98 aDescription.Truncate(); 99 } 100 101 /** 102 * Get the description for the given row. 103 */ RowDescription(uint32_t aRowIdx,nsString & aDescription)104 virtual void RowDescription(uint32_t aRowIdx, nsString& aDescription) { 105 aDescription.Truncate(); 106 } 107 108 /** 109 * Return true if the given column is selected. 110 */ IsColSelected(uint32_t aColIdx)111 virtual bool IsColSelected(uint32_t aColIdx) { return false; } 112 113 /** 114 * Return true if the given row is selected. 115 */ IsRowSelected(uint32_t aRowIdx)116 virtual bool IsRowSelected(uint32_t aRowIdx) { return false; } 117 118 /** 119 * Return true if the given cell is selected. 120 */ IsCellSelected(uint32_t aRowIdx,uint32_t aColIdx)121 virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx) { 122 return false; 123 } 124 125 /** 126 * Return the number of selected cells. 127 */ SelectedCellCount()128 virtual uint32_t SelectedCellCount() { return 0; } 129 130 /** 131 * Return the number of selected columns. 132 */ SelectedColCount()133 virtual uint32_t SelectedColCount() { return 0; } 134 135 /** 136 * Return the number of selected rows. 137 */ SelectedRowCount()138 virtual uint32_t SelectedRowCount() { return 0; } 139 140 /** 141 * Get the set of selected cells. 142 */ 143 virtual void SelectedCells(nsTArray<LocalAccessible*>* aCells) = 0; 144 145 /** 146 * Get the set of selected cell indices. 147 */ 148 virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells) = 0; 149 150 /** 151 * Get the set of selected column indices. 152 */ 153 virtual void SelectedColIndices(nsTArray<uint32_t>* aCols) = 0; 154 155 /** 156 * Get the set of selected row indices. 157 */ 158 virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows) = 0; 159 160 /** 161 * Select the given column unselecting any other selected columns. 162 */ SelectCol(uint32_t aColIdx)163 virtual void SelectCol(uint32_t aColIdx) {} 164 165 /** 166 * Select the given row unselecting all other previously selected rows. 167 */ SelectRow(uint32_t aRowIdx)168 virtual void SelectRow(uint32_t aRowIdx) {} 169 170 /** 171 * Unselect the given column leaving other selected columns selected. 172 */ UnselectCol(uint32_t aColIdx)173 virtual void UnselectCol(uint32_t aColIdx) {} 174 175 /** 176 * Unselect the given row leaving other selected rows selected. 177 */ UnselectRow(uint32_t aRowIdx)178 virtual void UnselectRow(uint32_t aRowIdx) {} 179 180 /** 181 * Return true if the table is probably for layout. 182 */ 183 virtual bool IsProbablyLayoutTable(); 184 185 /** 186 * Convert the table to an Accessible*. 187 */ 188 virtual LocalAccessible* AsAccessible() = 0; 189 190 typedef nsRefPtrHashtable<nsPtrHashKey<const TableCellAccessible>, 191 LocalAccessible> 192 HeaderCache; 193 194 /** 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. 200 */ GetHeaderCache()201 HeaderCache& GetHeaderCache() { return mHeaderCache; } 202 203 protected: 204 /** 205 * Return row accessible at the given row index. 206 */ 207 LocalAccessible* RowAt(int32_t aRow); 208 209 /** 210 * Return cell accessible at the given column index in the row. 211 */ 212 LocalAccessible* CellInRowAt(LocalAccessible* aRow, int32_t aColumn); 213 214 private: 215 HeaderCache mHeaderCache; 216 }; 217 218 } // namespace a11y 219 } // namespace mozilla 220 221 #endif 222