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

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

Issue 2706743002: MacViews/a11y: Disable most text-specific attributes for protected textfields. (Closed)
Patch Set: Review comments. Created 3 years, 10 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
« no previous file with comments | « base/mac/sdk_forward_declarations.h ('k') | ui/views/widget/native_widget_mac_accessibility_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9edb01336f2b23b0513e8bf4e20d314dc76925e0..5d3c0caaeae2a62489aede774f6bc7178a36bb5f 100644
--- a/ui/accessibility/platform/ax_platform_node_mac.mm
+++ b/ui/accessibility/platform/ax_platform_node_mac.mm
@@ -355,23 +355,30 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
// Attributes required for user-editable controls.
NSArray* const kValueAttributes = @[ NSAccessibilityValueAttribute ];
- // Attributes required for textfields.
- NSArray* const kTextfieldAttributes = @[
+ // Attributes required for unprotected textfields.
+ NSArray* const kUnprotectedTextfieldAttributes = @[
NSAccessibilityInsertionPointLineNumberAttribute,
NSAccessibilityNumberOfCharactersAttribute,
- NSAccessibilityPlaceholderValueAttribute,
NSAccessibilitySelectedTextAttribute,
NSAccessibilitySelectedTextRangeAttribute,
NSAccessibilityVisibleCharacterRangeAttribute,
];
+ // Required for all textfields, including protected ones.
+ NSString* const kTextfieldAttributes =
+ NSAccessibilityPlaceholderValueAttribute;
+
base::scoped_nsobject<NSMutableArray> axAttributes(
[[NSMutableArray alloc] init]);
[axAttributes addObjectsFromArray:kAllRoleAttributes];
switch (node_->GetData().role) {
case ui::AX_ROLE_TEXT_FIELD:
- [axAttributes addObjectsFromArray:kTextfieldAttributes];
+ [axAttributes addObject:kTextfieldAttributes];
+ if (!ui::AXNodeData::IsFlagSet(node_->GetData().state,
+ ui::AX_STATE_PROTECTED)) {
+ [axAttributes addObjectsFromArray:kUnprotectedTextfieldAttributes];
+ }
// Fallthrough.
case ui::AX_ROLE_CHECK_BOX:
case ui::AX_ROLE_COMBO_BOX:
@@ -405,11 +412,15 @@ 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]) {
+ // NSSecureTextField doesn't allow values to be edited (despite showing up
+ // as editable), match its behavior.
+ if (node_->GetData().HasStateFlag(ui::AX_STATE_PROTECTED))
+ 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 (node_->GetData().role == ui::AX_ROLE_TAB)
+ return !node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED);
}
if ([attributeName isEqualToString:NSAccessibilityValueAttribute] ||
@@ -435,7 +446,8 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
// Check for attributes first. Only the |data.action| should be set here - any
// type-specific information, if needed, should be set below.
- if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
+ if ([attribute isEqualToString:NSAccessibilityValueAttribute] &&
+ !node_->GetData().HasStateFlag(ui::AX_STATE_PROTECTED)) {
data.action = node_->GetData().role == ui::AX_ROLE_TAB
? ui::AX_ACTION_SET_SELECTION
: ui::AX_ACTION_SET_VALUE;
@@ -583,12 +595,18 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
// Text-specific attributes.
- (NSString*)AXSelectedText {
+ if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
+ return nil;
+
NSRange selectedTextRange;
[[self AXSelectedTextRange] getValue:&selectedTextRange];
return [[self AXValue] substringWithRange:selectedTextRange];
}
- (NSValue*)AXSelectedTextRange {
+ if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
+ return nil;
+
int textDir, start, end;
node_->GetIntAttribute(ui::AX_ATTR_TEXT_DIRECTION, &textDir);
node_->GetIntAttribute(ui::AX_ATTR_TEXT_SEL_START, &start);
@@ -603,14 +621,20 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
}
- (NSNumber*)AXNumberOfCharacters {
+ if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
+ return nil;
return @([[self AXValue] length]);
}
- (NSValue*)AXVisibleCharacterRange {
+ if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
+ return nil;
return [NSValue valueWithRange:{0, [[self AXNumberOfCharacters] intValue]}];
}
- (NSNumber*)AXInsertionPointLineNumber {
+ if (ui::AXNodeData::IsFlagSet(node_->GetData().state, ui::AX_STATE_PROTECTED))
+ return nil;
// Multiline is not supported on views.
return @0;
}
« no previous file with comments | « base/mac/sdk_forward_declarations.h ('k') | ui/views/widget/native_widget_mac_accessibility_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698