|
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 |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #ifndef mozilla_a11y_AccIterator_h__ |
|
8 #define mozilla_a11y_AccIterator_h__ |
|
9 |
|
10 #include "DocAccessible.h" |
|
11 #include "Filters.h" |
|
12 |
|
13 class nsITreeView; |
|
14 |
|
15 namespace mozilla { |
|
16 namespace a11y { |
|
17 |
|
18 /** |
|
19 * AccIterable is a basic interface for iterators over accessibles. |
|
20 */ |
|
21 class AccIterable |
|
22 { |
|
23 public: |
|
24 virtual ~AccIterable() { } |
|
25 virtual Accessible* Next() = 0; |
|
26 |
|
27 private: |
|
28 friend class Relation; |
|
29 nsAutoPtr<AccIterable> mNextIter; |
|
30 }; |
|
31 |
|
32 /** |
|
33 * Allows to iterate through accessible children or subtree complying with |
|
34 * filter function. |
|
35 */ |
|
36 class AccIterator : public AccIterable |
|
37 { |
|
38 public: |
|
39 AccIterator(Accessible* aRoot, filters::FilterFuncPtr aFilterFunc); |
|
40 virtual ~AccIterator(); |
|
41 |
|
42 /** |
|
43 * Return next accessible complying with filter function. Return the first |
|
44 * accessible for the first time. |
|
45 */ |
|
46 virtual Accessible* Next(); |
|
47 |
|
48 private: |
|
49 AccIterator(); |
|
50 AccIterator(const AccIterator&); |
|
51 AccIterator& operator =(const AccIterator&); |
|
52 |
|
53 struct IteratorState |
|
54 { |
|
55 IteratorState(Accessible* aParent, IteratorState* mParentState = nullptr); |
|
56 |
|
57 Accessible* mParent; |
|
58 int32_t mIndex; |
|
59 IteratorState* mParentState; |
|
60 }; |
|
61 |
|
62 filters::FilterFuncPtr mFilterFunc; |
|
63 IteratorState* mState; |
|
64 }; |
|
65 |
|
66 |
|
67 /** |
|
68 * Allows to traverse through related accessibles that are pointing to the given |
|
69 * dependent accessible by relation attribute. |
|
70 */ |
|
71 class RelatedAccIterator : public AccIterable |
|
72 { |
|
73 public: |
|
74 /** |
|
75 * Constructor. |
|
76 * |
|
77 * @param aDocument [in] the document accessible the related |
|
78 * & accessibles belong to. |
|
79 * @param aDependentContent [in] the content of dependent accessible that |
|
80 * relations were requested for |
|
81 * @param aRelAttr [in] relation attribute that relations are |
|
82 * pointed by |
|
83 */ |
|
84 RelatedAccIterator(DocAccessible* aDocument, nsIContent* aDependentContent, |
|
85 nsIAtom* aRelAttr); |
|
86 |
|
87 virtual ~RelatedAccIterator() { } |
|
88 |
|
89 /** |
|
90 * Return next related accessible for the given dependent accessible. |
|
91 */ |
|
92 virtual Accessible* Next(); |
|
93 |
|
94 private: |
|
95 RelatedAccIterator(); |
|
96 RelatedAccIterator(const RelatedAccIterator&); |
|
97 RelatedAccIterator& operator = (const RelatedAccIterator&); |
|
98 |
|
99 DocAccessible* mDocument; |
|
100 nsIAtom* mRelAttr; |
|
101 DocAccessible::AttrRelProviderArray* mProviders; |
|
102 nsIContent* mBindingParent; |
|
103 uint32_t mIndex; |
|
104 }; |
|
105 |
|
106 |
|
107 /** |
|
108 * Used to iterate through HTML labels associated with the given accessible. |
|
109 */ |
|
110 class HTMLLabelIterator : public AccIterable |
|
111 { |
|
112 public: |
|
113 enum LabelFilter { |
|
114 eAllLabels, |
|
115 eSkipAncestorLabel |
|
116 }; |
|
117 |
|
118 HTMLLabelIterator(DocAccessible* aDocument, const Accessible* aAccessible, |
|
119 LabelFilter aFilter = eAllLabels); |
|
120 |
|
121 virtual ~HTMLLabelIterator() { } |
|
122 |
|
123 /** |
|
124 * Return next label accessible associated with the given element. |
|
125 */ |
|
126 virtual Accessible* Next(); |
|
127 |
|
128 private: |
|
129 HTMLLabelIterator(); |
|
130 HTMLLabelIterator(const HTMLLabelIterator&); |
|
131 HTMLLabelIterator& operator = (const HTMLLabelIterator&); |
|
132 |
|
133 RelatedAccIterator mRelIter; |
|
134 // XXX: replace it on weak reference (bug 678429), it's safe to use raw |
|
135 // pointer now because iterators life cycle is short. |
|
136 const Accessible* mAcc; |
|
137 LabelFilter mLabelFilter; |
|
138 }; |
|
139 |
|
140 |
|
141 /** |
|
142 * Used to iterate through HTML outputs associated with the given element. |
|
143 */ |
|
144 class HTMLOutputIterator : public AccIterable |
|
145 { |
|
146 public: |
|
147 HTMLOutputIterator(DocAccessible* aDocument, nsIContent* aElement); |
|
148 virtual ~HTMLOutputIterator() { } |
|
149 |
|
150 /** |
|
151 * Return next output accessible associated with the given element. |
|
152 */ |
|
153 virtual Accessible* Next(); |
|
154 |
|
155 private: |
|
156 HTMLOutputIterator(); |
|
157 HTMLOutputIterator(const HTMLOutputIterator&); |
|
158 HTMLOutputIterator& operator = (const HTMLOutputIterator&); |
|
159 |
|
160 RelatedAccIterator mRelIter; |
|
161 }; |
|
162 |
|
163 |
|
164 /** |
|
165 * Used to iterate through XUL labels associated with the given element. |
|
166 */ |
|
167 class XULLabelIterator : public AccIterable |
|
168 { |
|
169 public: |
|
170 XULLabelIterator(DocAccessible* aDocument, nsIContent* aElement); |
|
171 virtual ~XULLabelIterator() { } |
|
172 |
|
173 /** |
|
174 * Return next label accessible associated with the given element. |
|
175 */ |
|
176 virtual Accessible* Next(); |
|
177 |
|
178 private: |
|
179 XULLabelIterator(); |
|
180 XULLabelIterator(const XULLabelIterator&); |
|
181 XULLabelIterator& operator = (const XULLabelIterator&); |
|
182 |
|
183 RelatedAccIterator mRelIter; |
|
184 }; |
|
185 |
|
186 |
|
187 /** |
|
188 * Used to iterate through XUL descriptions associated with the given element. |
|
189 */ |
|
190 class XULDescriptionIterator : public AccIterable |
|
191 { |
|
192 public: |
|
193 XULDescriptionIterator(DocAccessible* aDocument, nsIContent* aElement); |
|
194 virtual ~XULDescriptionIterator() { } |
|
195 |
|
196 /** |
|
197 * Return next description accessible associated with the given element. |
|
198 */ |
|
199 virtual Accessible* Next(); |
|
200 |
|
201 private: |
|
202 XULDescriptionIterator(); |
|
203 XULDescriptionIterator(const XULDescriptionIterator&); |
|
204 XULDescriptionIterator& operator = (const XULDescriptionIterator&); |
|
205 |
|
206 RelatedAccIterator mRelIter; |
|
207 }; |
|
208 |
|
209 /** |
|
210 * Used to iterate through IDs, elements or accessibles pointed by IDRefs |
|
211 * attribute. Note, any method used to iterate through IDs, elements, or |
|
212 * accessibles moves iterator to next position. |
|
213 */ |
|
214 class IDRefsIterator : public AccIterable |
|
215 { |
|
216 public: |
|
217 IDRefsIterator(DocAccessible* aDoc, nsIContent* aContent, |
|
218 nsIAtom* aIDRefsAttr); |
|
219 virtual ~IDRefsIterator() { } |
|
220 |
|
221 /** |
|
222 * Return next ID. |
|
223 */ |
|
224 const nsDependentSubstring NextID(); |
|
225 |
|
226 /** |
|
227 * Return next element. |
|
228 */ |
|
229 nsIContent* NextElem(); |
|
230 |
|
231 /** |
|
232 * Return the element with the given ID. |
|
233 */ |
|
234 nsIContent* GetElem(const nsDependentSubstring& aID); |
|
235 |
|
236 // AccIterable |
|
237 virtual Accessible* Next(); |
|
238 |
|
239 private: |
|
240 IDRefsIterator(); |
|
241 IDRefsIterator(const IDRefsIterator&); |
|
242 IDRefsIterator operator = (const IDRefsIterator&); |
|
243 |
|
244 nsString mIDs; |
|
245 nsIContent* mContent; |
|
246 DocAccessible* mDoc; |
|
247 nsAString::index_type mCurrIdx; |
|
248 }; |
|
249 |
|
250 /** |
|
251 * Iterator that points to a single accessible returning it on the first call |
|
252 * to Next(). |
|
253 */ |
|
254 class SingleAccIterator : public AccIterable |
|
255 { |
|
256 public: |
|
257 SingleAccIterator(Accessible* aTarget): mAcc(aTarget) { } |
|
258 virtual ~SingleAccIterator() { } |
|
259 |
|
260 virtual Accessible* Next(); |
|
261 |
|
262 private: |
|
263 SingleAccIterator(); |
|
264 SingleAccIterator(const SingleAccIterator&); |
|
265 SingleAccIterator& operator = (const SingleAccIterator&); |
|
266 |
|
267 nsRefPtr<Accessible> mAcc; |
|
268 }; |
|
269 |
|
270 |
|
271 /** |
|
272 * Used to iterate items of the given item container. |
|
273 */ |
|
274 class ItemIterator : public AccIterable |
|
275 { |
|
276 public: |
|
277 ItemIterator(Accessible* aItemContainer) : |
|
278 mContainer(aItemContainer), mAnchor(nullptr) { } |
|
279 virtual ~ItemIterator() { } |
|
280 |
|
281 virtual Accessible* Next(); |
|
282 |
|
283 private: |
|
284 ItemIterator() MOZ_DELETE; |
|
285 ItemIterator(const ItemIterator&) MOZ_DELETE; |
|
286 ItemIterator& operator = (const ItemIterator&) MOZ_DELETE; |
|
287 |
|
288 Accessible* mContainer; |
|
289 Accessible* mAnchor; |
|
290 }; |
|
291 |
|
292 |
|
293 /** |
|
294 * Used to iterate through XUL tree items of the same level. |
|
295 */ |
|
296 class XULTreeItemIterator : public AccIterable |
|
297 { |
|
298 public: |
|
299 XULTreeItemIterator(XULTreeAccessible* aXULTree, nsITreeView* aTreeView, |
|
300 int32_t aRowIdx); |
|
301 virtual ~XULTreeItemIterator() { } |
|
302 |
|
303 virtual Accessible* Next(); |
|
304 |
|
305 private: |
|
306 XULTreeItemIterator() MOZ_DELETE; |
|
307 XULTreeItemIterator(const XULTreeItemIterator&) MOZ_DELETE; |
|
308 XULTreeItemIterator& operator = (const XULTreeItemIterator&) MOZ_DELETE; |
|
309 |
|
310 XULTreeAccessible* mXULTree; |
|
311 nsITreeView* mTreeView; |
|
312 int32_t mRowCount; |
|
313 int32_t mContainerLevel; |
|
314 int32_t mCurrRowIdx; |
|
315 }; |
|
316 |
|
317 } // namespace a11y |
|
318 } // namespace mozilla |
|
319 |
|
320 #endif |