Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Unified Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm

Issue 2691303002: Add context menu for ContentSuggestions (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 a7590b2fe43a62c57c4d73818ca5035825d390fa..66b50ba211b28c46b34e0d38b5237ae6e759a705 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
@@ -185,4 +192,36 @@ 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 =
+ [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath];
+
+ if (touchedItem == [self.collectionViewModel
+ headerForSection:touchedItemIndexPath.section] ||
lpromero 2017/02/14 16:18:17 If you are pressing the header, how come the colle
gambard 2017/02/15 10:37:56 It is returning nil actually. Should I let the tes
lpromero 2017/02/15 10:48:28 [self.collectionViewModel itemAtIndexPath:touchedI
+ touchedItem.type != ContentSuggestionsItemTypeArticle) {
+ // Do not trigger context menu on headers.
lpromero 2017/02/14 16:18:17 This comment does not seem to talk about the secon
gambard 2017/02/15 10:37:56 Done.
+ return;
+ }
+
+ ContentSuggestionsArticleItem* articleItem =
+ base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem);
+
+ [self.suggestionCommandHandler displayContextMenuForArticle:articleItem
+ atPoint:touchLocation];
+}
+
@end

Powered by Google App Engine
This is Rietveld 408576698