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 || !aFromUser) {
123
return;
124
}
125
126
RefPtr<SessionAccessibility> sessionAcc =
127
SessionAccessibility::GetInstanceFor(aTarget);
128
129
if (!sessionAcc) {
130
return;
131
}
132
133
if (aReason == nsIAccessiblePivot::REASON_POINT) {
134
sessionAcc->SendHoverEnterEvent(WrapperFor(aNewPosition));
135
} else {
136
RefPtr<AccessibleWrap> wrapperForNewPosition = WrapperFor(aNewPosition);
137
sessionAcc->SendAccessibilityFocusedEvent(wrapperForNewPosition);
138
}
139
140
if (aBoundaryType != nsIAccessiblePivot::NO_BOUNDARY) {
141
sessionAcc->SendTextTraversedEvent(WrapperFor(aNewPosition),
142
aNewStartOffset, aNewEndOffset);
143
}
144
}
145
146
void a11y::ProxyScrollingEvent(ProxyAccessible* aTarget, uint32_t aEventType,
147
uint32_t aScrollX, uint32_t aScrollY,
148
uint32_t aMaxScrollX, uint32_t aMaxScrollY) {
149
if (aEventType == nsIAccessibleEvent::EVENT_SCROLLING) {
150
SessionAccessibility* sessionAcc =
151
SessionAccessibility::GetInstanceFor(aTarget);
152
153
if (sessionAcc) {
154
sessionAcc->SendScrollingEvent(WrapperFor(aTarget), aScrollX, aScrollY,
155
aMaxScrollX, aMaxScrollY);
156
}
157
}
158
}
159
160
void a11y::ProxyAnnouncementEvent(ProxyAccessible* aTarget,
161
const nsString& aAnnouncement,
162
uint16_t aPriority) {
163
SessionAccessibility* sessionAcc =
164
SessionAccessibility::GetInstanceFor(aTarget);
165
166
if (sessionAcc) {
167
sessionAcc->SendAnnouncementEvent(WrapperFor(aTarget), aAnnouncement,
168
aPriority);
169
}
170
}
171
172
void a11y::ProxyBatch(ProxyAccessible* aDocument, const uint64_t aBatchType,
173
const nsTArray<ProxyAccessible*>& aAccessibles,
174
const nsTArray<BatchData>& aData) {
175
SessionAccessibility* sessionAcc =
176
SessionAccessibility::GetInstanceFor(aDocument);
177
if (!sessionAcc) {
178
return;
179
}
180
181
nsTArray<AccessibleWrap*> accWraps(aAccessibles.Length());
182
for (size_t i = 0; i < aAccessibles.Length(); i++) {
183
accWraps.AppendElement(WrapperFor(aAccessibles.ElementAt(i)));
184
}
185
186
switch (aBatchType) {
187
case DocAccessibleWrap::eBatch_Viewport:
188
sessionAcc->ReplaceViewportCache(accWraps, aData);
189
break;
190
case DocAccessibleWrap::eBatch_FocusPath:
191
sessionAcc->ReplaceFocusPathCache(accWraps, aData);
192
break;
193
case DocAccessibleWrap::eBatch_BoundsUpdate:
194
sessionAcc->UpdateCachedBounds(accWraps, aData);
195
break;
196
default:
197
MOZ_ASSERT_UNREACHABLE("Unknown batch type.");
198
break;
199
}
200
}