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