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

Side by Side Diff: ios/chrome/browser/ui/browser_view_controller.mm

Issue 2660143002: Removing iPad Tab Switcher experimental flag. (Closed)
Patch Set: Rebased. Created 3 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/browser_view_controller.h" 5 #import "ios/chrome/browser/ui/browser_view_controller.h"
6 6
7 #import <AssetsLibrary/AssetsLibrary.h> 7 #import <AssetsLibrary/AssetsLibrary.h>
8 #import <MobileCoreServices/MobileCoreServices.h> 8 #import <MobileCoreServices/MobileCoreServices.h>
9 #import <PassKit/PassKit.h> 9 #import <PassKit/PassKit.h>
10 #import <Photos/Photos.h> 10 #import <Photos/Photos.h>
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 #import "ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.h" 111 #import "ios/chrome/browser/ui/dialogs/java_script_dialog_presenter_impl.h"
112 #import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h" 112 #import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h"
113 #import "ios/chrome/browser/ui/external_file_controller.h" 113 #import "ios/chrome/browser/ui/external_file_controller.h"
114 #import "ios/chrome/browser/ui/external_file_remover.h" 114 #import "ios/chrome/browser/ui/external_file_remover.h"
115 #include "ios/chrome/browser/ui/file_locations.h" 115 #include "ios/chrome/browser/ui/file_locations.h"
116 #import "ios/chrome/browser/ui/find_bar/find_bar_controller_ios.h" 116 #import "ios/chrome/browser/ui/find_bar/find_bar_controller_ios.h"
117 #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" 117 #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h"
118 #import "ios/chrome/browser/ui/fullscreen_controller.h" 118 #import "ios/chrome/browser/ui/fullscreen_controller.h"
119 #import "ios/chrome/browser/ui/history/tab_history_cell.h" 119 #import "ios/chrome/browser/ui/history/tab_history_cell.h"
120 #import "ios/chrome/browser/ui/key_commands_provider.h" 120 #import "ios/chrome/browser/ui/key_commands_provider.h"
121 #import "ios/chrome/browser/ui/no_tabs/no_tabs_controller.h"
122 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h" 121 #import "ios/chrome/browser/ui/ntp/new_tab_page_controller.h"
123 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_view_controller .h" 122 #import "ios/chrome/browser/ui/ntp/recent_tabs/recent_tabs_panel_view_controller .h"
124 #include "ios/chrome/browser/ui/omnibox/page_info_model.h" 123 #include "ios/chrome/browser/ui/omnibox/page_info_model.h"
125 #import "ios/chrome/browser/ui/omnibox/page_info_view_controller.h" 124 #import "ios/chrome/browser/ui/omnibox/page_info_view_controller.h"
126 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller. h" 125 #import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller. h"
127 #import "ios/chrome/browser/ui/page_not_available_controller.h" 126 #import "ios/chrome/browser/ui/page_not_available_controller.h"
128 #import "ios/chrome/browser/ui/preload_controller.h" 127 #import "ios/chrome/browser/ui/preload_controller.h"
129 #import "ios/chrome/browser/ui/preload_controller_delegate.h" 128 #import "ios/chrome/browser/ui/preload_controller_delegate.h"
130 #import "ios/chrome/browser/ui/print/print_controller.h" 129 #import "ios/chrome/browser/ui/print/print_controller.h"
131 #import "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h" 130 #import "ios/chrome/browser/ui/qr_scanner/qr_scanner_view_controller.h"
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } else { 234 } else {
236 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.Image", action, 235 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.Image", action,
237 NUM_ACTIONS); 236 NUM_ACTIONS);
238 } 237 }
239 } else { 238 } else {
240 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.Link", action, 239 UMA_HISTOGRAM_ENUMERATION("ContextMenu.SelectedOption.Link", action,
241 NUM_ACTIONS); 240 NUM_ACTIONS);
242 } 241 }
243 } 242 }
244 243
245 // Duration to show or hide the No-Tabs UI.
246 const NSTimeInterval kNoTabsAnimationDuration = 0.25;
247
248 const CGFloat kVoiceSearchBarHeight = 59.0; 244 const CGFloat kVoiceSearchBarHeight = 59.0;
249 245
250 // Dimensions to use when downsizing an image for search-by-image. 246 // Dimensions to use when downsizing an image for search-by-image.
251 const CGFloat kSearchByImageMaxImageArea = 90000.0; 247 const CGFloat kSearchByImageMaxImageArea = 90000.0;
252 const CGFloat kSearchByImageMaxImageWidth = 600.0; 248 const CGFloat kSearchByImageMaxImageWidth = 600.0;
253 const CGFloat kSearchByImageMaxImageHeight = 400.0; 249 const CGFloat kSearchByImageMaxImageHeight = 400.0;
254 250
255 // The delay, in seconds, after startup before cleaning up the files received 251 // The delay, in seconds, after startup before cleaning up the files received
256 // from other applications that are not bookmarked nor referenced by an open or 252 // from other applications that are not bookmarked nor referenced by an open or
257 // recently closed tab. 253 // recently closed tab.
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Used to display the QR Scanner UI. Nil if not visible. 385 // Used to display the QR Scanner UI. Nil if not visible.
390 base::scoped_nsobject<QRScannerViewController> _qrScannerViewController; 386 base::scoped_nsobject<QRScannerViewController> _qrScannerViewController;
391 387
392 // Used to display the Suggestions. 388 // Used to display the Suggestions.
393 base::scoped_nsobject<ContentSuggestionsCoordinator> 389 base::scoped_nsobject<ContentSuggestionsCoordinator>
394 _contentSuggestionsCoordinator; 390 _contentSuggestionsCoordinator;
395 391
396 // Used to display the Find In Page UI. Nil if not visible. 392 // Used to display the Find In Page UI. Nil if not visible.
397 base::scoped_nsobject<FindBarControllerIOS> _findBarController; 393 base::scoped_nsobject<FindBarControllerIOS> _findBarController;
398 394
399 // Used to display the No-Tabs UI for iPads. Nil if not visible.
400 base::scoped_nsobject<NoTabsController> _noTabsController;
401
402 // Used to display the Print UI. Nil if not visible. 395 // Used to display the Print UI. Nil if not visible.
403 base::scoped_nsobject<PrintController> _printController; 396 base::scoped_nsobject<PrintController> _printController;
404 397
405 // Records the set of domains for which full screen alert has already been 398 // Records the set of domains for which full screen alert has already been
406 // shown. 399 // shown.
407 base::scoped_nsobject<NSMutableSet> _fullScreenAlertShown; 400 base::scoped_nsobject<NSMutableSet> _fullScreenAlertShown;
408 401
409 // Adapter to let BVC be the delegate for WebState. 402 // Adapter to let BVC be the delegate for WebState.
410 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate; 403 std::unique_ptr<web::WebStateDelegateBridge> _webStateDelegate;
411 404
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // Voice search bar at the bottom of the view overlayed on |_contentArea| 439 // Voice search bar at the bottom of the view overlayed on |_contentArea|
447 // when displaying voice search results. 440 // when displaying voice search results.
448 base::scoped_nsprotocol<UIView<VoiceSearchBar>*> _voiceSearchBar; 441 base::scoped_nsprotocol<UIView<VoiceSearchBar>*> _voiceSearchBar;
449 442
450 // The image fetcher used to save images and perform image-based searches. 443 // The image fetcher used to save images and perform image-based searches.
451 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; 444 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher;
452 445
453 // Card side swipe view. 446 // Card side swipe view.
454 base::scoped_nsobject<CardSideSwipeView> _sideSwipeView; 447 base::scoped_nsobject<CardSideSwipeView> _sideSwipeView;
455 448
456 // Used to cache value of |hasModeToggleSwitch| if set before the tab strip
457 // controller has been created.
458 BOOL _modeToggleNeedsSetting;
459
460 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor. 449 // Dominant color cache. Key: (NSString*)url, val: (UIColor*)dominantColor.
461 base::scoped_nsobject<NSMutableDictionary> _dominantColorCache; 450 base::scoped_nsobject<NSMutableDictionary> _dominantColorCache;
462 451
463 // Bridge to register for bookmark changes. 452 // Bridge to register for bookmark changes.
464 std::unique_ptr<BrowserBookmarkModelBridge> _bookmarkModelBridge; 453 std::unique_ptr<BrowserBookmarkModelBridge> _bookmarkModelBridge;
465 454
466 // Cached pointer to the bookmarks model. 455 // Cached pointer to the bookmarks model.
467 bookmarks::BookmarkModel* _bookmarkModel; // weak 456 bookmarks::BookmarkModel* _bookmarkModel; // weak
468 457
469 // The controller that shows the bookmarking UI after the user taps the star 458 // The controller that shows the bookmarking UI after the user taps the star
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 // Sets the correct frame and heirarchy for subviews and helper views. 571 // Sets the correct frame and heirarchy for subviews and helper views.
583 - (void)setUpViewLayout; 572 - (void)setUpViewLayout;
584 // Sets the correct frame for the tab strip based on the given maximum width. 573 // Sets the correct frame for the tab strip based on the given maximum width.
585 - (void)layoutTabStripForWidth:(CGFloat)maxWidth; 574 - (void)layoutTabStripForWidth:(CGFloat)maxWidth;
586 // Makes |tab| the currently visible tab, displaying its view. Calls 575 // Makes |tab| the currently visible tab, displaying its view. Calls
587 // -selectedTabChanged on the toolbar only if |newSelection| is YES. 576 // -selectedTabChanged on the toolbar only if |newSelection| is YES.
588 - (void)displayTab:(Tab*)tab isNewSelection:(BOOL)newSelection; 577 - (void)displayTab:(Tab*)tab isNewSelection:(BOOL)newSelection;
589 // Initializes the bookmark interaction controller if not already initialized. 578 // Initializes the bookmark interaction controller if not already initialized.
590 - (void)initializeBookmarkInteractionController; 579 - (void)initializeBookmarkInteractionController;
591 580
592 // Shows the No-Tabs UI with animation.
593 - (void)showNoTabsUI;
594 // Dismisses the No-Tabs UI with animation.
595 - (void)dismissNoTabsUI;
596
597 // Shows the tools menu popup. 581 // Shows the tools menu popup.
598 - (void)showToolsMenuPopup; 582 - (void)showToolsMenuPopup;
599 // Add all delegates to the provided |tab|. 583 // Add all delegates to the provided |tab|.
600 - (void)installDelegatesForTab:(Tab*)tab; 584 - (void)installDelegatesForTab:(Tab*)tab;
601 // Closes the current tab, with animation if applicable. 585 // Closes the current tab, with animation if applicable.
602 - (void)closeCurrentTab; 586 - (void)closeCurrentTab;
603 // Shows the menu to initiate sharing |data|. 587 // Shows the menu to initiate sharing |data|.
604 - (void)sharePageWithData:(ShareToData*)data; 588 - (void)sharePageWithData:(ShareToData*)data;
605 // Convenience method to share the current page. 589 // Convenience method to share the current page.
606 - (void)sharePage; 590 - (void)sharePage;
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 941
958 #pragma mark - Accessibility 942 #pragma mark - Accessibility
959 943
960 - (BOOL)accessibilityPerformEscape { 944 - (BOOL)accessibilityPerformEscape {
961 [self dismissPopups]; 945 [self dismissPopups];
962 return YES; 946 return YES;
963 } 947 }
964 948
965 #pragma mark - Properties 949 #pragma mark - Properties
966 950
967 // Implements |hasModeToggleSwitch| property as pass-throughs to tab strip
968 // controller and no-tabs controller. If set before the controller has been
969 // created, cache it.
970 - (void)setHasModeToggleSwitch:(BOOL)hasModeToggleSwitch {
971 if (!experimental_flags::IsTabSwitcherEnabled()) {
972 if (_tabStripController)
973 _tabStripController.get().hasModeToggleSwitch = hasModeToggleSwitch;
974 else
975 _modeToggleNeedsSetting = hasModeToggleSwitch;
976 }
977 [_noTabsController setHasModeToggleSwitch:hasModeToggleSwitch];
978 }
979
980 // Implements |hasModeToggleSwitch| property as pass-throughs to tab strip
981 // controller, unless it hasn't been created in which return the cached version.
982 - (BOOL)hasModeToggleSwitch {
983 if (_tabStripController)
984 return _tabStripController.get().hasModeToggleSwitch;
985 return _modeToggleNeedsSetting;
986 }
987
988 - (void)setActive:(BOOL)active { 951 - (void)setActive:(BOOL)active {
989 if (_active == active) { 952 if (_active == active) {
990 return; 953 return;
991 } 954 }
992 _active = active; 955 _active = active;
993 956
994 // If not active, display an activity indicator overlay over the view to 957 // If not active, display an activity indicator overlay over the view to
995 // prevent interaction with the web page. 958 // prevent interaction with the web page.
996 // TODO(crbug.com/637093): This coordinator should be managed by the 959 // TODO(crbug.com/637093): This coordinator should be managed by the
997 // coordinator used to present BrowserViewController, when implemented. 960 // coordinator used to present BrowserViewController, when implemented.
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 1118
1156 - (void)shieldWasTapped:(id)sender { 1119 - (void)shieldWasTapped:(id)sender {
1157 [_toolbarController cancelOmniboxEdit]; 1120 [_toolbarController cancelOmniboxEdit];
1158 } 1121 }
1159 1122
1160 - (void)newTab:(id)sender { 1123 - (void)newTab:(id)sender {
1161 [self setLastTapPoint:sender]; 1124 [self setLastTapPoint:sender];
1162 DCHECK(self.visible || self.dismissingModal); 1125 DCHECK(self.visible || self.dismissingModal);
1163 Tab* currentTab = [_model currentTab]; 1126 Tab* currentTab = [_model currentTab];
1164 if (currentTab) { 1127 if (currentTab) {
1165 BOOL isChromeScheme = 1128 [currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES];
1166 web::GetWebClient()->IsAppSpecificURL([currentTab url]);
1167 BOOL snapshotOnIpad =
1168 (!IsIPadIdiom() || experimental_flags::IsTabSwitcherEnabled());
1169 if (snapshotOnIpad || !isChromeScheme) {
1170 [currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES];
1171 }
1172 } 1129 }
1173 [self addSelectedTabWithURL:GURL(kChromeUINewTabURL) 1130 [self addSelectedTabWithURL:GURL(kChromeUINewTabURL)
1174 transition:ui::PAGE_TRANSITION_TYPED]; 1131 transition:ui::PAGE_TRANSITION_TYPED];
1175 } 1132 }
1176 1133
1177 #pragma mark - UIViewController methods 1134 #pragma mark - UIViewController methods
1178 1135
1179 // Perform additional set up after loading the view, typically from a nib. 1136 // Perform additional set up after loading the view, typically from a nib.
1180 - (void)viewDidLoad { 1137 - (void)viewDidLoad {
1181 CGRect initialViewsRect = self.view.frame; 1138 CGRect initialViewsRect = self.view.frame;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 - (void)viewWillAppear:(BOOL)animated { 1184 - (void)viewWillAppear:(BOOL)animated {
1228 [super viewWillAppear:animated]; 1185 [super viewWillAppear:animated];
1229 1186
1230 // Reparent the toolbar if it's been relinquished. 1187 // Reparent the toolbar if it's been relinquished.
1231 if (_isToolbarControllerRelinquished) 1188 if (_isToolbarControllerRelinquished)
1232 [self reparentToolbarController]; 1189 [self reparentToolbarController];
1233 1190
1234 self.visible = YES; 1191 self.visible = YES;
1235 1192
1236 // Restore hidden infobars. 1193 // Restore hidden infobars.
1237 if (IsIPadIdiom() && experimental_flags::IsTabSwitcherEnabled()) { 1194 if (IsIPadIdiom()) {
1238 _infoBarContainer->RestoreInfobars(); 1195 _infoBarContainer->RestoreInfobars();
1239 } 1196 }
1240 1197
1241 // If the controller is suspended, or has been paged out due to low memory, 1198 // If the controller is suspended, or has been paged out due to low memory,
1242 // updating the view will be handled when it's displayed again. 1199 // updating the view will be handled when it's displayed again.
1243 if (![_model webUsageEnabled] || !self.contentArea) 1200 if (![_model webUsageEnabled] || !self.contentArea)
1244 return; 1201 return;
1245 // Update the displayed tab (if any; the switcher may not have created one 1202 // Update the displayed tab (if any; the switcher may not have created one
1246 // yet) in case it changed while showing the switcher. 1203 // yet) in case it changed while showing the switcher.
1247 Tab* currentTab = [_model currentTab]; 1204 Tab* currentTab = [_model currentTab];
1248 if (currentTab) 1205 if (currentTab)
1249 [self displayTab:currentTab isNewSelection:YES]; 1206 [self displayTab:currentTab isNewSelection:YES];
1250 } 1207 }
1251 1208
1252 - (void)viewWillDisappear:(BOOL)animated { 1209 - (void)viewWillDisappear:(BOOL)animated {
1253 self.viewVisible = NO; 1210 self.viewVisible = NO;
1254 [self updateDialogPresenterActiveState]; 1211 [self updateDialogPresenterActiveState];
1255 [[_model currentTab] updateFullscreenWithToolbarVisible:YES]; 1212 [[_model currentTab] updateFullscreenWithToolbarVisible:YES];
1256 [[_model currentTab] wasHidden]; 1213 [[_model currentTab] wasHidden];
1257 [_bookmarkInteractionController dismissSnackbar]; 1214 [_bookmarkInteractionController dismissSnackbar];
1258 if (IsIPadIdiom() && experimental_flags::IsTabSwitcherEnabled()) { 1215 if (IsIPadIdiom()) {
1259 _infoBarContainer->SuspendInfobars(); 1216 _infoBarContainer->SuspendInfobars();
1260 } 1217 }
1261 [super viewWillDisappear:animated]; 1218 [super viewWillDisappear:animated];
1262 } 1219 }
1263 1220
1264 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orient 1221 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)orient
1265 duration:(NSTimeInterval)duration { 1222 duration:(NSTimeInterval)duration {
1266 [super willRotateToInterfaceOrientation:orient duration:duration]; 1223 [super willRotateToInterfaceOrientation:orient duration:duration];
1267 [self dismissPopups]; 1224 [self dismissPopups];
1268 [self reshowFindBarIfNeededWithCoordinator:nil]; 1225 [self reshowFindBarIfNeededWithCoordinator:nil];
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 // as the BrowserViewController. 1261 // as the BrowserViewController.
1305 self.contentArea = nil; 1262 self.contentArea = nil;
1306 self.typingShield = nil; 1263 self.typingShield = nil;
1307 if (_voiceSearchController.get()) 1264 if (_voiceSearchController.get())
1308 _voiceSearchController->SetDelegate(nil); 1265 _voiceSearchController->SetDelegate(nil);
1309 _qrScannerViewController.reset(); 1266 _qrScannerViewController.reset();
1310 _toolbarController.reset(); 1267 _toolbarController.reset();
1311 _toolbarModelDelegate.reset(); 1268 _toolbarModelDelegate.reset();
1312 _toolbarModelIOS.reset(); 1269 _toolbarModelIOS.reset();
1313 _tabStripController.reset(); 1270 _tabStripController.reset();
1314 _noTabsController.reset();
1315 _sideSwipeController.reset(); 1271 _sideSwipeController.reset();
1316 } 1272 }
1317 } 1273 }
1318 1274
1319 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { 1275 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
1320 [super traitCollectionDidChange:previousTraitCollection]; 1276 [super traitCollectionDidChange:previousTraitCollection];
1321 // TODO(crbug.com/527092): - traitCollectionDidChange: is not always forwarded 1277 // TODO(crbug.com/527092): - traitCollectionDidChange: is not always forwarded
1322 // because in some cases the presented view controller isn't a child of the 1278 // because in some cases the presented view controller isn't a child of the
1323 // BVC in the view controller hierarchy (some intervening object isn't a 1279 // BVC in the view controller hierarchy (some intervening object isn't a
1324 // view controller). 1280 // view controller).
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
1738 _toolbarController.reset([_dependencyFactory 1694 _toolbarController.reset([_dependencyFactory
1739 newWebToolbarControllerWithDelegate:self 1695 newWebToolbarControllerWithDelegate:self
1740 urlLoader:self 1696 urlLoader:self
1741 preloadProvider:_preloadController.get()]); 1697 preloadProvider:_preloadController.get()]);
1742 [_toolbarController setTabCount:[_model count]]; 1698 [_toolbarController setTabCount:[_model count]];
1743 if (_voiceSearchController.get()) 1699 if (_voiceSearchController.get())
1744 _voiceSearchController->SetDelegate(_toolbarController); 1700 _voiceSearchController->SetDelegate(_toolbarController);
1745 1701
1746 // If needed, create the tabstrip. 1702 // If needed, create the tabstrip.
1747 if (IsIPadIdiom()) { 1703 if (IsIPadIdiom()) {
1748 // Determine if it's incognito. Whether or not the toggle button is
1749 // visible is consolidated in logic elsewhere so it doesn't need to be set
1750 // here.
1751 _tabStripController.reset( 1704 _tabStripController.reset(
1752 [_dependencyFactory newTabStripControllerWithTabModel:_model]); 1705 [_dependencyFactory newTabStripControllerWithTabModel:_model]);
1753 _tabStripController.get().fullscreenDelegate = self; 1706 _tabStripController.get().fullscreenDelegate = self;
1754 [_tabStripController setHasTabSwitcherToggleSwitch: 1707 [_tabStripController setHasTabSwitcherToggleSwitch:YES];
1755 experimental_flags::IsTabSwitcherEnabled()];
1756
1757 // If set before the views are loaded, pass the mode toggle to the
1758 // toolbar controller (only needed if YES, defaults to NO).
1759 if (_modeToggleNeedsSetting) {
1760 _tabStripController.get().hasModeToggleSwitch = _modeToggleNeedsSetting;
1761 }
1762 } 1708 }
1763 1709
1764 // Create infobar container. 1710 // Create infobar container.
1765 if (!_infoBarContainerDelegate) { 1711 if (!_infoBarContainerDelegate) {
1766 _infoBarContainerDelegate.reset(new InfoBarContainerDelegateIOS(self)); 1712 _infoBarContainerDelegate.reset(new InfoBarContainerDelegateIOS(self));
1767 _infoBarContainer.reset( 1713 _infoBarContainer.reset(
1768 new InfoBarContainerIOS(_infoBarContainerDelegate.get())); 1714 new InfoBarContainerIOS(_infoBarContainerDelegate.get()));
1769 } 1715 }
1770 } 1716 }
1771 1717
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1955 } 1901 }
1956 [[_toolbarController view] setHidden:hideToolbar]; 1902 [[_toolbarController view] setHidden:hideToolbar];
1957 } 1903 }
1958 } 1904 }
1959 1905
1960 - (void)updateDialogPresenterActiveState { 1906 - (void)updateDialogPresenterActiveState {
1961 self.dialogPresenter.active = self.active && self.viewVisible; 1907 self.dialogPresenter.active = self.active && self.viewVisible;
1962 } 1908 }
1963 1909
1964 - (void)dismissPopups { 1910 - (void)dismissPopups {
1965 if (_noTabsController.get()) 1911 [_toolbarController dismissToolsMenuPopup];
1966 [_noTabsController dismissToolsMenuPopup];
1967 else
1968 [_toolbarController dismissToolsMenuPopup];
1969 [self hidePageInfoPopupForView:nil]; 1912 [self hidePageInfoPopupForView:nil];
1970 [_toolbarController dismissTabHistoryPopup]; 1913 [_toolbarController dismissTabHistoryPopup];
1971 [[_model currentTab].webController recordStateInHistory]; 1914 [[_model currentTab].webController recordStateInHistory];
1972 } 1915 }
1973 1916
1974 #pragma mark - Tap handling 1917 #pragma mark - Tap handling
1975 1918
1976 - (void)setLastTapPoint:(id)sender { 1919 - (void)setLastTapPoint:(id)sender {
1977 CGPoint center; 1920 CGPoint center;
1978 UIView* parentView = nil; 1921 UIView* parentView = nil;
(...skipping 1274 matching lines...) Expand 10 before | Expand all | Expand 10 after
3253 // the error on the main thread. 3196 // the error on the main thread.
3254 [self displayPrivacyErrorAlertOnMainQueue:errorMessage]; 3197 [self displayPrivacyErrorAlertOnMainQueue:errorMessage];
3255 } else { 3198 } else {
3256 // TODO(noyau): Ideally I'd like to show an infobar with a link to switch to 3199 // TODO(noyau): Ideally I'd like to show an infobar with a link to switch to
3257 // the photo application. The current behaviour is to create the photo there 3200 // the photo application. The current behaviour is to create the photo there
3258 // but not providing any link to it is suboptimal. That's what Safari is 3201 // but not providing any link to it is suboptimal. That's what Safari is
3259 // doing, and what the PM want, but it doesn't make it right. 3202 // doing, and what the PM want, but it doesn't make it right.
3260 } 3203 }
3261 } 3204 }
3262 3205
3263 #pragma mark - No-tabs UI methods
3264
3265 // Show the No-Tabs UI (hiding normal tab/web ui).
3266 - (void)showNoTabsUI {
3267 // The No-Tabs UI is only shown on tablet for non-incognito BVCs. (Incognito
3268 // mode does not have a No-Tabs UI; the user is simply shown the non-incognito
3269 // BVC when the last incognito tab is closed.)
3270 DCHECK(IsIPadIdiom());
3271 DCHECK(!_isOffTheRecord);
3272
3273 // The method showNoTabsUI is called asynchronously when the number of tabs
3274 // reaches zero. Do not show the no tabs UI if a tab was added in the mean
3275 // time.
3276 if ([_model count])
3277 return;
3278
3279 DCHECK([_model currentTab] == nil);
3280 DCHECK([_contentArea subviews].count == 0 ||
3281 experimental_flags::IsTabSwitcherEnabled());
3282 _noTabsController.reset([[NoTabsController alloc] initWithView:self.view]);
3283
3284 // Close the tools popup menu if it is open, as its contents/location were
3285 // specific to being in the tabs UI.
3286 [_toolbarController dismissToolsMenuPopup];
3287
3288 // Immediately hide the web, toolbar, and tabstrip.
3289 [[_toolbarController view] setHidden:YES];
3290 [[_tabStripController view] setHidden:YES];
3291
3292 // Set up the toggle switch animation, if needed.
3293 if ([self hasModeToggleSwitch]) {
3294 UIButton* animationStartButton = [_tabStripController modeToggleButton];
3295 [_noTabsController installAnimationImageForButton:animationStartButton
3296 inView:self.view
3297 show:YES];
3298 }
3299
3300 [_noTabsController prepareForShowAnimation];
3301 [UIView animateWithDuration:kNoTabsAnimationDuration
3302 animations:^{
3303 [_noTabsController showNoTabsUI];
3304 }
3305 completion:^(BOOL finished) {
3306 [_noTabsController showAnimationDidFinish];
3307 [_noTabsController setHasModeToggleSwitch:[self hasModeToggleSwitch]];
3308 }];
3309 }
3310
3311 // Hide the No-Tabs UI (restoring normal tab/web ui).
3312 - (void)dismissNoTabsUI {
3313 // The No-Tabs UI is only shown on tablet for non-incognito BVCs, so there is
3314 // no need to dismiss it for an incognito BVC.
3315 DCHECK(IsIPadIdiom());
3316 if (_isOffTheRecord)
3317 return;
3318
3319 // Set up the toggle switch animation, if needed.
3320 if ([self hasModeToggleSwitch]) {
3321 UIButton* animationEndButton = [_tabStripController modeToggleButton];
3322 [_noTabsController installAnimationImageForButton:animationEndButton
3323 inView:self.view
3324 show:NO];
3325 }
3326
3327 [_noTabsController prepareForDismissAnimation];
3328
3329 // Pull the controller out of the scoped_nsobject so the animation blocks can
3330 // retain it.
3331 NoTabsController* noTabsController = _noTabsController.get();
3332 [UIView animateWithDuration:kNoTabsAnimationDuration
3333 animations:^{
3334 [noTabsController dismissNoTabsUI];
3335 }
3336 completion:^(BOOL finished) {
3337 // When the animation is finished, remove all of the No-Tabs UI and
3338 // reshow the tabstrip, web toolbar, and web.
3339 [noTabsController dismissAnimationDidFinish];
3340 [[_toolbarController view] setHidden:NO];
3341 [[_tabStripController view] setHidden:NO];
3342 }];
3343 // Nullify the instance variable. The controller is retained by the animation.
3344 // Nullifying this variable prevents button press performed during the
3345 // animation to be routed to the noTabController.
3346 _noTabsController.reset();
3347 }
3348
3349 #pragma mark - Showing popups 3206 #pragma mark - Showing popups
3350 3207
3351 - (void)showToolsMenuPopup { 3208 - (void)showToolsMenuPopup {
3352 DCHECK(_browserState); 3209 DCHECK(_browserState);
3353 DCHECK(self.visible || self.dismissingModal); 3210 DCHECK(self.visible || self.dismissingModal);
3354 DCHECK(!_noTabsController);
3355 3211
3356 // Dismiss the omnibox (if open). 3212 // Dismiss the omnibox (if open).
3357 [_toolbarController cancelOmniboxEdit]; 3213 [_toolbarController cancelOmniboxEdit];
3358 // Dismiss the soft keyboard (if open). 3214 // Dismiss the soft keyboard (if open).
3359 [[_model currentTab].webController dismissKeyboard]; 3215 [[_model currentTab].webController dismissKeyboard];
3360 // Dismiss Find in Page focus. 3216 // Dismiss Find in Page focus.
3361 [self updateFindBar:NO shouldFocus:NO]; 3217 [self updateFindBar:NO shouldFocus:NO];
3362 3218
3363 base::scoped_nsobject<ToolsMenuContext> context( 3219 base::scoped_nsobject<ToolsMenuContext> context(
3364 [[ToolsMenuContext alloc] initWithDisplayView:[self view]]); 3220 [[ToolsMenuContext alloc] initWithDisplayView:[self view]]);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
3446 [self webPageOrderedOpen:GURL(kPageInfoHelpCenterURL) 3302 [self webPageOrderedOpen:GURL(kPageInfoHelpCenterURL)
3447 referrer:web::Referrer() 3303 referrer:web::Referrer()
3448 windowName:nil 3304 windowName:nil
3449 inBackground:NO 3305 inBackground:NO
3450 appendTo:kCurrentTab]; 3306 appendTo:kCurrentTab];
3451 [self hidePageInfoPopupForView:nil]; 3307 [self hidePageInfoPopupForView:nil];
3452 } 3308 }
3453 3309
3454 - (void)showTabHistoryPopupForBackwardHistory { 3310 - (void)showTabHistoryPopupForBackwardHistory {
3455 DCHECK(self.visible || self.dismissingModal); 3311 DCHECK(self.visible || self.dismissingModal);
3456 DCHECK(!_noTabsController);
3457 3312
3458 // Dismiss the omnibox (if open). 3313 // Dismiss the omnibox (if open).
3459 [_toolbarController cancelOmniboxEdit]; 3314 [_toolbarController cancelOmniboxEdit];
3460 // Dismiss the soft keyboard (if open). 3315 // Dismiss the soft keyboard (if open).
3461 Tab* tab = [_model currentTab]; 3316 Tab* tab = [_model currentTab];
3462 [tab.webController dismissKeyboard]; 3317 [tab.webController dismissKeyboard];
3463 3318
3464 DCHECK([tab navigationManager]); 3319 DCHECK([tab navigationManager]);
3465 CRWSessionController* sc = [tab navigationManager]->GetSessionController(); 3320 CRWSessionController* sc = [tab navigationManager]->GetSessionController();
3466 [_toolbarController showTabHistoryPopupInView:[self view] 3321 [_toolbarController showTabHistoryPopupInView:[self view]
3467 withSessionEntries:[sc backwardEntries] 3322 withSessionEntries:[sc backwardEntries]
3468 forBackHistory:YES]; 3323 forBackHistory:YES];
3469 } 3324 }
3470 3325
3471 - (void)showTabHistoryPopupForForwardHistory { 3326 - (void)showTabHistoryPopupForForwardHistory {
3472 DCHECK(self.visible || self.dismissingModal); 3327 DCHECK(self.visible || self.dismissingModal);
3473 DCHECK(!_noTabsController);
3474 3328
3475 // Dismiss the omnibox (if open). 3329 // Dismiss the omnibox (if open).
3476 [_toolbarController cancelOmniboxEdit]; 3330 [_toolbarController cancelOmniboxEdit];
3477 // Dismiss the soft keyboard (if open). 3331 // Dismiss the soft keyboard (if open).
3478 Tab* tab = [_model currentTab]; 3332 Tab* tab = [_model currentTab];
3479 [tab.webController dismissKeyboard]; 3333 [tab.webController dismissKeyboard];
3480 3334
3481 DCHECK([tab navigationManager]); 3335 DCHECK([tab navigationManager]);
3482 CRWSessionController* sc = [tab navigationManager]->GetSessionController(); 3336 CRWSessionController* sc = [tab navigationManager]->GetSessionController();
3483 [_toolbarController showTabHistoryPopupInView:[self view] 3337 [_toolbarController showTabHistoryPopupInView:[self view]
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 case IDC_SHOW_MAIL_COMPOSER: 3874 case IDC_SHOW_MAIL_COMPOSER:
4021 [self showMailComposer:sender]; 3875 [self showMailComposer:sender];
4022 break; 3876 break;
4023 case IDC_READER_MODE: 3877 case IDC_READER_MODE:
4024 [[_model currentTab] switchToReaderMode]; 3878 [[_model currentTab] switchToReaderMode];
4025 break; 3879 break;
4026 case IDC_REQUEST_DESKTOP_SITE: 3880 case IDC_REQUEST_DESKTOP_SITE:
4027 [self enableDesktopUserAgent]; 3881 [self enableDesktopUserAgent];
4028 break; 3882 break;
4029 case IDC_SHOW_TOOLS_MENU: { 3883 case IDC_SHOW_TOOLS_MENU: {
4030 // TODO(blundell): Change this if/else to 3884 [self showToolsMenuPopup];
4031 // |DCHECK(!_noTabsController)| if/when the no tabs controller
4032 // becomes part of the responder chain.
4033 // The no tabs controller's toolbar should open the menu when in the
4034 // no-tabs UI.
4035 if (_noTabsController.get())
4036 [_noTabsController showToolsMenuPopup];
4037 else
4038 [self showToolsMenuPopup];
4039 break; 3885 break;
4040 } 3886 }
4041 case IDC_SHOW_BOOKMARK_MANAGER: { 3887 case IDC_SHOW_BOOKMARK_MANAGER: {
4042 if (IsIPadIdiom()) { 3888 if (IsIPadIdiom()) {
4043 [self showAllBookmarks]; 3889 [self showAllBookmarks];
4044 } else { 3890 } else {
4045 [self initializeBookmarkInteractionController]; 3891 [self initializeBookmarkInteractionController];
4046 [_bookmarkInteractionController presentBookmarks]; 3892 [_bookmarkInteractionController presentBookmarks];
4047 } 3893 }
4048 break; 3894 break;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
4129 break; 3975 break;
4130 } 3976 }
4131 } 3977 }
4132 3978
4133 - (void)closeCurrentTab { 3979 - (void)closeCurrentTab {
4134 Tab* currentTab = [_model currentTab]; 3980 Tab* currentTab = [_model currentTab];
4135 NSUInteger tabIndex = [_model indexOfTab:currentTab]; 3981 NSUInteger tabIndex = [_model indexOfTab:currentTab];
4136 if (tabIndex == NSNotFound) 3982 if (tabIndex == NSNotFound)
4137 return; 3983 return;
4138 3984
4139 // Take snapshot on iPad only if Tab switcher is enabled, if not just close 3985 // TODO(crbug.com/688003): Evaluate if a screenshot of the tab is needed on
4140 // the tab. 3986 // iPad.
4141 if (IsIPadIdiom() && !experimental_flags::IsTabSwitcherEnabled()) {
4142 [_model closeTabAtIndex:tabIndex];
4143 return;
4144 }
4145
4146 // Create image of tab for close animation.
4147 UIImageView* exitingPage = [self pageOpenCloseAnimationView]; 3987 UIImageView* exitingPage = [self pageOpenCloseAnimationView];
4148 exitingPage.image = 3988 exitingPage.image =
4149 [currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES]; 3989 [currentTab updateSnapshotWithOverlay:YES visibleFrameOnly:YES];
4150 3990
4151 // Close the actual tab, and add its image as a subview. 3991 // Close the actual tab, and add its image as a subview.
4152 [_model closeTabAtIndex:tabIndex]; 3992 [_model closeTabAtIndex:tabIndex];
4153 3993
4154 // Do not animate close in iPad. 3994 // Do not animate close in iPad.
4155 if (!IsIPadIdiom()) { 3995 if (!IsIPadIdiom()) {
4156 [_contentArea addSubview:exitingPage]; 3996 [_contentArea addSubview:exitingPage];
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
4194 [[_model currentTab].findInPageController 4034 [[_model currentTab].findInPageController
4195 disableFindInPageWithCompletionHandler:^{ 4035 disableFindInPageWithCompletionHandler:^{
4196 [self updateFindBar:NO shouldFocus:NO]; 4036 [self updateFindBar:NO shouldFocus:NO];
4197 }]; 4037 }];
4198 [_contextualSearchController movePanelOffscreen]; 4038 [_contextualSearchController movePanelOffscreen];
4199 4039
4200 [_paymentRequestManager cancelRequest]; 4040 [_paymentRequestManager cancelRequest];
4201 4041
4202 [_printController dismissAnimated:YES]; 4042 [_printController dismissAnimated:YES];
4203 _printController.reset(); 4043 _printController.reset();
4204 if (_noTabsController.get()) 4044 [_toolbarController dismissToolsMenuPopup];
4205 [_noTabsController dismissToolsMenuPopup];
4206 else
4207 [_toolbarController dismissToolsMenuPopup];
4208 [_contextMenuCoordinator stop]; 4045 [_contextMenuCoordinator stop];
4209 [self dismissRateThisAppDialog]; 4046 [self dismissRateThisAppDialog];
4210 4047
4211 [_contentSuggestionsCoordinator stop]; 4048 [_contentSuggestionsCoordinator stop];
4212 4049
4213 if (self.presentedViewController) { 4050 if (self.presentedViewController) {
4214 // Dismisses any other modal controllers that may be present, e.g. Recent 4051 // Dismisses any other modal controllers that may be present, e.g. Recent
4215 // Tabs. 4052 // Tabs.
4216 // Note that currently, some controllers like the bookmark ones were already 4053 // Note that currently, some controllers like the bookmark ones were already
4217 // dismissed (in this example in -dismissBookmarkModalControllerAnimated:), 4054 // dismissed (in this example in -dismissBookmarkModalControllerAnimated:),
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
4599 [[UpgradeCenter sharedInstance] tabWillClose:tab.tabId]; 4436 [[UpgradeCenter sharedInstance] tabWillClose:tab.tabId];
4600 if ([model count] == 1) { // About to remove the last tab. 4437 if ([model count] == 1) { // About to remove the last tab.
4601 [_contextualSearchController setTab:nil]; 4438 [_contextualSearchController setTab:nil];
4602 [_paymentRequestManager setWebState:nil]; 4439 [_paymentRequestManager setWebState:nil];
4603 } 4440 }
4604 } 4441 }
4605 4442
4606 // Called when the number of tabs changes. Update the toolbar accordingly. 4443 // Called when the number of tabs changes. Update the toolbar accordingly.
4607 - (void)tabModelDidChangeTabCount:(TabModel*)model { 4444 - (void)tabModelDidChangeTabCount:(TabModel*)model {
4608 DCHECK(model == _model); 4445 DCHECK(model == _model);
4609 if ([_model count] == 1 && _noTabsController.get()) {
4610 [self dismissNoTabsUI];
4611 }
4612
4613 [_toolbarController setTabCount:[_model count]]; 4446 [_toolbarController setTabCount:[_model count]];
4614 // If the iPad tab switcher feature is enabled, the tab switcher is shown
4615 // instead of the no tabs UI. Showing the tab switcher in that case is
4616 // done from the main controller.
4617 // If the iPad tab switcher feature is disabled and the number of tabs is
4618 // zero, ensure the no-tabs UI is visible (such as if the last tab was closed
4619 // programmatically from JS). This is done on a delay because the
4620 // notification happens while the tab is going away and trying to trigger a
4621 // change during teardown causes problems.
4622 BOOL showNoTabsUIOnIPad =
4623 IsIPadIdiom() && !experimental_flags::IsTabSwitcherEnabled();
4624 if (![_model count] && showNoTabsUIOnIPad && !_isOffTheRecord) {
4625 [self performSelector:@selector(showNoTabsUI)
4626 withObject:nil
4627 afterDelay:0.01];
4628 }
4629 } 4447 }
4630 4448
4631 #pragma mark - Upgrade Detection 4449 #pragma mark - Upgrade Detection
4632 4450
4633 - (void)showUpgrade:(UpgradeCenter*)center { 4451 - (void)showUpgrade:(UpgradeCenter*)center {
4634 // Add an infobar on all the open tabs. 4452 // Add an infobar on all the open tabs.
4635 for (Tab* tab in _model.get()) { 4453 for (Tab* tab in _model.get()) {
4636 NSString* tabId = tab.tabId; 4454 NSString* tabId = tab.tabId;
4637 DCHECK([tab infoBarManager]); 4455 DCHECK([tab infoBarManager]);
4638 [center addInfoBarToManager:[tab infoBarManager] forTabId:tabId]; 4456 [center addInfoBarToManager:[tab infoBarManager] forTabId:tabId];
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
5144 4962
5145 - (UIView*)voiceSearchButton { 4963 - (UIView*)voiceSearchButton {
5146 return _voiceSearchButton; 4964 return _voiceSearchButton;
5147 } 4965 }
5148 4966
5149 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { 4967 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
5150 return [self currentLogoAnimationControllerOwner]; 4968 return [self currentLogoAnimationControllerOwner];
5151 } 4969 }
5152 4970
5153 @end 4971 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/browser_view_controller.h ('k') | ios/chrome/browser/ui/main/browser_view_wrangler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698