michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_a11y_TreeWalker_h_ michael@0: #define mozilla_a11y_TreeWalker_h_ michael@0: michael@0: #include "mozilla/Attributes.h" michael@0: #include michael@0: michael@0: class nsIContent; michael@0: michael@0: namespace mozilla { michael@0: namespace a11y { michael@0: michael@0: class Accessible; michael@0: class DocAccessible; michael@0: michael@0: struct WalkState; michael@0: michael@0: /** michael@0: * This class is used to walk the DOM tree to create accessible tree. michael@0: */ michael@0: class TreeWalker MOZ_FINAL michael@0: { michael@0: public: michael@0: enum { michael@0: // used to walk the existing tree of the given node michael@0: eWalkCache = 1, michael@0: // used to walk the context tree starting from given node michael@0: eWalkContextTree = 2 | eWalkCache michael@0: }; michael@0: michael@0: /** michael@0: * Constructor michael@0: * michael@0: * @param aContext [in] container accessible for the given node, used to michael@0: * define accessible context michael@0: * @param aNode [in] the node the search will be prepared relative to michael@0: * @param aFlags [in] flags (see enum above) michael@0: */ michael@0: TreeWalker(Accessible* aContext, nsIContent* aNode, uint32_t aFlags = 0); michael@0: ~TreeWalker(); michael@0: michael@0: /** michael@0: * Return the next child accessible. michael@0: * michael@0: * @note Returned accessible is bound to the document, if the accessible is michael@0: * rejected during tree creation then the caller should be unbind it michael@0: * from the document. michael@0: */ michael@0: Accessible* NextChild() michael@0: { michael@0: return NextChildInternal(false); michael@0: } michael@0: michael@0: private: michael@0: TreeWalker(); michael@0: TreeWalker(const TreeWalker&); michael@0: TreeWalker& operator =(const TreeWalker&); michael@0: michael@0: /** michael@0: * Return the next child accessible. michael@0: * michael@0: * @param aNoWalkUp [in] specifies the walk direction, true means we michael@0: * shouldn't go up through the tree if we failed find michael@0: * accessible children. michael@0: */ michael@0: Accessible* NextChildInternal(bool aNoWalkUp); michael@0: michael@0: /** michael@0: * Create new state for the given node and push it on top of stack. michael@0: * michael@0: * @note State stack is used to navigate up/down the DOM subtree during michael@0: * accessible children search. michael@0: */ michael@0: void PushState(nsIContent* aNode); michael@0: michael@0: /** michael@0: * Pop state from stack. michael@0: */ michael@0: void PopState(); michael@0: michael@0: DocAccessible* mDoc; michael@0: Accessible* mContext; michael@0: int32_t mChildFilter; michael@0: uint32_t mFlags; michael@0: WalkState* mState; michael@0: }; michael@0: michael@0: } // namespace a11y michael@0: } // namespace mozilla michael@0: michael@0: #endif // mozilla_a11y_TreeWalker_h_