Commit 8efe1d99 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Migrate FindInPage and TextZoom coordinators to BrowserCoordinator

Now that both Find In Page and Text Zoom have their own separate
commands, we can move the actual implementations into BrowserCoordinator.
This leaves BVC simpler and simplifies the cleanup logic, because now
both coordinators can be stopped in BrowserCoordinator's
-stopChildCoordinators.

Bug: 1052818
Change-Id: Ib19dc967fae1777a086a6184ab328062eeef525c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062442
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#743911}
parent 25e1634f
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "ios/chrome/browser/chrome_url_constants.h" #include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/download/download_directory_util.h" #include "ios/chrome/browser/download/download_directory_util.h"
#import "ios/chrome/browser/download/pass_kit_tab_helper.h" #import "ios/chrome/browser/download/pass_kit_tab_helper.h"
#import "ios/chrome/browser/find_in_page/find_tab_helper.h"
#import "ios/chrome/browser/main/browser.h" #import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/store_kit/store_kit_coordinator.h" #import "ios/chrome/browser/store_kit/store_kit_coordinator.h"
#import "ios/chrome/browser/store_kit/store_kit_tab_helper.h" #import "ios/chrome/browser/store_kit/store_kit_tab_helper.h"
...@@ -32,11 +33,15 @@ ...@@ -32,11 +33,15 @@
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/browser_coordinator_commands.h" #import "ios/chrome/browser/ui/commands/browser_coordinator_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/find_in_page_commands.h"
#import "ios/chrome/browser/ui/commands/infobar_commands.h" #import "ios/chrome/browser/ui/commands/infobar_commands.h"
#import "ios/chrome/browser/ui/commands/page_info_commands.h" #import "ios/chrome/browser/ui/commands/page_info_commands.h"
#import "ios/chrome/browser/ui/commands/password_breach_commands.h" #import "ios/chrome/browser/ui/commands/password_breach_commands.h"
#import "ios/chrome/browser/ui/commands/text_zoom_commands.h"
#import "ios/chrome/browser/ui/download/ar_quick_look_coordinator.h" #import "ios/chrome/browser/ui/download/ar_quick_look_coordinator.h"
#import "ios/chrome/browser/ui/download/pass_kit_coordinator.h" #import "ios/chrome/browser/ui/download/pass_kit_coordinator.h"
#import "ios/chrome/browser/ui/find_bar/find_bar_controller_ios.h"
#import "ios/chrome/browser/ui/find_bar/find_bar_coordinator.h"
#import "ios/chrome/browser/ui/infobars/infobar_feature.h" #import "ios/chrome/browser/ui/infobars/infobar_feature.h"
#import "ios/chrome/browser/ui/open_in/open_in_mediator.h" #import "ios/chrome/browser/ui/open_in/open_in_mediator.h"
#import "ios/chrome/browser/ui/overlays/overlay_container_coordinator.h" #import "ios/chrome/browser/ui/overlays/overlay_container_coordinator.h"
...@@ -50,6 +55,9 @@ ...@@ -50,6 +55,9 @@
#import "ios/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h" #import "ios/chrome/browser/ui/recent_tabs/recent_tabs_coordinator.h"
#import "ios/chrome/browser/ui/settings/autofill/autofill_add_credit_card_coordinator.h" #import "ios/chrome/browser/ui/settings/autofill/autofill_add_credit_card_coordinator.h"
#import "ios/chrome/browser/ui/snackbar/snackbar_coordinator.h" #import "ios/chrome/browser/ui/snackbar/snackbar_coordinator.h"
#import "ios/chrome/browser/ui/text_zoom/text_zoom_coordinator.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_coordinator_delegate.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_presenter.h"
#import "ios/chrome/browser/ui/translate/legacy_translate_infobar_coordinator.h" #import "ios/chrome/browser/ui/translate/legacy_translate_infobar_coordinator.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h" #import "ios/chrome/browser/url_loading/url_loading_params.h"
#import "ios/chrome/browser/url_loading/url_loading_service.h" #import "ios/chrome/browser/url_loading/url_loading_service.h"
...@@ -71,6 +79,7 @@ ...@@ -71,6 +79,7 @@
FormInputAccessoryCoordinatorNavigator, FormInputAccessoryCoordinatorNavigator,
PageInfoCommands, PageInfoCommands,
RepostFormTabHelperDelegate, RepostFormTabHelperDelegate,
ToolbarAccessoryCoordinatorDelegate,
URLLoadingServiceDelegate, URLLoadingServiceDelegate,
WebStateListObserving> WebStateListObserving>
...@@ -105,6 +114,9 @@ ...@@ -105,6 +114,9 @@
@property(nonatomic, strong) @property(nonatomic, strong)
BadgePopupMenuCoordinator* badgePopupMenuCoordinator; BadgePopupMenuCoordinator* badgePopupMenuCoordinator;
// Coordinator for the find bar.
@property(nonatomic, strong) FindBarCoordinator* findBarCoordinator;
// Coordinator in charge of the presenting autofill options above the // Coordinator in charge of the presenting autofill options above the
// keyboard. // keyboard.
@property(nonatomic, strong) @property(nonatomic, strong)
...@@ -118,6 +130,9 @@ ...@@ -118,6 +130,9 @@
@property(nonatomic, strong) @property(nonatomic, strong)
ManualFillAllPasswordCoordinator* allPasswordCoordinator; ManualFillAllPasswordCoordinator* allPasswordCoordinator;
// Weak reference for the next coordinator to be displayed over the toolbar.
@property(nonatomic, weak) ChromeCoordinator* nextToolbarCoordinator;
// Coordinator for Page Info UI. // Coordinator for Page Info UI.
@property(nonatomic, strong) ChromeCoordinator* pageInfoCoordinator; @property(nonatomic, strong) ChromeCoordinator* pageInfoCoordinator;
...@@ -150,6 +165,9 @@ ...@@ -150,6 +165,9 @@
// Coordinator for presenting SKStoreProductViewController. // Coordinator for presenting SKStoreProductViewController.
@property(nonatomic, strong) StoreKitCoordinator* storeKitCoordinator; @property(nonatomic, strong) StoreKitCoordinator* storeKitCoordinator;
// Coordinator for Text Zoom.
@property(nonatomic, strong) TextZoomCoordinator* textZoomCoordinator;
// Coordinator for the translate infobar's language selection and translate // Coordinator for the translate infobar's language selection and translate
// option popup menus. // option popup menus.
@property(nonatomic, strong) @property(nonatomic, strong)
...@@ -187,6 +205,10 @@ ...@@ -187,6 +205,10 @@
DCHECK(self.browserState); DCHECK(self.browserState);
DCHECK(!self.viewController); DCHECK(!self.viewController);
[self startBrowserContainer]; [self startBrowserContainer];
[self.dispatcher startDispatchingToTarget:self
forProtocol:@protocol(TextZoomCommands)];
[self.dispatcher startDispatchingToTarget:self
forProtocol:@protocol(FindInPageCommands)];
[self createViewController]; [self createViewController];
[self startChildCoordinators]; [self startChildCoordinators];
[self.dispatcher [self.dispatcher
...@@ -394,6 +416,9 @@ ...@@ -394,6 +416,9 @@
[self.ARQuickLookCoordinator stop]; [self.ARQuickLookCoordinator stop];
self.ARQuickLookCoordinator = nil; self.ARQuickLookCoordinator = nil;
[self.findBarCoordinator stop];
self.findBarCoordinator = nil;
[self.formInputAccessoryCoordinator stop]; [self.formInputAccessoryCoordinator stop];
self.formInputAccessoryCoordinator = nil; self.formInputAccessoryCoordinator = nil;
self.injectionHandler = nil; self.injectionHandler = nil;
...@@ -429,6 +454,9 @@ ...@@ -429,6 +454,9 @@
[self.storeKitCoordinator stop]; [self.storeKitCoordinator stop];
self.storeKitCoordinator = nil; self.storeKitCoordinator = nil;
[self.textZoomCoordinator stop];
self.textZoomCoordinator = nil;
[self.translateInfobarCoordinator stop]; [self.translateInfobarCoordinator stop];
self.translateInfobarCoordinator = nil; self.translateInfobarCoordinator = nil;
...@@ -527,6 +555,116 @@ ...@@ -527,6 +555,116 @@
[self.addCreditCardCoordinator start]; [self.addCreditCardCoordinator start];
} }
#pragma mark - FindInPageCommands
- (void)openFindInPage {
if (!self.canShowFindBar)
return;
self.findBarCoordinator =
[[FindBarCoordinator alloc] initWithBaseViewController:self.viewController
browser:self.browser];
self.findBarCoordinator.presenter =
self.viewController.toolbarAccessoryPresenter;
self.findBarCoordinator.delegate = self;
self.findBarCoordinator.presentationDelegate = self.viewController;
if (self.viewController.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.findBarCoordinator;
[self hideTextZoom];
return;
}
[self.findBarCoordinator start];
}
- (void)closeFindInPage {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
__weak __typeof(self) weakSelf = self;
if (currentWebState) {
FindTabHelper* findTabHelper = FindTabHelper::FromWebState(currentWebState);
if (findTabHelper->IsFindUIActive()) {
findTabHelper->StopFinding(^{
[weakSelf.findBarCoordinator stop];
});
} else {
[self.findBarCoordinator stop];
}
}
}
- (void)showFindUIIfActive {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
auto* findHelper = FindTabHelper::FromWebState(currentWebState);
if (findHelper && findHelper->IsFindUIActive() &&
!self.findBarCoordinator.presenter.isPresenting) {
[self.findBarCoordinator start];
}
}
- (void)hideFindUI {
[self.findBarCoordinator stop];
}
- (void)defocusFindInPage {
[self.findBarCoordinator defocusFindBar];
}
- (void)searchFindInPage {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
DCHECK(currentWebState);
FindTabHelper* helper = FindTabHelper::FromWebState(currentWebState);
__weak __typeof(self) weakSelf = self;
helper->StartFinding([self.findBarCoordinator.findBarController searchTerm],
^(FindInPageModel* model) {
[weakSelf.findBarCoordinator.findBarController
updateResultsCount:model];
});
if (!self.browserState->IsOffTheRecord())
helper->PersistSearchTerm();
}
- (void)findNextStringInPage {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
DCHECK(currentWebState);
// TODO(crbug.com/603524): Reshow find bar if necessary.
FindTabHelper::FromWebState(currentWebState)
->ContinueFinding(FindTabHelper::FORWARD, ^(FindInPageModel* model) {
[self.findBarCoordinator.findBarController updateResultsCount:model];
});
}
- (void)findPreviousStringInPage {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
DCHECK(currentWebState);
// TODO(crbug.com/603524): Reshow find bar if necessary.
FindTabHelper::FromWebState(currentWebState)
->ContinueFinding(FindTabHelper::REVERSE, ^(FindInPageModel* model) {
[self.findBarCoordinator.findBarController updateResultsCount:model];
});
}
#pragma mark - FindInPageCommands Helpers
- (BOOL)canShowFindBar {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
if (!currentWebState) {
return NO;
}
auto* helper = FindTabHelper::FromWebState(currentWebState);
return (helper && helper->CurrentPageSupportsFindInPage() &&
!helper->IsFindUIActive());
}
#pragma mark - PageInfoCommands #pragma mark - PageInfoCommands
- (void)legacyShowPageInfoForOriginPoint:(CGPoint)originPoint { - (void)legacyShowPageInfoForOriginPoint:(CGPoint)originPoint {
...@@ -608,6 +746,45 @@ ...@@ -608,6 +746,45 @@
self.repostFormCoordinator = nil; self.repostFormCoordinator = nil;
} }
#pragma mark - ToolbarAccessoryCoordinatorDelegate
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)coordinator {
if (!self.nextToolbarCoordinator) {
return;
}
if (self.nextToolbarCoordinator == self.findBarCoordinator) {
[self openFindInPage];
self.nextToolbarCoordinator = nil;
} else if (self.nextToolbarCoordinator == self.textZoomCoordinator) {
[self showTextZoom];
self.nextToolbarCoordinator = nil;
}
}
#pragma mark - TextZoomCommands
- (void)showTextZoom {
self.textZoomCoordinator = [[TextZoomCoordinator alloc]
initWithBaseViewController:self.viewController
browser:self.browser];
self.textZoomCoordinator.presenter =
self.viewController.toolbarAccessoryPresenter;
self.textZoomCoordinator.delegate = self;
if (self.viewController.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.textZoomCoordinator;
[self closeFindInPage];
return;
}
[self.textZoomCoordinator start];
}
- (void)hideTextZoom {
[self.textZoomCoordinator stop];
}
#pragma mark - URLLoadingServiceDelegate #pragma mark - URLLoadingServiceDelegate
- (void)animateOpenBackgroundTabFromParams:(const UrlLoadParams&)params - (void)animateOpenBackgroundTabFromParams:(const UrlLoadParams&)params
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "base/ios/block_types.h" #import "base/ios/block_types.h"
#import "ios/chrome/browser/ui/find_bar/find_bar_coordinator.h"
#import "ios/chrome/browser/ui/page_info/requirements/page_info_presentation.h" #import "ios/chrome/browser/ui/page_info/requirements/page_info_presentation.h"
#import "ios/chrome/browser/ui/settings/sync/utils/sync_presenter.h" #import "ios/chrome/browser/ui/settings/sync/utils/sync_presenter.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_coordinator_delegate.h" #import "ios/chrome/browser/ui/toolbar/toolbar_coordinator_delegate.h"
...@@ -35,6 +36,7 @@ class ChromeBrowserState; ...@@ -35,6 +36,7 @@ class ChromeBrowserState;
// which implement the interface. // which implement the interface.
@interface BrowserViewController @interface BrowserViewController
: UIViewController <LogoAnimationControllerOwnerOwner, : UIViewController <LogoAnimationControllerOwnerOwner,
FindBarPresentationDelegate,
PageInfoPresentation, PageInfoPresentation,
SyncPresenter, SyncPresenter,
ToolbarCoordinatorDelegate> ToolbarCoordinatorDelegate>
...@@ -96,6 +98,10 @@ class ChromeBrowserState; ...@@ -96,6 +98,10 @@ class ChromeBrowserState;
@property(nonatomic, strong) @property(nonatomic, strong)
UIViewController* infobarModalOverlayContainerViewController; UIViewController* infobarModalOverlayContainerViewController;
// Presenter used to display accessories over the toolbar (e.g. Find In Page).
@property(nonatomic, strong)
ToolbarAccessoryPresenter* toolbarAccessoryPresenter;
// Whether the receiver is currently the primary BVC. // Whether the receiver is currently the primary BVC.
- (void)setPrimary:(BOOL)primary; - (void)setPrimary:(BOOL)primary;
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#import "ios/chrome/browser/download/download_manager_tab_helper.h" #import "ios/chrome/browser/download/download_manager_tab_helper.h"
#include "ios/chrome/browser/feature_engagement/tracker_factory.h" #include "ios/chrome/browser/feature_engagement/tracker_factory.h"
#include "ios/chrome/browser/feature_engagement/tracker_util.h" #include "ios/chrome/browser/feature_engagement/tracker_util.h"
#import "ios/chrome/browser/find_in_page/find_in_page_response_delegate.h"
#import "ios/chrome/browser/find_in_page/find_tab_helper.h" #import "ios/chrome/browser/find_in_page/find_tab_helper.h"
#include "ios/chrome/browser/first_run/first_run.h" #include "ios/chrome/browser/first_run/first_run.h"
#import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h" #import "ios/chrome/browser/geolocation/omnibox_geolocation_controller.h"
...@@ -93,9 +92,6 @@ ...@@ -93,9 +92,6 @@
#import "ios/chrome/browser/ui/dialogs/overlay_java_script_dialog_presenter.h" #import "ios/chrome/browser/ui/dialogs/overlay_java_script_dialog_presenter.h"
#import "ios/chrome/browser/ui/download/download_manager_coordinator.h" #import "ios/chrome/browser/ui/download/download_manager_coordinator.h"
#import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h" #import "ios/chrome/browser/ui/elements/activity_overlay_coordinator.h"
#import "ios/chrome/browser/ui/find_bar/find_bar_controller_ios.h"
#import "ios/chrome/browser/ui/find_bar/find_bar_coordinator.h"
#import "ios/chrome/browser/ui/find_bar/find_bar_view_controller.h"
#import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h" #import "ios/chrome/browser/ui/first_run/welcome_to_chrome_view_controller.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_animator.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_animator.h"
#import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h" #import "ios/chrome/browser/ui/fullscreen/fullscreen_controller.h"
...@@ -129,8 +125,6 @@ ...@@ -129,8 +125,6 @@
#import "ios/chrome/browser/ui/tabs/requirements/tab_strip_presentation.h" #import "ios/chrome/browser/ui/tabs/requirements/tab_strip_presentation.h"
#import "ios/chrome/browser/ui/tabs/switch_to_tab_animation_view.h" #import "ios/chrome/browser/ui/tabs/switch_to_tab_animation_view.h"
#import "ios/chrome/browser/ui/tabs/tab_strip_legacy_coordinator.h" #import "ios/chrome/browser/ui/tabs/tab_strip_legacy_coordinator.h"
#import "ios/chrome/browser/ui/text_zoom/text_zoom_coordinator.h"
#import "ios/chrome/browser/ui/text_zoom/text_zoom_view_controller.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_coordinator_delegate.h" #import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_coordinator_delegate.h"
#import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_presenter.h" #import "ios/chrome/browser/ui/toolbar/accessory/toolbar_accessory_presenter.h"
#import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_coordinator.h" #import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_coordinator.h"
...@@ -365,7 +359,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -365,7 +359,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
SigninPresenter, SigninPresenter,
SnapshotGeneratorDelegate, SnapshotGeneratorDelegate,
TabStripPresentation, TabStripPresentation,
ToolbarAccessoryCoordinatorDelegate, FindBarPresentationDelegate,
ToolbarHeightProviderForFullscreen, ToolbarHeightProviderForFullscreen,
WebStateListObserving, WebStateListObserving,
UIGestureRecognizerDelegate, UIGestureRecognizerDelegate,
...@@ -498,8 +492,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -498,8 +492,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
@property(nonatomic, strong, readonly) DialogPresenter* dialogPresenter; @property(nonatomic, strong, readonly) DialogPresenter* dialogPresenter;
// The object that manages keyboard commands on behalf of the BVC. // The object that manages keyboard commands on behalf of the BVC.
@property(nonatomic, strong, readonly) KeyCommandsProvider* keyCommandsProvider; @property(nonatomic, strong, readonly) KeyCommandsProvider* keyCommandsProvider;
// Helper method to check web controller canShowFindBar method.
@property(nonatomic, assign, readonly) BOOL canShowFindBar;
// Whether the controller's view is currently available. // Whether the controller's view is currently available.
// YES from viewWillAppear to viewWillDisappear. // YES from viewWillAppear to viewWillDisappear.
@property(nonatomic, assign, getter=isVisible) BOOL visible; @property(nonatomic, assign, getter=isVisible) BOOL visible;
...@@ -517,9 +509,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -517,9 +509,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Whether BVC prefers to hide the status bar. This value is used to determine // Whether BVC prefers to hide the status bar. This value is used to determine
// the response from the |prefersStatusBarHidden| method. // the response from the |prefersStatusBarHidden| method.
@property(nonatomic, assign) BOOL hideStatusBar; @property(nonatomic, assign) BOOL hideStatusBar;
// Presenter used to display accessories over the toolbar (e.g. Find In Page).
@property(nonatomic, strong)
ToolbarAccessoryPresenter* toolbarAccessoryPresenter;
// Coordinator for displaying a modal overlay with activity indicator to prevent // Coordinator for displaying a modal overlay with activity indicator to prevent
// the user from interacting with the browser view. // the user from interacting with the browser view.
@property(nonatomic, strong) @property(nonatomic, strong)
...@@ -553,16 +542,11 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -553,16 +542,11 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Coordinator for the popup menus. // Coordinator for the popup menus.
@property(nonatomic, strong) PopupMenuCoordinator* popupMenuCoordinator; @property(nonatomic, strong) PopupMenuCoordinator* popupMenuCoordinator;
// Coordinator for find in page.
@property(nonatomic, strong) FindBarCoordinator* findBarCoordinator;
// Coordinator for text zoom.
@property(nonatomic, strong) TextZoomCoordinator* textZoomCoordinator;
@property(nonatomic, weak) ChromeCoordinator* nextToolbarCoordinator;
@property(nonatomic, strong) BubblePresenter* bubblePresenter; @property(nonatomic, strong) BubblePresenter* bubblePresenter;
// Command handler for text zoom commands
@property(nonatomic, weak) id<TextZoomCommands> textZoomHandler;
// Primary toolbar. // Primary toolbar.
@property(nonatomic, strong) @property(nonatomic, strong)
PrimaryToolbarCoordinator* primaryToolbarCoordinator; PrimaryToolbarCoordinator* primaryToolbarCoordinator;
...@@ -742,15 +726,11 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -742,15 +726,11 @@ NSString* const kBrowserViewControllerSnackbarCategory =
_browserContainerViewController = browserContainerViewController; _browserContainerViewController = browserContainerViewController;
_dependencyFactory = factory; _dependencyFactory = factory;
self.commandDispatcher = browser->GetCommandDispatcher(); self.commandDispatcher = browser->GetCommandDispatcher();
self.textZoomHandler =
HandlerForProtocol(self.commandDispatcher, TextZoomCommands);
[self.commandDispatcher [self.commandDispatcher
startDispatchingToTarget:self startDispatchingToTarget:self
forProtocol:@protocol(BrowserCommands)]; forProtocol:@protocol(BrowserCommands)];
[self.commandDispatcher
startDispatchingToTarget:self
forProtocol:@protocol(FindInPageCommands)];
[self.commandDispatcher
startDispatchingToTarget:self
forProtocol:@protocol(TextZoomCommands)];
[self.commandDispatcher [self.commandDispatcher
startDispatchingToTarget:applicationCommandEndpoint startDispatchingToTarget:applicationCommandEndpoint
forProtocol:@protocol(ApplicationCommands)]; forProtocol:@protocol(ApplicationCommands)];
...@@ -916,18 +896,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -916,18 +896,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
return _keyCommandsProvider; return _keyCommandsProvider;
} }
- (BOOL)canShowFindBar {
// Make sure web controller can handle find in page.
web::WebState* webState = self.currentWebState;
if (!webState) {
return NO;
}
auto* helper = FindTabHelper::FromWebState(webState);
return (helper && helper->CurrentPageSupportsFindInPage() &&
!helper->IsFindUIActive());
}
- (BOOL)canShowTabStrip { - (BOOL)canShowTabStrip {
return IsRegularXRegularSizeClass(self); return IsRegularXRegularSizeClass(self);
} }
...@@ -1148,11 +1116,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1148,11 +1116,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
completion:nil]; completion:nil];
} }
[self.bubblePresenter userEnteredTabSwitcher]; [self.bubblePresenter userEnteredTabSwitcher];
// TODO(crbug.com/1052818): These should not be necessary once the
// coordinators are moved up to BrowserCoordinator.
[self.dispatcher hideFindUI];
[self.textZoomCoordinator stop];
} }
- (void)presentBubblesIfEligible { - (void)presentBubblesIfEligible {
...@@ -1236,7 +1199,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1236,7 +1199,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Keyboard shouldn't overlay the ecoutez window, so dismiss find in page and // Keyboard shouldn't overlay the ecoutez window, so dismiss find in page and
// dismiss the keyboard. // dismiss the keyboard.
[self.dispatcher closeFindInPage]; [self.dispatcher closeFindInPage];
[self hideTextZoom]; [self.textZoomHandler hideTextZoom];
[[self viewForWebState:self.currentWebState] endEditing:NO]; [[self viewForWebState:self.currentWebState] endEditing:NO];
// Ensure that voice search objects are created. // Ensure that voice search objects are created.
...@@ -1322,7 +1285,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1322,7 +1285,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[_ntpCoordinatorsForWebStates[webState] dismissModals]; [_ntpCoordinatorsForWebStates[webState] dismissModals];
} }
[self.dispatcher closeFindInPage]; [self.dispatcher closeFindInPage];
[self.textZoomCoordinator stop]; [self.textZoomHandler hideTextZoom];
} }
[self.dispatcher dismissPopupMenuAnimated:NO]; [self.dispatcher dismissPopupMenuAnimated:NO];
...@@ -1717,7 +1680,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1717,7 +1680,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
if (ShouldShowCompactToolbar(previousTraitCollection) != if (ShouldShowCompactToolbar(previousTraitCollection) !=
ShouldShowCompactToolbar()) { ShouldShowCompactToolbar()) {
[self.dispatcher hideFindUI]; [self.dispatcher hideFindUI];
[self.textZoomCoordinator stop]; [self.textZoomHandler hideTextZoom];
} }
// Update the toolbar visibility. // Update the toolbar visibility.
...@@ -2394,7 +2357,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2394,7 +2357,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
if (!self.inNewTabAnimation) { if (!self.inNewTabAnimation) {
// Hide findbar. |updateToolbar| will restore the findbar later. // Hide findbar. |updateToolbar| will restore the findbar later.
[self.dispatcher hideFindUI]; [self.dispatcher hideFindUI];
[self.textZoomCoordinator stop]; [self.textZoomHandler hideTextZoom];
// Make new content visible, resizing it first as the orientation may // Make new content visible, resizing it first as the orientation may
// have changed from the last time it was displayed. // have changed from the last time it was displayed.
...@@ -4203,26 +4166,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4203,26 +4166,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
} }
- (void)showTextZoom {
if (self.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.textZoomCoordinator;
[self closeFindInPage];
return;
}
self.textZoomCoordinator =
[[TextZoomCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
self.textZoomCoordinator.presenter = self.toolbarAccessoryPresenter;
self.textZoomCoordinator.delegate = self;
[self.textZoomCoordinator start];
}
- (void)hideTextZoom {
[self.textZoomCoordinator stop];
}
#pragma mark - BrowserCommands helpers #pragma mark - BrowserCommands helpers
// Reloads the original url of the last non-redirect item (including non-history // Reloads the original url of the last non-redirect item (including non-history
...@@ -4235,92 +4178,6 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4235,92 +4178,6 @@ NSString* const kBrowserViewControllerSnackbarCategory =
navigationManager->ReloadWithUserAgentType(userAgentType); navigationManager->ReloadWithUserAgentType(userAgentType);
} }
#pragma mark - FindInPageCommands
- (void)openFindInPage {
if (!self.canShowFindBar)
return;
if (self.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.findBarCoordinator;
[self hideTextZoom];
return;
}
self.findBarCoordinator =
[[FindBarCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
self.findBarCoordinator.presenter = self.toolbarAccessoryPresenter;
self.findBarCoordinator.delegate = self;
[self.findBarCoordinator start];
}
- (void)closeFindInPage {
__weak BrowserViewController* weakSelf = self;
if (self.currentWebState) {
FindTabHelper* findTabHelper =
FindTabHelper::FromWebState(self.currentWebState);
if (findTabHelper->IsFindUIActive()) {
findTabHelper->StopFinding(^{
[weakSelf hideFindUI];
});
} else {
[self hideFindUI];
}
}
}
- (void)showFindUIIfActive {
web::WebState* currentWebState =
self.browser->GetWebStateList()->GetActiveWebState();
auto* findHelper = FindTabHelper::FromWebState(currentWebState);
if (findHelper && findHelper->IsFindUIActive() &&
!self.findBarCoordinator.presenter.isPresenting) {
[self.findBarCoordinator start];
}
}
- (void)hideFindUI {
[self.findBarCoordinator stop];
}
- (void)defocusFindInPage {
[self.findBarCoordinator defocusFindBar];
}
- (void)searchFindInPage {
DCHECK(self.currentWebState);
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
__weak __typeof(self) weakSelf = self;
helper->StartFinding([self.findBarCoordinator.findBarController searchTerm],
^(FindInPageModel* model) {
[weakSelf.findBarCoordinator.findBarController
updateResultsCount:model];
});
if (!_isOffTheRecord)
helper->PersistSearchTerm();
}
- (void)findNextStringInPage {
DCHECK(self.currentWebState);
// TODO(crbug.com/603524): Reshow find bar if necessary.
FindTabHelper::FromWebState(self.currentWebState)
->ContinueFinding(FindTabHelper::FORWARD, ^(FindInPageModel* model) {
[self.findBarCoordinator.findBarController updateResultsCount:model];
});
}
- (void)findPreviousStringInPage {
DCHECK(self.currentWebState);
// TODO(crbug.com/603524): Reshow find bar if necessary.
FindTabHelper::FromWebState(self.currentWebState)
->ContinueFinding(FindTabHelper::REVERSE, ^(FindInPageModel* model) {
[self.findBarCoordinator.findBarController updateResultsCount:model];
});
}
#pragma mark - WebStateListObserving methods #pragma mark - WebStateListObserving methods
// Observer method, active WebState changed. // Observer method, active WebState changed.
...@@ -4363,7 +4220,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4363,7 +4220,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Remove the find bar for now. // Remove the find bar for now.
[self.dispatcher hideFindUI]; [self.dispatcher hideFindUI];
[self.textZoomCoordinator stop]; [self.textZoomHandler hideTextZoom];
} }
- (void)webStateList:(WebStateList*)webStateList - (void)webStateList:(WebStateList*)webStateList
...@@ -4630,7 +4487,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4630,7 +4487,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Hide UI accessories such as find bar and first visit overlays // Hide UI accessories such as find bar and first visit overlays
// for welcome page. // for welcome page.
[self.dispatcher hideFindUI]; [self.dispatcher hideFindUI];
[self.textZoomCoordinator stop]; [self.textZoomHandler hideTextZoom];
[self.infobarContainerCoordinator hideContainer:YES]; [self.infobarContainerCoordinator hideContainer:YES];
} }
} }
...@@ -4803,32 +4660,14 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4803,32 +4660,14 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[[self view] addSubview:tabStripView]; [[self view] addSubview:tabStripView];
} }
#pragma mark - ToolbarAccessoryCoordinatorDelegate #pragma mark - FindBarPresentationDelegate
- (void)setHeadersForToolbarAccessoryCoordinator: - (void)setHeadersForFindBarCoordinator:
(ChromeCoordinator*)toolbarAccessoryCoordinator { (FindBarCoordinator*)findBarCoordinator {
[self setFramesForHeaders:[self headerViews] [self setFramesForHeaders:[self headerViews]
atOffset:[self currentHeaderOffset]]; atOffset:[self currentHeaderOffset]];
} }
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)coordinator {
if (!self.nextToolbarCoordinator) {
return;
}
if (self.nextToolbarCoordinator == self.findBarCoordinator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self openFindInPage];
});
self.nextToolbarCoordinator = nil;
} else if (self.nextToolbarCoordinator == self.textZoomCoordinator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showTextZoom];
});
self.nextToolbarCoordinator = nil;
}
}
#pragma mark - Toolbar Accessory Methods #pragma mark - Toolbar Accessory Methods
- (ToolbarAccessoryPresenter*)toolbarAccessoryPresenter { - (ToolbarAccessoryPresenter*)toolbarAccessoryPresenter {
......
...@@ -29,7 +29,9 @@ ...@@ -29,7 +29,9 @@
#import "ios/chrome/browser/ui/browser_view/key_commands_provider.h" #import "ios/chrome/browser/ui/browser_view/key_commands_provider.h"
#import "ios/chrome/browser/ui/commands/application_commands.h" #import "ios/chrome/browser/ui/commands/application_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/commands/find_in_page_commands.h"
#import "ios/chrome/browser/ui/commands/page_info_commands.h" #import "ios/chrome/browser/ui/commands/page_info_commands.h"
#import "ios/chrome/browser/ui/commands/text_zoom_commands.h"
#include "ios/chrome/browser/ui/util/ui_util.h" #include "ios/chrome/browser/ui/util/ui_util.h"
#include "ios/chrome/browser/web_state_list/fake_web_state_list_delegate.h" #include "ios/chrome/browser/web_state_list/fake_web_state_list_delegate.h"
#include "ios/chrome/browser/web_state_list/web_state_list.h" #include "ios/chrome/browser/web_state_list/web_state_list.h"
...@@ -136,6 +138,17 @@ class BrowserViewControllerTest : public BlockCleanupTest { ...@@ -136,6 +138,17 @@ class BrowserViewControllerTest : public BlockCleanupTest {
SessionRestorationBrowserAgent::CreateForBrowser( SessionRestorationBrowserAgent::CreateForBrowser(
browser_.get(), [[TestSessionService alloc] init]); browser_.get(), [[TestSessionService alloc] init]);
id mockFindInPageCommandHandler =
OCMProtocolMock(@protocol(FindInPageCommands));
[browser_->GetCommandDispatcher()
startDispatchingToTarget:mockFindInPageCommandHandler
forProtocol:@protocol(FindInPageCommands)];
id mockTextZoomCommandHandler =
OCMProtocolMock(@protocol(TextZoomCommands));
[browser_->GetCommandDispatcher()
startDispatchingToTarget:mockTextZoomCommandHandler
forProtocol:@protocol(TextZoomCommands)];
// Create three web states. // Create three web states.
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
web::WebState::CreateParams params(chrome_browser_state_.get()); web::WebState::CreateParams params(chrome_browser_state_.get());
......
...@@ -12,6 +12,12 @@ ...@@ -12,6 +12,12 @@
@class ToolbarAccessoryPresenter; @class ToolbarAccessoryPresenter;
@protocol ToolbarAccessoryCoordinatorDelegate; @protocol ToolbarAccessoryCoordinatorDelegate;
@protocol FindBarPresentationDelegate
- (void)setHeadersForFindBarCoordinator:(FindBarCoordinator*)findBarCoordinator;
@end
// Coordinator for the Find Bar and the Find In page feature. Currently, this // Coordinator for the Find Bar and the Find In page feature. Currently, this
// is mostly a collection of code extracted from BrowserViewController and not // is mostly a collection of code extracted from BrowserViewController and not
// a good example of the ideal coordinator architecture. // a good example of the ideal coordinator architecture.
...@@ -22,6 +28,8 @@ ...@@ -22,6 +28,8 @@
@property(nonatomic, weak) id<ToolbarAccessoryCoordinatorDelegate> delegate; @property(nonatomic, weak) id<ToolbarAccessoryCoordinatorDelegate> delegate;
@property(nonatomic, weak) id<FindBarPresentationDelegate> presentationDelegate;
// Find bar controller object. This should probably be private, but is not to // Find bar controller object. This should probably be private, but is not to
// make the transition easier. // make the transition easier.
@property(nonatomic, strong) FindBarControllerIOS* findBarController; @property(nonatomic, strong) FindBarControllerIOS* findBarController;
......
...@@ -77,8 +77,6 @@ ...@@ -77,8 +77,6 @@
} }
[self.findBarController findBarViewWillHide]; [self.findBarController findBarViewWillHide];
[self.presenter dismissAnimated:animated]; [self.presenter dismissAnimated:animated];
self.mediator = nil;
} }
- (void)showAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus { - (void)showAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus {
...@@ -99,7 +97,7 @@ ...@@ -99,7 +97,7 @@
if (!self.browserState->IsOffTheRecord()) { if (!self.browserState->IsOffTheRecord()) {
helper->RestoreSearchTerm(); helper->RestoreSearchTerm();
} }
[self.delegate setHeadersForToolbarAccessoryCoordinator:self]; [self.presentationDelegate setHeadersForFindBarCoordinator:self];
[self.findBarController updateView:helper->GetFindResult() [self.findBarController updateView:helper->GetFindResult()
initialUpdate:YES initialUpdate:YES
focusTextfield:shouldFocus]; focusTextfield:shouldFocus];
......
...@@ -9,9 +9,6 @@ ...@@ -9,9 +9,6 @@
@protocol ToolbarAccessoryCoordinatorDelegate @protocol ToolbarAccessoryCoordinatorDelegate
- (void)setHeadersForToolbarAccessoryCoordinator:
(ChromeCoordinator*)toolbarAccessoryCoordinator;
- (void)toolbarAccessoryCoordinatorDidDismissUI: - (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)toolbarAccessoryCoordinator; (ChromeCoordinator*)toolbarAccessoryCoordinator;
......
...@@ -122,13 +122,12 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -122,13 +122,12 @@ const CGFloat kAnimationDuration = 0.15;
[weakSelf.presentedViewController.view removeFromSuperview]; [weakSelf.presentedViewController.view removeFromSuperview];
[weakSelf.presentedViewController removeFromParentViewController]; [weakSelf.presentedViewController removeFromParentViewController];
[weakSelf.backgroundView removeFromSuperview]; [weakSelf.backgroundView removeFromSuperview];
weakSelf.backgroundView = nil;
weakSelf.presenting = NO;
if ([weakSelf.delegate if ([weakSelf.delegate
respondsToSelector:@selector(containedPresenterDidDismiss:)]) { respondsToSelector:@selector(containedPresenterDidDismiss:)]) {
[weakSelf.delegate containedPresenterDidDismiss:weakSelf]; [weakSelf.delegate containedPresenterDidDismiss:weakSelf];
} }
weakSelf.backgroundView = nil;
weakSelf.presenting = NO;
[weakSelf.delegate containedPresenterDidDismiss:weakSelf];
}; };
if (animated) { if (animated) {
void (^animation)(); void (^animation)();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment