OLD | NEW |
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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 - (void)addUIFunctionalityForModelAndBrowserState; | 630 - (void)addUIFunctionalityForModelAndBrowserState; |
631 // Sets the correct frame and heirarchy for subviews and helper views. | 631 // Sets the correct frame and heirarchy for subviews and helper views. |
632 - (void)setUpViewLayout; | 632 - (void)setUpViewLayout; |
633 // Sets the correct frame for the tab strip based on the given maximum width. | 633 // Sets the correct frame for the tab strip based on the given maximum width. |
634 - (void)layoutTabStripForWidth:(CGFloat)maxWidth; | 634 - (void)layoutTabStripForWidth:(CGFloat)maxWidth; |
635 // Makes |tab| the currently visible tab, displaying its view. Calls | 635 // Makes |tab| the currently visible tab, displaying its view. Calls |
636 // -selectedTabChanged on the toolbar only if |newSelection| is YES. | 636 // -selectedTabChanged on the toolbar only if |newSelection| is YES. |
637 - (void)displayTab:(Tab*)tab isNewSelection:(BOOL)newSelection; | 637 - (void)displayTab:(Tab*)tab isNewSelection:(BOOL)newSelection; |
638 // Initializes the bookmark interaction controller if not already initialized. | 638 // Initializes the bookmark interaction controller if not already initialized. |
639 - (void)initializeBookmarkInteractionController; | 639 - (void)initializeBookmarkInteractionController; |
640 | |
641 // Shows the tools menu popup. | |
642 - (void)showToolsMenuPopup; | |
643 // Add all delegates to the provided |tab|. | 640 // Add all delegates to the provided |tab|. |
644 - (void)installDelegatesForTab:(Tab*)tab; | 641 - (void)installDelegatesForTab:(Tab*)tab; |
645 // Remove delegates from the provided |tab|. | 642 // Remove delegates from the provided |tab|. |
646 - (void)uninstallDelegatesForTab:(Tab*)tab; | 643 - (void)uninstallDelegatesForTab:(Tab*)tab; |
647 // Closes the current tab, with animation if applicable. | 644 // Closes the current tab, with animation if applicable. |
648 - (void)closeCurrentTab; | 645 - (void)closeCurrentTab; |
649 // Shows the menu to initiate sharing |data|. | 646 // Shows the menu to initiate sharing |data|. |
650 - (void)sharePageWithData:(ShareToData*)data; | 647 - (void)sharePageWithData:(ShareToData*)data; |
651 // Convenience method to share the current page. | 648 // Convenience method to share the current page. |
652 - (void)sharePage; | 649 - (void)sharePage; |
(...skipping 2777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3430 } else { | 3427 } else { |
3431 // TODO(noyau): Ideally I'd like to show an infobar with a link to switch to | 3428 // TODO(noyau): Ideally I'd like to show an infobar with a link to switch to |
3432 // the photo application. The current behaviour is to create the photo there | 3429 // the photo application. The current behaviour is to create the photo there |
3433 // but not providing any link to it is suboptimal. That's what Safari is | 3430 // but not providing any link to it is suboptimal. That's what Safari is |
3434 // doing, and what the PM want, but it doesn't make it right. | 3431 // doing, and what the PM want, but it doesn't make it right. |
3435 } | 3432 } |
3436 } | 3433 } |
3437 | 3434 |
3438 #pragma mark - Showing popups | 3435 #pragma mark - Showing popups |
3439 | 3436 |
3440 - (void)showToolsMenuPopup { | |
3441 DCHECK(_browserState); | |
3442 DCHECK(self.visible || self.dismissingModal); | |
3443 | |
3444 // Record the time this menu was requested; to be stored in the configuration | |
3445 // object. | |
3446 NSDate* showToolsMenuPopupRequestDate = [NSDate date]; | |
3447 | |
3448 // Dismiss the omnibox (if open). | |
3449 [_toolbarController cancelOmniboxEdit]; | |
3450 // Dismiss the soft keyboard (if open). | |
3451 [[_model currentTab].webController dismissKeyboard]; | |
3452 // Dismiss Find in Page focus. | |
3453 [self updateFindBar:NO shouldFocus:NO]; | |
3454 | |
3455 ToolsMenuConfiguration* configuration = | |
3456 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; | |
3457 configuration.requestStartTime = | |
3458 showToolsMenuPopupRequestDate.timeIntervalSinceReferenceDate; | |
3459 if ([_model count] == 0) | |
3460 [configuration setNoOpenedTabs:YES]; | |
3461 | |
3462 if (_isOffTheRecord) | |
3463 [configuration setInIncognito:YES]; | |
3464 | |
3465 if (!_readingListMenuNotifier) { | |
3466 _readingListMenuNotifier = [[ReadingListMenuNotifier alloc] | |
3467 initWithReadingList:ReadingListModelFactory::GetForBrowserState( | |
3468 _browserState)]; | |
3469 } | |
3470 [configuration setReadingListMenuNotifier:_readingListMenuNotifier]; | |
3471 | |
3472 [configuration setUserAgentType:self.userAgentType]; | |
3473 | |
3474 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; | |
3475 | |
3476 ToolsPopupController* toolsPopupController = | |
3477 [_toolbarController toolsPopupController]; | |
3478 if ([_model currentTab]) { | |
3479 BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked(); | |
3480 [toolsPopupController setIsCurrentPageBookmarked:isBookmarked]; | |
3481 [toolsPopupController setCanShowFindBar:self.canShowFindBar]; | |
3482 [toolsPopupController setCanUseReaderMode:self.canUseReaderMode]; | |
3483 [toolsPopupController setCanShowShareMenu:self.canShowShareMenu]; | |
3484 | |
3485 if (!IsIPadIdiom()) | |
3486 [toolsPopupController setIsTabLoading:_toolbarModelIOS->IsLoading()]; | |
3487 } | |
3488 } | |
3489 | |
3490 - (void)showPageInfoPopupForView:(UIView*)sourceView { | 3437 - (void)showPageInfoPopupForView:(UIView*)sourceView { |
3491 Tab* tab = [_model currentTab]; | 3438 Tab* tab = [_model currentTab]; |
3492 DCHECK([tab navigationManager]); | 3439 DCHECK([tab navigationManager]); |
3493 web::NavigationItem* navItem = [tab navigationManager]->GetVisibleItem(); | 3440 web::NavigationItem* navItem = [tab navigationManager]->GetVisibleItem(); |
3494 | 3441 |
3495 // It is fully expected to have a navItem here, as showPageInfoPopup can only | 3442 // It is fully expected to have a navItem here, as showPageInfoPopup can only |
3496 // be trigerred by a button enabled when a current item matches some | 3443 // be trigerred by a button enabled when a current item matches some |
3497 // conditions. However a crash was seen were navItem was NULL hence this | 3444 // conditions. However a crash was seen were navItem was NULL hence this |
3498 // test after a DCHECK. | 3445 // test after a DCHECK. |
3499 DCHECK(navItem); | 3446 DCHECK(navItem); |
(...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4051 | 3998 |
4052 - (void)bookmarkPage { | 3999 - (void)bookmarkPage { |
4053 [self initializeBookmarkInteractionController]; | 4000 [self initializeBookmarkInteractionController]; |
4054 [_bookmarkInteractionController | 4001 [_bookmarkInteractionController |
4055 presentBookmarkForTab:[_model currentTab] | 4002 presentBookmarkForTab:[_model currentTab] |
4056 currentlyBookmarked:_toolbarModelIOS->IsCurrentTabBookmarkedByUser() | 4003 currentlyBookmarked:_toolbarModelIOS->IsCurrentTabBookmarkedByUser() |
4057 inView:[_toolbarController bookmarkButtonView] | 4004 inView:[_toolbarController bookmarkButtonView] |
4058 originRect:[_toolbarController bookmarkButtonAnchorRect]]; | 4005 originRect:[_toolbarController bookmarkButtonAnchorRect]]; |
4059 } | 4006 } |
4060 | 4007 |
| 4008 - (void)showToolsMenu { |
| 4009 DCHECK(_browserState); |
| 4010 DCHECK(self.visible || self.dismissingModal); |
| 4011 |
| 4012 // Record the time this menu was requested; to be stored in the configuration |
| 4013 // object. |
| 4014 NSDate* showToolsMenuPopupRequestDate = [NSDate date]; |
| 4015 |
| 4016 // Dismiss the omnibox (if open). |
| 4017 [_toolbarController cancelOmniboxEdit]; |
| 4018 // Dismiss the soft keyboard (if open). |
| 4019 [[_model currentTab].webController dismissKeyboard]; |
| 4020 // Dismiss Find in Page focus. |
| 4021 [self updateFindBar:NO shouldFocus:NO]; |
| 4022 |
| 4023 ToolsMenuConfiguration* configuration = |
| 4024 [[ToolsMenuConfiguration alloc] initWithDisplayView:[self view]]; |
| 4025 configuration.requestStartTime = |
| 4026 showToolsMenuPopupRequestDate.timeIntervalSinceReferenceDate; |
| 4027 if ([_model count] == 0) |
| 4028 [configuration setNoOpenedTabs:YES]; |
| 4029 |
| 4030 if (_isOffTheRecord) |
| 4031 [configuration setInIncognito:YES]; |
| 4032 |
| 4033 if (!_readingListMenuNotifier) { |
| 4034 _readingListMenuNotifier = [[ReadingListMenuNotifier alloc] |
| 4035 initWithReadingList:ReadingListModelFactory::GetForBrowserState( |
| 4036 _browserState)]; |
| 4037 } |
| 4038 [configuration setReadingListMenuNotifier:_readingListMenuNotifier]; |
| 4039 |
| 4040 [configuration setUserAgentType:self.userAgentType]; |
| 4041 |
| 4042 [_toolbarController showToolsMenuPopupWithConfiguration:configuration]; |
| 4043 |
| 4044 ToolsPopupController* toolsPopupController = |
| 4045 [_toolbarController toolsPopupController]; |
| 4046 if ([_model currentTab]) { |
| 4047 BOOL isBookmarked = _toolbarModelIOS->IsCurrentTabBookmarked(); |
| 4048 [toolsPopupController setIsCurrentPageBookmarked:isBookmarked]; |
| 4049 [toolsPopupController setCanShowFindBar:self.canShowFindBar]; |
| 4050 [toolsPopupController setCanUseReaderMode:self.canUseReaderMode]; |
| 4051 [toolsPopupController setCanShowShareMenu:self.canShowShareMenu]; |
| 4052 |
| 4053 if (!IsIPadIdiom()) |
| 4054 [toolsPopupController setIsTabLoading:_toolbarModelIOS->IsLoading()]; |
| 4055 } |
| 4056 } |
| 4057 |
4061 #pragma mark - Command Handling | 4058 #pragma mark - Command Handling |
4062 | 4059 |
4063 - (IBAction)chromeExecuteCommand:(id)sender { | 4060 - (IBAction)chromeExecuteCommand:(id)sender { |
4064 NSInteger command = [sender tag]; | 4061 NSInteger command = [sender tag]; |
4065 | 4062 |
4066 if (!_model || !_browserState) | 4063 if (!_model || !_browserState) |
4067 return; | 4064 return; |
4068 Tab* currentTab = [_model currentTab]; | 4065 Tab* currentTab = [_model currentTab]; |
4069 | 4066 |
4070 switch (command) { | 4067 switch (command) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4134 break; | 4131 break; |
4135 case IDC_READER_MODE: | 4132 case IDC_READER_MODE: |
4136 [[_model currentTab] switchToReaderMode]; | 4133 [[_model currentTab] switchToReaderMode]; |
4137 break; | 4134 break; |
4138 case IDC_REQUEST_DESKTOP_SITE: | 4135 case IDC_REQUEST_DESKTOP_SITE: |
4139 [[_model currentTab] reloadWithUserAgentType:web::UserAgentType::DESKTOP]; | 4136 [[_model currentTab] reloadWithUserAgentType:web::UserAgentType::DESKTOP]; |
4140 break; | 4137 break; |
4141 case IDC_REQUEST_MOBILE_SITE: | 4138 case IDC_REQUEST_MOBILE_SITE: |
4142 [[_model currentTab] reloadWithUserAgentType:web::UserAgentType::MOBILE]; | 4139 [[_model currentTab] reloadWithUserAgentType:web::UserAgentType::MOBILE]; |
4143 break; | 4140 break; |
4144 case IDC_SHOW_TOOLS_MENU: { | |
4145 [self showToolsMenuPopup]; | |
4146 break; | |
4147 } | |
4148 case IDC_SHOW_BOOKMARK_MANAGER: { | 4141 case IDC_SHOW_BOOKMARK_MANAGER: { |
4149 if (IsIPadIdiom()) { | 4142 if (IsIPadIdiom()) { |
4150 [self showAllBookmarks]; | 4143 [self showAllBookmarks]; |
4151 } else { | 4144 } else { |
4152 [self initializeBookmarkInteractionController]; | 4145 [self initializeBookmarkInteractionController]; |
4153 [_bookmarkInteractionController presentBookmarks]; | 4146 [_bookmarkInteractionController presentBookmarks]; |
4154 } | 4147 } |
4155 break; | 4148 break; |
4156 } | 4149 } |
4157 case IDC_SHOW_OTHER_DEVICES: { | 4150 case IDC_SHOW_OTHER_DEVICES: { |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5245 | 5238 |
5246 - (UIView*)voiceSearchButton { | 5239 - (UIView*)voiceSearchButton { |
5247 return _voiceSearchButton; | 5240 return _voiceSearchButton; |
5248 } | 5241 } |
5249 | 5242 |
5250 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { | 5243 - (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner { |
5251 return [self currentLogoAnimationControllerOwner]; | 5244 return [self currentLogoAnimationControllerOwner]; |
5252 } | 5245 } |
5253 | 5246 |
5254 @end | 5247 @end |
OLD | NEW |