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

Add a custom view for the Toolbar View Controller

The toolbar view allows to support the old fullscreen.

Bug: 792436
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ia39ce944840655255acfaf85ddce607425db40ae
Reviewed-on: https://chromium-review.googlesource.com/810945
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#522744}
parent 25bda349
...@@ -7,6 +7,8 @@ source_set("toolbar") { ...@@ -7,6 +7,8 @@ source_set("toolbar") {
sources = [ sources = [
"legacy_toolbar_coordinator.h", "legacy_toolbar_coordinator.h",
"legacy_toolbar_coordinator.mm", "legacy_toolbar_coordinator.mm",
"legacy_toolbar_view.h",
"legacy_toolbar_view.mm",
"new_tab_button.h", "new_tab_button.h",
"new_tab_button.mm", "new_tab_button.mm",
"omnibox_focuser.h", "omnibox_focuser.h",
...@@ -22,8 +24,6 @@ source_set("toolbar") { ...@@ -22,8 +24,6 @@ source_set("toolbar") {
"toolbar_model_ios.h", "toolbar_model_ios.h",
"toolbar_owner.h", "toolbar_owner.h",
"toolbar_snapshot_providing.h", "toolbar_snapshot_providing.h",
"toolbar_view.h",
"toolbar_view.mm",
"toolbar_view_delegate.h", "toolbar_view_delegate.h",
"tools_menu_button_observer_bridge.h", "tools_menu_button_observer_bridge.h",
"tools_menu_button_observer_bridge.mm", "tools_menu_button_observer_bridge.mm",
......
...@@ -56,6 +56,8 @@ source_set("toolbar_ui") { ...@@ -56,6 +56,8 @@ source_set("toolbar_ui") {
"toolbar_button_updater.h", "toolbar_button_updater.h",
"toolbar_button_updater.mm", "toolbar_button_updater.mm",
"toolbar_consumer.h", "toolbar_consumer.h",
"toolbar_view.h",
"toolbar_view.mm",
"toolbar_view_controller.h", "toolbar_view_controller.h",
"toolbar_view_controller.mm", "toolbar_view_controller.mm",
] ]
......
// 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_CLEAN_TOOLBAR_VIEW_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_VIEW_H_
#import <UIKit/UIKit.h>
// TODO(crbug.com/792440): Once the new notification for fullscreen is
// completed, this protocol can be removed. Protocol handling the fullscreen for
// the Toolbar.
@protocol ToolbarViewFullscreenDelegate
// Called when the frame of the Toolbar View has changed.
- (void)toolbarViewFrameChanged;
@end
// The view displaying the toolbar.
@interface ToolbarView : UIView
// The delegate used to handle frame changes.
@property(nonatomic, weak) id<ToolbarViewFullscreenDelegate> delegate;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_CLEAN_TOOLBAR_VIEW_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/clean/toolbar_view.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation ToolbarView
@synthesize delegate = _delegate;
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
[self.delegate toolbarViewFrameChanged];
}
@end
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_configuration.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_configuration.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_constants.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_constants.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_tools_menu_button.h" #import "ios/chrome/browser/ui/toolbar/clean/toolbar_tools_menu_button.h"
#import "ios/chrome/browser/ui/toolbar/clean/toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.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/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
...@@ -30,7 +31,7 @@ ...@@ -30,7 +31,7 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface ToolbarViewController () @interface ToolbarViewController ()<ToolbarViewFullscreenDelegate>
@property(nonatomic, strong) ToolbarButtonFactory* buttonFactory; @property(nonatomic, strong) ToolbarButtonFactory* buttonFactory;
@property(nonatomic, strong) ToolbarButtonUpdater* buttonUpdater; @property(nonatomic, strong) ToolbarButtonUpdater* buttonUpdater;
...@@ -76,9 +77,12 @@ ...@@ -76,9 +77,12 @@
// Top anchor at the bottom of the safeAreaLayoutGuide. Used so views don't // Top anchor at the bottom of the safeAreaLayoutGuide. Used so views don't
// overlap with the Status Bar. // overlap with the Status Bar.
@property(nonatomic, strong) NSLayoutYAxisAnchor* topSafeAnchor; @property(nonatomic, strong) NSLayoutYAxisAnchor* topSafeAnchor;
@property(nonatomic, strong) ToolbarView* view;
@end @end
@implementation ToolbarViewController @implementation ToolbarViewController
@dynamic view;
@synthesize leadingStackViewButtons = _leadingStackViewButtons; @synthesize leadingStackViewButtons = _leadingStackViewButtons;
@synthesize trailingStackViewButtons = _trailingStackViewButtons; @synthesize trailingStackViewButtons = _trailingStackViewButtons;
@synthesize backgroundView = _backgroundView; @synthesize backgroundView = _backgroundView;
...@@ -257,6 +261,11 @@ ...@@ -257,6 +261,11 @@
#pragma mark - View lifecyle #pragma mark - View lifecyle
- (void)loadView {
self.view = [[ToolbarView alloc] init];
self.view.delegate = self;
}
- (void)viewDidLoad { - (void)viewDidLoad {
// The view can be obstructed by the background view. // The view can be obstructed by the background view.
self.view.backgroundColor = self.view.backgroundColor =
...@@ -701,13 +710,28 @@ ...@@ -701,13 +710,28 @@
self.shareButton.enabled = enabled; self.shareButton.enabled = enabled;
} }
#pragma mark - ToolbarViewFullscreenDelegate
- (void)toolbarViewFrameChanged {
CGRect frame = self.view.frame;
CGFloat distanceOffscreen =
IsIPadIdiom()
? fmax((kIPadToolbarY - frame.origin.y) - kScrollFadeDistance, 0)
: -1 * frame.origin.y;
CGFloat fraction = 1 - fmin(distanceOffscreen / kScrollFadeDistance, 1);
self.leadingStackView.alpha = fraction;
self.locationBarContainer.alpha = fraction;
self.trailingStackView.alpha = fraction;
}
#pragma mark - ActivityServicePositioner #pragma mark - ActivityServicePositioner
- (UIView*)shareButtonView { - (UIView*)shareButtonView {
return self.shareButton; return self.shareButton;
} }
#pragma mark = BubbleViewAnchorPointProvider #pragma mark - BubbleViewAnchorPointProvider
- (CGPoint)anchorPointForTabSwitcherButton:(BubbleArrowDirection)direction { - (CGPoint)anchorPointForTabSwitcherButton:(BubbleArrowDirection)direction {
CGPoint anchorPoint = CGPoint anchorPoint =
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_VIEW_H_ #ifndef IOS_CHROME_BROWSER_UI_TOOLBAR_LEGACY_TOOLBAR_VIEW_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_VIEW_H_ #define IOS_CHROME_BROWSER_UI_TOOLBAR_LEGACY_TOOLBAR_VIEW_H_
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
@protocol ToolbarViewDelegate; @protocol ToolbarViewDelegate;
@interface ToolbarView : UIView<RelaxedBoundsConstraintsHitTestSupport> @interface LegacyToolbarView : UIView<RelaxedBoundsConstraintsHitTestSupport>
- (instancetype)initWithNibName:(NSString*)name - (instancetype)initWithNibName:(NSString*)name
bundle:(NSBundle*)bundle NS_UNAVAILABLE; bundle:(NSBundle*)bundle NS_UNAVAILABLE;
- (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE; - (instancetype)initWithCoder:(NSCoder*)coder NS_UNAVAILABLE;
...@@ -25,4 +25,4 @@ ...@@ -25,4 +25,4 @@
@end @end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_VIEW_H_ #endif // IOS_CHROME_BROWSER_UI_TOOLBAR_LEGACY_TOOLBAR_VIEW_H_
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/toolbar/toolbar_view.h" #import "ios/chrome/browser/ui/toolbar/legacy_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_view_delegate.h" #import "ios/chrome/browser/ui/toolbar/toolbar_view_delegate.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
@implementation ToolbarView @implementation LegacyToolbarView
@synthesize delegate = delegate_; @synthesize delegate = delegate_;
@synthesize animatingTransition = animatingTransition_; @synthesize animatingTransition = animatingTransition_;
......
...@@ -10,9 +10,9 @@ ...@@ -10,9 +10,9 @@
#import "base/mac/scoped_nsobject.h" #import "base/mac/scoped_nsobject.h"
#import "ios/chrome/browser/ui/activity_services/requirements/activity_service_positioner.h" #import "ios/chrome/browser/ui/activity_services/requirements/activity_service_positioner.h"
#import "ios/chrome/browser/ui/bubble/bubble_view_anchor_point_provider.h" #import "ios/chrome/browser/ui/bubble/bubble_view_anchor_point_provider.h"
#import "ios/chrome/browser/ui/toolbar/legacy_toolbar_view.h"
#import "ios/chrome/browser/ui/toolbar/public/abstract_toolbar.h" #import "ios/chrome/browser/ui/toolbar/public/abstract_toolbar.h"
#import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.h" #import "ios/chrome/browser/ui/toolbar/public/toolbar_controller_constants.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_view.h"
#import "ios/chrome/browser/ui/tools_menu/public/tools_menu_presentation_provider.h" #import "ios/chrome/browser/ui/tools_menu/public/tools_menu_presentation_provider.h"
#import "ios/chrome/browser/ui/tools_menu/public/tools_menu_presentation_state_provider.h" #import "ios/chrome/browser/ui/tools_menu/public/tools_menu_presentation_state_provider.h"
...@@ -31,7 +31,7 @@ class ReadingListModel; ...@@ -31,7 +31,7 @@ class ReadingListModel;
ToolsMenuPresentationProvider> ToolsMenuPresentationProvider>
// The top-level toolbar view. // The top-level toolbar view.
@property(nonatomic, strong) ToolbarView* view; @property(nonatomic, strong) LegacyToolbarView* view;
// The view for the toolbar shadow image. This is a subview of |view| to // The view for the toolbar shadow image. This is a subview of |view| to
// allow clients to alter the visibility of the shadow without affecting other // allow clients to alter the visibility of the shadow without affecting other
// components of the toolbar. // components of the toolbar.
......
...@@ -147,7 +147,7 @@ using ios::material::TimingFunction; ...@@ -147,7 +147,7 @@ using ios::material::TimingFunction;
toolsMenuButtonFrame.origin.y += statusBarOffset; toolsMenuButtonFrame.origin.y += statusBarOffset;
} }
self.view = [[ToolbarView alloc] initWithFrame:viewFrame]; self.view = [[LegacyToolbarView alloc] initWithFrame:viewFrame];
if (IsSafeAreaCompatibleToolbarEnabled()) { if (IsSafeAreaCompatibleToolbarEnabled()) {
[self.view setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.view setTranslatesAutoresizingMaskIntoConstraints:NO];
} }
......
...@@ -193,10 +193,10 @@ void SelectNewTabPagePanel(ntp_home::PanelIdentifier panel_type) { ...@@ -193,10 +193,10 @@ void SelectNewTabPagePanel(ntp_home::PanelIdentifier panel_type) {
chrome_test_util::ButtonWithAccessibilityLabelId(IDS_IOS_ACCNAME_RELOAD); chrome_test_util::ButtonWithAccessibilityLabelId(IDS_IOS_ACCNAME_RELOAD);
id<GREYMatcher> bookmarkButton = id<GREYMatcher> bookmarkButton =
chrome_test_util::ButtonWithAccessibilityLabelId(IDS_TOOLTIP_STAR); chrome_test_util::ButtonWithAccessibilityLabelId(IDS_TOOLTIP_STAR);
id<GREYMatcher> voiceSearchButton = id<GREYMatcher> voiceSearchButton = grey_allOf(
grey_allOf(chrome_test_util::ButtonWithAccessibilityLabelId( chrome_test_util::ButtonWithAccessibilityLabelId(
IDS_IOS_ACCNAME_VOICE_SEARCH), IDS_IOS_ACCNAME_VOICE_SEARCH),
grey_ancestor(grey_kindOfClass([ToolbarView class])), nil); grey_ancestor(grey_kindOfClass([LegacyToolbarView class])), nil);
NSString* ntpOmniboxLabel = l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT); NSString* ntpOmniboxLabel = l10n_util::GetNSString(IDS_OMNIBOX_EMPTY_HINT);
NSString* focusedOmniboxLabel = l10n_util::GetNSString(IDS_ACCNAME_LOCATION); NSString* focusedOmniboxLabel = l10n_util::GetNSString(IDS_ACCNAME_LOCATION);
NSString* omniboxLabel = NSString* omniboxLabel =
......
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