OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/content_suggestions/content_suggestions_view_cont
roller.h" | 5 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_view_cont
roller.h" |
6 | 6 |
| 7 #include "base/mac/foundation_util.h" |
7 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 8 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" | 9 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" |
9 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_mos
t_visited_cell.h" |
10 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" | 12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_updater.h" |
| 13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio
n_utils.h" |
11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" | 14 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.
h" |
12 | 15 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
14 #error "This file requires ARC support." | 17 #error "This file requires ARC support." |
15 #endif | 18 #endif |
16 | 19 |
17 namespace { | 20 namespace { |
18 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>; | 21 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>; |
19 } | 22 } |
20 | 23 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 [self.suggestionCommandHandler openPageForItem:item]; | 138 [self.suggestionCommandHandler openPageForItem:item]; |
136 break; | 139 break; |
137 case ContentSuggestionTypeMostVisited: | 140 case ContentSuggestionTypeMostVisited: |
138 // TODO(crbug.com/707754): Open the most visited site. | 141 // TODO(crbug.com/707754): Open the most visited site. |
139 break; | 142 break; |
140 case ContentSuggestionTypeEmpty: | 143 case ContentSuggestionTypeEmpty: |
141 break; | 144 break; |
142 } | 145 } |
143 } | 146 } |
144 | 147 |
| 148 #pragma mark - UICollectionViewDelegateFlowLayout |
| 149 |
| 150 - (CGSize)collectionView:(UICollectionView*)collectionView |
| 151 layout:(UICollectionViewLayout*)collectionViewLayout |
| 152 sizeForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 153 if ([self.collectionUpdater isMostVisitedSection:indexPath.section]) { |
| 154 return [ContentSuggestionsMostVisitedCell defaultSize]; |
| 155 } |
| 156 return [super collectionView:collectionView |
| 157 layout:collectionViewLayout |
| 158 sizeForItemAtIndexPath:indexPath]; |
| 159 } |
| 160 |
| 161 - (UIEdgeInsets)collectionView:(UICollectionView*)collectionView |
| 162 layout:(UICollectionViewLayout*)collectionViewLayout |
| 163 insetForSectionAtIndex:(NSInteger)section { |
| 164 if ([self.collectionUpdater isMostVisitedSection:section]) { |
| 165 CGFloat margin = content_suggestions::centeredTilesMarginForWidth( |
| 166 collectionView.frame.size.width); |
| 167 return UIEdgeInsetsMake(0, margin, 0, margin); |
| 168 } |
| 169 return [super collectionView:collectionView |
| 170 layout:collectionViewLayout |
| 171 insetForSectionAtIndex:section]; |
| 172 } |
| 173 |
| 174 - (CGFloat)collectionView:(UICollectionView*)collectionView |
| 175 layout:(UICollectionViewLayout*) |
| 176 collectionViewLayout |
| 177 minimumLineSpacingForSectionAtIndex:(NSInteger)section { |
| 178 if ([self.collectionUpdater isMostVisitedSection:section]) { |
| 179 return content_suggestions::spacingBetweenTiles(); |
| 180 } |
| 181 return [super collectionView:collectionView |
| 182 layout:collectionViewLayout |
| 183 minimumLineSpacingForSectionAtIndex:section]; |
| 184 } |
| 185 |
145 #pragma mark - MDCCollectionViewStylingDelegate | 186 #pragma mark - MDCCollectionViewStylingDelegate |
146 | 187 |
147 - (UIColor*)collectionView:(nonnull UICollectionView*)collectionView | 188 - (UIColor*)collectionView:(nonnull UICollectionView*)collectionView |
148 cellBackgroundColorAtIndexPath:(nonnull NSIndexPath*)indexPath { | 189 cellBackgroundColorAtIndexPath:(nonnull NSIndexPath*)indexPath { |
149 if ([self.collectionUpdater | 190 if ([self.collectionUpdater |
150 shouldUseCustomStyleForSection:indexPath.section]) { | 191 shouldUseCustomStyleForSection:indexPath.section]) { |
151 return [UIColor clearColor]; | 192 return [UIColor clearColor]; |
152 } | 193 } |
153 return [UIColor whiteColor]; | 194 return [UIColor whiteColor]; |
154 } | 195 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { | 259 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { |
219 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) | 260 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) |
220 return; | 261 return; |
221 | 262 |
222 NSIndexPath* emptyItem = | 263 NSIndexPath* emptyItem = |
223 [self.collectionUpdater addEmptyItemForSection:section]; | 264 [self.collectionUpdater addEmptyItemForSection:section]; |
224 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; | 265 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; |
225 } | 266 } |
226 | 267 |
227 @end | 268 @end |
OLD | NEW |