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
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
|
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/browser_accessibility.h"
#include "base/logging.h"
#include "chrome/browser/browser_accessibility_manager.h"
using webkit_glue::WebAccessibility;
HRESULT BrowserAccessibility::Initialize(int iaccessible_id, int routing_id,
int process_id, HWND parent_hwnd) {
// Check input parameters. Root id is 1000, to avoid conflicts with the ids
// used by MSAA.
if (!parent_hwnd || iaccessible_id < 1000)
return E_INVALIDARG;
iaccessible_id_ = iaccessible_id;
routing_id_ = routing_id;
process_id_ = process_id;
parent_hwnd_ = parent_hwnd;
// Mark instance as active.
instance_active_ = true;
return S_OK;
}
HRESULT BrowserAccessibility::accDoDefaultAction(VARIANT var_id) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
// TODO(klink): Once we have MSAA events, change these fails to having
// BrowserAccessibilityManager firing the right event.
return E_FAIL;
}
if (var_id.vt != VT_I4)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_DODEFAULTACTION,
var_id, NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code)
return S_FALSE;
return S_OK;
}
STDMETHODIMP BrowserAccessibility::accHitTest(LONG x_left, LONG y_top,
VARIANT* child) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (!child)
return E_INVALIDARG;
if (!parent_hwnd_) {
// Parent HWND needed for coordinate conversion.
return E_FAIL;
}
// Convert coordinates to test from screen into client window coordinates, to
// maintain sandbox functionality on renderer side.
POINT p = {x_left, y_top};
::ScreenToClient(parent_hwnd_, &p);
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_HITTEST,
EmptyVariant(), p.x, p.y)) {
return E_FAIL;
}
if (!response().return_code) {
// The point is outside of the object's boundaries.
child->vt = VT_EMPTY;
return S_FALSE;
}
if (response().output_long1 == -1) {
if (CreateInstance(IID_IAccessible, response().object_id,
reinterpret_cast<void**>(&child->pdispVal)) == S_OK) {
child->vt = VT_DISPATCH;
// Increment the reference count for the retrieved interface.
child->pdispVal->AddRef();
} else {
return E_NOINTERFACE;
}
} else {
child->vt = VT_I4;
child->lVal = response().output_long1;
}
return S_OK;
}
STDMETHODIMP BrowserAccessibility::accLocation(LONG* x_left, LONG* y_top,
LONG* width, LONG* height,
VARIANT var_id) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !x_left || !y_top || !width || !height ||
!parent_hwnd_) {
return E_INVALIDARG;
}
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_LOCATION, var_id,
NULL, NULL)) {
return E_FAIL;
}
POINT top_left = {0, 0};
// Find the top left corner of the containing window in screen coords, and
// adjust the output position by this amount.
::ClientToScreen(parent_hwnd_, &top_left);
*x_left = response().output_long1 + top_left.x;
*y_top = response().output_long2 + top_left.y;
*width = response().output_long3;
*height = response().output_long4;
return S_OK;
}
STDMETHODIMP BrowserAccessibility::accNavigate(LONG nav_dir, VARIANT start,
VARIANT* end) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (start.vt != VT_I4 || !end)
return E_INVALIDARG;
if ((nav_dir == NAVDIR_LASTCHILD || nav_dir == NAVDIR_FIRSTCHILD) &&
start.lVal != CHILDID_SELF) {
// MSAA states that navigating to first/last child can only be from self.
return E_INVALIDARG;
}
if (nav_dir == NAVDIR_DOWN || nav_dir == NAVDIR_UP ||
nav_dir == NAVDIR_LEFT || nav_dir == NAVDIR_RIGHT) {
// Directions not implemented, matching Mozilla and IE.
return E_INVALIDARG;
}
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_NAVIGATE, start,
nav_dir, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// No screen element was found in the specified direction.
end->vt = VT_EMPTY;
return S_FALSE;
}
if (response().output_long1 == -1) {
if (CreateInstance(IID_IAccessible, response().object_id,
reinterpret_cast<void**>(&end->pdispVal)) == S_OK) {
end->vt = VT_DISPATCH;
// Increment the reference count for the retrieved interface.
end->pdispVal->AddRef();
} else {
return E_NOINTERFACE;
}
} else {
end->vt = VT_I4;
end->lVal = response().output_long1;
}
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accChild(VARIANT var_child,
IDispatch** disp_child) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_child.vt != VT_I4 || !disp_child)
return E_INVALIDARG;
// If var_child is the parent, remain with the same IDispatch.
if (var_child.lVal == CHILDID_SELF && iaccessible_id_ != 1000)
return S_OK;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_GETCHILD, var_child,
NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// When at a leaf, children are handled by the parent object.
*disp_child = NULL;
return S_FALSE;
}
// Retrieve the IUnknown interface for the parent view, and assign the
// IDispatch returned.
if (CreateInstance(IID_IAccessible, response().object_id,
reinterpret_cast<void**>(disp_child)) == S_OK) {
// Increment the reference count for the retrieved interface.
(*disp_child)->AddRef();
return S_OK;
} else {
return E_NOINTERFACE;
}
}
STDMETHODIMP BrowserAccessibility::get_accChildCount(LONG* child_count) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (!child_count)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_CHILDCOUNT,
EmptyVariant(), NULL, NULL)) {
return E_FAIL;
}
*child_count = response().output_long1;
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accDefaultAction(VARIANT var_id,
BSTR* def_action) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !def_action)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_DEFAULTACTION,
var_id, NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// No string found.
return S_FALSE;
}
*def_action = SysAllocString(response().output_string.c_str());
DCHECK(*def_action);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accDescription(VARIANT var_id,
BSTR* desc) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !desc)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_DESCRIPTION, var_id,
NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// No string found.
return S_FALSE;
}
*desc = SysAllocString(response().output_string.c_str());
DCHECK(*desc);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accFocus(VARIANT* focus_child) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (!focus_child)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_GETFOCUSEDCHILD,
EmptyVariant(), NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// The window that contains this object is not the active window.
focus_child->vt = VT_EMPTY;
return S_FALSE;
}
if (response().output_long1 == -1) {
if (CreateInstance(IID_IAccessible, response().object_id,
reinterpret_cast<void**>(&focus_child->pdispVal)) == S_OK) {
focus_child->vt = VT_DISPATCH;
// Increment the reference count for the retrieved interface.
focus_child->pdispVal->AddRef();
} else {
return E_NOINTERFACE;
}
} else {
focus_child->vt = VT_I4;
focus_child->lVal = response().output_long1;
}
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accHelp(VARIANT var_id, BSTR* help) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !help)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_HELPTEXT, var_id,
NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code || response().output_string.empty()) {
// No string found.
return S_FALSE;
}
*help = SysAllocString(response().output_string.c_str());
DCHECK(*help);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accKeyboardShortcut(VARIANT var_id,
BSTR* acc_key) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !acc_key)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_KEYBOARDSHORTCUT,
var_id, NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// No string found.
return S_FALSE;
}
*acc_key = SysAllocString(response().output_string.c_str());
DCHECK(*acc_key);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accName(VARIANT var_id, BSTR* name) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !name)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_NAME, var_id, NULL,
NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// No string found.
return S_FALSE;
}
*name = SysAllocString(response().output_string.c_str());
DCHECK(*name);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accParent(IDispatch** disp_parent) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (!disp_parent || !parent_hwnd_)
return E_INVALIDARG;
// Root node's parent is the containing HWND's IAccessible.
if (iaccessible_id_ == 1000) {
// For an object that has no parent (e.g. root), point the accessible parent
// to the default implementation.
HRESULT hr =
::CreateStdAccessibleObject(parent_hwnd_, OBJID_WINDOW,
IID_IAccessible,
reinterpret_cast<void**>(disp_parent));
if (!SUCCEEDED(hr)) {
*disp_parent = NULL;
return S_FALSE;
}
return S_OK;
}
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_GETPARENT,
EmptyVariant(), NULL, NULL)) {
return E_FAIL;
}
if (!response().return_code) {
// No parent exists for this object.
return S_FALSE;
}
// Retrieve the IUnknown interface for the parent view, and assign the
// IDispatch returned.
if (CreateInstance(IID_IAccessible, response().object_id,
reinterpret_cast<void**>(disp_parent)) == S_OK) {
// Increment the reference count for the retrieved interface.
(*disp_parent)->AddRef();
return S_OK;
} else {
return E_NOINTERFACE;
}
}
STDMETHODIMP BrowserAccessibility::get_accRole(VARIANT var_id, VARIANT* role) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !role)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_ROLE, var_id, NULL,
NULL)) {
return E_FAIL;
}
role->vt = VT_I4;
role->lVal = MSAARole(response().output_long1);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accState(VARIANT var_id,
VARIANT* state) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !state)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_STATE, var_id, NULL,
NULL)) {
return E_FAIL;
}
state->vt = VT_I4;
state->lVal = MSAAState(response().output_long1);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accValue(VARIANT var_id, BSTR* value) {
if (!instance_active()) {
// Instance no longer active, fail gracefully.
return E_FAIL;
}
if (var_id.vt != VT_I4 || !value)
return E_INVALIDARG;
if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_VALUE, var_id, NULL,
NULL)) {
return E_FAIL;
}
if (!response().return_code || response().output_string.empty()) {
// No string found.
return S_FALSE;
}
*value = SysAllocString(response().output_string.c_str());
DCHECK(*value);
return S_OK;
}
STDMETHODIMP BrowserAccessibility::get_accHelpTopic(BSTR* help_file,
VARIANT var_id,
LONG* topic_id) {
if (help_file)
*help_file = NULL;
if (topic_id)
*topic_id = static_cast<LONG>(-1);
return E_NOTIMPL;
}
STDMETHODIMP BrowserAccessibility::get_accSelection(VARIANT* selected) {
if (selected)
selected->vt = VT_EMPTY;
return E_NOTIMPL;
}
STDMETHODIMP BrowserAccessibility::CreateInstance(REFIID iid,
int iaccessible_id,
void** interface_ptr) {
return BrowserAccessibilityManager::GetInstance()->
CreateAccessibilityInstance(iid, iaccessible_id, routing_id_,
process_id_, parent_hwnd_, interface_ptr);
}
bool BrowserAccessibility::RequestAccessibilityInfo(int iaccessible_func_id,
VARIANT var_id, LONG input1,
LONG input2) {
// Create and populate IPC message structure, for retrieval of accessibility
// information from the renderer.
WebAccessibility::InParams in_params;
in_params.object_id = iaccessible_id_;
in_params.function_id = iaccessible_func_id;
in_params.child_id = var_id.lVal;
in_params.input_long1 = input1;
in_params.input_long2 = input2;
return BrowserAccessibilityManager::GetInstance()->
RequestAccessibilityInfo(&in_params, routing_id_, process_id_);
}
const WebAccessibility::OutParams& BrowserAccessibility::response() {
return BrowserAccessibilityManager::GetInstance()->response();
}
long BrowserAccessibility::MSAARole(long browser_accessibility_role) {
switch (browser_accessibility_role) {
case WebAccessibility::ROLE_APPLICATION:
return ROLE_SYSTEM_APPLICATION;
case WebAccessibility::ROLE_CELL:
return ROLE_SYSTEM_CELL;
case WebAccessibility::ROLE_CHECKBUTTON:
return ROLE_SYSTEM_CHECKBUTTON;
case WebAccessibility::ROLE_COLUMN:
return ROLE_SYSTEM_COLUMN;
case WebAccessibility::ROLE_COLUMNHEADER:
return ROLE_SYSTEM_COLUMNHEADER;
case WebAccessibility::ROLE_DOCUMENT:
return ROLE_SYSTEM_DOCUMENT;
case WebAccessibility::ROLE_GRAPHIC:
return ROLE_SYSTEM_GRAPHIC;
case WebAccessibility::ROLE_GROUPING:
return ROLE_SYSTEM_GROUPING;
case WebAccessibility::ROLE_LINK:
return ROLE_SYSTEM_LINK;
case WebAccessibility::ROLE_LIST:
case WebAccessibility::ROLE_LISTBOX:
return ROLE_SYSTEM_LIST;
case WebAccessibility::ROLE_LISTITEM:
return ROLE_SYSTEM_LISTITEM;
case WebAccessibility::ROLE_MENUBAR:
return ROLE_SYSTEM_MENUBAR;
case WebAccessibility::ROLE_MENUITEM:
return ROLE_SYSTEM_MENUITEM;
case WebAccessibility::ROLE_MENUPOPUP:
return ROLE_SYSTEM_MENUPOPUP;
case WebAccessibility::ROLE_OUTLINE:
return ROLE_SYSTEM_OUTLINE;
case WebAccessibility::ROLE_PAGETABLIST:
return ROLE_SYSTEM_PAGETABLIST;
case WebAccessibility::ROLE_PROGRESSBAR:
return ROLE_SYSTEM_PROGRESSBAR;
case WebAccessibility::ROLE_PUSHBUTTON:
return ROLE_SYSTEM_PUSHBUTTON;
case WebAccessibility::ROLE_RADIOBUTTON:
return ROLE_SYSTEM_RADIOBUTTON;
case WebAccessibility::ROLE_ROW:
return ROLE_SYSTEM_ROW;
case WebAccessibility::ROLE_ROWHEADER:
return ROLE_SYSTEM_ROWHEADER;
case WebAccessibility::ROLE_SEPARATOR:
return ROLE_SYSTEM_SEPARATOR;
case WebAccessibility::ROLE_SLIDER:
return ROLE_SYSTEM_SLIDER;
case WebAccessibility::ROLE_STATICTEXT:
return ROLE_SYSTEM_STATICTEXT;
case WebAccessibility::ROLE_STATUSBAR:
return ROLE_SYSTEM_STATUSBAR;
case WebAccessibility::ROLE_TABLE:
return ROLE_SYSTEM_TABLE;
case WebAccessibility::ROLE_TEXT:
return ROLE_SYSTEM_TEXT;
case WebAccessibility::ROLE_TOOLBAR:
return ROLE_SYSTEM_TOOLBAR;
case WebAccessibility::ROLE_TOOLTIP:
return ROLE_SYSTEM_TOOLTIP;
case WebAccessibility::ROLE_CLIENT:
default:
// This is the default role for MSAA.
return ROLE_SYSTEM_CLIENT;
}
}
long BrowserAccessibility::MSAAState(long browser_accessibility_state) {
long state = 0;
if ((browser_accessibility_state >> WebAccessibility::STATE_CHECKED) & 1)
state |= STATE_SYSTEM_CHECKED;
if ((browser_accessibility_state >> WebAccessibility::STATE_FOCUSABLE) & 1)
state |= STATE_SYSTEM_FOCUSABLE;
if ((browser_accessibility_state >> WebAccessibility::STATE_FOCUSED) & 1)
state |= STATE_SYSTEM_FOCUSED;
if ((browser_accessibility_state >> WebAccessibility::STATE_HOTTRACKED) & 1)
state |= STATE_SYSTEM_HOTTRACKED;
if ((browser_accessibility_state >>
WebAccessibility::STATE_INDETERMINATE) & 1) {
state |= STATE_SYSTEM_INDETERMINATE;
}
if ((browser_accessibility_state >> WebAccessibility::STATE_LINKED) & 1)
state |= STATE_SYSTEM_LINKED;
if ((browser_accessibility_state >>
WebAccessibility::STATE_MULTISELECTABLE) & 1) {
state |= STATE_SYSTEM_MULTISELECTABLE;
}
if ((browser_accessibility_state >> WebAccessibility::STATE_OFFSCREEN) & 1)
state |= STATE_SYSTEM_OFFSCREEN;
if ((browser_accessibility_state >> WebAccessibility::STATE_PRESSED) & 1)
state |= STATE_SYSTEM_PRESSED;
if ((browser_accessibility_state >> WebAccessibility::STATE_PROTECTED) & 1)
state |= STATE_SYSTEM_PROTECTED;
if ((browser_accessibility_state >> WebAccessibility::STATE_READONLY) & 1)
state |= STATE_SYSTEM_READONLY;
if ((browser_accessibility_state >> WebAccessibility::STATE_TRAVERSED) & 1)
state |= STATE_SYSTEM_TRAVERSED;
if ((browser_accessibility_state >> WebAccessibility::STATE_UNAVAILABLE) & 1)
state |= STATE_SYSTEM_UNAVAILABLE;
return state;
}
|