Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "content/browser/accessibility/browser_accessibility_win.h" | 5 #include "content/browser/accessibility/browser_accessibility_win.h" |
| 6 | 6 |
| 7 #include <UIAutomationClient.h> | 7 #include <UIAutomationClient.h> |
| 8 #include <UIAutomationCoreApi.h> | 8 #include <UIAutomationCoreApi.h> |
| 9 | 9 |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 // http://developer.mozilla.org/en/Accessibility/AT-APIs/ImplementationFeatures/ MSAA | 25 // http://developer.mozilla.org/en/Accessibility/AT-APIs/ImplementationFeatures/ MSAA |
| 26 const GUID GUID_ISimpleDOM = { | 26 const GUID GUID_ISimpleDOM = { |
| 27 0x0c539790, 0x12e4, 0x11cf, | 27 0x0c539790, 0x12e4, 0x11cf, |
| 28 0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8}; | 28 0xb6, 0x61, 0x00, 0xaa, 0x00, 0x4c, 0xd6, 0xd8}; |
| 29 const GUID GUID_IAccessibleContentDocument = { | 29 const GUID GUID_IAccessibleContentDocument = { |
| 30 0xa5d8e1f3, 0x3571, 0x4d8f, | 30 0xa5d8e1f3, 0x3571, 0x4d8f, |
| 31 0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e}; | 31 0x95, 0x21, 0x07, 0xed, 0x28, 0xfb, 0x07, 0x2e}; |
| 32 | 32 |
| 33 const char16 BrowserAccessibilityWin::kEmbeddedCharacter[] = L"\xfffc"; | 33 const char16 BrowserAccessibilityWin::kEmbeddedCharacter[] = L"\xfffc"; |
| 34 | 34 |
| 35 // static | |
| 36 LONG BrowserAccessibilityWin::next_unique_id_win_ = -1; | |
| 37 | |
| 35 // | 38 // |
| 36 // BrowserAccessibilityRelation | 39 // BrowserAccessibilityRelation |
| 37 // | 40 // |
| 38 // A simple implementation of IAccessibleRelation, used to represent | 41 // A simple implementation of IAccessibleRelation, used to represent |
| 39 // a relationship between two accessible nodes in the tree. | 42 // a relationship between two accessible nodes in the tree. |
| 40 // | 43 // |
| 41 | 44 |
| 42 class BrowserAccessibilityRelation | 45 class BrowserAccessibilityRelation |
| 43 : public CComObjectRootEx<CComMultiThreadModel>, | 46 : public CComObjectRootEx<CComMultiThreadModel>, |
| 44 public IAccessibleRelation { | 47 public IAccessibleRelation { |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 return static_cast<BrowserAccessibilityWin*>(this); | 184 return static_cast<BrowserAccessibilityWin*>(this); |
| 182 } | 185 } |
| 183 | 186 |
| 184 BrowserAccessibilityWin::BrowserAccessibilityWin() | 187 BrowserAccessibilityWin::BrowserAccessibilityWin() |
| 185 : ia_role_(0), | 188 : ia_role_(0), |
| 186 ia_state_(0), | 189 ia_state_(0), |
| 187 ia2_role_(0), | 190 ia2_role_(0), |
| 188 ia2_state_(0), | 191 ia2_state_(0), |
| 189 first_time_(true), | 192 first_time_(true), |
| 190 old_ia_state_(0) { | 193 old_ia_state_(0) { |
| 194 // Start unique IDs at -1 and decrement each time, because get_accChild | |
| 195 // uses positive IDs to enumerate children, so we use negative IDs to | |
| 196 // clearly distinguish between indices and unique IDs. | |
| 197 unique_id_win_ = next_unique_id_win_; | |
| 198 next_unique_id_win_--; | |
| 199 if (next_unique_id_win_ > 0) | |
| 200 next_unique_id_win_ = -1; | |
| 191 } | 201 } |
| 192 | 202 |
| 193 BrowserAccessibilityWin::~BrowserAccessibilityWin() { | 203 BrowserAccessibilityWin::~BrowserAccessibilityWin() { |
| 194 for (size_t i = 0; i < relations_.size(); ++i) | 204 for (size_t i = 0; i < relations_.size(); ++i) |
| 195 relations_[i]->Release(); | 205 relations_[i]->Release(); |
| 196 } | 206 } |
| 197 | 207 |
| 198 // | 208 // |
| 199 // IAccessible methods. | 209 // IAccessible methods. |
| 200 // | 210 // |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 return S_OK; | 671 return S_OK; |
| 662 } | 672 } |
| 663 | 673 |
| 664 STDMETHODIMP BrowserAccessibilityWin::get_uniqueID(LONG* unique_id) { | 674 STDMETHODIMP BrowserAccessibilityWin::get_uniqueID(LONG* unique_id) { |
| 665 if (!instance_active_) | 675 if (!instance_active_) |
| 666 return E_FAIL; | 676 return E_FAIL; |
| 667 | 677 |
| 668 if (!unique_id) | 678 if (!unique_id) |
| 669 return E_INVALIDARG; | 679 return E_INVALIDARG; |
| 670 | 680 |
| 671 *unique_id = child_id_; | 681 *unique_id = unique_id_win_; |
| 672 return S_OK; | 682 return S_OK; |
| 673 } | 683 } |
| 674 | 684 |
| 675 STDMETHODIMP BrowserAccessibilityWin::get_windowHandle(HWND* window_handle) { | 685 STDMETHODIMP BrowserAccessibilityWin::get_windowHandle(HWND* window_handle) { |
| 676 if (!instance_active_) | 686 if (!instance_active_) |
| 677 return E_FAIL; | 687 return E_FAIL; |
| 678 | 688 |
| 679 if (!window_handle) | 689 if (!window_handle) |
| 680 return E_INVALIDARG; | 690 return E_INVALIDARG; |
| 681 | 691 |
| (...skipping 1561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2243 | 2253 |
| 2244 string16 tag; | 2254 string16 tag; |
| 2245 if (GetStringAttribute(AccessibilityNodeData::ATTR_HTML_TAG, &tag)) | 2255 if (GetStringAttribute(AccessibilityNodeData::ATTR_HTML_TAG, &tag)) |
| 2246 *node_name = SysAllocString(tag.c_str()); | 2256 *node_name = SysAllocString(tag.c_str()); |
| 2247 else | 2257 else |
| 2248 *node_name = NULL; | 2258 *node_name = NULL; |
| 2249 | 2259 |
| 2250 *name_space_id = 0; | 2260 *name_space_id = 0; |
| 2251 *node_value = SysAllocString(value_.c_str()); | 2261 *node_value = SysAllocString(value_.c_str()); |
| 2252 *num_children = children_.size(); | 2262 *num_children = children_.size(); |
| 2253 *unique_id = child_id_; | 2263 *unique_id = unique_id_win_; |
| 2254 | 2264 |
| 2255 if (ia_role_ == ROLE_SYSTEM_DOCUMENT) { | 2265 if (ia_role_ == ROLE_SYSTEM_DOCUMENT) { |
| 2256 *node_type = NODETYPE_DOCUMENT; | 2266 *node_type = NODETYPE_DOCUMENT; |
| 2257 } else if (ia_role_ == ROLE_SYSTEM_TEXT && | 2267 } else if (ia_role_ == ROLE_SYSTEM_TEXT && |
| 2258 ((ia2_state_ & IA2_STATE_EDITABLE) == 0)) { | 2268 ((ia2_state_ & IA2_STATE_EDITABLE) == 0)) { |
| 2259 *node_type = NODETYPE_TEXT; | 2269 *node_type = NODETYPE_TEXT; |
| 2260 } else { | 2270 } else { |
| 2261 *node_type = NODETYPE_ELEMENT; | 2271 *node_type = NODETYPE_ELEMENT; |
| 2262 } | 2272 } |
| 2263 | 2273 |
| (...skipping 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2872 // Normally focus events are handled elsewhere, however | 2882 // Normally focus events are handled elsewhere, however |
| 2873 // focus for managed descendants is platform-specific. | 2883 // focus for managed descendants is platform-specific. |
| 2874 // Fire a focus event if the focused descendant in a multi-select | 2884 // Fire a focus event if the focused descendant in a multi-select |
| 2875 // list box changes. | 2885 // list box changes. |
| 2876 if (role_ == AccessibilityNodeData::ROLE_LISTBOX_OPTION && | 2886 if (role_ == AccessibilityNodeData::ROLE_LISTBOX_OPTION && |
| 2877 (ia_state_ & STATE_SYSTEM_FOCUSABLE) && | 2887 (ia_state_ & STATE_SYSTEM_FOCUSABLE) && |
| 2878 (ia_state_ & STATE_SYSTEM_SELECTABLE) && | 2888 (ia_state_ & STATE_SYSTEM_SELECTABLE) && |
| 2879 (ia_state_ & STATE_SYSTEM_FOCUSED) && | 2889 (ia_state_ & STATE_SYSTEM_FOCUSED) && |
| 2880 !(old_ia_state_ & STATE_SYSTEM_FOCUSED)) { | 2890 !(old_ia_state_ & STATE_SYSTEM_FOCUSED)) { |
| 2881 ::NotifyWinEvent(EVENT_OBJECT_FOCUS, hwnd, | 2891 ::NotifyWinEvent(EVENT_OBJECT_FOCUS, hwnd, |
| 2882 OBJID_CLIENT, child_id()); | 2892 OBJID_CLIENT, unique_id_win()); |
| 2883 } | 2893 } |
| 2884 | 2894 |
| 2885 if ((ia_state_ & STATE_SYSTEM_SELECTED) && | 2895 if ((ia_state_ & STATE_SYSTEM_SELECTED) && |
| 2886 !(old_ia_state_ & STATE_SYSTEM_SELECTED)) { | 2896 !(old_ia_state_ & STATE_SYSTEM_SELECTED)) { |
| 2887 ::NotifyWinEvent(EVENT_OBJECT_SELECTIONADD, hwnd, | 2897 ::NotifyWinEvent(EVENT_OBJECT_SELECTIONADD, hwnd, |
| 2888 OBJID_CLIENT, child_id()); | 2898 OBJID_CLIENT, unique_id_win()); |
| 2889 } else if (!(ia_state_ & STATE_SYSTEM_SELECTED) && | 2899 } else if (!(ia_state_ & STATE_SYSTEM_SELECTED) && |
| 2890 (old_ia_state_ & STATE_SYSTEM_SELECTED)) { | 2900 (old_ia_state_ & STATE_SYSTEM_SELECTED)) { |
| 2891 ::NotifyWinEvent(EVENT_OBJECT_SELECTIONREMOVE, hwnd, | 2901 ::NotifyWinEvent(EVENT_OBJECT_SELECTIONREMOVE, hwnd, |
| 2892 OBJID_CLIENT, child_id()); | 2902 OBJID_CLIENT, unique_id_win()); |
| 2893 } | 2903 } |
| 2894 | 2904 |
| 2895 old_ia_state_ = ia_state_; | 2905 old_ia_state_ = ia_state_; |
| 2896 } | 2906 } |
| 2897 | 2907 |
| 2898 first_time_ = false; | 2908 first_time_ = false; |
| 2899 } | 2909 } |
| 2900 | 2910 |
| 2901 void BrowserAccessibilityWin::NativeAddReference() { | 2911 void BrowserAccessibilityWin::NativeAddReference() { |
| 2902 AddRef(); | 2912 AddRef(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2920 if (var_id.vt != VT_I4) | 2930 if (var_id.vt != VT_I4) |
| 2921 return NULL; | 2931 return NULL; |
| 2922 | 2932 |
| 2923 LONG child_id = var_id.lVal; | 2933 LONG child_id = var_id.lVal; |
| 2924 if (child_id == CHILDID_SELF) | 2934 if (child_id == CHILDID_SELF) |
| 2925 return this; | 2935 return this; |
| 2926 | 2936 |
| 2927 if (child_id >= 1 && child_id <= static_cast<LONG>(children_.size())) | 2937 if (child_id >= 1 && child_id <= static_cast<LONG>(children_.size())) |
| 2928 return children_[child_id - 1]->ToBrowserAccessibilityWin(); | 2938 return children_[child_id - 1]->ToBrowserAccessibilityWin(); |
| 2929 | 2939 |
| 2930 return manager_->GetFromChildID(child_id)->ToBrowserAccessibilityWin(); | 2940 return manager_->ToBrowserAccessibilityManagerWin()-> |
| 2941 GetFromUniqueIdWin(child_id)->ToBrowserAccessibilityWin(); | |
|
aboxhall
2013/04/09 09:28:29
I don't think ToBrowserAccessibilityWin() is neces
dmazzoni
2013/04/09 19:44:04
You're right, thanks.
| |
| 2931 } | 2942 } |
| 2932 | 2943 |
| 2933 HRESULT BrowserAccessibilityWin::GetStringAttributeAsBstr( | 2944 HRESULT BrowserAccessibilityWin::GetStringAttributeAsBstr( |
| 2934 AccessibilityNodeData::StringAttribute attribute, | 2945 AccessibilityNodeData::StringAttribute attribute, |
| 2935 BSTR* value_bstr) { | 2946 BSTR* value_bstr) { |
| 2936 string16 str; | 2947 string16 str; |
| 2937 | 2948 |
| 2938 if (!GetStringAttribute(attribute, &str)) | 2949 if (!GetStringAttribute(attribute, &str)) |
| 2939 return S_FALSE; | 2950 return S_FALSE; |
| 2940 | 2951 |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3517 // The role should always be set. | 3528 // The role should always be set. |
| 3518 DCHECK(!role_name_.empty() || ia_role_); | 3529 DCHECK(!role_name_.empty() || ia_role_); |
| 3519 | 3530 |
| 3520 // If we didn't explicitly set the IAccessible2 role, make it the same | 3531 // If we didn't explicitly set the IAccessible2 role, make it the same |
| 3521 // as the MSAA role. | 3532 // as the MSAA role. |
| 3522 if (!ia2_role_) | 3533 if (!ia2_role_) |
| 3523 ia2_role_ = ia_role_; | 3534 ia2_role_ = ia_role_; |
| 3524 } | 3535 } |
| 3525 | 3536 |
| 3526 } // namespace content | 3537 } // namespace content |
| OLD | NEW |