Commit 79a6ac50 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Move back/forward buttons update to new object

The updates to the back/forward buttons, related to the tab history
presentations are now moved to a new object. The goal of this object is
to contain most of the updates of the buttons of the toolbar.

Bug: 784846
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Idc95d91cfca5a265e661d89550a8b1dc5e40d3ef
Reviewed-on: https://chromium-review.googlesource.com/768869
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#517440}
parent 53bcd586
...@@ -148,6 +148,7 @@ using web::WebStateImpl; ...@@ -148,6 +148,7 @@ using web::WebStateImpl;
- (void)selectedTabChanged; - (void)selectedTabChanged;
- (void)dismissToolsMenuPopup; - (void)dismissToolsMenuPopup;
- (void)cancelOmniboxEdit; - (void)cancelOmniboxEdit;
- (ToolbarButtonUpdater*)buttonUpdater;
@property(nonatomic, readonly, weak) UIViewController* viewController; @property(nonatomic, readonly, weak) UIViewController* viewController;
@end @end
...@@ -183,6 +184,9 @@ using web::WebStateImpl; ...@@ -183,6 +184,9 @@ using web::WebStateImpl;
- (UIViewController*)viewController { - (UIViewController*)viewController {
return self; return self;
} }
- (ToolbarButtonUpdater*)buttonUpdater {
return nil;
}
@end @end
#pragma mark - #pragma mark -
......
...@@ -14,6 +14,8 @@ source_set("toolbar") { ...@@ -14,6 +14,8 @@ source_set("toolbar") {
"toolbar_adapter.mm", "toolbar_adapter.mm",
"toolbar_button_tints.h", "toolbar_button_tints.h",
"toolbar_button_tints.mm", "toolbar_button_tints.mm",
"toolbar_button_updater.h",
"toolbar_button_updater.mm",
"toolbar_controller+protected.h", "toolbar_controller+protected.h",
"toolbar_controller.h", "toolbar_controller.h",
"toolbar_controller.mm", "toolbar_controller.mm",
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
OmniboxFocuser, OmniboxFocuser,
VoiceSearchControllerDelegate, VoiceSearchControllerDelegate,
ActivityServicePositioner, ActivityServicePositioner,
TabHistoryPositioner,
TabHistoryUIUpdater,
QRScannerResultLoading, QRScannerResultLoading,
BubbleViewAnchorPointProvider> BubbleViewAnchorPointProvider>
@end @end
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#import "ios/chrome/browser/ui/toolbar/legacy_toolbar_coordinator.h" #import "ios/chrome/browser/ui/toolbar/legacy_toolbar_coordinator.h"
#import "ios/chrome/browser/ui/toolbar/omnibox_focuser.h" #import "ios/chrome/browser/ui/toolbar/omnibox_focuser.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_button_updater.h"
#import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h" #import "ios/chrome/browser/ui/toolbar/web_toolbar_controller.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
...@@ -51,11 +52,11 @@ ...@@ -51,11 +52,11 @@
} }
- (id<TabHistoryPositioner>)tabHistoryPositioner { - (id<TabHistoryPositioner>)tabHistoryPositioner {
return self.toolbarController; return self.toolbarController.buttonUpdater;
} }
- (id<TabHistoryUIUpdater>)tabHistoryUIUpdater { - (id<TabHistoryUIUpdater>)tabHistoryUIUpdater {
return self.toolbarController; return self.toolbarController.buttonUpdater;
} }
- (id<QRScannerResultLoading>)QRScannerResultLoader { - (id<QRScannerResultLoading>)QRScannerResultLoader {
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/toolbar/public/abstract_toolbar.h" #import "ios/chrome/browser/ui/toolbar/public/abstract_toolbar.h"
@class Tab; @class Tab;
@class ToolbarButtonUpdater;
@protocol WebToolbarDelegate; @protocol WebToolbarDelegate;
// WebToolbarController public interface. // WebToolbarController public interface.
...@@ -42,6 +43,8 @@ ...@@ -42,6 +43,8 @@
@property(nonatomic, weak) id<WebToolbarDelegate> delegate; @property(nonatomic, weak) id<WebToolbarDelegate> delegate;
// Convienence getter for the UIViewController. // Convienence getter for the UIViewController.
@property(nonatomic, readonly, weak) UIViewController* viewController; @property(nonatomic, readonly, weak) UIViewController* viewController;
// Object handling the updates of the buttons.
@property(nonatomic, strong) ToolbarButtonUpdater* buttonUpdater;
@end @end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_PUBLIC_ABSTRACT_WEB_TOOLBAR_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_PUBLIC_ABSTRACT_WEB_TOOLBAR_H_
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
@implementation ToolbarAdapter @implementation ToolbarAdapter
@synthesize backgroundView = _backgroundView; @synthesize backgroundView = _backgroundView;
@synthesize buttonUpdater = _buttonAdapter;
@synthesize toolbarCoordinator = _toolbarCoordinator; @synthesize toolbarCoordinator = _toolbarCoordinator;
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize toolsPopupController = _toolsPopupController; @synthesize toolsPopupController = _toolsPopupController;
......
// 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_BUTTON_UPDATER_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_BUTTON_UPDATER_H_
#import <UIKit/UIKit.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"
// Updater for the toolbar buttons.
@interface ToolbarButtonUpdater
: NSObject<TabHistoryPositioner, TabHistoryUIUpdater>
// Back button of the toolbar.
@property(nonatomic, strong) UIButton* backButton;
// Forward button of the toolbar.
@property(nonatomic, strong) UIButton* forwardButton;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_BUTTON_UPDATER_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_button_updater.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface ToolbarButtonUpdater ()
// Keeps track of whether or not the back button's images have been reversed.
@property(nonatomic, assign) ToolbarButtonMode backButtonMode;
// Keeps track of whether or not the forward button's images have been
// reversed.
@property(nonatomic, assign) ToolbarButtonMode forwardButtonMode;
@end
@implementation ToolbarButtonUpdater
@synthesize backButton = _backButton;
@synthesize forwardButton = _forwardButton;
@synthesize backButtonMode = _backButtonMode;
@synthesize forwardButtonMode = _forwardButtonMode;
#pragma mark - Public
- (instancetype)init {
self = [super init];
if (self) {
_backButtonMode = ToolbarButtonModeNormal;
_forwardButtonMode = ToolbarButtonModeNormal;
}
return self;
}
#pragma mark - TabHistoryPositioner
- (CGPoint)originPointForToolbarButton:(ToolbarButtonType)toolbarButton {
UIButton* historyButton =
toolbarButton ? self.backButton : self.forwardButton;
// Set the origin for the tools popup to the leading side of the bottom of the
// pressed buttons.
CGRect buttonBounds = [historyButton.imageView bounds];
CGPoint leadingBottomCorner = CGPointMake(CGRectGetLeadingEdge(buttonBounds),
CGRectGetMaxY(buttonBounds));
CGPoint origin = [historyButton.imageView convertPoint:leadingBottomCorner
toView:historyButton.window];
return origin;
}
#pragma mark - TabHistoryUIUpdater
- (void)updateUIForTabHistoryPresentationFrom:(ToolbarButtonType)button {
UIButton* historyButton = button ? self.backButton : self.forwardButton;
// Keep the button pressed by swapping the normal and highlighted images.
[self setImagesForNavButton:historyButton withTabHistoryVisible:YES];
}
- (void)updateUIForTabHistoryWasDismissed {
[self setImagesForNavButton:self.backButton withTabHistoryVisible:NO];
[self setImagesForNavButton:self.forwardButton withTabHistoryVisible:NO];
}
#pragma mark - Private
- (void)setImagesForNavButton:(UIButton*)button
withTabHistoryVisible:(BOOL)tabHistoryVisible {
BOOL isBackButton = button == self.backButton;
ToolbarButtonMode newMode =
tabHistoryVisible ? ToolbarButtonModeReversed : ToolbarButtonModeNormal;
if (isBackButton && newMode == self.backButtonMode)
return;
if (!isBackButton && newMode == self.forwardButtonMode)
return;
UIImage* normalImage = [button imageForState:UIControlStateNormal];
UIImage* highlightedImage = [button imageForState:UIControlStateHighlighted];
[button setImage:highlightedImage forState:UIControlStateNormal];
[button setImage:normalImage forState:UIControlStateHighlighted];
if (isBackButton)
self.backButtonMode = newMode;
else
self.forwardButtonMode = newMode;
}
@end
...@@ -7,8 +7,6 @@ ...@@ -7,8 +7,6 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.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/omnibox/omnibox_popup_positioner.h" #include "ios/chrome/browser/ui/omnibox/omnibox_popup_positioner.h"
#include "ios/chrome/browser/ui/qr_scanner/requirements/qr_scanner_result_loading.h" #include "ios/chrome/browser/ui/qr_scanner/requirements/qr_scanner_result_loading.h"
#import "ios/chrome/browser/ui/toolbar/omnibox_focuser.h" #import "ios/chrome/browser/ui/toolbar/omnibox_focuser.h"
...@@ -30,12 +28,10 @@ class ChromeBrowserState; ...@@ -30,12 +28,10 @@ class ChromeBrowserState;
// Web-view specific toolbar, adding navigation controls like back/forward, // Web-view specific toolbar, adding navigation controls like back/forward,
// omnibox, etc. // omnibox, etc.
@interface WebToolbarController @interface WebToolbarController
: ToolbarController<OmniboxFocuser, : ToolbarController<AbstractWebToolbar,
OmniboxFocuser,
QRScannerResultLoading, QRScannerResultLoading,
TabHistoryPositioner, VoiceSearchControllerDelegate>
TabHistoryUIUpdater,
VoiceSearchControllerDelegate,
AbstractWebToolbar>
// Mark inherited initializer as unavailable. // Mark inherited initializer as unavailable.
- (instancetype)initWithStyle:(ToolbarControllerStyle)style - (instancetype)initWithStyle:(ToolbarControllerStyle)style
......
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_base_feature.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_base_feature.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_utils.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_utils.h"
#import "ios/chrome/browser/ui/toolbar/public/web_toolbar_controller_constants.h" #import "ios/chrome/browser/ui/toolbar/public/web_toolbar_controller_constants.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_button_updater.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h" #import "ios/chrome/browser/ui/toolbar/toolbar_controller+protected.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h" #import "ios/chrome/browser/ui/toolbar/toolbar_model_ios.h"
#include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h"
...@@ -133,13 +134,6 @@ using ios::material::TimingFunction; ...@@ -133,13 +134,6 @@ using ios::material::TimingFunction;
// icon should indicate so. // icon should indicate so.
BOOL _isTTSPlaying; BOOL _isTTSPlaying;
// Keeps track of whether or not the back button's images have been reversed.
ToolbarButtonMode _backButtonMode;
// Keeps track of whether or not the forward button's images have been
// reversed.
ToolbarButtonMode _forwardButtonMode;
// Keeps track of the last known toolbar frame. // Keeps track of the last known toolbar frame.
CGRect _lastKnownToolbarFrame; CGRect _lastKnownToolbarFrame;
...@@ -190,8 +184,6 @@ using ios::material::TimingFunction; ...@@ -190,8 +184,6 @@ using ios::material::TimingFunction;
// Called by long press gesture recognizer, used to display back/forward // Called by long press gesture recognizer, used to display back/forward
// history. // history.
- (void)handleLongPress:(UILongPressGestureRecognizer*)gesture; - (void)handleLongPress:(UILongPressGestureRecognizer*)gesture;
- (void)setImagesForNavButton:(UIButton*)button
withTabHistoryVisible:(BOOL)tabHistoryVisible;
// Returns a map where the keys are names of text-to-speech notifications and // Returns a map where the keys are names of text-to-speech notifications and
// the values are the selectors to use for these notifications. // the values are the selectors to use for these notifications.
+ (const std::map<__strong NSString*, SEL>&)selectorsForTTSNotificationNames; + (const std::map<__strong NSString*, SEL>&)selectorsForTTSNotificationNames;
...@@ -234,6 +226,7 @@ using ios::material::TimingFunction; ...@@ -234,6 +226,7 @@ using ios::material::TimingFunction;
@implementation WebToolbarController @implementation WebToolbarController
@synthesize buttonUpdater = _buttonUpdater;
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize urlLoader = _urlLoader; @synthesize urlLoader = _urlLoader;
...@@ -307,9 +300,12 @@ using ios::material::TimingFunction; ...@@ -307,9 +300,12 @@ using ios::material::TimingFunction;
alpha:1.0]; alpha:1.0];
[_locationBarView.textField setPlaceholderTextColor:placeholderTextColor]; [_locationBarView.textField setPlaceholderTextColor:placeholderTextColor];
} }
_buttonUpdater = [[ToolbarButtonUpdater alloc] init];
_backButton = [[UIButton alloc] _backButton = [[UIButton alloc]
initWithFrame:LayoutRectGetRect(kBackButtonFrame[idiom])]; initWithFrame:LayoutRectGetRect(kBackButtonFrame[idiom])];
_buttonUpdater.backButton = _backButton;
[_backButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | [_backButton setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
UIViewAutoresizingFlexibleTopMargin]; UIViewAutoresizingFlexibleTopMargin];
...@@ -317,6 +313,7 @@ using ios::material::TimingFunction; ...@@ -317,6 +313,7 @@ using ios::material::TimingFunction;
// called. // called.
_forwardButton = [[UIButton alloc] _forwardButton = [[UIButton alloc]
initWithFrame:LayoutRectGetRect(kForwardButtonFrame[idiom])]; initWithFrame:LayoutRectGetRect(kForwardButtonFrame[idiom])];
_buttonUpdater.forwardButton = _forwardButton;
[_forwardButton [_forwardButton
setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() | setAutoresizingMask:UIViewAutoresizingFlexibleTrailingMargin() |
UIViewAutoresizingFlexibleTopMargin]; UIViewAutoresizingFlexibleTopMargin];
...@@ -457,8 +454,6 @@ using ios::material::TimingFunction; ...@@ -457,8 +454,6 @@ using ios::material::TimingFunction;
action:@selector(goForward) action:@selector(goForward)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
_backButtonMode = ToolbarButtonModeNormal;
_forwardButtonMode = ToolbarButtonModeNormal;
UILongPressGestureRecognizer* backLongPress = UILongPressGestureRecognizer* backLongPress =
[[UILongPressGestureRecognizer alloc] [[UILongPressGestureRecognizer alloc]
initWithTarget:self initWithTarget:self
...@@ -1069,32 +1064,6 @@ using ios::material::TimingFunction; ...@@ -1069,32 +1064,6 @@ using ios::material::TimingFunction;
} }
} }
#pragma mark - TabHistory Requirements
- (CGPoint)originPointForToolbarButton:(ToolbarButtonType)toolbarButton {
UIButton* historyButton = toolbarButton ? _backButton : _forwardButton;
// Set the origin for the tools popup to the leading side of the bottom of the
// pressed buttons.
CGRect buttonBounds = [historyButton.imageView bounds];
CGPoint leadingBottomCorner = CGPointMake(CGRectGetLeadingEdge(buttonBounds),
CGRectGetMaxY(buttonBounds));
CGPoint origin = [historyButton.imageView convertPoint:leadingBottomCorner
toView:historyButton.window];
return origin;
}
- (void)updateUIForTabHistoryPresentationFrom:(ToolbarButtonType)button {
UIButton* historyButton = button ? _backButton : _forwardButton;
// Keep the button pressed by swapping the normal and highlighted images.
[self setImagesForNavButton:historyButton withTabHistoryVisible:YES];
}
- (void)updateUIForTabHistoryWasDismissed {
[self setImagesForNavButton:_backButton withTabHistoryVisible:NO];
[self setImagesForNavButton:_forwardButton withTabHistoryVisible:NO];
}
#pragma mark - #pragma mark -
#pragma mark DropAndNavigateDelegate #pragma mark DropAndNavigateDelegate
...@@ -1388,26 +1357,6 @@ using ios::material::TimingFunction; ...@@ -1388,26 +1357,6 @@ using ios::material::TimingFunction;
} }
} }
- (void)setImagesForNavButton:(UIButton*)button
withTabHistoryVisible:(BOOL)tabHistoryVisible {
BOOL isBackButton = button == _backButton;
ToolbarButtonMode newMode =
tabHistoryVisible ? ToolbarButtonModeReversed : ToolbarButtonModeNormal;
if (isBackButton && newMode == _backButtonMode)
return;
if (!isBackButton && newMode == _forwardButtonMode)
return;
UIImage* normalImage = [button imageForState:UIControlStateNormal];
UIImage* highlightedImage = [button imageForState:UIControlStateHighlighted];
[button setImage:highlightedImage forState:UIControlStateNormal];
[button setImage:normalImage forState:UIControlStateHighlighted];
if (isBackButton)
_backButtonMode = newMode;
else
_forwardButtonMode = newMode;
}
- (void)updateToolbarAlphaForFrame:(CGRect)frame { - (void)updateToolbarAlphaForFrame:(CGRect)frame {
// Don't update the toolbar buttons if we are animating for a transition. // Don't update the toolbar buttons if we are animating for a transition.
if (self.view.animatingTransition) if (self.view.animatingTransition)
......
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