Commit d94921c0 authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Fix VoiceOver Issues in Tabgrid

- Updates _currentPage properly in response to 3-finger accessibility swipe. This will now properly read out the currently visible page if a user swipes to a different page.
- Ensures that only the currently visible page's elements can be selected in the scroll view. This resolves an issue VoiceOver was having with what page to readout and to focus on. Oftentimes the visible page was not readout or selectable.

Video: https://drive.google.com/open?id=1Q62MUlrVcNlqnFIQOfw_YiGHinTKb_45

Bug: 880079
Change-Id: Ic9a91762e9a5f04b267ac588c83a675d61bd53cf
Reviewed-on: https://chromium-review.googlesource.com/1221474
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Original-Commit-Position: refs/heads/master@{#592818}
Reviewed-on: https://chromium-review.googlesource.com/1238995
Cr-Commit-Position: refs/heads/master@{#595075}
parent 4921575f
......@@ -304,21 +304,42 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
// scrolling.
self.topToolbar.pageControl.userInteractionEnabled = NO;
self.pageChangeInteraction = PageChangeInteractionScrollDrag;
[self updatePageViewAccessibilityVisibility];
}
- (void)scrollViewDidEndDragging:(UIScrollView*)scrollView
willDecelerate:(BOOL)decelerate {
// Re-enable the page control since the user isn't dragging anymore.
self.topToolbar.pageControl.userInteractionEnabled = YES;
[self updatePageViewAccessibilityVisibility];
}
- (void)scrollViewDidEndDecelerating:(UIScrollView*)scrollView {
// Mark the interaction as ended, so that scrolls that don't change page don't
// cause other interactions to be mislabeled.
self.pageChangeInteraction = PageChangeInteractionNone;
[self updatePageViewAccessibilityVisibility];
// Update _currentPage if scroll view has moved to a new page. Especially
// important here for 3-finger accessibility swipes since it's not registered
// as dragging in scrollViewDidScroll:
TabGridPage page = GetPageFromScrollView(scrollView);
if (page != _currentPage) {
// Original current page is about to not be visible. Disable it from being
// focused by VoiceOver.
self.currentPageViewController.view.accessibilityElementsHidden = YES;
_currentPage = page;
// Allow VoiceOver to focus on the new current page's elements.
self.currentPageViewController.view.accessibilityElementsHidden = NO;
[self broadcastIncognitoContentVisibility];
[self configureButtonsForActiveAndCurrentPage];
// TODO(crbug.com/872303) : This is a workaround because TabRestoreService
// does not notify observers when entries are removed. When close all tabs
// removes entries, the remote tabs page in the tab grid are not updated.
// This ensures that the table is updated whenever scrolling to it.
if (_currentPage == TabGridPageRemoteTabs) {
[self.remoteTabsViewController loadModel];
[self.remoteTabsViewController.tableView reloadData];
}
}
}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView*)scrollView {
......@@ -531,9 +552,15 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
// the ivar may have been set before the scroll view could be updated. Calling
// this method should always update the scroll view's offset if possible.
// Original current page is about to not be visible. Disable it from being
// focused by VoiceOver.
self.currentPageViewController.view.accessibilityElementsHidden = YES;
// If the view isn't loaded yet, just do bookkeeping on _currentPage.
if (!self.viewLoaded) {
_currentPage = currentPage;
// Allow VoiceOver to focus on the new current page's elements.
self.currentPageViewController.view.accessibilityElementsHidden = NO;
return;
}
CGFloat pageWidth = self.scrollView.frame.size.width;
......@@ -556,6 +583,9 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
_currentPage = currentPage;
}
}
// Allow VoiceOver to focus on the new current page's elements.
self.currentPageViewController.view.accessibilityElementsHidden = NO;
// TODO(crbug.com/872303) : This is a workaround because TabRestoreService
// does not notify observers when entries are removed. When close all tabs
// removes entries, the remote tabs page in the tab grid are not updated. This
......@@ -582,7 +612,6 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
if (_scrollViewAnimatingContentOffset == scrollViewAnimatingContentOffset)
return;
_scrollViewAnimatingContentOffset = scrollViewAnimatingContentOffset;
[self updatePageViewAccessibilityVisibility];
}
// Adds the scroll view and sets constraints.
......@@ -908,19 +937,6 @@ NSUInteger GetPageIndexFromPage(TabGridPage page) {
kTabGridCloseAllButtonIdentifier;
}
// Updates the visibility of the pages' accessibility elements. When
// |scrollView| is scrolling, all pages should be visible. When stationary,
// however, the accessibility elements of off-screen pages should be hidden.
- (void)updatePageViewAccessibilityVisibility {
BOOL scrolling = self.scrollView.dragging || self.scrollView.decelerating ||
self.scrollViewAnimatingContentOffset;
UIViewController* currentPageViewController = self.currentPageViewController;
for (UIViewController* pageViewController in self.pageViewControllers) {
pageViewController.view.accessibilityElementsHidden =
!scrolling && pageViewController != currentPageViewController;
}
}
// Shows the two toolbars and the floating button. Suitable for use in
// animations.
- (void)showToolbars {
......
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