1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/base/TreeWalker.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,95 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_a11y_TreeWalker_h_ 1.10 +#define mozilla_a11y_TreeWalker_h_ 1.11 + 1.12 +#include "mozilla/Attributes.h" 1.13 +#include <stdint.h> 1.14 + 1.15 +class nsIContent; 1.16 + 1.17 +namespace mozilla { 1.18 +namespace a11y { 1.19 + 1.20 +class Accessible; 1.21 +class DocAccessible; 1.22 + 1.23 +struct WalkState; 1.24 + 1.25 +/** 1.26 + * This class is used to walk the DOM tree to create accessible tree. 1.27 + */ 1.28 +class TreeWalker MOZ_FINAL 1.29 +{ 1.30 +public: 1.31 + enum { 1.32 + // used to walk the existing tree of the given node 1.33 + eWalkCache = 1, 1.34 + // used to walk the context tree starting from given node 1.35 + eWalkContextTree = 2 | eWalkCache 1.36 + }; 1.37 + 1.38 + /** 1.39 + * Constructor 1.40 + * 1.41 + * @param aContext [in] container accessible for the given node, used to 1.42 + * define accessible context 1.43 + * @param aNode [in] the node the search will be prepared relative to 1.44 + * @param aFlags [in] flags (see enum above) 1.45 + */ 1.46 + TreeWalker(Accessible* aContext, nsIContent* aNode, uint32_t aFlags = 0); 1.47 + ~TreeWalker(); 1.48 + 1.49 + /** 1.50 + * Return the next child accessible. 1.51 + * 1.52 + * @note Returned accessible is bound to the document, if the accessible is 1.53 + * rejected during tree creation then the caller should be unbind it 1.54 + * from the document. 1.55 + */ 1.56 + Accessible* NextChild() 1.57 + { 1.58 + return NextChildInternal(false); 1.59 + } 1.60 + 1.61 +private: 1.62 + TreeWalker(); 1.63 + TreeWalker(const TreeWalker&); 1.64 + TreeWalker& operator =(const TreeWalker&); 1.65 + 1.66 + /** 1.67 + * Return the next child accessible. 1.68 + * 1.69 + * @param aNoWalkUp [in] specifies the walk direction, true means we 1.70 + * shouldn't go up through the tree if we failed find 1.71 + * accessible children. 1.72 + */ 1.73 + Accessible* NextChildInternal(bool aNoWalkUp); 1.74 + 1.75 + /** 1.76 + * Create new state for the given node and push it on top of stack. 1.77 + * 1.78 + * @note State stack is used to navigate up/down the DOM subtree during 1.79 + * accessible children search. 1.80 + */ 1.81 + void PushState(nsIContent* aNode); 1.82 + 1.83 + /** 1.84 + * Pop state from stack. 1.85 + */ 1.86 + void PopState(); 1.87 + 1.88 + DocAccessible* mDoc; 1.89 + Accessible* mContext; 1.90 + int32_t mChildFilter; 1.91 + uint32_t mFlags; 1.92 + WalkState* mState; 1.93 +}; 1.94 + 1.95 +} // namespace a11y 1.96 +} // namespace mozilla 1.97 + 1.98 +#endif // mozilla_a11y_TreeWalker_h_