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: Fix gn deps 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
« no previous file with comments | « ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..e6ff832e00151bf4043fd1df1708f16c2eda9634 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,35 @@ 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 ([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
« no previous file with comments | « ios/chrome/browser/ui/content_suggestions/content_suggestions_commands.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698