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
|
// Copyright (c) 2010 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.
#ifndef CHROME_BROWSER_BROWSER_ACCESSIBILITY_WIN_H_
#define CHROME_BROWSER_BROWSER_ACCESSIBILITY_WIN_H_
#pragma once
#include <atlbase.h>
#include <atlcom.h>
#include <oleacc.h>
#include <map>
#include <vector>
#include "chrome/browser/browser_accessibility_manager_win.h"
#include "ia2_api_all.h" // Generated
#include "ISimpleDOMDocument.h" // Generated
#include "ISimpleDOMNode.h" // Generated
#include "ISimpleDOMText.h" // Generated
#include "webkit/glue/webaccessibility.h"
using webkit_glue::WebAccessibility;
////////////////////////////////////////////////////////////////////////////////
//
// BrowserAccessibility
//
// Class implementing the MSAA IAccessible COM interface for the
// Browser-Renderer communication of MSAA information, providing accessibility
// to be used by screen readers and other assistive technology (AT).
//
////////////////////////////////////////////////////////////////////////////////
class ATL_NO_VTABLE BrowserAccessibility
: public CComObjectRootEx<CComMultiThreadModel>,
public IDispatchImpl<IAccessible2, &IID_IAccessible2,
&LIBID_IAccessible2Lib>,
public IAccessibleImage,
public IAccessibleText,
public IServiceProvider,
public ISimpleDOMDocument,
public ISimpleDOMNode,
public ISimpleDOMText {
public:
BEGIN_COM_MAP(BrowserAccessibility)
COM_INTERFACE_ENTRY2(IDispatch, IAccessible2)
COM_INTERFACE_ENTRY2(IAccessible, IAccessible2)
COM_INTERFACE_ENTRY(IAccessible2)
COM_INTERFACE_ENTRY(IAccessibleImage)
COM_INTERFACE_ENTRY(IAccessibleText)
COM_INTERFACE_ENTRY(IServiceProvider)
COM_INTERFACE_ENTRY(ISimpleDOMDocument)
COM_INTERFACE_ENTRY(ISimpleDOMNode)
COM_INTERFACE_ENTRY(ISimpleDOMText)
END_COM_MAP()
BrowserAccessibility();
virtual ~BrowserAccessibility();
// Initialize this object and mark it as active.
void Initialize(BrowserAccessibilityManager* manager,
BrowserAccessibility* parent,
LONG child_id,
LONG index_in_parent,
const webkit_glue::WebAccessibility& src);
// Add a child of this object.
void AddChild(BrowserAccessibility* child);
// Mark this object as inactive, and remove references to all children.
// When no other clients hold any references to this object it will be
// deleted, and in the meantime, calls to any methods will return E_FAIL.
void InactivateTree();
// Return true if this object is equal to or a descendant of |ancestor|.
bool IsDescendantOf(BrowserAccessibility* ancestor);
// Returns the parent of this object, or NULL if it's the BrowserAccessibility
// root.
BrowserAccessibility* GetParent();
// Returns the number of children of this BrowserAccessibility object.
uint32 GetChildCount();
// Return the previous sibling of this object, or NULL if it's the first
// child of its parent.
BrowserAccessibility* GetPreviousSibling();
// Return the next sibling of this object, or NULL if it's the last child
// of its parent.
BrowserAccessibility* GetNextSibling();
// Replace a child BrowserAccessibility object. Used when updating the
// accessibility tree.
void ReplaceChild(
const BrowserAccessibility* old_acc, BrowserAccessibility* new_acc);
// Accessors
LONG child_id() const { return child_id_; }
int32 renderer_id() const { return renderer_id_; }
LONG index_in_parent() const { return index_in_parent_; }
// Add one to the reference count and return the same object. Always
// use this method when returning a BrowserAccessibility object as
// an output parameter to a COM interface, never use it otherwise.
BrowserAccessibility* NewReference();
//
// IAccessible methods.
//
// Performs the default action on a given object.
STDMETHODIMP accDoDefaultAction(VARIANT var_id);
// Retrieves the child element or child object at a given point on the screen.
STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child);
// Retrieves the specified object's current screen location.
STDMETHODIMP accLocation(LONG* x_left,
LONG* y_top,
LONG* width,
LONG* height,
VARIANT var_id);
// Traverses to another UI element and retrieves the object.
STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);
// Retrieves an IDispatch interface pointer for the specified child.
STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child);
// Retrieves the number of accessible children.
STDMETHODIMP get_accChildCount(LONG* child_count);
// Retrieves a string that describes the object's default action.
STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action);
// Retrieves the object's description.
STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc);
// Retrieves the object that has the keyboard focus.
STDMETHODIMP get_accFocus(VARIANT* focus_child);
// Retrieves the help information associated with the object.
STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help);
// Retrieves the specified object's shortcut.
STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key);
// Retrieves the name of the specified object.
STDMETHODIMP get_accName(VARIANT var_id, BSTR* name);
// Retrieves the IDispatch interface of the object's parent.
STDMETHODIMP get_accParent(IDispatch** disp_parent);
// Retrieves information describing the role of the specified object.
STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role);
// Retrieves the current state of the specified object.
STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state);
// Returns the value associated with the object.
STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value);
// Make an object take focus or extend the selection.
STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id);
STDMETHODIMP get_accHelpTopic(BSTR* help_file,
VARIANT var_id,
LONG* topic_id);
STDMETHODIMP get_accSelection(VARIANT* selected);
// Deprecated methods, not implemented.
STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) {
return E_NOTIMPL;
}
STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val) {
return E_NOTIMPL;
}
//
// IAccessible2 methods.
//
// Returns role from a longer list of possible roles.
STDMETHODIMP role(LONG* role);
// Returns the state bitmask from a larger set of possible states.
STDMETHODIMP get_states(AccessibleStates* states);
// Returns the attributes specific to this IAccessible2 object,
// such as a cell's formula.
STDMETHODIMP get_attributes(BSTR* attributes);
// Get the unique ID of this object so that the client knows if it's
// been encountered previously.
STDMETHODIMP get_uniqueID(LONG* unique_id);
// Get the window handle of the enclosing window.
STDMETHODIMP get_windowHandle(HWND* window_handle);
// Get this object's index in its parent object.
STDMETHODIMP get_indexInParent(LONG* index_in_parent);
// IAccessible2 methods not implemented.
STDMETHODIMP get_extendedRole(BSTR* extended_role) {
return E_NOTIMPL;
}
STDMETHODIMP get_nRelations(LONG* n_relations) {
return E_NOTIMPL;
}
STDMETHODIMP get_relation(LONG relation_index,
IAccessibleRelation** relation) {
return E_NOTIMPL;
}
STDMETHODIMP get_relations(LONG max_relations,
IAccessibleRelation** relations,
LONG* n_relations) {
return E_NOTIMPL;
}
STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) {
return E_NOTIMPL;
}
STDMETHODIMP scrollToPoint(enum IA2CoordinateType coordinate_type,
LONG x,
LONG y) {
return E_NOTIMPL;
}
STDMETHODIMP get_groupPosition(LONG* group_level,
LONG* similar_items_in_group,
LONG* position_in_group) {
return E_NOTIMPL;
}
STDMETHODIMP get_localizedExtendedRole(BSTR* localized_extended_role) {
return E_NOTIMPL;
}
STDMETHODIMP get_nExtendedStates(LONG* n_extended_states) {
return E_NOTIMPL;
}
STDMETHODIMP get_extendedStates(LONG max_extended_states,
BSTR** extended_states,
LONG* n_extended_states) {
return E_NOTIMPL;
}
STDMETHODIMP get_localizedExtendedStates(LONG max_localized_extended_states,
BSTR** localized_extended_states,
LONG* n_localized_extended_states) {
return E_NOTIMPL;
}
STDMETHODIMP get_locale(IA2Locale* locale) {
return E_NOTIMPL;
}
//
// IAccessibleImage methods.
//
STDMETHODIMP get_description(BSTR* description);
STDMETHODIMP get_imagePosition(enum IA2CoordinateType coordinate_type,
long* x, long* y);
STDMETHODIMP get_imageSize(long* height, long* width);
//
// IAccessibleText methods.
//
STDMETHODIMP get_nCharacters(long* n_characters);
STDMETHODIMP get_text(long start_offset, long end_offset, BSTR* text);
STDMETHODIMP get_caretOffset(long* offset);
// IAccessibleText methods not implemented.
STDMETHODIMP addSelection(long start_offset, long end_offset) {
return E_NOTIMPL;
}
STDMETHODIMP get_attributes(long offset, long* start_offset, long* end_offset,
BSTR* text_attributes) {
return E_NOTIMPL;
}
STDMETHODIMP get_characterExtents(long offset,
enum IA2CoordinateType coord_type,
long* x, long* y,
long* width, long* height) {
return E_NOTIMPL;
}
STDMETHODIMP get_nSelections(long* n_selections) {
return E_NOTIMPL;
}
STDMETHODIMP get_offsetAtPoint(long x, long y,
enum IA2CoordinateType coord_type,
long* offset) {
return E_NOTIMPL;
}
STDMETHODIMP get_selection(long selection_index,
long* start_offset,
long* end_offset) {
return E_NOTIMPL;
}
STDMETHODIMP get_textBeforeOffset(long offset,
enum IA2TextBoundaryType boundary_type,
long* start_offset, long* end_offset,
BSTR* text) {
return E_NOTIMPL;
}
STDMETHODIMP get_textAfterOffset(long offset,
enum IA2TextBoundaryType boundary_type,
long* start_offset, long* end_offset,
BSTR* text) {
return E_NOTIMPL;
}
STDMETHODIMP get_textAtOffset(long offset,
enum IA2TextBoundaryType boundary_type,
long* start_offset, long* end_offset,
BSTR* text) {
return E_NOTIMPL;
}
STDMETHODIMP removeSelection(long selection_index) {
return E_NOTIMPL;
}
STDMETHODIMP setCaretOffset(long offset) {
return E_NOTIMPL;
}
STDMETHODIMP setSelection(long selection_index,
long start_offset,
long end_offset) {
return E_NOTIMPL;
}
STDMETHODIMP scrollSubstringTo(long start_index,
long end_index,
enum IA2ScrollType scroll_type) {
return E_NOTIMPL;
}
STDMETHODIMP scrollSubstringToPoint(long start_index, long end_index,
enum IA2CoordinateType coordinate_type,
long x, long y) {
return E_NOTIMPL;
}
STDMETHODIMP get_newText(IA2TextSegment* new_text) {
return E_NOTIMPL;
}
STDMETHODIMP get_oldText(IA2TextSegment* old_text) {
return E_NOTIMPL;
}
//
// ISimpleDOMDocument methods.
//
STDMETHODIMP get_URL(BSTR* url);
STDMETHODIMP get_title(BSTR* title);
STDMETHODIMP get_mimeType(BSTR* mime_type);
STDMETHODIMP get_docType(BSTR* doc_type);
STDMETHODIMP get_nameSpaceURIForID(
short name_space_id, BSTR *name_space_uri) {
return E_NOTIMPL;
}
STDMETHODIMP put_alternateViewMediaTypes(
BSTR *comma_separated_media_types) {
return E_NOTIMPL;
}
//
// ISimpleDOMNode methods.
//
STDMETHODIMP get_nodeInfo(
BSTR* node_name,
short* name_space_id,
BSTR* node_value,
unsigned int* num_children,
unsigned int* unique_id,
unsigned short* node_type);
STDMETHODIMP get_attributes(
unsigned short max_attribs,
BSTR* attrib_names,
short* name_space_id,
BSTR* attrib_values,
unsigned short* num_attribs);
STDMETHODIMP get_attributesForNames(
unsigned short num_attribs,
BSTR* attrib_names,
short* name_space_id,
BSTR* attrib_values);
STDMETHODIMP get_computedStyle(
unsigned short max_style_properties,
boolean use_alternate_view,
BSTR *style_properties,
BSTR *style_values,
unsigned short *num_style_properties);
STDMETHODIMP get_computedStyleForProperties(
unsigned short num_style_properties,
boolean use_alternate_view,
BSTR* style_properties,
BSTR* style_values);
STDMETHODIMP scrollTo(boolean placeTopLeft);
STDMETHODIMP get_parentNode(ISimpleDOMNode** node);
STDMETHODIMP get_firstChild(ISimpleDOMNode** node);
STDMETHODIMP get_lastChild(ISimpleDOMNode** node);
STDMETHODIMP get_previousSibling(ISimpleDOMNode** node);
STDMETHODIMP get_nextSibling(ISimpleDOMNode** node);
STDMETHODIMP get_childAt(
unsigned int child_index,
ISimpleDOMNode** node);
STDMETHODIMP get_innerHTML(BSTR* innerHTML) {
return E_NOTIMPL;
}
STDMETHODIMP get_localInterface(void** local_interface) {
return E_NOTIMPL;
}
STDMETHODIMP get_language(BSTR* language) {
return E_NOTIMPL;
}
//
// ISimpleDOMText methods.
//
STDMETHODIMP get_domText(BSTR* dom_text);
STDMETHODIMP get_clippedSubstringBounds(
unsigned int start_index,
unsigned int end_index,
int* x,
int* y,
int* width,
int* height) {
return E_NOTIMPL;
}
STDMETHODIMP get_unclippedSubstringBounds(
unsigned int start_index,
unsigned int end_index,
int* x,
int* y,
int* width,
int* height) {
return E_NOTIMPL;
}
STDMETHODIMP scrollToSubstring(
unsigned int start_index,
unsigned int end_index) {
return E_NOTIMPL;
}
STDMETHODIMP get_fontFamily(BSTR *font_family) {
return E_NOTIMPL;
}
//
// IServiceProvider methods.
//
STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void** object);
//
// CComObjectRootEx methods.
//
HRESULT WINAPI InternalQueryInterface(void* this_ptr,
const _ATL_INTMAP_ENTRY* entries,
REFIID iid,
void** object);
private:
// Many MSAA methods take a var_id parameter indicating that the operation
// should be performed on a particular child ID, rather than this object.
// This method tries to figure out the target object from |var_id| and
// returns a pointer to the target object if it exists, otherwise NULL.
// Does not return a new reference.
BrowserAccessibility* GetTargetFromChildID(const VARIANT& var_id);
// Initialize the role and state metadata from the role enum and state
// bitmasks defined in webkit/glue/webaccessibility.h.
void InitRoleAndState(LONG web_accessibility_role,
LONG web_accessibility_state);
// Return true if this attribute is in the attributes map.
bool HasAttribute(WebAccessibility::Attribute attribute);
// Retrieve the string value of an attribute from the attribute map and
// returns true if found.
bool GetAttribute(WebAccessibility::Attribute attribute, string16* value);
// Retrieve the string value of an attribute from the attribute map and
// if found and nonempty, allocate a new BSTR (with SysAllocString)
// and return S_OK. If not found or empty, return S_FALSE.
HRESULT GetAttributeAsBstr(
WebAccessibility::Attribute attribute, BSTR* value_bstr);
// Escape a string like it would be escaped for a URL or HTML form.
string16 Escape(string16 str);
// The manager of this tree of accessibility objects; needed for
// global operations like focus tracking.
BrowserAccessibilityManager* manager_;
// The parent of this object, may be NULL if we're the root object.
BrowserAccessibility* parent_;
// The ID of this object; globally unique within the browser process.
LONG child_id_;
// The index of this within its parent object.
LONG index_in_parent_;
// The ID of this object in the renderer process.
int32 renderer_id_;
// The children of this object.
std::vector<BrowserAccessibility*> children_;
// Accessibility metadata from the renderer, used to respond to MSAA
// events.
string16 name_;
string16 value_;
std::map<int32, string16> attributes_;
std::vector<std::pair<string16, string16> > html_attributes_;
LONG role_;
LONG state_;
string16 role_name_;
LONG ia2_role_;
LONG ia2_state_;
WebKit::WebRect location_;
// COM objects are reference-counted. When we're done with this object
// and it's removed from our accessibility tree, a client may still be
// holding onto a pointer to this object, so we mark it as inactive
// so that calls to any of this object's methods immediately return
// failure.
bool instance_active_;
DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility);
};
#endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_WIN_H_
|