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

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: Update to allow selection range changes when read-only. 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/controls/textfield/textfield.cc » ('j') | ui/views/controls/textfield/textfield.cc » ('J')
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 5bfa69c675fa5c1124ea5fcf8954307ef461170f..cae3c2de2461ad4b2424d1cfe0dc14cd8edaaa35 100644
--- a/ui/accessibility/platform/ax_platform_node_mac.mm
+++ b/ui/accessibility/platform/ax_platform_node_mac.mm
@@ -370,18 +370,24 @@ 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;
}
+ if ([attributeName
+ isEqualToString:NSAccessibilitySelectedTextRangeAttribute]) {
+ return YES;
+ }
+
// 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] &&
@@ -416,6 +422,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 =
@@ -424,8 +433,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);
@@ -488,17 +503,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 {
@@ -540,8 +554,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 {
@@ -567,22 +580,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/controls/textfield/textfield.cc » ('j') | ui/views/controls/textfield/textfield.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698