OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/ntp/google_landing_controller.h" | 5 #import "ios/chrome/browser/ui/ntp/google_landing_view_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
10 #include "base/metrics/user_metrics.h" | 10 #include "base/metrics/user_metrics.h" |
11 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
12 #include "components/strings/grit/components_strings.h" | 12 #include "components/strings/grit/components_strings.h" |
13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" | 14 #import "ios/chrome/browser/ui/commands/generic_chrome_command.h" |
15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 15 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 const CGFloat kDoodleTopMarginIPadLandscape = 82; | 65 const CGFloat kDoodleTopMarginIPadLandscape = 82; |
66 const NSInteger kMaxNumMostVisitedFaviconRows = 2; | 66 const NSInteger kMaxNumMostVisitedFaviconRows = 2; |
67 const CGFloat kMaxSearchFieldFrameMargin = 200; | 67 const CGFloat kMaxSearchFieldFrameMargin = 200; |
68 const CGFloat kShiftTilesDownAnimationDuration = 0.2; | 68 const CGFloat kShiftTilesDownAnimationDuration = 0.2; |
69 | 69 |
70 const CGFloat kMostVisitedPaddingIPhone = 16; | 70 const CGFloat kMostVisitedPaddingIPhone = 16; |
71 const CGFloat kMostVisitedPaddingIPadFavicon = 24; | 71 const CGFloat kMostVisitedPaddingIPadFavicon = 24; |
72 | 72 |
73 } // namespace | 73 } // namespace |
74 | 74 |
75 @interface GoogleLandingController (UsedByGoogleLandingView) | 75 @interface GoogleLandingViewController (UsedByGoogleLandingView) |
76 // Update frames for subviews depending on the interface orientation. | 76 // Update frames for subviews depending on the interface orientation. |
77 - (void)updateSubviewFrames; | 77 - (void)updateSubviewFrames; |
78 // Resets the collection view's inset to 0. | 78 // Resets the collection view's inset to 0. |
79 - (void)resetSectionInset; | 79 - (void)resetSectionInset; |
80 - (void)reloadData; | 80 - (void)reloadData; |
81 @end | 81 @end |
82 | 82 |
83 // Subclassing the main UIScrollView allows calls for setFrame. | 83 // Subclassing the main UIScrollView allows calls for setFrame. |
84 @interface GoogleLandingView : UIView { | 84 @interface GoogleLandingView : UIView { |
85 GoogleLandingController* _googleLanding; | 85 GoogleLandingViewController* _googleLanding; |
86 } | 86 } |
87 | 87 |
88 - (void)setFrameDelegate:(GoogleLandingController*)delegate; | 88 - (void)setFrameDelegate:(GoogleLandingViewController*)delegate; |
89 | 89 |
90 @end | 90 @end |
91 | 91 |
92 @implementation GoogleLandingView | 92 @implementation GoogleLandingView |
93 | 93 |
94 - (void)setFrameDelegate:(GoogleLandingController*)delegate { | 94 - (void)setFrameDelegate:(GoogleLandingViewController*)delegate { |
95 _googleLanding = delegate; | 95 _googleLanding = delegate; |
96 } | 96 } |
97 | 97 |
98 - (void)setFrame:(CGRect)frame { | 98 - (void)setFrame:(CGRect)frame { |
99 // On iPad and in fullscreen, the collection view's inset is very large. | 99 // On iPad and in fullscreen, the collection view's inset is very large. |
100 // When Chrome enters slide over mode, the previously set inset is larger than | 100 // When Chrome enters slide over mode, the previously set inset is larger than |
101 // the newly set collection view's width, which makes the collection view | 101 // the newly set collection view's width, which makes the collection view |
102 // throw an exception. | 102 // throw an exception. |
103 // To prevent this from happening, we reset the inset to 0 before changing the | 103 // To prevent this from happening, we reset the inset to 0 before changing the |
104 // frame. | 104 // frame. |
105 [_googleLanding resetSectionInset]; | 105 [_googleLanding resetSectionInset]; |
106 [super setFrame:frame]; | 106 [super setFrame:frame]; |
107 [_googleLanding updateSubviewFrames]; | 107 [_googleLanding updateSubviewFrames]; |
108 [_googleLanding reloadData]; | 108 [_googleLanding reloadData]; |
109 } | 109 } |
110 | 110 |
111 @end | 111 @end |
112 | 112 |
113 @interface GoogleLandingController ()<OverscrollActionsControllerDelegate, | 113 @interface GoogleLandingViewController ()<OverscrollActionsControllerDelegate, |
114 UICollectionViewDataSource, | 114 UICollectionViewDataSource, |
115 UICollectionViewDelegate, | 115 UICollectionViewDelegate, |
116 UICollectionViewDelegateFlowLayout, | 116 UICollectionViewDelegateFlowLayout, |
117 UIGestureRecognizerDelegate, | 117 UIGestureRecognizerDelegate, |
118 WhatsNewHeaderViewDelegate> { | 118 WhatsNewHeaderViewDelegate> { |
119 // Fake omnibox. | 119 // Fake omnibox. |
120 base::scoped_nsobject<UIButton> _searchTapTarget; | 120 base::scoped_nsobject<UIButton> _searchTapTarget; |
121 | 121 |
122 // A collection view for the most visited sites. | 122 // A collection view for the most visited sites. |
123 base::scoped_nsobject<UICollectionView> _mostVisitedView; | 123 base::scoped_nsobject<UICollectionView> _mostVisitedView; |
124 | 124 |
125 // The overscroll actions controller managing accelerators over the toolbar. | 125 // The overscroll actions controller managing accelerators over the toolbar. |
126 base::scoped_nsobject<OverscrollActionsController> | 126 base::scoped_nsobject<OverscrollActionsController> |
127 _overscrollActionsController; | 127 _overscrollActionsController; |
128 | 128 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 // Updates the collection view's scroll view offset for the next frame of the | 253 // Updates the collection view's scroll view offset for the next frame of the |
254 // shiftTilesDown animation. | 254 // shiftTilesDown animation. |
255 - (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link; | 255 - (void)shiftTilesDownAnimationDidFire:(CADisplayLink*)link; |
256 // Returns the size to use for Most Visited cells in the NTP. | 256 // Returns the size to use for Most Visited cells in the NTP. |
257 - (CGSize)mostVisitedCellSize; | 257 - (CGSize)mostVisitedCellSize; |
258 // Returns the padding for use between Most Visited cells. | 258 // Returns the padding for use between Most Visited cells. |
259 - (CGFloat)mostVisitedCellPadding; | 259 - (CGFloat)mostVisitedCellPadding; |
260 | 260 |
261 @end | 261 @end |
262 | 262 |
263 @implementation GoogleLandingController | 263 @implementation GoogleLandingViewController |
264 | 264 |
265 @dynamic view; | 265 @dynamic view; |
266 @synthesize logoVendor = _logoVendor; | 266 @synthesize logoVendor = _logoVendor; |
267 @synthesize dataSource = _dataSource; | 267 @synthesize dataSource = _dataSource; |
268 // Property declared in NewTabPagePanelProtocol. | 268 // Property declared in NewTabPagePanelProtocol. |
269 @synthesize delegate = _delegate; | 269 @synthesize delegate = _delegate; |
270 @synthesize dispatcher = _dispatcher; | 270 @synthesize dispatcher = _dispatcher; |
271 @synthesize isOffTheRecord = _isOffTheRecord; | 271 @synthesize isOffTheRecord = _isOffTheRecord; |
272 @synthesize logoIsShowing = _logoIsShowing; | 272 @synthesize logoIsShowing = _logoIsShowing; |
273 @synthesize promoText = _promoText; | 273 @synthesize promoText = _promoText; |
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1130 topController = topController.presentedViewController; | 1130 topController = topController.presentedViewController; |
1131 | 1131 |
1132 _contextMenuCoordinator.reset([[ContextMenuCoordinator alloc] | 1132 _contextMenuCoordinator.reset([[ContextMenuCoordinator alloc] |
1133 initWithBaseViewController:topController | 1133 initWithBaseViewController:topController |
1134 params:params]); | 1134 params:params]); |
1135 | 1135 |
1136 ProceduralBlock action; | 1136 ProceduralBlock action; |
1137 | 1137 |
1138 // Open In New Tab. | 1138 // Open In New Tab. |
1139 GURL url = [self urlForIndex:index]; | 1139 GURL url = [self urlForIndex:index]; |
1140 base::WeakNSObject<GoogleLandingController> weakSelf(self); | 1140 base::WeakNSObject<GoogleLandingViewController> weakSelf(self); |
1141 action = ^{ | 1141 action = ^{ |
1142 base::scoped_nsobject<GoogleLandingController> strongSelf( | 1142 base::scoped_nsobject<GoogleLandingViewController> strongSelf( |
1143 [weakSelf retain]); | 1143 [weakSelf retain]); |
1144 if (!strongSelf) | 1144 if (!strongSelf) |
1145 return; | 1145 return; |
1146 MostVisitedCell* cell = (MostVisitedCell*)sender.view; | 1146 MostVisitedCell* cell = (MostVisitedCell*)sender.view; |
1147 [[strongSelf dataSource] logMostVisitedClick:index | 1147 [[strongSelf dataSource] logMostVisitedClick:index |
1148 tileType:cell.tileType]; | 1148 tileType:cell.tileType]; |
1149 [[strongSelf dispatcher] webPageOrderedOpen:url | 1149 [[strongSelf dispatcher] webPageOrderedOpen:url |
1150 referrer:web::Referrer() | 1150 referrer:web::Referrer() |
1151 inBackground:YES | 1151 inBackground:YES |
1152 appendTo:kCurrentTab]; | 1152 appendTo:kCurrentTab]; |
1153 }; | 1153 }; |
1154 [_contextMenuCoordinator | 1154 [_contextMenuCoordinator |
1155 addItemWithTitle:l10n_util::GetNSStringWithFixup( | 1155 addItemWithTitle:l10n_util::GetNSStringWithFixup( |
1156 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) | 1156 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) |
1157 action:action]; | 1157 action:action]; |
1158 | 1158 |
1159 if (!self.isOffTheRecord) { | 1159 if (!self.isOffTheRecord) { |
1160 // Open in Incognito Tab. | 1160 // Open in Incognito Tab. |
1161 action = ^{ | 1161 action = ^{ |
1162 base::scoped_nsobject<GoogleLandingController> strongSelf( | 1162 base::scoped_nsobject<GoogleLandingViewController> strongSelf( |
1163 [weakSelf retain]); | 1163 [weakSelf retain]); |
1164 if (!strongSelf) | 1164 if (!strongSelf) |
1165 return; | 1165 return; |
1166 MostVisitedCell* cell = (MostVisitedCell*)sender.view; | 1166 MostVisitedCell* cell = (MostVisitedCell*)sender.view; |
1167 [[strongSelf dataSource] logMostVisitedClick:index | 1167 [[strongSelf dataSource] logMostVisitedClick:index |
1168 tileType:cell.tileType]; | 1168 tileType:cell.tileType]; |
1169 [[strongSelf dispatcher] webPageOrderedOpen:url | 1169 [[strongSelf dispatcher] webPageOrderedOpen:url |
1170 referrer:web::Referrer() | 1170 referrer:web::Referrer() |
1171 inIncognito:YES | 1171 inIncognito:YES |
1172 inBackground:NO | 1172 inBackground:NO |
1173 appendTo:kCurrentTab]; | 1173 appendTo:kCurrentTab]; |
1174 }; | 1174 }; |
1175 [_contextMenuCoordinator | 1175 [_contextMenuCoordinator |
1176 addItemWithTitle:l10n_util::GetNSStringWithFixup( | 1176 addItemWithTitle:l10n_util::GetNSStringWithFixup( |
1177 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) | 1177 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) |
1178 action:action]; | 1178 action:action]; |
1179 } | 1179 } |
1180 | 1180 |
1181 // Remove the most visited url. | 1181 // Remove the most visited url. |
1182 NSString* title = | 1182 NSString* title = |
1183 l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK); | 1183 l10n_util::GetNSStringWithFixup(IDS_BOOKMARK_BUBBLE_REMOVE_BOOKMARK); |
1184 action = ^{ | 1184 action = ^{ |
1185 base::scoped_nsobject<GoogleLandingController> strongSelf( | 1185 base::scoped_nsobject<GoogleLandingViewController> strongSelf( |
1186 [weakSelf retain]); | 1186 [weakSelf retain]); |
1187 // Early return if the controller has been deallocated. | 1187 // Early return if the controller has been deallocated. |
1188 if (!strongSelf) | 1188 if (!strongSelf) |
1189 return; | 1189 return; |
1190 base::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); | 1190 base::RecordAction(UserMetricsAction("MostVisited_UrlBlacklisted")); |
1191 [[strongSelf dataSource] addBlacklistedURL:url]; | 1191 [[strongSelf dataSource] addBlacklistedURL:url]; |
1192 [strongSelf showMostVisitedUndoForURL:net::NSURLWithGURL(url)]; | 1192 [strongSelf showMostVisitedUndoForURL:net::NSURLWithGURL(url)]; |
1193 }; | 1193 }; |
1194 [_contextMenuCoordinator addItemWithTitle:title action:action]; | 1194 [_contextMenuCoordinator addItemWithTitle:title action:action]; |
1195 | 1195 |
1196 [_contextMenuCoordinator start]; | 1196 [_contextMenuCoordinator start]; |
1197 | 1197 |
1198 if (IsIPadIdiom()) | 1198 if (IsIPadIdiom()) |
1199 [self blurOmnibox]; | 1199 [self blurOmnibox]; |
1200 } | 1200 } |
1201 } | 1201 } |
1202 | 1202 |
1203 - (void)showMostVisitedUndoForURL:(NSURL*)url { | 1203 - (void)showMostVisitedUndoForURL:(NSURL*)url { |
1204 _deletedUrl.reset([url retain]); | 1204 _deletedUrl.reset([url retain]); |
1205 | 1205 |
1206 MDCSnackbarMessageAction* action = | 1206 MDCSnackbarMessageAction* action = |
1207 [[[MDCSnackbarMessageAction alloc] init] autorelease]; | 1207 [[[MDCSnackbarMessageAction alloc] init] autorelease]; |
1208 base::WeakNSObject<GoogleLandingController> weakSelf(self); | 1208 base::WeakNSObject<GoogleLandingViewController> weakSelf(self); |
1209 action.handler = ^{ | 1209 action.handler = ^{ |
1210 base::scoped_nsobject<GoogleLandingController> strongSelf( | 1210 base::scoped_nsobject<GoogleLandingViewController> strongSelf( |
1211 [weakSelf retain]); | 1211 [weakSelf retain]); |
1212 if (!strongSelf) | 1212 if (!strongSelf) |
1213 return; | 1213 return; |
1214 [[strongSelf dataSource] | 1214 [[strongSelf dataSource] |
1215 removeBlacklistedURL:net::GURLWithNSURL(_deletedUrl)]; | 1215 removeBlacklistedURL:net::GURLWithNSURL(_deletedUrl)]; |
1216 }; | 1216 }; |
1217 action.title = l10n_util::GetNSString(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE); | 1217 action.title = l10n_util::GetNSString(IDS_NEW_TAB_UNDO_THUMBNAIL_REMOVE); |
1218 action.accessibilityIdentifier = @"Undo"; | 1218 action.accessibilityIdentifier = @"Undo"; |
1219 | 1219 |
1220 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); | 1220 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 - (NSInteger)numberOfNonEmptyTilesShown { | 1406 - (NSInteger)numberOfNonEmptyTilesShown { |
1407 NSInteger numCells = | 1407 NSInteger numCells = |
1408 MIN([self numberOfItems], self.maximumMostVisitedSitesShown); | 1408 MIN([self numberOfItems], self.maximumMostVisitedSitesShown); |
1409 return MAX(numCells, [self numberOfColumns]); | 1409 return MAX(numCells, [self numberOfColumns]); |
1410 } | 1410 } |
1411 | 1411 |
1412 - (GURL)urlForIndex:(NSUInteger)index { | 1412 - (GURL)urlForIndex:(NSUInteger)index { |
1413 return [self.dataSource mostVisitedAtIndex:index].url; | 1413 return [self.dataSource mostVisitedAtIndex:index].url; |
1414 } | 1414 } |
1415 | 1415 |
1416 #pragma mark - GoogleLandingController (ExposedForTesting) methods. | 1416 #pragma mark - GoogleLandingViewController (ExposedForTesting) methods. |
1417 | 1417 |
1418 - (BOOL)scrolledToTop { | 1418 - (BOOL)scrolledToTop { |
1419 return _scrolledToTop; | 1419 return _scrolledToTop; |
1420 } | 1420 } |
1421 | 1421 |
1422 - (BOOL)animateHeader { | 1422 - (BOOL)animateHeader { |
1423 return _animateHeader; | 1423 return _animateHeader; |
1424 } | 1424 } |
1425 | 1425 |
1426 #pragma mark - OverscrollActionsControllerDelegate | 1426 #pragma mark - OverscrollActionsControllerDelegate |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1514 - (void)setCanGoForward:(BOOL)canGoForward { | 1514 - (void)setCanGoForward:(BOOL)canGoForward { |
1515 _canGoForward = canGoForward; | 1515 _canGoForward = canGoForward; |
1516 [_headerView setCanGoForward:self.canGoForward]; | 1516 [_headerView setCanGoForward:self.canGoForward]; |
1517 } | 1517 } |
1518 | 1518 |
1519 - (void)setCanGoBack:(BOOL)canGoBack { | 1519 - (void)setCanGoBack:(BOOL)canGoBack { |
1520 _canGoBack = canGoBack; | 1520 _canGoBack = canGoBack; |
1521 [_headerView setCanGoBack:self.canGoBack]; | 1521 [_headerView setCanGoBack:self.canGoBack]; |
1522 } | 1522 } |
1523 @end | 1523 @end |
OLD | NEW |