2010-02-20 16:55:04 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2010-02-20 16:55:04 -08:00
|
|
|
|
2012-11-19 01:20:09 -08:00
|
|
|
#ifndef mozilla_a11y_TreeWalker_h_
|
|
|
|
#define mozilla_a11y_TreeWalker_h_
|
2010-02-20 16:55:04 -08:00
|
|
|
|
2014-02-15 07:21:40 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-09-10 15:18:59 -07:00
|
|
|
#include <stdint.h>
|
2014-08-11 23:02:28 -07:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2013-03-21 17:05:20 -07:00
|
|
|
|
|
|
|
class nsIContent;
|
2010-02-20 16:55:04 -08:00
|
|
|
|
2012-11-17 18:01:44 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace a11y {
|
|
|
|
|
2012-05-28 18:18:45 -07:00
|
|
|
class Accessible;
|
2012-05-27 02:01:40 -07:00
|
|
|
class DocAccessible;
|
2012-11-17 18:01:44 -08:00
|
|
|
|
2010-02-20 16:55:04 -08:00
|
|
|
/**
|
|
|
|
* This class is used to walk the DOM tree to create accessible tree.
|
|
|
|
*/
|
2015-03-21 09:28:04 -07:00
|
|
|
class TreeWalker final
|
2010-02-20 16:55:04 -08:00
|
|
|
{
|
|
|
|
public:
|
2014-02-15 07:21:40 -08:00
|
|
|
enum {
|
|
|
|
// used to walk the existing tree of the given node
|
|
|
|
eWalkCache = 1,
|
|
|
|
// used to walk the context tree starting from given node
|
|
|
|
eWalkContextTree = 2 | eWalkCache
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2016-02-26 10:29:27 -08:00
|
|
|
* Used to navigate and create if needed the accessible children.
|
|
|
|
*/
|
|
|
|
explicit TreeWalker(Accessible* aContext);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Used to navigate the accessible children relative to the anchor.
|
2014-02-15 07:21:40 -08:00
|
|
|
*
|
|
|
|
* @param aContext [in] container accessible for the given node, used to
|
|
|
|
* define accessible context
|
2016-02-26 10:29:27 -08:00
|
|
|
* @param aAnchorNode [in] the node the search will be prepared relative to
|
2014-02-15 07:21:40 -08:00
|
|
|
* @param aFlags [in] flags (see enum above)
|
|
|
|
*/
|
2016-03-14 03:16:00 -07:00
|
|
|
TreeWalker(Accessible* aContext, nsIContent* aAnchorNode, uint32_t aFlags = eWalkCache);
|
2016-02-26 10:29:27 -08:00
|
|
|
|
2014-02-15 07:21:40 -08:00
|
|
|
~TreeWalker();
|
2010-02-20 16:55:04 -08:00
|
|
|
|
|
|
|
/**
|
2016-02-18 14:57:17 -08:00
|
|
|
* Return the next accessible.
|
2011-03-31 02:30:58 -07:00
|
|
|
*
|
|
|
|
* @note Returned accessible is bound to the document, if the accessible is
|
|
|
|
* rejected during tree creation then the caller should be unbind it
|
|
|
|
* from the document.
|
2010-02-20 16:55:04 -08:00
|
|
|
*/
|
2016-02-18 14:57:17 -08:00
|
|
|
Accessible* Next();
|
2010-02-20 16:55:04 -08:00
|
|
|
|
|
|
|
private:
|
2012-11-19 01:20:09 -08:00
|
|
|
TreeWalker();
|
|
|
|
TreeWalker(const TreeWalker&);
|
|
|
|
TreeWalker& operator =(const TreeWalker&);
|
2010-02-20 16:55:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create new state for the given node and push it on top of stack.
|
|
|
|
*
|
|
|
|
* @note State stack is used to navigate up/down the DOM subtree during
|
|
|
|
* accessible children search.
|
|
|
|
*/
|
2016-02-28 08:30:46 -08:00
|
|
|
dom::AllChildrenIterator* PushState(nsIContent* aContent)
|
2014-08-11 23:02:28 -07:00
|
|
|
{
|
2016-02-28 08:30:46 -08:00
|
|
|
return mStateStack.AppendElement(
|
|
|
|
dom::AllChildrenIterator(aContent, mChildFilter));
|
2014-08-11 23:02:28 -07:00
|
|
|
}
|
2010-02-20 16:55:04 -08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Pop state from stack.
|
|
|
|
*/
|
2016-02-28 08:30:46 -08:00
|
|
|
dom::AllChildrenIterator* PopState();
|
2010-02-20 16:55:04 -08:00
|
|
|
|
2012-05-27 02:01:40 -07:00
|
|
|
DocAccessible* mDoc;
|
2012-11-17 07:27:03 -08:00
|
|
|
Accessible* mContext;
|
2014-08-11 23:02:28 -07:00
|
|
|
nsIContent* mAnchorNode;
|
2016-02-28 08:30:46 -08:00
|
|
|
|
|
|
|
AutoTArray<dom::AllChildrenIterator, 20> mStateStack;
|
|
|
|
uint32_t mARIAOwnsIdx;
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t mChildFilter;
|
2014-02-15 07:21:40 -08:00
|
|
|
uint32_t mFlags;
|
2010-02-20 16:55:04 -08:00
|
|
|
};
|
|
|
|
|
2012-11-19 01:20:09 -08:00
|
|
|
} // namespace a11y
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_a11y_TreeWalker_h_
|