OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 5 #ifndef CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 6 #define CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
10 #include <oleacc.h> | |
11 #include <stddef.h> | |
12 #include <stdint.h> | |
13 #include <UIAutomationCore.h> | |
14 | 10 |
15 #include <vector> | |
16 | |
17 #include "base/compiler_specific.h" | |
18 #include "base/gtest_prod_util.h" | |
19 #include "base/macros.h" | |
20 #include "content/browser/accessibility/browser_accessibility.h" | 11 #include "content/browser/accessibility/browser_accessibility.h" |
| 12 #include "content/browser/accessibility/browser_accessibility_com_win.h" |
21 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
22 #include "third_party/iaccessible2/ia2_api_all.h" | |
23 #include "third_party/isimpledom/ISimpleDOMDocument.h" | |
24 #include "third_party/isimpledom/ISimpleDOMNode.h" | |
25 #include "third_party/isimpledom/ISimpleDOMText.h" | |
26 #include "ui/accessibility/platform/ax_platform_node_win.h" | |
27 | 14 |
28 namespace content { | 15 namespace content { |
29 class BrowserAccessibilityRelation; | |
30 | 16 |
31 //////////////////////////////////////////////////////////////////////////////// | 17 class CONTENT_EXPORT BrowserAccessibilityWin : public BrowserAccessibility { |
32 // | |
33 // BrowserAccessibilityWin | |
34 // | |
35 // Class implementing the windows accessible interface for the Browser-Renderer | |
36 // communication of accessibility information, providing accessibility | |
37 // to be used by screen readers and other assistive technology (AT). | |
38 // | |
39 //////////////////////////////////////////////////////////////////////////////// | |
40 class __declspec(uuid("562072fe-3390-43b1-9e2c-dd4118f5ac79")) | |
41 BrowserAccessibilityWin | |
42 : public BrowserAccessibility, | |
43 public CComObjectRootEx<CComMultiThreadModel>, | |
44 public IDispatchImpl<IAccessible2, &IID_IAccessible2, | |
45 &LIBID_IAccessible2Lib>, | |
46 public IAccessibleApplication, | |
47 public IAccessibleHyperlink, | |
48 public IAccessibleHypertext, | |
49 public IAccessibleImage, | |
50 public IAccessibleTable, | |
51 public IAccessibleTable2, | |
52 public IAccessibleTableCell, | |
53 public IAccessibleValue, | |
54 public IServiceProvider, | |
55 public ISimpleDOMDocument, | |
56 public ISimpleDOMNode, | |
57 public ISimpleDOMText, | |
58 public IAccessibleEx, | |
59 public IRawElementProviderSimple { | |
60 public: | 18 public: |
61 BEGIN_COM_MAP(BrowserAccessibilityWin) | 19 BrowserAccessibilityWin(); |
62 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2) | 20 ~BrowserAccessibilityWin() override; |
63 COM_INTERFACE_ENTRY(IAccessible) | |
64 COM_INTERFACE_ENTRY(IAccessible2) | |
65 COM_INTERFACE_ENTRY(IAccessibleAction) | |
66 COM_INTERFACE_ENTRY(IAccessibleApplication) | |
67 COM_INTERFACE_ENTRY(IAccessibleEx) | |
68 COM_INTERFACE_ENTRY(IAccessibleHyperlink) | |
69 COM_INTERFACE_ENTRY(IAccessibleHypertext) | |
70 COM_INTERFACE_ENTRY(IAccessibleImage) | |
71 COM_INTERFACE_ENTRY(IAccessibleTable) | |
72 COM_INTERFACE_ENTRY(IAccessibleTable2) | |
73 COM_INTERFACE_ENTRY(IAccessibleTableCell) | |
74 COM_INTERFACE_ENTRY(IAccessibleText) | |
75 COM_INTERFACE_ENTRY(IAccessibleValue) | |
76 COM_INTERFACE_ENTRY(IRawElementProviderSimple) | |
77 COM_INTERFACE_ENTRY(IServiceProvider) | |
78 COM_INTERFACE_ENTRY(ISimpleDOMDocument) | |
79 COM_INTERFACE_ENTRY(ISimpleDOMNode) | |
80 COM_INTERFACE_ENTRY(ISimpleDOMText) | |
81 END_COM_MAP() | |
82 | |
83 // Represents a non-static text node in IAccessibleHypertext. This character | |
84 // is embedded in the response to IAccessibleText::get_text, indicating the | |
85 // position where a non-static text child object appears. | |
86 CONTENT_EXPORT static const base::char16 kEmbeddedCharacter; | |
87 | |
88 // Mappings from roles and states to human readable strings. Initialize | |
89 // with |InitializeStringMaps|. | |
90 static std::map<int32_t, base::string16> role_string_map; | |
91 static std::map<int32_t, base::string16> state_string_map; | |
92 | |
93 CONTENT_EXPORT BrowserAccessibilityWin(); | |
94 | |
95 CONTENT_EXPORT ~BrowserAccessibilityWin() override; | |
96 | |
97 // Called after an atomic tree update completes. See | |
98 // BrowserAccessibilityManagerWin::OnAtomicUpdateFinished for more | |
99 // details on what these do. | |
100 CONTENT_EXPORT void UpdateStep1ComputeWinAttributes(); | |
101 CONTENT_EXPORT void UpdateStep2ComputeHypertext(); | |
102 CONTENT_EXPORT void UpdateStep3FireEvents(bool is_subtree_creation); | |
103 | 21 |
104 // This is used to call UpdateStep1ComputeWinAttributes, ... above when | 22 // This is used to call UpdateStep1ComputeWinAttributes, ... above when |
105 // a node needs to be updated for some other reason other than via | 23 // a node needs to be updated for some other reason other than via |
106 // OnAtomicUpdateFinished. | 24 // OnAtomicUpdateFinished. |
107 CONTENT_EXPORT void UpdatePlatformAttributes() override; | 25 void UpdatePlatformAttributes() override; |
108 | 26 |
109 // | 27 // |
110 // BrowserAccessibility methods. | 28 // BrowserAccessibility methods. |
111 // | 29 // |
112 CONTENT_EXPORT void OnSubtreeWillBeDeleted() override; | 30 void OnSubtreeWillBeDeleted() override; |
113 CONTENT_EXPORT void NativeAddReference() override; | 31 bool IsNative() const override; |
114 CONTENT_EXPORT void NativeReleaseReference() override; | 32 void Destroy() override; |
115 CONTENT_EXPORT bool IsNative() const override; | 33 void OnLocationChanged() override; |
116 CONTENT_EXPORT void OnLocationChanged() override; | 34 base::string16 GetText() const override; |
117 | 35 |
118 // | 36 class BrowserAccessibilityComWin* GetCOM() const; |
119 // IAccessible methods. | |
120 // | |
121 | |
122 // Performs the default action on a given object. | |
123 CONTENT_EXPORT STDMETHODIMP accDoDefaultAction(VARIANT var_id) override; | |
124 | |
125 // Retrieves the child element or child object at a given point on the screen. | |
126 CONTENT_EXPORT STDMETHODIMP | |
127 accHitTest(LONG x_left, LONG y_top, VARIANT* child) override; | |
128 | |
129 // Retrieves the specified object's current screen location. | |
130 CONTENT_EXPORT STDMETHODIMP accLocation(LONG* x_left, | |
131 LONG* y_top, | |
132 LONG* width, | |
133 LONG* height, | |
134 VARIANT var_id) override; | |
135 | |
136 // Traverses to another UI element and retrieves the object. | |
137 CONTENT_EXPORT STDMETHODIMP | |
138 accNavigate(LONG nav_dir, VARIANT start, VARIANT* end) override; | |
139 | |
140 // Retrieves an IDispatch interface pointer for the specified child. | |
141 CONTENT_EXPORT STDMETHODIMP | |
142 get_accChild(VARIANT var_child, IDispatch** disp_child) override; | |
143 | |
144 // Retrieves the number of accessible children. | |
145 CONTENT_EXPORT STDMETHODIMP get_accChildCount(LONG* child_count) override; | |
146 | |
147 // Retrieves a string that describes the object's default action. | |
148 CONTENT_EXPORT STDMETHODIMP | |
149 get_accDefaultAction(VARIANT var_id, BSTR* default_action) override; | |
150 | |
151 // Retrieves the object's description. | |
152 CONTENT_EXPORT STDMETHODIMP | |
153 get_accDescription(VARIANT var_id, BSTR* desc) override; | |
154 | |
155 // Retrieves the object that has the keyboard focus. | |
156 CONTENT_EXPORT STDMETHODIMP get_accFocus(VARIANT* focus_child) override; | |
157 | |
158 // Retrieves the help information associated with the object. | |
159 CONTENT_EXPORT STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* heflp) override; | |
160 | |
161 // Retrieves the specified object's shortcut. | |
162 CONTENT_EXPORT STDMETHODIMP | |
163 get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key) override; | |
164 | |
165 // Retrieves the name of the specified object. | |
166 CONTENT_EXPORT STDMETHODIMP get_accName(VARIANT var_id, BSTR* name) override; | |
167 | |
168 // Retrieves the IDispatch interface of the object's parent. | |
169 CONTENT_EXPORT STDMETHODIMP get_accParent(IDispatch** disp_parent) override; | |
170 | |
171 // Retrieves information describing the role of the specified object. | |
172 CONTENT_EXPORT STDMETHODIMP | |
173 get_accRole(VARIANT var_id, VARIANT* role) override; | |
174 | |
175 // Retrieves the current state of the specified object. | |
176 CONTENT_EXPORT STDMETHODIMP | |
177 get_accState(VARIANT var_id, VARIANT* state) override; | |
178 | |
179 // Returns the value associated with the object. | |
180 CONTENT_EXPORT STDMETHODIMP | |
181 get_accValue(VARIANT var_id, BSTR* value) override; | |
182 | |
183 // Make an object take focus or extend the selection. | |
184 CONTENT_EXPORT STDMETHODIMP | |
185 accSelect(LONG flags_sel, VARIANT var_id) override; | |
186 | |
187 CONTENT_EXPORT STDMETHODIMP | |
188 get_accHelpTopic(BSTR* help_file, VARIANT var_id, LONG* topic_id) override; | |
189 | |
190 CONTENT_EXPORT STDMETHODIMP get_accSelection(VARIANT* selected) override; | |
191 | |
192 // Deprecated methods, not implemented. | |
193 CONTENT_EXPORT STDMETHODIMP | |
194 put_accName(VARIANT var_id, BSTR put_name) override; | |
195 CONTENT_EXPORT STDMETHODIMP | |
196 put_accValue(VARIANT var_id, BSTR put_val) override; | |
197 | |
198 // | |
199 // IAccessible2 methods. | |
200 // | |
201 | |
202 // Returns role from a longer list of possible roles. | |
203 CONTENT_EXPORT STDMETHODIMP role(LONG* role) override; | |
204 | |
205 // Returns the state bitmask from a larger set of possible states. | |
206 CONTENT_EXPORT STDMETHODIMP get_states(AccessibleStates* states) override; | |
207 | |
208 // Returns the attributes specific to this IAccessible2 object, | |
209 // such as a cell's formula. | |
210 CONTENT_EXPORT STDMETHODIMP get_attributes(BSTR* attributes) override; | |
211 | |
212 // Get the unique ID of this object so that the client knows if it's | |
213 // been encountered previously. | |
214 CONTENT_EXPORT STDMETHODIMP get_uniqueID(LONG* unique_id) override; | |
215 | |
216 // Get the window handle of the enclosing window. | |
217 CONTENT_EXPORT STDMETHODIMP get_windowHandle(HWND* window_handle) override; | |
218 | |
219 // Get this object's index in its parent object. | |
220 CONTENT_EXPORT STDMETHODIMP get_indexInParent(LONG* index_in_parent) override; | |
221 | |
222 CONTENT_EXPORT STDMETHODIMP get_nRelations(LONG* n_relations) override; | |
223 | |
224 CONTENT_EXPORT STDMETHODIMP | |
225 get_relation(LONG relation_index, IAccessibleRelation** relation) override; | |
226 | |
227 CONTENT_EXPORT STDMETHODIMP get_relations(LONG max_relations, | |
228 IAccessibleRelation** relations, | |
229 LONG* n_relations) override; | |
230 | |
231 CONTENT_EXPORT STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) override; | |
232 | |
233 CONTENT_EXPORT STDMETHODIMP | |
234 scrollToPoint(enum IA2CoordinateType coordinate_type, | |
235 LONG x, | |
236 LONG y) override; | |
237 | |
238 CONTENT_EXPORT STDMETHODIMP | |
239 get_groupPosition(LONG* group_level, | |
240 LONG* similar_items_in_group, | |
241 LONG* position_in_group) override; | |
242 | |
243 CONTENT_EXPORT STDMETHODIMP | |
244 get_localizedExtendedRole(BSTR* localized_extended_role) override; | |
245 | |
246 // | |
247 // IAccessible2 methods not implemented. | |
248 // | |
249 CONTENT_EXPORT STDMETHODIMP get_extendedRole(BSTR* extended_role) override; | |
250 CONTENT_EXPORT STDMETHODIMP | |
251 get_nExtendedStates(LONG* n_extended_states) override; | |
252 CONTENT_EXPORT STDMETHODIMP | |
253 get_extendedStates(LONG max_extended_states, | |
254 BSTR** extended_states, | |
255 LONG* n_extended_states) override; | |
256 CONTENT_EXPORT STDMETHODIMP | |
257 get_localizedExtendedStates(LONG max_localized_extended_states, | |
258 BSTR** localized_extended_states, | |
259 LONG* n_localized_extended_states) override; | |
260 CONTENT_EXPORT STDMETHODIMP get_locale(IA2Locale* locale) override; | |
261 | |
262 // | |
263 // IAccessibleApplication methods. | |
264 // | |
265 CONTENT_EXPORT STDMETHODIMP get_appName(BSTR* app_name) override; | |
266 | |
267 CONTENT_EXPORT STDMETHODIMP get_appVersion(BSTR* app_version) override; | |
268 | |
269 CONTENT_EXPORT STDMETHODIMP get_toolkitName(BSTR* toolkit_name) override; | |
270 | |
271 CONTENT_EXPORT STDMETHODIMP | |
272 get_toolkitVersion(BSTR* toolkit_version) override; | |
273 | |
274 // | |
275 // IAccessibleImage methods. | |
276 // | |
277 CONTENT_EXPORT STDMETHODIMP get_description(BSTR* description) override; | |
278 | |
279 CONTENT_EXPORT STDMETHODIMP | |
280 get_imagePosition(enum IA2CoordinateType coordinate_type, | |
281 LONG* x, | |
282 LONG* y) override; | |
283 | |
284 CONTENT_EXPORT STDMETHODIMP get_imageSize(LONG* height, LONG* width) override; | |
285 | |
286 // | |
287 // IAccessibleTable methods. | |
288 // | |
289 | |
290 // get_description - also used by IAccessibleImage | |
291 | |
292 CONTENT_EXPORT STDMETHODIMP | |
293 get_accessibleAt(long row, long column, IUnknown** accessible) override; | |
294 | |
295 CONTENT_EXPORT STDMETHODIMP get_caption(IUnknown** accessible) override; | |
296 | |
297 CONTENT_EXPORT STDMETHODIMP | |
298 get_childIndex(long row_index, long column_index, long* cell_index) override; | |
299 | |
300 CONTENT_EXPORT STDMETHODIMP | |
301 get_columnDescription(long column, BSTR* description) override; | |
302 | |
303 CONTENT_EXPORT STDMETHODIMP | |
304 get_columnExtentAt(long row, long column, long* n_columns_spanned) override; | |
305 | |
306 CONTENT_EXPORT STDMETHODIMP | |
307 get_columnHeader(IAccessibleTable** accessible_table, | |
308 long* starting_row_index) override; | |
309 | |
310 CONTENT_EXPORT STDMETHODIMP | |
311 get_columnIndex(long cell_index, long* column_index) override; | |
312 | |
313 CONTENT_EXPORT STDMETHODIMP get_nColumns(long* column_count) override; | |
314 | |
315 CONTENT_EXPORT STDMETHODIMP get_nRows(long* row_count) override; | |
316 | |
317 CONTENT_EXPORT STDMETHODIMP get_nSelectedChildren(long* cell_count) override; | |
318 | |
319 CONTENT_EXPORT STDMETHODIMP get_nSelectedColumns(long* column_count) override; | |
320 | |
321 CONTENT_EXPORT STDMETHODIMP get_nSelectedRows(long* row_count) override; | |
322 | |
323 CONTENT_EXPORT STDMETHODIMP | |
324 get_rowDescription(long row, BSTR* description) override; | |
325 | |
326 CONTENT_EXPORT STDMETHODIMP | |
327 get_rowExtentAt(long row, long column, long* n_rows_spanned) override; | |
328 | |
329 CONTENT_EXPORT STDMETHODIMP | |
330 get_rowHeader(IAccessibleTable** accessible_table, | |
331 long* starting_column_index) override; | |
332 | |
333 CONTENT_EXPORT STDMETHODIMP | |
334 get_rowIndex(long cell_index, long* row_index) override; | |
335 | |
336 CONTENT_EXPORT STDMETHODIMP get_selectedChildren(long max_children, | |
337 long** children, | |
338 long* n_children) override; | |
339 | |
340 CONTENT_EXPORT STDMETHODIMP get_selectedColumns(long max_columns, | |
341 long** columns, | |
342 long* n_columns) override; | |
343 | |
344 CONTENT_EXPORT STDMETHODIMP | |
345 get_selectedRows(long max_rows, long** rows, long* n_rows) override; | |
346 | |
347 CONTENT_EXPORT STDMETHODIMP get_summary(IUnknown** accessible) override; | |
348 | |
349 CONTENT_EXPORT STDMETHODIMP | |
350 get_isColumnSelected(long column, boolean* is_selected) override; | |
351 | |
352 CONTENT_EXPORT STDMETHODIMP | |
353 get_isRowSelected(long row, boolean* is_selected) override; | |
354 | |
355 CONTENT_EXPORT STDMETHODIMP | |
356 get_isSelected(long row, long column, boolean* is_selected) override; | |
357 | |
358 CONTENT_EXPORT STDMETHODIMP | |
359 get_rowColumnExtentsAtIndex(long index, | |
360 long* row, | |
361 long* column, | |
362 long* row_extents, | |
363 long* column_extents, | |
364 boolean* is_selected) override; | |
365 | |
366 CONTENT_EXPORT STDMETHODIMP selectRow(long row) override; | |
367 | |
368 CONTENT_EXPORT STDMETHODIMP selectColumn(long column) override; | |
369 | |
370 CONTENT_EXPORT STDMETHODIMP unselectRow(long row) override; | |
371 | |
372 CONTENT_EXPORT STDMETHODIMP unselectColumn(long column) override; | |
373 | |
374 CONTENT_EXPORT STDMETHODIMP | |
375 get_modelChange(IA2TableModelChange* model_change) override; | |
376 | |
377 // | |
378 // IAccessibleTable2 methods. | |
379 // | |
380 // (Most of these are duplicates of IAccessibleTable methods, only the | |
381 // unique ones are included here.) | |
382 // | |
383 | |
384 CONTENT_EXPORT STDMETHODIMP | |
385 get_cellAt(long row, long column, IUnknown** cell) override; | |
386 | |
387 CONTENT_EXPORT STDMETHODIMP get_nSelectedCells(long* cell_count) override; | |
388 | |
389 CONTENT_EXPORT STDMETHODIMP | |
390 get_selectedCells(IUnknown*** cells, long* n_selected_cells) override; | |
391 | |
392 CONTENT_EXPORT STDMETHODIMP | |
393 get_selectedColumns(long** columns, long* n_columns) override; | |
394 | |
395 CONTENT_EXPORT STDMETHODIMP | |
396 get_selectedRows(long** rows, long* n_rows) override; | |
397 | |
398 // | |
399 // IAccessibleTableCell methods. | |
400 // | |
401 | |
402 CONTENT_EXPORT STDMETHODIMP | |
403 get_columnExtent(long* n_columns_spanned) override; | |
404 | |
405 CONTENT_EXPORT STDMETHODIMP | |
406 get_columnHeaderCells(IUnknown*** cell_accessibles, | |
407 long* n_column_header_cells) override; | |
408 | |
409 CONTENT_EXPORT STDMETHODIMP get_columnIndex(long* column_index) override; | |
410 | |
411 CONTENT_EXPORT STDMETHODIMP get_rowExtent(long* n_rows_spanned) override; | |
412 | |
413 CONTENT_EXPORT STDMETHODIMP | |
414 get_rowHeaderCells(IUnknown*** cell_accessibles, | |
415 long* n_row_header_cells) override; | |
416 | |
417 CONTENT_EXPORT STDMETHODIMP get_rowIndex(long* row_index) override; | |
418 | |
419 CONTENT_EXPORT STDMETHODIMP get_isSelected(boolean* is_selected) override; | |
420 | |
421 CONTENT_EXPORT STDMETHODIMP | |
422 get_rowColumnExtents(long* row, | |
423 long* column, | |
424 long* row_extents, | |
425 long* column_extents, | |
426 boolean* is_selected) override; | |
427 | |
428 CONTENT_EXPORT STDMETHODIMP get_table(IUnknown** table) override; | |
429 | |
430 // | |
431 // IAccessibleText methods. | |
432 // | |
433 | |
434 CONTENT_EXPORT STDMETHODIMP get_nCharacters(LONG* n_characters) override; | |
435 | |
436 CONTENT_EXPORT STDMETHODIMP get_caretOffset(LONG* offset) override; | |
437 | |
438 CONTENT_EXPORT STDMETHODIMP | |
439 get_characterExtents(LONG offset, | |
440 enum IA2CoordinateType coord_type, | |
441 LONG* out_x, | |
442 LONG* out_y, | |
443 LONG* out_width, | |
444 LONG* out_height) override; | |
445 | |
446 CONTENT_EXPORT STDMETHODIMP get_nSelections(LONG* n_selections) override; | |
447 | |
448 CONTENT_EXPORT STDMETHODIMP get_selection(LONG selection_index, | |
449 LONG* start_offset, | |
450 LONG* end_offset) override; | |
451 | |
452 CONTENT_EXPORT STDMETHODIMP | |
453 get_text(LONG start_offset, LONG end_offset, BSTR* text) override; | |
454 | |
455 CONTENT_EXPORT STDMETHODIMP | |
456 get_textAtOffset(LONG offset, | |
457 enum IA2TextBoundaryType boundary_type, | |
458 LONG* start_offset, | |
459 LONG* end_offset, | |
460 BSTR* text) override; | |
461 | |
462 CONTENT_EXPORT STDMETHODIMP | |
463 get_textBeforeOffset(LONG offset, | |
464 enum IA2TextBoundaryType boundary_type, | |
465 LONG* start_offset, | |
466 LONG* end_offset, | |
467 BSTR* text) override; | |
468 | |
469 CONTENT_EXPORT STDMETHODIMP | |
470 get_textAfterOffset(LONG offset, | |
471 enum IA2TextBoundaryType boundary_type, | |
472 LONG* start_offset, | |
473 LONG* end_offset, | |
474 BSTR* text) override; | |
475 | |
476 CONTENT_EXPORT STDMETHODIMP get_newText(IA2TextSegment* new_text) override; | |
477 | |
478 CONTENT_EXPORT STDMETHODIMP get_oldText(IA2TextSegment* old_text) override; | |
479 | |
480 CONTENT_EXPORT STDMETHODIMP | |
481 get_offsetAtPoint(LONG x, | |
482 LONG y, | |
483 enum IA2CoordinateType coord_type, | |
484 LONG* offset) override; | |
485 | |
486 CONTENT_EXPORT STDMETHODIMP | |
487 scrollSubstringTo(LONG start_index, | |
488 LONG end_index, | |
489 enum IA2ScrollType scroll_type) override; | |
490 | |
491 CONTENT_EXPORT STDMETHODIMP | |
492 scrollSubstringToPoint(LONG start_index, | |
493 LONG end_index, | |
494 enum IA2CoordinateType coordinate_type, | |
495 LONG x, | |
496 LONG y) override; | |
497 | |
498 CONTENT_EXPORT STDMETHODIMP | |
499 addSelection(LONG start_offset, LONG end_offset) override; | |
500 | |
501 CONTENT_EXPORT STDMETHODIMP removeSelection(LONG selection_index) override; | |
502 | |
503 CONTENT_EXPORT STDMETHODIMP setCaretOffset(LONG offset) override; | |
504 | |
505 CONTENT_EXPORT STDMETHODIMP setSelection(LONG selection_index, | |
506 LONG start_offset, | |
507 LONG end_offset) override; | |
508 | |
509 // IAccessibleText methods not implemented. | |
510 CONTENT_EXPORT STDMETHODIMP get_attributes(LONG offset, | |
511 LONG* start_offset, | |
512 LONG* end_offset, | |
513 BSTR* text_attributes) override; | |
514 | |
515 // | |
516 // IAccessibleHypertext methods. | |
517 // | |
518 | |
519 CONTENT_EXPORT STDMETHODIMP get_nHyperlinks(long* hyperlink_count) override; | |
520 | |
521 CONTENT_EXPORT STDMETHODIMP | |
522 get_hyperlink(long index, IAccessibleHyperlink** hyperlink) override; | |
523 | |
524 CONTENT_EXPORT STDMETHODIMP | |
525 get_hyperlinkIndex(long char_index, long* hyperlink_index) override; | |
526 | |
527 // IAccessibleHyperlink methods. | |
528 CONTENT_EXPORT STDMETHODIMP get_anchor(long index, VARIANT* anchor) override; | |
529 CONTENT_EXPORT STDMETHODIMP get_anchorTarget(long index, | |
530 VARIANT* anchor_target) override; | |
531 CONTENT_EXPORT STDMETHODIMP get_startIndex(long* index) override; | |
532 CONTENT_EXPORT STDMETHODIMP get_endIndex(long* index) override; | |
533 // This method is deprecated in the IA2 Spec and so we don't implement it. | |
534 CONTENT_EXPORT STDMETHODIMP get_valid(boolean* valid) override; | |
535 | |
536 // IAccessibleAction mostly not implemented. | |
537 CONTENT_EXPORT STDMETHODIMP nActions(long* n_actions) override; | |
538 CONTENT_EXPORT STDMETHODIMP doAction(long action_index) override; | |
539 CONTENT_EXPORT STDMETHODIMP | |
540 get_description(long action_index, BSTR* description) override; | |
541 CONTENT_EXPORT STDMETHODIMP get_keyBinding(long action_index, | |
542 long n_max_bindings, | |
543 BSTR** key_bindings, | |
544 long* n_bindings) override; | |
545 CONTENT_EXPORT STDMETHODIMP get_name(long action_index, BSTR* name) override; | |
546 CONTENT_EXPORT STDMETHODIMP | |
547 get_localizedName(long action_index, BSTR* localized_name) override; | |
548 | |
549 // | |
550 // IAccessibleValue methods. | |
551 // | |
552 | |
553 CONTENT_EXPORT STDMETHODIMP get_currentValue(VARIANT* value) override; | |
554 | |
555 CONTENT_EXPORT STDMETHODIMP get_minimumValue(VARIANT* value) override; | |
556 | |
557 CONTENT_EXPORT STDMETHODIMP get_maximumValue(VARIANT* value) override; | |
558 | |
559 CONTENT_EXPORT STDMETHODIMP setCurrentValue(VARIANT new_value) override; | |
560 | |
561 // | |
562 // ISimpleDOMDocument methods. | |
563 // | |
564 | |
565 CONTENT_EXPORT STDMETHODIMP get_URL(BSTR* url) override; | |
566 | |
567 CONTENT_EXPORT STDMETHODIMP get_title(BSTR* title) override; | |
568 | |
569 CONTENT_EXPORT STDMETHODIMP get_mimeType(BSTR* mime_type) override; | |
570 | |
571 CONTENT_EXPORT STDMETHODIMP get_docType(BSTR* doc_type) override; | |
572 | |
573 CONTENT_EXPORT STDMETHODIMP | |
574 get_nameSpaceURIForID(short name_space_id, BSTR* name_space_uri) override; | |
575 CONTENT_EXPORT STDMETHODIMP | |
576 put_alternateViewMediaTypes(BSTR* comma_separated_media_types) override; | |
577 | |
578 // | |
579 // ISimpleDOMNode methods. | |
580 // | |
581 | |
582 CONTENT_EXPORT STDMETHODIMP get_nodeInfo(BSTR* node_name, | |
583 short* name_space_id, | |
584 BSTR* node_value, | |
585 unsigned int* num_children, | |
586 unsigned int* unique_id, | |
587 unsigned short* node_type) override; | |
588 | |
589 CONTENT_EXPORT STDMETHODIMP | |
590 get_attributes(unsigned short max_attribs, | |
591 BSTR* attrib_names, | |
592 short* name_space_id, | |
593 BSTR* attrib_values, | |
594 unsigned short* num_attribs) override; | |
595 | |
596 CONTENT_EXPORT STDMETHODIMP | |
597 get_attributesForNames(unsigned short num_attribs, | |
598 BSTR* attrib_names, | |
599 short* name_space_id, | |
600 BSTR* attrib_values) override; | |
601 | |
602 CONTENT_EXPORT STDMETHODIMP | |
603 get_computedStyle(unsigned short max_style_properties, | |
604 boolean use_alternate_view, | |
605 BSTR* style_properties, | |
606 BSTR* style_values, | |
607 unsigned short* num_style_properties) override; | |
608 | |
609 CONTENT_EXPORT STDMETHODIMP | |
610 get_computedStyleForProperties(unsigned short num_style_properties, | |
611 boolean use_alternate_view, | |
612 BSTR* style_properties, | |
613 BSTR* style_values) override; | |
614 | |
615 CONTENT_EXPORT STDMETHODIMP scrollTo(boolean placeTopLeft) override; | |
616 | |
617 CONTENT_EXPORT STDMETHODIMP get_parentNode(ISimpleDOMNode** node) override; | |
618 | |
619 CONTENT_EXPORT STDMETHODIMP get_firstChild(ISimpleDOMNode** node) override; | |
620 | |
621 CONTENT_EXPORT STDMETHODIMP get_lastChild(ISimpleDOMNode** node) override; | |
622 | |
623 CONTENT_EXPORT STDMETHODIMP | |
624 get_previousSibling(ISimpleDOMNode** node) override; | |
625 | |
626 CONTENT_EXPORT STDMETHODIMP get_nextSibling(ISimpleDOMNode** node) override; | |
627 | |
628 CONTENT_EXPORT STDMETHODIMP | |
629 get_childAt(unsigned int child_index, ISimpleDOMNode** node) override; | |
630 | |
631 CONTENT_EXPORT STDMETHODIMP get_innerHTML(BSTR* innerHTML) override; | |
632 | |
633 CONTENT_EXPORT STDMETHODIMP | |
634 get_localInterface(void** local_interface) override; | |
635 | |
636 CONTENT_EXPORT STDMETHODIMP get_language(BSTR* language) override; | |
637 | |
638 // | |
639 // ISimpleDOMText methods. | |
640 // | |
641 | |
642 CONTENT_EXPORT STDMETHODIMP get_domText(BSTR* dom_text) override; | |
643 | |
644 CONTENT_EXPORT STDMETHODIMP | |
645 get_clippedSubstringBounds(unsigned int start_index, | |
646 unsigned int end_index, | |
647 int* out_x, | |
648 int* out_y, | |
649 int* out_width, | |
650 int* out_height) override; | |
651 | |
652 CONTENT_EXPORT STDMETHODIMP | |
653 get_unclippedSubstringBounds(unsigned int start_index, | |
654 unsigned int end_index, | |
655 int* out_x, | |
656 int* out_y, | |
657 int* out_width, | |
658 int* out_height) override; | |
659 | |
660 CONTENT_EXPORT STDMETHODIMP | |
661 scrollToSubstring(unsigned int start_index, unsigned int end_index) override; | |
662 | |
663 CONTENT_EXPORT STDMETHODIMP get_fontFamily(BSTR* font_family) override; | |
664 | |
665 // | |
666 // IServiceProvider methods. | |
667 // | |
668 | |
669 CONTENT_EXPORT STDMETHODIMP | |
670 QueryService(REFGUID guidService, REFIID riid, void** object) override; | |
671 | |
672 // IAccessibleEx methods not implemented. | |
673 CONTENT_EXPORT STDMETHODIMP | |
674 GetObjectForChild(long child_id, IAccessibleEx** ret) override; | |
675 | |
676 CONTENT_EXPORT STDMETHODIMP | |
677 GetIAccessiblePair(IAccessible** acc, long* child_id) override; | |
678 | |
679 CONTENT_EXPORT STDMETHODIMP GetRuntimeId(SAFEARRAY** runtime_id) override; | |
680 | |
681 CONTENT_EXPORT STDMETHODIMP | |
682 ConvertReturnedElement(IRawElementProviderSimple* element, | |
683 IAccessibleEx** acc) override; | |
684 | |
685 // | |
686 // IRawElementProviderSimple methods. | |
687 // | |
688 // The GetPatternProvider/GetPropertyValue methods need to be implemented for | |
689 // the on-screen keyboard to show up in Windows 8 metro. | |
690 CONTENT_EXPORT STDMETHODIMP | |
691 GetPatternProvider(PATTERNID id, IUnknown** provider) override; | |
692 CONTENT_EXPORT STDMETHODIMP | |
693 GetPropertyValue(PROPERTYID id, VARIANT* ret) override; | |
694 | |
695 // | |
696 // IRawElementProviderSimple methods not implemented | |
697 // | |
698 CONTENT_EXPORT STDMETHODIMP | |
699 get_ProviderOptions(enum ProviderOptions* ret) override; | |
700 CONTENT_EXPORT STDMETHODIMP | |
701 get_HostRawElementProvider(IRawElementProviderSimple** provider) override; | |
702 | |
703 // | |
704 // CComObjectRootEx methods. | |
705 // | |
706 | |
707 // Called by BEGIN_COM_MAP() / END_COM_MAP(). | |
708 static CONTENT_EXPORT HRESULT WINAPI | |
709 InternalQueryInterface(void* this_ptr, | |
710 const _ATL_INTMAP_ENTRY* entries, | |
711 REFIID iid, | |
712 void** object); | |
713 | |
714 // Computes and caches the IA2 text style attributes for the text and other | |
715 // embedded child objects. | |
716 CONTENT_EXPORT void ComputeStylesIfNeeded(); | |
717 | |
718 // |offset| could either be a text character or a child index in case of | |
719 // non-text objects. | |
720 AXPlatformPosition::AXPositionInstance CreatePositionForSelectionAt( | |
721 int offset) const; | |
722 | |
723 CONTENT_EXPORT base::string16 GetText() const override; | |
724 | |
725 // Accessors. | |
726 int32_t ia_role() const { return win_attributes_->ia_role; } | |
727 int32_t ia_state() const { return win_attributes_->ia_state; } | |
728 const base::string16& role_name() const { return win_attributes_->role_name; } | |
729 int32_t ia2_role() const { return win_attributes_->ia2_role; } | |
730 int32_t ia2_state() const { return win_attributes_->ia2_state; } | |
731 const std::vector<base::string16>& ia2_attributes() const { | |
732 return win_attributes_->ia2_attributes; | |
733 } | |
734 base::string16 name() const { return win_attributes_->name; } | |
735 base::string16 description() const { return win_attributes_->description; } | |
736 base::string16 value() const { return win_attributes_->value; } | |
737 const std::map<int, std::vector<base::string16>>& offset_to_text_attributes() | |
738 const { | |
739 return win_attributes_->offset_to_text_attributes; | |
740 } | |
741 std::map<int32_t, int32_t>& hyperlink_offset_to_index() const { | |
742 return win_attributes_->hyperlink_offset_to_index; | |
743 } | |
744 std::vector<int32_t>& hyperlinks() const { | |
745 return win_attributes_->hyperlinks; | |
746 } | |
747 | 37 |
748 private: | 38 private: |
749 // Returns the IA2 text attributes for this object. | 39 CComObject<BrowserAccessibilityComWin>* browser_accessibility_com_; |
750 std::vector<base::string16> ComputeTextAttributes() const; | |
751 | |
752 // Add one to the reference count and return the same object. Always | |
753 // use this method when returning a BrowserAccessibilityWin object as | |
754 // an output parameter to a COM interface, never use it otherwise. | |
755 BrowserAccessibilityWin* NewReference(); | |
756 | |
757 // Returns a list of IA2 attributes indicating the offsets in the text of a | |
758 // leaf object, such as a text field or static text, where spelling errors are | |
759 // present. | |
760 std::map<int, std::vector<base::string16>> GetSpellingAttributes() const; | |
761 | |
762 // Many MSAA methods take a var_id parameter indicating that the operation | |
763 // should be performed on a particular child ID, rather than this object. | |
764 // This method tries to figure out the target object from |var_id| and | |
765 // returns a pointer to the target object if it exists, otherwise NULL. | |
766 // Does not return a new reference. | |
767 BrowserAccessibilityWin* GetTargetFromChildID(const VARIANT& var_id); | |
768 | |
769 // Initialize the role and state metadata from the role enum and state | |
770 // bitmasks defined in ui::AXNodeData. | |
771 void InitRoleAndState(); | |
772 | |
773 // Retrieve the value of an attribute from the string attribute map and | |
774 // if found and nonempty, allocate a new BSTR (with SysAllocString) | |
775 // and return S_OK. If not found or empty, return S_FALSE. | |
776 HRESULT GetStringAttributeAsBstr( | |
777 ui::AXStringAttribute attribute, | |
778 BSTR* value_bstr); | |
779 | |
780 // Escapes characters in string attributes as required by the IA2 Spec. | |
781 // It's okay for input to be the same as output. | |
782 CONTENT_EXPORT static void SanitizeStringAttributeForIA2( | |
783 const base::string16& input, | |
784 base::string16* output); | |
785 FRIEND_TEST_ALL_PREFIXES(BrowserAccessibilityTest, | |
786 TestSanitizeStringAttributeForIA2); | |
787 | |
788 // Sets the selection given a start and end offset in IA2 Hypertext. | |
789 void SetIA2HypertextSelection(LONG start_offset, LONG end_offset); | |
790 | |
791 // If the string attribute |attribute| is present, add its value as an | |
792 // IAccessible2 attribute with the name |ia2_attr|. | |
793 void StringAttributeToIA2(ui::AXStringAttribute attribute, | |
794 const char* ia2_attr); | |
795 | |
796 // If the bool attribute |attribute| is present, add its value as an | |
797 // IAccessible2 attribute with the name |ia2_attr|. | |
798 void BoolAttributeToIA2(ui::AXBoolAttribute attribute, | |
799 const char* ia2_attr); | |
800 | |
801 // If the int attribute |attribute| is present, add its value as an | |
802 // IAccessible2 attribute with the name |ia2_attr|. | |
803 void IntAttributeToIA2(ui::AXIntAttribute attribute, | |
804 const char* ia2_attr); | |
805 | |
806 // | |
807 // Helper methods for IA2 hyperlinks. | |
808 // | |
809 // Hyperlink is an IA2 misnomer. It refers to objects embedded within other | |
810 // objects, such as a numbered list within a contenteditable div. | |
811 // Also, in IA2, text that includes embedded objects is called hypertext. | |
812 | |
813 // Returns true if the current object is an IA2 hyperlink. | |
814 bool IsHyperlink() const; | |
815 // Returns the hyperlink at the given text position, or nullptr if no | |
816 // hyperlink can be found. | |
817 BrowserAccessibilityWin* GetHyperlinkFromHypertextOffset(int offset) const; | |
818 | |
819 // Functions for retrieving offsets for hyperlinks and hypertext. | |
820 // Return -1 in case of failure. | |
821 int32_t GetHyperlinkIndexFromChild( | |
822 const BrowserAccessibilityWin& child) const; | |
823 int32_t GetHypertextOffsetFromHyperlinkIndex(int32_t hyperlink_index) const; | |
824 int32_t GetHypertextOffsetFromChild( | |
825 const BrowserAccessibilityWin& child) const; | |
826 int32_t GetHypertextOffsetFromDescendant( | |
827 const BrowserAccessibilityWin& descendant) const; | |
828 | |
829 // If the selection endpoint is either equal to or an ancestor of this object, | |
830 // returns endpoint_offset. | |
831 // If the selection endpoint is a descendant of this object, returns its | |
832 // offset. Otherwise, returns either 0 or the length of the hypertext | |
833 // depending on the direction of the selection. | |
834 // Returns -1 in case of unexpected failure, e.g. the selection endpoint | |
835 // cannot be found in the accessibility tree. | |
836 int GetHypertextOffsetFromEndpoint( | |
837 const BrowserAccessibilityWin& endpoint_object, | |
838 int endpoint_offset) const; | |
839 | |
840 // | |
841 // Selection helper functions. | |
842 // | |
843 // The following functions retrieve the endpoints of the current selection. | |
844 // First they check for a local selection found on the current control, e.g. | |
845 // when querying the selection on a textarea. | |
846 // If not found they retrieve the global selection found on the current frame. | |
847 int GetSelectionAnchor() const; | |
848 int GetSelectionFocus() const; | |
849 // Retrieves the selection offsets in the way required by the IA2 APIs. | |
850 // selection_start and selection_end are -1 when there is no selection active | |
851 // on this object. | |
852 // The greatest of the two offsets is one past the last character of the | |
853 // selection.) | |
854 void GetSelectionOffsets(int* selection_start, int* selection_end) const; | |
855 | |
856 // Get the value text, which might come from the floating-point | |
857 // value for some roles. | |
858 base::string16 GetValueText(); | |
859 | |
860 bool IsSameHypertextCharacter(size_t old_char_index, size_t new_char_index); | |
861 void ComputeHypertextRemovedAndInserted( | |
862 int* start, int* old_len, int* new_len); | |
863 | |
864 // If offset is a member of IA2TextSpecialOffsets this function updates the | |
865 // value of offset and returns, otherwise offset remains unchanged. | |
866 void HandleSpecialTextOffset(LONG* offset); | |
867 | |
868 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType. | |
869 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type); | |
870 | |
871 // Search forwards (direction == 1) or backwards (direction == -1) | |
872 // from the given offset until the given boundary is found, and | |
873 // return the offset of that boundary. | |
874 LONG FindBoundary(const base::string16& text, | |
875 IA2TextBoundaryType ia2_boundary, | |
876 LONG start_offset, | |
877 ui::TextBoundaryDirection direction); | |
878 | |
879 // Searches forward from the given offset until the start of the next style | |
880 // is found, or searches backward from the given offset until the start of the | |
881 // current style is found. | |
882 LONG FindStartOfStyle(LONG start_offset, | |
883 ui::TextBoundaryDirection direction) const; | |
884 | |
885 // ID refers to the node ID in the current tree, not the globally unique ID. | |
886 // TODO(nektar): Could we use globally unique IDs everywhere? | |
887 // TODO(nektar): Rename this function to GetFromNodeID. | |
888 BrowserAccessibilityWin* GetFromID(int32_t id) const; | |
889 | |
890 // Returns true if this is a list box option with a parent of type list box, | |
891 // or a menu list option with a parent of type menu list popup. | |
892 bool IsListBoxOptionOrMenuListOption(); | |
893 | |
894 // For adding / removing IA2 relations. | |
895 | |
896 void AddRelation(const base::string16& relation_type, int target_id); | |
897 void AddBidirectionalRelations(const base::string16& relation_type, | |
898 const base::string16& reverse_relation_type, | |
899 ui::AXIntListAttribute attribute); | |
900 // Clears all the forward relations from this object to any other object and | |
901 // the associated reverse relations on the other objects, but leaves any | |
902 // reverse relations on this object alone. | |
903 void ClearOwnRelations(); | |
904 void RemoveBidirectionalRelationsOfType( | |
905 const base::string16& relation_type, | |
906 const base::string16& reverse_relation_type); | |
907 void RemoveTargetFromRelation(const base::string16& relation_type, | |
908 int target_id); | |
909 | |
910 // Updates object attributes of IA2 with html attributes. | |
911 void UpdateRequiredAttributes(); | |
912 | |
913 // Fire a Windows-specific accessibility event notification on this node. | |
914 void FireNativeEvent(LONG win_event_type) const; | |
915 | |
916 ui::AXPlatformNodeWin* GetPlatformNodeWin() const; | |
917 | |
918 static bool IsInTreeGrid(const BrowserAccessibility* item); | |
919 | |
920 struct WinAttributes { | |
921 WinAttributes(); | |
922 ~WinAttributes(); | |
923 | |
924 // IAccessible role and state. | |
925 int32_t ia_role; | |
926 int32_t ia_state; | |
927 base::string16 role_name; | |
928 | |
929 // IAccessible name, description, help, value. | |
930 base::string16 name; | |
931 base::string16 description; | |
932 base::string16 value; | |
933 | |
934 // IAccessible2 role and state. | |
935 int32_t ia2_role; | |
936 int32_t ia2_state; | |
937 | |
938 // IAccessible2 attributes. | |
939 std::vector<base::string16> ia2_attributes; | |
940 | |
941 // Hypertext. | |
942 base::string16 hypertext; | |
943 | |
944 // Maps each style span to its start offset in hypertext. | |
945 std::map<int, std::vector<base::string16>> offset_to_text_attributes; | |
946 | |
947 // Maps an embedded character offset in |hypertext_| to an index in | |
948 // |hyperlinks_|. | |
949 std::map<int32_t, int32_t> hyperlink_offset_to_index; | |
950 | |
951 // The unique id of a BrowserAccessibilityWin for each hyperlink. | |
952 // TODO(nektar): Replace object IDs with child indices if we decide that | |
953 // we are not implementing IA2 hyperlinks for anything other than IA2 | |
954 // Hypertext. | |
955 std::vector<int32_t> hyperlinks; | |
956 }; | |
957 | |
958 std::unique_ptr<WinAttributes> win_attributes_; | |
959 | |
960 // Only valid during the scope of a IA2_EVENT_TEXT_REMOVED or | |
961 // IA2_EVENT_TEXT_INSERTED event. | |
962 std::unique_ptr<WinAttributes> old_win_attributes_; | |
963 | |
964 // Relationships between this node and other nodes. | |
965 std::vector<BrowserAccessibilityRelation*> relations_; | |
966 | |
967 // The previous scroll position, so we can tell if this object scrolled. | |
968 int previous_scroll_x_; | |
969 int previous_scroll_y_; | |
970 | |
971 // Give BrowserAccessibility::Create access to our constructor. | 40 // Give BrowserAccessibility::Create access to our constructor. |
972 friend class BrowserAccessibility; | 41 friend class BrowserAccessibility; |
973 friend class BrowserAccessibilityRelation; | |
974 | |
975 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityWin); | 42 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibilityWin); |
976 }; | 43 }; |
977 | 44 |
978 CONTENT_EXPORT BrowserAccessibilityWin* | 45 CONTENT_EXPORT BrowserAccessibilityWin* |
979 ToBrowserAccessibilityWin(BrowserAccessibility* obj); | 46 ToBrowserAccessibilityWin(BrowserAccessibility* obj); |
980 | 47 |
981 CONTENT_EXPORT const BrowserAccessibilityWin* | 48 CONTENT_EXPORT const BrowserAccessibilityWin* |
982 ToBrowserAccessibilityWin(const BrowserAccessibility* obj); | 49 ToBrowserAccessibilityWin(const BrowserAccessibility* obj); |
983 | 50 |
984 } // namespace content | 51 } // namespace content |
985 | 52 |
986 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ | 53 #endif // CONTENT_BROWSER_ACCESSIBILITY_BROWSER_ACCESSIBILITY_WIN_H_ |
OLD | NEW |