2010-02-21 03:55:04 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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-21 03:55:04 +03:00
|
|
|
|
2012-11-19 13:20:09 +04:00
|
|
|
#include "TreeWalker.h"
|
2010-02-21 03:55:04 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
#include "Accessible.h"
|
2015-09-15 19:01:51 +03:00
|
|
|
#include "AccIterator.h"
|
2010-02-21 03:55:04 +03:00
|
|
|
#include "nsAccessibilityService.h"
|
2012-05-27 13:01:40 +04:00
|
|
|
#include "DocAccessible.h"
|
2010-02-21 03:55:04 +03:00
|
|
|
|
2014-07-16 22:41:57 +04:00
|
|
|
#include "mozilla/dom/ChildIterator.h"
|
2014-02-15 19:21:40 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2010-06-08 20:39:58 +04:00
|
|
|
|
2014-08-12 10:02:28 +04:00
|
|
|
using namespace mozilla;
|
2012-11-18 06:01:44 +04:00
|
|
|
using namespace mozilla::a11y;
|
|
|
|
|
2010-02-21 03:55:04 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-19 13:20:09 +04:00
|
|
|
// TreeWalker
|
2010-02-21 03:55:04 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-11-19 13:20:09 +04:00
|
|
|
TreeWalker::
|
2014-02-15 19:21:40 +04:00
|
|
|
TreeWalker(Accessible* aContext, nsIContent* aContent, uint32_t aFlags) :
|
2014-08-12 10:02:28 +04:00
|
|
|
mDoc(aContext->Document()), mContext(aContext), mAnchorNode(aContent),
|
2016-02-26 19:04:05 +03:00
|
|
|
mFlags(aFlags)
|
2010-02-21 03:55:04 +03:00
|
|
|
{
|
2016-02-26 19:04:05 +03:00
|
|
|
NS_ASSERTION(aContent, "No node for the accessible tree walker!");
|
2010-02-21 03:55:04 +03:00
|
|
|
|
2016-02-26 19:04:05 +03:00
|
|
|
mChildFilter = mContext->NoXBLKids() ?
|
|
|
|
nsIContent::eAllButXBL : nsIContent::eAllChildren;
|
|
|
|
mChildFilter |= nsIContent::eSkipPlaceholderContent;
|
2010-10-15 19:34:35 +04:00
|
|
|
|
2016-02-26 19:04:05 +03:00
|
|
|
if (aContent)
|
|
|
|
PushState(aContent);
|
2014-07-16 22:41:57 +04:00
|
|
|
|
2012-11-19 13:20:09 +04:00
|
|
|
MOZ_COUNT_CTOR(TreeWalker);
|
2010-02-21 03:55:04 +03:00
|
|
|
}
|
|
|
|
|
2012-11-19 13:20:09 +04:00
|
|
|
TreeWalker::~TreeWalker()
|
2010-02-21 03:55:04 +03:00
|
|
|
{
|
2012-11-19 13:20:09 +04:00
|
|
|
MOZ_COUNT_DTOR(TreeWalker);
|
2010-02-21 03:55:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2012-11-19 13:20:09 +04:00
|
|
|
// TreeWalker: private
|
2010-02-21 03:55:04 +03:00
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible*
|
2016-02-19 01:57:17 +03:00
|
|
|
TreeWalker::Next()
|
2010-02-21 03:55:04 +03:00
|
|
|
{
|
2014-08-12 10:02:28 +04:00
|
|
|
if (mStateStack.IsEmpty())
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-02-21 03:55:04 +03:00
|
|
|
|
2015-09-15 19:01:51 +03:00
|
|
|
ChildrenIterator* top = &mStateStack[mStateStack.Length() - 1];
|
2014-08-12 10:02:28 +04:00
|
|
|
while (top) {
|
2015-09-15 19:01:51 +03:00
|
|
|
Accessible* child = nullptr;
|
|
|
|
bool skipSubtree = false;
|
|
|
|
while (nsIContent* childNode = Next(top, &child, &skipSubtree)) {
|
|
|
|
if (child)
|
|
|
|
return child;
|
2014-02-15 19:21:40 +04:00
|
|
|
|
2014-08-12 10:02:28 +04:00
|
|
|
// Walk down into subtree to find accessibles.
|
2015-09-15 19:01:51 +03:00
|
|
|
if (!skipSubtree && childNode->IsElement())
|
2014-08-12 10:02:28 +04:00
|
|
|
top = PushState(childNode);
|
|
|
|
}
|
2014-09-01 16:31:35 +04:00
|
|
|
|
2014-08-12 10:02:28 +04:00
|
|
|
top = PopState();
|
|
|
|
}
|
2014-09-01 16:31:35 +04:00
|
|
|
|
2014-02-15 19:21:40 +04:00
|
|
|
// If we traversed the whole subtree of the anchor node. Move to next node
|
|
|
|
// relative anchor node within the context subtree if possible.
|
|
|
|
if (mFlags != eWalkContextTree)
|
|
|
|
return nullptr;
|
|
|
|
|
2014-08-12 10:02:28 +04:00
|
|
|
nsINode* contextNode = mContext->GetNode();
|
|
|
|
while (mAnchorNode != contextNode) {
|
|
|
|
nsINode* parentNode = mAnchorNode->GetFlattenedTreeParent();
|
2014-02-15 19:21:40 +04:00
|
|
|
if (!parentNode || !parentNode->IsElement())
|
|
|
|
return nullptr;
|
2010-02-21 03:55:04 +03:00
|
|
|
|
2014-08-12 10:02:28 +04:00
|
|
|
nsIContent* parent = parentNode->AsElement();
|
2015-09-15 19:01:51 +03:00
|
|
|
top = PushState(parent);
|
2016-02-11 16:24:38 +03:00
|
|
|
if (top->mDOMIter.Seek(mAnchorNode)) {
|
|
|
|
mAnchorNode = parent;
|
2016-02-19 01:57:17 +03:00
|
|
|
return Next();
|
2014-02-15 19:21:40 +04:00
|
|
|
}
|
2014-09-01 16:31:35 +04:00
|
|
|
|
2014-08-12 10:02:28 +04:00
|
|
|
// XXX We really should never get here, it means we're trying to find an
|
|
|
|
// accessible for a dom node where iterating over its parent's children
|
|
|
|
// doesn't return it. However this sometimes happens when we're asked for
|
|
|
|
// the nearest accessible to place holder content which we ignore.
|
|
|
|
mAnchorNode = parent;
|
2014-02-15 19:21:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
2010-02-21 03:55:04 +03:00
|
|
|
}
|
|
|
|
|
2015-09-15 19:01:51 +03:00
|
|
|
nsIContent*
|
|
|
|
TreeWalker::Next(ChildrenIterator* aIter, Accessible** aAccesible,
|
|
|
|
bool* aSkipSubtree)
|
|
|
|
{
|
|
|
|
nsIContent* childEl = aIter->mDOMIter.GetNextChild();
|
|
|
|
if (!aAccesible)
|
|
|
|
return childEl;
|
|
|
|
|
|
|
|
*aAccesible = nullptr;
|
|
|
|
*aSkipSubtree = false;
|
|
|
|
|
|
|
|
if (childEl) {
|
2016-02-24 16:01:21 +03:00
|
|
|
Accessible* accessible = nullptr;
|
|
|
|
if (mFlags & eWalkCache) {
|
|
|
|
accessible = mDoc->GetAccessible(childEl);
|
|
|
|
}
|
|
|
|
else if (mContext->IsAcceptableChild(childEl)) {
|
|
|
|
accessible = GetAccService()->
|
|
|
|
GetOrCreateAccessible(childEl, mContext, aSkipSubtree);
|
|
|
|
}
|
2015-09-15 19:01:51 +03:00
|
|
|
|
|
|
|
// Ignore the accessible and its subtree if it was repositioned by means of
|
|
|
|
// aria-owns.
|
|
|
|
if (accessible) {
|
2015-10-30 01:08:48 +03:00
|
|
|
if (accessible->IsRelocated()) {
|
2015-09-15 19:01:51 +03:00
|
|
|
*aSkipSubtree = true;
|
|
|
|
} else {
|
|
|
|
*aAccesible = accessible;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return childEl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At last iterate over ARIA owned children.
|
|
|
|
Accessible* parent = mDoc->GetAccessible(aIter->mDOMIter.Parent());
|
|
|
|
if (parent) {
|
|
|
|
Accessible* child = mDoc->ARIAOwnedAt(parent, aIter->mARIAOwnsIdx++);
|
|
|
|
if (child) {
|
|
|
|
*aAccesible = child;
|
|
|
|
return child->GetContent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TreeWalker::ChildrenIterator*
|
2012-11-19 13:20:09 +04:00
|
|
|
TreeWalker::PopState()
|
2010-02-21 03:55:04 +03:00
|
|
|
{
|
2014-08-12 10:02:28 +04:00
|
|
|
size_t length = mStateStack.Length();
|
|
|
|
mStateStack.RemoveElementAt(length - 1);
|
|
|
|
return mStateStack.IsEmpty() ? nullptr : &mStateStack[mStateStack.Length() - 1];
|
2010-02-21 03:55:04 +03:00
|
|
|
}
|