Index: ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.mm |
diff --git a/ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.mm b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.mm |
new file mode 100644 |
index 0000000000000000000000000000000000000000..3aa5468cc88b947eea717afbdf3765c4335835ed |
--- /dev/null |
+++ b/ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.mm |
@@ -0,0 +1,46 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h" |
+ |
+#if !defined(__has_feature) || !__has_feature(objc_arc) |
+#error "This file requires ARC support." |
+#endif |
+ |
+namespace { |
+const CGFloat kMinTabWidth = 200.0f; |
+const CGFloat kInterTabSpacing = 20.0f; |
+const UIEdgeInsets kEdgeInsets = {20.0f, 20.0f, 20.0f, 20.0f}; |
marq (ping after 24h)
2017/02/20 10:09:47
kSectionInsets, clarifying role rather than type.
edchin
2017/02/21 22:30:10
Done.
|
+} |
+ |
+@implementation TabGridCollectionViewLayout |
+ |
+#pragma mark - UICollectionViewLayout |
+ |
+// This is called whenever the layout is invalidated, including during rotation. |
+- (void)prepareLayout { |
+ [super prepareLayout]; |
+ [self updateLayoutWithBounds:[[self collectionView] bounds].size]; |
+} |
+ |
+#pragma mark - Private |
+ |
+// This sets the appropriate itemSize given the bounds of the collection view. |
+- (void)updateLayoutWithBounds:(CGSize)boundsSize { |
+ int numColumns = static_cast<int>(floor(boundsSize.width - kInterTabSpacing) / |
marq (ping after 24h)
2017/02/20 10:09:47
'columns' is a perfectly good name for this variab
edchin
2017/02/21 22:30:10
Done.
|
+ (kMinTabWidth + kInterTabSpacing)); |
+ CGFloat tabWidth = |
+ (boundsSize.width - kInterTabSpacing * (numColumns + 1)) / numColumns; |
+ if (numColumns < 2 || tabWidth > 250.0f) { |
marq (ping after 24h)
2017/02/20 10:09:47
Extract 250 into a constant and define its use.
edchin
2017/02/21 22:30:10
Done.
|
+ numColumns++; |
+ tabWidth = |
+ (boundsSize.width - kInterTabSpacing * (numColumns + 1)) / numColumns; |
+ } |
+ self.itemSize = CGSizeMake(tabWidth, tabWidth); |
+ self.sectionInset = kEdgeInsets; |
+ self.minimumLineSpacing = kInterTabSpacing; |
+ self.minimumInteritemSpacing = kInterTabSpacing; |
+} |
+ |
+@end |