Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: ui/views/accessibility/native_view_accessibility_win.h

Issue 909143003: Re-land: Implement NativeViewAccessibilityWin using AXPlatformNodeWin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update GN build Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_ 5 #ifndef UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_
6 #define UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_ 6 #define UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_
7 7
8 #include <atlbase.h>
9 #include <atlcom.h>
10 #include <oleacc.h>
11
12 #include <UIAutomationCore.h>
13
14 #include <set>
15 #include <vector>
16
17 #include "third_party/iaccessible2/ia2_api_all.h"
18 #include "ui/accessibility/ax_view_state.h"
19 #include "ui/views/accessibility/native_view_accessibility.h" 8 #include "ui/views/accessibility/native_view_accessibility.h"
20 #include "ui/views/controls/native/native_view_host.h"
21 #include "ui/views/view.h" 9 #include "ui/views/view.h"
22 10
23 namespace ui {
24 enum TextBoundaryDirection;
25 enum TextBoundaryType;
26 }
27
28 namespace views { 11 namespace views {
29 12
30 //////////////////////////////////////////////////////////////////////////////// 13 class NativeViewAccessibilityWin : public NativeViewAccessibility {
31 //
32 // NativeViewAccessibilityWin
33 //
34 // Class implementing the MSAA IAccessible COM interface for a generic View,
35 // providing accessibility to be used by screen readers and other assistive
36 // technology (AT).
37 //
38 ////////////////////////////////////////////////////////////////////////////////
39 class __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
40 NativeViewAccessibilityWin
41 : public CComObjectRootEx<CComMultiThreadModel>,
42 public IDispatchImpl<IAccessible2_2, &IID_IAccessible2_2,
43 &LIBID_IAccessible2Lib>,
44 public IAccessibleText,
45 public IServiceProvider,
46 public IAccessibleEx,
47 public IRawElementProviderSimple,
48 public NativeViewAccessibility {
49 public: 14 public:
50 BEGIN_COM_MAP(NativeViewAccessibilityWin) 15 NativeViewAccessibilityWin(View* view);
51 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2_2)
52 COM_INTERFACE_ENTRY(IAccessible)
53 COM_INTERFACE_ENTRY(IAccessible2)
54 COM_INTERFACE_ENTRY(IAccessible2_2)
55 COM_INTERFACE_ENTRY(IAccessibleEx)
56 COM_INTERFACE_ENTRY(IAccessibleText)
57 COM_INTERFACE_ENTRY(IRawElementProviderSimple)
58 COM_INTERFACE_ENTRY(IServiceProvider)
59 END_COM_MAP()
60
61 virtual ~NativeViewAccessibilityWin(); 16 virtual ~NativeViewAccessibilityWin();
62 17
63 // NativeViewAccessibility. 18 // NativeViewAccessibility.
64 void NotifyAccessibilityEvent(ui::AXEvent event_type) override; 19 gfx::NativeViewAccessible GetParent() override;
65 gfx::NativeViewAccessible GetNativeObject() override; 20 gfx::AcceleratedWidget GetTargetForNativeAccessibilityEvent() override;
66 void Destroy() override;
67
68 // Supported IAccessible methods.
69
70 // Retrieves the child element or child object at a given point on the screen.
71 STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child) override;
72
73 // Performs the object's default action.
74 STDMETHODIMP accDoDefaultAction(VARIANT var_id) override;
75
76 // Retrieves the specified object's current screen location.
77 STDMETHODIMP accLocation(LONG* x_left,
78 LONG* y_top,
79 LONG* width,
80 LONG* height,
81 VARIANT var_id) override;
82
83 // Traverses to another UI element and retrieves the object.
84 STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end) override;
85
86 // Retrieves an IDispatch interface pointer for the specified child.
87 STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child) override;
88
89 // Retrieves the number of accessible children.
90 STDMETHODIMP get_accChildCount(LONG* child_count) override;
91
92 // Retrieves a string that describes the object's default action.
93 STDMETHODIMP get_accDefaultAction(VARIANT var_id,
94 BSTR* default_action) override;
95
96 // Retrieves the tooltip description.
97 STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc) override;
98
99 // Retrieves the object that has the keyboard focus.
100 STDMETHODIMP get_accFocus(VARIANT* focus_child) override;
101
102 // Retrieves the specified object's shortcut.
103 STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id,
104 BSTR* access_key) override;
105
106 // Retrieves the name of the specified object.
107 STDMETHODIMP get_accName(VARIANT var_id, BSTR* name) override;
108
109 // Retrieves the IDispatch interface of the object's parent.
110 STDMETHODIMP get_accParent(IDispatch** disp_parent) override;
111
112 // Retrieves information describing the role of the specified object.
113 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role) override;
114
115 // Retrieves the current state of the specified object.
116 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state) override;
117
118 // Retrieve or set the string value associated with the specified object.
119 // Setting the value is not typically used by screen readers, but it's
120 // used frequently by automation software.
121 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value) override;
122 STDMETHODIMP put_accValue(VARIANT var_id, BSTR new_value) override;
123
124 // Selections not applicable to views.
125 STDMETHODIMP get_accSelection(VARIANT* selected) override;
126 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id) override;
127
128 // Help functions not supported.
129 STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help) override;
130 STDMETHODIMP get_accHelpTopic(BSTR* help_file,
131 VARIANT var_id,
132 LONG* topic_id) override;
133
134 // Deprecated functions, not implemented here.
135 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) override;
136
137 //
138 // IAccessible2
139 //
140
141 STDMETHODIMP role(LONG* role) override;
142
143 STDMETHODIMP get_states(AccessibleStates* states) override;
144
145 STDMETHODIMP get_uniqueID(LONG* unique_id) override;
146
147 STDMETHODIMP get_windowHandle(HWND* window_handle) override;
148
149 STDMETHODIMP get_relationTargetsOfType(BSTR type,
150 long max_targets,
151 IUnknown*** targets,
152 long* n_targets) override;
153
154 STDMETHODIMP get_attributes(BSTR* attributes) override;
155
156 //
157 // IAccessible2 methods not implemented.
158 //
159
160 STDMETHODIMP get_attribute(BSTR name, VARIANT* attribute) override {
161 return E_NOTIMPL;
162 }
163 STDMETHODIMP get_indexInParent(LONG* index_in_parent) override {
164 return E_NOTIMPL;
165 }
166 STDMETHODIMP get_extendedRole(BSTR* extended_role) override {
167 return E_NOTIMPL;
168 }
169 STDMETHODIMP get_nRelations(LONG* n_relations) override { return E_NOTIMPL; }
170 STDMETHODIMP get_relation(LONG relation_index,
171 IAccessibleRelation** relation) override {
172 return E_NOTIMPL;
173 }
174 STDMETHODIMP get_relations(LONG max_relations,
175 IAccessibleRelation** relations,
176 LONG* n_relations) override {
177 return E_NOTIMPL;
178 }
179 STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) override {
180 return E_NOTIMPL;
181 }
182 STDMETHODIMP scrollToPoint(enum IA2CoordinateType coordinate_type,
183 LONG x,
184 LONG y) override {
185 return E_NOTIMPL;
186 }
187 STDMETHODIMP get_groupPosition(LONG* group_level,
188 LONG* similar_items_in_group,
189 LONG* position_in_group) override {
190 return E_NOTIMPL;
191 }
192 STDMETHODIMP get_localizedExtendedRole(
193 BSTR* localized_extended_role) override {
194 return E_NOTIMPL;
195 }
196 STDMETHODIMP get_nExtendedStates(LONG* n_extended_states) override {
197 return E_NOTIMPL;
198 }
199 STDMETHODIMP get_extendedStates(LONG max_extended_states,
200 BSTR** extended_states,
201 LONG* n_extended_states) override {
202 return E_NOTIMPL;
203 }
204 STDMETHODIMP get_localizedExtendedStates(
205 LONG max_localized_extended_states,
206 BSTR** localized_extended_states,
207 LONG* n_localized_extended_states) override {
208 return E_NOTIMPL;
209 }
210 STDMETHODIMP get_locale(IA2Locale* locale) override { return E_NOTIMPL; }
211 STDMETHODIMP get_accessibleWithCaret(IUnknown** accessible,
212 long* caret_offset) override {
213 return E_NOTIMPL;
214 }
215
216 //
217 // IAccessibleText methods.
218 //
219
220 STDMETHODIMP get_nCharacters(LONG* n_characters) override;
221
222 STDMETHODIMP get_caretOffset(LONG* offset) override;
223
224 STDMETHODIMP get_nSelections(LONG* n_selections) override;
225
226 STDMETHODIMP get_selection(LONG selection_index,
227 LONG* start_offset,
228 LONG* end_offset) override;
229
230 STDMETHODIMP get_text(LONG start_offset,
231 LONG end_offset,
232 BSTR* text) override;
233
234 STDMETHODIMP get_textAtOffset(LONG offset,
235 enum IA2TextBoundaryType boundary_type,
236 LONG* start_offset,
237 LONG* end_offset,
238 BSTR* text) override;
239
240 STDMETHODIMP get_textBeforeOffset(LONG offset,
241 enum IA2TextBoundaryType boundary_type,
242 LONG* start_offset,
243 LONG* end_offset,
244 BSTR* text) override;
245
246 STDMETHODIMP get_textAfterOffset(LONG offset,
247 enum IA2TextBoundaryType boundary_type,
248 LONG* start_offset,
249 LONG* end_offset,
250 BSTR* text) override;
251
252 STDMETHODIMP get_offsetAtPoint(LONG x,
253 LONG y,
254 enum IA2CoordinateType coord_type,
255 LONG* offset) override;
256
257 //
258 // IAccessibleText methods not implemented.
259 //
260
261 STDMETHODIMP get_newText(IA2TextSegment* new_text) override {
262 return E_NOTIMPL;
263 }
264 STDMETHODIMP get_oldText(IA2TextSegment* old_text) override {
265 return E_NOTIMPL;
266 }
267 STDMETHODIMP addSelection(LONG start_offset, LONG end_offset) override {
268 return E_NOTIMPL;
269 }
270 STDMETHODIMP get_attributes(LONG offset,
271 LONG* start_offset,
272 LONG* end_offset,
273 BSTR* text_attributes) override {
274 return E_NOTIMPL;
275 }
276 STDMETHODIMP get_characterExtents(LONG offset,
277 enum IA2CoordinateType coord_type,
278 LONG* x,
279 LONG* y,
280 LONG* width,
281 LONG* height) override {
282 return E_NOTIMPL;
283 }
284 STDMETHODIMP removeSelection(LONG selection_index) override {
285 return E_NOTIMPL;
286 }
287 STDMETHODIMP setCaretOffset(LONG offset) override { return E_NOTIMPL; }
288 STDMETHODIMP setSelection(LONG selection_index,
289 LONG start_offset,
290 LONG end_offset) override {
291 return E_NOTIMPL;
292 }
293 STDMETHODIMP scrollSubstringTo(LONG start_index,
294 LONG end_index,
295 enum IA2ScrollType scroll_type) override {
296 return E_NOTIMPL;
297 }
298 STDMETHODIMP scrollSubstringToPoint(LONG start_index,
299 LONG end_index,
300 enum IA2CoordinateType coordinate_type,
301 LONG x,
302 LONG y) override {
303 return E_NOTIMPL;
304 }
305
306 //
307 // IServiceProvider methods.
308 //
309
310 STDMETHODIMP QueryService(REFGUID guidService,
311 REFIID riid,
312 void** object) override;
313
314 //
315 // IAccessibleEx methods not implemented.
316 //
317 STDMETHODIMP GetObjectForChild(long child_id, IAccessibleEx** ret) override {
318 return E_NOTIMPL;
319 }
320
321 STDMETHODIMP GetIAccessiblePair(IAccessible** acc, long* child_id) override {
322 return E_NOTIMPL;
323 }
324
325 STDMETHODIMP GetRuntimeId(SAFEARRAY** runtime_id) override {
326 return E_NOTIMPL;
327 }
328
329 STDMETHODIMP ConvertReturnedElement(IRawElementProviderSimple* element,
330 IAccessibleEx** acc) override {
331 return E_NOTIMPL;
332 }
333
334 //
335 // IRawElementProviderSimple methods.
336 //
337 // The GetPatternProvider/GetPropertyValue methods need to be implemented for
338 // the on-screen keyboard to show up in Windows 8 metro.
339 STDMETHODIMP GetPatternProvider(PATTERNID id, IUnknown** provider) override;
340 STDMETHODIMP GetPropertyValue(PROPERTYID id, VARIANT* ret) override;
341
342 //
343 // IRawElementProviderSimple methods not implemented.
344 //
345 STDMETHODIMP get_ProviderOptions(enum ProviderOptions* ret) override {
346 return E_NOTIMPL;
347 }
348
349 STDMETHODIMP get_HostRawElementProvider(
350 IRawElementProviderSimple** provider) override {
351 return E_NOTIMPL;
352 }
353
354 // Static methods
355
356 // Returns a conversion from the event (as defined in ax_enums.idl)
357 // to an MSAA event.
358 static int32 MSAAEvent(ui::AXEvent event);
359
360 // Returns a conversion from the Role (as defined in ax_enums.idl)
361 // to an MSAA role.
362 static int32 MSAARole(ui::AXRole role);
363
364 // Returns a conversion from the State (as defined in ax_enums.idl)
365 // to MSAA states set.
366 static int32 MSAAState(const ui::AXViewState& state);
367
368 protected:
369 NativeViewAccessibilityWin();
370
371 private:
372 // Determines navigation direction for accNavigate, based on left, up and
373 // previous being mapped all to previous and right, down, next being mapped
374 // to next. Returns true if navigation direction is next, false otherwise.
375 bool IsNavDirNext(int nav_dir) const;
376
377 // Determines if the navigation target is within the allowed bounds. Returns
378 // true if it is, false otherwise.
379 bool IsValidNav(int nav_dir,
380 int start_id,
381 int lower_bound,
382 int upper_bound) const;
383
384 // Determines if the child id variant is valid.
385 bool IsValidId(const VARIANT& child) const;
386
387 // Helper function which sets applicable states of view.
388 void SetState(VARIANT* msaa_state, View* view);
389
390 // Return the text to use for IAccessibleText.
391 base::string16 TextForIAccessibleText();
392
393 // If offset is a member of IA2TextSpecialOffsets this function updates the
394 // value of offset and returns, otherwise offset remains unchanged.
395 void HandleSpecialTextOffset(const base::string16& text, LONG* offset);
396
397 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType.
398 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type);
399
400 // Search forwards (direction == 1) or backwards (direction == -1)
401 // from the given offset until the given boundary is found, and
402 // return the offset of that boundary.
403 LONG FindBoundary(const base::string16& text,
404 IA2TextBoundaryType ia2_boundary,
405 LONG start_offset,
406 ui::TextBoundaryDirection direction);
407
408 // Populates the given vector with all widgets that are either a child
409 // or are owned by this view's widget, and who are not contained in a
410 // NativeViewHost.
411 void PopulateChildWidgetVector(std::vector<Widget*>* child_widgets);
412
413 // Adds this view to alert_target_view_storage_ids_.
414 void AddAlertTarget();
415
416 // Removes this view from alert_target_view_storage_ids_.
417 void RemoveAlertTarget();
418
419 // Give CComObject access to the class constructor.
420 template <class Base> friend class CComObject;
421
422 // A unique id for each object, needed for IAccessible2.
423 long unique_id_;
424
425 // Next unique id to assign.
426 static long next_unique_id_;
427
428 // Circular queue size.
429 static const int kMaxViewStorageIds = 20;
430
431 // Circular queue of view storage ids corresponding to child ids
432 // used to post notifications using NotifyWinEvent.
433 static int view_storage_ids_[kMaxViewStorageIds];
434
435 // Next index into |view_storage_ids_| to use.
436 static int next_view_storage_id_index_;
437
438 // A vector of view storage ids of views that have been the target of
439 // an alert event, in order to provide an api to quickly identify all
440 // open alerts.
441 static std::vector<int> alert_target_view_storage_ids_;
442 21
443 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityWin); 22 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityWin);
444 }; 23 };
445 24
446 } // namespace views 25 } // namespace views
447 26
448 #endif // UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_ 27 #endif // UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_
OLDNEW
« no previous file with comments | « ui/views/accessibility/native_view_accessibility_unittest.cc ('k') | ui/views/accessibility/native_view_accessibility_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698