1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* 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/. */
#ifndef mozilla_a11y_DocAccessibleChild_h
#define mozilla_a11y_DocAccessibleChild_h
#include "mozilla/a11y/COMPtrTypes.h"
#include "mozilla/a11y/DocAccessibleChildBase.h"
#include "mozilla/dom/BrowserBridgeChild.h"
#include "mozilla/dom/BrowserChild.h"
#include "mozilla/mscom/Ptr.h"
namespace mozilla {
namespace a11y {
/*
* These objects handle content side communication for an accessible document,
* and their lifetime is the same as the document they represent.
*/
class DocAccessibleChild : public DocAccessibleChildBase {
public:
DocAccessibleChild(DocAccessible* aDoc, IProtocol* aManager);
~DocAccessibleChild();
virtual void Shutdown() override;
virtual ipc::IPCResult RecvParentCOMProxy(
const IDispatchHolder& aParentCOMProxy) override;
virtual ipc::IPCResult RecvEmulatedWindow(
const WindowsHandle& aEmulatedWindowHandle,
const IDispatchHolder& aEmulatedWindowCOMProxy) override;
virtual ipc::IPCResult RecvTopLevelDocCOMProxy(
const IAccessibleHolder& aCOMProxy) override;
virtual ipc::IPCResult RecvRestoreFocus() override;
HWND GetNativeWindowHandle() const;
IDispatch* GetEmulatedWindowIAccessible() const {
return mEmulatedWindowProxy.get();
}
IDispatch* GetParentIAccessible() const { return mParentProxy.get(); }
IAccessible* GetTopLevelDocIAccessible() const {
return mTopLevelDocProxy.get();
}
bool SendEvent(const uint64_t& aID, const uint32_t& type);
bool SendHideEvent(const uint64_t& aRootID, const bool& aFromUser);
bool SendStateChangeEvent(const uint64_t& aID, const uint64_t& aState,
const bool& aEnabled);
bool SendCaretMoveEvent(const uint64_t& aID, const int32_t& aOffset,
const bool& aIsSelectionCollapsed,
const bool& aIsAtEndOfLine,
const int32_t& aGranularity);
bool SendCaretMoveEvent(const uint64_t& aID,
const LayoutDeviceIntRect& aCaretRect,
const int32_t& aOffset,
const bool& aIsSelectionCollapsed,
const bool& aIsAtEndOfLine,
const int32_t& aGranularity);
bool SendFocusEvent(const uint64_t& aID);
bool SendFocusEvent(const uint64_t& aID,
const LayoutDeviceIntRect& aCaretRect);
bool SendTextChangeEvent(const uint64_t& aID, const nsString& aStr,
const int32_t& aStart, const uint32_t& aLen,
const bool& aIsInsert, const bool& aFromUser,
const bool aDoSync = false);
bool SendSelectionEvent(const uint64_t& aID, const uint64_t& aWidgetID,
const uint32_t& aType);
bool SendRoleChangedEvent(const a11y::role& aRole,
uint8_t aRoleMapEntryIndex);
bool SendScrollingEvent(const uint64_t& aID, const uint64_t& aType,
const uint32_t& aScrollX, const uint32_t& aScrollY,
const uint32_t& aMaxScrollX,
const uint32_t& aMaxScrollY);
bool ConstructChildDocInParentProcess(DocAccessibleChild* aNewChildDoc,
uint64_t aUniqueID, uint32_t aMsaaID);
bool SendBindChildDoc(DocAccessibleChild* aChildDoc,
const uint64_t& aNewParentID);
/**
* Set the embedder accessible on a BrowserBridgeChild to an accessible in
* this document.
* Sending this will be deferred if this DocAccessibleChild hasn't been
* constructed in the parent process yet.
*/
void SetEmbedderOnBridge(dom::BrowserBridgeChild* aBridge, uint64_t aID);
protected:
virtual void MaybeSendShowEvent(ShowEventData& aData,
bool aFromUser) override;
private:
void RemoveDeferredConstructor();
LayoutDeviceIntRect GetCaretRectFor(const uint64_t& aID);
/**
* DocAccessibleChild should not fire events until it has asynchronously
* received the COM proxy for its parent. OTOH, content a11y may still be
* attempting to fire events during this window of time. If this object does
* not yet have its parent proxy, instead of immediately sending the events to
* our parent, we enqueue them to mDeferredEvents. As soon as
* RecvParentCOMProxy is called, we play back mDeferredEvents.
*/
struct DeferredEvent {
void Dispatch() { Dispatch(mTarget); }
virtual ~DeferredEvent() {}
protected:
explicit DeferredEvent(DocAccessibleChild* aTarget) : mTarget(aTarget) {}
virtual void Dispatch(DocAccessibleChild* aIPCDoc) = 0;
private:
DocAccessibleChild* mTarget;
};
void PushDeferredEvent(UniquePtr<DeferredEvent> aEvent);
struct SerializedShow final : public DeferredEvent {
SerializedShow(DocAccessibleChild* aTarget, ShowEventData& aEventData,
bool aFromUser)
: DeferredEvent(aTarget),
mEventData(aEventData.ID(), aEventData.Idx(),
nsTArray<AccessibleData>(), aEventData.EventSuppressed()),
mFromUser(aFromUser) {
// Since IPDL doesn't generate a move constructor for ShowEventData,
// we move NewTree manually (ugh). We still construct with an empty
// NewTree above so that the compiler catches any changes made to the
// ShowEventData structure in IPDL.
mEventData.NewTree() = std::move(aEventData.NewTree());
}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendShowEvent(mEventData, mFromUser);
}
ShowEventData mEventData;
bool mFromUser;
};
struct SerializedHide final : public DeferredEvent {
SerializedHide(DocAccessibleChild* aTarget, uint64_t aRootID,
bool aFromUser)
: DeferredEvent(aTarget), mRootID(aRootID), mFromUser(aFromUser) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendHideEvent(mRootID, mFromUser);
}
uint64_t mRootID;
bool mFromUser;
};
struct SerializedStateChange final : public DeferredEvent {
SerializedStateChange(DocAccessibleChild* aTarget, uint64_t aID,
uint64_t aState, bool aEnabled)
: DeferredEvent(aTarget),
mID(aID),
mState(aState),
mEnabled(aEnabled) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendStateChangeEvent(mID, mState, mEnabled);
}
uint64_t mID;
uint64_t mState;
bool mEnabled;
};
struct SerializedCaretMove final : public DeferredEvent {
SerializedCaretMove(DocAccessibleChild* aTarget, uint64_t aID,
const LayoutDeviceIntRect& aCaretRect, int32_t aOffset,
bool aIsSelectionCollapsed, bool aIsAtEndOfLine,
int32_t aGranularity)
: DeferredEvent(aTarget),
mID(aID),
mCaretRect(aCaretRect),
mOffset(aOffset),
mIsSelectionCollapsed(aIsSelectionCollapsed),
mIsAtEndOfLine(aIsAtEndOfLine),
mGranularity(aGranularity) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendCaretMoveEvent(mID, mCaretRect, mOffset,
mIsSelectionCollapsed,
mIsAtEndOfLine, mGranularity);
}
uint64_t mID;
LayoutDeviceIntRect mCaretRect;
int32_t mOffset;
bool mIsSelectionCollapsed;
bool mIsAtEndOfLine;
int32_t mGranularity;
};
struct SerializedFocus final : public DeferredEvent {
SerializedFocus(DocAccessibleChild* aTarget, uint64_t aID,
const LayoutDeviceIntRect& aCaretRect)
: DeferredEvent(aTarget), mID(aID), mCaretRect(aCaretRect) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendFocusEvent(mID, mCaretRect);
}
uint64_t mID;
LayoutDeviceIntRect mCaretRect;
};
struct SerializedTextChange final : public DeferredEvent {
SerializedTextChange(DocAccessibleChild* aTarget, uint64_t aID,
const nsString& aStr, int32_t aStart, uint32_t aLen,
bool aIsInsert, bool aFromUser)
: DeferredEvent(aTarget),
mID(aID),
mStr(aStr),
mStart(aStart),
mLen(aLen),
mIsInsert(aIsInsert),
mFromUser(aFromUser) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendTextChangeEvent(mID, mStr, mStart, mLen, mIsInsert,
mFromUser, false);
}
uint64_t mID;
nsString mStr;
int32_t mStart;
uint32_t mLen;
bool mIsInsert;
bool mFromUser;
};
struct SerializedSelection final : public DeferredEvent {
SerializedSelection(DocAccessibleChild* aTarget, uint64_t aID,
uint64_t aWidgetID, uint32_t aType)
: DeferredEvent(aTarget),
mID(aID),
mWidgetID(aWidgetID),
mType(aType) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendSelectionEvent(mID, mWidgetID, mType);
}
uint64_t mID;
uint64_t mWidgetID;
uint32_t mType;
};
struct SerializedRoleChanged final : public DeferredEvent {
explicit SerializedRoleChanged(DocAccessibleChild* aTarget,
a11y::role aRole, uint8_t aRoleMapEntryIndex)
: DeferredEvent(aTarget),
mRole(aRole),
mRoleMapEntryIndex(aRoleMapEntryIndex) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendRoleChangedEvent(mRole, mRoleMapEntryIndex);
}
a11y::role mRole;
uint8_t mRoleMapEntryIndex;
};
struct SerializedScrolling final : public DeferredEvent {
explicit SerializedScrolling(DocAccessibleChild* aTarget, uint64_t aID,
uint64_t aType, uint32_t aScrollX,
uint32_t aScrollY, uint32_t aMaxScrollX,
uint32_t aMaxScrollY)
: DeferredEvent(aTarget),
mID(aID),
mType(aType),
mScrollX(aScrollX),
mScrollY(aScrollY),
mMaxScrollX(aMaxScrollX),
mMaxScrollY(aMaxScrollY) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendScrollingEvent(mID, mType, mScrollX, mScrollY,
mMaxScrollX, mMaxScrollY);
}
uint64_t mID;
uint64_t mType;
uint32_t mScrollX;
uint32_t mScrollY;
uint32_t mMaxScrollX;
uint32_t mMaxScrollY;
};
struct SerializedEvent final : public DeferredEvent {
SerializedEvent(DocAccessibleChild* aTarget, uint64_t aID, uint32_t aType)
: DeferredEvent(aTarget), mID(aID), mType(aType) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override {
Unused << aIPCDoc->SendEvent(mID, mType);
}
uint64_t mID;
uint32_t mType;
};
struct SerializedChildDocConstructor final : public DeferredEvent {
SerializedChildDocConstructor(DocAccessibleChild* aIPCDoc,
DocAccessibleChild* aParentIPCDoc,
uint64_t aUniqueID,
dom::BrowsingContext* aBrowsingContext,
uint32_t aMsaaID)
: DeferredEvent(aParentIPCDoc),
mIPCDoc(aIPCDoc),
mUniqueID(aUniqueID),
mBrowsingContext(aBrowsingContext),
mMsaaID(aMsaaID) {}
void Dispatch(DocAccessibleChild* aParentIPCDoc) override {
auto browserChild =
static_cast<dom::BrowserChild*>(aParentIPCDoc->Manager());
MOZ_ASSERT(browserChild);
Unused << browserChild->SendPDocAccessibleConstructor(
mIPCDoc, aParentIPCDoc, mUniqueID, mBrowsingContext, mMsaaID,
IAccessibleHolder());
mIPCDoc->SetConstructedInParentProcess();
}
DocAccessibleChild* mIPCDoc;
uint64_t mUniqueID;
// By the time we replay this, the document and its BrowsingContext might
// be dead, so we use MaybeDiscardedBrowsingContext here. Ideally, we just
// wouldn't replay this, but this is tricky because IPDL should manage the
// lifetime of DocAccessibleChild, which means we must send the constructor.
dom::MaybeDiscardedBrowsingContext mBrowsingContext;
uint32_t mMsaaID;
};
friend struct SerializedChildDocConstructor;
struct SerializedBindChildDoc final : public DeferredEvent {
SerializedBindChildDoc(DocAccessibleChild* aParentDoc,
DocAccessibleChild* aChildDoc, uint64_t aNewParentID)
: DeferredEvent(aParentDoc),
mChildDoc(aChildDoc),
mNewParentID(aNewParentID) {}
void Dispatch(DocAccessibleChild* aParentIPCDoc) override {
Unused << aParentIPCDoc->SendBindChildDoc(mChildDoc, mNewParentID);
}
DocAccessibleChild* mChildDoc;
uint64_t mNewParentID;
};
struct SerializedShutdown final : public DeferredEvent {
explicit SerializedShutdown(DocAccessibleChild* aTarget)
: DeferredEvent(aTarget) {}
void Dispatch(DocAccessibleChild* aIPCDoc) override { aIPCDoc->Shutdown(); }
};
struct SerializedSetEmbedder final : public DeferredEvent {
SerializedSetEmbedder(dom::BrowserBridgeChild* aBridge,
DocAccessibleChild* aDoc, uint64_t aID)
: DeferredEvent(aDoc), mBridge(aBridge), mID(aID) {}
void Dispatch(DocAccessibleChild* aDoc) override {
mBridge->SetEmbedderAccessible(aDoc, mID);
}
RefPtr<dom::BrowserBridgeChild> mBridge;
uint64_t mID;
};
mscom::ProxyUniquePtr<IDispatch> mParentProxy;
mscom::ProxyUniquePtr<IDispatch> mEmulatedWindowProxy;
mscom::ProxyUniquePtr<IAccessible> mTopLevelDocProxy;
nsTArray<UniquePtr<DeferredEvent>> mDeferredEvents;
HWND mEmulatedWindowHandle;
};
} // namespace a11y
} // namespace mozilla
#endif // mozilla_a11y_DocAccessibleChild_h
|