Chromium Code Reviews| 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]) | |
|
lody
2017/05/17 08:23:33
It looks like single-line ifs in this file use { }
gambard
2017/05/17 09:39:43
Done.
| |
| 154 return [ContentSuggestionsMostVisitedCell defaultSize]; | |
| 155 return [super collectionView:collectionView | |
| 156 layout:collectionViewLayout | |
| 157 sizeForItemAtIndexPath:indexPath]; | |
| 158 } | |
| 159 | |
| 160 - (UIEdgeInsets)collectionView:(UICollectionView*)collectionView | |
| 161 layout:(UICollectionViewLayout*)collectionViewLayout | |
| 162 insetForSectionAtIndex:(NSInteger)section { | |
| 163 if ([self.collectionUpdater isMostVisitedSection:section]) { | |
| 164 CGFloat margin = content_suggestions::centeredTilesMarginForWidth( | |
| 165 collectionView.frame.size.width); | |
| 166 return UIEdgeInsetsMake(0, margin, 0, margin); | |
| 167 } | |
| 168 return [super collectionView:collectionView | |
| 169 layout:collectionViewLayout | |
| 170 insetForSectionAtIndex:section]; | |
| 171 } | |
| 172 | |
| 173 - (CGFloat)collectionView:(UICollectionView*)collectionView | |
| 174 layout:(UICollectionViewLayout*) | |
| 175 collectionViewLayout | |
| 176 minimumLineSpacingForSectionAtIndex:(NSInteger)section { | |
| 177 if ([self.collectionUpdater isMostVisitedSection:section]) { | |
| 178 return content_suggestions::spacingBetweenTiles(); | |
| 179 } | |
| 180 return [super collectionView:collectionView | |
| 181 layout:collectionViewLayout | |
| 182 minimumLineSpacingForSectionAtIndex:section]; | |
| 183 } | |
| 184 | |
| 145 #pragma mark - MDCCollectionViewStylingDelegate | 185 #pragma mark - MDCCollectionViewStylingDelegate |
| 146 | 186 |
| 147 - (UIColor*)collectionView:(nonnull UICollectionView*)collectionView | 187 - (UIColor*)collectionView:(nonnull UICollectionView*)collectionView |
| 148 cellBackgroundColorAtIndexPath:(nonnull NSIndexPath*)indexPath { | 188 cellBackgroundColorAtIndexPath:(nonnull NSIndexPath*)indexPath { |
| 149 if ([self.collectionUpdater | 189 if ([self.collectionUpdater |
| 150 shouldUseCustomStyleForSection:indexPath.section]) { | 190 shouldUseCustomStyleForSection:indexPath.section]) { |
| 151 return [UIColor clearColor]; | 191 return [UIColor clearColor]; |
| 152 } | 192 } |
| 153 return [UIColor whiteColor]; | 193 return [UIColor whiteColor]; |
| 154 } | 194 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 218 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { | 258 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { |
| 219 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) | 259 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) |
| 220 return; | 260 return; |
| 221 | 261 |
| 222 NSIndexPath* emptyItem = | 262 NSIndexPath* emptyItem = |
| 223 [self.collectionUpdater addEmptyItemForSection:section]; | 263 [self.collectionUpdater addEmptyItemForSection:section]; |
| 224 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; | 264 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; |
| 225 } | 265 } |
| 226 | 266 |
| 227 @end | 267 @end |
| OLD | NEW |