OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_frame/test/chrome_frame_ui_test_utils.h" | 5 #include "chrome_frame/test/chrome_frame_ui_test_utils.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include <sstream> | 9 #include <sstream> |
10 #include <stack> | 10 #include <stack> |
(...skipping 19 matching lines...) Expand all Loading... |
30 const int kChromeDOMAccessibilityTreeTimeoutMs = 10 * 1000; | 30 const int kChromeDOMAccessibilityTreeTimeoutMs = 10 * 1000; |
31 | 31 |
32 // Timeout for waiting on a menu to popup. | 32 // Timeout for waiting on a menu to popup. |
33 const int kMenuPopupTimeoutMs = 10 * 1000; | 33 const int kMenuPopupTimeoutMs = 10 * 1000; |
34 | 34 |
35 // AccObject methods | 35 // AccObject methods |
36 AccObject::AccObject(IAccessible* accessible, int child_id) | 36 AccObject::AccObject(IAccessible* accessible, int child_id) |
37 : accessible_(accessible), child_id_(child_id) { | 37 : accessible_(accessible), child_id_(child_id) { |
38 DCHECK(accessible); | 38 DCHECK(accessible); |
39 if (child_id != CHILDID_SELF) { | 39 if (child_id != CHILDID_SELF) { |
40 ScopedComPtr<IDispatch> dispatch; | 40 base::win::ScopedComPtr<IDispatch> dispatch; |
41 // This class does not support referring to a full MSAA object using the | 41 // This class does not support referring to a full MSAA object using the |
42 // parent object and the child id. | 42 // parent object and the child id. |
43 HRESULT result = accessible_->get_accChild(child_id_, dispatch.Receive()); | 43 HRESULT result = accessible_->get_accChild(child_id_, dispatch.Receive()); |
44 if (result != S_FALSE && result != E_NOINTERFACE) { | 44 if (result != S_FALSE && result != E_NOINTERFACE) { |
45 LOG(ERROR) << "AccObject created which refers to full MSAA object using " | 45 LOG(ERROR) << "AccObject created which refers to full MSAA object using " |
46 "parent object and child id. This should NOT be done."; | 46 "parent object and child id. This should NOT be done."; |
47 } | 47 } |
48 DCHECK(result == S_FALSE || result == E_NOINTERFACE); | 48 DCHECK(result == S_FALSE || result == E_NOINTERFACE); |
49 } | 49 } |
50 } | 50 } |
51 | 51 |
52 // static | 52 // static |
53 AccObject* AccObject::CreateFromWindow(HWND hwnd) { | 53 AccObject* AccObject::CreateFromWindow(HWND hwnd) { |
54 ScopedComPtr<IAccessible> accessible; | 54 base::win::ScopedComPtr<IAccessible> accessible; |
55 ::AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, | 55 ::AccessibleObjectFromWindow(hwnd, OBJID_CLIENT, |
56 IID_IAccessible, reinterpret_cast<void**>(accessible.Receive())); | 56 IID_IAccessible, reinterpret_cast<void**>(accessible.Receive())); |
57 if (accessible) | 57 if (accessible) |
58 return new AccObject(accessible); | 58 return new AccObject(accessible); |
59 return NULL; | 59 return NULL; |
60 } | 60 } |
61 | 61 |
62 // static | 62 // static |
63 AccObject* AccObject::CreateFromEvent(HWND hwnd, LONG object_id, | 63 AccObject* AccObject::CreateFromEvent(HWND hwnd, LONG object_id, |
64 LONG child_id) { | 64 LONG child_id) { |
65 ScopedComPtr<IAccessible> accessible; | 65 base::win::ScopedComPtr<IAccessible> accessible; |
66 base::win::ScopedVariant acc_child_id; | 66 base::win::ScopedVariant acc_child_id; |
67 ::AccessibleObjectFromEvent(hwnd, object_id, child_id, accessible.Receive(), | 67 ::AccessibleObjectFromEvent(hwnd, object_id, child_id, accessible.Receive(), |
68 acc_child_id.Receive()); | 68 acc_child_id.Receive()); |
69 if (accessible && acc_child_id.type() == VT_I4) | 69 if (accessible && acc_child_id.type() == VT_I4) |
70 return new AccObject(accessible, V_I4(&acc_child_id)); | 70 return new AccObject(accessible, V_I4(&acc_child_id)); |
71 return NULL; | 71 return NULL; |
72 } | 72 } |
73 | 73 |
74 // static | 74 // static |
75 AccObject* AccObject::CreateFromDispatch(IDispatch* dispatch) { | 75 AccObject* AccObject::CreateFromDispatch(IDispatch* dispatch) { |
76 if (dispatch) { | 76 if (dispatch) { |
77 ScopedComPtr<IAccessible> accessible; | 77 base::win::ScopedComPtr<IAccessible> accessible; |
78 accessible.QueryFrom(dispatch); | 78 accessible.QueryFrom(dispatch); |
79 if (accessible) | 79 if (accessible) |
80 return new AccObject(accessible); | 80 return new AccObject(accessible); |
81 } | 81 } |
82 return NULL; | 82 return NULL; |
83 } | 83 } |
84 | 84 |
85 // static | 85 // static |
86 AccObject* AccObject::CreateFromPoint(int x, int y) { | 86 AccObject* AccObject::CreateFromPoint(int x, int y) { |
87 ScopedComPtr<IAccessible> accessible; | 87 base::win::ScopedComPtr<IAccessible> accessible; |
88 base::win::ScopedVariant child_id; | 88 base::win::ScopedVariant child_id; |
89 POINT point = {x, y}; | 89 POINT point = {x, y}; |
90 ::AccessibleObjectFromPoint(point, accessible.Receive(), child_id.Receive()); | 90 ::AccessibleObjectFromPoint(point, accessible.Receive(), child_id.Receive()); |
91 if (accessible && child_id.type() == VT_I4) | 91 if (accessible && child_id.type() == VT_I4) |
92 return new AccObject(accessible, V_I4(&child_id)); | 92 return new AccObject(accessible, V_I4(&child_id)); |
93 return NULL; | 93 return NULL; |
94 } | 94 } |
95 | 95 |
96 bool AccObject::DoDefaultAction() { | 96 bool AccObject::DoDefaultAction() { |
97 // Prevent clients from using this method to try to select menu items, which | 97 // Prevent clients from using this method to try to select menu items, which |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return false; | 246 return false; |
247 } | 247 } |
248 location.Offset(offset.x, offset.y); | 248 location.Offset(offset.x, offset.y); |
249 *client_location = location; | 249 *client_location = location; |
250 return true; | 250 return true; |
251 } | 251 } |
252 | 252 |
253 AccObject* AccObject::GetParent() { | 253 AccObject* AccObject::GetParent() { |
254 if (IsSimpleElement()) | 254 if (IsSimpleElement()) |
255 return new AccObject(accessible_); | 255 return new AccObject(accessible_); |
256 ScopedComPtr<IDispatch> dispatch; | 256 base::win::ScopedComPtr<IDispatch> dispatch; |
257 if (FAILED(accessible_->get_accParent(dispatch.Receive()))) | 257 if (FAILED(accessible_->get_accParent(dispatch.Receive()))) |
258 return NULL; | 258 return NULL; |
259 return AccObject::CreateFromDispatch(dispatch.get()); | 259 return AccObject::CreateFromDispatch(dispatch.get()); |
260 } | 260 } |
261 | 261 |
262 bool AccObject::GetChildren(RefCountedAccObjectVector* client_objects) { | 262 bool AccObject::GetChildren(RefCountedAccObjectVector* client_objects) { |
263 DCHECK(client_objects); | 263 DCHECK(client_objects); |
264 int child_count; | 264 int child_count; |
265 if (!GetChildCount(&child_count)) { | 265 if (!GetChildCount(&child_count)) { |
266 LOG(ERROR) << "Failed to get child count of AccObject"; | 266 LOG(ERROR) << "Failed to get child count of AccObject"; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 *class_name = class_arr; | 381 *class_name = class_arr; |
382 return true; | 382 return true; |
383 } | 383 } |
384 } | 384 } |
385 return false; | 385 return false; |
386 } | 386 } |
387 | 387 |
388 bool AccObject::GetSelectionRange(int* start_offset, int* end_offset) { | 388 bool AccObject::GetSelectionRange(int* start_offset, int* end_offset) { |
389 DCHECK(start_offset); | 389 DCHECK(start_offset); |
390 DCHECK(end_offset); | 390 DCHECK(end_offset); |
391 ScopedComPtr<IAccessibleText> accessible_text; | 391 base::win::ScopedComPtr<IAccessibleText> accessible_text; |
392 HRESULT hr = DoQueryService(IID_IAccessibleText, | 392 HRESULT hr = DoQueryService(IID_IAccessibleText, |
393 accessible_, | 393 accessible_, |
394 accessible_text.Receive()); | 394 accessible_text.Receive()); |
395 if (FAILED(hr)) { | 395 if (FAILED(hr)) { |
396 LOG(ERROR) << "Could not get IAccessibleText interface. Error: " << hr | 396 LOG(ERROR) << "Could not get IAccessibleText interface. Error: " << hr |
397 << "\nIs IAccessible2Proxy.dll registered?"; | 397 << "\nIs IAccessible2Proxy.dll registered?"; |
398 return false; | 398 return false; |
399 } | 399 } |
400 | 400 |
401 LONG selection_count = 0; | 401 LONG selection_count = 0; |
402 accessible_text->get_nSelections(&selection_count); | 402 accessible_text->get_nSelections(&selection_count); |
403 LONG start = 0, end = 0; | 403 LONG start = 0, end = 0; |
404 if (selection_count > 0) { | 404 if (selection_count > 0) { |
405 if (FAILED(accessible_text->get_selection(0, &start, &end))) { | 405 if (FAILED(accessible_text->get_selection(0, &start, &end))) { |
406 LOG(WARNING) << "Could not get first selection"; | 406 LOG(WARNING) << "Could not get first selection"; |
407 return false; | 407 return false; |
408 } | 408 } |
409 } | 409 } |
410 *start_offset = start; | 410 *start_offset = start; |
411 *end_offset = end; | 411 *end_offset = end; |
412 return true; | 412 return true; |
413 } | 413 } |
414 | 414 |
415 bool AccObject::GetSelectedText(std::wstring* text) { | 415 bool AccObject::GetSelectedText(std::wstring* text) { |
416 DCHECK(text); | 416 DCHECK(text); |
417 int start = 0, end = 0; | 417 int start = 0, end = 0; |
418 if (!GetSelectionRange(&start, &end)) | 418 if (!GetSelectionRange(&start, &end)) |
419 return false; | 419 return false; |
420 ScopedComPtr<IAccessibleText> accessible_text; | 420 base::win::ScopedComPtr<IAccessibleText> accessible_text; |
421 HRESULT hr = DoQueryService(IID_IAccessibleText, | 421 HRESULT hr = DoQueryService(IID_IAccessibleText, |
422 accessible_, | 422 accessible_, |
423 accessible_text.Receive()); | 423 accessible_text.Receive()); |
424 if (FAILED(hr)) { | 424 if (FAILED(hr)) { |
425 LOG(ERROR) << "Could not get IAccessibleText interface. Error: " << hr | 425 LOG(ERROR) << "Could not get IAccessibleText interface. Error: " << hr |
426 << "\nIs IAccessible2Proxy.dll registered?"; | 426 << "\nIs IAccessible2Proxy.dll registered?"; |
427 return false; | 427 return false; |
428 } | 428 } |
429 base::win::ScopedBstr text_bstr; | 429 base::win::ScopedBstr text_bstr; |
430 if (FAILED(accessible_text->get_text(start, end, text_bstr.Receive()))) { | 430 if (FAILED(accessible_text->get_text(start, end, text_bstr.Receive()))) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
492 const VARIANT& variant) { | 492 const VARIANT& variant) { |
493 IAccessible* accessible = object->accessible_; | 493 IAccessible* accessible = object->accessible_; |
494 if (V_VT(&variant) == VT_I4) { | 494 if (V_VT(&variant) == VT_I4) { |
495 // According to MSDN, a server is allowed to return a full Accessibility | 495 // According to MSDN, a server is allowed to return a full Accessibility |
496 // object using the parent object and the child id. If get_accChild is | 496 // object using the parent object and the child id. If get_accChild is |
497 // called with the id, the server must return the actual IAccessible | 497 // called with the id, the server must return the actual IAccessible |
498 // interface. Do that here to get an actual IAccessible interface if | 498 // interface. Do that here to get an actual IAccessible interface if |
499 // possible, since this class operates under the assumption that if the | 499 // possible, since this class operates under the assumption that if the |
500 // child id is not CHILDID_SELF, the object is a simple element. See the | 500 // child id is not CHILDID_SELF, the object is a simple element. See the |
501 // DCHECK in the constructor. | 501 // DCHECK in the constructor. |
502 ScopedComPtr<IDispatch> dispatch; | 502 base::win::ScopedComPtr<IDispatch> dispatch; |
503 HRESULT result = accessible->get_accChild(variant, | 503 HRESULT result = accessible->get_accChild(variant, |
504 dispatch.Receive()); | 504 dispatch.Receive()); |
505 if (result == S_FALSE || result == E_NOINTERFACE) { | 505 if (result == S_FALSE || result == E_NOINTERFACE) { |
506 // The object in question really is a simple element. | 506 // The object in question really is a simple element. |
507 return new AccObject(accessible, V_I4(&variant)); | 507 return new AccObject(accessible, V_I4(&variant)); |
508 } else if (SUCCEEDED(result)) { | 508 } else if (SUCCEEDED(result)) { |
509 // The object in question was actually a full object. | 509 // The object in question was actually a full object. |
510 return CreateFromDispatch(dispatch.get()); | 510 return CreateFromDispatch(dispatch.get()); |
511 } | 511 } |
512 VLOG(1) << "Failed to determine if child id refers to a full " | 512 VLOG(1) << "Failed to determine if child id refers to a full " |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 return desk; | 738 return desk; |
739 } | 739 } |
740 | 740 |
741 FilePath GetIAccessible2ProxyStubPath() { | 741 FilePath GetIAccessible2ProxyStubPath() { |
742 FilePath path; | 742 FilePath path; |
743 PathService::Get(chrome::DIR_APP, &path); | 743 PathService::Get(chrome::DIR_APP, &path); |
744 return path.AppendASCII("IAccessible2Proxy.dll"); | 744 return path.AppendASCII("IAccessible2Proxy.dll"); |
745 } | 745 } |
746 | 746 |
747 } // namespace chrome_frame_test | 747 } // namespace chrome_frame_test |
OLD | NEW |