Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/accessible/generic/BaseAccessibles.cpp
Line
Count
Source (jump to first uncovered line)
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
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 "BaseAccessibles.h"
7
8
#include "Accessible-inl.h"
9
#include "HyperTextAccessibleWrap.h"
10
#include "nsAccessibilityService.h"
11
#include "nsAccUtils.h"
12
#include "nsCoreUtils.h"
13
#include "Role.h"
14
#include "States.h"
15
#include "nsIURI.h"
16
17
using namespace mozilla::a11y;
18
19
////////////////////////////////////////////////////////////////////////////////
20
// LeafAccessible
21
////////////////////////////////////////////////////////////////////////////////
22
23
LeafAccessible::
24
  LeafAccessible(nsIContent* aContent, DocAccessible* aDoc) :
25
  AccessibleWrap(aContent, aDoc)
26
0
{
27
0
  mStateFlags |= eNoKidsFromDOM;
28
0
}
29
30
////////////////////////////////////////////////////////////////////////////////
31
// LeafAccessible: Accessible public
32
33
Accessible*
34
LeafAccessible::ChildAtPoint(int32_t aX, int32_t aY,
35
                             EWhichChildAtPoint aWhichChild)
36
0
{
37
0
  // Don't walk into leaf accessibles.
38
0
  return this;
39
0
}
40
41
bool
42
LeafAccessible::InsertChildAt(uint32_t aIndex, Accessible* aChild)
43
0
{
44
0
  MOZ_ASSERT_UNREACHABLE("InsertChildAt called on leaf accessible!");
45
0
  return false;
46
0
}
47
48
bool
49
LeafAccessible::RemoveChild(Accessible* aChild)
50
0
{
51
0
  MOZ_ASSERT_UNREACHABLE("RemoveChild called on leaf accessible!");
52
0
  return false;
53
0
}
54
55
bool
56
LeafAccessible::IsAcceptableChild(nsIContent* aEl) const
57
0
{
58
0
  // No children for leaf accessible.
59
0
  return false;
60
0
}
61
62
63
////////////////////////////////////////////////////////////////////////////////
64
// LinkableAccessible
65
////////////////////////////////////////////////////////////////////////////////
66
67
////////////////////////////////////////////////////////////////////////////////
68
// LinkableAccessible. nsIAccessible
69
70
void
71
LinkableAccessible::TakeFocus() const
72
0
{
73
0
  if (const Accessible* actionAcc = ActionWalk()) {
74
0
    actionAcc->TakeFocus();
75
0
  } else {
76
0
    AccessibleWrap::TakeFocus();
77
0
  }
78
0
}
79
80
uint64_t
81
LinkableAccessible::NativeLinkState() const
82
0
{
83
0
  bool isLink;
84
0
  const Accessible* actionAcc = ActionWalk(&isLink);
85
0
  if (isLink) {
86
0
    return states::LINKED | (actionAcc->LinkState() & states::TRAVERSED);
87
0
  }
88
0
89
0
  return 0;
90
0
}
91
92
void
93
LinkableAccessible::Value(nsString& aValue) const
94
0
{
95
0
  aValue.Truncate();
96
0
97
0
  Accessible::Value(aValue);
98
0
  if (!aValue.IsEmpty()) {
99
0
    return;
100
0
  }
101
0
102
0
  bool isLink;
103
0
  const Accessible* actionAcc = ActionWalk(&isLink);
104
0
  if (isLink) {
105
0
    actionAcc->Value(aValue);
106
0
  }
107
0
}
108
109
uint8_t
110
LinkableAccessible::ActionCount() const
111
0
{
112
0
  bool isLink, isOnclick, isLabelWithControl;
113
0
  ActionWalk(&isLink, &isOnclick, &isLabelWithControl);
114
0
  return (isLink || isOnclick || isLabelWithControl) ? 1 : 0;
115
0
}
116
117
const Accessible*
118
LinkableAccessible::ActionWalk(bool* aIsLink, bool* aIsOnclick,
119
                               bool* aIsLabelWithControl) const
