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/. */
6 #ifndef mozilla_a11y_TreeWalker_h_
7 #define mozilla_a11y_TreeWalker_h_
9 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/ChildIterator.h"
19 class LocalAccessible
;
23 * This class is used to walk the DOM tree to create accessible tree.
25 class TreeWalker final
{
28 // used to walk the existing tree of the given node
30 // used to walk the context tree starting from given node
31 eWalkContextTree
= 2 | eWalkCache
,
36 * Used to navigate and create if needed the accessible children.
38 explicit TreeWalker(LocalAccessible
* aContext
);
41 * Used to navigate the accessible children relative to the anchor.
43 * @param aContext [in] container accessible for the given node, used to
44 * define accessible context
45 * @param aAnchorNode [in] the node the search will be prepared relative to
46 * @param aFlags [in] flags (see enum above)
48 TreeWalker(LocalAccessible
* aContext
, nsIContent
* aAnchorNode
,
49 uint32_t aFlags
= eWalkCache
);
52 * Navigates the accessible children within the anchor node subtree.
54 TreeWalker(DocAccessible
* aDocument
, nsIContent
* aAnchorNode
);
59 * Resets the walker state, and sets the given node as an anchor. Returns a
60 * first accessible element within the node including the node itself.
62 LocalAccessible
* Scope(nsIContent
* aAnchorNode
);
65 * Resets the walker state.
74 * Sets the walker state to the given child node if it's within the anchor.
76 bool Seek(nsIContent
* aChildNode
);
79 * Return the next/prev accessible.
81 * @note Returned accessible is bound to the document, if the accessible is
82 * rejected during tree creation then the caller should be unbind it
85 LocalAccessible
* Next();
86 LocalAccessible
* Prev();
88 LocalAccessible
* Context() const { return mContext
; }
89 DocAccessible
* Document() const { return mDoc
; }
93 TreeWalker(const TreeWalker
&);
94 TreeWalker
& operator=(const TreeWalker
&);
97 * Return an accessible for the given node if any.
99 LocalAccessible
* AccessibleFor(nsIContent
* aNode
, uint32_t aFlags
,
103 * Create new state for the given node and push it on top of stack / at bottom
106 * @note State stack is used to navigate up/down the DOM subtree during
107 * accessible children search.
109 dom::AllChildrenIterator
* PushState(nsIContent
* aContent
,
110 bool aStartAtBeginning
) {
111 return mStateStack
.AppendElement(
112 dom::AllChildrenIterator(aContent
, mChildFilter
, aStartAtBeginning
));
114 dom::AllChildrenIterator
* PrependState(nsIContent
* aContent
,
115 bool aStartAtBeginning
) {
116 return mStateStack
.InsertElementAt(
117 0, dom::AllChildrenIterator(aContent
, mChildFilter
, aStartAtBeginning
));
121 * Pop state from stack.
123 dom::AllChildrenIterator
* PopState();
126 LocalAccessible
* mContext
;
127 nsIContent
* mAnchorNode
;
129 AutoTArray
<dom::AllChildrenIterator
, 20> mStateStack
;
130 uint32_t mARIAOwnsIdx
;
132 int32_t mChildFilter
;
135 enum Phase
{ eAtStart
, eAtDOM
, eAtARIAOwns
, eAtEnd
};
140 } // namespace mozilla
142 #endif // mozilla_a11y_TreeWalker_h_