Commit 74675afc authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add voice over "container" behavior

This CL adds accessibility traits to the toolbars such as they are
acting as VoiceOver "container". If the user sets the accessibility
rotor to "containers", the user is able to go navigate quickly between
the toolbars and the webpage.

Bug: 856212
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I309a1308bb200bf9f90aaa4b164a3798c93c0f31
Reviewed-on: https://chromium-review.googlesource.com/1118275Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#571111}
parent 86462a94
...@@ -69,6 +69,21 @@ ...@@ -69,6 +69,21 @@
[super viewDidLoad]; [super viewDidLoad];
[self addStandardActionsForAllButtons]; [self addStandardActionsForAllButtons];
if (@available(iOS 11.0, *)) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(voiceOverChanged:)
name:UIAccessibilityVoiceOverStatusDidChangeNotification
object:nil];
} else {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(voiceOverChanged:)
name:UIAccessibilityVoiceOverStatusChanged
object:nil];
}
[self makeViewAccessibilityTraitsContainer];
// Adds the layout guide to the buttons. // Adds the layout guide to the buttons.
self.view.toolsMenuButton.guideName = kToolsMenuGuide; self.view.toolsMenuButton.guideName = kToolsMenuGuide;
self.view.tabGridButton.guideName = kTabSwitcherGuide; self.view.tabGridButton.guideName = kTabSwitcherGuide;
...@@ -224,6 +239,36 @@ ...@@ -224,6 +239,36 @@
} }
} }
#pragma mark - Accessibility
// Callback called when the voice over value is changed.
- (void)voiceOverChanged:(NSNotification*)notification {
if (!UIAccessibilityIsVoiceOverRunning())
return;
__weak AdaptiveToolbarViewController* weakSelf = self;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
// The accessibility traits of the UIToolbar is only
// available after a certain amount of time after voice over
// activation.
[weakSelf makeViewAccessibilityTraitsContainer];
});
}
// Updates the accessibility traits of the view to have it interpreted as a
// container by voice over.
- (void)makeViewAccessibilityTraitsContainer {
if (self.view.accessibilityTraits == UIAccessibilityTraitNone) {
// TODO(crbug.com/857475): Remove this workaround once it is possible to set
// elements as voice over container. For now, set the accessibility traits
// of the toolbar to the accessibility traits of a UIToolbar allows it to
// act as a voice over container.
UIToolbar* toolbar = [[UIToolbar alloc] init];
self.view.accessibilityTraits = toolbar.accessibilityTraits;
}
}
#pragma mark - Private #pragma mark - Private
// Updates all buttons visibility to match any recent WebState or SizeClass // Updates all buttons visibility to match any recent WebState or SizeClass
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment