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

Side by Side Diff: ios/chrome/browser/ui/content_suggestions/content_suggestions_view_controller.mm

Issue 2887433002: Move the ContentSuggestions items to a new target (Closed)
Patch Set: Created 3 years, 7 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 unified diff | Download patch
OLDNEW
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"
8 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 7 #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" 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
10 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 9 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
11 #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_ite m.h"
12 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h" 10 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collectio n_updater.h"
13 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h" 11 #import "ios/chrome/browser/ui/content_suggestions/content_suggestions_commands. h"
14 #include "url/gurl.h"
15 12
16 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
17 #error "This file requires ARC support." 14 #error "This file requires ARC support."
18 #endif 15 #endif
19 16
20 namespace { 17 namespace {
21 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>; 18 using CSCollectionViewItem = CollectionViewItem<SuggestedContent>;
22 } 19 }
23 20
24 @interface ContentSuggestionsViewController () 21 @interface ContentSuggestionsViewController ()
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 125
129 - (void)collectionView:(UICollectionView*)collectionView 126 - (void)collectionView:(UICollectionView*)collectionView
130 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 127 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
131 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 128 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
132 129
133 CollectionViewItem* item = 130 CollectionViewItem* item =
134 [self.collectionViewModel itemAtIndexPath:indexPath]; 131 [self.collectionViewModel itemAtIndexPath:indexPath];
135 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) { 132 switch ([self.collectionUpdater contentSuggestionTypeForItem:item]) {
136 case ContentSuggestionTypeReadingList: 133 case ContentSuggestionTypeReadingList:
137 case ContentSuggestionTypeArticle: 134 case ContentSuggestionTypeArticle:
138 [self openSuggestion:item]; 135 [self.suggestionCommandHandler openPageForItem:item];
139 break; 136 break;
140 case ContentSuggestionTypeMostVisited: 137 case ContentSuggestionTypeMostVisited:
141 // TODO(crbug.com/707754): Open the most visited site. 138 // TODO(crbug.com/707754): Open the most visited site.
142 break; 139 break;
143 case ContentSuggestionTypeEmpty: 140 case ContentSuggestionTypeEmpty:
144 break; 141 break;
145 } 142 }
146 } 143 }
147 144
148 #pragma mark - MDCCollectionViewStylingDelegate 145 #pragma mark - MDCCollectionViewStylingDelegate
(...skipping 30 matching lines...) Expand all
179 insetForSectionAtIndex:indexPath.section]; 176 insetForSectionAtIndex:indexPath.section];
180 177
181 return [MDCCollectionViewCell 178 return [MDCCollectionViewCell
182 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) - 179 cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds) -
183 inset.left - inset.right 180 inset.left - inset.right
184 forItem:item]; 181 forItem:item];
185 } 182 }
186 183
187 #pragma mark - Private 184 #pragma mark - Private
188 185
189 // Opens the article associated with |item|. |item| must be a
190 // ContentSuggestionsItem.
191 - (void)openSuggestion:(CollectionViewItem*)item {
192 ContentSuggestionsItem* suggestion =
193 base::mac::ObjCCastStrict<ContentSuggestionsItem>(item);
194 [self.suggestionCommandHandler openURL:suggestion.URL];
195 }
196
197 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer { 186 - (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer {
198 if (self.editor.editing || 187 if (self.editor.editing ||
199 gestureRecognizer.state != UIGestureRecognizerStateBegan) { 188 gestureRecognizer.state != UIGestureRecognizerStateBegan) {
200 return; 189 return;
201 } 190 }
202 191
203 CGPoint touchLocation = 192 CGPoint touchLocation =
204 [gestureRecognizer locationOfTouch:0 inView:self.collectionView]; 193 [gestureRecognizer locationOfTouch:0 inView:self.collectionView];
205 NSIndexPath* touchedItemIndexPath = 194 NSIndexPath* touchedItemIndexPath =
206 [self.collectionView indexPathForItemAtPoint:touchLocation]; 195 [self.collectionView indexPathForItemAtPoint:touchLocation];
207 if (!touchedItemIndexPath || 196 if (!touchedItemIndexPath ||
208 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) { 197 ![self.collectionViewModel hasItemAtIndexPath:touchedItemIndexPath]) {
209 // Make sure there is an item at this position. 198 // Make sure there is an item at this position.
210 return; 199 return;
211 } 200 }
212 CollectionViewItem* touchedItem = 201 CollectionViewItem* touchedItem =
213 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath]; 202 [self.collectionViewModel itemAtIndexPath:touchedItemIndexPath];
214 203
215 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] != 204 if ([self.collectionUpdater contentSuggestionTypeForItem:touchedItem] !=
216 ContentSuggestionTypeArticle) { 205 ContentSuggestionTypeArticle) {
217 // Only trigger context menu on articles. 206 // Only trigger context menu on articles.
218 return; 207 return;
219 } 208 }
220 209
221 ContentSuggestionsItem* suggestionItem =
222 base::mac::ObjCCastStrict<ContentSuggestionsItem>(touchedItem);
223
224 [self.suggestionCommandHandler 210 [self.suggestionCommandHandler
225 displayContextMenuForArticle:suggestionItem 211 displayContextMenuForArticle:touchedItem
226 atPoint:touchLocation 212 atPoint:touchLocation
227 atIndexPath:touchedItemIndexPath]; 213 atIndexPath:touchedItemIndexPath];
228 } 214 }
229 215
230 // Checks if the |section| is empty and add an empty element if it is the case. 216 // Checks if the |section| is empty and add an empty element if it is the case.
231 // Must be called from inside a performBatchUpdates: block. 217 // Must be called from inside a performBatchUpdates: block.
232 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section { 218 - (void)addEmptySectionPlaceholderIfNeeded:(NSInteger)section {
233 if ([self.collectionViewModel numberOfItemsInSection:section] > 0) 219 if ([self.collectionViewModel numberOfItemsInSection:section] > 0)
234 return; 220 return;
235 221
236 NSIndexPath* emptyItem = 222 NSIndexPath* emptyItem =
237 [self.collectionUpdater addEmptyItemForSection:section]; 223 [self.collectionUpdater addEmptyItemForSection:section];
238 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]]; 224 [self.collectionView insertItemsAtIndexPaths:@[ emptyItem ]];
239 } 225 }
240 226
241 @end 227 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/content_suggestions/content_suggestions_data_sink.h ('k') | ios/chrome/browser/ui/settings/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698