Commit cc989fc9 authored by Mark Cogan's avatar Mark Cogan Committed by Commit Bot

[iOS] RTL paging fixes for Tab Grid.

Fix various paging isssues in RTL with the Tab Grid.

- Tapping the page control, or otherwise setting |currentPage| on the
  TabGridViewController will set the correct offset for the scroll view.

- Scrolling the view will set the correct page.

- Scrolling the view moves the page control correctly.

Bug: 822328
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ic8f53c894fd4388b97d82093ac35ad675caa87a5
Reviewed-on: https://chromium-review.googlesource.com/1013927Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Mark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#551317}
parent 5b0f4e9c
......@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/tab_grid/tab_grid_view_controller.h"
#include "base/strings/sys_string_conversions.h"
#import "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_commands.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_consumer.h"
#import "ios/chrome/browser/ui/tab_grid/grid/grid_image_data_source.h"
......@@ -32,10 +33,23 @@ typedef NS_ENUM(NSUInteger, TabGridConfiguration) {
// Computes the page from the offset and width of |scrollView|.
TabGridPage GetPageFromScrollView(UIScrollView* scrollView) {
// TODO(crbug.com/822328) : Fix for RTL.
CGFloat pageWidth = scrollView.frame.size.width;
float fractionalPage = scrollView.contentOffset.x / pageWidth;
return static_cast<TabGridPage>(lround(fractionalPage));
NSUInteger page = lround(scrollView.contentOffset.x / pageWidth);
if (UseRTLLayout()) {
// In RTL, page indexes are inverted, so subtract |page| from the highest-
// index TabGridPage value.
return static_cast<TabGridPage>(TabGridPageRemoteTabs - page);
}
return static_cast<TabGridPage>(page);
}
NSUInteger GetPageIndexFromPage(TabGridPage page) {
if (UseRTLLayout()) {
// In RTL, page indexes are inverted, so subtract |page| from the highest-
// index TabGridPage value.
return static_cast<NSUInteger>(TabGridPageRemoteTabs - page);
}
return static_cast<NSUInteger>(page);
}
// Temporary alert used while building this feature.
......@@ -191,6 +205,9 @@ UIAlertController* NotImplementedAlert() {
CGFloat offsetWidth =
self.scrollView.contentSize.width - self.scrollView.frame.size.width;
CGFloat offset = scrollView.contentOffset.x / offsetWidth;
// In RTL, flip the offset.
if (UseRTLLayout())
offset = 1.0 - offset;
self.topToolbar.pageControl.sliderPosition = offset;
TabGridPage page = GetPageFromScrollView(scrollView);
......@@ -296,8 +313,8 @@ UIAlertController* NotImplementedAlert() {
return;
}
CGFloat pageWidth = self.scrollView.frame.size.width;
NSUInteger page = static_cast<NSUInteger>(currentPage);
CGPoint offset = CGPointMake(page * pageWidth, 0);
NSUInteger pageIndex = GetPageIndexFromPage(currentPage);
CGPoint offset = CGPointMake(pageIndex * pageWidth, 0);
// If the view is visible, animate the change. Otherwise don't.
if (self.view.window == nil) {
self.scrollView.contentOffset = offset;
......
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