2010-02-21 00:55:04 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2003
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Aaron Leventhal <aaronleventhal@moonset.net> (original author)
|
|
|
|
* Alexander Surkov <surkov.alexander@gmail.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "nsAccTreeWalker.h"
|
|
|
|
|
2010-02-21 00:56:35 +00:00
|
|
|
#include "nsAccessible.h"
|
2010-02-21 00:55:04 +00:00
|
|
|
#include "nsAccessibilityService.h"
|
|
|
|
|
2010-06-08 16:39:58 +00:00
|
|
|
#include "nsINodeList.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
|
2010-02-21 00:55:04 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// WalkState
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct WalkState
|
|
|
|
{
|
|
|
|
WalkState(nsIContent *aContent) :
|
|
|
|
content(aContent), childIdx(0), prevState(nsnull) {}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIContent> content;
|
|
|
|
nsCOMPtr<nsINodeList> childList;
|
|
|
|
PRUint32 childIdx;
|
|
|
|
WalkState *prevState;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccTreeWalker
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsAccTreeWalker::
|
|
|
|
nsAccTreeWalker(nsIWeakReference* aShell, nsIContent* aContent,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool aWalkAnonContent, bool aWalkCache) :
|
2011-05-20 10:55:37 +00:00
|
|
|
mWeakShell(aShell), mWalkCache(aWalkCache), mState(nsnull)
|
2010-02-21 00:55:04 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aContent, "No node for the accessible tree walker!");
|
|
|
|
|
|
|
|
if (aContent)
|
|
|
|
mState = new WalkState(aContent);
|
|
|
|
|
2010-10-15 15:34:35 +00:00
|
|
|
mChildFilter = aWalkAnonContent ? nsIContent::eAllChildren :
|
2010-02-21 00:55:04 +00:00
|
|
|
nsIContent::eAllButXBL;
|
|
|
|
|
2010-10-15 15:34:35 +00:00
|
|
|
mChildFilter |= nsIContent::eSkipPlaceholderContent;
|
|
|
|
|
2010-02-21 00:55:04 +00:00
|
|
|
MOZ_COUNT_CTOR(nsAccTreeWalker);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAccTreeWalker::~nsAccTreeWalker()
|
|
|
|
{
|
|
|
|
// Clear state stack from memory
|
|
|
|
while (mState)
|
|
|
|
PopState();
|
|
|
|
|
|
|
|
MOZ_COUNT_DTOR(nsAccTreeWalker);
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccTreeWalker: private
|
|
|
|
|
2011-03-31 09:30:58 +00:00
|
|
|
nsAccessible*
|
|
|
|
nsAccTreeWalker::NextChildInternal(bool aNoWalkUp)
|
2010-02-21 00:55:04 +00:00
|
|
|
{
|
|
|
|
if (!mState || !mState->content)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
if (!mState->childList)
|
2010-10-15 15:34:35 +00:00
|
|
|
mState->childList = mState->content->GetChildren(mChildFilter);
|
2010-02-21 00:55:04 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell(do_QueryReferent(mWeakShell));
|
|
|
|
|
|
|
|
PRUint32 length = 0;
|
|
|
|
if (mState->childList)
|
|
|
|
mState->childList->GetLength(&length);
|
|
|
|
|
2010-02-21 01:31:07 +00:00
|
|
|
while (mState->childIdx < length) {
|
2010-02-21 00:55:04 +00:00
|
|
|
nsIContent* childNode = mState->childList->GetNodeAt(mState->childIdx);
|
|
|
|
mState->childIdx++;
|
|
|
|
|
2010-11-13 17:49:26 +00:00
|
|
|
bool isSubtreeHidden = false;
|
2011-04-07 05:17:29 +00:00
|
|
|
nsAccessible* accessible = mWalkCache ?
|
|
|
|
GetAccService()->GetAccessibleInWeakShell(childNode, mWeakShell) :
|
2010-07-01 02:18:08 +00:00
|
|
|
GetAccService()->GetOrCreateAccessible(childNode, presShell, mWeakShell,
|
2010-11-13 17:49:26 +00:00
|
|
|
&isSubtreeHidden);
|
2010-02-21 00:55:04 +00:00
|
|
|
|
|
|
|
if (accessible)
|
2011-03-31 09:30:58 +00:00
|
|
|
return accessible;
|
2010-02-21 00:55:04 +00:00
|
|
|
|
|
|
|
// Walk down into subtree to find accessibles.
|
2010-11-13 17:49:26 +00:00
|
|
|
if (!isSubtreeHidden) {
|
2010-02-21 00:55:04 +00:00
|
|
|
if (!PushState(childNode))
|
|
|
|
break;
|
|
|
|
|
2011-03-31 09:30:58 +00:00
|
|
|
accessible = NextChildInternal(true);
|
2010-02-21 00:55:04 +00:00
|
|
|
if (accessible)
|
2011-03-31 09:30:58 +00:00
|
|
|
return accessible;
|
2010-02-21 00:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No more children, get back to the parent.
|
|
|
|
PopState();
|
|
|
|
|
2011-03-31 09:30:58 +00:00
|
|
|
return aNoWalkUp ? nsnull : NextChildInternal(false);
|
2010-02-21 00:55:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsAccTreeWalker::PopState()
|
|
|
|
{
|
|
|
|
WalkState* prevToLastState = mState->prevState;
|
|
|
|
delete mState;
|
|
|
|
mState = prevToLastState;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2010-02-21 00:55:04 +00:00
|
|
|
nsAccTreeWalker::PushState(nsIContent* aContent)
|
|
|
|
{
|
|
|
|
WalkState* nextToLastState = new WalkState(aContent);
|
|
|
|
if (!nextToLastState)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
nextToLastState->prevState = mState;
|
|
|
|
mState = nextToLastState;
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|