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

Unified Diff: ios/chrome/browser/ui/tabs/tab_strip_controller.mm

Issue 2628533002: Fix tabs are not rendered properly when restore tabs after crash on iPad (Closed)
Patch Set: Addressed feedback Created 3 years, 11 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/tabs/tab_strip_controller.mm
diff --git a/ios/chrome/browser/ui/tabs/tab_strip_controller.mm b/ios/chrome/browser/ui/tabs/tab_strip_controller.mm
index 715b40e8287fe44be710e795880c888358ca1083..fd96524b688b930ccbf48ae70b14fe0bd7372197 100644
--- a/ios/chrome/browser/ui/tabs/tab_strip_controller.mm
+++ b/ios/chrome/browser/ui/tabs/tab_strip_controller.mm
@@ -286,6 +286,11 @@ - (NSUInteger)modelIndexForDraggedTab;
// Takes into account whether or not the mode toggle button is showing.
- (CGFloat)tabStripVisibleSpace;
+// Shift all of the tab strip subviews by an amount equal to the content offset
+// change, which effectively places the subviews back where they were before the
+// change, in terms of screen coordinates.
+- (void)shiftTabStripSubviews:(CGPoint)oldContentOffset;
+
// Updates the scroll view's content size based on the current set of tabs and
// closing tabs. After updating the content size, repositions views so they
// they will appear stationary on screen.
@@ -313,6 +318,11 @@ - (CGFloat)tabOverlap;
// Returns the minimum tab view width depending on the current layout mode.
- (CGFloat)minTabWidth;
+// Automatically scroll the tab strip view to keep the newly inserted tab view
+// visible.
+// This method must be called with a valid |tabIndex|.
+- (void)autoScrollForNewTab:(NSUInteger)tabIndex;
+
// Updates the content offset of the tab strip view in order to keep the
// selected tab view visible.
// Content offset adjustement is only needed/performed in compact mode or
@@ -1169,6 +1179,16 @@ - (void)removeTabSwitcherToggleButton {
[self updateScrollViewFrameForToggleButton];
}
+- (void)shiftTabStripSubviews:(CGPoint)oldContentOffset {
+ CGFloat dx = [_tabStripView contentOffset].x - oldContentOffset.x;
+ for (UIView* view in [_tabStripView subviews]) {
+ CGRect frame = [view frame];
+ frame.origin.x += dx;
+ [view setFrame:frame];
+ _targetFrames.AddFrame(view, frame);
+ }
+}
+
- (void)updateContentSizeAndRepositionViews {
// TODO(rohitrao): The following lines are duplicated in
// layoutTabStripSubviews. Find a way to consolidate this logic.
@@ -1197,19 +1217,10 @@ - (void)updateContentSizeAndRepositionViews {
// will never change if the content size is growing.)
//
// To handle this without making views appear to jump, shift all of the
- // subviews by an amount equal to the size change. This effectively places
- // the subviews back where they were before the change, in terms of screen
- // coordinates.
+ // subviews by an amount equal to the size change.
CGPoint oldOffset = [_tabStripView contentOffset];
[_tabStripView setContentSize:contentSize];
-
- CGFloat dx = [_tabStripView contentOffset].x - oldOffset.x;
- for (UIView* view in [_tabStripView subviews]) {
- CGRect frame = [view frame];
- frame.origin.x += dx;
- [view setFrame:frame];
- _targetFrames.AddFrame(view, frame);
- }
+ [self shiftTabStripSubviews:oldOffset];
}
- (CGRect)scrollViewFrameForTab:(TabView*)view {
@@ -1252,36 +1263,58 @@ - (CGFloat)minTabWidth {
return IsCompactTablet() ? kMinTabWidthForCompactLayout : kMinTabWidth;
}
-- (void)updateContentOffsetForTabIndex:(NSUInteger)tabIndex
- isNewTab:(BOOL)isNewTab {
+- (void)autoScrollForNewTab:(NSUInteger)tabIndex {
DCHECK_NE(NSNotFound, static_cast<NSInteger>(tabIndex));
- if (experimental_flags::IsTabStripAutoScrollNewTabsEnabled() && isNewTab) {
- // The following code calculates the amount of scroll needed to make
- // |tabIndex| visible in the "virtual" coordinate system, where root is x=0
- // and it contains all the tabs laid out as if the tabstrip was infinitely
- // long. The amount of scroll is calculated as a desired length that it is
- // just large enough to contain all the tabs to the left of |tabIndex|, with
- // the standard overlap.
- NSUInteger numNonClosingTabsToLeft = 0;
- NSUInteger i = 0;
- for (TabView* tab in _tabArray.get()) {
- if ([_closingTabs containsObject:tab])
- ++i;
+ // The following code calculates the amount of scroll needed to make
+ // |tabIndex| visible in the "virtual" coordinate system, where root is x=0
+ // and it contains all the tabs laid out as if the tabstrip was infinitely
+ // long. The amount of scroll is calculated as a desired length that it is
+ // just large enough to contain all the tabs to the left of |tabIndex|, with
+ // the standard overlap.
+ if (tabIndex == [_tabArray count] - 1) {
+ const CGFloat tabStripAvailableSpace =
+ _tabStripView.frame.size.width - _tabStripView.contentInset.right;
+ CGPoint oldOffset = [_tabStripView contentOffset];
+ if (_tabStripView.contentSize.width > tabStripAvailableSpace) {
+ CGFloat scrollToPoint =
+ _tabStripView.contentSize.width - tabStripAvailableSpace;
+ [_tabStripView setContentOffset:CGPointMake(scrollToPoint, 0)];
+ }
- if (i == tabIndex)
- break;
+ // To handle content offset change without making views appear to jump,
+ // shift all of the subviews by an amount equal to the size change.
+ [self shiftTabStripSubviews:oldOffset];
+ return;
+ }
- ++numNonClosingTabsToLeft;
+ NSUInteger numNonClosingTabsToLeft = 0;
+ NSUInteger i = 0;
+ for (TabView* tab in _tabArray.get()) {
+ if ([_closingTabs containsObject:tab])
++i;
- }
- const CGFloat tabHeight = CGRectGetHeight([_tabStripView bounds]);
- CGRect scrollRect =
- CGRectMake(_currentTabWidth * numNonClosingTabsToLeft -
- ([self tabOverlap] * (numNonClosingTabsToLeft - 1)),
- 0, _currentTabWidth, tabHeight);
- [_tabStripView scrollRectToVisible:scrollRect animated:YES];
+ if (i == tabIndex)
+ break;
+
+ ++numNonClosingTabsToLeft;
+ ++i;
+ }
+
+ const CGFloat tabHeight = CGRectGetHeight([_tabStripView bounds]);
+ CGRect scrollRect =
+ CGRectMake(_currentTabWidth * numNonClosingTabsToLeft -
+ ([self tabOverlap] * (numNonClosingTabsToLeft - 1)),
+ 0, _currentTabWidth, tabHeight);
+ [_tabStripView scrollRectToVisible:scrollRect animated:YES];
+}
+
+- (void)updateContentOffsetForTabIndex:(NSUInteger)tabIndex
+ isNewTab:(BOOL)isNewTab {
+ DCHECK_NE(NSNotFound, static_cast<NSInteger>(tabIndex));
+
+ if (experimental_flags::IsTabStripAutoScrollNewTabsEnabled() && isNewTab) {
+ [self autoScrollForNewTab:tabIndex];
return;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698