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

Side by Side Diff: content/browser/accessibility/browser_accessibility_win.cc

Issue 2518183002: Moved action verbs out of Blink. (Closed)
Patch Set: Exposes appropriate state and action names when controls are disabled. Created 4 years 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 (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 <algorithm> 10 #include <algorithm>
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 HRESULT BrowserAccessibilityWin::accDoDefaultAction(VARIANT var_id) { 414 HRESULT BrowserAccessibilityWin::accDoDefaultAction(VARIANT var_id) {
415 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_DO_DEFAULT_ACTION); 415 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_DO_DEFAULT_ACTION);
416 if (!instance_active()) 416 if (!instance_active())
417 return E_FAIL; 417 return E_FAIL;
418 418
419 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 419 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id);
420 if (!target) 420 if (!target)
421 return E_INVALIDARG; 421 return E_INVALIDARG;
422 422
423 // Return an error if it's not clickable. 423 // Return an error if it's not clickable.
424 if (!target->HasStringAttribute(ui::AX_ATTR_ACTION)) 424 if (!target->HasIntAttribute(ui::AX_ATTR_ACTION))
425 return DISP_E_MEMBERNOTFOUND; 425 return DISP_E_MEMBERNOTFOUND;
426 426
427 manager()->DoDefaultAction(*target); 427 manager()->DoDefaultAction(*target);
428 return S_OK; 428 return S_OK;
429 } 429 }
430 430
431 STDMETHODIMP BrowserAccessibilityWin::accHitTest(LONG x_left, 431 STDMETHODIMP BrowserAccessibilityWin::accHitTest(LONG x_left,
432 LONG y_top, 432 LONG y_top,
433 VARIANT* child) { 433 VARIANT* child) {
434 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_HIT_TEST); 434 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_ACC_HIT_TEST);
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 if (!instance_active()) 570 if (!instance_active())
571 return E_FAIL; 571 return E_FAIL;
572 572
573 if (!def_action) 573 if (!def_action)
574 return E_INVALIDARG; 574 return E_INVALIDARG;
575 575
576 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id); 576 BrowserAccessibilityWin* target = GetTargetFromChildID(var_id);
577 if (!target) 577 if (!target)
578 return E_INVALIDARG; 578 return E_INVALIDARG;
579 579
580 return target->GetStringAttributeAsBstr( 580 return target->get_localizedName(0, def_action);
581 ui::AX_ATTR_ACTION, def_action);
582 } 581 }
583 582
584 STDMETHODIMP BrowserAccessibilityWin::get_accDescription(VARIANT var_id, 583 STDMETHODIMP BrowserAccessibilityWin::get_accDescription(VARIANT var_id,
585 BSTR* desc) { 584 BSTR* desc) {
586 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DESCRIPTION); 585 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_ACC_DESCRIPTION);
587 if (!instance_active()) 586 if (!instance_active())
588 return E_FAIL; 587 return E_FAIL;
589 588
590 if (!desc) 589 if (!desc)
591 return E_INVALIDARG; 590 return E_INVALIDARG;
(...skipping 2240 matching lines...) Expand 10 before | Expand all | Expand 10 after
2832 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_N_ACTIONS); 2831 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_N_ACTIONS);
2833 if (!instance_active()) 2832 if (!instance_active())
2834 return E_FAIL; 2833 return E_FAIL;
2835 2834
2836 if (!n_actions) 2835 if (!n_actions)
2837 return E_INVALIDARG; 2836 return E_INVALIDARG;
2838 2837
2839 // |IsHyperlink| is required for |IAccessibleHyperlink::anchor/anchorTarget| 2838 // |IsHyperlink| is required for |IAccessibleHyperlink::anchor/anchorTarget|
2840 // to work properly because the |IAccessibleHyperlink| interface inherits from 2839 // to work properly because the |IAccessibleHyperlink| interface inherits from
2841 // |IAccessibleAction|. 2840 // |IAccessibleAction|.
2842 if (IsHyperlink() || HasStringAttribute(ui::AX_ATTR_ACTION)) { 2841 if (IsHyperlink() || HasIntAttribute(ui::AX_ATTR_ACTION)) {
2843 *n_actions = 1; 2842 *n_actions = 1;
2844 } else { 2843 } else {
2845 *n_actions = 0; 2844 *n_actions = 0;
2846 } 2845 }
2847 2846
2848 return S_OK; 2847 return S_OK;
2849 } 2848 }
2850 2849
2851 STDMETHODIMP BrowserAccessibilityWin::doAction(long action_index) { 2850 STDMETHODIMP BrowserAccessibilityWin::doAction(long action_index) {
2852 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_DO_ACTION); 2851 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_DO_ACTION);
2853 if (!instance_active()) 2852 if (!instance_active())
2854 return E_FAIL; 2853 return E_FAIL;
2855 2854
2856 if (!HasStringAttribute(ui::AX_ATTR_ACTION) || action_index != 0) 2855 if (!HasIntAttribute(ui::AX_ATTR_ACTION) || action_index != 0)
2857 return E_INVALIDARG; 2856 return E_INVALIDARG;
2858 2857
2859 manager()->DoDefaultAction(*this); 2858 manager()->DoDefaultAction(*this);
2860 return S_OK; 2859 return S_OK;
2861 } 2860 }
2862 2861
2863 STDMETHODIMP 2862 STDMETHODIMP
2864 BrowserAccessibilityWin::get_description(long action_index, BSTR* description) { 2863 BrowserAccessibilityWin::get_description(long action_index, BSTR* description) {
2865 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IAACTION_GET_DESCRIPTION); 2864 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_IAACTION_GET_DESCRIPTION);
2866 return E_NOTIMPL; 2865 return E_NOTIMPL;
2867 } 2866 }
2868 2867
2869 STDMETHODIMP BrowserAccessibilityWin::get_keyBinding(long action_index, 2868 STDMETHODIMP BrowserAccessibilityWin::get_keyBinding(long action_index,
2870 long n_max_bindings, 2869 long n_max_bindings,
2871 BSTR** key_bindings, 2870 BSTR** key_bindings,
2872 long* n_bindings) { 2871 long* n_bindings) {
2873 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_KEY_BINDING); 2872 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_KEY_BINDING);
2874 return E_NOTIMPL; 2873 return E_NOTIMPL;
2875 } 2874 }
2876 2875
2877 STDMETHODIMP BrowserAccessibilityWin::get_name(long action_index, BSTR* name) { 2876 STDMETHODIMP BrowserAccessibilityWin::get_name(long action_index, BSTR* name) {
2878 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NAME); 2877 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_NAME);
2879 if (!instance_active()) 2878 if (!instance_active())
2880 return E_FAIL; 2879 return E_FAIL;
2881 2880
2882 if (!name) 2881 if (!name)
2883 return E_INVALIDARG; 2882 return E_INVALIDARG;
2884 2883
2885 base::string16 action_verb; 2884 int action;
2886 if (!GetString16Attribute(ui::AX_ATTR_ACTION, &action_verb) || 2885 if (!GetIntAttribute(ui::AX_ATTR_ACTION, &action) || action_index != 0) {
2887 action_index != 0) {
2888 *name = nullptr; 2886 *name = nullptr;
2889 return E_INVALIDARG; 2887 return E_INVALIDARG;
2890 } 2888 }
2891 2889
2890 base::string16 action_verb =
2891 ActionToUnlocalizedString(static_cast<ui::AXSupportedAction>(action));
2892 if (action_verb.empty() || action_verb == L"none") {
2893 *name = nullptr;
2894 return S_FALSE;
2895 }
2896
2892 *name = SysAllocString(action_verb.c_str()); 2897 *name = SysAllocString(action_verb.c_str());
2893 DCHECK(name); 2898 DCHECK(name);
2894 return S_OK; 2899 return S_OK;
2895 } 2900 }
2896 2901
2897 STDMETHODIMP 2902 STDMETHODIMP
2898 BrowserAccessibilityWin::get_localizedName(long action_index, 2903 BrowserAccessibilityWin::get_localizedName(long action_index,
2899 BSTR* localized_name) { 2904 BSTR* localized_name) {
2900 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_NAME); 2905 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_NAME);
2901 return E_NOTIMPL; 2906 if (!instance_active())
2907 return E_FAIL;
2908
2909 if (!localized_name)
2910 return E_INVALIDARG;
2911
2912 int action;
2913 if (!GetIntAttribute(ui::AX_ATTR_ACTION, &action) || action_index != 0) {
2914 *localized_name = nullptr;
2915 return E_INVALIDARG;
2916 }
2917
2918 base::string16 action_verb =
2919 ui::ActionToString(static_cast<ui::AXSupportedAction>(action));
2920 if (action_verb.empty()) {
2921 *localized_name = nullptr;
2922 return S_FALSE;
2923 }
2924
2925 *localized_name = SysAllocString(action_verb.c_str());
2926 DCHECK(localized_name);
2927 return S_OK;
2902 } 2928 }
2903 2929
2904 // 2930 //
2905 // IAccessibleValue methods. 2931 // IAccessibleValue methods.
2906 // 2932 //
2907 2933
2908 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) { 2934 STDMETHODIMP BrowserAccessibilityWin::get_currentValue(VARIANT* value) {
2909 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CURRENT_VALUE); 2935 WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_CURRENT_VALUE);
2910 if (!instance_active()) 2936 if (!instance_active())
2911 return E_FAIL; 2937 return E_FAIL;
(...skipping 1107 matching lines...) Expand 10 before | Expand all | Expand 10 after
4019 } 4045 }
4020 4046
4021 bool BrowserAccessibilityWin::IsNative() const { 4047 bool BrowserAccessibilityWin::IsNative() const {
4022 return true; 4048 return true;
4023 } 4049 }
4024 4050
4025 void BrowserAccessibilityWin::OnLocationChanged() { 4051 void BrowserAccessibilityWin::OnLocationChanged() {
4026 FireNativeEvent(EVENT_OBJECT_LOCATIONCHANGE); 4052 FireNativeEvent(EVENT_OBJECT_LOCATIONCHANGE);
4027 } 4053 }
4028 4054
4055 // Some APIs need to return non-localized action names.
4056 // static
4057 base::string16 BrowserAccessibilityWin::ActionToUnlocalizedString(
4058 ui::AXSupportedAction supported_action) {
4059 switch (supported_action) {
4060 case ui::AX_SUPPORTED_ACTION_NONE:
dmazzoni 2016/11/29 16:28:10 This isn't a valid value, right? I think this shou
4061 return L"none";
4062 case ui::AX_SUPPORTED_ACTION_ACTIVATE:
4063 return L"activate";
4064 case ui::AX_SUPPORTED_ACTION_CHECK:
4065 return L"check";
4066 case ui::AX_SUPPORTED_ACTION_CLICK:
4067 return L"click";
4068 case ui::AX_SUPPORTED_ACTION_JUMP:
4069 return L"jump";
4070 case ui::AX_SUPPORTED_ACTION_OPEN:
4071 return L"open";
4072 case ui::AX_SUPPORTED_ACTION_PRESS:
4073 return L"press";
4074 case ui::AX_SUPPORTED_ACTION_SELECT:
4075 return L"select";
4076 case ui::AX_SUPPORTED_ACTION_UNCHECK:
4077 return L"uncheck";
4078 }
4079 NOTREACHED();
4080 return base::string16();
4081 }
4082
4029 std::vector<base::string16> BrowserAccessibilityWin::ComputeTextAttributes() 4083 std::vector<base::string16> BrowserAccessibilityWin::ComputeTextAttributes()
4030 const { 4084 const {
4031 std::vector<base::string16> attributes; 4085 std::vector<base::string16> attributes;
4032 4086
4033 // We include list markers for now, but there might be other objects that are 4087 // We include list markers for now, but there might be other objects that are
4034 // auto generated. 4088 // auto generated.
4035 // TODO(nektar): Compute what objects are auto-generated in Blink. 4089 // TODO(nektar): Compute what objects are auto-generated in Blink.
4036 if (GetRole() == ui::AX_ROLE_LIST_MARKER) 4090 if (GetRole() == ui::AX_ROLE_LIST_MARKER)
4037 attributes.push_back(L"auto-generated:true"); 4091 attributes.push_back(L"auto-generated:true");
4038 else 4092 else
(...skipping 1492 matching lines...) Expand 10 before | Expand all | Expand 10 after
5531 return static_cast<BrowserAccessibilityWin*>(obj); 5585 return static_cast<BrowserAccessibilityWin*>(obj);
5532 } 5586 }
5533 5587
5534 const BrowserAccessibilityWin* 5588 const BrowserAccessibilityWin*
5535 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) { 5589 ToBrowserAccessibilityWin(const BrowserAccessibility* obj) {
5536 DCHECK(!obj || obj->IsNative()); 5590 DCHECK(!obj || obj->IsNative());
5537 return static_cast<const BrowserAccessibilityWin*>(obj); 5591 return static_cast<const BrowserAccessibilityWin*>(obj);
5538 } 5592 }
5539 5593
5540 } // namespace content 5594 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698