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 @@
#include "ios/chrome/browser/chrome_url_constants.h"
#include "ios/chrome/browser/download/download_directory_util.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/store_kit/store_kit_coordinator.h"
#import "ios/chrome/browser/store_kit/store_kit_tab_helper.h"
......@@ -32,11 +33,15 @@
#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/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/page_info_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/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/open_in/open_in_mediator.h"
#import "ios/chrome/browser/ui/overlays/overlay_container_coordinator.h"
......@@ -50,6 +55,9 @@
#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/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/url_loading/url_loading_params.h"
#import "ios/chrome/browser/url_loading/url_loading_service.h"
......@@ -71,6 +79,7 @@
FormInputAccessoryCoordinatorNavigator,
PageInfoCommands,
RepostFormTabHelperDelegate,
ToolbarAccessoryCoordinatorDelegate,
URLLoadingServiceDelegate,
WebStateListObserving>
......@@ -105,6 +114,9 @@
@property(nonatomic, strong)
BadgePopupMenuCoordinator* badgePopupMenuCoordinator;
// Coordinator for the find bar.
@property(nonatomic, strong) FindBarCoordinator* findBarCoordinator;
// Coordinator in charge of the presenting autofill options above the
// keyboard.
@property(nonatomic, strong)
......@@ -118,6 +130,9 @@
@property(nonatomic, strong)
ManualFillAllPasswordCoordinator* allPasswordCoordinator;
// Weak reference for the next coordinator to be displayed over the toolbar.
@property(nonatomic, weak) ChromeCoordinator* nextToolbarCoordinator;
// Coordinator for Page Info UI.
@property(nonatomic, strong) ChromeCoordinator* pageInfoCoordinator;
......@@ -150,6 +165,9 @@
// Coordinator for presenting SKStoreProductViewController.
@property(nonatomic, strong) StoreKitCoordinator* storeKitCoordinator;
// Coordinator for Text Zoom.
@property(nonatomic, strong) TextZoomCoordinator* textZoomCoordinator;
// Coordinator for the translate infobar's language selection and translate
// option popup menus.
@property(nonatomic, strong)
......@@ -187,6 +205,10 @@
DCHECK(self.browserState);
DCHECK(!self.viewController);
[self startBrowserContainer];
[self.dispatcher startDispatchingToTarget:self
forProtocol:@protocol(TextZoomCommands)];
[self.dispatcher startDispatchingToTarget:self
forProtocol:@protocol(FindInPageCommands)];
[self createViewController];
[self startChildCoordinators];
[self.dispatcher
......@@ -394,6 +416,9 @@
[self.ARQuickLookCoordinator stop];
self.ARQuickLookCoordinator = nil;
[self.findBarCoordinator stop];
self.findBarCoordinator = nil;
[self.formInputAccessoryCoordinator stop];
self.formInputAccessoryCoordinator = nil;
self.injectionHandler = nil;
......@@ -429,6 +454,9 @@
[self.storeKitCoordinator stop];
self.storeKitCoordinator = nil;
[self.textZoomCoordinator stop];
self.textZoomCoordinator = nil;
[self.translateInfobarCoordinator stop];
self.translateInfobarCoordinator = nil;
......@@ -527,6 +555,116 @@
[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
- (void)legacyShowPageInfoForOriginPoint:(CGPoint)originPoint {
......@@ -608,6 +746,45 @@
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
- (void)animateOpenBackgroundTabFromParams:(const UrlLoadParams&)params
......
......@@ -8,6 +8,7 @@
#import <UIKit/UIKit.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/settings/sync/utils/sync_presenter.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_coordinator_delegate.h"
......@@ -35,6 +36,7 @@ class ChromeBrowserState;
// which implement the interface.
@interface BrowserViewController
: UIViewController <LogoAnimationControllerOwnerOwner,
FindBarPresentationDelegate,
PageInfoPresentation,
SyncPresenter,
ToolbarCoordinatorDelegate>
......@@ -96,6 +98,10 @@ class ChromeBrowserState;
@property(nonatomic, strong)
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.
- (void)setPrimary:(BOOL)primary;
......
......@@ -29,7 +29,9 @@
#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/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/text_zoom_commands.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/web_state_list.h"
......@@ -136,6 +138,17 @@ class BrowserViewControllerTest : public BlockCleanupTest {
SessionRestorationBrowserAgent::CreateForBrowser(
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.
for (int i = 0; i < 3; i++) {
web::WebState::CreateParams params(chrome_browser_state_.get());
......
......@@ -12,6 +12,12 @@
@class ToolbarAccessoryPresenter;
@protocol ToolbarAccessoryCoordinatorDelegate;
@protocol FindBarPresentationDelegate
- (void)setHeadersForFindBarCoordinator:(FindBarCoordinator*)findBarCoordinator;
@end
// Coordinator for the Find Bar and the Find In page feature. Currently, this
// is mostly a collection of code extracted from BrowserViewController and not
// a good example of the ideal coordinator architecture.
......@@ -22,6 +28,8 @@
@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
// make the transition easier.
@property(nonatomic, strong) FindBarControllerIOS* findBarController;
......
......@@ -77,8 +77,6 @@
}
[self.findBarController findBarViewWillHide];
[self.presenter dismissAnimated:animated];
self.mediator = nil;
}
- (void)showAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus {
......@@ -99,7 +97,7 @@
if (!self.browserState->IsOffTheRecord()) {
helper->RestoreSearchTerm();
}
[self.delegate setHeadersForToolbarAccessoryCoordinator:self];
[self.presentationDelegate setHeadersForFindBarCoordinator:self];
[self.findBarController updateView:helper->GetFindResult()
initialUpdate:YES
focusTextfield:shouldFocus];
......
......@@ -9,9 +9,6 @@
@protocol ToolbarAccessoryCoordinatorDelegate
- (void)setHeadersForToolbarAccessoryCoordinator:
(ChromeCoordinator*)toolbarAccessoryCoordinator;
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)toolbarAccessoryCoordinator;
......
......@@ -122,13 +122,12 @@ const CGFloat kAnimationDuration = 0.15;
[weakSelf.presentedViewController.view removeFromSuperview];
[weakSelf.presentedViewController removeFromParentViewController];
[weakSelf.backgroundView removeFromSuperview];
weakSelf.backgroundView = nil;
weakSelf.presenting = NO;
if ([weakSelf.delegate
respondsToSelector:@selector(containedPresenterDidDismiss:)]) {
[weakSelf.delegate containedPresenterDidDismiss:weakSelf];
}
weakSelf.backgroundView = nil;
weakSelf.presenting = NO;
[weakSelf.delegate containedPresenterDidDismiss:weakSelf];
};
if (animated) {
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