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

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

Issue 2684203002: MacViews/a11y: Allow accessibility clients to set new selections in Textfields. (Closed)
Patch Set: Rebase. 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 | « no previous file | 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 3cf4db2cbf039007eeb6202e62489804c1fe57ac..9edb01336f2b23b0513e8bf4e20d314dc76925e0 100644
--- a/ui/accessibility/platform/ax_platform_node_mac.mm
+++ b/ui/accessibility/platform/ax_platform_node_mac.mm
@@ -392,14 +392,15 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
}
- (BOOL)accessibilityIsAttributeSettable:(NSString*)attributeName {
+ if (node_->GetData().HasStateFlag(ui::AX_STATE_DISABLED))
+ return NO;
+
// 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:NSAccessibilitySelectedChildrenAttribute] ||
[attributeName
- isEqualToString:NSAccessibilitySelectedTextRangeAttribute] ||
- [attributeName
isEqualToString:NSAccessibilityVisibleCharacterRangeAttribute]) {
return NO;
}
@@ -412,7 +413,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
}
if ([attributeName isEqualToString:NSAccessibilityValueAttribute] ||
- [attributeName isEqualToString:NSAccessibilitySelectedTextAttribute]) {
+ [attributeName isEqualToString:NSAccessibilitySelectedTextAttribute] ||
+ [attributeName
+ isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
return !ui::AXNodeData::IsFlagSet(node_->GetData().state,
ui::AX_STATE_READ_ONLY);
}
@@ -438,6 +441,9 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
: ui::AX_ACTION_SET_VALUE;
} else if ([attribute isEqualToString:NSAccessibilitySelectedTextAttribute]) {
data.action = ui::AX_ACTION_REPLACE_SELECTED_TEXT;
+ } else if ([attribute
+ isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
+ data.action = ui::AX_ACTION_SET_SELECTION;
} else if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) {
if ([value isKindOfClass:[NSNumber class]]) {
data.action =
@@ -446,8 +452,14 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
}
// Set type-specific information as necessary for actions set above.
- if ([value isKindOfClass:[NSString class]])
+ if ([value isKindOfClass:[NSString class]]) {
data.value = base::SysNSStringToUTF16(value);
+ } else if (data.action == ui::AX_ACTION_SET_SELECTION &&
+ [value isKindOfClass:[NSValue class]]) {
+ NSRange range = [value rangeValue];
+ data.anchor_offset = range.location;
+ data.focus_offset = NSMaxRange(range);
+ }
if (data.action != ui::AX_ACTION_NONE)
node_->GetDelegate()->AccessibilityPerformAction(data);
@@ -510,17 +522,16 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
}
- (NSNumber*)AXEnabled {
- return [NSNumber
- numberWithBool:!ui::AXNodeData::IsFlagSet(node_->GetData().state,
- ui::AX_STATE_DISABLED)];
+ return @(!ui::AXNodeData::IsFlagSet(node_->GetData().state,
+ ui::AX_STATE_DISABLED));
}
- (NSNumber*)AXFocused {
if (ui::AXNodeData::IsFlagSet(node_->GetData().state,
ui::AX_STATE_FOCUSABLE))
- return [NSNumber numberWithBool:(node_->GetDelegate()->GetFocus() ==
- node_->GetNativeViewAccessible())];
- return [NSNumber numberWithBool:NO];
+ return
+ @(node_->GetDelegate()->GetFocus() == node_->GetNativeViewAccessible());
+ return @NO;
}
- (id)AXParent {
@@ -562,8 +573,7 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
// Misc attributes.
- (NSNumber*)AXSelected {
- return [NSNumber
- numberWithBool:node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED)];
+ return @(node_->GetData().HasStateFlag(ui::AX_STATE_SELECTED));
}
- (NSString*)AXPlaceholderValue {
@@ -589,22 +599,20 @@ void NotifyMacEvent(AXPlatformNodeCocoa* target, ui::AXEvent event_type) {
bool isReversed = (textDir == ui::AX_TEXT_DIRECTION_RTL) ||
(textDir == ui::AX_TEXT_DIRECTION_BTT);
int beginSelectionIndex = (end > start && !isReversed) ? start : end;
- return [NSValue
- valueWithRange:NSMakeRange(beginSelectionIndex, abs(end - start))];
+ return [NSValue valueWithRange:{beginSelectionIndex, abs(end - start)}];
}
- (NSNumber*)AXNumberOfCharacters {
- return [NSNumber numberWithInteger:[[self AXValue] length]];
+ return @([[self AXValue] length]);
}
- (NSValue*)AXVisibleCharacterRange {
- return [NSValue
- valueWithRange:NSMakeRange(0, [[self AXNumberOfCharacters] intValue])];
+ return [NSValue valueWithRange:{0, [[self AXNumberOfCharacters] intValue]}];
}
- (NSNumber*)AXInsertionPointLineNumber {
// Multiline is not supported on views.
- return [NSNumber numberWithInteger:0];
+ return @0;
}
@end
« no previous file with comments | « no previous file | ui/views/widget/native_widget_mac_accessibility_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698