Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h" | 5 #import "ios/chrome/browser/ui/tabs/tab_strip_controller.h" |
| 6 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h" | 6 #import "ios/chrome/browser/ui/tabs/tab_strip_controller_private.h" |
| 7 | 7 |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 1245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1256 isNewTab:(BOOL)isNewTab { | 1256 isNewTab:(BOOL)isNewTab { |
| 1257 DCHECK_NE(NSNotFound, static_cast<NSInteger>(tabIndex)); | 1257 DCHECK_NE(NSNotFound, static_cast<NSInteger>(tabIndex)); |
| 1258 | 1258 |
| 1259 if (experimental_flags::IsTabStripAutoScrollNewTabsEnabled() && isNewTab) { | 1259 if (experimental_flags::IsTabStripAutoScrollNewTabsEnabled() && isNewTab) { |
| 1260 // The following code calculates the amount of scroll needed to make | 1260 // The following code calculates the amount of scroll needed to make |
| 1261 // |tabIndex| visible in the "virtual" coordinate system, where root is x=0 | 1261 // |tabIndex| visible in the "virtual" coordinate system, where root is x=0 |
| 1262 // and it contains all the tabs laid out as if the tabstrip was infinitely | 1262 // and it contains all the tabs laid out as if the tabstrip was infinitely |
| 1263 // long. The amount of scroll is calculated as a desired length that it is | 1263 // long. The amount of scroll is calculated as a desired length that it is |
| 1264 // just large enough to contain all the tabs to the left of |tabIndex|, with | 1264 // just large enough to contain all the tabs to the left of |tabIndex|, with |
| 1265 // the standard overlap. | 1265 // the standard overlap. |
| 1266 if (tabIndex == [_tabArray count] - 1) { | |
|
rohitrao (ping after 24h)
2017/01/19 01:44:22
If crash restore adds 100 tabs to the tabstrip, wi
liaoyuke
2017/01/20 00:55:51
Yes, the complexity is n^2, every tab view will be
| |
| 1267 const CGFloat tabStripAvailableSpace = | |
| 1268 _tabStripView.frame.size.width - _tabStripView.contentInset.right; | |
| 1269 CGPoint oldOffset = [_tabStripView contentOffset]; | |
| 1270 if (_tabStripView.contentSize.width > tabStripAvailableSpace) { | |
| 1271 CGFloat scrollToPoint = | |
| 1272 _tabStripView.contentSize.width - tabStripAvailableSpace; | |
| 1273 [_tabStripView setContentOffset:CGPointMake(scrollToPoint, 0)]; | |
| 1274 } | |
| 1275 | |
| 1276 // To handle content offset change without making views appear to jump, | |
| 1277 // shift all of the subviews by an amount equal to the size change. This | |
| 1278 // effectively places the subviews back where they were before the change, | |
| 1279 // in terms of screen coordinates. | |
| 1280 CGFloat dx = [_tabStripView contentOffset].x - oldOffset.x; | |
| 1281 for (UIView* view in [_tabStripView subviews]) { | |
|
rohitrao (ping after 24h)
2017/01/19 01:44:22
Is there any way to share this code with the other
liaoyuke
2017/01/20 00:55:51
Done.
| |
| 1282 CGRect frame = [view frame]; | |
| 1283 frame.origin.x += dx; | |
| 1284 [view setFrame:frame]; | |
| 1285 _targetFrames.AddFrame(view, frame); | |
| 1286 } | |
| 1287 return; | |
|
rohitrao (ping after 24h)
2017/01/19 01:44:22
This function now has two early returns, which mak
liaoyuke
2017/01/20 00:55:51
From my point of view, I think it would be non-tri
| |
| 1288 } | |
| 1289 | |
| 1266 NSUInteger numNonClosingTabsToLeft = 0; | 1290 NSUInteger numNonClosingTabsToLeft = 0; |
| 1267 NSUInteger i = 0; | 1291 NSUInteger i = 0; |
| 1268 for (TabView* tab in _tabArray.get()) { | 1292 for (TabView* tab in _tabArray.get()) { |
| 1269 if ([_closingTabs containsObject:tab]) | 1293 if ([_closingTabs containsObject:tab]) |
| 1270 ++i; | 1294 ++i; |
| 1271 | 1295 |
| 1272 if (i == tabIndex) | 1296 if (i == tabIndex) |
| 1273 break; | 1297 break; |
| 1274 | 1298 |
| 1275 ++numNonClosingTabsToLeft; | 1299 ++numNonClosingTabsToLeft; |
| (...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1689 | 1713 |
| 1690 @implementation TabStripController (Testing) | 1714 @implementation TabStripController (Testing) |
| 1691 | 1715 |
| 1692 - (TabView*)existingTabViewForTab:(Tab*)tab { | 1716 - (TabView*)existingTabViewForTab:(Tab*)tab { |
| 1693 NSUInteger tabIndex = [_tabModel indexOfTab:tab]; | 1717 NSUInteger tabIndex = [_tabModel indexOfTab:tab]; |
| 1694 NSUInteger tabViewIndex = [self indexForModelIndex:tabIndex]; | 1718 NSUInteger tabViewIndex = [self indexForModelIndex:tabIndex]; |
| 1695 return [_tabArray objectAtIndex:tabViewIndex]; | 1719 return [_tabArray objectAtIndex:tabViewIndex]; |
| 1696 } | 1720 } |
| 1697 | 1721 |
| 1698 @end | 1722 @end |
| OLD | NEW |