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

Side by Side Diff: ios/chrome/browser/ui/ntp/google_landing_controller.mm

Issue 2829003002: Add CommandDispatcher to BrowserViewController. (Closed)
Patch Set: rohit comments 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 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_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"
16 #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h" 16 #import "ios/chrome/browser/ui/context_menu/context_menu_coordinator.h"
17 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" 17 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h"
18 #import "ios/chrome/browser/ui/ntp/most_visited_cell.h" 18 #import "ios/chrome/browser/ui/ntp/most_visited_cell.h"
19 #import "ios/chrome/browser/ui/ntp/most_visited_layout.h" 19 #import "ios/chrome/browser/ui/ntp/most_visited_layout.h"
20 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h" 20 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_constants.h"
21 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_view.h" 21 #import "ios/chrome/browser/ui/ntp/new_tab_page_header_view.h"
22 #import "ios/chrome/browser/ui/ntp/whats_new_header_view.h" 22 #import "ios/chrome/browser/ui/ntp/whats_new_header_view.h"
23 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller. h" 23 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller. h"
24 #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
24 #include "ios/chrome/browser/ui/ui_util.h" 25 #include "ios/chrome/browser/ui/ui_util.h"
25 #import "ios/chrome/browser/ui/uikit_ui_util.h" 26 #import "ios/chrome/browser/ui/uikit_ui_util.h"
27 #import "ios/chrome/browser/ui/url_loader.h"
26 #include "ios/chrome/common/string_util.h" 28 #include "ios/chrome/common/string_util.h"
27 #include "ios/chrome/grit/ios_strings.h" 29 #include "ios/chrome/grit/ios_strings.h"
28 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h" 30 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h"
29 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 31 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
30 #import "ios/web/public/web_state/context_menu_params.h" 32 #import "ios/web/public/web_state/context_menu_params.h"
31 #import "net/base/mac/url_conversions.h" 33 #import "net/base/mac/url_conversions.h"
32 #include "ui/base/l10n/l10n_util.h" 34 #include "ui/base/l10n/l10n_util.h"
35 #include "ui/base/page_transition_types.h"
33 36
34 using base::UserMetricsAction; 37 using base::UserMetricsAction;
35 38
36 namespace { 39 namespace {
37 40
38 enum { 41 enum {
39 SectionWithOmnibox, 42 SectionWithOmnibox,
40 SectionWithMostVisited, 43 SectionWithMostVisited,
41 NumberOfCollectionViewSections, 44 NumberOfCollectionViewSections,
42 }; 45 };
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 260
258 @end 261 @end
259 262
260 @implementation GoogleLandingController 263 @implementation GoogleLandingController
261 264
262 @dynamic view; 265 @dynamic view;
263 @synthesize logoVendor = _logoVendor; 266 @synthesize logoVendor = _logoVendor;
264 @synthesize dataSource = _dataSource; 267 @synthesize dataSource = _dataSource;
265 // Property declared in NewTabPagePanelProtocol. 268 // Property declared in NewTabPagePanelProtocol.
266 @synthesize delegate = _delegate; 269 @synthesize delegate = _delegate;
270 @synthesize dispatcher = _dispatcher;
267 @synthesize isOffTheRecord = _isOffTheRecord; 271 @synthesize isOffTheRecord = _isOffTheRecord;
268 @synthesize logoIsShowing = _logoIsShowing; 272 @synthesize logoIsShowing = _logoIsShowing;
269 @synthesize promoText = _promoText; 273 @synthesize promoText = _promoText;
270 @synthesize promoIcon = _promoIcon; 274 @synthesize promoIcon = _promoIcon;
271 @synthesize promoCanShow = _promoCanShow; 275 @synthesize promoCanShow = _promoCanShow;
272 @synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown; 276 @synthesize maximumMostVisitedSitesShown = _maximumMostVisitedSitesShown;
273 @synthesize tabCount = _tabCount; 277 @synthesize tabCount = _tabCount;
274 @synthesize canGoForward = _canGoForward; 278 @synthesize canGoForward = _canGoForward;
275 @synthesize canGoBack = _canGoBack; 279 @synthesize canGoBack = _canGoBack;
276 @synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled; 280 @synthesize voiceSearchIsEnabled = _voiceSearchIsEnabled;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 [[_mostVisitedView collectionViewLayout] invalidateLayout]; 789 [[_mostVisitedView collectionViewLayout] invalidateLayout];
786 } 790 }
787 } 791 }
788 completion:^(BOOL finished) { 792 completion:^(BOOL finished) {
789 // Check to see if we are still scrolled to the top -- it's possible 793 // Check to see if we are still scrolled to the top -- it's possible
790 // (and difficult) to resign the first responder and initiate a 794 // (and difficult) to resign the first responder and initiate a
791 // -shiftTilesDown before the animation here completes. 795 // -shiftTilesDown before the animation here completes.
792 if (_scrolledToTop) { 796 if (_scrolledToTop) {
793 _animateHeader = NO; 797 _animateHeader = NO;
794 if (!IsIPadIdiom()) { 798 if (!IsIPadIdiom()) {
795 [self.dataSource onFakeboxAnimationComplete]; 799 [self.dispatcher onFakeboxAnimationComplete];
796 [_headerView fadeOutShadow]; 800 [_headerView fadeOutShadow];
797 [_searchTapTarget setHidden:YES]; 801 [_searchTapTarget setHidden:YES];
798 } 802 }
799 } 803 }
800 }]; 804 }];
801 } 805 }
802 806
803 - (void)searchFieldTapped:(id)sender { 807 - (void)searchFieldTapped:(id)sender {
804 [self.dataSource focusFakebox]; 808 [self.dispatcher focusFakebox];
805 } 809 }
806 810
807 - (void)blurOmnibox { 811 - (void)blurOmnibox {
808 if (_omniboxFocused) { 812 if (_omniboxFocused) {
809 [self.dataSource cancelOmniboxEdit]; 813 [self.dispatcher cancelOmniboxEdit];
810 } else { 814 } else {
811 [self locationBarResignsFirstResponder]; 815 [self locationBarResignsFirstResponder];
812 } 816 }
813 } 817 }
814 818
815 - (void)locationBarResignsFirstResponder { 819 - (void)locationBarResignsFirstResponder {
816 if (!_isShowing && !_scrolledToTop) 820 if (!_isShowing && !_scrolledToTop)
817 return; 821 return;
818 822
819 _omniboxFocused = NO; 823 _omniboxFocused = NO;
820 if ([_contextMenuCoordinator isVisible]) { 824 if ([_contextMenuCoordinator isVisible]) {
821 return; 825 return;
822 } 826 }
823 827
824 [self shiftTilesDown]; 828 [self shiftTilesDown];
825 } 829 }
826 830
827 - (void)shiftTilesDown { 831 - (void)shiftTilesDown {
828 _animateHeader = YES; 832 _animateHeader = YES;
829 _scrolledToTop = NO; 833 _scrolledToTop = NO;
830 if (!IsIPadIdiom()) { 834 if (!IsIPadIdiom()) {
831 [_searchTapTarget setHidden:NO]; 835 [_searchTapTarget setHidden:NO];
832 [self.dataSource onFakeboxBlur]; 836 [self.dispatcher onFakeboxBlur];
833 } 837 }
834 838
835 // Reload most visited sites in case the number of placeholder cells needs to 839 // Reload most visited sites in case the number of placeholder cells needs to
836 // be updated after an orientation change. 840 // be updated after an orientation change.
837 [_mostVisitedView reloadData]; 841 [_mostVisitedView reloadData];
838 842
839 // Reshow views that are within range of the most visited collection view 843 // Reshow views that are within range of the most visited collection view
840 // (if necessary). 844 // (if necessary).
841 [self.view removeGestureRecognizer:_tapGestureRecognizer]; 845 [self.view removeGestureRecognizer:_tapGestureRecognizer];
842 [self.view removeGestureRecognizer:_swipeGestureRecognizer]; 846 [self.view removeGestureRecognizer:_swipeGestureRecognizer];
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 static_cast<int64_t>(1 * NSEC_PER_SEC)), 975 static_cast<int64_t>(1 * NSEC_PER_SEC)),
972 dispatch_get_main_queue(), ^{ 976 dispatch_get_main_queue(), ^{
973 [blockView release]; 977 [blockView release];
974 }); 978 });
975 } 979 }
976 980
977 const NSUInteger visitedIndex = indexPath.row; 981 const NSUInteger visitedIndex = indexPath.row;
978 [self blurOmnibox]; 982 [self blurOmnibox];
979 DCHECK(visitedIndex < [self numberOfItems]); 983 DCHECK(visitedIndex < [self numberOfItems]);
980 [self.dataSource logMostVisitedClick:visitedIndex tileType:cell.tileType]; 984 [self.dataSource logMostVisitedClick:visitedIndex tileType:cell.tileType];
981 [self.dataSource loadURL:[self urlForIndex:visitedIndex] 985 [self.dispatcher loadURL:[self urlForIndex:visitedIndex]
982 referrer:web::Referrer() 986 referrer:web::Referrer()
983 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK 987 transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK
984 rendererInitiated:NO]; 988 rendererInitiated:NO];
985 } 989 }
986 990
987 #pragma mark - UICollectionViewDataSource 991 #pragma mark - UICollectionViewDataSource
988 992
989 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView 993 - (UICollectionReusableView*)collectionView:(UICollectionView*)collectionView
990 viewForSupplementaryElementOfKind:(NSString*)kind 994 viewForSupplementaryElementOfKind:(NSString*)kind
991 atIndexPath:(NSIndexPath*)indexPath { 995 atIndexPath:(NSIndexPath*)indexPath {
992 DCHECK(kind == UICollectionElementKindSectionHeader); 996 DCHECK(kind == UICollectionElementKindSectionHeader);
993 997
994 if (!_supplementaryViews) 998 if (!_supplementaryViews)
995 _supplementaryViews.reset([[NSMutableArray alloc] init]); 999 _supplementaryViews.reset([[NSMutableArray alloc] init]);
996 1000
997 if (indexPath.section == SectionWithOmnibox) { 1001 if (indexPath.section == SectionWithOmnibox) {
998 if (!_headerView) { 1002 if (!_headerView) {
999 _headerView.reset([[collectionView 1003 _headerView.reset([[collectionView
1000 dequeueReusableSupplementaryViewOfKind: 1004 dequeueReusableSupplementaryViewOfKind:
1001 UICollectionElementKindSectionHeader 1005 UICollectionElementKindSectionHeader
1002 withReuseIdentifier:@"header" 1006 withReuseIdentifier:@"header"
1003 forIndexPath:indexPath] retain]); 1007 forIndexPath:indexPath] retain]);
1004 [_headerView addSubview:[self.logoVendor view]]; 1008 [_headerView addSubview:[self.logoVendor view]];
1005 [_headerView addSubview:_searchTapTarget]; 1009 [_headerView addSubview:_searchTapTarget];
1006 [_headerView addViewsToSearchField:_searchTapTarget]; 1010 [_headerView addViewsToSearchField:_searchTapTarget];
1007 1011
1008 if (!IsIPadIdiom()) { 1012 if (!IsIPadIdiom()) {
1009 // iPhone header also contains a toolbar since the normal toolbar is 1013 // iPhone header also contains a toolbar since the normal toolbar is
1010 // hidden. 1014 // hidden.
1011 [_headerView addToolbarWithDataSource:self.dataSource]; 1015 [_headerView addToolbarWithDataSource:self.dataSource
1016 dispatcher:self.dispatcher];
1012 [_headerView setToolbarTabCount:self.tabCount]; 1017 [_headerView setToolbarTabCount:self.tabCount];
1013 [_headerView setCanGoForward:self.canGoForward]; 1018 [_headerView setCanGoForward:self.canGoForward];
1014 [_headerView setCanGoBack:self.canGoBack]; 1019 [_headerView setCanGoBack:self.canGoBack];
1015 } 1020 }
1016 [_supplementaryViews addObject:_headerView]; 1021 [_supplementaryViews addObject:_headerView];
1017 } 1022 }
1018 return _headerView; 1023 return _headerView;
1019 } 1024 }
1020 1025
1021 if (indexPath.section == SectionWithMostVisited) { 1026 if (indexPath.section == SectionWithMostVisited) {
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 GURL url = [self urlForIndex:index]; 1139 GURL url = [self urlForIndex:index];
1135 base::WeakNSObject<GoogleLandingController> weakSelf(self); 1140 base::WeakNSObject<GoogleLandingController> weakSelf(self);
1136 action = ^{ 1141 action = ^{
1137 base::scoped_nsobject<GoogleLandingController> strongSelf( 1142 base::scoped_nsobject<GoogleLandingController> strongSelf(
1138 [weakSelf retain]); 1143 [weakSelf retain]);
1139 if (!strongSelf) 1144 if (!strongSelf)
1140 return; 1145 return;
1141 MostVisitedCell* cell = (MostVisitedCell*)sender.view; 1146 MostVisitedCell* cell = (MostVisitedCell*)sender.view;
1142 [[strongSelf dataSource] logMostVisitedClick:index 1147 [[strongSelf dataSource] logMostVisitedClick:index
1143 tileType:cell.tileType]; 1148 tileType:cell.tileType];
1144 [[strongSelf dataSource] webPageOrderedOpen:url 1149 [[strongSelf dispatcher] webPageOrderedOpen:url
1145 referrer:web::Referrer() 1150 referrer:web::Referrer()
1146 inBackground:YES 1151 inBackground:YES
1147 appendTo:kCurrentTab]; 1152 appendTo:kCurrentTab];
1148 }; 1153 };
1149 [_contextMenuCoordinator 1154 [_contextMenuCoordinator
1150 addItemWithTitle:l10n_util::GetNSStringWithFixup( 1155 addItemWithTitle:l10n_util::GetNSStringWithFixup(
1151 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) 1156 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)
1152 action:action]; 1157 action:action];
1153 1158
1154 if (!self.isOffTheRecord) { 1159 if (!self.isOffTheRecord) {
1155 // Open in Incognito Tab. 1160 // Open in Incognito Tab.
1156 action = ^{ 1161 action = ^{
1157 base::scoped_nsobject<GoogleLandingController> strongSelf( 1162 base::scoped_nsobject<GoogleLandingController> strongSelf(
1158 [weakSelf retain]); 1163 [weakSelf retain]);
1159 if (!strongSelf) 1164 if (!strongSelf)
1160 return; 1165 return;
1161 MostVisitedCell* cell = (MostVisitedCell*)sender.view; 1166 MostVisitedCell* cell = (MostVisitedCell*)sender.view;
1162 [[strongSelf dataSource] logMostVisitedClick:index 1167 [[strongSelf dataSource] logMostVisitedClick:index
1163 tileType:cell.tileType]; 1168 tileType:cell.tileType];
1164 [[strongSelf dataSource] webPageOrderedOpen:url 1169 [[strongSelf dispatcher] webPageOrderedOpen:url
1165 referrer:web::Referrer() 1170 referrer:web::Referrer()
1166 inIncognito:YES 1171 inIncognito:YES
1167 inBackground:NO 1172 inBackground:NO
1168 appendTo:kCurrentTab]; 1173 appendTo:kCurrentTab];
1169 }; 1174 };
1170 [_contextMenuCoordinator 1175 [_contextMenuCoordinator
1171 addItemWithTitle:l10n_util::GetNSStringWithFixup( 1176 addItemWithTitle:l10n_util::GetNSStringWithFixup(
1172 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) 1177 IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB)
1173 action:action]; 1178 action:action];
1174 } 1179 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1215 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess); 1220 TriggerHapticFeedbackForNotification(UINotificationFeedbackTypeSuccess);
1216 MDCSnackbarMessage* message = [MDCSnackbarMessage 1221 MDCSnackbarMessage* message = [MDCSnackbarMessage
1217 messageWithText:l10n_util::GetNSString( 1222 messageWithText:l10n_util::GetNSString(
1218 IDS_IOS_NEW_TAB_MOST_VISITED_ITEM_REMOVED)]; 1223 IDS_IOS_NEW_TAB_MOST_VISITED_ITEM_REMOVED)];
1219 message.action = action; 1224 message.action = action;
1220 message.category = @"MostVisitedUndo"; 1225 message.category = @"MostVisitedUndo";
1221 [MDCSnackbarManager showMessage:message]; 1226 [MDCSnackbarManager showMessage:message];
1222 } 1227 }
1223 1228
1224 - (void)onPromoLabelTapped { 1229 - (void)onPromoLabelTapped {
1225 [self.dataSource cancelOmniboxEdit]; 1230 [self.dispatcher cancelOmniboxEdit];
1226 [_promoHeaderView setHidden:YES]; 1231 [_promoHeaderView setHidden:YES];
1227 [self.view setNeedsLayout]; 1232 [self.view setNeedsLayout];
1228 [self.dataSource promoTapped]; 1233 [self.dataSource promoTapped];
1229 } 1234 }
1230 1235
1231 // Returns the Y value to use for the scroll view's contentOffset when scrolling 1236 // Returns the Y value to use for the scroll view's contentOffset when scrolling
1232 // the omnibox to the top of the screen. 1237 // the omnibox to the top of the screen.
1233 - (CGFloat)pinnedOffsetY { 1238 - (CGFloat)pinnedOffsetY {
1234 CGFloat headerHeight = [_headerView frame].size.height; 1239 CGFloat headerHeight = [_headerView frame].size.height;
1235 CGFloat offsetY = 1240 CGFloat offsetY =
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 #pragma mark - UIScrollViewDelegate Methods. 1317 #pragma mark - UIScrollViewDelegate Methods.
1313 1318
1314 - (void)scrollViewDidScroll:(UIScrollView*)scrollView { 1319 - (void)scrollViewDidScroll:(UIScrollView*)scrollView {
1315 [self.delegate updateNtpBarShadowForPanelController:self]; 1320 [self.delegate updateNtpBarShadowForPanelController:self];
1316 [_overscrollActionsController scrollViewDidScroll:scrollView]; 1321 [_overscrollActionsController scrollViewDidScroll:scrollView];
1317 1322
1318 // Blur the omnibox when the scroll view is scrolled below the pinned offset. 1323 // Blur the omnibox when the scroll view is scrolled below the pinned offset.
1319 CGFloat pinnedOffsetY = [self pinnedOffsetY]; 1324 CGFloat pinnedOffsetY = [self pinnedOffsetY];
1320 if (_omniboxFocused && scrollView.dragging && 1325 if (_omniboxFocused && scrollView.dragging &&
1321 scrollView.contentOffset.y < pinnedOffsetY) { 1326 scrollView.contentOffset.y < pinnedOffsetY) {
1322 [self.dataSource cancelOmniboxEdit]; 1327 [self.dispatcher cancelOmniboxEdit];
1323 } 1328 }
1324 1329
1325 if (IsIPadIdiom()) { 1330 if (IsIPadIdiom()) {
1326 return; 1331 return;
1327 } 1332 }
1328 1333
1329 if (_animateHeader) { 1334 if (_animateHeader) {
1330 [self updateSearchField]; 1335 [self updateSearchField];
1331 } 1336 }
1332 } 1337 }
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1509 - (void)setCanGoForward:(BOOL)canGoForward { 1514 - (void)setCanGoForward:(BOOL)canGoForward {
1510 _canGoForward = canGoForward; 1515 _canGoForward = canGoForward;
1511 [_headerView setCanGoForward:self.canGoForward]; 1516 [_headerView setCanGoForward:self.canGoForward];
1512 } 1517 }
1513 1518
1514 - (void)setCanGoBack:(BOOL)canGoBack { 1519 - (void)setCanGoBack:(BOOL)canGoBack {
1515 _canGoBack = canGoBack; 1520 _canGoBack = canGoBack;
1516 [_headerView setCanGoBack:self.canGoBack]; 1521 [_headerView setCanGoBack:self.canGoBack];
1517 } 1522 }
1518 @end 1523 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/google_landing_controller.h ('k') | ios/chrome/browser/ui/ntp/google_landing_controller_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698