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

Side by Side Diff: ios/chrome/browser/ui/tabs/tab_strip_controller.mm

Issue 2706983002: Make minimum width of tabs dynamic on iOS. (Closed)
Patch Set: Created 3 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 // Amount of time needed to trigger drag and drop mode when long pressing. 64 // Amount of time needed to trigger drag and drop mode when long pressing.
65 const NSTimeInterval kDragAndDropLongPressDuration = 0.4; 65 const NSTimeInterval kDragAndDropLongPressDuration = 0.4;
66 66
67 // Tab dimensions. 67 // Tab dimensions.
68 const CGFloat kTabOverlap = 26.0; 68 const CGFloat kTabOverlap = 26.0;
69 const CGFloat kTabOverlapForCompactLayout = 30.0; 69 const CGFloat kTabOverlapForCompactLayout = 30.0;
70 70
71 const CGFloat kNewTabOverlap = 8.0; 71 const CGFloat kNewTabOverlap = 8.0;
72 const CGFloat kMaxTabWidth = 265.0; 72 const CGFloat kMaxTabWidth = 265.0;
73 const CGFloat kMaxTabWidthForCompactLayout = 225.0;
73 74
74 // Toggle button dimensions. 75 // Toggle button dimensions.
75 const CGFloat kModeToggleButtonWidth = 36.0; 76 const CGFloat kModeToggleButtonWidth = 36.0;
76 const CGFloat kTabSwitcherToggleButtonWidth = 46.0; 77 const CGFloat kTabSwitcherToggleButtonWidth = 46.0;
77 const CGFloat kModeToggleButtonBackgroundWidth = 62.0; 78 const CGFloat kModeToggleButtonBackgroundWidth = 62.0;
78 79
79 const CGFloat kNewTabRightPadding = 4.0; 80 const CGFloat kNewTabRightPadding = 4.0;
80 const CGFloat kMinTabWidth = 200.0; 81 const CGFloat kMinTabWidth = 200.0;
81 const CGFloat kMinTabWidthForCompactLayout = 160.0; 82 const CGFloat kMinTabWidthForCompactLayout = 160.0;
82 83
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 // flag so that the layout will be animated. 310 // flag so that the layout will be animated.
310 - (void)setNeedsLayoutWithAnimation; 311 - (void)setNeedsLayoutWithAnimation;
311 312
312 // Returns the maximum number of collapsed tabs depending on the current layout 313 // Returns the maximum number of collapsed tabs depending on the current layout
313 // mode. 314 // mode.
314 - (NSUInteger)maxNumCollapsedTabs; 315 - (NSUInteger)maxNumCollapsedTabs;
315 316
316 // Returns the tab overlap width depending on the current layout mode. 317 // Returns the tab overlap width depending on the current layout mode.
317 - (CGFloat)tabOverlap; 318 - (CGFloat)tabOverlap;
318 319
320 // Returns the maximum tab view width depending on the current layout mode.
321 - (CGFloat)maxTabWidth;
322
319 // Returns the minimum tab view width depending on the current layout mode. 323 // Returns the minimum tab view width depending on the current layout mode.
320 - (CGFloat)minTabWidth; 324 - (CGFloat)minTabWidth;
321 325
322 // Automatically scroll the tab strip view to keep the newly inserted tab view 326 // Automatically scroll the tab strip view to keep the newly inserted tab view
323 // visible. 327 // visible.
324 // This method must be called with a valid |tabIndex|. 328 // This method must be called with a valid |tabIndex|.
325 - (void)autoScrollForNewTab:(NSUInteger)tabIndex; 329 - (void)autoScrollForNewTab:(NSUInteger)tabIndex;
326 330
327 // Updates the content offset of the tab strip view in order to keep the 331 // Updates the content offset of the tab strip view in order to keep the
328 // selected tab view visible. 332 // selected tab view visible.
(...skipping 863 matching lines...) Expand 10 before | Expand all | Expand 10 after
1192 - (void)updateContentSizeAndRepositionViews { 1196 - (void)updateContentSizeAndRepositionViews {
1193 // TODO(rohitrao): The following lines are duplicated in 1197 // TODO(rohitrao): The following lines are duplicated in
1194 // layoutTabStripSubviews. Find a way to consolidate this logic. 1198 // layoutTabStripSubviews. Find a way to consolidate this logic.
1195 const NSUInteger tabCount = [_tabArray count] - [_closingTabs count]; 1199 const NSUInteger tabCount = [_tabArray count] - [_closingTabs count];
1196 if (!tabCount) 1200 if (!tabCount)
1197 return; 1201 return;
1198 const CGFloat tabHeight = CGRectGetHeight([_tabStripView bounds]); 1202 const CGFloat tabHeight = CGRectGetHeight([_tabStripView bounds]);
1199 CGFloat visibleSpace = [self tabStripVisibleSpace]; 1203 CGFloat visibleSpace = [self tabStripVisibleSpace];
1200 _currentTabWidth = 1204 _currentTabWidth =
1201 (visibleSpace + ([self tabOverlap] * (tabCount - 1))) / tabCount; 1205 (visibleSpace + ([self tabOverlap] * (tabCount - 1))) / tabCount;
1202 _currentTabWidth = MIN(_currentTabWidth, kMaxTabWidth); 1206 _currentTabWidth = MIN(_currentTabWidth, [self maxTabWidth]);
1203 _currentTabWidth = MAX(_currentTabWidth, [self minTabWidth]); 1207 _currentTabWidth = MAX(_currentTabWidth, [self minTabWidth]);
1204 1208
1205 // Set the content size to be large enough to contain all the tabs at the 1209 // Set the content size to be large enough to contain all the tabs at the
1206 // desired width, with the standard overlap, plus the new tab button. 1210 // desired width, with the standard overlap, plus the new tab button.
1207 CGSize contentSize = CGSizeMake( 1211 CGSize contentSize = CGSizeMake(
1208 _currentTabWidth * tabCount - ([self tabOverlap] * (tabCount - 1)) + 1212 _currentTabWidth * tabCount - ([self tabOverlap] * (tabCount - 1)) +
1209 CGRectGetWidth([_buttonNewTab frame]) - kNewTabOverlap, 1213 CGRectGetWidth([_buttonNewTab frame]) - kNewTabOverlap,
1210 tabHeight); 1214 tabHeight);
1211 if (CGSizeEqualToSize([_tabStripView contentSize], contentSize)) 1215 if (CGSizeEqualToSize([_tabStripView contentSize], contentSize))
1212 return; 1216 return;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 1256
1253 - (NSUInteger)maxNumCollapsedTabs { 1257 - (NSUInteger)maxNumCollapsedTabs {
1254 return IsCompactTablet() ? kMaxNumCollapsedTabsForCompactLayout 1258 return IsCompactTablet() ? kMaxNumCollapsedTabsForCompactLayout
1255 : kMaxNumCollapsedTabs; 1259 : kMaxNumCollapsedTabs;
1256 } 1260 }
1257 1261
1258 - (CGFloat)tabOverlap { 1262 - (CGFloat)tabOverlap {
1259 return IsCompactTablet() ? kTabOverlapForCompactLayout : kTabOverlap; 1263 return IsCompactTablet() ? kTabOverlapForCompactLayout : kTabOverlap;
1260 } 1264 }
1261 1265
1266 - (CGFloat)maxTabWidth {
1267 return IsCompactTablet() ? kMaxTabWidthForCompactLayout : kMaxTabWidth;
1268 }
1269
1262 - (CGFloat)minTabWidth { 1270 - (CGFloat)minTabWidth {
1263 return IsCompactTablet() ? kMinTabWidthForCompactLayout : kMinTabWidth; 1271 return IsCompactTablet() ? kMinTabWidthForCompactLayout : kMinTabWidth;
1264 } 1272 }
1265 1273
1266 - (void)autoScrollForNewTab:(NSUInteger)tabIndex { 1274 - (void)autoScrollForNewTab:(NSUInteger)tabIndex {
1267 DCHECK_NE(NSNotFound, static_cast<NSInteger>(tabIndex)); 1275 DCHECK_NE(NSNotFound, static_cast<NSInteger>(tabIndex));
1268 1276
1269 // The following code calculates the amount of scroll needed to make 1277 // The following code calculates the amount of scroll needed to make
1270 // |tabIndex| visible in the "virtual" coordinate system, where root is x=0 1278 // |tabIndex| visible in the "virtual" coordinate system, where root is x=0
1271 // and it contains all the tabs laid out as if the tabstrip was infinitely 1279 // and it contains all the tabs laid out as if the tabstrip was infinitely
(...skipping 450 matching lines...) Expand 10 before | Expand all | Expand 10 after
1722 1730
1723 @implementation TabStripController (Testing) 1731 @implementation TabStripController (Testing)
1724 1732
1725 - (TabView*)existingTabViewForTab:(Tab*)tab { 1733 - (TabView*)existingTabViewForTab:(Tab*)tab {
1726 NSUInteger tabIndex = [_tabModel indexOfTab:tab]; 1734 NSUInteger tabIndex = [_tabModel indexOfTab:tab];
1727 NSUInteger tabViewIndex = [self indexForModelIndex:tabIndex]; 1735 NSUInteger tabViewIndex = [self indexForModelIndex:tabIndex];
1728 return [_tabArray objectAtIndex:tabViewIndex]; 1736 return [_tabArray objectAtIndex:tabViewIndex];
1729 } 1737 }
1730 1738
1731 @end 1739 @end
OLDNEW
« 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