| 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 #include "base/mac/foundation_util.h" |
| 8 #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" |
| 9 #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" |
| 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 244 NSIndexPath* touchedItemIndexPath = | 244 NSIndexPath* touchedItemIndexPath = |
| 245 [self.collectionView indexPathForItemAtPoint:touchLocation]; | 245 [self.collectionView indexPathForItemAtPoint:touchLocation]; |
| 246 if (!touchedItemIndexPath || | 246 if (!touchedItemIndexPath || |
| 247 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { | 247 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { |
| 248 // Make sure there is an item at this position. | 248 // Make sure there is an item at this position. |
| 249 return; | 249 return; |
| 250 } | 250 } |
| 251 CollectionViewItem* touchedItem = | 251 CollectionViewItem* touchedItem = |
| 252 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; | 252 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; |
| 253 | 253 |
| 254 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != | 254 ContentSuggestionType type = |
| 255 ContentSuggestionTypeArticle) { | 255 [self.collectionUpdater contentSuggestionTypeForItem:touchedItem]; |
| 256 // Only trigger context menu on articles. | 256 switch (type) { |
| 257 return; | 257 case ContentSuggestionTypeArticle: |
| 258 [self.suggestionCommandHandler |
| 259 displayContextMenuForArticle:touchedItem |
| 260 atPoint:touchLocation |
| 261 atIndexPath:touchedItemIndexPath]; |
| 262 break; |
| 263 case ContentSuggestionTypeMostVisited: |
| 264 [self.suggestionCommandHandler |
| 265 displayContextMenuForMostVisitedItem:touchedItem |
| 266 atPoint:touchLocation |
| 267 atIndexPath:touchedItemIndexPath]; |
| 268 break; |
| 269 default: |
| 270 break; |
| 258 } | 271 } |
| 259 | 272 |
| 260 [self.suggestionCommandHandler | |
| 261 displayContextMenuForArticle:touchedItem | |
| 262 atPoint:touchLocation | |
| 263 atIndexPath:touchedItemIndexPath]; | |
| 264 } | 273 } |
| 265 | 274 |
| 266 // Checks if the |section| is empty and add an empty element if it is the case. | 275 // Checks if the |section| is empty and add an empty element if it is the case. |
| 267 // Must be called from inside a performBatchUpdates: block. | 276 // Must be called from inside a performBatchUpdates: block. |
| 268 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { | 277 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { |
| 269 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) | 278 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) |
| 270 return; | 279 return; |
| 271 | 280 |
| 272 NSIndexPath* emptyItem = | 281 NSIndexPath* emptyItem = |
| 273 [self.collectionUpdater addEmptyItemForSection:section]; | 282 [self.collectionUpdater addEmptyItemForSection:section]; |
| 274 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; | 283 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; |
| 275 } | 284 } |
| 276 | 285 |
| 277 // Tells WebToolbarController to resign focus to the omnibox. | 286 // Tells WebToolbarController to resign focus to the omnibox. |
| 278 - (void)blurOmnibox { | 287 - (void)blurOmnibox { |
| 279 // TODO(crbug.com/700375): once the omnibox is part of Content Suggestions, | 288 // TODO(crbug.com/700375): once the omnibox is part of Content Suggestions, |
| 280 // remove the fake omnibox focus here. | 289 // remove the fake omnibox focus here. |
| 281 } | 290 } |
| 282 | 291 |
| 283 @end | 292 @end |
| OLD | NEW |