120
0
{
121
0
  if (aIsOnclick) {
122
0
    *aIsOnclick = false;
123
0
  }
124
0
  if (aIsLink) {
125
0
    *aIsLink = false;
126
0
  }
127
0
  if (aIsLabelWithControl) {
128
0
    *aIsLabelWithControl = false;
129
0
  }
130
0
131
0
  if (nsCoreUtils::HasClickListener(mContent)) {
132
0
    if (aIsOnclick) {
133
0
      *aIsOnclick = true;
134
0
    }
135
0
    return nullptr;
136
0
  }
137
0
138
0
  // XXX: The logic looks broken since the click listener may be registered
139
0
  // on non accessible node in parent chain but this node is skipped when tree
140
0
  // is traversed.
141
0
  const Accessible* walkUpAcc = this;
142
0
  while ((walkUpAcc = walkUpAcc->Parent()) && !walkUpAcc->IsDoc()) {
143
0
    if (walkUpAcc->LinkState() & states::LINKED) {
144
0
      if (aIsLink) {
145
0
        *aIsLink = true;
146
0
      }
147
0
      return walkUpAcc;
148
0
    }
149
0
150
0
    if (nsCoreUtils::HasClickListener(walkUpAcc->GetContent())) {
151
0
      if (aIsOnclick) {
152
0
        *aIsOnclick = true;
153
0
      }
154
0
      return walkUpAcc;
155
0
    }
156
0
157
0
    if (nsCoreUtils::IsLabelWithControl(walkUpAcc->GetContent())) {
158
0
      if (aIsLabelWithControl) {
159
0
        *aIsLabelWithControl = true;
160
0
      }
161
0
      return walkUpAcc;
162
0
    }
163
0
  }
164
0
  return nullptr;
165
0
}
166
167
void
168
LinkableAccessible::ActionNameAt(uint8_t aIndex, nsAString& aName)
169
0
{
170
0
  aName.Truncate();
171
0
172
0
  // Action 0 (default action): Jump to link
173
0
  if (aIndex == eAction_Jump) {
174
0
    bool isOnclick, isLink, isLabelWithControl;
175
0
    ActionWalk(&isLink, &isOnclick, &isLabelWithControl);
176
0
    if (isLink) {
177
0
      aName.AssignLiteral("jump");
178
0
    } else if (isOnclick || isLabelWithControl) {
179
0
      aName.AssignLiteral("click");
180
0
    }
181
0
  }
182
0
}
183
184
bool
185
LinkableAccessible::DoAction(uint8_t aIndex) const
186
0
{
187
0
  if (aIndex != eAction_Jump) {
188
0
    return false;
189
0
  }
190
0
191
0
  if (const Accessible* actionAcc = ActionWalk()) {
192
0
    return actionAcc->DoAction(aIndex);
193
0
  }
194
0
195
0
  return AccessibleWrap::DoAction(aIndex);
196
0
}
197
198
KeyBinding
199
LinkableAccessible::AccessKey() const
200
0
{
201
0
  if (const Accessible* actionAcc =
202
0
    const_cast<LinkableAccessible*>(this)->ActionWalk()) {
203
0
    return actionAcc->AccessKey();
204
0
  }
205
0
206
0
  return Accessible::AccessKey();
207
0
}
208
209
////////////////////////////////////////////////////////////////////////////////
210
// LinkableAccessible: HyperLinkAccessible
211
212
already_AddRefed<nsIURI>
213
LinkableAccessible::AnchorURIAt(uint32_t aAnchorIndex) const
214
0
{
215
0
  bool isLink;
216
0
  const Accessible* actionAcc = ActionWalk(&isLink);
217
0
  if (isLink) {
218
0
    NS_ASSERTION(actionAcc->IsLink(), "HyperLink isn't implemented.");
219
0
220
0
    if (actionAcc->IsLink()) {
221
0
      return actionAcc->AnchorURIAt(aAnchorIndex);
222
0
    }
223
0
  }
224
0
225
0
  return nullptr;
226
0
}
227
228
229
////////////////////////////////////////////////////////////////////////////////
230
// DummyAccessible
231
////////////////////////////////////////////////////////////////////////////////
232
233
uint64_t
234
DummyAccessible::NativeState() const
235
0
{
236
0
  return 0;
237
0
}
238
uint64_t
239
DummyAccessible::NativeInteractiveState() const
240
0
{
241
0
  return 0;
242
0
}
243
244
uint64_t
245
DummyAccessible::NativeLinkState() const
246
0
{
247
0
  return 0;
248
0
}
249
250
bool
251
DummyAccessible::NativelyUnavailable() const
252
0
{
253
0
  return false;
254
0
}
255
256
void
257
DummyAccessible::ApplyARIAState(uint64_t* aState) const
258
0
{
259
0
}