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

Side by Side Diff: chrome/browser/browser_accessibility.cc

Issue 2031004: Revert 46567 - Reimplement accessibility of web content by caching the entire... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/browser_accessibility.h ('k') | chrome/browser/browser_accessibility_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/browser/browser_accessibility.h" 5 #include "chrome/browser/browser_accessibility.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "chrome/browser/browser_accessibility_manager.h" 8 #include "chrome/browser/browser_accessibility_manager.h"
9 9
10 using webkit_glue::WebAccessibility; 10 using webkit_glue::WebAccessibility;
11 11
12 BrowserAccessibility::BrowserAccessibility() 12 HRESULT BrowserAccessibility::Initialize(int iaccessible_id, int routing_id,
13 : manager_(NULL), 13 int process_id, HWND parent_hwnd) {
14 parent_(NULL), 14 // Check input parameters. Root id is 1000, to avoid conflicts with the ids
15 child_id_(-1), 15 // used by MSAA.
16 index_in_parent_(-1), 16 if (!parent_hwnd || iaccessible_id < 1000)
17 renderer_id_(-1), 17 return E_INVALIDARG;
18 instance_active_(false) { 18
19 iaccessible_id_ = iaccessible_id;
20 routing_id_ = routing_id;
21 process_id_ = process_id;
22 parent_hwnd_ = parent_hwnd;
23
24 // Mark instance as active.
25 instance_active_ = true;
26 return S_OK;
19 } 27 }
20 28
21 BrowserAccessibility::~BrowserAccessibility() {
22 InactivateTree();
23 }
24
25 void BrowserAccessibility::Initialize(
26 BrowserAccessibilityManager* manager,
27 BrowserAccessibility* parent,
28 LONG child_id,
29 LONG index_in_parent,
30 const webkit_glue::WebAccessibility& src) {
31 manager_ = manager;
32 parent_ = parent;
33 child_id_ = child_id;
34 index_in_parent_ = index_in_parent;
35
36 renderer_id_ = src.id;
37 name_ = src.name;
38 value_ = src.value;
39 action_ = src.action;
40 description_ = src.description;
41 help_ = src.help;
42 shortcut_ = src.shortcut;
43 role_ = MSAARole(src.role);
44 state_ = MSAAState(src.state);
45 location_ = src.location;
46
47 instance_active_ = true;
48
49 // Focused is a dynamic state, only one node will be focused at a time.
50 state_ &= ~STATE_SYSTEM_FOCUSED;
51 }
52
53 void BrowserAccessibility::AddChild(BrowserAccessibility* child) {
54 children_.push_back(child);
55 }
56
57 void BrowserAccessibility::InactivateTree() {
58 // Mark this object as inactive, so calls to all COM methods will return
59 // failure.
60 instance_active_ = false;
61
62 // Now we can safely call InactivateTree on our children and remove
63 // references to them, so that as much of the tree as possible will be
64 // destroyed now - however, nodes that still have references to them
65 // might stick around a while until all clients have released them.
66 for (std::vector<BrowserAccessibility*>::iterator iter =
67 children_.begin();
68 iter != children_.end(); ++iter) {
69 (*iter)->InactivateTree();
70 (*iter)->Release();
71 }
72 children_.clear();
73 }
74
75 bool BrowserAccessibility::IsDescendantOf(BrowserAccessibility* ancestor) {
76 if (this == ancestor) {
77 return true;
78 } else if (parent_) {
79 return parent_->IsDescendantOf(ancestor);
80 }
81
82 return false;
83 }
84
85 BrowserAccessibility* BrowserAccessibility::GetPreviousSibling() {
86 if (parent_ && index_in_parent_ > 0)
87 return parent_->children_[index_in_parent_ - 1];
88
89 return NULL;
90 }
91
92 BrowserAccessibility* BrowserAccessibility::GetNextSibling() {
93 if (parent_ &&
94 index_in_parent_ < static_cast<int>(parent_->children_.size() - 1)) {
95 return parent_->children_[index_in_parent_ + 1];
96 }
97
98 return NULL;
99 }
100
101 BrowserAccessibility* BrowserAccessibility::NewReference() {
102 AddRef();
103 return this;
104 }
105
106 //
107 // IAccessible methods.
108 //
109
110 HRESULT BrowserAccessibility::accDoDefaultAction(VARIANT var_id) { 29 HRESULT BrowserAccessibility::accDoDefaultAction(VARIANT var_id) {
111 if (!instance_active_) { 30 if (!instance_active()) {
112 // Instance no longer active, fail gracefully. 31 // Instance no longer active, fail gracefully.
32 // TODO(ctguil): Once we have MSAA events, change these fails to having
33 // BrowserAccessibilityManager firing the right event.
113 return E_FAIL; 34 return E_FAIL;
114 } 35 }
115 36
116 return E_NOTIMPL; 37 if (var_id.vt != VT_I4)
38 return E_INVALIDARG;
39
40 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_DODEFAULTACTION,
41 var_id, NULL, NULL)) {
42 return E_FAIL;
43 }
44
45 if (response().return_code == WebAccessibility::RETURNCODE_FALSE)
46 return S_FALSE;
47
48 return S_OK;
117 } 49 }
118 50
119 STDMETHODIMP BrowserAccessibility::accHitTest(LONG x_left, LONG y_top, 51 STDMETHODIMP BrowserAccessibility::accHitTest(LONG x_left, LONG y_top,
120 VARIANT* child) { 52 VARIANT* child) {
121 if (!instance_active_) { 53 if (!instance_active()) {
122 // Instance no longer active, fail gracefully. 54 // Instance no longer active, fail gracefully.
123 return E_FAIL; 55 return E_FAIL;
124 } 56 }
125 57
126 if (!child) 58 if (!child)
127 return E_INVALIDARG; 59 return E_INVALIDARG;
128 60
129 return E_NOTIMPL; 61 if (!parent_hwnd_) {
62 // Parent HWND needed for coordinate conversion.
63 return E_FAIL;
64 }
65
66 // Convert coordinates to test from screen into client window coordinates, to
67 // maintain sandbox functionality on renderer side.
68 POINT p = {x_left, y_top};
69 ::ScreenToClient(parent_hwnd_, &p);
70
71 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_HITTEST,
72 ChildSelfVariant(), p.x, p.y)) {
73 return E_FAIL;
74 }
75
76 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
77 // The point is outside of the object's boundaries.
78 child->vt = VT_EMPTY;
79 return S_FALSE;
80 }
81
82 if (response().output_long1 == -1) {
83 if (CreateInstance(IID_IAccessible, response().object_id,
84 reinterpret_cast<void**>(&child->pdispVal)) == S_OK) {
85 child->vt = VT_DISPATCH;
86 // Increment the reference count for the retrieved interface.
87 child->pdispVal->AddRef();
88 } else {
89 return E_NOINTERFACE;
90 }
91 } else {
92 child->vt = VT_I4;
93 child->lVal = response().output_long1;
94 }
95
96 return S_OK;
130 } 97 }
131 98
132 STDMETHODIMP BrowserAccessibility::accLocation(LONG* x_left, LONG* y_top, 99 STDMETHODIMP BrowserAccessibility::accLocation(LONG* x_left, LONG* y_top,
133 LONG* width, LONG* height, 100 LONG* width, LONG* height,
134 VARIANT var_id) { 101 VARIANT var_id) {
135 if (!instance_active_) { 102 if (!instance_active()) {
136 // Instance no longer active, fail gracefully. 103 // Instance no longer active, fail gracefully.
137 return E_FAIL; 104 return E_FAIL;
138 } 105 }
139 106
140 if (!x_left || !y_top || !width || !height) 107 if (var_id.vt != VT_I4 || !x_left || !y_top || !width || !height ||
108 !parent_hwnd_) {
141 return E_INVALIDARG; 109 return E_INVALIDARG;
110 }
142 111
143 BrowserAccessibility* target = GetTargetFromChildID(var_id); 112 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_LOCATION, var_id,
144 if (!target) 113 NULL, NULL)) {
145 return E_INVALIDARG; 114 return E_FAIL;
115 }
116
117 POINT top_left = {0, 0};
146 118
147 // Find the top left corner of the containing window in screen coords, and 119 // Find the top left corner of the containing window in screen coords, and
148 // adjust the output position by this amount. 120 // adjust the output position by this amount.
149 HWND parent_hwnd = manager_->GetParentHWND(); 121 ::ClientToScreen(parent_hwnd_, &top_left);
150 POINT top_left = {0, 0};
151 ::ClientToScreen(parent_hwnd, &top_left);
152 122
153 *x_left = target->location_.x + top_left.x; 123 *x_left = response().output_long1 + top_left.x;
154 *y_top = target->location_.y + top_left.y; 124 *y_top = response().output_long2 + top_left.y;
155 *width = target->location_.width; 125
156 *height = target->location_.height; 126 *width = response().output_long3;
127 *height = response().output_long4;
157 128
158 return S_OK; 129 return S_OK;
159 } 130 }
160 131
161 STDMETHODIMP BrowserAccessibility::accNavigate( 132 STDMETHODIMP BrowserAccessibility::accNavigate(LONG nav_dir, VARIANT start,
162 LONG nav_dir, VARIANT start, VARIANT* end) { 133 VARIANT* end) {
163 BrowserAccessibility* target = GetTargetFromChildID(start); 134 if (!instance_active()) {
164 if (!target) 135 // Instance no longer active, fail gracefully.
136 return E_FAIL;
137 }
138
139 if (start.vt != VT_I4 || !end)
165 return E_INVALIDARG; 140 return E_INVALIDARG;
166 141
167 if ((nav_dir == NAVDIR_LASTCHILD || nav_dir == NAVDIR_FIRSTCHILD) && 142 if ((nav_dir == NAVDIR_LASTCHILD || nav_dir == NAVDIR_FIRSTCHILD) &&
168 start.lVal != CHILDID_SELF) { 143 start.lVal != CHILDID_SELF) {
169 // MSAA states that navigating to first/last child can only be from self. 144 // MSAA states that navigating to first/last child can only be from self.
170 return E_INVALIDARG; 145 return E_INVALIDARG;
171 } 146 }
172 147
173 BrowserAccessibility* result; 148 if (nav_dir == NAVDIR_DOWN || nav_dir == NAVDIR_UP ||
174 switch (nav_dir) { 149 nav_dir == NAVDIR_LEFT || nav_dir == NAVDIR_RIGHT) {
175 case NAVDIR_DOWN: 150 // Directions not implemented, matching Mozilla and IE.
176 case NAVDIR_UP: 151 return E_INVALIDARG;
177 case NAVDIR_LEFT:
178 case NAVDIR_RIGHT:
179 // These directions are not implemented, matching Mozilla and IE.
180 return E_NOTIMPL;
181 case NAVDIR_FIRSTCHILD:
182 if (target->children_.size() > 0)
183 result = target->children_[0];
184 break;
185 case NAVDIR_LASTCHILD:
186 if (target->children_.size() > 0)
187 result = target->children_[target->children_.size() - 1];
188 break;
189 case NAVDIR_NEXT:
190 result = target->GetNextSibling();
191 break;
192 case NAVDIR_PREVIOUS:
193 result = target->GetPreviousSibling();
194 break;
195 } 152 }
196 153
197 if (!result) { 154 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_NAVIGATE, start,
155 nav_dir, NULL)) {
156 return E_FAIL;
157 }
158
159 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
160 // No screen element was found in the specified direction.
198 end->vt = VT_EMPTY; 161 end->vt = VT_EMPTY;
199 return S_FALSE; 162 return S_FALSE;
200 } 163 }
201 164
202 end->vt = VT_DISPATCH; 165 if (response().output_long1 == -1) {
203 end->pdispVal = result->NewReference(); 166 if (CreateInstance(IID_IAccessible, response().object_id,
167 reinterpret_cast<void**>(&end->pdispVal)) == S_OK) {
168 end->vt = VT_DISPATCH;
169 // Increment the reference count for the retrieved interface.
170 end->pdispVal->AddRef();
171 } else {
172 return E_NOINTERFACE;
173 }
174 } else {
175 end->vt = VT_I4;
176 end->lVal = response().output_long1;
177 }
178
204 return S_OK; 179 return S_OK;
205 } 180 }
206 181
207 STDMETHODIMP BrowserAccessibility::get_accChild(VARIANT var_child, 182 STDMETHODIMP BrowserAccessibility::get_accChild(VARIANT var_child,
208 IDispatch** disp_child) { 183 IDispatch** disp_child) {
209 if (!instance_active_) { 184 if (!instance_active()) {
210 // Instance no longer active, fail gracefully. 185 // Instance no longer active, fail gracefully.
211 return E_FAIL; 186 return E_FAIL;
212 } 187 }
213 188
214 if (!disp_child) 189 if (var_child.vt != VT_I4 || !disp_child)
215 return E_INVALIDARG; 190 return E_INVALIDARG;
216 191
217 *disp_child = NULL; 192 // If var_child is the parent, remain with the same IDispatch.
193 if (var_child.lVal == CHILDID_SELF && iaccessible_id_ != 1000)
194 return S_OK;
218 195
219 BrowserAccessibility* target = GetTargetFromChildID(var_child); 196 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_GETCHILD, var_child,
220 if (!target) 197 NULL, NULL)) {
221 return E_INVALIDARG; 198 return E_FAIL;
199 }
222 200
223 (*disp_child) = target->NewReference(); 201 // TODO(ctguil): Figure out when the return code would be false
224 return S_OK; 202 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
203 // When at a leaf, children are handled by the parent object.
204 *disp_child = NULL;
205 return S_FALSE;
206 }
207
208 // Retrieve the IUnknown interface for the parent view, and assign the
209 // IDispatch returned.
210 if (CreateInstance(IID_IAccessible, response().object_id,
211 reinterpret_cast<void**>(disp_child)) == S_OK) {
212 // Increment the reference count for the retrieved interface.
213 (*disp_child)->AddRef();
214 return S_OK;
215 } else {
216 return E_NOINTERFACE;
217 }
225 } 218 }
226 219
227 STDMETHODIMP BrowserAccessibility::get_accChildCount(LONG* child_count) { 220 STDMETHODIMP BrowserAccessibility::get_accChildCount(LONG* child_count) {
228 if (!instance_active_) { 221 if (!instance_active()) {
229 // Instance no longer active, fail gracefully. 222 // Instance no longer active, fail gracefully.
230 return E_FAIL; 223 return E_FAIL;
231 } 224 }
232 225
233 if (!child_count) 226 if (!child_count)
234 return E_INVALIDARG; 227 return E_INVALIDARG;
235 228
236 *child_count = children_.size(); 229 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_CHILDCOUNT,
230 ChildSelfVariant(), NULL, NULL)) {
231 return E_FAIL;
232 }
233
234 *child_count = response().output_long1;
237 return S_OK; 235 return S_OK;
238 } 236 }
239 237
240 STDMETHODIMP BrowserAccessibility::get_accDefaultAction(VARIANT var_id, 238 STDMETHODIMP BrowserAccessibility::get_accDefaultAction(VARIANT var_id,
241 BSTR* def_action) { 239 BSTR* def_action) {
242 if (!instance_active_) { 240 if (!instance_active()) {
243 // Instance no longer active, fail gracefully. 241 // Instance no longer active, fail gracefully.
244 return E_FAIL; 242 return E_FAIL;
245 } 243 }
246 244
247 if (!def_action) 245 if (var_id.vt != VT_I4 || !def_action)
248 return E_INVALIDARG; 246 return E_INVALIDARG;
249 247
250 BrowserAccessibility* target = GetTargetFromChildID(var_id); 248 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_DEFAULTACTION,
251 if (!target) 249 var_id, NULL, NULL)) {
252 return E_INVALIDARG; 250 return E_FAIL;
251 }
253 252
254 // Return false if the string is empty. 253 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
255 if (target->action_.size() == 0) 254 // No string found.
256 return S_FALSE; 255 return S_FALSE;
256 }
257 257
258 *def_action = SysAllocString(target->action_.c_str()); 258 *def_action = SysAllocString(response().output_string.c_str());
259 259
260 DCHECK(*def_action); 260 DCHECK(*def_action);
261 return S_OK; 261 return S_OK;
262 } 262 }
263 263
264 STDMETHODIMP BrowserAccessibility::get_accDescription(VARIANT var_id, 264 STDMETHODIMP BrowserAccessibility::get_accDescription(VARIANT var_id,
265 BSTR* desc) { 265 BSTR* desc) {
266 if (!instance_active_) { 266 if (!instance_active()) {
267 // Instance no longer active, fail gracefully. 267 // Instance no longer active, fail gracefully.
268 return E_FAIL; 268 return E_FAIL;
269 } 269 }
270 270
271 if (!desc) 271 if (var_id.vt != VT_I4 || !desc)
272 return E_INVALIDARG; 272 return E_INVALIDARG;
273 273
274 BrowserAccessibility* target = GetTargetFromChildID(var_id); 274 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_DESCRIPTION, var_id,
275 if (!target) 275 NULL, NULL)) {
276 return E_INVALIDARG; 276 return E_FAIL;
277 }
277 278
278 // Return false if the string is empty. 279 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
279 if (target->description_.size() == 0) 280 // No string found.
280 return S_FALSE; 281 return S_FALSE;
282 }
281 283
282 *desc = SysAllocString(target->description_.c_str()); 284 *desc = SysAllocString(response().output_string.c_str());
283 285
284 DCHECK(*desc); 286 DCHECK(*desc);
285 return S_OK; 287 return S_OK;
286 } 288 }
287 289
288 STDMETHODIMP BrowserAccessibility::get_accFocus(VARIANT* focus_child) { 290 STDMETHODIMP BrowserAccessibility::get_accFocus(VARIANT* focus_child) {
289 if (!instance_active_) { 291 if (!instance_active()) {
290 // Instance no longer active, fail gracefully. 292 // Instance no longer active, fail gracefully.
291 return E_FAIL; 293 return E_FAIL;
292 } 294 }
293 295
294 if (!focus_child) 296 if (!focus_child)
295 return E_INVALIDARG; 297 return E_INVALIDARG;
296 298
297 BrowserAccessibility* focus = manager_->GetFocus(this); 299 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_GETFOCUSEDCHILD,
298 if (focus == this) { 300 ChildSelfVariant(), NULL, NULL)) {
301 return E_FAIL;
302 }
303
304 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
305 // The window that contains this object is not the active window.
306 focus_child->vt = VT_EMPTY;
307 return S_FALSE;
308 }
309
310 if (response().output_long1 == -1) {
311 if (CreateInstance(IID_IAccessible, response().object_id,
312 reinterpret_cast<void**>(&focus_child->pdispVal)) == S_OK) {
313 focus_child->vt = VT_DISPATCH;
314 // Increment the reference count for the retrieved interface.
315 focus_child->pdispVal->AddRef();
316 } else {
317 return E_NOINTERFACE;
318 }
319 } else {
299 focus_child->vt = VT_I4; 320 focus_child->vt = VT_I4;
300 focus_child->lVal = CHILDID_SELF; 321 focus_child->lVal = response().output_long1;
301 } else if (focus == NULL) {
302 focus_child->vt = VT_EMPTY;
303 } else {
304 focus_child->vt = VT_DISPATCH;
305 focus_child->pdispVal = focus->NewReference();
306 } 322 }
307 323
308 return S_OK; 324 return S_OK;
309 } 325 }
310 326
311 STDMETHODIMP BrowserAccessibility::get_accHelp(VARIANT var_id, BSTR* help) { 327 STDMETHODIMP BrowserAccessibility::get_accHelp(VARIANT var_id, BSTR* help) {
312 if (!instance_active_) { 328 if (!instance_active()) {
313 // Instance no longer active, fail gracefully. 329 // Instance no longer active, fail gracefully.
314 return E_FAIL; 330 return E_FAIL;
315 } 331 }
316 332
317 if (!help) 333 if (var_id.vt != VT_I4 || !help)
318 return E_INVALIDARG; 334 return E_INVALIDARG;
319 335
320 BrowserAccessibility* target = GetTargetFromChildID(var_id); 336 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_HELPTEXT, var_id,
321 if (!target) 337 NULL, NULL)) {
322 return E_INVALIDARG; 338 return E_FAIL;
339 }
323 340
324 // Return false if the string is empty. 341 if (response().return_code == WebAccessibility::RETURNCODE_FALSE ||
325 if (target->help_.size() == 0) 342 response().output_string.empty()) {
343 // No string found.
326 return S_FALSE; 344 return S_FALSE;
345 }
327 346
328 *help = SysAllocString(target->help_.c_str()); 347 *help = SysAllocString(response().output_string.c_str());
329 348
330 DCHECK(*help); 349 DCHECK(*help);
331 return S_OK; 350 return S_OK;
332 } 351 }
333 352
334 STDMETHODIMP BrowserAccessibility::get_accKeyboardShortcut(VARIANT var_id, 353 STDMETHODIMP BrowserAccessibility::get_accKeyboardShortcut(VARIANT var_id,
335 BSTR* acc_key) { 354 BSTR* acc_key) {
336 if (!instance_active_) { 355 if (!instance_active()) {
337 // Instance no longer active, fail gracefully. 356 // Instance no longer active, fail gracefully.
338 return E_FAIL; 357 return E_FAIL;
339 } 358 }
340 359
341 if (!acc_key) 360 if (var_id.vt != VT_I4 || !acc_key)
342 return E_INVALIDARG; 361 return E_INVALIDARG;
343 362
344 BrowserAccessibility* target = GetTargetFromChildID(var_id); 363 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_KEYBOARDSHORTCUT,
345 if (!target) 364 var_id, NULL, NULL)) {
346 return E_INVALIDARG; 365 return E_FAIL;
366 }
347 367
348 // Return false if the string is empty. 368 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
349 if (target->shortcut_.size() == 0) 369 // No string found.
350 return S_FALSE; 370 return S_FALSE;
371 }
351 372
352 *acc_key = SysAllocString(target->shortcut_.c_str()); 373 *acc_key = SysAllocString(response().output_string.c_str());
353 374
354 DCHECK(*acc_key); 375 DCHECK(*acc_key);
355 return S_OK; 376 return S_OK;
356 } 377 }
357 378
358 STDMETHODIMP BrowserAccessibility::get_accName(VARIANT var_id, BSTR* name) { 379 STDMETHODIMP BrowserAccessibility::get_accName(VARIANT var_id, BSTR* name) {
359 if (!instance_active_) { 380 if (!instance_active()) {
360 // Instance no longer active, fail gracefully. 381 // Instance no longer active, fail gracefully.
361 return E_FAIL; 382 return E_FAIL;
362 } 383 }
363 384
364 if (!name) 385 if (var_id.vt != VT_I4 || !name)
365 return E_INVALIDARG; 386 return E_INVALIDARG;
366 387
367 BrowserAccessibility* target = GetTargetFromChildID(var_id); 388 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_NAME, var_id, NULL,
368 if (!target) 389 NULL)) {
369 return E_INVALIDARG; 390 return E_FAIL;
391 }
370 392
371 // Return false if the string is empty. 393 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
372 if (target->name_.size() == 0) 394 // No string found.
373 return S_FALSE; 395 return S_FALSE;
396 }
374 397
375 *name = SysAllocString(target->name_.c_str()); 398 *name = SysAllocString(response().output_string.c_str());
376 399
377 DCHECK(*name); 400 DCHECK(*name);
378 return S_OK; 401 return S_OK;
379 } 402 }
380 403
381 STDMETHODIMP BrowserAccessibility::get_accParent(IDispatch** disp_parent) { 404 STDMETHODIMP BrowserAccessibility::get_accParent(IDispatch** disp_parent) {
382 if (!instance_active_) { 405 if (!instance_active()) {
383 // Instance no longer active, fail gracefully. 406 // Instance no longer active, fail gracefully.
384 return E_FAIL; 407 return E_FAIL;
385 } 408 }
386 409
387 if (!disp_parent) 410 if (!disp_parent || !parent_hwnd_)
388 return E_INVALIDARG; 411 return E_INVALIDARG;
389 412
390 IAccessible* parent = parent_; 413 // Root node's parent is the containing HWND's IAccessible.
391 if (parent == NULL) { 414 if (iaccessible_id_ == 1000) {
392 // This happens if we're the root of the tree; 415 // For an object that has no parent (e.g. root), point the accessible parent
393 // return the IAccessible for the window. 416 // to the default implementation.
394 parent = manager_->GetParentWindowIAccessible(); 417 HRESULT hr =
418 ::CreateStdAccessibleObject(parent_hwnd_, OBJID_WINDOW,
419 IID_IAccessible,
420 reinterpret_cast<void**>(disp_parent));
421
422 if (!SUCCEEDED(hr)) {
423 *disp_parent = NULL;
424 return S_FALSE;
425 }
426 return S_OK;
395 } 427 }
396 428
397 parent->AddRef(); 429 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_GETPARENT,
398 *disp_parent = parent; 430 ChildSelfVariant(), NULL, NULL)) {
399 return S_OK; 431 return E_FAIL;
432 }
433
434 if (response().return_code == WebAccessibility::RETURNCODE_FALSE) {
435 // No parent exists for this object.
436 return S_FALSE;
437 }
438
439 // Retrieve the IUnknown interface for the parent view, and assign the
440 // IDispatch returned.
441 if (CreateInstance(IID_IAccessible, response().object_id,
442 reinterpret_cast<void**>(disp_parent)) == S_OK) {
443 // Increment the reference count for the retrieved interface.
444 (*disp_parent)->AddRef();
445 return S_OK;
446 } else {
447 return E_NOINTERFACE;
448 }
400 } 449 }
401 450
402 STDMETHODIMP BrowserAccessibility::get_accRole(VARIANT var_id, VARIANT* role) { 451 STDMETHODIMP BrowserAccessibility::get_accRole(VARIANT var_id, VARIANT* role) {
403 if (!instance_active_) { 452 if (!instance_active()) {
404 // Instance no longer active, fail gracefully. 453 // Instance no longer active, fail gracefully.
405 return E_FAIL; 454 return E_FAIL;
406 } 455 }
407 456
408 if (!role) 457 if (var_id.vt != VT_I4 || !role)
409 return E_INVALIDARG; 458 return E_INVALIDARG;
410 459
411 BrowserAccessibility* target = GetTargetFromChildID(var_id); 460 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_ROLE, var_id, NULL,
412 if (!target) 461 NULL)) {
413 return E_INVALIDARG; 462 return E_FAIL;
463 }
414 464
415 role->vt = VT_I4; 465 role->vt = VT_I4;
416 role->lVal = target->role_; 466 role->lVal = MSAARole(response().output_long1);
417 return S_OK; 467 return S_OK;
418 } 468 }
419 469
420 STDMETHODIMP BrowserAccessibility::get_accState(VARIANT var_id, 470 STDMETHODIMP BrowserAccessibility::get_accState(VARIANT var_id,
421 VARIANT* state) { 471 VARIANT* state) {
422 if (!instance_active_) { 472 if (!instance_active()) {
423 // Instance no longer active, fail gracefully. 473 // Instance no longer active, fail gracefully.
424 return E_FAIL; 474 return E_FAIL;
425 } 475 }
426 476
427 if (!state) 477 if (var_id.vt != VT_I4 || !state)
428 return E_INVALIDARG; 478 return E_INVALIDARG;
429 479
430 BrowserAccessibility* target = GetTargetFromChildID(var_id); 480 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_STATE, var_id, NULL,
431 if (!target) 481 NULL)) {
432 return E_INVALIDARG; 482 return E_FAIL;
483 }
433 484
434 state->vt = VT_I4; 485 state->vt = VT_I4;
435 state->lVal = target->state_; 486 state->lVal = MSAAState(response().output_long1);
436 if (manager_->GetFocus(NULL) == this)
437 state->lVal |= STATE_SYSTEM_FOCUSED;
438
439 return S_OK; 487 return S_OK;
440 } 488 }
441 489
442 STDMETHODIMP BrowserAccessibility::get_accValue(VARIANT var_id, BSTR* value) { 490 STDMETHODIMP BrowserAccessibility::get_accValue(VARIANT var_id, BSTR* value) {
443 if (!instance_active_) { 491 if (!instance_active()) {
444 // Instance no longer active, fail gracefully. 492 // Instance no longer active, fail gracefully.
445 return E_FAIL; 493 return E_FAIL;
446 } 494 }
447 495
448 if (!value) 496 if (var_id.vt != VT_I4 || !value)
449 return E_INVALIDARG; 497 return E_INVALIDARG;
450 498
451 BrowserAccessibility* target = GetTargetFromChildID(var_id); 499 if (!RequestAccessibilityInfo(WebAccessibility::FUNCTION_VALUE, var_id, NULL,
452 if (!target) 500 NULL)) {
453 return E_INVALIDARG; 501 return E_FAIL;
502 }
454 503
455 *value = SysAllocString(target->value_.c_str()); 504 if (response().return_code == WebAccessibility::RETURNCODE_FALSE ||
505 response().output_string.empty()) {
506 // No string found.
507 return S_FALSE;
508 }
509
510 *value = SysAllocString(response().output_string.c_str());
456 511
457 DCHECK(*value); 512 DCHECK(*value);
458 return S_OK; 513 return S_OK;
459 } 514 }
460 515
461 STDMETHODIMP BrowserAccessibility::get_accHelpTopic(BSTR* help_file, 516 STDMETHODIMP BrowserAccessibility::get_accHelpTopic(BSTR* help_file,
462 VARIANT var_id, 517 VARIANT var_id,
463 LONG* topic_id) { 518 LONG* topic_id) {
519 if (help_file)
520 *help_file = NULL;
521
522 if (topic_id)
523 *topic_id = static_cast<LONG>(-1);
524
464 return E_NOTIMPL; 525 return E_NOTIMPL;
465 } 526 }
466 527
467 STDMETHODIMP BrowserAccessibility::get_accSelection(VARIANT* selected) { 528 STDMETHODIMP BrowserAccessibility::get_accSelection(VARIANT* selected) {
468 if (!instance_active_) { 529 if (selected)
469 // Instance no longer active, fail gracefully. 530 selected->vt = VT_EMPTY;
470 return E_FAIL;
471 }
472 531
473 return E_NOTIMPL; 532 return E_NOTIMPL;
474 } 533 }
475 534
476 STDMETHODIMP BrowserAccessibility::accSelect(LONG flags_sel, VARIANT var_id) { 535 STDMETHODIMP BrowserAccessibility::CreateInstance(REFIID iid,
477 if (!instance_active_) { 536 int iaccessible_id,
478 // Instance no longer active, fail gracefully. 537 void** interface_ptr) {
479 return E_FAIL; 538 return BrowserAccessibilityManager::GetInstance()->
480 } 539 CreateAccessibilityInstance(iid, iaccessible_id, routing_id_,
481 540 process_id_, parent_hwnd_, interface_ptr);
482 return E_NOTIMPL;
483 } 541 }
484 542
485 // 543 bool BrowserAccessibility::RequestAccessibilityInfo(int iaccessible_func_id,
486 // IAccessible2 methods. 544 VARIANT var_id, LONG input1,
487 // 545 LONG input2) {
546 DCHECK(V_VT(&var_id) == VT_I4);
488 547
489 STDMETHODIMP BrowserAccessibility::role(LONG* role) { 548 // Create and populate IPC message structure, for retrieval of accessibility
490 if (!instance_active_) { 549 // information from the renderer.
491 // Instance no longer active, fail gracefully. 550 WebAccessibility::InParams in_params;
492 return E_FAIL; 551 in_params.object_id = iaccessible_id_;
493 } 552 in_params.function_id = iaccessible_func_id;
553 in_params.child_id = V_I4(&var_id);
554 in_params.input_long1 = input1;
555 in_params.input_long2 = input2;
494 556
495 if (!role) 557 return BrowserAccessibilityManager::GetInstance()->
496 return E_INVALIDARG; 558 RequestAccessibilityInfo(&in_params, routing_id_, process_id_) &&
497 559 response().return_code != WebAccessibility::RETURNCODE_FAIL;
498 *role = role_;
499
500 return S_OK;
501 } 560 }
502 561
503 STDMETHODIMP BrowserAccessibility::get_states(AccessibleStates* states) { 562 const WebAccessibility::OutParams& BrowserAccessibility::response() {
504 if (!instance_active_) { 563 return BrowserAccessibilityManager::GetInstance()->response();
505 // Instance no longer active, fail gracefully.
506 return E_FAIL;
507 }
508
509 if (!states)
510 return E_INVALIDARG;
511
512 *states = state_;
513
514 return S_OK;
515 } 564 }
516 565
517 STDMETHODIMP BrowserAccessibility::get_uniqueID(LONG* unique_id) { 566 long BrowserAccessibility::MSAARole(long browser_accessibility_role) {
518 if (!instance_active_) {
519 // Instance no longer active, fail gracefully.
520 return E_FAIL;
521 }
522
523 if (!unique_id)
524 return E_INVALIDARG;
525
526 *unique_id = child_id_;
527 return S_OK;
528 }
529
530 STDMETHODIMP BrowserAccessibility::get_windowHandle(HWND* window_handle) {
531 if (!instance_active_) {
532 // Instance no longer active, fail gracefully.
533 return E_FAIL;
534 }
535
536 if (!window_handle)
537 return E_INVALIDARG;
538
539 *window_handle = manager_->GetParentHWND();
540 return S_OK;
541 }
542
543 STDMETHODIMP BrowserAccessibility::get_indexInParent(LONG* index_in_parent) {
544 if (!instance_active_) {
545 // Instance no longer active, fail gracefully.
546 return E_FAIL;
547 }
548
549 if (!index_in_parent)
550 return E_INVALIDARG;
551
552 *index_in_parent = index_in_parent_;
553 return S_OK;
554 }
555
556 //
557 // IServiceProvider methods.
558 //
559
560 STDMETHODIMP BrowserAccessibility::QueryService(
561 REFGUID guidService, REFIID riid, void** object) {
562 if (!instance_active_) {
563 // Instance no longer active, fail gracefully.
564 return E_FAIL;
565 }
566
567 if (guidService == IID_IAccessible || guidService == IID_IAccessible2)
568 return QueryInterface(riid, object);
569
570 *object = NULL;
571 return E_FAIL;
572 }
573
574 //
575 // Private methods.
576 //
577
578 BrowserAccessibility* BrowserAccessibility::GetTargetFromChildID(
579 const VARIANT& var_id) {
580 if (var_id.vt != VT_I4)
581 return NULL;
582
583 LONG child_id = var_id.lVal;
584 if (child_id == CHILDID_SELF)
585 return this;
586
587 if (child_id >= 1 && child_id <= static_cast<LONG>(children_.size()))
588 return children_[child_id - 1];
589
590 return manager_->GetFromChildID(child_id);
591 }
592
593 LONG BrowserAccessibility::MSAARole(LONG browser_accessibility_role) {
594 switch (browser_accessibility_role) { 567 switch (browser_accessibility_role) {
595 case WebAccessibility::ROLE_APPLICATION: 568 case WebAccessibility::ROLE_APPLICATION:
596 return ROLE_SYSTEM_APPLICATION; 569 return ROLE_SYSTEM_APPLICATION;
597 case WebAccessibility::ROLE_CELL: 570 case WebAccessibility::ROLE_CELL:
598 return ROLE_SYSTEM_CELL; 571 return ROLE_SYSTEM_CELL;
599 case WebAccessibility::ROLE_CHECKBUTTON: 572 case WebAccessibility::ROLE_CHECKBUTTON:
600 return ROLE_SYSTEM_CHECKBUTTON; 573 return ROLE_SYSTEM_CHECKBUTTON;
601 case WebAccessibility::ROLE_COLUMN: 574 case WebAccessibility::ROLE_COLUMN:
602 return ROLE_SYSTEM_COLUMN; 575 return ROLE_SYSTEM_COLUMN;
603 case WebAccessibility::ROLE_COLUMNHEADER: 576 case WebAccessibility::ROLE_COLUMNHEADER:
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
651 return ROLE_SYSTEM_TOOLBAR; 624 return ROLE_SYSTEM_TOOLBAR;
652 case WebAccessibility::ROLE_TOOLTIP: 625 case WebAccessibility::ROLE_TOOLTIP:
653 return ROLE_SYSTEM_TOOLTIP; 626 return ROLE_SYSTEM_TOOLTIP;
654 case WebAccessibility::ROLE_CLIENT: 627 case WebAccessibility::ROLE_CLIENT:
655 default: 628 default:
656 // This is the default role for MSAA. 629 // This is the default role for MSAA.
657 return ROLE_SYSTEM_CLIENT; 630 return ROLE_SYSTEM_CLIENT;
658 } 631 }
659 } 632 }
660 633
661 LONG BrowserAccessibility::MSAAState(LONG browser_accessibility_state) { 634 long BrowserAccessibility::MSAAState(long browser_accessibility_state) {
662 LONG state = 0; 635 long state = 0;
663 636
664 if ((browser_accessibility_state >> WebAccessibility::STATE_CHECKED) & 1) 637 if ((browser_accessibility_state >> WebAccessibility::STATE_CHECKED) & 1)
665 state |= STATE_SYSTEM_CHECKED; 638 state |= STATE_SYSTEM_CHECKED;
666 639
667 if ((browser_accessibility_state >> WebAccessibility::STATE_FOCUSABLE) & 1) 640 if ((browser_accessibility_state >> WebAccessibility::STATE_FOCUSABLE) & 1)
668 state |= STATE_SYSTEM_FOCUSABLE; 641 state |= STATE_SYSTEM_FOCUSABLE;
669 642
670 if ((browser_accessibility_state >> WebAccessibility::STATE_FOCUSED) & 1) 643 if ((browser_accessibility_state >> WebAccessibility::STATE_FOCUSED) & 1)
671 state |= STATE_SYSTEM_FOCUSED; 644 state |= STATE_SYSTEM_FOCUSED;
672 645
(...skipping 26 matching lines...) Expand all
699 state |= STATE_SYSTEM_READONLY; 672 state |= STATE_SYSTEM_READONLY;
700 673
701 if ((browser_accessibility_state >> WebAccessibility::STATE_TRAVERSED) & 1) 674 if ((browser_accessibility_state >> WebAccessibility::STATE_TRAVERSED) & 1)
702 state |= STATE_SYSTEM_TRAVERSED; 675 state |= STATE_SYSTEM_TRAVERSED;
703 676
704 if ((browser_accessibility_state >> WebAccessibility::STATE_UNAVAILABLE) & 1) 677 if ((browser_accessibility_state >> WebAccessibility::STATE_UNAVAILABLE) & 1)
705 state |= STATE_SYSTEM_UNAVAILABLE; 678 state |= STATE_SYSTEM_UNAVAILABLE;
706 679
707 return state; 680 return state;
708 } 681 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_accessibility.h ('k') | chrome/browser/browser_accessibility_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698