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_H_ | |
6 #define CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ | |
7 | |
8 #include <atlbase.h> | |
9 #include <atlcom.h> | |
10 #include <oleacc.h> | |
11 | |
12 #include <vector> | |
13 | |
14 #include "base/scoped_comptr_win.h" | |
15 #include "chrome/browser/browser_accessibility_manager.h" | |
16 #include "ia2_api_all.h" // Generated | |
17 #include "webkit/glue/webaccessibility.h" | |
18 | |
19 using webkit_glue::WebAccessibility; | |
20 | |
21 //////////////////////////////////////////////////////////////////////////////// | |
22 // | |
23 // BrowserAccessibility | |
24 // | |
25 // Class implementing the MSAA IAccessible COM interface for the | |
26 // Browser-Renderer communication of MSAA information, providing accessibility | |
27 // to be used by screen readers and other assistive technology (AT). | |
28 // | |
29 //////////////////////////////////////////////////////////////////////////////// | |
30 class ATL_NO_VTABLE BrowserAccessibility | |
31 : public CComObjectRootEx<CComMultiThreadModel>, | |
32 public IDispatchImpl<IAccessible2, &IID_IAccessible2, | |
33 &LIBID_IAccessible2Lib>, | |
34 public IAccessibleImage, | |
35 public IAccessibleText, | |
36 public IServiceProvider { | |
37 public: | |
38 BEGIN_COM_MAP(BrowserAccessibility) | |
39 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2) | |
40 COM_INTERFACE_ENTRY2(IAccessible, IAccessible2) | |
41 COM_INTERFACE_ENTRY(IAccessible2) | |
42 COM_INTERFACE_ENTRY(IAccessibleImage) | |
43 COM_INTERFACE_ENTRY(IAccessibleText) | |
44 COM_INTERFACE_ENTRY(IServiceProvider) | |
45 END_COM_MAP() | |
46 | |
47 BrowserAccessibility(); | |
48 | |
49 virtual ~BrowserAccessibility(); | |
50 | |
51 // Initialize this object and mark it as active. | |
52 void Initialize(BrowserAccessibilityManager* manager, | |
53 BrowserAccessibility* parent, | |
54 LONG child_id, | |
55 LONG index_in_parent, | |
56 const webkit_glue::WebAccessibility& src); | |
57 | |
58 // Add a child of this object. | |
59 void AddChild(BrowserAccessibility* child); | |
60 | |
61 // Mark this object as inactive, and remove references to all children. | |
62 // When no other clients hold any references to this object it will be | |
63 // deleted, and in the meantime, calls to any methods will return E_FAIL. | |
64 void InactivateTree(); | |
65 | |
66 // Return true if this object is equal to or a descendant of |ancestor|. | |
67 bool IsDescendantOf(BrowserAccessibility* ancestor); | |
68 | |
69 // Return the previous sibling of this object, or NULL if it's the first | |
70 // child of its parent. | |
71 BrowserAccessibility* GetPreviousSibling(); | |
72 | |
73 // Return the next sibling of this object, or NULL if it's the last child | |
74 // of its parent. | |
75 BrowserAccessibility* GetNextSibling(); | |
76 | |
77 // Accessors | |
78 LONG child_id() const { return child_id_; } | |
79 int32 renderer_id() const { return renderer_id_; } | |
80 | |
81 // Add one to the reference count and return the same object. Always | |
82 // use this method when returning a BrowserAccessibility object as | |
83 // an output parameter to a COM interface, never use it otherwise. | |
84 BrowserAccessibility* NewReference(); | |
85 | |
86 // | |
87 // IAccessible methods. | |
88 // | |
89 | |
90 // Performs the default action on a given object. | |
91 STDMETHODIMP accDoDefaultAction(VARIANT var_id); | |
92 | |
93 // Retrieves the child element or child object at a given point on the screen. | |
94 STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child); | |
95 | |
96 // Retrieves the specified object's current screen location. | |
97 STDMETHODIMP accLocation(LONG* x_left, | |
98 LONG* y_top, | |
99 LONG* width, | |
100 LONG* height, | |
101 VARIANT var_id); | |
102 | |
103 // Traverses to another UI element and retrieves the object. | |
104 STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end); | |
105 | |
106 // Retrieves an IDispatch interface pointer for the specified child. | |
107 STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child); | |
108 | |
109 // Retrieves the number of accessible children. | |
110 STDMETHODIMP get_accChildCount(LONG* child_count); | |
111 | |
112 // Retrieves a string that describes the object's default action. | |
113 STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action); | |
114 | |
115 // Retrieves the object's description. | |
116 STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc); | |
117 | |
118 // Retrieves the object that has the keyboard focus. | |
119 STDMETHODIMP get_accFocus(VARIANT* focus_child); | |
120 | |
121 // Retrieves the help information associated with the object. | |
122 STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help); | |
123 | |
124 // Retrieves the specified object's shortcut. | |
125 STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key); | |
126 | |
127 // Retrieves the name of the specified object. | |
128 STDMETHODIMP get_accName(VARIANT var_id, BSTR* name); | |
129 | |
130 // Retrieves the IDispatch interface of the object's parent. | |
131 STDMETHODIMP get_accParent(IDispatch** disp_parent); | |
132 | |
133 // Retrieves information describing the role of the specified object. | |
134 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role); | |
135 | |
136 // Retrieves the current state of the specified object. | |
137 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state); | |
138 | |
139 // Returns the value associated with the object. | |
140 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value); | |
141 | |
142 // Make an object take focus or extend the selection. | |
143 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id); | |
144 | |
145 STDMETHODIMP get_accHelpTopic(BSTR* help_file, | |
146 VARIANT var_id, | |
147 LONG* topic_id); | |
148 | |
149 STDMETHODIMP get_accSelection(VARIANT* selected); | |
150 | |
151 // Deprecated methods, not implemented. | |
152 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) { | |
153 return E_NOTIMPL; | |
154 } | |
155 STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val) { | |
156 return E_NOTIMPL; | |
157 } | |
158 | |
159 // | |
160 // IAccessible2 methods. | |
161 // | |
162 | |
163 // Returns role from a longer list of possible roles. | |
164 STDMETHODIMP role(LONG* role); | |
165 | |
166 // Returns the state bitmask from a larger set of possible states. | |
167 STDMETHODIMP get_states(AccessibleStates* states); | |
168 | |
169 // Returns the attributes specific to this IAccessible2 object, | |
170 // such as a cell's formula. | |
171 STDMETHODIMP get_attributes(BSTR* attributes); | |
172 | |
173 // Get the unique ID of this object so that the client knows if it's | |
174 // been encountered previously. | |
175 STDMETHODIMP get_uniqueID(LONG* unique_id); | |
176 | |
177 // Get the window handle of the enclosing window. | |
178 STDMETHODIMP get_windowHandle(HWND* window_handle); | |
179 | |
180 // Get this object's index in its parent object. | |
181 STDMETHODIMP get_indexInParent(LONG* index_in_parent); | |
182 | |
183 // IAccessible2 methods not implemented. | |
184 STDMETHODIMP get_extendedRole(BSTR* extended_role) { | |
185 return E_NOTIMPL; | |
186 } | |
187 STDMETHODIMP get_nRelations(LONG* n_relations) { | |
188 return E_NOTIMPL; | |
189 } | |
190 STDMETHODIMP get_relation(LONG relation_index, | |
191 IAccessibleRelation** relation) { | |
192 return E_NOTIMPL; | |
193 } | |
194 STDMETHODIMP get_relations(LONG max_relations, | |
195 IAccessibleRelation** relations, | |
196 LONG* n_relations) { | |
197 return E_NOTIMPL; | |
198 } | |
199 STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) { | |
200 return E_NOTIMPL; | |
201 } | |
202 STDMETHODIMP scrollToPoint(enum IA2CoordinateType coordinate_type, | |
203 LONG x, | |
204 LONG y) { | |
205 return E_NOTIMPL; | |
206 } | |
207 STDMETHODIMP get_groupPosition(LONG* group_level, | |
208 LONG* similar_items_in_group, | |
209 LONG* position_in_group) { | |
210 return E_NOTIMPL; | |
211 } | |
212 STDMETHODIMP get_localizedExtendedRole(BSTR* localized_extended_role) { | |
213 return E_NOTIMPL; | |
214 } | |
215 STDMETHODIMP get_nExtendedStates(LONG* n_extended_states) { | |
216 return E_NOTIMPL; | |
217 } | |
218 STDMETHODIMP get_extendedStates(LONG max_extended_states, | |
219 BSTR** extended_states, | |
220 LONG* n_extended_states) { | |
221 return E_NOTIMPL; | |
222 } | |
223 STDMETHODIMP get_localizedExtendedStates(LONG max_localized_extended_states, | |
224 BSTR** localized_extended_states, | |
225 LONG* n_localized_extended_states) { | |
226 return E_NOTIMPL; | |
227 } | |
228 STDMETHODIMP get_locale(IA2Locale* locale) { | |
229 return E_NOTIMPL; | |
230 } | |
231 | |
232 // | |
233 // IAccessibleImage methods. | |
234 // | |
235 | |
236 STDMETHODIMP get_description(BSTR* description); | |
237 | |
238 STDMETHODIMP get_imagePosition(enum IA2CoordinateType coordinate_type, | |
239 long* x, long* y); | |
240 | |
241 STDMETHODIMP get_imageSize(long* height, long* width); | |
242 | |
243 // | |
244 // IAccessibleText methods. | |
245 // | |
246 | |
247 STDMETHODIMP get_nCharacters(long* n_characters); | |
248 | |
249 STDMETHODIMP get_text(long start_offset, long end_offset, BSTR* text); | |
250 | |
251 STDMETHODIMP get_caretOffset(long* offset); | |
252 | |
253 // IAccessibleText methods not implemented. | |
254 STDMETHODIMP addSelection(long start_offset, long end_offset) { | |
255 return E_NOTIMPL; | |
256 } | |
257 STDMETHODIMP get_attributes(long offset, long* start_offset, long* end_offset, | |
258 BSTR* text_attributes) { | |
259 return E_NOTIMPL; | |
260 } | |
261 STDMETHODIMP get_characterExtents(long offset, | |
262 enum IA2CoordinateType coord_type, | |
263 long* x, long* y, | |
264 long* width, long* height) { | |
265 return E_NOTIMPL; | |
266 } | |
267 STDMETHODIMP get_nSelections(long* n_selections) { | |
268 return E_NOTIMPL; | |
269 } | |
270 STDMETHODIMP get_offsetAtPoint(long x, long y, | |
271 enum IA2CoordinateType coord_type, | |
272 long* offset) { | |
273 return E_NOTIMPL; | |
274 } | |
275 STDMETHODIMP get_selection(long selection_index, | |
276 long* start_offset, | |
277 long* end_offset) { | |
278 return E_NOTIMPL; | |
279 } | |
280 STDMETHODIMP get_textBeforeOffset(long offset, | |
281 enum IA2TextBoundaryType boundary_type, | |
282 long* start_offset, long* end_offset, | |
283 BSTR* text) { | |
284 return E_NOTIMPL; | |
285 } | |
286 STDMETHODIMP get_textAfterOffset(long offset, | |
287 enum IA2TextBoundaryType boundary_type, | |
288 long* start_offset, long* end_offset, | |
289 BSTR* text) { | |
290 return E_NOTIMPL; | |
291 } | |
292 STDMETHODIMP get_textAtOffset(long offset, | |
293 enum IA2TextBoundaryType boundary_type, | |
294 long* start_offset, long* end_offset, | |
295 BSTR* text) { | |
296 return E_NOTIMPL; | |
297 } | |
298 STDMETHODIMP removeSelection(long selection_index) { | |
299 return E_NOTIMPL; | |
300 } | |
301 STDMETHODIMP setCaretOffset(long offset) { | |
302 return E_NOTIMPL; | |
303 } | |
304 STDMETHODIMP setSelection(long selection_index, | |
305 long start_offset, | |
306 long end_offset) { | |
307 return E_NOTIMPL; | |
308 } | |
309 STDMETHODIMP scrollSubstringTo(long start_index, | |
310 long end_index, | |
311 enum IA2ScrollType scroll_type) { | |
312 return E_NOTIMPL; | |
313 } | |
314 STDMETHODIMP scrollSubstringToPoint(long start_index, long end_index, | |
315 enum IA2CoordinateType coordinate_type, | |
316 long x, long y) { | |
317 return E_NOTIMPL; | |
318 } | |
319 STDMETHODIMP get_newText(IA2TextSegment* new_text) { | |
320 return E_NOTIMPL; | |
321 } | |
322 STDMETHODIMP get_oldText(IA2TextSegment* old_text) { | |
323 return E_NOTIMPL; | |
324 } | |
325 | |
326 // | |
327 // IServiceProvider methods. | |
328 // | |
329 | |
330 STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void** object); | |
331 | |
332 // | |
333 // CComObjectRootEx methods. | |
334 // | |
335 | |
336 HRESULT WINAPI InternalQueryInterface(void* this_ptr, | |
337 const _ATL_INTMAP_ENTRY* entries, | |
338 REFIID iid, | |
339 void** object); | |
340 | |
341 private: | |
342 // Many MSAA methods take a var_id parameter indicating that the operation | |
343 // should be performed on a particular child ID, rather than this object. | |
344 // This method tries to figure out the target object from |var_id| and | |
345 // returns a pointer to the target object if it exists, otherwise NULL. | |
346 // Does not return a new reference. | |
347 BrowserAccessibility* GetTargetFromChildID(const VARIANT& var_id); | |
348 | |
349 // Initialize the role and state metadata from the role enum and state | |
350 // bitmasks defined in webkit/glue/webaccessibility.h. | |
351 void InitRoleAndState(LONG web_accessibility_role, | |
352 LONG web_accessibility_state); | |
353 | |
354 // Return true if this attribute is in the attributes map. | |
355 bool HasAttribute(WebAccessibility::Attribute attribute); | |
356 | |
357 // Retrieve the string value of an attribute from the attribute map and | |
358 // returns true if found. | |
359 bool GetAttribute(WebAccessibility::Attribute attribute, string16* value); | |
360 | |
361 // The manager of this tree of accessibility objects; needed for | |
362 // global operations like focus tracking. | |
363 BrowserAccessibilityManager* manager_; | |
364 // The parent of this object, may be NULL if we're the root object. | |
365 BrowserAccessibility* parent_; | |
366 // The ID of this object; globally unique within the browser process. | |
367 LONG child_id_; | |
368 // The index of this within its parent object. | |
369 LONG index_in_parent_; | |
370 // The ID of this object in the renderer process. | |
371 int32 renderer_id_; | |
372 | |
373 // The children of this object. | |
374 std::vector<BrowserAccessibility*> children_; | |
375 | |
376 // Accessibility metadata from the renderer, used to respond to MSAA | |
377 // events. | |
378 string16 name_; | |
379 string16 value_; | |
380 std::map<int32, string16> attributes_; | |
381 | |
382 LONG role_; | |
383 LONG state_; | |
384 string16 role_name_; | |
385 LONG ia2_role_; | |
386 LONG ia2_state_; | |
387 WebKit::WebRect location_; | |
388 | |
389 // COM objects are reference-counted. When we're done with this object | |
390 // and it's removed from our accessibility tree, a client may still be | |
391 // holding onto a pointer to this object, so we mark it as inactive | |
392 // so that calls to any of this object's methods immediately return | |
393 // failure. | |
394 bool instance_active_; | |
395 | |
396 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); | |
397 }; | |
398 | |
399 #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ | |
OLD | NEW |