Source code

Revision control

Other Tools

1
/* -*- Mode: c++; c-basic-offset: 2; tab-width: 20; indent-tabs-mode: nil; -*-
2
* This Source Code Form is subject to the terms of the Mozilla Public
3
* License, v. 2.0. If a copy of the MPL was not distributed with this
4
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6
#include "RootAccessibleWrap.h"
7
8
#include "Accessible-inl.h"
9
#include "AccessibleOrProxy.h"
10
#include "DocAccessibleParent.h"
11
#include "ProxyAccessibleWrap.h"
12
#include "SessionAccessibility.h"
13
#include "mozilla/PresShell.h"
14
15
using namespace mozilla;
16
using namespace mozilla::a11y;
17
18
RootAccessibleWrap::RootAccessibleWrap(dom::Document* aDoc,
19
PresShell* aPresShell)
20
: RootAccessible(aDoc, aPresShell) {}
21
22
RootAccessibleWrap::~RootAccessibleWrap() {}
23
24
AccessibleWrap* RootAccessibleWrap::GetContentAccessible() {
25
if (ProxyAccessible* proxy = GetPrimaryRemoteTopLevelContentDoc()) {
26
return WrapperFor(proxy);
27
}
28
29
// Find first document that is not defunct or hidden.
30
// This is exclusively for Fennec which has a deck of browser elements.
31
// Otherwise, standard GeckoView will only have one browser element.
32
for (size_t i = 0; i < ChildDocumentCount(); i++) {
33
DocAccessible* childDoc = GetChildDocumentAt(i);
34
if (childDoc && !childDoc->IsDefunct() && !childDoc->IsHidden()) {
35
return childDoc;
36
}
37
}
38
39
return nullptr;
40
}
41
42
AccessibleWrap* RootAccessibleWrap::FindAccessibleById(int32_t aID) {
43
AccessibleWrap* contentAcc = GetContentAccessible();
44
45
if (!contentAcc) {
46
return nullptr;
47
}
48
49
if (aID == AccessibleWrap::kNoID) {
50
return contentAcc;
51
}
52
53
if (contentAcc->IsProxy()) {
54
return FindAccessibleById(static_cast<DocProxyAccessibleWrap*>(contentAcc),
55
aID);
56
}
57
58
return FindAccessibleById(
59
static_cast<DocAccessibleWrap*>(contentAcc->AsDoc()), aID);
60
}
61
62
AccessibleWrap* RootAccessibleWrap::FindAccessibleById(
63
DocProxyAccessibleWrap* aDoc, int32_t aID) {
64
AccessibleWrap* acc = aDoc->GetAccessibleByID(aID);
65
uint32_t index = 0;
66
while (!acc) {
67
auto child =
68
static_cast<DocProxyAccessibleWrap*>(aDoc->GetChildDocumentAt(index++));
69
if (!child) {
70
break;
71
}
72
acc = FindAccessibleById(child, aID);
73
}
74
75
return acc;
76
}
77
78
AccessibleWrap* RootAccessibleWrap::FindAccessibleById(DocAccessibleWrap* aDoc,
79
int32_t aID) {
80
AccessibleWrap* acc = aDoc->GetAccessibleByID(aID);
81
uint32_t index = 0;
82
while (!acc) {
83
auto child =
84
static_cast<DocAccessibleWrap*>(aDoc->GetChildDocumentAt(index++));
85
if (!child) {
86
break;
87
}
88
acc = FindAccessibleById(child, aID);
89
}
90
91
return acc;
92
}