OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #import "ios/clean/chrome/browser/ui/tab_grid/tab_grid_collection_view_layout.h" | |
6 | |
7 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
8 #error "This file requires ARC support." | |
9 #endif | |
10 | |
11 namespace { | |
12 const CGFloat kMinTabWidth = 200.0f; | |
13 const CGFloat kInterTabSpacing = 20.0f; | |
14 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.
| |
15 } | |
16 | |
17 @implementation TabGridCollectionViewLayout | |
18 | |
19 #pragma mark - UICollectionViewLayout | |
20 | |
21 // This is called whenever the layout is invalidated, including during rotation. | |
22 - (void)prepareLayout { | |
23 [super prepareLayout]; | |
24 [self updateLayoutWithBounds:[[self collectionView] bounds].size]; | |
25 } | |
26 | |
27 #pragma mark - Private | |
28 | |
29 // This sets the appropriate itemSize given the bounds of the collection view. | |
30 - (void)updateLayoutWithBounds:(CGSize)boundsSize { | |
31 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.
| |
32 (kMinTabWidth + kInterTabSpacing)); | |
33 CGFloat tabWidth = | |
34 (boundsSize.width - kInterTabSpacing * (numColumns + 1)) / numColumns; | |
35 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.
| |
36 numColumns++; | |
37 tabWidth = | |
38 (boundsSize.width - kInterTabSpacing * (numColumns + 1)) / numColumns; | |
39 } | |
40 self.itemSize = CGSizeMake(tabWidth, tabWidth); | |
41 self.sectionInset = kEdgeInsets; | |
42 self.minimumLineSpacing = kInterTabSpacing; | |
43 self.minimumInteritemSpacing = kInterTabSpacing; | |
44 } | |
45 | |
46 @end | |
OLD | NEW |