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

Unified Diff: ui/accessibility/platform/ax_platform_node_mac.mm

Issue 2578303003: a11y: Add a11y information to views::Tab and manually ignore its a11y children. (Closed)
Patch Set: Review comments. Created 3 years, 11 months 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 side-by-side diff with in-line comments
Download patch
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..2f165c8db5c3e6e7800663504112b4337c05a91d 100644
--- a/ui/accessibility/platform/ax_platform_node_mac.mm
+++ b/ui/accessibility/platform/ax_platform_node_mac.mm
@@ -12,7 +12,9 @@
#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"
+#include "ui/strings/grit/ui_strings.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,10 +381,18 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
return NO;
}
+ // Since tabs use the Radio Button role on Mac, the standard way to set them
+ // is via the value attribute rather than the selected attribute.
+ 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])
+ [attributeName isEqualToString:NSAccessibilitySelectedTextAttribute]) {
return !ui::AXNodeData::IsFlagSet(node_->GetData().state,
ui::AX_STATE_READ_ONLY);
+ }
if ([attributeName isEqualToString:NSAccessibilityFocusedAttribute]) {
return ui::AXNodeData::IsFlagSet(node_->GetData().state,
@@ -396,12 +406,21 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
- (void)accessibilitySetValue:(id)value forAttribute:(NSString*)attribute {
ui::AXActionData data;
+
+ // Check for attributes which accept any |value| type (i.e. ids) first. Only
+ // the |data.action| should be set here - any type-specific information, if
+ // needed, should be set below, where there are type checks.
+ if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
+ data.action = node_->GetData().role == ui::AX_ROLE_TAB
+ ? ui::AX_ACTION_SET_SELECTION
+ : data.action = ui::AX_ACTION_SET_VALUE;
tapted 2017/01/10 16:22:18 the single `=` doesn't look right on this line, al
Patti Lor 2017/01/11 05:51:44 Oops, thank you - joined the line but didn't edit
+ }
+
+ // Set actions for attributes restricted to a specific type. Also set
+ // type-specific information as necessary for actions set above.
tapted 2017/01/10 16:22:18 It looks easy to introduce codepaths where the stu
Patti Lor 2017/01/11 05:51:44 Not intentional - I was trying to make a nice way
if ([value isKindOfClass:[NSString class]]) {
data.value = base::SysNSStringToUTF16(value);
- if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
- data.action = ui::AX_ACTION_SET_VALUE;
- } else if ([attribute
- isEqualToString:NSAccessibilitySelectedTextAttribute]) {
+ if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) {
data.action = ui::AX_ACTION_REPLACE_SELECTED_TEXT;
}
} else if ([value isKindOfClass:[NSNumber class]]) {
@@ -468,6 +487,15 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
}
- (NSString*)AXRoleDescription {
+ switch (node_->GetData().role) {
+ case ui::AX_ROLE_TAB:
+ // There is no NSAccessibilityTabRole or similar (AXRadioButton is used
+ // instead). Do the same as NSTabView and put "tab" in the description.
+ return [l10n_util::GetNSStringWithFixup(IDS_ACCNAME_TAB_ROLE_DESCRIPTION)
+ lowercaseString];
+ default:
+ break;
+ }
return NSAccessibilityRoleDescription([self AXRole], [self AXSubrole]);
}
@@ -479,7 +507,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
return [self getStringAttribute:ui::AX_ATTR_NAME];
}
-- (NSString*)AXValue {
+- (id)AXValue {
+ if (node_->GetData().role == ui::AX_ROLE_TAB)
+ return [self AXSelected];
return [self getStringAttribute:ui::AX_ATTR_VALUE];
}
@@ -550,6 +580,13 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
valueWithRange:NSMakeRange(0, [[self AXNumberOfCharacters] intValue])];
}
+// Misc NSAccessibility attributes.
+
+- (NSNumber*)AXSelected {
+ return [NSNumber
+ numberWithBool:node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED)];
+}
+
@end
namespace ui {

Powered by Google App Engine
This is Rietveld 408576698