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/. */
7 #ifndef mozilla_a11y_AccIterator_h__
8 #define mozilla_a11y_AccIterator_h__
11 #include "mozilla/a11y/DocAccessible.h"
20 class DocAccessibleParent
;
23 * AccIterable is a basic interface for iterators over accessibles.
27 virtual ~AccIterable() {}
28 virtual Accessible
* Next() = 0;
31 friend class Relation
;
32 std::unique_ptr
<AccIterable
> mNextIter
;
36 * Allows to iterate through accessible children or subtree complying with
39 class AccIterator
: public AccIterable
{
41 AccIterator(const LocalAccessible
* aRoot
, filters::FilterFuncPtr aFilterFunc
);
42 virtual ~AccIterator();
45 * Return next accessible complying with filter function. Return the first
46 * accessible for the first time.
48 virtual LocalAccessible
* Next() override
;
52 AccIterator(const AccIterator
&);
53 AccIterator
& operator=(const AccIterator
&);
55 struct IteratorState
{
56 explicit IteratorState(const LocalAccessible
* aParent
,
57 IteratorState
* mParentState
= nullptr);
59 const LocalAccessible
* mParent
;
61 IteratorState
* mParentState
;
64 filters::FilterFuncPtr mFilterFunc
;
65 IteratorState
* mState
;
69 * Allows to traverse through related accessibles that are pointing to the given
70 * dependent accessible by relation attribute. This is typically used to query
71 * implicit reverse relations; e.g. calculating the LABEL_FOR relation for a
72 * label where that label was referenced using aria-labelledby.
74 class RelatedAccIterator
: public AccIterable
{
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, null for all relations
86 RelatedAccIterator(DocAccessible
* aDocument
, nsIContent
* aDependentContent
,
89 virtual ~RelatedAccIterator() {}
92 * Return next related accessible for the given dependent accessible.
94 virtual LocalAccessible
* Next() override
;
98 RelatedAccIterator(const RelatedAccIterator
&);
99 RelatedAccIterator
& operator=(const RelatedAccIterator
&);
101 DocAccessible
* mDocument
;
102 nsIContent
* mDependentContent
;
104 DocAccessible::AttrRelProviders
* mProviders
;
106 bool mIsWalkingDependentElements
;
110 * Used to iterate through HTML labels associated with the given accessible.
112 class HTMLLabelIterator
: public AccIterable
{
114 enum LabelFilter
{ eAllLabels
, eSkipAncestorLabel
};
116 HTMLLabelIterator(DocAccessible
* aDocument
,
117 const LocalAccessible
* aAccessible
,
118 LabelFilter aFilter
= eAllLabels
);
120 virtual ~HTMLLabelIterator() {}
123 * Return next label accessible associated with the given element.
125 virtual LocalAccessible
* Next() override
;
129 HTMLLabelIterator(const HTMLLabelIterator
&);
130 HTMLLabelIterator
& operator=(const HTMLLabelIterator
&);
132 bool IsLabel(LocalAccessible
* aLabel
);
134 RelatedAccIterator mRelIter
;
135 // XXX: replace it on weak reference (bug 678429), it's safe to use raw
136 // pointer now because iterators life cycle is short.
137 const LocalAccessible
* mAcc
;
138 LabelFilter mLabelFilter
;
142 * Used to iterate through HTML outputs associated with the given element.
144 class HTMLOutputIterator
: public AccIterable
{
146 HTMLOutputIterator(DocAccessible
* aDocument
, nsIContent
* aElement
);
147 virtual ~HTMLOutputIterator() {}
150 * Return next output accessible associated with the given element.
152 virtual LocalAccessible
* Next() override
;
155 HTMLOutputIterator();
156 HTMLOutputIterator(const HTMLOutputIterator
&);
157 HTMLOutputIterator
& operator=(const HTMLOutputIterator
&);
159 RelatedAccIterator mRelIter
;
163 * Used to iterate through XUL labels associated with the given element.
165 class XULLabelIterator
: public AccIterable
{
167 XULLabelIterator(DocAccessible
* aDocument
, nsIContent
* aElement
);
168 virtual ~XULLabelIterator() {}
171 * Return next label accessible associated with the given element.
173 virtual LocalAccessible
* Next() override
;
177 XULLabelIterator(const XULLabelIterator
&);
178 XULLabelIterator
& operator=(const XULLabelIterator
&);
180 RelatedAccIterator mRelIter
;
184 * Used to iterate through XUL descriptions associated with the given element.
186 class XULDescriptionIterator
: public AccIterable
{
188 XULDescriptionIterator(DocAccessible
* aDocument
, nsIContent
* aElement
);
189 virtual ~XULDescriptionIterator() {}
192 * Return next description accessible associated with the given element.
194 virtual LocalAccessible
* Next() override
;
197 XULDescriptionIterator();
198 XULDescriptionIterator(const XULDescriptionIterator
&);
199 XULDescriptionIterator
& operator=(const XULDescriptionIterator
&);
201 RelatedAccIterator mRelIter
;
205 * Used to iterate through IDs, elements or accessibles pointed by IDRefs
206 * attribute. Note, any method used to iterate through IDs, elements, or
207 * accessibles moves iterator to next position.
209 class IDRefsIterator
: public AccIterable
{
211 IDRefsIterator(DocAccessible
* aDoc
, nsIContent
* aContent
,
212 nsAtom
* aIDRefsAttr
);
213 virtual ~IDRefsIterator() {}
218 const nsDependentSubstring
NextID();
221 * Return next element.
223 nsIContent
* NextElem();
226 * Return the element with the given ID.
228 static dom::Element
* GetElem(nsIContent
* aContent
, const nsAString
& aID
);
229 dom::Element
* GetElem(const nsDependentSubstring
& aID
);
232 virtual LocalAccessible
* Next() override
;
236 IDRefsIterator(const IDRefsIterator
&);
237 IDRefsIterator
operator=(const IDRefsIterator
&);
240 nsIContent
* mContent
;
242 nsAString::index_type mCurrIdx
;
246 * Iterator that points to a single accessible returning it on the first call
249 class SingleAccIterator
: public AccIterable
{
251 explicit SingleAccIterator(Accessible
* aTarget
) : mAcc(aTarget
) {}
252 virtual ~SingleAccIterator() {}
254 virtual Accessible
* Next() override
;
258 SingleAccIterator(const SingleAccIterator
&);
259 SingleAccIterator
& operator=(const SingleAccIterator
&);
265 * Used to iterate items of the given item container.
267 class ItemIterator
: public AccIterable
{
269 explicit ItemIterator(const Accessible
* aItemContainer
)
270 : mContainer(aItemContainer
), mAnchor(nullptr) {}
272 virtual Accessible
* Next() override
;
275 ItemIterator() = delete;
276 ItemIterator(const ItemIterator
&) = delete;
277 ItemIterator
& operator=(const ItemIterator
&) = delete;
279 const Accessible
* mContainer
;
284 * Used to iterate through XUL tree items of the same level.
286 class XULTreeItemIterator
: public AccIterable
{
288 XULTreeItemIterator(const XULTreeAccessible
* aXULTree
, nsITreeView
* aTreeView
,
290 virtual ~XULTreeItemIterator() {}
292 virtual LocalAccessible
* Next() override
;
295 XULTreeItemIterator() = delete;
296 XULTreeItemIterator(const XULTreeItemIterator
&) = delete;
297 XULTreeItemIterator
& operator=(const XULTreeItemIterator
&) = delete;
299 const XULTreeAccessible
* mXULTree
;
300 nsITreeView
* mTreeView
;
302 int32_t mContainerLevel
;
307 * Used to iterate through a sequence of RemoteAccessibles supplied as an array
308 * of ids. Such id arrays are included in the RemoteAccessible cache.
310 class RemoteAccIterator
: public AccIterable
{
313 * Construct with a reference to an array owned somewhere else; e.g. a
314 * RemoteAccessible cache.
316 RemoteAccIterator(const nsTArray
<uint64_t>& aIds
, DocAccessibleParent
* aDoc
)
317 : mIds(aIds
), mDoc(aDoc
), mIndex(0) {}
319 virtual ~RemoteAccIterator() = default;
321 virtual Accessible
* Next() override
;
324 const nsTArray
<uint64_t>& mIds
;
325 DocAccessibleParent
* mDoc
;
330 } // namespace mozilla