accessible/src/html/HTMLTableAccessible.h

branch
TOR_BUG_9701
changeset 8
97036ab72558
equal deleted inserted replaced
-1:000000000000 0:f4419c6b3113
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
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 #ifndef mozilla_a11y_HTMLTableAccessible_h__
7 #define mozilla_a11y_HTMLTableAccessible_h__
8
9 #include "HyperTextAccessibleWrap.h"
10 #include "nsIAccessibleTable.h"
11 #include "TableAccessible.h"
12 #include "TableCellAccessible.h"
13 #include "xpcAccessibleTable.h"
14 #include "xpcAccessibleTableCell.h"
15
16 class nsITableLayout;
17 class nsITableCellLayout;
18
19 namespace mozilla {
20 namespace a11y {
21
22 /**
23 * HTML table cell accessible (html:td).
24 */
25 class HTMLTableCellAccessible : public HyperTextAccessibleWrap,
26 public nsIAccessibleTableCell,
27 public TableCellAccessible,
28 public xpcAccessibleTableCell
29 {
30 public:
31 HTMLTableCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
32
33 // nsISupports
34 NS_DECL_ISUPPORTS_INHERITED
35
36 // nsIAccessibleTableCell
37 NS_FORWARD_NSIACCESSIBLETABLECELL(xpcAccessibleTableCell::)
38
39 // Accessible
40 virtual TableCellAccessible* AsTableCell() { return this; }
41 virtual void Shutdown();
42 virtual a11y::role NativeRole();
43 virtual uint64_t NativeState();
44 virtual uint64_t NativeInteractiveState() const;
45 virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE;
46
47 // TableCellAccessible
48 virtual TableAccessible* Table() const MOZ_OVERRIDE;
49 virtual uint32_t ColIdx() const MOZ_OVERRIDE;
50 virtual uint32_t RowIdx() const MOZ_OVERRIDE;
51 virtual uint32_t ColExtent() const MOZ_OVERRIDE;
52 virtual uint32_t RowExtent() const MOZ_OVERRIDE;
53 virtual void ColHeaderCells(nsTArray<Accessible*>* aCells) MOZ_OVERRIDE;
54 virtual void RowHeaderCells(nsTArray<Accessible*>* aCells) MOZ_OVERRIDE;
55 virtual bool Selected() MOZ_OVERRIDE;
56
57 protected:
58 /**
59 * Return host table accessible.
60 */
61 already_AddRefed<nsIAccessibleTable> GetTableAccessible();
62
63 /**
64 * Return nsITableCellLayout of the table cell frame.
65 */
66 nsITableCellLayout* GetCellLayout() const;
67
68 /**
69 * Return row and column indices of the cell.
70 */
71 nsresult GetCellIndexes(int32_t& aRowIdx, int32_t& aColIdx) const;
72 };
73
74
75 /**
76 * HTML table row/column header accessible (html:th or html:td@scope).
77 */
78 class HTMLTableHeaderCellAccessible : public HTMLTableCellAccessible
79 {
80 public:
81 HTMLTableHeaderCellAccessible(nsIContent* aContent, DocAccessible* aDoc);
82
83 // Accessible
84 virtual a11y::role NativeRole();
85 };
86
87
88 /**
89 * HTML table row accessible (html:tr).
90 */
91 class HTMLTableRowAccessible : public AccessibleWrap
92 {
93 public:
94 HTMLTableRowAccessible(nsIContent* aContent, DocAccessible* aDoc) :
95 AccessibleWrap(aContent, aDoc)
96 {
97 mType = eHTMLTableRowType;
98 mGenericTypes |= eTableRow;
99 }
100 virtual ~HTMLTableRowAccessible() { }
101
102 NS_DECL_ISUPPORTS_INHERITED
103
104 // Accessible
105 virtual a11y::role NativeRole();
106 };
107
108
109 /**
110 * HTML table accessible (html:table).
111 */
112
113 // To turn on table debugging descriptions define SHOW_LAYOUT_HEURISTIC
114 // This allow release trunk builds to be used by testers to refine the
115 // data vs. layout heuristic
116 // #define SHOW_LAYOUT_HEURISTIC
117
118 class HTMLTableAccessible : public AccessibleWrap,
119 public xpcAccessibleTable,
120 public nsIAccessibleTable,
121 public TableAccessible
122 {
123 public:
124 HTMLTableAccessible(nsIContent* aContent, DocAccessible* aDoc) :
125 AccessibleWrap(aContent, aDoc), xpcAccessibleTable(this)
126 {
127 mType = eHTMLTableType;
128 mGenericTypes |= eTable;
129 }
130
131 NS_DECL_ISUPPORTS_INHERITED
132
133 // nsIAccessible Table
134 NS_FORWARD_NSIACCESSIBLETABLE(xpcAccessibleTable::)
135
136 // TableAccessible
137 virtual Accessible* Caption();
138 virtual void Summary(nsString& aSummary);
139 virtual uint32_t ColCount();
140 virtual uint32_t RowCount();
141 virtual Accessible* CellAt(uint32_t aRowIndex, uint32_t aColumnIndex);
142 virtual int32_t CellIndexAt(uint32_t aRowIdx, uint32_t aColIdx);
143 virtual int32_t ColIndexAt(uint32_t aCellIdx);
144 virtual int32_t RowIndexAt(uint32_t aCellIdx);
145 virtual void RowAndColIndicesAt(uint32_t aCellIdx, int32_t* aRowIdx,
146 int32_t* aColIdx);
147 virtual uint32_t ColExtentAt(uint32_t aRowIdx, uint32_t aColIdx);
148 virtual uint32_t RowExtentAt(uint32_t aRowIdx, uint32_t aColIdx);
149 virtual bool IsColSelected(uint32_t aColIdx);
150 virtual bool IsRowSelected(uint32_t aRowIdx);
151 virtual bool IsCellSelected(uint32_t aRowIdx, uint32_t aColIdx);
152 virtual uint32_t SelectedCellCount();
153 virtual uint32_t SelectedColCount();
154 virtual uint32_t SelectedRowCount();
155 virtual void SelectedCells(nsTArray<Accessible*>* aCells);
156 virtual void SelectedCellIndices(nsTArray<uint32_t>* aCells);
157 virtual void SelectedColIndices(nsTArray<uint32_t>* aCols);
158 virtual void SelectedRowIndices(nsTArray<uint32_t>* aRows);
159 virtual void SelectCol(uint32_t aColIdx);
160 virtual void SelectRow(uint32_t aRowIdx);
161 virtual void UnselectCol(uint32_t aColIdx);
162 virtual void UnselectRow(uint32_t aRowIdx);
163 virtual bool IsProbablyLayoutTable();
164 virtual Accessible* AsAccessible() { return this; }
165
166 // Accessible
167 virtual void Shutdown();
168 virtual TableAccessible* AsTable() { return this; }
169 virtual void Description(nsString& aDescription);
170 virtual a11y::role NativeRole();
171 virtual uint64_t NativeState();
172 virtual already_AddRefed<nsIPersistentProperties> NativeAttributes() MOZ_OVERRIDE;
173 virtual Relation RelationByType(RelationType aRelationType) MOZ_OVERRIDE;
174
175 protected:
176 // Accessible
177 virtual ENameValueFlag NativeName(nsString& aName) MOZ_OVERRIDE;
178 virtual void CacheChildren();
179
180 // HTMLTableAccessible
181
182 /**
183 * Add row or column to selection.
184 *
185 * @param aIndex [in] index of row or column to be selected
186 * @param aTarget [in] indicates what should be selected, either row or column
187 * (see nsISelectionPrivate)
188 */
189 nsresult AddRowOrColumnToSelection(int32_t aIndex, uint32_t aTarget);
190
191 /**
192 * Removes rows or columns at the given index or outside it from selection.
193 *
194 * @param aIndex [in] row or column index
195 * @param aTarget [in] indicates whether row or column should unselected
196 * @param aIsOuter [in] indicates whether all rows or column excepting
197 * the given one should be unselected or the given one
198 * should be unselected only
199 */
200 nsresult RemoveRowsOrColumnsFromSelection(int32_t aIndex,
201 uint32_t aTarget,
202 bool aIsOuter);
203
204 /**
205 * Return true if table has an element with the given tag name.
206 *
207 * @param aTagName [in] tag name of searched element
208 * @param aAllowEmpty [in, optional] points if found element can be empty
209 * or contain whitespace text only.
210 */
211 bool HasDescendant(const nsAString& aTagName, bool aAllowEmpty = true);
212
213 #ifdef SHOW_LAYOUT_HEURISTIC
214 nsString mLayoutHeuristic;
215 #endif
216 };
217
218 /**
219 * HTML caption accessible (html:caption).
220 */
221 class HTMLCaptionAccessible : public HyperTextAccessibleWrap
222 {
223 public:
224 HTMLCaptionAccessible(nsIContent* aContent, DocAccessible* aDoc) :
225 HyperTextAccessibleWrap(aContent, aDoc) { }
226 virtual ~HTMLCaptionAccessible() { }
227
228 // nsIAccessible
229
230 // Accessible
231 virtual a11y::role NativeRole();
232 virtual Relation RelationByType(RelationType aRelationType) MOZ_OVERRIDE;
233 };
234
235 } // namespace a11y
236 } // namespace mozilla
237
238 #endif

mercurial