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

Side by Side Diff: ui/accessibility/platform/ax_platform_node_win.h

Issue 909143003: Re-land: Implement NativeViewAccessibilityWin using AXPlatformNodeWin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix unit test Created 5 years, 10 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 2015 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_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_
6 #define UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_ 6 #define UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_
7 7
8 #include <atlbase.h> 8 #include <atlbase.h>
9 #include <atlcom.h> 9 #include <atlcom.h>
10 #include <oleacc.h> 10 #include <oleacc.h>
11 11
12 #include <UIAutomationCore.h>
13
14 #include <set>
15 #include <vector>
16
17 #include "third_party/iaccessible2/ia2_api_all.h" 12 #include "third_party/iaccessible2/ia2_api_all.h"
18 #include "ui/accessibility/ax_view_state.h" 13 #include "ui/accessibility/platform/ax_platform_node_base.h"
19 #include "ui/views/accessibility/native_view_accessibility.h"
20 #include "ui/views/controls/native/native_view_host.h"
21 #include "ui/views/view.h"
22 14
23 namespace ui { 15 namespace ui {
24 enum TextBoundaryDirection;
25 enum TextBoundaryType;
26 }
27 16
28 namespace views {
29
30 ////////////////////////////////////////////////////////////////////////////////
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")) 17 class __declspec(uuid("26f5641a-246d-457b-a96d-07f3fae6acf2"))
40 NativeViewAccessibilityWin 18 AXPlatformNodeWin
41 : public CComObjectRootEx<CComMultiThreadModel>, 19 : public CComObjectRootEx<CComMultiThreadModel>,
42 public IDispatchImpl<IAccessible2_2, &IID_IAccessible2_2, 20 public IDispatchImpl<IAccessible2_2, &IID_IAccessible2,
43 &LIBID_IAccessible2Lib>, 21 &LIBID_IAccessible2Lib>,
44 public IAccessibleText, 22 public IAccessibleText,
45 public IServiceProvider, 23 public IServiceProvider,
46 public IAccessibleEx, 24 public AXPlatformNodeBase {
47 public IRawElementProviderSimple,
48 public NativeViewAccessibility {
49 public: 25 public:
50 BEGIN_COM_MAP(NativeViewAccessibilityWin) 26 BEGIN_COM_MAP(AXPlatformNodeWin)
51 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2_2) 27 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2_2)
28 COM_INTERFACE_ENTRY(AXPlatformNodeWin)
52 COM_INTERFACE_ENTRY(IAccessible) 29 COM_INTERFACE_ENTRY(IAccessible)
53 COM_INTERFACE_ENTRY(IAccessible2) 30 COM_INTERFACE_ENTRY(IAccessible2)
54 COM_INTERFACE_ENTRY(IAccessible2_2) 31 COM_INTERFACE_ENTRY(IAccessible2_2)
55 COM_INTERFACE_ENTRY(IAccessibleEx)
56 COM_INTERFACE_ENTRY(IAccessibleText) 32 COM_INTERFACE_ENTRY(IAccessibleText)
57 COM_INTERFACE_ENTRY(IRawElementProviderSimple)
58 COM_INTERFACE_ENTRY(IServiceProvider) 33 COM_INTERFACE_ENTRY(IServiceProvider)
59 END_COM_MAP() 34 END_COM_MAP()
60 35
61 virtual ~NativeViewAccessibilityWin(); 36 virtual ~AXPlatformNodeWin();
62 37
63 // NativeViewAccessibility. 38 // AXPlatformNode overrides.
39 void Destroy() override;
40 gfx::NativeViewAccessible GetNativeViewAccessible() override;
64 void NotifyAccessibilityEvent(ui::AXEvent event_type) override; 41 void NotifyAccessibilityEvent(ui::AXEvent event_type) override;
65 gfx::NativeViewAccessible GetNativeObject() override;
66 void Destroy() override;
67 42
68 // Supported IAccessible methods. 43 //
44 // IAccessible methods.
45 //
69 46
70 // Retrieves the child element or child object at a given point on the screen. 47 // 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; 48 virtual STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child);
72 49
73 // Performs the object's default action. 50 // Performs the object's default action.
74 STDMETHODIMP accDoDefaultAction(VARIANT var_id) override; 51 STDMETHODIMP accDoDefaultAction(VARIANT var_id);
75 52
76 // Retrieves the specified object's current screen location. 53 // Retrieves the specified object's current screen location.
77 STDMETHODIMP accLocation(LONG* x_left, 54 STDMETHODIMP accLocation(LONG* x_left,
78 LONG* y_top, 55 LONG* y_top,
79 LONG* width, 56 LONG* width,
80 LONG* height, 57 LONG* height,
81 VARIANT var_id) override; 58 VARIANT var_id);
82 59
83 // Traverses to another UI element and retrieves the object. 60 // Traverses to another UI element and retrieves the object.
84 STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end) override; 61 STDMETHODIMP accNavigate(LONG nav_dir, VARIANT start, VARIANT* end);
85 62
86 // Retrieves an IDispatch interface pointer for the specified child. 63 // Retrieves an IDispatch interface pointer for the specified child.
87 STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child) override; 64 virtual STDMETHODIMP get_accChild(VARIANT var_child, IDispatch** disp_child);
88 65
89 // Retrieves the number of accessible children. 66 // Retrieves the number of accessible children.
90 STDMETHODIMP get_accChildCount(LONG* child_count) override; 67 virtual STDMETHODIMP get_accChildCount(LONG* child_count);
91 68
92 // Retrieves a string that describes the object's default action. 69 // Retrieves a string that describes the object's default action.
93 STDMETHODIMP get_accDefaultAction(VARIANT var_id, 70 STDMETHODIMP get_accDefaultAction(VARIANT var_id, BSTR* default_action);
94 BSTR* default_action) override;
95 71
96 // Retrieves the tooltip description. 72 // Retrieves the tooltip description.
97 STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc) override; 73 STDMETHODIMP get_accDescription(VARIANT var_id, BSTR* desc);
98 74
99 // Retrieves the object that has the keyboard focus. 75 // Retrieves the object that has the keyboard focus.
100 STDMETHODIMP get_accFocus(VARIANT* focus_child) override; 76 STDMETHODIMP get_accFocus(VARIANT* focus_child);
101 77
102 // Retrieves the specified object's shortcut. 78 // Retrieves the specified object's shortcut.
103 STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, 79 STDMETHODIMP get_accKeyboardShortcut(VARIANT var_id, BSTR* access_key);
104 BSTR* access_key) override;
105 80
106 // Retrieves the name of the specified object. 81 // Retrieves the name of the specified object.
107 STDMETHODIMP get_accName(VARIANT var_id, BSTR* name) override; 82 STDMETHODIMP get_accName(VARIANT var_id, BSTR* name);
108 83
109 // Retrieves the IDispatch interface of the object's parent. 84 // Retrieves the IDispatch interface of the object's parent.
110 STDMETHODIMP get_accParent(IDispatch** disp_parent) override; 85 STDMETHODIMP get_accParent(IDispatch** disp_parent);
111 86
112 // Retrieves information describing the role of the specified object. 87 // Retrieves information describing the role of the specified object.
113 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role) override; 88 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role);
114 89
115 // Retrieves the current state of the specified object. 90 // Retrieves the current state of the specified object.
116 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state) override; 91 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state);
92
93 // Gets the help string for the specified object.
94 STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help);
117 95
118 // Retrieve or set the string value associated with the specified object. 96 // 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 97 // Setting the value is not typically used by screen readers, but it's
120 // used frequently by automation software. 98 // used frequently by automation software.
121 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value) override; 99 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value);
122 STDMETHODIMP put_accValue(VARIANT var_id, BSTR new_value) override; 100 STDMETHODIMP put_accValue(VARIANT var_id, BSTR new_value);
123 101
124 // Selections not applicable to views. 102 // IAccessible methods not implemented.
125 STDMETHODIMP get_accSelection(VARIANT* selected) override; 103 STDMETHODIMP get_accSelection(VARIANT* selected);
126 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id) override; 104 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id);
127
128 // Help functions not supported.
129 STDMETHODIMP get_accHelp(VARIANT var_id, BSTR* help) override;
130 STDMETHODIMP get_accHelpTopic(BSTR* help_file, 105 STDMETHODIMP get_accHelpTopic(BSTR* help_file,
131 VARIANT var_id, 106 VARIANT var_id,
132 LONG* topic_id) override; 107 LONG* topic_id);
133 108 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name);
134 // Deprecated functions, not implemented here.
135 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) override;
136 109
137 // 110 //
138 // IAccessible2 111 // IAccessible2 methods.
139 // 112 //
140 113
141 STDMETHODIMP role(LONG* role) override; 114 STDMETHODIMP role(LONG* role) override;
142 115
143 STDMETHODIMP get_states(AccessibleStates* states) override; 116 STDMETHODIMP get_states(AccessibleStates* states) override;
144 117
145 STDMETHODIMP get_uniqueID(LONG* unique_id) override; 118 STDMETHODIMP get_uniqueID(LONG* unique_id) override;
146 119
147 STDMETHODIMP get_windowHandle(HWND* window_handle) override; 120 STDMETHODIMP get_windowHandle(HWND* window_handle) override;
148 121
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 enum IA2CoordinateType coordinate_type, 273 enum IA2CoordinateType coordinate_type,
301 LONG x, 274 LONG x,
302 LONG y) override { 275 LONG y) override {
303 return E_NOTIMPL; 276 return E_NOTIMPL;
304 } 277 }
305 278
306 // 279 //
307 // IServiceProvider methods. 280 // IServiceProvider methods.
308 // 281 //
309 282
310 STDMETHODIMP QueryService(REFGUID guidService, 283 STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void** object);
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 284
368 protected: 285 protected:
369 NativeViewAccessibilityWin(); 286 AXPlatformNodeWin();
370 287
371 private: 288 private:
372 // Determines navigation direction for accNavigate, based on left, up and 289 bool IsValidId(const VARIANT& child) const;
373 // previous being mapped all to previous and right, down, next being mapped 290 int MSAARole();
374 // to next. Returns true if navigation direction is next, false otherwise. 291 int MSAAState();
375 bool IsNavDirNext(int nav_dir) const; 292 int MSAAEvent(ui::AXEvent event);
376 293
377 // Determines if the navigation target is within the allowed bounds. Returns 294 HRESULT GetStringAttributeAsBstr(
378 // true if it is, false otherwise. 295 ui::AXStringAttribute attribute,
379 bool IsValidNav(int nav_dir, 296 BSTR* value_bstr) const;
380 int start_id,
381 int lower_bound,
382 int upper_bound) const;
383 297
384 // Determines if the child id variant is valid. 298 void AddAlertTarget();
385 bool IsValidId(const VARIANT& child) const; 299 void RemoveAlertTarget();
386
387 // Helper function which sets applicable states of view.
388 void SetState(VARIANT* msaa_state, View* view);
389 300
390 // Return the text to use for IAccessibleText. 301 // Return the text to use for IAccessibleText.
391 base::string16 TextForIAccessibleText(); 302 base::string16 TextForIAccessibleText();
392 303
393 // If offset is a member of IA2TextSpecialOffsets this function updates the 304 // If offset is a member of IA2TextSpecialOffsets this function updates the
394 // value of offset and returns, otherwise offset remains unchanged. 305 // value of offset and returns, otherwise offset remains unchanged.
395 void HandleSpecialTextOffset(const base::string16& text, LONG* offset); 306 void HandleSpecialTextOffset(const base::string16& text, LONG* offset);
396 307
397 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType. 308 // Convert from a IA2TextBoundaryType to a ui::TextBoundaryType.
398 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type); 309 ui::TextBoundaryType IA2TextBoundaryToTextBoundary(IA2TextBoundaryType type);
399 310
400 // Search forwards (direction == 1) or backwards (direction == -1) 311 // Search forwards (direction == 1) or backwards (direction == -1)
401 // from the given offset until the given boundary is found, and 312 // from the given offset until the given boundary is found, and
402 // return the offset of that boundary. 313 // return the offset of that boundary.
403 LONG FindBoundary(const base::string16& text, 314 LONG FindBoundary(const base::string16& text,
404 IA2TextBoundaryType ia2_boundary, 315 IA2TextBoundaryType ia2_boundary,
405 LONG start_offset, 316 LONG start_offset,
406 ui::TextBoundaryDirection direction); 317 ui::TextBoundaryDirection direction);
407 318
408 // Populates the given vector with all widgets that are either a child 319 // A windows-specific unique ID for this object. It's returned in
409 // or are owned by this view's widget, and who are not contained in a 320 // IAccessible2::get_uniqueID, but more importantly it's used for
410 // NativeViewHost. 321 // firing events. On Windows, we fire events on the nearest parent HWND
411 void PopulateChildWidgetVector(std::vector<Widget*>* child_widgets); 322 // and pass the unique ID as the child id parameter. When the client
412 323 // wants to retrieve the object the event was fired on, it calls
413 // Adds this view to alert_target_view_storage_ids_. 324 // get_accChild and passes the child ID. We use negative IDs for the unique
414 void AddAlertTarget(); 325 // ID so we can distinguish a request for an arbitrary child from a request
415 326 // for an immediate child of an object by its 0-based index.
416 // Removes this view from alert_target_view_storage_ids_. 327 LONG unique_id_win_;
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
443 DISALLOW_COPY_AND_ASSIGN(NativeViewAccessibilityWin);
444 }; 328 };
445 329
446 } // namespace views 330 } // namespace ui
447 331
448 #endif // UI_VIEWS_ACCESSIBILITY_NATIVE_VIEW_ACCESSIBILITY_WIN_H_ 332 #endif // UI_ACCESSIBILITY_PLATFORM_AX_PLATFORM_NODE_WIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698