OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ | 5 #ifndef CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ |
6 #define CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ | 6 #define CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ |
7 | 7 |
8 #include <atlbase.h> | 8 #include <atlbase.h> |
9 #include <atlcom.h> | 9 #include <atlcom.h> |
| 10 |
10 #include <oleacc.h> | 11 #include <oleacc.h> |
11 | 12 |
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" | 13 #include "webkit/glue/webaccessibility.h" |
18 | 14 |
19 using webkit_glue::WebAccessibility; | 15 using webkit_glue::WebAccessibility; |
20 | 16 |
21 //////////////////////////////////////////////////////////////////////////////// | 17 //////////////////////////////////////////////////////////////////////////////// |
22 // | 18 // |
23 // BrowserAccessibility | 19 // BrowserAccessibility |
24 // | 20 // |
25 // Class implementing the MSAA IAccessible COM interface for the | 21 // Class implementing the MSAA IAccessible COM interface for the |
26 // Browser-Renderer communication of MSAA information, providing accessibility | 22 // Browser-Renderer communication of MSAA information, providing accessibility |
27 // to be used by screen readers and other assistive technology (AT). | 23 // to be used by screen readers and other assistive technology (AT). |
28 // | 24 // |
29 //////////////////////////////////////////////////////////////////////////////// | 25 //////////////////////////////////////////////////////////////////////////////// |
30 class ATL_NO_VTABLE BrowserAccessibility | 26 class ATL_NO_VTABLE BrowserAccessibility |
31 : public CComObjectRootEx<CComMultiThreadModel>, | 27 : public CComObjectRootEx<CComMultiThreadModel>, |
32 public IDispatchImpl<IAccessible2, &IID_IAccessible2, | 28 public IDispatchImpl<IAccessible, &IID_IAccessible, &LIBID_Accessibility> { |
33 &LIBID_IAccessible2Lib>, | |
34 public IServiceProvider { | |
35 public: | 29 public: |
36 BEGIN_COM_MAP(BrowserAccessibility) | 30 BEGIN_COM_MAP(BrowserAccessibility) |
37 COM_INTERFACE_ENTRY2(IDispatch, IAccessible2) | 31 COM_INTERFACE_ENTRY2(IDispatch, IAccessible) |
38 COM_INTERFACE_ENTRY2(IAccessible, IAccessible2) | 32 COM_INTERFACE_ENTRY(IAccessible) |
39 COM_INTERFACE_ENTRY(IAccessible2) | |
40 COM_INTERFACE_ENTRY(IServiceProvider) | |
41 END_COM_MAP() | 33 END_COM_MAP() |
42 | 34 |
43 BrowserAccessibility(); | 35 BrowserAccessibility() |
| 36 : iaccessible_id_(-1), |
| 37 routing_id_(-1), |
| 38 process_id_(-1), |
| 39 parent_hwnd_(NULL), |
| 40 instance_active_(false) { |
| 41 } |
44 | 42 |
45 virtual ~BrowserAccessibility(); | 43 ~BrowserAccessibility() {} |
46 | 44 |
47 // Initialize this object and mark it as active. | 45 HRESULT Initialize(int iaccessible_id, |
48 void Initialize(BrowserAccessibilityManager* manager, | 46 int routing_id, |
49 BrowserAccessibility* parent, | 47 int process_id, |
50 LONG child_id, | 48 HWND parent_hwnd); |
51 LONG index_in_parent, | |
52 const webkit_glue::WebAccessibility& src); | |
53 | 49 |
54 // Add a child of this object. | 50 // Supported IAccessible methods. |
55 void AddChild(BrowserAccessibility* child); | |
56 | |
57 // Mark this object as inactive, and remove references to all children. | |
58 // When no other clients hold any references to this object it will be | |
59 // deleted, and in the meantime, calls to any methods will return E_FAIL. | |
60 void InactivateTree(); | |
61 | |
62 // Return true if this object is equal to or a descendant of |ancestor|. | |
63 bool IsDescendantOf(BrowserAccessibility* ancestor); | |
64 | |
65 // Return the previous sibling of this object, or NULL if it's the first | |
66 // child of its parent. | |
67 BrowserAccessibility* GetPreviousSibling(); | |
68 | |
69 // Return the next sibling of this object, or NULL if it's the last child | |
70 // of its parent. | |
71 BrowserAccessibility* GetNextSibling(); | |
72 | |
73 // Accessors | |
74 LONG child_id() { return child_id_; } | |
75 | |
76 // Add one to the reference count and return the same object. Always | |
77 // use this method when returning a BrowserAccessibility object as | |
78 // an output parameter to a COM interface, never use it otherwise. | |
79 BrowserAccessibility* NewReference(); | |
80 | |
81 // | |
82 // IAccessible methods. | |
83 // | |
84 | 51 |
85 // Performs the default action on a given object. | 52 // Performs the default action on a given object. |
86 STDMETHODIMP accDoDefaultAction(VARIANT var_id); | 53 STDMETHODIMP accDoDefaultAction(VARIANT var_id); |
87 | 54 |
88 // Retrieves the child element or child object at a given point on the screen. | 55 // Retrieves the child element or child object at a given point on the screen. |
89 STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child); | 56 STDMETHODIMP accHitTest(LONG x_left, LONG y_top, VARIANT* child); |
90 | 57 |
91 // Retrieves the specified object's current screen location. | 58 // Retrieves the specified object's current screen location. |
92 STDMETHODIMP accLocation(LONG* x_left, | 59 STDMETHODIMP accLocation(LONG* x_left, |
93 LONG* y_top, | 60 LONG* y_top, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 94 |
128 // Retrieves information describing the role of the specified object. | 95 // Retrieves information describing the role of the specified object. |
129 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role); | 96 STDMETHODIMP get_accRole(VARIANT var_id, VARIANT* role); |
130 | 97 |
131 // Retrieves the current state of the specified object. | 98 // Retrieves the current state of the specified object. |
132 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state); | 99 STDMETHODIMP get_accState(VARIANT var_id, VARIANT* state); |
133 | 100 |
134 // Returns the value associated with the object. | 101 // Returns the value associated with the object. |
135 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value); | 102 STDMETHODIMP get_accValue(VARIANT var_id, BSTR* value); |
136 | 103 |
137 // Make an object take focus or extend the selection. | 104 // Non-supported (by WebKit) IAccessible methods. |
138 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id); | 105 STDMETHODIMP accSelect(LONG flags_sel, VARIANT var_id) { return E_NOTIMPL; } |
139 | 106 |
140 STDMETHODIMP get_accHelpTopic(BSTR* help_file, | 107 STDMETHODIMP get_accHelpTopic(BSTR* help_file, |
141 VARIANT var_id, | 108 VARIANT var_id, |
142 LONG* topic_id); | 109 LONG* topic_id); |
143 | 110 |
144 STDMETHODIMP get_accSelection(VARIANT* selected); | 111 STDMETHODIMP get_accSelection(VARIANT* selected); |
145 | 112 |
146 // Deprecated methods, not implemented. | 113 // Deprecated functions, not implemented here. |
147 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) { | 114 STDMETHODIMP put_accName(VARIANT var_id, BSTR put_name) { return E_NOTIMPL; } |
148 return E_NOTIMPL; | 115 STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val) { return E_NOTIMPL; } |
| 116 |
| 117 // Accessors/mutators. |
| 118 HWND parent_hwnd() const { return parent_hwnd_;} |
| 119 |
| 120 // Modify/retrieve the state (active/inactive) of this instance. |
| 121 void set_instance_active(bool instance_active) { |
| 122 instance_active_ = instance_active; |
149 } | 123 } |
150 STDMETHODIMP put_accValue(VARIANT var_id, BSTR put_val) { | 124 int instance_active() const { return instance_active_; } |
151 return E_NOTIMPL; | 125 |
| 126 int routing_id() const { return routing_id_; } |
| 127 |
| 128 private: |
| 129 // Creates a VARIANT that will reference the current accessibility |
| 130 // object, not a child accessibility object. |
| 131 VARIANT ChildSelfVariant() const { |
| 132 VARIANT var; |
| 133 V_VT(&var) = VT_I4; |
| 134 V_I4(&var) = CHILDID_SELF; |
| 135 return var; |
152 } | 136 } |
153 | 137 |
154 // | 138 // Wrapper functions, calling through to singleton instance of |
155 // IAccessible2 methods. | 139 // BrowserAccessibilityManager. |
156 // | |
157 | 140 |
158 // Returns role from a longer list of possible roles. | 141 // Creates an instance of BrowserAccessibility, initializes it and sets the |
159 STDMETHODIMP role(LONG* role); | 142 // [iaccessible_id] and [parent_id]. |
| 143 STDMETHODIMP CreateInstance(REFIID iid, |
| 144 int iaccessible_id, |
| 145 void** interface_ptr); |
160 | 146 |
161 // Returns the state bitmask from a larger set of possible states. | 147 // Composes and sends a message for requesting needed accessibility |
162 STDMETHODIMP get_states(AccessibleStates* states); | 148 // information. Unused LONG input parameters should be NULL, and the VARIANT |
| 149 // an empty, valid instance. |
| 150 bool RequestAccessibilityInfo(int iaccessible_func_id, |
| 151 VARIANT var_id, |
| 152 LONG input1, LONG input2); |
163 | 153 |
164 // Get the unique ID of this object so that the client knows if it's | 154 // Accessors. |
165 // been encountered previously. | 155 const WebAccessibility::OutParams& response(); |
166 STDMETHODIMP get_uniqueID(LONG* unique_id); | |
167 | |
168 // Get the window handle of the enclosing window. | |
169 STDMETHODIMP get_windowHandle(HWND* window_handle); | |
170 | |
171 // Get this object's index in its parent object. | |
172 STDMETHODIMP get_indexInParent(LONG* index_in_parent); | |
173 | |
174 // IAccessible2 methods not implemented. | |
175 STDMETHODIMP get_extendedRole(BSTR* extended_role) { | |
176 return E_NOTIMPL; | |
177 } | |
178 STDMETHODIMP get_nRelations(LONG* n_relations) { | |
179 return E_NOTIMPL; | |
180 } | |
181 STDMETHODIMP get_relation(LONG relation_index, | |
182 IAccessibleRelation** relation) { | |
183 return E_NOTIMPL; | |
184 } | |
185 STDMETHODIMP get_relations(LONG max_relations, | |
186 IAccessibleRelation** relations, | |
187 LONG *n_relations) { | |
188 return E_NOTIMPL; | |
189 } | |
190 STDMETHODIMP scrollTo(enum IA2ScrollType scroll_type) { | |
191 return E_NOTIMPL; | |
192 } | |
193 STDMETHODIMP scrollToPoint(enum IA2CoordinateType coordinate_type, | |
194 LONG x, | |
195 LONG y) { | |
196 return E_NOTIMPL; | |
197 } | |
198 STDMETHODIMP get_groupPosition(LONG* group_level, | |
199 LONG* similar_items_in_group, | |
200 LONG* position_in_group) { | |
201 return E_NOTIMPL; | |
202 } | |
203 STDMETHODIMP get_localizedExtendedRole(BSTR* localized_extended_role) { | |
204 return E_NOTIMPL; | |
205 } | |
206 STDMETHODIMP get_nExtendedStates(LONG* n_extended_states) { | |
207 return E_NOTIMPL; | |
208 } | |
209 STDMETHODIMP get_extendedStates(LONG max_extended_states, | |
210 BSTR** extended_states, | |
211 LONG* n_extended_states) { | |
212 return E_NOTIMPL; | |
213 } | |
214 STDMETHODIMP get_localizedExtendedStates(LONG max_localized_extended_states, | |
215 BSTR** localized_extended_states, | |
216 LONG* n_localized_extended_states) { | |
217 return E_NOTIMPL; | |
218 } | |
219 STDMETHODIMP get_locale(IA2Locale* locale) { | |
220 return E_NOTIMPL; | |
221 } | |
222 STDMETHODIMP get_attributes(BSTR* attributes) { | |
223 return E_NOTIMPL; | |
224 } | |
225 | |
226 // | |
227 // IServiceProvider methods. | |
228 // | |
229 | |
230 STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void** object); | |
231 | |
232 private: | |
233 // Many MSAA methods take a var_id parameter indicating that the operation | |
234 // should be performed on a particular child ID, rather than this object. | |
235 // This method tries to figure out the target object from |var_id| and | |
236 // returns a pointer to the target object if it exists, otherwise NULL. | |
237 // Does not return a new reference. | |
238 BrowserAccessibility* GetTargetFromChildID(const VARIANT& var_id); | |
239 | 156 |
240 // Returns a conversion from the BrowserAccessibilityRole (as defined in | 157 // Returns a conversion from the BrowserAccessibilityRole (as defined in |
241 // webkit/glue/webaccessibility.h) to an MSAA role. | 158 // webkit/glue/webaccessibility.h) to an MSAA role. |
242 LONG MSAARole(LONG browser_accessibility_role); | 159 long MSAARole(long browser_accessibility_role); |
243 | 160 |
244 // Returns a conversion from the BrowserAccessibilityState (as defined in | 161 // Returns a conversion from the BrowserAccessibilityState (as defined in |
245 // webkit/glue/webaccessibility.h) to MSAA states set. | 162 // webkit/glue/webaccessibility.h) to MSAA states set. |
246 LONG MSAAState(LONG browser_accessibility_state); | 163 long MSAAState(long browser_accessibility_state); |
247 | 164 |
248 // The manager of this tree of accessibility objects; needed for | 165 // Id to uniquely distinguish this instance in the render-side caching, |
249 // global operations like focus tracking. | 166 // mapping it to the correct IAccessible on that side. Initialized to -1. |
250 BrowserAccessibilityManager* manager_; | 167 int iaccessible_id_; |
251 // The parent of this object, may be NULL if we're the root object. | |
252 BrowserAccessibility* parent_; | |
253 // The ID of this object; globally unique within the browser process. | |
254 LONG child_id_; | |
255 // The index of this within its parent object. | |
256 LONG index_in_parent_; | |
257 // The ID of this object in the renderer process. | |
258 int32 renderer_id_; | |
259 | 168 |
260 // The children of this object. | 169 // The unique ids of this IAccessible instance. Used to help |
261 std::vector<BrowserAccessibility*> children_; | 170 // BrowserAccessibilityManager instance retrieve the correct member |
| 171 // variables for this process. |
| 172 int routing_id_; |
| 173 int process_id_; |
262 | 174 |
263 // Accessibility metadata from the renderer, used to respond to MSAA | 175 HWND parent_hwnd_; |
264 // events. | |
265 string16 name_; | |
266 string16 value_; | |
267 string16 action_; | |
268 string16 description_; | |
269 string16 help_; | |
270 string16 shortcut_; | |
271 LONG role_; | |
272 LONG state_; | |
273 WebKit::WebRect location_; | |
274 | 176 |
275 // COM objects are reference-counted. When we're done with this object | 177 // The instance should only be active if there is a non-terminated |
276 // and it's removed from our accessibility tree, a client may still be | 178 // RenderProcessHost associated with it. The BrowserAccessibilityManager keeps |
277 // holding onto a pointer to this object, so we mark it as inactive | 179 // track of this state, and sets it to false to disable all calls into the |
278 // so that calls to any of this object's methods immediately return | 180 // renderer from this instance of BroweserAccessibility, and have all |
279 // failure. | 181 // IAccessible functions return E_FAIL. |
280 bool instance_active_; | 182 bool instance_active_; |
281 | 183 |
282 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); | 184 DISALLOW_COPY_AND_ASSIGN(BrowserAccessibility); |
283 }; | 185 }; |
284 | |
285 #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ | 186 #endif // CHROME_BROWSER_BROWSER_ACCESSIBILITY_H_ |
OLD | NEW |