Files
palemoon27/accessible/base/TreeWalker.cpp
T
roytam1 ef71ea0137 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1163397 - Convert PaintedLayerData::mLog to an nsCString in order to make it possible to safely store PaintedLayerData inside nsTArrays; r=roc (5b646d03e2)
- Bug 1195672 - Make focus changing by long tap behaves like by single tap. f=mtseng, r=roc (d9e71b113b)
- Bug 1155493 - Part 3: Dispatch event when carets are updated, pressed, released, tap, longpressonemptycontent, hidden. r=roc (cf25fa0a0b)
- Bug 1169151 - Update carets after long tapping on empty input. r=mtseng This fixed AccessibleCarets remain on the screen when long tapping on an empty input. (c04359621c)
- Bug 1170084 - Dispatch CaretStateChangedEvent via AsyncEventDispatcher. r=mtseng (4a9a95d6cf)
- Bug 1174600 - Fix first AccessibleCarets jumps to top of the screen when dragging. r=mtseng (7f9dc6de0b)
- Bug 1181418 - Send selectionEditable info to app_text_selection_dialog. r=tlin, r=kanru, sr=smaug (9d46e651c2)
- Bug 1194063 - Always launch caret timer in cursor mode. r=mtseng If the timer is not launched when the content is empty, the first caret will always has Appearance::NormalNotShown, which is not consistent with the behavior when the caret is shown when the content is not empty. (e49cc7199a)
- Bug 1195672 - Move the check that frame is selectable into SelectWord. f=mtseng, r=roc (131cc459d5)
- Bug 1195672 - Revise the logic of long tap on empty content. f=mtseng, r=roc (2aa98cd92d)
- Bug 1195672 - Add |nsAutoCString nsIFrame::ListTag()| for debugging. f=mtseng, r=roc (74c539bc52)
- Bug 1197739 - Do not change focus too early unless the frame is selectable. r=roc (85c00877ff)
- Bug 1100602 - Fire show/hide events in HTMLLIAccessible::UpdateBullet r=tbsaunde (d3bc4eee20)
- bug 1160181, don't deal with EventTargets for which a JS wrapper can't be created, rs=froydnj (266b2be346)
- Bug 1180798 - Pass event names in nsIEventListenerChangeListener r=smaug (29e684006b)
- Bug 1175913 - (Part 1) Subscribe to EventListenerService and recreate accessibles on click listener changes r=tbsaunde (374122f366)
- Bug 1175913 - (Part 2) Remove test expecting recreation on click listener change r=tbsaunde (497c12b886)
- bug 1189277 - only coalesce reorder events when a previous one for the same target is obsolete r=surkov (7bf90364ce)
- Bug 1136395 - accessibility/mochitest/test/common.js could use some additional output to help debug issues. r=surkov (316115f838)
- Bug 1133213 - make aria-owns to alter the accessible tree, fire show/hide mutation events as we do for the accessible tree alterations, r=yzen, f=davidb (d8ee919fe7)
- Bug 114524 - adding null check before creating treewalker in nsAccessibilityService::ContentRemoved r=surkov (c3b9eff4f8)
- Bug 1139834 - TraceLogger: refactor to add fail function, r=bbouvier (be0fdc7ca6)
- missing part of Bug 1139759 (5ea4d063ad)
- pointer style (afaf0014f2)
- useless crashreporter stuff (ac11789907)
2022-03-08 07:22:48 +08:00

147 lines
4.1 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
#include "TreeWalker.h"
#include "Accessible.h"
#include "AccIterator.h"
#include "nsAccessibilityService.h"
#include "DocAccessible.h"
#include "mozilla/dom/ChildIterator.h"
#include "mozilla/dom/Element.h"
using namespace mozilla;
using namespace mozilla::a11y;
////////////////////////////////////////////////////////////////////////////////
// TreeWalker
////////////////////////////////////////////////////////////////////////////////
TreeWalker::
TreeWalker(Accessible* aContext, nsIContent* aContent, uint32_t aFlags) :
mDoc(aContext->Document()), mContext(aContext), mAnchorNode(aContent),
mFlags(aFlags)
{
NS_ASSERTION(aContent, "No node for the accessible tree walker!");
mChildFilter = mContext->CanHaveAnonChildren() ?
nsIContent::eAllChildren : nsIContent::eAllButXBL;
mChildFilter |= nsIContent::eSkipPlaceholderContent;
if (aContent)
PushState(aContent);
MOZ_COUNT_CTOR(TreeWalker);
}
TreeWalker::~TreeWalker()
{
MOZ_COUNT_DTOR(TreeWalker);
}
////////////////////////////////////////////////////////////////////////////////
// TreeWalker: private
Accessible*
TreeWalker::NextChild()
{
if (mStateStack.IsEmpty())
return nullptr;
ChildrenIterator* top = &mStateStack[mStateStack.Length() - 1];
while (top) {
Accessible* child = nullptr;
bool skipSubtree = false;
while (nsIContent* childNode = Next(top, &child, &skipSubtree)) {
if (child)
return child;
// Walk down into subtree to find accessibles.
if (!skipSubtree && childNode->IsElement())
top = PushState(childNode);
}
top = PopState();
}
// 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;
nsINode* contextNode = mContext->GetNode();
while (mAnchorNode != contextNode) {
nsINode* parentNode = mAnchorNode->GetFlattenedTreeParent();
if (!parentNode || !parentNode->IsElement())
return nullptr;
nsIContent* parent = parentNode->AsElement();
top = PushState(parent);
while (nsIContent* childNode = Next(top)) {
if (childNode == mAnchorNode) {
mAnchorNode = parent;
return NextChild();
}
}
// 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;
}
return nullptr;
}
nsIContent*
TreeWalker::Next(ChildrenIterator* aIter, Accessible** aAccesible,
bool* aSkipSubtree)
{
nsIContent* childEl = aIter->mDOMIter.GetNextChild();
if (!aAccesible)
return childEl;
*aAccesible = nullptr;
*aSkipSubtree = false;
if (childEl) {
Accessible* accessible = mFlags & eWalkCache ?
mDoc->GetAccessible(childEl) :
GetAccService()->GetOrCreateAccessible(childEl, mContext, aSkipSubtree);
// Ignore the accessible and its subtree if it was repositioned by means of
// aria-owns.
if (accessible) {
if (accessible->IsRepositioned()) {
*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*
TreeWalker::PopState()
{
size_t length = mStateStack.Length();
mStateStack.RemoveElementAt(length - 1);
return mStateStack.IsEmpty() ? nullptr : &mStateStack[mStateStack.Length() - 1];
}