Source code

Revision control

Other Tools

1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* vim: set ts=2 et sw=2 tw=80: */
3
/* This Source Code Form is subject to the terms of the Mozilla Public
4
* License, v. 2.0. If a copy of the MPL was not distributed with this
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7
#include "Platform.h"
8
#include "ProxyAccessibleWrap.h"
9
#include "DocAccessibleWrap.h"
10
#include "SessionAccessibility.h"
11
#include "mozilla/a11y/ProxyAccessible.h"
12
#include "nsIAccessibleEvent.h"
13
#include "nsIAccessiblePivot.h"
14
15
using namespace mozilla;
16
using namespace mozilla::a11y;
17
18
void a11y::PlatformInit() {}
19
20
void a11y::PlatformShutdown() {}
21
22
void a11y::ProxyCreated(ProxyAccessible* aProxy, uint32_t aInterfaces) {
23
AccessibleWrap* wrapper = nullptr;
24
if (aProxy->IsDoc()) {
25
wrapper = new DocProxyAccessibleWrap(aProxy->AsDoc());
26
} else {
27
wrapper = new ProxyAccessibleWrap(aProxy);
28
}
29
30
wrapper->AddRef();
31
aProxy->SetWrapper(reinterpret_cast<uintptr_t>(wrapper));
32
}
33
34
void a11y::ProxyDestroyed(ProxyAccessible* aProxy) {
35
AccessibleWrap* wrapper =
36
reinterpret_cast<AccessibleWrap*>(aProxy->GetWrapper());
37
38
// If aProxy is a document that was created, but
39
// RecvPDocAccessibleConstructor failed then aProxy->GetWrapper() will be
40
// null.
41
if (!wrapper) {
42
return;
43
}
44
45
wrapper->Shutdown();
46
aProxy->SetWrapper(0);
47
wrapper->Release();
48
}
49
50
void a11y::ProxyEvent(ProxyAccessible* aTarget, uint32_t aEventType) {
51
SessionAccessibility* sessionAcc =
52
SessionAccessibility::GetInstanceFor(aTarget);
53
if (!sessionAcc) {
54
return;
55
}
56
57
switch (aEventType) {
58
case nsIAccessibleEvent::EVENT_FOCUS:
59
sessionAcc->SendFocusEvent(WrapperFor(aTarget));
60
break;
61
}
62
}
63
64
void a11y::ProxyStateChangeEvent(ProxyAccessible* aTarget, uint64_t aState,
65
bool aEnabled) {
66
SessionAccessibility* sessionAcc =
67
SessionAccessibility::GetInstanceFor(aTarget);
68
69
if (!sessionAcc) {
70
return;
71
}
72
73
if (aState & states::CHECKED) {
74
sessionAcc->SendClickedEvent(WrapperFor(aTarget), aEnabled);
75
}
76
77
if (aState & states::SELECTED) {
78
sessionAcc->SendSelectedEvent(WrapperFor(aTarget), aEnabled);
79
}
80
81
if (aState & states::BUSY) {
82
sessionAcc->SendWindowStateChangedEvent(WrapperFor(aTarget));
83
}
84
}
85
86
void a11y::ProxyCaretMoveEvent(ProxyAccessible* aTarget, int32_t aOffset) {
87
SessionAccessibility* sessionAcc =
88
SessionAccessibility::GetInstanceFor(aTarget);
89
90
if (sessionAcc) {
91
sessionAcc->SendTextSelectionChangedEvent(WrapperFor(aTarget), aOffset);
92
}
93
}
94
95
void a11y::ProxyTextChangeEvent(ProxyAccessible* aTarget, const nsString& aStr,
96
int32_t aStart, uint32_t aLen, bool aIsInsert,
97
bool aFromUser) {
98
SessionAccessibility* sessionAcc =
99
SessionAccessibility::GetInstanceFor(aTarget);
100
101
if (sessionAcc) {
102
sessionAcc->SendTextChangedEvent(WrapperFor(aTarget), aStr, aStart, aLen,
103
aIsInsert, aFromUser);
104
}
105
}
106
107
void a11y::ProxyShowHideEvent(ProxyAccessible* aTarget,
108
ProxyAccessible* aParent, bool aInsert,
109
bool aFromUser) {
110
// We rely on the window content changed events to be dispatched
111
// after the viewport cache is refreshed.
112
}
113
114
void a11y::ProxySelectionEvent(ProxyAccessible*, ProxyAccessible*, uint32_t) {}
115
116
void a11y::ProxyVirtualCursorChangeEvent(
117
ProxyAccessible* aTarget, ProxyAccessible* aOldPosition,
118
int32_t aOldStartOffset, int32_t aOldEndOffset,
119
ProxyAccessible* aNewPosition, int32_t aNewStartOffset,
120
int32_t aNewEndOffset, int16_t aReason, int16_t aBoundaryType,
121
bool aFromUser) {
122
if (!aNewPosition) {
123
return;
124
}
125
126
RefPtr<SessionAccessibility> sessionAcc =
127
SessionAccessibility::GetInstanceFor(aTarget);
128
129
if (!sessionAcc) {
130
return;
131
}
132
133
if (aOldPosition != aNewPosition) {
134
if (aReason == nsIAccessiblePivot::REASON_POINT) {
135
sessionAcc->SendHoverEnterEvent(WrapperFor(aNewPosition));
136
} else {
137
RefPtr<AccessibleWrap> wrapperForNewPosition = WrapperFor(aNewPosition);
138
sessionAcc->SendAccessibilityFocusedEvent(wrapperForNewPosition);
139
}
140
}
141
142
if (aBoundaryType != nsIAccessiblePivot::NO_BOUNDARY) {
143
sessionAcc->SendTextTraversedEvent(WrapperFor(aNewPosition),
144
aNewStartOffset, aNewEndOffset);
145
}
146
}
147
148
void a11y::ProxyScrollingEvent(ProxyAccessible* aTarget, uint32_t aEventType,
149
uint32_t aScrollX, uint32_t aScrollY,
150
uint32_t aMaxScrollX, uint32_t aMaxScrollY) {
151
if (aEventType == nsIAccessibleEvent::EVENT_SCROLLING) {
152
SessionAccessibility* sessionAcc =
153
SessionAccessibility::GetInstanceFor(aTarget);
154
155
if (sessionAcc) {
156
sessionAcc->SendScrollingEvent(WrapperFor(aTarget), aScrollX, aScrollY,
157
aMaxScrollX, aMaxScrollY);
158
}
159
}
160
}
161
162
void a11y::ProxyAnnouncementEvent(ProxyAccessible* aTarget,
163
const nsString& aAnnouncement,
164
uint16_t aPriority) {
165
SessionAccessibility* sessionAcc =
166
SessionAccessibility::GetInstanceFor(aTarget);
167
168
if (sessionAcc) {
169
sessionAcc->SendAnnouncementEvent(WrapperFor(aTarget), aAnnouncement,
170
aPriority);
171
}
172
}
173
174
void a11y::ProxyBatch(ProxyAccessible* aDocument, const uint64_t aBatchType,
175
const nsTArray<ProxyAccessible*>& aAccessibles,
176
const nsTArray<BatchData>& aData) {
177
SessionAccessibility* sessionAcc =
178
SessionAccessibility::GetInstanceFor(aDocument);
179
if (!sessionAcc) {
180
return;
181
}
182
183
nsTArray<AccessibleWrap*> accWraps(aAccessibles.Length());
184
for (size_t i = 0; i < aAccessibles.Length(); i++) {
185
accWraps.AppendElement(WrapperFor(aAccessibles.ElementAt(i)));
186
}
187
188
switch (aBatchType) {
189
case DocAccessibleWrap::eBatch_Viewport:
190
sessionAcc->ReplaceViewportCache(accWraps, aData);
191
break;
192
case DocAccessibleWrap::eBatch_FocusPath:
193
sessionAcc->ReplaceFocusPathCache(accWraps, aData);
194
break;
195
case DocAccessibleWrap::eBatch_BoundsUpdate:
196
sessionAcc->UpdateCachedBounds(accWraps, aData);
197
break;
198
default:
199
MOZ_ASSERT_UNREACHABLE("Unknown batch type.");
200
break;
201
}
202
}