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 620841889eae237edc5ee3a5a3f4f237f6de4a33..61b7e0ff54afce864aa694800aaea8ce011b1a4d 100644 |
| --- a/ui/accessibility/platform/ax_platform_node_mac.mm |
| +++ b/ui/accessibility/platform/ax_platform_node_mac.mm |
| @@ -10,6 +10,7 @@ |
| #include "base/macros.h" |
| #include "base/strings/sys_string_conversions.h" |
| #import "ui/accessibility/ax_node_data.h" |
|
tapted
2016/06/17 03:32:49
nit: can you update this to #include while you're
Patti Lor
2016/06/17 05:57:35
Done.
|
| +#include "ui/accessibility/ax_view_state.h" |
| #import "ui/accessibility/platform/ax_platform_node_delegate.h" |
|
tapted
2016/06/17 03:32:49
this too - these are not objc headers
Patti Lor
2016/06/17 05:57:35
Done, thanks for noticing :)
|
| #import "ui/gfx/mac/coordinate_conversion.h" |
| @@ -190,6 +191,11 @@ RoleMap BuildSubroleMap() { |
| } // namespace |
| +@interface AXPlatformNodeCocoa () |
| +// Helper function for string attributes that don't require extra processing. |
| +- (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute; |
| +@end |
| + |
| @implementation AXPlatformNodeCocoa |
| // A mapping of AX roles to native roles. |
| @@ -223,40 +229,10 @@ RoleMap BuildSubroleMap() { |
| return gfx::ScreenRectToNSRect(node_->GetBoundsInScreen()); |
| } |
| -- (NSArray*)AXChildren { |
| - if (!node_) |
| - return nil; |
| - int count = node_->GetChildCount(); |
| - NSMutableArray* children = [NSMutableArray arrayWithCapacity:count]; |
| - for (int i = 0; i < count; ++i) |
| - [children addObject:node_->ChildAtIndex(i)]; |
| - return NSAccessibilityUnignoredChildren(children); |
| -} |
| - |
| -- (id)AXParent { |
| - if (!node_) |
| - return nil; |
| - return NSAccessibilityUnignoredAncestor(node_->GetParent()); |
| -} |
| - |
| -- (NSValue*)AXPosition { |
| - return [NSValue valueWithPoint:self.boundsInScreen.origin]; |
| -} |
| - |
| -- (NSString*)AXRole { |
| - if (!node_) |
| - return nil; |
| - return [[self class] nativeRoleFromAXRole:node_->GetData().role]; |
| -} |
| - |
| -- (NSValue*)AXSize { |
| - return [NSValue valueWithSize:self.boundsInScreen.size]; |
| -} |
| - |
| -- (NSString*)AXTitle { |
| - std::string value; |
| - if (node_->GetStringAttribute(ui::AX_ATTR_NAME, &value)) |
| - return base::SysUTF8ToNSString(value); |
| +- (NSString*)getStringAttribute:(ui::AXStringAttribute)attribute { |
| + std::string attributeValue; |
| + if (node_->GetStringAttribute(attribute, &attributeValue)) |
| + return base::SysUTF8ToNSString(attributeValue); |
| return nil; |
| } |
| @@ -280,18 +256,43 @@ RoleMap BuildSubroleMap() { |
| - (NSArray*)accessibilityAttributeNames { |
| // These attributes are required on all accessibility objects. |
| - return @[ |
| - NSAccessibilityChildrenAttribute, |
| - NSAccessibilityParentAttribute, |
| - NSAccessibilityPositionAttribute, |
| - NSAccessibilityRoleAttribute, |
| - NSAccessibilitySizeAttribute, |
| + NSArray* const kAllRoleAttributes = @[ |
| + NSAccessibilityChildrenAttribute, NSAccessibilityParentAttribute, |
| + NSAccessibilityPositionAttribute, NSAccessibilityRoleAttribute, |
| + NSAccessibilitySizeAttribute, NSAccessibilitySubroleAttribute, |
| // Title is required for most elements. Cocoa asks for the value even if it |
| // is omitted here, but won't present it to accessibility APIs without this. |
| NSAccessibilityTitleAttribute, |
| + |
| + // Attributes which are not required, but are general to all roles. |
| + NSAccessibilityRoleDescriptionAttribute |
|
tapted
2016/06/17 03:32:49
nit: comma after
Patti Lor
2016/06/17 05:57:35
Done.
|
| ]; |
| - // TODO(tapted): Add additional attributes based on role. |
| + |
| + // Attributes required for user-editable controls. |
| + NSArray* const kValueAttributes = @[ NSAccessibilityValueAttribute ]; |
| + |
| + base::scoped_nsobject<NSMutableArray> axAttributes( |
| + [[NSMutableArray alloc] init]); |
| + [axAttributes addObjectsFromArray:kAllRoleAttributes]; |
|
tapted
2016/06/17 03:32:49
nit: blank line before
Patti Lor
2016/06/17 05:57:35
Done.
|
| + switch (node_->GetData().role) { |
| + case ui::AX_ROLE_CHECK_BOX: |
| + case ui::AX_ROLE_COMBO_BOX: |
| + case ui::AX_ROLE_MENU_ITEM_CHECK_BOX: |
| + case ui::AX_ROLE_MENU_ITEM_RADIO: |
| + case ui::AX_ROLE_RADIO_BUTTON: |
| + case ui::AX_ROLE_SEARCH_BOX: |
| + case ui::AX_ROLE_SLIDER: |
| + case ui::AX_ROLE_SLIDER_THUMB: |
| + case ui::AX_ROLE_TOGGLE_BUTTON: |
| + case ui::AX_ROLE_TEXT_FIELD: |
| + [axAttributes addObjectsFromArray:kValueAttributes]; |
| + break; |
| + // TODO(tapted): Add additional attributes based on role. |
| + default: |
| + break; |
| + } |
| + return axAttributes.autorelease(); |
| } |
| - (BOOL)accessibilityIsAttributeSettable:(NSString*)attribute { |
| @@ -305,6 +306,68 @@ RoleMap BuildSubroleMap() { |
| return nil; |
| } |
| +// NSAccessibility attributes. |
| + |
| +- (NSArray*)AXChildren { |
| + if (!node_) |
| + return nil; |
| + int count = node_->GetChildCount(); |
| + NSMutableArray* children = [NSMutableArray arrayWithCapacity:count]; |
| + for (int i = 0; i < count; ++i) |
| + [children addObject:node_->ChildAtIndex(i)]; |
| + return NSAccessibilityUnignoredChildren(children); |
| +} |
| + |
| +- (id)AXParent { |
| + if (!node_) |
| + return nil; |
| + return NSAccessibilityUnignoredAncestor(node_->GetParent()); |
| +} |
| + |
| +- (NSValue*)AXPosition { |
| + return [NSValue valueWithPoint:self.boundsInScreen.origin]; |
| +} |
| + |
| +- (NSString*)AXRole { |
| + if (!node_) |
| + return nil; |
| + return [[self class] nativeRoleFromAXRole:node_->GetData().role]; |
| +} |
| + |
| +- (NSString*)AXSubrole { |
| + ui::AXRole role = node_->GetData().role; |
| + switch (role) { |
| + case ui::AX_ROLE_TEXT_FIELD: |
| + if (ui::AXViewState::IsFlagSet(node_->GetData().state, |
| + ui::AX_STATE_PROTECTED)) { |
| + return NSAccessibilitySecureTextFieldSubrole; |
| + } |
|
tapted
2016/06/17 03:32:49
nit: no curlies required
Patti Lor
2016/06/17 05:57:35
Done.
|
| + break; |
| + default: |
| + break; |
| + } |
| + return [AXPlatformNodeCocoa nativeSubroleFromAXRole:role]; |
| +} |
| + |
| +- (NSString*)AXRoleDescription { |
| + NSString* description = [self getStringAttribute:ui::AX_ATTR_DESCRIPTION]; |
| + if (!description) |
| + return NSAccessibilityRoleDescription([self AXRole], [self AXSubrole]); |
| + return description; |
| +} |
| + |
| +- (NSValue*)AXSize { |
| + return [NSValue valueWithSize:self.boundsInScreen.size]; |
| +} |
| + |
| +- (NSString*)AXTitle { |
| + return [self getStringAttribute:ui::AX_ATTR_NAME]; |
| +} |
| + |
| +- (NSString*)AXValue { |
| + return [self getStringAttribute:ui::AX_ATTR_VALUE]; |
| +} |
| + |
| @end |
| namespace ui { |