| 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..2845950d812966d7d3131546b8777f1cdf400ecd 100644
|
| --- a/ui/accessibility/platform/ax_platform_node_mac.mm
|
| +++ b/ui/accessibility/platform/ax_platform_node_mac.mm
|
| @@ -9,8 +9,9 @@
|
|
|
| #include "base/macros.h"
|
| #include "base/strings/sys_string_conversions.h"
|
| -#import "ui/accessibility/ax_node_data.h"
|
| -#import "ui/accessibility/platform/ax_platform_node_delegate.h"
|
| +#include "ui/accessibility/ax_node_data.h"
|
| +#include "ui/accessibility/ax_view_state.h"
|
| +#include "ui/accessibility/platform/ax_platform_node_delegate.h"
|
| #import "ui/gfx/mac/coordinate_conversion.h"
|
|
|
| namespace {
|
| @@ -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,47 @@ RoleMap BuildSubroleMap() {
|
|
|
| - (NSArray*)accessibilityAttributeNames {
|
| // These attributes are required on all accessibility objects.
|
| - return @[
|
| + 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,
|
| ];
|
| - // 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];
|
| + 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 +310,67 @@ 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;
|
| + 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 {
|
|
|