Commit ccc4c684 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[ios] Creates ToolbarAdapter behind a feature flag.

- Creates a feature flag for Clean Toolbar.
- Creates a ToolbarAdapter class that will be inited when the flag is enabled.
- Adapter conforms to Toolbar protocol, but no-ops all implementation for now.
- Adapter inits a CleanToolbarView controller and plumbs a dispatcher, WebstateList
and ChromeBrowserState.
- Adds a WebStateList parameter to BrowserViewControllerDependencyFactory.
- Adds a convenience viewController getter to AbstractWebToolbar protocol.

CL mainly done by sczs@.

Bug: 784502
Change-Id: Ie0c1fce6062adc123e8226252b827281f96ff081
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Reviewed-on: https://chromium-review.googlesource.com/771713Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517398}
parent a77965be
......@@ -188,7 +188,10 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
FEATURE_VALUE_TYPE(kPropertyAnimationsToolbar)},
{"new-fullscreen-controller", flag_descriptions::kNewFullscreenName,
flag_descriptions::kNewFullscreenDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(fullscreen::features::kNewFullscreen)}};
FEATURE_VALUE_TYPE(fullscreen::features::kNewFullscreen)},
{"clean-toolbar", flag_descriptions::kCleanToolbarName,
flag_descriptions::kCleanToolbarDescription, flags_ui::kOsIos,
FEATURE_VALUE_TYPE(kCleanToolbar)}};
// Add all switches from experimental flags to |command_line|.
void AppendSwitchesFromExperimentalSettings(base::CommandLine* command_line) {
......
......@@ -25,6 +25,11 @@ const char kCaptivePortalDescription[] =
"When enabled, the Captive Portal landing page will be displayed if it is "
"detected that the user is connected to a Captive Portal network.";
const char kCleanToolbarName[] = "Clean Toolbar";
const char kCleanToolbarDescription[] =
"When enabled, the Clean Toolbar will be used instead of "
"WebToolbarController.";
const char kContextualSearch[] = "Contextual Search";
const char kContextualSearchDescription[] =
"Whether or not Contextual Search is enabled.";
......
......@@ -20,6 +20,10 @@ extern const char kBrowserTaskSchedulerDescription[];
extern const char kCaptivePortalName[];
extern const char kCaptivePortalDescription[];
// Title and description for the flag to enable Clean Toolbar.
extern const char kCleanToolbarName[];
extern const char kCleanToolbarDescription[];
// Title and description for the flag to enable Contextual Search.
extern const char kContextualSearch[];
extern const char kContextualSearchDescription[];
......
......@@ -109,7 +109,8 @@ void PerfTestWithBVC::SetUp() {
// Create the browser view controller with its testing factory.
bvc_factory_.reset([[BrowserViewControllerDependencyFactory alloc]
initWithBrowserState:chrome_browser_state_.get()]);
initWithBrowserState:chrome_browser_state_.get()
webStateList:[tab_model_ webStateList]]);
bvc_.reset([[BrowserViewController alloc]
initWithTabModel:tab_model_
browserState:chrome_browser_state_.get()
......
......@@ -18,6 +18,7 @@
@protocol Toolbar;
class ToolbarModelDelegateIOS;
class ToolbarModelIOS;
class WebStateList;
@protocol UrlLoader;
@protocol WebToolbarDelegate;
......@@ -35,7 +36,8 @@ class ChromeBrowserState;
// Creates a new factory backed by |browserState|. This must be the same browser
// state provided to BrowserViewController (and like BVC, this is a weak
// reference).
- (id)initWithBrowserState:(ios::ChromeBrowserState*)browserState;
- (id)initWithBrowserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList;
// Creates a new PassKit view controller to display |pass|.
- (PKAddPassesViewController*)newPassKitViewControllerForPass:(PKPass*)pass;
......
......@@ -15,6 +15,8 @@
#import "ios/chrome/browser/tabs/tab_model.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/key_commands_provider.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_base_feature.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_adapter.h"
#include "ios/chrome/browser/ui/toolbar/toolbar_model_delegate_ios.h"
#include "ios/chrome/browser/ui/toolbar/toolbar_model_impl_ios.h"
#import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
......@@ -28,12 +30,15 @@
@implementation BrowserViewControllerDependencyFactory {
ios::ChromeBrowserState* browserState_;
WebStateList* webStateList_;
}
- (id)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
- (id)initWithBrowserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList {
self = [super init];
if (self) {
browserState_ = browserState;
webStateList_ = webStateList;
}
return self;
}
......@@ -61,11 +66,21 @@ newToolbarControllerWithDelegate:(id<WebToolbarDelegate>)delegate
urlLoader:(id<UrlLoader>)urlLoader
dispatcher:
(id<ApplicationCommands, BrowserCommands>)dispatcher {
return static_cast<id<Toolbar>>([[WebToolbarController alloc]
initWithDelegate:delegate
urlLoader:urlLoader
browserState:browserState_
dispatcher:dispatcher]);
id<Toolbar> toolbarController;
if (base::FeatureList::IsEnabled(kPropertyAnimationsToolbar)) {
toolbarController = static_cast<id<Toolbar>>([[ToolbarAdapter alloc]
initWithDispatcher:dispatcher
browserState:browserState_
webStateList:webStateList_]);
} else {
toolbarController = static_cast<id<Toolbar>>([[WebToolbarController alloc]
initWithDelegate:delegate
urlLoader:urlLoader
browserState:browserState_
dispatcher:dispatcher]);
}
return toolbarController;
}
- (KeyCommandsProvider*)newKeyCommandsProvider {
......
......@@ -148,6 +148,8 @@ using web::WebStateImpl;
- (void)selectedTabChanged;
- (void)dismissToolsMenuPopup;
- (void)cancelOmniboxEdit;
@property(nonatomic, readonly, weak) UIViewController* viewController;
@end
@implementation TestWebToolbarController
......@@ -178,6 +180,9 @@ using web::WebStateImpl;
- (void)cancelOmniboxEdit {
return;
}
- (UIViewController*)viewController {
return self;
}
@end
#pragma mark -
......
......@@ -390,7 +390,8 @@
tabModel:(TabModel*)tabModel {
BrowserViewControllerDependencyFactory* factory =
[[BrowserViewControllerDependencyFactory alloc]
initWithBrowserState:browserState];
initWithBrowserState:browserState
webStateList:[tabModel webStateList]];
return [[BrowserViewController alloc]
initWithTabModel:tabModel
browserState:browserState
......
......@@ -10,6 +10,8 @@ source_set("toolbar") {
"new_tab_button.h",
"new_tab_button.mm",
"omnibox_focuser.h",
"toolbar_adapter.h",
"toolbar_adapter.mm",
"toolbar_button_tints.h",
"toolbar_button_tints.mm",
"toolbar_controller+protected.h",
......@@ -82,6 +84,7 @@ source_set("toolbar") {
"//ios/chrome/browser/ui/omnibox",
"//ios/chrome/browser/ui/popup_menu",
"//ios/chrome/browser/ui/qr_scanner/requirements",
"//ios/chrome/browser/ui/toolbar/clean:toolbar",
"//ios/chrome/browser/ui/toolbar/keyboard_assist",
"//ios/chrome/browser/ui/tools_menu",
"//ios/chrome/browser/ui/tools_menu:configuration",
......
......@@ -5,17 +5,27 @@
#ifndef IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_COORDINATOR_H_
#import "ios/chrome/browser/ui/coordinators/browser_coordinator.h"
#import <Foundation/Foundation.h>
namespace web {
class WebState;
@protocol ApplicationCommands;
@protocol BrowserCommands;
class WebStateList;
namespace ios {
class ChromeBrowserState;
}
// Coordinator to run a toolbar -- a UI element housing controls.
@interface ToolbarCoordinator : BrowserCoordinator
// The web state this ToolbarCoordinator is handling.
@property(nonatomic, assign) web::WebState* webState;
@interface ToolbarCoordinator : NSObject
// Weak reference to ChromeBrowserState;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// The dispatcher for this view controller.
@property(nonatomic, weak) id<ApplicationCommands, BrowserCommands> dispatcher;
// The web state list this ToolbarCoordinator is handling.
@property(nonatomic, assign) WebStateList* webStateList;
// Start this coordinator.
- (void)start;
// Stop this coordinator.
- (void)stop;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_COORDINATOR_H_
......@@ -33,9 +33,11 @@
@end
@implementation ToolbarCoordinator
@synthesize viewController = _viewController;
@synthesize webState = _webState;
@synthesize browserState = _browserState;
@synthesize dispatcher = _dispatcher;
@synthesize mediator = _mediator;
@synthesize viewController = _viewController;
@synthesize webStateList = _webStateList;
- (instancetype)init {
if ((self = [super init])) {
......@@ -47,26 +49,19 @@
#pragma mark - BrowserCoordinator
- (void)start {
if (self.started)
return;
ToolbarStyle style =
self.browser->browser_state()->IsOffTheRecord() ? INCOGNITO : NORMAL;
ToolbarStyle style = self.browserState->IsOffTheRecord() ? INCOGNITO : NORMAL;
ToolbarButtonFactory* factory =
[[ToolbarButtonFactory alloc] initWithStyle:style];
self.viewController =
[[ToolbarViewController alloc] initWithDispatcher:self.callableDispatcher
[[ToolbarViewController alloc] initWithDispatcher:self.dispatcher
buttonFactory:factory];
self.mediator.consumer = self.viewController;
self.mediator.webStateList = &self.browser->web_state_list();
[super start];
self.mediator.webStateList = self.webStateList;
}
- (void)stop {
[super stop];
[self.mediator disconnect];
}
......
......@@ -27,8 +27,8 @@
- (UIViewController*)toolbarViewController {
if (!_toolbarViewController)
_toolbarViewController =
static_cast<UIViewController*>(self.toolbarController);
_toolbarViewController = self.toolbarController.viewController;
return _toolbarViewController;
}
......
......@@ -40,6 +40,8 @@
- (void)resetToolbarAfterSideSwipeSnapshot;
// WebToolbarDelegate delegate.
@property(nonatomic, weak) id<WebToolbarDelegate> delegate;
// Convienence getter for the UIViewController.
@property(nonatomic, readonly, weak) UIViewController* viewController;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_PUBLIC_ABSTRACT_WEB_TOOLBAR_H_
......@@ -10,4 +10,8 @@
// Feature to choose whether the toolbar uses UIViewPropertyAnimators.
extern const base::Feature kPropertyAnimationsToolbar;
// Feature to choose whether to use the clean Toolbar stack or
// WebToolbarController.
extern const base::Feature kCleanToolbar;
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONTROLLER_BASE_FEATURE_H_
......@@ -10,3 +10,6 @@
extern const base::Feature kPropertyAnimationsToolbar{
"PropertyAnimationsToolbar", base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kCleanToolbar{"CleanToolbar",
base::FEATURE_DISABLED_BY_DEFAULT};
// Copyright 2017 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_TOOLBAR_TOOLBAR_ADAPTER_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ADAPTER_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_positioner.h"
#import "ios/chrome/browser/ui/history_popup/requirements/tab_history_positioner.h"
#import "ios/chrome/browser/ui/history_popup/requirements/tab_history_ui_updater.h"
#include "ios/chrome/browser/ui/qr_scanner/requirements/qr_scanner_result_loading.h"
#import "ios/chrome/browser/ui/toolbar/legacy_toolbar_coordinator.h"
#include "ios/public/provider/chrome/browser/voice/voice_search_controller_delegate.h"
@protocol ApplicationCommands;
@protocol BrowserCommands;
namespace ios {
class ChromeBrowserState;
}
class WebStateList;
// Temporary Adapter so ToolbarCoordinator can work as a <Toolbar>
// for LegacyToolbarCoordinator.
@interface ToolbarAdapter : NSObject<Toolbar>
- (instancetype)initWithDispatcher:
(id<ApplicationCommands, BrowserCommands>)dispatcher
browserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_ADAPTER_H_
// Copyright 2017 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/toolbar/toolbar_adapter.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_coordinator.h"
@interface ToolbarAdapter ()
@property(nonatomic, strong) ToolbarCoordinator* toolbarCoordinator;
@end
@implementation ToolbarAdapter
@synthesize backgroundView = _backgroundView;
@synthesize toolbarCoordinator = _toolbarCoordinator;
@synthesize delegate = _delegate;
@synthesize toolsPopupController = _toolsPopupController;
@synthesize viewController = _viewController;
- (instancetype)initWithDispatcher:
(id<ApplicationCommands, BrowserCommands>)dispatcher
browserState:(ios::ChromeBrowserState*)browserState
webStateList:(WebStateList*)webStateList {
self = [super init];
if (self) {
_toolbarCoordinator = [[ToolbarCoordinator alloc] init];
_toolbarCoordinator.webStateList = webStateList;
_toolbarCoordinator.dispatcher = dispatcher;
_toolbarCoordinator.browserState = browserState;
}
return self;
}
#pragma mark - Abstract WebToolbar
- (void)browserStateDestroyed {
return;
}
- (void)updateToolbarState {
return;
}
- (void)showPrerenderingAnimation {
return;
}
- (void)currentPageLoadStarted {
return;
}
- (CGRect)visibleOmniboxFrame {
return CGRectZero;
}
- (BOOL)isOmniboxFirstResponder {
return NO;
}
- (BOOL)showingOmniboxPopup {
return NO;
}
- (void)selectedTabChanged {
return;
}
- (void)updateToolbarForSideSwipeSnapshot:(Tab*)tab {
return;
}
- (void)resetToolbarAfterSideSwipeSnapshot {
return;
}
#pragma mark - Abstract Toolbar
- (void)setShareButtonEnabled:(BOOL)enabled {
return;
}
- (void)triggerToolsMenuButtonAnimation {
return;
}
- (void)adjustToolbarHeight {
return;
}
- (void)setBackgroundAlpha:(CGFloat)alpha {
return;
}
- (void)setTabCount:(NSInteger)tabCount {
return;
}
- (void)activateFakeSafeAreaInsets:(UIEdgeInsets)fakeSafeAreaInsets {
return;
}
- (void)deactivateFakeSafeAreaInsets {
return;
}
- (void)showToolsMenuPopupWithConfiguration:
(ToolsMenuConfiguration*)configuration {
return;
}
- (void)dismissToolsMenuPopup {
return;
}
#pragma mark - Omnibox Focuser
- (void)focusOmnibox {
return;
}
- (void)cancelOmniboxEdit {
return;
}
- (void)focusFakebox {
return;
}
- (void)onFakeboxBlur {
return;
}
- (void)onFakeboxAnimationComplete {
return;
}
#pragma mark - VoiceSearchControllerDelegate
- (void)receiveVoiceSearchResult:(NSString*)voiceResult {
return;
}
#pragma mark - ActivityServicePositioner
- (CGRect)shareButtonAnchorRect {
return CGRectZero;
}
- (UIView*)shareButtonView {
return nil;
}
#pragma mark - TabHistoryPositioner
- (CGPoint)originPointForToolbarButton:(ToolbarButtonType)toolbarButton {
return CGPointZero;
}
#pragma mark - TabHistoryUIUpdater
- (void)updateUIForTabHistoryPresentationFrom:(ToolbarButtonType)button {
return;
}
- (void)updateUIForTabHistoryWasDismissed {
return;
}
#pragma mark - QRScannerResultLoading
- (void)receiveQRScannerResult:(NSString*)qrScannerResult
loadImmediately:(BOOL)load {
return;
}
#pragma mark - BubbleViewAnchorPointProvider
- (CGPoint)anchorPointForTabSwitcherButton:(BubbleArrowDirection)direction {
return CGPointZero;
}
- (CGPoint)anchorPointForToolsMenuButton:(BubbleArrowDirection)direction {
return CGPointZero;
}
@end
......@@ -567,6 +567,10 @@ using ios::material::TimingFunction;
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (UIViewController*)viewController {
return self;
}
#pragma mark -
#pragma mark Acessors
......
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