Commit b213eb0d authored by edchin's avatar edchin Committed by Commit Bot

[ios] Synchronize tab grid page control with scroll view

Previously there was a bug where there was a mismatch of internal states
between the page control and the scroll view.
It is important that they both are synchronized with the same current
page.
This CL fixes the lack of synchronization.

TBR=marq@chromium.org
Bug: 825898

Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I284460d9581a05f780057ef53715484254978859
Reviewed-on: https://chromium-review.googlesource.com/981302
Commit-Queue: edchin <edchin@chromium.org>
Reviewed-by: default avataredchin <edchin@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545953}
parent e4bfb43f
...@@ -195,6 +195,14 @@ NSString* StringForItemCount(long count) { ...@@ -195,6 +195,14 @@ NSString* StringForItemCount(long count) {
self.selectedImageView.center = self.selectedImageView.center =
[self convertPoint:RectCenter(self.bounds) toView:self.sliderView]; [self convertPoint:RectCenter(self.bounds) toView:self.sliderView];
_sliderPosition = sliderPosition; _sliderPosition = sliderPosition;
// |_selectedPage| should be kept in sync with the slider position.
if (sliderPosition < 0.25)
_selectedPage = TabGridPageIncognitoTabs;
else if (sliderPosition < 0.75)
_selectedPage = TabGridPageRegularTabs;
else
_selectedPage = TabGridPageRemoteTabs;
} }
// Setters for the control's text values. These need to update three things: // Setters for the control's text values. These need to update three things:
......
...@@ -164,20 +164,21 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -164,20 +164,21 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
- (void)scrollViewDidScroll:(UIScrollView*)scrollView { - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
if (scrollView.dragging || scrollView.decelerating) { if (scrollView.dragging || scrollView.decelerating) {
// Only when user initiates scroll through dragging.
CGFloat offsetWidth = CGFloat offsetWidth =
self.scrollView.contentSize.width - self.scrollView.frame.size.width; self.scrollView.contentSize.width - self.scrollView.frame.size.width;
CGFloat offset = scrollView.contentOffset.x / offsetWidth; CGFloat offset = scrollView.contentOffset.x / offsetWidth;
self.topToolbar.pageControl.sliderPosition = offset; self.topToolbar.pageControl.sliderPosition = offset;
}
// Bookkeeping for the current page. // Bookkeeping for the current page.
// TODO(crbug.com/822328) : Fix for RTL. // TODO(crbug.com/822328) : Fix for RTL.
CGFloat pageWidth = scrollView.frame.size.width; CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth; float fractionalPage = scrollView.contentOffset.x / pageWidth;
NSUInteger page = lround(fractionalPage); NSUInteger page = lround(fractionalPage);
if (page != self.currentPage) { if (page != self.currentPage) {
_currentPage = static_cast<TabGridPage>(page); _currentPage = static_cast<TabGridPage>(page);
[self configureButtonsForOriginalAndCurrentPage]; [self configureButtonsForOriginalAndCurrentPage];
}
} }
} }
...@@ -279,7 +280,7 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) { ...@@ -279,7 +280,7 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
_currentPage = currentPage; _currentPage = currentPage;
} else { } else {
[self.scrollView setContentOffset:offset animated:YES]; [self.scrollView setContentOffset:offset animated:YES];
// _currentPage is set in scrollViewDidEndDecelerating: // _currentPage is set in scrollViewDidScroll:
} }
} }
......
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