Chromium Code Reviews| Index: ui/accessibility/platform/ax_platform_node_mac.mm |
| diff --git a/ui/accessibility/platform/ax_platform_node_mac.mm b/ui/accessibility/platform/ax_platform_node_mac.mm |
| index b06cb439dfc32467381b54aaa1d3a25868ed1589..b0e906706875eb55a873c9a65bfb78488eb1c309 100644 |
| --- a/ui/accessibility/platform/ax_platform_node_mac.mm |
| +++ b/ui/accessibility/platform/ax_platform_node_mac.mm |
| @@ -9,9 +9,11 @@ |
| #include "base/macros.h" |
| #include "base/strings/sys_string_conversions.h" |
| +#include "chrome/grit/generated_resources.h" |
| #include "ui/accessibility/ax_action_data.h" |
| #include "ui/accessibility/ax_node_data.h" |
| #include "ui/accessibility/platform/ax_platform_node_delegate.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| #import "ui/gfx/mac/coordinate_conversion.h" |
| namespace { |
| @@ -184,6 +186,7 @@ RoleMap BuildSubroleMap() { |
| {ui::AX_ROLE_SEARCH_BOX, @"AXSearchField"}, |
| {ui::AX_ROLE_STATUS, @"AXApplicationStatus"}, |
| {ui::AX_ROLE_SWITCH, @"AXSwitch"}, |
| + {ui::AX_ROLE_TAB, @"AXTab"}, |
| {ui::AX_ROLE_TAB_PANEL, @"AXTabPanel"}, |
| {ui::AX_ROLE_TIMER, @"AXApplicationTimer"}, |
| {ui::AX_ROLE_TOGGLE_BUTTON, @"AXToggleButton"}, |
| @@ -369,8 +372,7 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| // Allow certain attributes to be written via an accessibility client. A |
| // writable attribute will only appear as such if the accessibility element |
| // has a value set for that attribute. |
| - if ([attributeName isEqualToString:NSAccessibilitySelectedAttribute] || |
| - [attributeName |
| + if ([attributeName |
| isEqualToString:NSAccessibilitySelectedChildrenAttribute] || |
| [attributeName |
| isEqualToString:NSAccessibilitySelectedTextRangeAttribute] || |
| @@ -379,6 +381,14 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| return NO; |
| } |
| + // Tabs are a special case. For whatever reason, |
|
tapted
2017/01/03 00:29:27
The reason might be that in Cocoa, using role=AXRa
Patti Lor
2017/01/06 02:02:29
Done.
|
| + // NSAccessibilitySelectedAttribute isn't used for them, so allow editing of |
| + // the value attribute to select unselected tabs instead. |
| + if ([attributeName isEqualToString:NSAccessibilityValueAttribute] && |
| + node_->GetData().role == ui::AX_ROLE_TAB) { |
| + return !node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED); |
| + } |
| + |
| if ([attributeName isEqualToString:NSAccessibilityValueAttribute] || |
| [attributeName isEqualToString:NSAccessibilitySelectedTextAttribute]) |
| return !ui::AXNodeData::IsFlagSet(node_->GetData().state, |
| @@ -399,7 +409,11 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| if ([value isKindOfClass:[NSString class]]) { |
| data.value = base::SysNSStringToUTF16(value); |
| if ([attribute isEqualToString:NSAccessibilityValueAttribute]) { |
| - data.action = ui::AX_ACTION_SET_VALUE; |
| + // Tabs have no other way to set their selected state via a11y, so use the |
| + // value attribute here. |
| + data.action = node_->GetData().role == ui::AX_ROLE_TAB |
| + ? ui::AX_ACTION_SET_SELECTION |
| + : ui::AX_ACTION_SET_VALUE; |
| } else if ([attribute |
| isEqualToString:NSAccessibilitySelectedTextAttribute]) { |
| data.action = ui::AX_ACTION_REPLACE_SELECTED_TEXT; |
| @@ -468,6 +482,13 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (NSString*)AXRoleDescription { |
| + ui::AXRole role = node_->GetData().role; |
| + switch (role) { |
|
tapted
2017/01/03 00:29:27
nit: switch (node_->GetData().role) {
Patti Lor
2017/01/06 02:02:29
Done.
|
| + case ui::AX_ROLE_TAB: |
| + return l10n_util::GetNSStringWithFixup(IDS_ACCNAME_TAB); |
|
Patti Lor
2016/12/30 00:35:02
There's no "NSAccessibilityTabRole" or similar, so
tapted
2017/01/03 00:29:27
Can we move IDS_ACCNAME_TAB to ui_resources.grd? I
Patti Lor
2017/01/06 02:02:29
A recent patch (https://codereview.chromium.org/25
|
| + default: |
| + break; |
| + } |
| return NSAccessibilityRoleDescription([self AXRole], [self AXSubrole]); |
| } |
| @@ -480,6 +501,8 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| } |
| - (NSString*)AXValue { |
| + if (node_->GetData().role == ui::AX_ROLE_TAB) |
| + return [[self AXSelected] stringValue]; |
| return [self getStringAttribute:ui::AX_ATTR_VALUE]; |
| } |
| @@ -550,6 +573,13 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) { |
| valueWithRange:NSMakeRange(0, [[self AXNumberOfCharacters] intValue])]; |
| } |
| +// Misc NSAccessibility attributes. |
| + |
| +- (NSNumber*)AXSelected { |
|
Patti Lor
2016/12/30 00:35:02
Not sure if we should leave this in; I can't tell
tapted
2017/01/03 00:29:27
This looks good. I think it's fine to add anythin
Patti Lor
2017/01/06 02:02:29
Acknowledged.
|
| + return [NSNumber |
| + numberWithBool:node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED)]; |
| +} |
| + |
| @end |
| namespace ui { |