| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 #pragma mark - UIViewController | 55 #pragma mark - UIViewController |
| 56 | 56 |
| 57 - (void)viewDidLoad { | 57 - (void)viewDidLoad { |
| 58 [super viewDidLoad]; | 58 [super viewDidLoad]; |
| 59 | 59 |
| 60 _collectionUpdater.collectionViewController = self; | 60 _collectionUpdater.collectionViewController = self; |
| 61 | 61 |
| 62 self.collectionView.delegate = self; | 62 self.collectionView.delegate = self; |
| 63 self.styler.cellStyle = MDCCollectionViewCellStyleCard; | 63 self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| 64 |
| 65 UILongPressGestureRecognizer* longPressRecognizer = |
| 66 [[UILongPressGestureRecognizer alloc] |
| 67 initWithTarget:self |
| 68 action:@selector(handleLongPress:)]; |
| 69 longPressRecognizer.numberOfTouchesRequired = 1; |
| 70 [self.collectionView addGestureRecognizer:longPressRecognizer]; |
| 64 } | 71 } |
| 65 | 72 |
| 66 #pragma mark - UICollectionViewDelegate | 73 #pragma mark - UICollectionViewDelegate |
| 67 | 74 |
| 68 - (void)collectionView:(UICollectionView*)collectionView | 75 - (void)collectionView:(UICollectionView*)collectionView |
| 69 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 76 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 70 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 77 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 71 | 78 |
| 72 CollectionViewItem* item = | 79 CollectionViewItem* item = |
| 73 [self.collectionViewModel itemAtIndexPath:indexPath]; | 80 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 }]; | 180 }]; |
| 174 } | 181 } |
| 175 } | 182 } |
| 176 | 183 |
| 177 - (void)openArticle:(CollectionViewItem*)item { | 184 - (void)openArticle:(CollectionViewItem*)item { |
| 178 ContentSuggestionsArticleItem* article = | 185 ContentSuggestionsArticleItem* article = |
| 179 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); | 186 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); |
| 180 [self.suggestionCommandHandler openURL:article.articleURL]; | 187 [self.suggestionCommandHandler openURL:article.articleURL]; |
| 181 } | 188 } |
| 182 | 189 |
| 190 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { |
| 191 if (self.editor.editing || |
| 192 gestureRecognizer.state != UIGestureRecognizerStateBegan) { |
| 193 return; |
| 194 } |
| 195 |
| 196 CGPoint touchLocation = |
| 197 [gestureRecognizer locationOfTouch:0 inView:self.collectionView]; |
| 198 NSIndexPath* touchedItemIndexPath = |
| 199 [self.collectionView indexPathForItemAtPoint:touchLocation]; |
| 200 if (!touchedItemIndexPath || |
| 201 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { |
| 202 // Make sure there is an item at this position. |
| 203 return; |
| 204 } |
| 205 CollectionViewItem* touchedItem = |
| 206 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; |
| 207 |
| 208 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != |
| 209 ContentSuggestionTypeArticle) { |
| 210 // Only trigger context menu on articles. |
| 211 return; |
| 212 } |
| 213 |
| 214 ContentSuggestionsArticleItem* articleItem = |
| 215 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); |
| 216 |
| 217 [self.suggestionCommandHandler displayContextMenuForArticle:articleItem |
| 218 atPoint:touchLocation]; |
| 219 } |
| 220 |
| 183 @end | 221 @end |
| OLD | NEW |