OLD | NEW |
| (Empty) |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CHROME_BROWSER_BROWSER_ACCESSIBILITY_WIN_H_ | |
6 #define CHROME_BROWSER_BROWSER_ACCESSIBILITY_WIN_H_ | |
7 #pragma once | |
8 | |
9 #include <atlbase.h> | |
10 #include <atlcom.h> | |
11 #include <oleacc.h> | |
12 | |
13 #include <map> | |
14 #include <vector> | |
15 | |
16 #include "chrome/browser/browser_accessibility_manager_win.h" | |
17 #include "ia2_api_all.h" // Generated | |
18 #include "ISimpleDOMDocument.h" // Generated | |
19 #include "ISimpleDOMNode.h" // Generated | |
20 #include "ISimpleDOMText.h" // Generated | |
21 #include "webkit/glue/webaccessibility.h" | |
22 | |
23 using webkit_glue::WebAccessibility; | |
24 | |
25 //////////////////////////////////////////////////////////////////////////////// | |
26 // | |
27 // BrowserAccessibility | |
28 // | |
29 // Class implementing the MSAA IAccessible COM interface for the | |
30 // Browser-Renderer communication of MSAA information, providing accessibility | |
31 // to be used by screen readers and other assistive technology (AT). | |
32 // | |
33 //////////////////////////////////////////////////////////////////////////////// | |
34 class ATL_NO_VTABLE BrowserAccessibility | |
35 : public CComObjectRootEx<CComMultiThreadModel>, | |
36 public IDispatchImpl<IAccessible2, &IID_IAccessible2, | |
37 &LIBID_IAccessible2Lib>, | |
38 public IAccessibleImage, | |
39 public IAccessibleText, | |
40 public IServiceProvider, | |
41 public ISimpleDOMDocument, | |
42 public ISimpleDOMNode, | |
43 public ISimpleDOMText { | |
44 public: | |
45 BEGIN_COM_MAP(BrowserAccessibility) | |
46 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2) | |
47 COM_INTERFACE_ENTRY2(IAccessible, IAccessible2) | |
48 COM_INTERFACE_ENTRY(IAccessible2) | |
49 COM_INTERFACE_ENTRY(IAccessibleImage) | |
50 COM_INTERFACE_ENTRY(IAccessibleText) | |
51 COM_INTERFACE_ENTRY(IServiceProvider) | |
52 COM_INTERFACE_ENTRY(ISimpleDOMDocument) | |
53 COM_INTERFACE_ENTRY(ISimpleDOMNode) | |
54 COM_INTERFACE_ENTRY(ISimpleDOMText) | |
55 END_COM_MAP() | |
56 | |
57 BrowserAccessibility(); | |
58 | |
59 virtual ~BrowserAccessibility(); | |
60 | |
61 // Initialize this object and mark it as active. | |
62 void Initialize(BrowserAccessibilityManager* manager, | |
63 BrowserAccessibility* parent, | |
64 LONG child_id, | |
65 LONG index_in_parent, | |
66 const webkit_glue::WebAccessibility& src); | |
67 | |
68 // Add a child of this object. | |
69 void AddChild(BrowserAccessibility* child); | |
70 | |
71 // Mark this object as inactive, and remove references to all children. | |
72 // When no other clients hold any references to this object it will be | |
73 // deleted, and in the meantime, calls to any methods will return E_FAIL. | |
74 void InactivateTree(); | |
75 | |
76 // Return true if this object is equal to or a descendant of |ancestor|. | |
77 bool IsDescendantOf(BrowserAccessibility* ancestor); | |
78 | |
79 // Returns the parent of this object, or NULL if it's the BrowserAccessibility | |
80 // root. | |
81 BrowserAccessibility* GetParent(); | |
82 | |
83 // Returns the number of children of this BrowserAccessibility object. | |
84 uint32 GetChildCount(); | |
85 | |
86 // Return the previous sibling of this object, or NULL if it's the first | |
87 // child of its parent. | |
88 BrowserAccessibility* GetPreviousSibling(); | |
89 | |
90 // Return the next sibling of this object, or NULL if it's the last child | |
91 // of its parent. | |
92 BrowserAccessibility* GetNextSibling(); | |
93 | |
94 // Replace a child BrowserAccessibility object. Used when updating the | |
95 // accessibility tree. | |
96 void ReplaceChild( | |
97 const BrowserAccessibility* old_acc, BrowserAccessibility* new_acc); | |
98 | |
99 // Accessors | |
100 LONG child_id() const { return child_id_; } | |
101 int32 renderer_id() const { return renderer_id_; } | |
102 LONG index_in_parent() const { return index_in_parent_; } | |
103 | |
104 // Add one to the reference count and return the same object. Always | |
105 // use this method when returning a BrowserAccessibility object as | |
106 // an output parameter to a COM interface, never use it otherwise. | |
107 BrowserAccessibility* NewReference(); | |
108 | |
109 // | |
110 // IAccessible methods. | |
111 // | |
112 | |
113 // Performs the default action on a given object. | |
114 STDMETHODIMP accDoDefaultAction(VARIANT var_id); | |
115 | |
116 // Retrieves the child element or child object at a given point on the screen. | |
117 STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child); | |
118 | |
119 // Retrieves the specified object's current screen location. | |
120 STDMETHODIMP accLocation(LONG* x_left, | |
121 LONG* y_top, | |
122 LONG* width, | |
123 LONG* height, | |
124 VARIANT var_id); | |
125 | |
126 // Traverses to another UI element and retrieves the object. | |
127 STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end); | |
128 | |
129 // Retrieves an IDispatch interface pointer for the specified child. | |
130 STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child); | |
131 | |
132 // Retrieves the number of accessible children. | |
133 STDMETHODIMP get_accChildCount(LONG* child_count); | |
134 | |
135 // Retrieves a string that describes the object's default action. | |
136 STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action); | |
137 | |
138 // Retrieves the object's description. | |
139 STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc); | |
140 | |
141 // Retrieves the object that has the keyboard focus. | |
142 STDMETHODIMP get_accFocus(VARIANT* focus_child); | |
143 | |
144 // Retrieves the help information associated with the object. | |
145 STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help); | |
146 | |
147 // Retrieves the specified object's shortcut. | |
148 STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key); | |
149 | |
150 // Retrieves the name of the specified object. | |
151 STDMETHODIMP get_accName(VARIANT var_id, BSTR* name); | |
152 | |
153 // Retrieves the IDispatch interface of the object's parent. | |
154 STDMETHODIMP get_accParent(IDispatch** disp_parent); | |
155 | |
156 // Retrieves information describing the role of the specified object. | |
157 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role); | |
158 | |
159 // Retrieves the current state of the specified object. | |
160 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state); | |
161 | |
162 // Returns the value associated with the object. | |
163 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value); | |
164 | |
165 // Make an object take focus or extend the selection. | |
166 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id); | |
167 | |
168 STDMETHODIMP get_accHelpTopic(BSTR* help_file, | |
169 VARIANT var_id, | |
170 LONG* topic_id); | |
171 | |
172 STDMETHODIMP get_accSelection(VARIANT* selected); | |
173 | |
174 // Deprecated methods, not implemented. | |
175 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) { | |
176 return E_NOTIMPL; | |
177 } | |
178 STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val) { | |
179 return E_NOTIMPL; | |
180 } | |
181 | |
182 // | |
183 // IAccessible2 methods. | |
184 // | |
185 | |
186 // Returns role from a longer list of possible roles. | |
187 STDMETHODIMP role(LONG* role); | |
188 | |
189 // Returns the state bitmask from a larger set of possible states. | |
190 STDMETHODIMP get_states(AccessibleStates* states); | |
191 | |
192 // Returns the attributes specific to this IAccessible2 object, | |
193 // such as a cell's formula. | |
194 STDMETHODIMP get_attributes(BSTR* attributes); | |
195 | |
196 // Get the unique ID of this object so that the client knows if it's | |
197 // been encountered previously. | |
198 STDMETHODIMP get_uniqueID(LONG* unique_id); | |
199 | |
200 // Get the window handle of the enclosing window. | |
201 STDMETHODIMP get_windowHandle(HWND* window_handle); | |
202 | |
203 // Get this object's index in its parent object. | |
204 STDMETHODIMP get_indexInParent(LONG* index_in_parent); | |
205 | |
206 // IAccessible2 methods not implemented. | |
207 STDMETHODIMP get_extendedRole(BSTR* extended_role) { | |
208 return E_NOTIMPL; | |
209 } | |
210 STDMETHODIMP get_nRelations(LONG* n_relations) { | |
211 return E_NOTIMPL; | |
212 } | |
213 STDMETHODIMP get_relation(LONG relation_index, | |
214 IAccessibleRelation** relation) { | |
215 return E_NOTIMPL; | |
216 } | |
217 STDMETHODIMP get_relations(LONG max_relations, | |
218 IAccessibleRelation** relations, | |
219 LONG* n_relations) { | |
220 return E_NOTIMPL; | |
221 } | |
222 STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) { | |
223 return E_NOTIMPL; | |
224 } | |
225 STDMETHODIMP scrollToPoint(enum IA2CoordinateType coordinate_type, | |
226 LONG x, | |
227 LONG y) { | |
228 return E_NOTIMPL; | |
229 } | |
230 STDMETHODIMP get_groupPosition(LONG* group_level, | |
231 LONG* similar_items_in_group, | |
232 LONG* position_in_group) { | |
233 return E_NOTIMPL; | |
234 } | |
235 STDMETHODIMP get_localizedExtendedRole(BSTR* localized_extended_role) { | |
236 return E_NOTIMPL; | |
237 } | |
238 STDMETHODIMP get_nExtendedStates(LONG* n_extended_states) { | |
239 return E_NOTIMPL; | |
240 } | |
241 STDMETHODIMP get_extendedStates(LONG max_extended_states, | |
242 BSTR** extended_states, | |
243 LONG* n_extended_states) { | |
244 return E_NOTIMPL; | |
245 } | |
246 STDMETHODIMP get_localizedExtendedStates(LONG max_localized_extended_states, | |
247 BSTR** localized_extended_states, | |
248 LONG* n_localized_extended_states) { | |
249 return E_NOTIMPL; | |
250 } | |
251 STDMETHODIMP get_locale(IA2Locale* locale) { | |
252 return E_NOTIMPL; | |
253 } | |
254 | |
255 // | |
256 // IAccessibleImage methods. | |
257 // | |
258 | |
259 STDMETHODIMP get_description(BSTR* description); | |
260 | |
261 STDMETHODIMP get_imagePosition(enum IA2CoordinateType coordinate_type, | |
262 long* x, long* y); | |
263 | |
264 STDMETHODIMP get_imageSize(long* height, long* width); | |
265 | |
266 // | |
267 // IAccessibleText methods. | |
268 // | |
269 | |
270 STDMETHODIMP get_nCharacters(long* n_characters); | |
271 | |
272 STDMETHODIMP get_text(long start_offset, long end_offset, BSTR* text); | |
273 | |
274 STDMETHODIMP get_caretOffset(long* offset); | |
275 | |
276 // IAccessibleText methods not implemented. | |
277 STDMETHODIMP addSelection(long start_offset, long end_offset) { | |
278 return E_NOTIMPL; | |
279 } | |
280 STDMETHODIMP get_attributes(long offset, long* start_offset, long* end_offset, | |
281 BSTR* text_attributes) { | |
282 return E_NOTIMPL; | |
283 } | |
284 STDMETHODIMP get_characterExtents(long offset, | |
285 enum IA2CoordinateType coord_type, | |
286 long* x, long* y, | |
287 long* width, long* height) { | |
288 return E_NOTIMPL; | |
289 } | |
290 STDMETHODIMP get_nSelections(long* n_selections) { | |
291 return E_NOTIMPL; | |
292 } | |
293 STDMETHODIMP get_offsetAtPoint(long x, long y, | |
294 enum IA2CoordinateType coord_type, | |
295 long* offset) { | |
296 return E_NOTIMPL; | |
297 } | |
298 STDMETHODIMP get_selection(long selection_index, | |
299 long* start_offset, | |
300 long* end_offset) { | |
301 return E_NOTIMPL; | |
302 } | |
303 STDMETHODIMP get_textBeforeOffset(long offset, | |
304 enum IA2TextBoundaryType boundary_type, | |
305 long* start_offset, long* end_offset, | |
306 BSTR* text) { | |
307 return E_NOTIMPL; | |
308 } | |
309 STDMETHODIMP get_textAfterOffset(long offset, | |
310 enum IA2TextBoundaryType boundary_type, | |
311 long* start_offset, long* end_offset, | |
312 BSTR* text) { | |
313 return E_NOTIMPL; | |
314 } | |
315 STDMETHODIMP get_textAtOffset(long offset, | |
316 enum IA2TextBoundaryType boundary_type, | |
317 long* start_offset, long* end_offset, | |
318 BSTR* text) { | |
319 return E_NOTIMPL; | |
320 } | |
321 STDMETHODIMP removeSelection(long selection_index) { | |
322 return E_NOTIMPL; | |
323 } | |
324 STDMETHODIMP setCaretOffset(long offset) { | |
325 return E_NOTIMPL; | |
326 } | |
327 STDMETHODIMP setSelection(long selection_index, | |
328 long start_offset, | |
329 long end_offset) { | |
330 return E_NOTIMPL; | |
331 } | |
332 STDMETHODIMP scrollSubstringTo(long start_index, | |
333 long end_index, | |
334 enum IA2ScrollType scroll_type) { | |
335 return E_NOTIMPL; | |
336 } | |
337 STDMETHODIMP scrollSubstringToPoint(long start_index, long end_index, | |
338 enum IA2CoordinateType coordinate_type, | |
339 long x, long y) { | |
340 return E_NOTIMPL; | |
341 } | |
342 STDMETHODIMP get_newText(IA2TextSegment* new_text) { | |
343 return E_NOTIMPL; | |
344 } | |
345 STDMETHODIMP get_oldText(IA2TextSegment* old_text) { | |
346 return E_NOTIMPL; | |
347 } | |
348 | |
349 // | |
350 // ISimpleDOMDocument methods. | |
351 // | |
352 | |
353 STDMETHODIMP get_URL(BSTR* url); | |
354 | |
355 STDMETHODIMP get_title(BSTR* title); | |
356 | |
357 STDMETHODIMP get_mimeType(BSTR* mime_type); | |
358 | |
359 STDMETHODIMP get_docType(BSTR* doc_type); | |
360 | |
361 STDMETHODIMP get_nameSpaceURIForID( | |
362 short name_space_id, BSTR *name_space_uri) { | |
363 return E_NOTIMPL; | |
364 } | |
365 STDMETHODIMP put_alternateViewMediaTypes( | |
366 BSTR *comma_separated_media_types) { | |
367 return E_NOTIMPL; | |
368 } | |
369 | |
370 // | |
371 // ISimpleDOMNode methods. | |
372 // | |
373 | |
374 STDMETHODIMP get_nodeInfo( | |
375 BSTR* node_name, | |
376 short* name_space_id, | |
377 BSTR* node_value, | |
378 unsigned int* num_children, | |
379 unsigned int* unique_id, | |
380 unsigned short* node_type); | |
381 | |
382 STDMETHODIMP get_attributes( | |
383 unsigned short max_attribs, | |
384 BSTR* attrib_names, | |
385 short* name_space_id, | |
386 BSTR* attrib_values, | |
387 unsigned short* num_attribs); | |
388 | |
389 STDMETHODIMP get_attributesForNames( | |
390 unsigned short num_attribs, | |
391 BSTR* attrib_names, | |
392 short* name_space_id, | |
393 BSTR* attrib_values); | |
394 | |
395 STDMETHODIMP get_computedStyle( | |
396 unsigned short max_style_properties, | |
397 boolean use_alternate_view, | |
398 BSTR *style_properties, | |
399 BSTR *style_values, | |
400 unsigned short *num_style_properties); | |
401 | |
402 STDMETHODIMP get_computedStyleForProperties( | |
403 unsigned short num_style_properties, | |
404 boolean use_alternate_view, | |
405 BSTR* style_properties, | |
406 BSTR* style_values); | |
407 | |
408 STDMETHODIMP scrollTo(boolean placeTopLeft); | |
409 | |
410 STDMETHODIMP get_parentNode(ISimpleDOMNode** node); | |
411 | |
412 STDMETHODIMP get_firstChild(ISimpleDOMNode** node); | |
413 | |
414 STDMETHODIMP get_lastChild(ISimpleDOMNode** node); | |
415 | |
416 STDMETHODIMP get_previousSibling(ISimpleDOMNode** node); | |
417 | |
418 STDMETHODIMP get_nextSibling(ISimpleDOMNode** node); | |
419 | |
420 STDMETHODIMP get_childAt( | |
421 unsigned int child_index, | |
422 ISimpleDOMNode** node); | |
423 | |
424 STDMETHODIMP get_innerHTML(BSTR* innerHTML) { | |
425 return E_NOTIMPL; | |
426 } | |
427 | |
428 STDMETHODIMP get_localInterface(void** local_interface) { | |
429 return E_NOTIMPL; | |
430 } | |
431 | |
432 STDMETHODIMP get_language(BSTR* language) { | |
433 return E_NOTIMPL; | |
434 } | |
435 | |
436 // | |
437 // ISimpleDOMText methods. | |
438 // | |
439 | |
440 STDMETHODIMP get_domText(BSTR* dom_text); | |
441 | |
442 STDMETHODIMP get_clippedSubstringBounds( | |
443 unsigned int start_index, | |
444 unsigned int end_index, | |
445 int* x, | |
446 int* y, | |
447 int* width, | |
448 int* height) { | |
449 return E_NOTIMPL; | |
450 } | |
451 | |
452 STDMETHODIMP get_unclippedSubstringBounds( | |
453 unsigned int start_index, | |
454 unsigned int end_index, | |
455 int* x, | |
456 int* y, | |
457 int* width, | |
458 int* height) { | |
459 return E_NOTIMPL; | |
460 } | |
461 | |
462 STDMETHODIMP scrollToSubstring( | |
463 unsigned int start_index, | |
464 unsigned int end_index) { | |
465 return E_NOTIMPL; | |
466 } | |
467 | |
468 STDMETHODIMP get_fontFamily(BSTR *font_family) { | |
469 return E_NOTIMPL; | |
470 } | |
471 | |
472 // | |
473 // IServiceProvider methods. | |
474 // | |
475 | |
476 STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void** object); | |
477 | |
478 // | |
479 // CComObjectRootEx methods. | |
480 // | |
481 | |
482 HRESULT WINAPI InternalQueryInterface(void* this_ptr, | |
483 const _ATL_INTMAP_ENTRY* entries, | |
484 REFIID iid, | |
485 void** object); | |
486 | |
487 private: | |
488 // Many MSAA methods take a var_id parameter indicating that the operation | |
489 // should be performed on a particular child ID, rather than this object. | |
490 // This method tries to figure out the target object from |var_id| and | |
491 // returns a pointer to the target object if it exists, otherwise NULL. | |
492 // Does not return a new reference. | |
493 BrowserAccessibility* GetTargetFromChildID(const VARIANT& var_id); | |
494 | |
495 // Initialize the role and state metadata from the role enum and state | |
496 // bitmasks defined in webkit/glue/webaccessibility.h. | |
497 void InitRoleAndState(LONG web_accessibility_role, | |
498 LONG web_accessibility_state); | |
499 | |
500 // Return true if this attribute is in the attributes map. | |
501 bool HasAttribute(WebAccessibility::Attribute attribute); | |
502 | |
503 // Retrieve the string value of an attribute from the attribute map and | |
504 // returns true if found. | |
505 bool GetAttribute(WebAccessibility::Attribute attribute, string16* value); | |
506 | |
507 // Retrieve the string value of an attribute from the attribute map and | |
508 // if found and nonempty, allocate a new BSTR (with SysAllocString) | |
509 // and return S_OK. If not found or empty, return S_FALSE. | |
510 HRESULT GetAttributeAsBstr( | |
511 WebAccessibility::Attribute attribute, BSTR* value_bstr); | |
512 | |
513 // Escape a string like it would be escaped for a URL or HTML form. | |
514 string16 Escape(string16 str); | |
515 | |
516 // The manager of this tree of accessibility objects; needed for | |
517 // global operations like focus tracking. | |
518 BrowserAccessibilityManager* manager_; | |
519 // The parent of this object, may be NULL if we're the root object. | |
520 BrowserAccessibility* parent_; | |
521 // The ID of this object; globally unique within the browser process. | |
522 LONG child_id_; | |
523 // The index of this within its parent object. | |
524 LONG index_in_parent_; | |
525 // The ID of this object in the renderer process. | |
526 int32 renderer_id_; | |
527 | |
528 // The children of this object. | |
529 std::vector<BrowserAccessibility*> children_; | |
530 | |
531 // Accessibility metadata from the renderer, used to respond to MSAA | |
532 // events. | |
533 string16 name_; | |
534 string16 value_; | |
535 std::map<int32, string16> attributes_; | |
536 std::vector<std::pair<string16, string16> > html_attributes_; | |
537 | |
538 LONG role_; | |
539 LONG state_; | |
540 string16 role_name_; | |
541 LONG ia2_role_; | |
542 LONG ia2_state_; | |
543 WebKit::WebRect location_; | |
544 | |
545 // COM objects are reference-counted. When we're done with this object | |
546 // and it's removed from our accessibility tree, a client may still be | |
547 // holding onto a pointer to this object, so we mark it as inactive | |
548 // so that calls to any of this object's methods immediately return | |
549 // failure. | |
550 bool instance_active_; | |
551 | |
552 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); | |
553 }; | |
554 | |
555 #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_WIN_H_ | |
OLD | NEW |