Chromium Code Reviews| Index: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm |
| diff --git a/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm b/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm |
| index 276c6f47f47b9997930842b6cf693fdc4261cca2..0bc8e9dec4ec69295c0ada8fdaeb1afbb91e0d7f 100644 |
| --- a/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm |
| +++ b/ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm |
| @@ -61,6 +61,13 @@ const NSTimeInterval kAnimationDuration = 0.35; |
| self.collectionView.delegate = self; |
| self.styler.cellStyle = MDCCollectionViewCellStyleCard; |
| + |
| + UILongPressGestureRecognizer* longPressRecognizer = |
| + [[UILongPressGestureRecognizer alloc] |
| + initWithTarget:self |
| + action:@selector(handleLongPress:)]; |
| + longPressRecognizer.numberOfTouchesRequired = 1; |
| + [self.collectionView addGestureRecognizer:longPressRecognizer]; |
| } |
| #pragma mark - UICollectionViewDelegate |
| @@ -180,4 +187,37 @@ const NSTimeInterval kAnimationDuration = 0.35; |
| [self.suggestionCommandHandler openURL:article.articleURL]; |
| } |
| +- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { |
| + if (self.editor.editing || |
| + gestureRecognizer.state != UIGestureRecognizerStateBegan) { |
| + return; |
| + } |
| + |
| + CGPoint touchLocation = |
| + [gestureRecognizer locationOfTouch:0 inView:self.collectionView]; |
| + NSIndexPath* touchedItemIndexPath = |
| + [self.collectionView indexPathForItemAtPoint:touchLocation]; |
| + if (!touchedItemIndexPath || |
| + ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { |
| + // Make sure there is an item at this position. |
| + return; |
| + } |
| + CollectionViewItem* touchedItem = |
|
stkhapugin
2017/02/15 16:03:36
nit: keep all code handling the *touch* here, and
gambard
2017/02/16 10:17:13
The "..." will probably be handled at the cell lev
|
| + [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; |
| + |
| + if (touchedItem == [self.collectionViewModel |
| + headerForSection:touchedItemIndexPath.section] || |
|
stkhapugin
2017/02/15 16:03:36
I'm not familiar with this API, is it possible tha
gambard
2017/02/16 10:17:13
Done.
|
| + [self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != |
| + ContentSuggestionTypeArticle) { |
| + // Only trigger context menu on articles. |
| + return; |
| + } |
| + |
| + ContentSuggestionsArticleItem* articleItem = |
| + base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); |
| + |
| + [self.suggestionCommandHandler displayContextMenuForArticle:articleItem |
| + atPoint:touchLocation]; |
| +} |
| + |
| @end |