Chromium Code Reviews| 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 = | |
|
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
| |
| 206 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; | |
| 207 | |
| 208 if (touchedItem == [self.collectionViewModel | |
| 209 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.
| |
| 210 [self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != | |
| 211 ContentSuggestionTypeArticle) { | |
| 212 // Only trigger context menu on articles. | |
| 213 return; | |
| 214 } | |
| 215 | |
| 216 ContentSuggestionsArticleItem* articleItem = | |
| 217 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); | |
| 218 | |
| 219 [self.suggestionCommandHandler displayContextMenuForArticle:articleItem | |
| 220 atPoint:touchLocation]; | |
| 221 } | |
| 222 | |
| 183 @end | 223 @end |
| OLD | NEW |