Commit 3b0649bf authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

[iOS] Add skeleton of Text Zoom UI

This adds a simple UI for text zoom (just the done button). The more
important contribution is that now, BVC will check which feature is
active, text zoom or find in page, and if something asks it to display
the other, it first dismisses the shown one.

Bug: 1028938
Change-Id: I576a096a635e0736f70e853f3c78e5459d7f4b78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1946481
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#730153}
parent c369c7ae
...@@ -139,6 +139,8 @@ source_set("browser_view") { ...@@ -139,6 +139,8 @@ source_set("browser_view") {
"//ios/chrome/browser/ui/tabs", "//ios/chrome/browser/ui/tabs",
"//ios/chrome/browser/ui/tabs:coordinator", "//ios/chrome/browser/ui/tabs:coordinator",
"//ios/chrome/browser/ui/tabs/requirements", "//ios/chrome/browser/ui/tabs/requirements",
"//ios/chrome/browser/ui/text_zoom",
"//ios/chrome/browser/ui/text_zoom:text_zoom_ui",
"//ios/chrome/browser/ui/toolbar", "//ios/chrome/browser/ui/toolbar",
"//ios/chrome/browser/ui/toolbar:toolbar_ui", "//ios/chrome/browser/ui/toolbar:toolbar_ui",
"//ios/chrome/browser/ui/toolbar/accessory", "//ios/chrome/browser/ui/toolbar/accessory",
......
...@@ -129,6 +129,8 @@ ...@@ -129,6 +129,8 @@
#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"
...@@ -558,6 +560,11 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -558,6 +560,11 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// Coordinator for find in page. // Coordinator for find in page.
@property(nonatomic, strong) FindBarCoordinator* findBarCoordinator; @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;
// Primary toolbar. // Primary toolbar.
...@@ -1011,7 +1018,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1011,7 +1018,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
.viewController.view .viewController.view
headerBehaviour:Hideable]]; headerBehaviour:Hideable]];
} }
if (self.toolbarAccessoryPresenter.backgroundView) { if (self.toolbarAccessoryPresenter.isPresenting) {
[results addObject:[HeaderDefinition [results addObject:[HeaderDefinition
definitionWithView:self.toolbarAccessoryPresenter definitionWithView:self.toolbarAccessoryPresenter
.backgroundView .backgroundView
...@@ -1269,7 +1276,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1269,7 +1276,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
auto* findHelper = FindTabHelper::FromWebState(webState); auto* findHelper = FindTabHelper::FromWebState(webState);
if (findHelper) { if (findHelper) {
findHelper->StopFinding(^{ findHelper->StopFinding(^{
[self.findBarCoordinator hideFindBarWithAnimation:YES]; [self.findBarCoordinator stop];
}); });
} }
} }
...@@ -1667,7 +1674,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -1667,7 +1674,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
// updateToobar]; // updateToobar];
if (ShouldShowCompactToolbar(previousTraitCollection) != if (ShouldShowCompactToolbar(previousTraitCollection) !=
ShouldShowCompactToolbar()) { ShouldShowCompactToolbar()) {
[self.findBarCoordinator hideFindBarWithAnimation:NO]; [self.findBarCoordinator stop];
} }
// Update the toolbar visibility. // Update the toolbar visibility.
...@@ -2360,7 +2367,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2360,7 +2367,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.findBarCoordinator hideFindBarWithAnimation:NO]; [self.findBarCoordinator stop];
// 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.
...@@ -2452,7 +2459,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -2452,7 +2459,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
auto* findHelper = FindTabHelper::FromWebState(webState); auto* findHelper = FindTabHelper::FromWebState(webState);
if (findHelper && findHelper->IsFindUIActive()) { if (findHelper && findHelper->IsFindUIActive()) {
[self.findBarCoordinator showFindBarAnimated:NO]; [self.findBarCoordinator start];
} }
BOOL hideToolbar = NO; BOOL hideToolbar = NO;
...@@ -4045,30 +4052,27 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4045,30 +4052,27 @@ NSString* const kBrowserViewControllerSnackbarCategory =
if (!self.canShowFindBar) if (!self.canShowFindBar)
return; return;
if (!self.toolbarAccessoryPresenter) { if (self.toolbarAccessoryPresenter.isPresenting) {
self.toolbarAccessoryPresenter = self.nextToolbarCoordinator = self.findBarCoordinator;
[[ToolbarAccessoryPresenter alloc] initWithIsIncognito:_isOffTheRecord]; [self hideTextZoom];
self.toolbarAccessoryPresenter.baseViewController = self; return;
} }
if (!self.findBarCoordinator) { [self.findBarCoordinator start];
self.findBarCoordinator =
[[FindBarCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
self.findBarCoordinator.presenter = self.toolbarAccessoryPresenter;
self.findBarCoordinator.delegate = self;
[self.findBarCoordinator start];
}
[self.findBarCoordinator startFindInPage];
} }
- (void)closeFindInPage { - (void)closeFindInPage {
__weak BrowserViewController* weakSelf = self; __weak BrowserViewController* weakSelf = self;
if (self.currentWebState) { if (self.currentWebState) {
FindTabHelper::FromWebState(self.currentWebState)->StopFinding(^{ FindTabHelper* findTabHelper =
[weakSelf.findBarCoordinator hideFindBarWithAnimation:YES]; FindTabHelper::FromWebState(self.currentWebState);
}); if (findTabHelper->IsFindUIActive()) {
findTabHelper->StopFinding(^{
[weakSelf.findBarCoordinator stop];
});
} else {
[self.findBarCoordinator stop];
}
} }
} }
...@@ -4206,6 +4210,20 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4206,6 +4210,20 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} }
} }
- (void)showTextZoom {
if (self.toolbarAccessoryPresenter.isPresenting) {
self.nextToolbarCoordinator = self.textZoomCoordinator;
[self closeFindInPage];
return;
}
[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
...@@ -4261,7 +4279,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4261,7 +4279,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
return; return;
// Remove the find bar for now. // Remove the find bar for now.
[self.findBarCoordinator hideFindBarWithAnimation:NO]; [self.findBarCoordinator stop];
} }
- (void)webStateList:(WebStateList*)webStateList - (void)webStateList:(WebStateList*)webStateList
...@@ -4538,7 +4556,7 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4538,7 +4556,7 @@ NSString* const kBrowserViewControllerSnackbarCategory =
} else { } else {
// 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.findBarCoordinator hideFindBarWithAnimation:NO]; [self.findBarCoordinator stop];
[self.infobarContainerCoordinator hideContainer:YES]; [self.infobarContainerCoordinator hideContainer:YES];
} }
} }
...@@ -4719,6 +4737,59 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -4719,6 +4737,59 @@ NSString* const kBrowserViewControllerSnackbarCategory =
atOffset:[self currentHeaderOffset]]; atOffset:[self currentHeaderOffset]];
} }
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)coordinator {
if (self.nextToolbarCoordinator == self.findBarCoordinator) {
dispatch_async(dispatch_get_main_queue(), ^{
[self showFindInPage];
});
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
- (ToolbarAccessoryPresenter*)toolbarAccessoryPresenter {
if (_toolbarAccessoryPresenter) {
return _toolbarAccessoryPresenter;
}
_toolbarAccessoryPresenter =
[[ToolbarAccessoryPresenter alloc] initWithIsIncognito:_isOffTheRecord];
_toolbarAccessoryPresenter.baseViewController = self;
return _toolbarAccessoryPresenter;
}
- (FindBarCoordinator*)findBarCoordinator {
if (_findBarCoordinator) {
return _findBarCoordinator;
}
_findBarCoordinator =
[[FindBarCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
_findBarCoordinator.presenter = self.toolbarAccessoryPresenter;
_findBarCoordinator.delegate = self;
return _findBarCoordinator;
}
- (TextZoomCoordinator*)textZoomCoordinator {
if (_textZoomCoordinator) {
return _textZoomCoordinator;
}
_textZoomCoordinator =
[[TextZoomCoordinator alloc] initWithBaseViewController:self
browser:self.browser];
_textZoomCoordinator.presenter = self.toolbarAccessoryPresenter;
_textZoomCoordinator.delegate = self;
return _textZoomCoordinator;
}
#pragma mark - ManageAccountsDelegate #pragma mark - ManageAccountsDelegate
- (void)onManageAccounts { - (void)onManageAccounts {
......
...@@ -116,6 +116,12 @@ class GURL; ...@@ -116,6 +116,12 @@ class GURL;
// prevent interaction with the web page. // prevent interaction with the web page.
- (void)showActivityOverlay:(BOOL)show; - (void)showActivityOverlay:(BOOL)show;
// Shows the Text Zoom UI.
- (void)showTextZoom;
// Dismisses the Text Zoom UI.
- (void)hideTextZoom;
@end @end
#endif // IOS_CHROME_BROWSER_UI_COMMANDS_BROWSER_COMMANDS_H_ #endif // IOS_CHROME_BROWSER_UI_COMMANDS_BROWSER_COMMANDS_H_
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
@interface FindBarControllerIOS : NSObject @interface FindBarControllerIOS : NSObject
// The dispatcher for sending browser commands. // The command handler for browser commands.
@property(nonatomic, weak) id<BrowserCommands> dispatcher; @property(nonatomic, weak) id<BrowserCommands> commandHandler;
// The view controller containing all the buttons and textfields that is common // The view controller containing all the buttons and textfields that is common
// between iPhone and iPad. // between iPhone and iPad.
@property(nonatomic, strong, readonly) @property(nonatomic, strong, readonly)
......
...@@ -89,7 +89,7 @@ const NSTimeInterval kSearchShortDelay = 0.100; ...@@ -89,7 +89,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
action:@selector(editingChanged) action:@selector(editingChanged)
forControlEvents:UIControlEventEditingChanged]; forControlEvents:UIControlEventEditingChanged];
[_findBarViewController.findBarView.nextButton [_findBarViewController.findBarView.nextButton
addTarget:self.dispatcher addTarget:self.commandHandler
action:@selector(findNextStringInPage) action:@selector(findNextStringInPage)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.nextButton [_findBarViewController.findBarView.nextButton
...@@ -97,7 +97,7 @@ const NSTimeInterval kSearchShortDelay = 0.100; ...@@ -97,7 +97,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
action:@selector(hideKeyboard:) action:@selector(hideKeyboard:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.previousButton [_findBarViewController.findBarView.previousButton
addTarget:self.dispatcher addTarget:self.commandHandler
action:@selector(findPreviousStringInPage) action:@selector(findPreviousStringInPage)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.previousButton [_findBarViewController.findBarView.previousButton
...@@ -105,7 +105,7 @@ const NSTimeInterval kSearchShortDelay = 0.100; ...@@ -105,7 +105,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
action:@selector(hideKeyboard:) action:@selector(hideKeyboard:)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
[_findBarViewController.findBarView.closeButton [_findBarViewController.findBarView.closeButton
addTarget:self.dispatcher addTarget:self.commandHandler
action:@selector(closeFindInPage) action:@selector(closeFindInPage)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
...@@ -203,7 +203,7 @@ const NSTimeInterval kSearchShortDelay = 0.100; ...@@ -203,7 +203,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
[self.delayTimer invalidate]; [self.delayTimer invalidate];
NSUInteger length = [[self searchTerm] length]; NSUInteger length = [[self searchTerm] length];
if (length == 0) { if (length == 0) {
[self.dispatcher searchFindInPage]; [self.commandHandler searchFindInPage];
return; return;
} }
...@@ -214,7 +214,7 @@ const NSTimeInterval kSearchShortDelay = 0.100; ...@@ -214,7 +214,7 @@ const NSTimeInterval kSearchShortDelay = 0.100;
(length > kSearchDelayChars) ? kSearchShortDelay : kSearchLongDelay; (length > kSearchDelayChars) ? kSearchShortDelay : kSearchLongDelay;
self.delayTimer = self.delayTimer =
[NSTimer scheduledTimerWithTimeInterval:delay [NSTimer scheduledTimerWithTimeInterval:delay
target:self.dispatcher target:self.commandHandler
selector:@selector(searchFindInPage) selector:@selector(searchFindInPage)
userInfo:nil userInfo:nil
repeats:NO]; repeats:NO];
......
...@@ -25,15 +25,6 @@ ...@@ -25,15 +25,6 @@
// make the transition easier. // make the transition easier.
@property(nonatomic, strong) FindBarControllerIOS* findBarController; @property(nonatomic, strong) FindBarControllerIOS* findBarController;
// Starts the Find In Page process.
- (void)startFindInPage;
// Shows the Find Bar UI.
- (void)showFindBarAnimated:(BOOL)animated;
// Hides the Find Bar UI.
- (void)hideFindBarWithAnimation:(BOOL)animated;
// Defocuses the Find Bar text field. // Defocuses the Find Bar text field.
- (void)defocusFindBar; - (void)defocusFindBar;
......
...@@ -24,36 +24,48 @@ ...@@ -24,36 +24,48 @@
@interface FindBarCoordinator () <FindInPageResponseDelegate, @interface FindBarCoordinator () <FindInPageResponseDelegate,
ContainedPresenterDelegate> ContainedPresenterDelegate>
// Command handler for |BrowserCommand|s.
@property(nonatomic, readonly) id<BrowserCommands> browserCommandHandler;
@end @end
@implementation FindBarCoordinator @implementation FindBarCoordinator
- (void)start { - (void)start {
self.findBarController = [[FindBarControllerIOS alloc] if (!self.findBarController) {
initWithIncognito:self.browserState->IsOffTheRecord()]; self.findBarController = [[FindBarControllerIOS alloc]
initWithIncognito:self.browserState->IsOffTheRecord()];
self.findBarController.commandHandler = self.browserCommandHandler;
}
self.presenter.delegate = self; self.presenter.delegate = self;
self.findBarController.dispatcher =
static_cast<id<BrowserCommands>>(self.browser->GetCommandDispatcher());
}
- (void)startFindInPage {
DCHECK(self.currentWebState); DCHECK(self.currentWebState);
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState); FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
DCHECK(!helper->IsFindUIActive()); // If the FindUI is already active, just reshow it.
helper->SetResponseDelegate(self); if (helper->IsFindUIActive()) {
helper->SetFindUIActive(true); [self showAnimated:NO shouldFocus:[self.findBarController isFocused]];
} else {
[self showFindBarAnimated:YES shouldFocus:YES]; DCHECK(!helper->IsFindUIActive());
helper->SetResponseDelegate(self);
helper->SetFindUIActive(true);
[self showAnimated:YES shouldFocus:YES];
}
} }
- (void)showFindBarAnimated:(BOOL)animated { - (void)stop {
[self showFindBarAnimated:animated if (!self.presenter.isPresenting) {
shouldFocus:[self.findBarController isFocused]]; return;
}
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
// If the FindUI is still active, the dismiss should be unanimated, because
// the UI will be brought back later.
BOOL animated = helper && !helper->IsFindUIActive();
[self.findBarController findBarViewWillHide];
[self.presenter dismissAnimated:animated];
} }
- (void)showFindBarAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus { - (void)showAnimated:(BOOL)animated shouldFocus:(BOOL)shouldFocus {
self.presenter.presentedViewController = self.presenter.presentedViewController =
self.findBarController.findBarViewController; self.findBarController.findBarViewController;
...@@ -77,11 +89,6 @@ ...@@ -77,11 +89,6 @@
focusTextfield:shouldFocus]; focusTextfield:shouldFocus];
} }
- (void)hideFindBarWithAnimation:(BOOL)animated {
[self.findBarController findBarViewWillHide];
[self.presenter dismissAnimated:animated];
}
- (void)defocusFindBar { - (void)defocusFindBar {
FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState); FindTabHelper* helper = FindTabHelper::FromWebState(self.currentWebState);
if (helper && helper->IsFindUIActive()) { if (helper && helper->IsFindUIActive()) {
...@@ -98,7 +105,7 @@ ...@@ -98,7 +105,7 @@
} }
- (void)findDidStop { - (void)findDidStop {
[self hideFindBarWithAnimation:YES]; [self.browserCommandHandler closeFindInPage];
} }
#pragma mark - ContainedPresenterDelegate #pragma mark - ContainedPresenterDelegate
...@@ -109,6 +116,7 @@ ...@@ -109,6 +116,7 @@
- (void)containedPresenterDidDismiss:(id<ContainedPresenter>)presenter { - (void)containedPresenterDidDismiss:(id<ContainedPresenter>)presenter {
[self.findBarController findBarViewDidHide]; [self.findBarController findBarViewDidHide];
[self.delegate toolbarAccessoryCoordinatorDidDismissUI:self];
} }
#pragma mark - Private #pragma mark - Private
...@@ -119,4 +127,9 @@ ...@@ -119,4 +127,9 @@
: nullptr; : nullptr;
} }
- (id<BrowserCommands>)browserCommandHandler {
return HandlerForProtocol(self.browser->GetCommandDispatcher(),
BrowserCommands);
}
@end @end
...@@ -110,6 +110,7 @@ using base::UserMetricsAction; ...@@ -110,6 +110,7 @@ using base::UserMetricsAction;
break; break;
case PopupMenuActionTextZoom: case PopupMenuActionTextZoom:
RecordAction(UserMetricsAction("MobileMenuTextZoom")); RecordAction(UserMetricsAction("MobileMenuTextZoom"));
[self.dispatcher showTextZoom];
break; break;
#if !defined(NDEBUG) #if !defined(NDEBUG)
case PopupMenuActionViewSource: case PopupMenuActionViewSource:
......
# Copyright 2019 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("text_zoom") {
sources = [
"text_zoom_coordinator.h",
"text_zoom_coordinator.mm",
]
deps = [
":text_zoom_ui",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/coordinators:chrome_coordinators",
"//ios/chrome/browser/ui/presenters",
"//ios/chrome/browser/ui/toolbar/accessory",
"//ios/chrome/browser/ui/toolbar/public:constants",
"//ios/chrome/common/colors",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
source_set("text_zoom_ui") {
sources = [
"text_zoom_view_controller.h",
"text_zoom_view_controller.mm",
]
deps = [
"//components/strings:components_strings",
"//ios/chrome/browser/ui/commands",
"//ui/base",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_COORDINATOR_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/coordinators/chrome_coordinator.h"
@class TextZoomViewController;
@class ToolbarAccessoryPresenter;
@protocol ToolbarAccessoryCoordinatorDelegate;
// Coordinator for the UI of the text zoom feature, which allows adjusting the
// zoom level of the text of a webpage.
@interface TextZoomCoordinator : ChromeCoordinator
// Presenter used by this coordinator to present itself.
@property(nonatomic, strong) ToolbarAccessoryPresenter* presenter;
// Delegate to inform when this coordinator's UI is dismissed.
@property(nonatomic, weak) id<ToolbarAccessoryCoordinatorDelegate> delegate;
@end
#endif // IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_COORDINATOR_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/text_zoom/text_zoom_coordinator.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/main/browser.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#include "ios/chrome/browser/ui/presenters/contained_presenter_delegate.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_presenter.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_constants.h"
#import "ios/chrome/common/colors/dynamic_color_util.h"
#import "ios/chrome/common/colors/semantic_color_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface TextZoomCoordinator () <ContainedPresenterDelegate>
// The view controller managed by this coordinator.
@property(nonatomic, strong, readwrite)
TextZoomViewController* textZoomViewController;
@end
@implementation TextZoomCoordinator
#pragma mark - ChromeCoordinator
- (void)start {
self.textZoomViewController = [[TextZoomViewController alloc] init];
self.textZoomViewController.commandHandler =
HandlerForProtocol(self.browser->GetCommandDispatcher(), BrowserCommands);
[self showAnimated:YES];
}
- (void)stop {
[self.presenter dismissAnimated:YES];
self.textZoomViewController = nil;
}
- (void)showAnimated:(BOOL)animated {
self.presenter.presentedViewController = self.textZoomViewController;
self.presenter.delegate = self;
[self.presenter prepareForPresentation];
[self.presenter presentAnimated:animated];
}
#pragma mark - ContainedPresenterDelegate
- (void)containedPresenterDidDismiss:(id<ContainedPresenter>)presenter {
[self.delegate toolbarAccessoryCoordinatorDidDismissUI:self];
}
@end
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
@protocol BrowserCommands;
@interface TextZoomViewController : UIViewController
@property(nonatomic, weak) id<BrowserCommands> commandHandler;
@end
#endif // IOS_CHROME_BROWSER_UI_TEXT_ZOOM_TEXT_ZOOM_VIEW_CONTROLLER_H_
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/text_zoom/text_zoom_view_controller.h"
#include "components/strings/grit/components_strings.h"
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Horizontal padding between all elements (except the previous/next buttons).
const CGFloat kPadding = 8;
const CGFloat kButtonFontSize = 17;
}
@interface TextZoomViewController ()
@property(nonatomic, strong) UIButton* closeButton;
@end
@implementation TextZoomViewController
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.closeButton];
[NSLayoutConstraint activateConstraints:@[
// Close Button.
[self.closeButton.centerYAnchor
constraintEqualToAnchor:self.view.centerYAnchor],
// [self.closeButton.heightAnchor constraintEqualToConstant:kButtonLength],
// Use button intrinsic width.
[self.closeButton.trailingAnchor
constraintEqualToAnchor:self.view.safeAreaLayoutGuide.trailingAnchor
constant:-kPadding],
]];
[self.closeButton
setContentCompressionResistancePriority:UILayoutPriorityDefaultHigh + 1
forAxis:UILayoutConstraintAxisHorizontal];
}
#pragma mark - Private methods (control actions)
- (void)closeButtonWasTapped:(id)sender {
[self.commandHandler hideTextZoom];
}
#pragma mark - Private property Accessors
// Creates and returns the close button.
- (UIButton*)closeButton {
if (!_closeButton) {
_closeButton = [UIButton buttonWithType:UIButtonTypeSystem];
[_closeButton setTitle:l10n_util::GetNSString(IDS_DONE)
forState:UIControlStateNormal];
_closeButton.translatesAutoresizingMaskIntoConstraints = NO;
// _closeButton.accessibilityIdentifier = kFindInPageCloseButtonId;
_closeButton.titleLabel.font = [UIFont systemFontOfSize:kButtonFontSize];
[_closeButton addTarget:self
action:@selector(closeButtonWasTapped:)
forControlEvents:UIControlEventTouchUpInside];
}
return _closeButton;
}
@end
...@@ -12,6 +12,9 @@ ...@@ -12,6 +12,9 @@
- (void)setHeadersForToolbarAccessoryCoordinator: - (void)setHeadersForToolbarAccessoryCoordinator:
(ChromeCoordinator*)toolbarAccessoryCoordinator; (ChromeCoordinator*)toolbarAccessoryCoordinator;
- (void)toolbarAccessoryCoordinatorDidDismissUI:
(ChromeCoordinator*)toolbarAccessoryCoordinator;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_ACCESSORY_TOOLBAR_ACCESSORY_COORDINATOR_DELEGATE_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_ACCESSORY_TOOLBAR_ACCESSORY_COORDINATOR_DELEGATE_H_
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// Whether the presenter is currently presenting a view
@property(nonatomic, readonly, getter=isPresenting) BOOL presenting;
// The main presented view. // The main presented view.
@property(nonatomic, strong, readonly) UIView* backgroundView; @property(nonatomic, strong, readonly) UIView* backgroundView;
......
...@@ -36,6 +36,9 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -36,6 +36,9 @@ const CGFloat kAnimationDuration = 0.15;
@interface ToolbarAccessoryPresenter () @interface ToolbarAccessoryPresenter ()
// The |presenting| public property redefined as readwrite.
@property(nonatomic, assign, readwrite, getter=isPresenting) BOOL presenting;
// The view that acts as the background for |presentedView|, redefined as // The view that acts as the background for |presentedView|, redefined as
// readwrite. This is especially important on iPhone, as this view that holds // readwrite. This is especially important on iPhone, as this view that holds
// everything around the safe area. // everything around the safe area.
...@@ -66,6 +69,7 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -66,6 +69,7 @@ const CGFloat kAnimationDuration = 0.15;
} }
- (void)prepareForPresentation { - (void)prepareForPresentation {
self.presenting = YES;
self.backgroundView = [self createBackgroundView]; self.backgroundView = [self createBackgroundView];
[self.baseViewController addChildViewController:self.presentedViewController]; [self.baseViewController addChildViewController:self.presentedViewController];
[self.baseViewController.view addSubview:self.backgroundView]; [self.baseViewController.view addSubview:self.backgroundView];
...@@ -75,32 +79,39 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -75,32 +79,39 @@ const CGFloat kAnimationDuration = 0.15;
} else { } else {
[self prepareForPresentationOnIPad]; [self prepareForPresentationOnIPad];
} }
// Force initial layout before the animation.
[self.baseViewController.view layoutIfNeeded];
} }
- (void)presentAnimated:(BOOL)animated { - (void)presentAnimated:(BOOL)animated {
if (animated) {
// Force initial layout before the animation.
[self.baseViewController.view layoutIfNeeded];
}
if (ShouldShowCompactToolbar()) { if (ShouldShowCompactToolbar()) {
[self setupFinalConstraintsOnIPhone]; [self setupFinalConstraintsOnIPhone];
} else { } else {
[self setupFinalConstraintsOnIPad]; [self setupFinalConstraintsOnIPad];
} }
CGFloat duration = animated ? kAnimationDuration : 0;
__weak __typeof(self) weakSelf = self; __weak __typeof(self) weakSelf = self;
[UIView animateWithDuration:duration auto completion = ^void(BOOL) {
animations:^() { [weakSelf.presentedViewController
[self.backgroundView layoutIfNeeded]; didMoveToParentViewController:weakSelf.baseViewController];
} if ([weakSelf.delegate
completion:^(BOOL finished) { respondsToSelector:@selector(containedPresenterDidPresent:)]) {
[weakSelf.presentedViewController [weakSelf.delegate containedPresenterDidPresent:weakSelf];
didMoveToParentViewController:weakSelf.baseViewController]; }
if ([weakSelf.delegate };
respondsToSelector:@selector(containedPresenterDidPresent:)]) {
[weakSelf.delegate containedPresenterDidPresent:weakSelf]; if (animated) {
} [UIView animateWithDuration:kAnimationDuration
}]; animations:^() {
[self.baseViewController.view layoutIfNeeded];
}
completion:completion];
} else {
completion(YES);
}
} }
- (void)dismissAnimated:(BOOL)animated { - (void)dismissAnimated:(BOOL)animated {
...@@ -116,6 +127,8 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -116,6 +127,8 @@ const CGFloat kAnimationDuration = 0.15;
[weakSelf.delegate containedPresenterDidDismiss:weakSelf]; [weakSelf.delegate containedPresenterDidDismiss:weakSelf];
} }
weakSelf.backgroundView = nil; 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