Chromium Code Reviews| Index: content/browser/accessibility/browser_accessibility_win.cc |
| diff --git a/content/browser/accessibility/browser_accessibility_win.cc b/content/browser/accessibility/browser_accessibility_win.cc |
| index d77d60d807df37b81a29a06f654076daa7f39529..e9e9ffb9f69659c760386877a84fb8489c05c554 100644 |
| --- a/content/browser/accessibility/browser_accessibility_win.cc |
| +++ b/content/browser/accessibility/browser_accessibility_win.cc |
| @@ -421,7 +421,7 @@ HRESULT BrowserAccessibilityWin::accDoDefaultAction(VARIANT var_id) { |
| return E_INVALIDARG; |
| // Return an error if it's not clickable. |
| - if (!target->HasStringAttribute(ui::AX_ATTR_ACTION)) |
| + if (!target->HasIntAttribute(ui::AX_ATTR_ACTION)) |
| return DISP_E_MEMBERNOTFOUND; |
| manager()->DoDefaultAction(*target); |
| @@ -577,8 +577,7 @@ STDMETHODIMP BrowserAccessibilityWin::get_accDefaultAction(VARIANT var_id, |
| if (!target) |
| return E_INVALIDARG; |
| - return target->GetStringAttributeAsBstr( |
| - ui::AX_ATTR_ACTION, def_action); |
| + return target->get_localizedName(0, def_action); |
| } |
| STDMETHODIMP BrowserAccessibilityWin::get_accDescription(VARIANT var_id, |
| @@ -2839,7 +2838,7 @@ STDMETHODIMP BrowserAccessibilityWin::nActions(long* n_actions) { |
| // |IsHyperlink| is required for |IAccessibleHyperlink::anchor/anchorTarget| |
| // to work properly because the |IAccessibleHyperlink| interface inherits from |
| // |IAccessibleAction|. |
| - if (IsHyperlink() || HasStringAttribute(ui::AX_ATTR_ACTION)) { |
| + if (IsHyperlink() || HasIntAttribute(ui::AX_ATTR_ACTION)) { |
| *n_actions = 1; |
| } else { |
| *n_actions = 0; |
| @@ -2853,7 +2852,7 @@ STDMETHODIMP BrowserAccessibilityWin::doAction(long action_index) { |
| if (!instance_active()) |
| return E_FAIL; |
| - if (!HasStringAttribute(ui::AX_ATTR_ACTION) || action_index != 0) |
| + if (!HasIntAttribute(ui::AX_ATTR_ACTION) || action_index != 0) |
| return E_INVALIDARG; |
| manager()->DoDefaultAction(*this); |
| @@ -2882,13 +2881,19 @@ STDMETHODIMP BrowserAccessibilityWin::get_name(long action_index, BSTR* name) { |
| if (!name) |
| return E_INVALIDARG; |
| - base::string16 action_verb; |
| - if (!GetString16Attribute(ui::AX_ATTR_ACTION, &action_verb) || |
| - action_index != 0) { |
| + int action; |
| + if (!GetIntAttribute(ui::AX_ATTR_ACTION, &action) || action_index != 0) { |
| *name = nullptr; |
| return E_INVALIDARG; |
| } |
| + base::string16 action_verb = |
| + ActionToUnlocalizedString(static_cast<ui::AXSupportedAction>(action)); |
| + if (action_verb.empty() || action_verb == L"None") { |
| + *name = nullptr; |
| + return S_FALSE; |
| + } |
| + |
| *name = SysAllocString(action_verb.c_str()); |
| DCHECK(name); |
| return S_OK; |
| @@ -2898,7 +2903,28 @@ STDMETHODIMP |
| BrowserAccessibilityWin::get_localizedName(long action_index, |
| BSTR* localized_name) { |
| WIN_ACCESSIBILITY_API_HISTOGRAM(UMA_API_GET_LOCALIZED_NAME); |
| - return E_NOTIMPL; |
| + if (!instance_active()) |
| + return E_FAIL; |
| + |
| + if (!localized_name) |
| + return E_INVALIDARG; |
| + |
| + int action; |
| + if (!GetIntAttribute(ui::AX_ATTR_ACTION, &action) || action_index != 0) { |
| + *localized_name = nullptr; |
| + return E_INVALIDARG; |
| + } |
| + |
| + base::string16 action_verb = |
| + ui::ActionToString(static_cast<ui::AXSupportedAction>(action)); |
| + if (action_verb.empty()) { |
| + *localized_name = nullptr; |
| + return S_FALSE; |
| + } |
| + |
| + *localized_name = SysAllocString(action_verb.c_str()); |
| + DCHECK(localized_name); |
| + return S_OK; |
| } |
| // |
| @@ -4026,6 +4052,34 @@ void BrowserAccessibilityWin::OnLocationChanged() { |
| FireNativeEvent(EVENT_OBJECT_LOCATIONCHANGE); |
| } |
| +// Some APIs need to return non-localized action names. |
| +// static |
| +base::string16 BrowserAccessibilityWin::ActionToUnlocalizedString( |
| + ui::AXSupportedAction supported_action) { |
| + switch (supported_action) { |
| + case ui::AX_SUPPORTED_ACTION_NONE: |
| + return L"None"; |
| + case ui::AX_SUPPORTED_ACTION_ACTIVATE: |
| + return L"Activate"; |
| + case ui::AX_SUPPORTED_ACTION_CHECK: |
| + return L"Check"; |
| + case ui::AX_SUPPORTED_ACTION_CLICK: |
| + return L"Click"; |
|
dmazzoni
2016/11/28 17:03:32
I think NVDA expected "click", lowercase.
Most of
|
| + case ui::AX_SUPPORTED_ACTION_JUMP: |
| + return L"Jump"; |
| + case ui::AX_SUPPORTED_ACTION_OPEN: |
| + return L"Open"; |
| + case ui::AX_SUPPORTED_ACTION_PRESS: |
| + return L"Press"; |
| + case ui::AX_SUPPORTED_ACTION_SELECT: |
| + return L"Select"; |
| + case ui::AX_SUPPORTED_ACTION_UNCHECK: |
| + return L"Uncheck"; |
| + } |
| + NOTREACHED(); |
| + return base::string16(); |
| +} |
| + |
| std::vector<base::string16> BrowserAccessibilityWin::ComputeTextAttributes() |
| const { |
| std::vector<base::string16> attributes; |