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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 }]; | 185 }]; |
| 179 } | 186 } |
| 180 } | 187 } |
| 181 | 188 |
| 182 - (void)openArticle:(CollectionViewItem*)item { | 189 - (void)openArticle:(CollectionViewItem*)item { |
| 183 ContentSuggestionsArticleItem* article = | 190 ContentSuggestionsArticleItem* article = |
| 184 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); | 191 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(item); |
| 185 [self.suggestionCommandHandler openURL:article.articleURL]; | 192 [self.suggestionCommandHandler openURL:article.articleURL]; |
| 186 } | 193 } |
| 187 | 194 |
| 195 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { | |
| 196 if (self.editor.editing || | |
| 197 gestureRecognizer.state != UIGestureRecognizerStateBegan) { | |
| 198 return; | |
| 199 } | |
| 200 | |
| 201 CGPoint touchLocation = | |
| 202 [gestureRecognizer locationOfTouch:0 inView:self.collectionView]; | |
| 203 NSIndexPath* touchedItemIndexPath = | |
| 204 [self.collectionView indexPathForItemAtPoint:touchLocation]; | |
| 205 if (!touchedItemIndexPath || | |
| 206 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { | |
| 207 // Make sure there is an item at this position. | |
| 208 return; | |
| 209 } | |
| 210 CollectionViewItem* touchedItem = | |
| 211 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; | |
| 212 | |
| 213 if (touchedItem == [self.collectionViewModel | |
| 214 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
| |
| 215 touchedItem.type != ContentSuggestionsItemTypeArticle) { | |
| 216 // 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.
| |
| 217 return; | |
| 218 } | |
| 219 | |
| 220 ContentSuggestionsArticleItem* articleItem = | |
| 221 base::mac::ObjCCastStrict<ContentSuggestionsArticleItem>(touchedItem); | |
| 222 | |
| 223 [self.suggestionCommandHandler displayContextMenuForArticle:articleItem | |
| 224 atPoint:touchLocation]; | |
| 225 } | |
| 226 | |
| 188 @end | 227 @end |
| OLD | NEW |