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-05-20 11:40:25 +04:00
|
|
|
|
2010-06-21 17:08:27 +04:00
|
|
|
#include "AccIterator.h"
|
|
|
|
|
2013-02-26 11:17:10 +04:00
|
|
|
#include "AccGroupInfo.h"
|
|
|
|
#ifdef MOZ_XUL
|
|
|
|
# include "XULTreeAccessible.h"
|
|
|
|
#endif
|
2010-05-20 11:40:25 +04:00
|
|
|
|
2015-11-24 22:44:24 +03:00
|
|
|
#include "mozilla/dom/HTMLLabelElement.h"
|
2012-03-13 20:06:21 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-06-11 02:18:31 +04:00
|
|
|
using namespace mozilla::a11y;
|
2011-08-10 05:44:00 +04:00
|
|
|
|
2010-05-20 11:40:25 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-11-18 05:55:44 +03:00
|
|
|
// AccIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2010-05-20 11:40:25 +04:00
|
|
|
|
2018-05-04 16:37:11 +03:00
|
|
|
AccIterator::AccIterator(const Accessible* aAccessible,
|
2012-08-28 17:13:59 +04:00
|
|
|
filters::FilterFuncPtr aFilterFunc)
|
|
|
|
: mFilterFunc(aFilterFunc) {
|
2010-05-20 11:40:25 +04:00
|
|
|
mState = new IteratorState(aAccessible);
|
|
|
|
}
|
|
|
|
|
2010-06-21 17:08:27 +04:00
|
|
|
AccIterator::~AccIterator() {
|
2010-05-20 11:40:25 +04:00
|
|
|
while (mState) {
|
|
|
|
IteratorState* tmp = mState;
|
|
|
|
mState = tmp->mParentState;
|
|
|
|
delete tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
Accessible* AccIterator::Next() {
|
2010-05-20 11:40:25 +04:00
|
|
|
while (mState) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* child = mState->mParent->GetChildAt(mState->mIndex++);
|
2010-05-20 11:40:25 +04:00
|
|
|
if (!child) {
|
2012-08-28 17:13:59 +04:00
|
|
|
IteratorState* tmp = mState;
|
2010-05-20 11:40:25 +04:00
|
|
|
mState = mState->mParentState;
|
|
|
|
delete tmp;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2012-08-28 17:13:59 +04:00
|
|
|
uint32_t result = mFilterFunc(child);
|
|
|
|
if (result & filters::eMatch) return child;
|
2010-05-20 11:40:25 +04:00
|
|
|
|
2012-08-28 17:13:59 +04:00
|
|
|
if (!(result & filters::eSkipSubtree)) {
|
|
|
|
IteratorState* childState = new IteratorState(child, mState);
|
2010-05-20 11:40:25 +04:00
|
|
|
mState = childState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-05-20 11:40:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsAccIterator::IteratorState
|
|
|
|
|
2018-05-04 16:37:11 +03:00
|
|
|
AccIterator::IteratorState::IteratorState(const Accessible* aParent,
|
2010-06-21 17:08:27 +04:00
|
|
|
IteratorState* mParentState)
|
2010-05-20 11:40:25 +04:00
|
|
|
: mParent(aParent), mIndex(0), mParentState(mParentState) {}
|
2010-11-18 05:55:44 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// RelatedAccIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
RelatedAccIterator::RelatedAccIterator(DocAccessible* aDocument,
|
|
|
|
nsIContent* aDependentContent,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aRelAttr)
|
2012-07-30 18:20:58 +04:00
|
|
|
: mDocument(aDocument),
|
|
|
|
mRelAttr(aRelAttr),
|
|
|
|
mProviders(nullptr),
|
|
|
|
mBindingParent(nullptr),
|
|
|
|
mIndex(0) {
|
2018-10-30 03:17:04 +03:00
|
|
|
mBindingParent = aDependentContent->IsInAnonymousSubtree()
|
|
|
|
? aDependentContent->GetBindingParent()
|
|
|
|
: nullptr;
|
2014-05-30 11:36:53 +04:00
|
|
|
nsAtom* IDAttr = mBindingParent ? nsGkAtoms::anonid : nsGkAtoms::id;
|
2010-11-18 05:55:44 +03:00
|
|
|
|
|
|
|
nsAutoString id;
|
2017-12-07 21:13:50 +03:00
|
|
|
if (aDependentContent->IsElement() &&
|
2018-10-30 03:17:04 +03:00
|
|
|
aDependentContent->AsElement()->GetAttr(kNameSpaceID_None, IDAttr, id)) {
|
|
|
|
mProviders = mDocument->GetRelProviders(aDependentContent->AsElement(), id);
|
|
|
|
}
|
2010-11-18 05:55:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* RelatedAccIterator::Next() {
|
|
|
|
if (!mProviders) return nullptr;
|
|
|
|
|
|
|
|
while (mIndex < mProviders->Length()) {
|
2012-05-27 13:01:40 +04:00
|
|
|
DocAccessible::AttrRelProvider* provider = (*mProviders)[mIndex++];
|
2010-11-18 05:55:44 +03:00
|
|
|
|
|
|
|
// Return related accessible for the given attribute and if the provider
|
|
|
|
// content is in the same binding in the case of XBL usage.
|
2012-03-13 20:06:21 +04:00
|
|
|
if (provider->mRelAttr == mRelAttr) {
|
2018-10-30 03:17:04 +03:00
|
|
|
nsIContent* bindingParent = provider->mContent->IsInAnonymousSubtree()
|
|
|
|
? provider->mContent->GetBindingParent()
|
|
|
|
: nullptr;
|
2012-03-13 20:06:21 +04:00
|
|
|
bool inScope = mBindingParent == bindingParent ||
|
|
|
|
mBindingParent == provider->mContent;
|
|
|
|
|
|
|
|
if (inScope) {
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* related = mDocument->GetAccessible(provider->mContent);
|
2012-03-13 20:06:21 +04:00
|
|
|
if (related) return related;
|
|
|
|
|
|
|
|
// If the document content is pointed by relation then return the
|
|
|
|
// document itself.
|
|
|
|
if (provider->mContent == mDocument->GetContent()) return mDocument;
|
|
|
|
}
|
2010-11-18 05:55:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-18 05:55:44 +03:00
|
|
|
}
|
2010-11-20 05:37:18 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLLabelIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-29 05:18:45 +04:00
|
|
|
HTMLLabelIterator::HTMLLabelIterator(DocAccessible* aDocument,
|
|
|
|
const Accessible* aAccessible,
|
2010-11-20 05:37:18 +03:00
|
|
|
LabelFilter aFilter)
|
2011-09-29 07:13:08 +04:00
|
|
|
: mRelIter(aDocument, aAccessible->GetContent(), nsGkAtoms::_for),
|
|
|
|
mAcc(aAccessible),
|
|
|
|
mLabelFilter(aFilter) {}
|
2010-11-20 05:37:18 +03:00
|
|
|
|
2015-11-24 22:44:24 +03:00
|
|
|
bool HTMLLabelIterator::IsLabel(Accessible* aLabel) {
|
|
|
|
dom::HTMLLabelElement* labelEl =
|
2018-03-22 00:39:04 +03:00
|
|
|
dom::HTMLLabelElement::FromNode(aLabel->GetContent());
|
2015-11-24 22:44:24 +03:00
|
|
|
return labelEl && labelEl->GetControl() == mAcc->GetContent();
|
|
|
|
}
|
|
|
|
|
2010-11-20 05:37:18 +03:00
|
|
|
Accessible* HTMLLabelIterator::Next() {
|
|
|
|
// Get either <label for="[id]"> element which explicitly points to given
|
|
|
|
// element, or <label> ancestor which implicitly point to it.
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* label = nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
while ((label = mRelIter.Next())) {
|
2015-11-24 22:44:24 +03:00
|
|
|
if (IsLabel(label)) {
|
2010-11-20 05:37:18 +03:00
|
|
|
return label;
|
2015-11-24 22:44:24 +03:00
|
|
|
}
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 07:13:08 +04:00
|
|
|
// Ignore ancestor label on not widget accessible.
|
|
|
|
if (mLabelFilter == eSkipAncestorLabel || !mAcc->IsWidget()) return nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
|
2011-09-29 07:13:08 +04:00
|
|
|
// Go up tree to get a name of ancestor label if there is one (an ancestor
|
|
|
|
// <label> implicitly points to us). Don't go up farther than form or
|
|
|
|
// document.
|
2012-05-29 05:18:45 +04:00
|
|
|
Accessible* walkUp = mAcc->Parent();
|
2011-09-29 07:13:08 +04:00
|
|
|
while (walkUp && !walkUp->IsDoc()) {
|
2015-11-24 22:44:24 +03:00
|
|
|
nsIContent* walkUpEl = walkUp->GetContent();
|
|
|
|
if (IsLabel(walkUp) &&
|
2017-12-07 21:13:50 +03:00
|
|
|
!walkUpEl->AsElement()->HasAttr(kNameSpaceID_None, nsGkAtoms::_for)) {
|
2015-03-03 14:08:59 +03:00
|
|
|
mLabelFilter = eSkipAncestorLabel; // prevent infinite loop
|
|
|
|
return walkUp;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
2011-09-29 07:13:08 +04:00
|
|
|
|
2015-11-24 22:44:24 +03:00
|
|
|
if (walkUpEl->IsHTMLElement(nsGkAtoms::form)) break;
|
2015-03-03 14:08:59 +03:00
|
|
|
|
2011-09-29 07:13:08 +04:00
|
|
|
walkUp = walkUp->Parent();
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// HTMLOutputIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
HTMLOutputIterator::HTMLOutputIterator(DocAccessible* aDocument,
|
|
|
|
nsIContent* aElement)
|
2011-06-04 01:35:17 +04:00
|
|
|
: mRelIter(aDocument, aElement, nsGkAtoms::_for) {}
|
2010-11-20 05:37:18 +03:00
|
|
|
|
|
|
|
Accessible* HTMLOutputIterator::Next() {
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* output = nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
while ((output = mRelIter.Next())) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (output->GetContent()->IsHTMLElement(nsGkAtoms::output)) return output;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULLabelIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
XULLabelIterator::XULLabelIterator(DocAccessible* aDocument,
|
|
|
|
nsIContent* aElement)
|
2011-06-04 01:35:17 +04:00
|
|
|
: mRelIter(aDocument, aElement, nsGkAtoms::control) {}
|
2010-11-20 05:37:18 +03:00
|
|
|
|
|
|
|
Accessible* XULLabelIterator::Next() {
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* label = nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
while ((label = mRelIter.Next())) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (label->GetContent()->IsXULElement(nsGkAtoms::label)) return label;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULDescriptionIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
XULDescriptionIterator::XULDescriptionIterator(DocAccessible* aDocument,
|
|
|
|
nsIContent* aElement)
|
2011-06-04 01:35:17 +04:00
|
|
|
: mRelIter(aDocument, aElement, nsGkAtoms::control) {}
|
2010-11-20 05:37:18 +03:00
|
|
|
|
|
|
|
Accessible* XULDescriptionIterator::Next() {
|
2012-07-30 18:20:58 +04:00
|
|
|
Accessible* descr = nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
while ((descr = mRelIter.Next())) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (descr->GetContent()->IsXULElement(nsGkAtoms::description)) return descr;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-11-20 05:37:18 +03:00
|
|
|
}
|
2011-08-10 05:44:00 +04:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// IDRefsIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2012-05-27 13:01:40 +04:00
|
|
|
IDRefsIterator::IDRefsIterator(DocAccessible* aDoc, nsIContent* aContent,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aIDRefsAttr)
|
2012-05-09 00:27:05 +04:00
|
|
|
: mContent(aContent), mDoc(aDoc), mCurrIdx(0) {
|
2018-10-30 03:17:04 +03:00
|
|
|
if (mContent->IsElement()) {
|
2017-12-07 21:13:50 +03:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, aIDRefsAttr, mIDs);
|
2018-10-30 03:17:04 +03:00
|
|
|
}
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const nsDependentSubstring IDRefsIterator::NextID() {
|
|
|
|
for (; mCurrIdx < mIDs.Length(); mCurrIdx++) {
|
|
|
|
if (!NS_IsAsciiWhitespace(mIDs[mCurrIdx])) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mCurrIdx >= mIDs.Length()) return nsDependentSubstring();
|
|
|
|
|
|
|
|
nsAString::index_type idStartIdx = mCurrIdx;
|
|
|
|
while (++mCurrIdx < mIDs.Length()) {
|
|
|
|
if (NS_IsAsciiWhitespace(mIDs[mCurrIdx])) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Substring(mIDs, idStartIdx, mCurrIdx++ - idStartIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* IDRefsIterator::NextElem() {
|
|
|
|
while (true) {
|
|
|
|
const nsDependentSubstring id = NextID();
|
|
|
|
if (id.IsEmpty()) break;
|
|
|
|
|
|
|
|
nsIContent* refContent = GetElem(id);
|
|
|
|
if (refContent) return refContent;
|
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent* IDRefsIterator::GetElem(const nsDependentSubstring& aID) {
|
2012-03-13 20:06:21 +04:00
|
|
|
// Get elements in DOM tree by ID attribute if this is an explicit content.
|
|
|
|
// In case of bound element check its anonymous subtree.
|
|
|
|
if (!mContent->IsInAnonymousSubtree()) {
|
2018-10-30 03:17:04 +03:00
|
|
|
dom::DocumentOrShadowRoot* docOrShadowRoot =
|
|
|
|
mContent->GetUncomposedDocOrConnectedShadowRoot();
|
|
|
|
if (docOrShadowRoot) {
|
|
|
|
dom::Element* refElm = docOrShadowRoot->GetElementById(aID);
|
|
|
|
if (refElm || !mContent->GetXBLBinding()) return refElm;
|
|
|
|
}
|
2012-03-13 20:06:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If content is in anonymous subtree or an element having anonymous subtree
|
|
|
|
// then use "anonid" attribute to get elements in anonymous subtree.
|
|
|
|
|
|
|
|
// Check inside the binding the element is contained in.
|
|
|
|
nsIContent* bindingParent = mContent->GetBindingParent();
|
|
|
|
if (bindingParent) {
|
2012-05-28 08:52:53 +04:00
|
|
|
nsIContent* refElm =
|
|
|
|
bindingParent->OwnerDoc()->GetAnonymousElementByAttribute(
|
|
|
|
bindingParent, nsGkAtoms::anonid, aID);
|
|
|
|
|
2012-03-13 20:06:21 +04:00
|
|
|
if (refElm) return refElm;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check inside the binding of the element.
|
2013-07-17 20:05:03 +04:00
|
|
|
if (mContent->GetXBLBinding()) {
|
2012-05-28 08:52:53 +04:00
|
|
|
return mContent->OwnerDoc()->GetAnonymousElementByAttribute(
|
|
|
|
mContent, nsGkAtoms::anonid, aID);
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* IDRefsIterator::Next() {
|
2015-10-30 01:08:48 +03:00
|
|
|
nsIContent* nextEl = nullptr;
|
|
|
|
while ((nextEl = NextElem())) {
|
|
|
|
Accessible* acc = mDoc->GetAccessible(nextEl);
|
|
|
|
if (acc) {
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
2013-02-26 11:17:10 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// SingleAccIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-10 05:44:00 +04:00
|
|
|
Accessible* SingleAccIterator::Next() {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Accessible> nextAcc;
|
2011-08-10 05:44:00 +04:00
|
|
|
mAcc.swap(nextAcc);
|
2015-08-13 15:22:48 +03:00
|
|
|
if (!nextAcc || nextAcc->IsDefunct()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return nextAcc;
|
2011-08-10 05:44:00 +04:00
|
|
|
}
|
|
|
|
|
2013-02-26 11:17:10 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// ItemIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Accessible* ItemIterator::Next() {
|
|
|
|
if (mContainer) {
|
|
|
|
mAnchor = AccGroupInfo::FirstItemOf(mContainer);
|
|
|
|
mContainer = nullptr;
|
|
|
|
return mAnchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mAnchor ? (mAnchor = AccGroupInfo::NextItemTo(mAnchor)) : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// XULTreeItemIterator
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2018-05-13 12:14:29 +03:00
|
|
|
XULTreeItemIterator::XULTreeItemIterator(const XULTreeAccessible* aXULTree,
|
2013-02-26 11:17:10 +04:00
|
|
|
nsITreeView* aTreeView,
|
|
|
|
int32_t aRowIdx)
|
|
|
|
: mXULTree(aXULTree),
|
|
|
|
mTreeView(aTreeView),
|
|
|
|
mRowCount(-1),
|
|
|
|
mContainerLevel(-1),
|
|
|
|
mCurrRowIdx(aRowIdx + 1) {
|
|
|
|
mTreeView->GetRowCount(&mRowCount);
|
|
|
|
if (aRowIdx != -1) mTreeView->GetLevel(aRowIdx, &mContainerLevel);
|
|
|
|
}
|
|
|
|
|
|
|
|
Accessible* XULTreeItemIterator::Next() {
|
|
|
|
while (mCurrRowIdx < mRowCount) {
|
|
|
|
int32_t level = 0;
|
|
|
|
mTreeView->GetLevel(mCurrRowIdx, &level);
|
|
|
|
|
|
|
|
if (level == mContainerLevel + 1)
|
|
|
|
return mXULTree->GetTreeItemAccessible(mCurrRowIdx++);
|
|
|
|
|
|
|
|
if (level <= mContainerLevel) { // got level up
|
|
|
|
mCurrRowIdx = mRowCount;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
mCurrRowIdx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|