Commit 840196a1 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Creates contract CleanToolbar button.

Adds a Toolbar Button that will be used to contract the toolbar/omnibox.
The contract button is only shown when the Toolbar is expanded. A simple animation is used.
Currently the button has no functionality, that will be added in a follow up CL.

Screenshot:
https://drive.google.com/open?id=1UIiS-Y1JTKwuU7lrQACtDK8RL1g10_7K

Bug: 790763
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Icf2d7e3b866c2f87f7346556f41328ba19044bfd
Reviewed-on: https://chromium-review.googlesource.com/802831
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521015}
parent d6cfe11e
...@@ -46,6 +46,8 @@ ...@@ -46,6 +46,8 @@
- (ToolbarButton*)bookmarkToolbarButton; - (ToolbarButton*)bookmarkToolbarButton;
// VoiceSearch ToolbarButton. // VoiceSearch ToolbarButton.
- (ToolbarButton*)voiceSearchButton; - (ToolbarButton*)voiceSearchButton;
// ContractToolbar ToolbarButton.
- (ToolbarButton*)contractToolbarButton;
// Returns images for Voice Search in an array representing the NORMAL/PRESSED // Returns images for Voice Search in an array representing the NORMAL/PRESSED
// state // state
......
...@@ -49,6 +49,8 @@ const int styleCount = 2; ...@@ -49,6 +49,8 @@ const int styleCount = 2;
return self; return self;
} }
#pragma mark - Buttons
- (ToolbarButton*)backToolbarButton { - (ToolbarButton*)backToolbarButton {
int backButtonImages[styleCount][TOOLBAR_STATE_COUNT] = int backButtonImages[styleCount][TOOLBAR_STATE_COUNT] =
TOOLBAR_IDR_THREE_STATE(BACK); TOOLBAR_IDR_THREE_STATE(BACK);
...@@ -223,6 +225,21 @@ const int styleCount = 2; ...@@ -223,6 +225,21 @@ const int styleCount = 2;
return voiceSearchButton; return voiceSearchButton;
} }
- (ToolbarButton*)contractToolbarButton {
NSString* collapseName = _style ? @"collapse_incognito" : @"collapse";
NSString* collapsePressedName =
_style ? @"collapse_pressed_incognito" : @"collapse_pressed";
ToolbarButton* contractToolbarButton = [ToolbarButton
toolbarButtonWithImageForNormalState:[UIImage imageNamed:collapseName]
imageForHighlightedState:[UIImage
imageNamed:collapsePressedName]
imageForDisabledState:nil];
contractToolbarButton.accessibilityLabel = l10n_util::GetNSString(IDS_CANCEL);
return contractToolbarButton;
}
#pragma mark - Helpers
- (NSArray<UIImage*>*)voiceSearchImages { - (NSArray<UIImage*>*)voiceSearchImages {
// The voice search images can be overridden by the branded image provider. // The voice search images can be overridden by the branded image provider.
int imageID; int imageID;
......
...@@ -20,6 +20,7 @@ extern const CGFloat kIncognitoToolbarBackgroundColor; ...@@ -20,6 +20,7 @@ extern const CGFloat kIncognitoToolbarBackgroundColor;
extern const CGFloat kVerticalMargin; extern const CGFloat kVerticalMargin;
extern const CGFloat kHorizontalMargin; extern const CGFloat kHorizontalMargin;
extern const CGFloat kStackViewSpacing; extern const CGFloat kStackViewSpacing;
extern const CGFloat kTrailingMargin;
// Location bar styling. // Location bar styling.
extern const CGFloat kLocationBarBorderWidth; extern const CGFloat kLocationBarBorderWidth;
......
...@@ -14,6 +14,7 @@ const CGFloat kIncognitoToolbarBackgroundColor = 0x505050; ...@@ -14,6 +14,7 @@ const CGFloat kIncognitoToolbarBackgroundColor = 0x505050;
const CGFloat kVerticalMargin = 7.0f; const CGFloat kVerticalMargin = 7.0f;
const CGFloat kHorizontalMargin = 1.0f; const CGFloat kHorizontalMargin = 1.0f;
const CGFloat kStackViewSpacing = 2.0f; const CGFloat kStackViewSpacing = 2.0f;
const CGFloat kTrailingMargin = 10.0f;
const CGFloat kLocationBarBorderWidth = 1.0f; const CGFloat kLocationBarBorderWidth = 1.0f;
const CGFloat kLocationBarBorderColor = 0xD0D0D0; const CGFloat kLocationBarBorderColor = 0xD0D0D0;
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
@property(nonatomic, strong) ToolbarButton* stopButton; @property(nonatomic, strong) ToolbarButton* stopButton;
@property(nonatomic, strong) ToolbarButton* voiceSearchButton; @property(nonatomic, strong) ToolbarButton* voiceSearchButton;
@property(nonatomic, strong) ToolbarButton* bookmarkButton; @property(nonatomic, strong) ToolbarButton* bookmarkButton;
@property(nonatomic, strong) ToolbarButton* contractButton;
@property(nonatomic, assign) BOOL voiceSearchEnabled; @property(nonatomic, assign) BOOL voiceSearchEnabled;
@property(nonatomic, strong) MDCProgressView* progressBar; @property(nonatomic, strong) MDCProgressView* progressBar;
// Background view, used to display the incognito NTP background color on the // Background view, used to display the incognito NTP background color on the
...@@ -49,7 +50,9 @@ ...@@ -49,7 +50,9 @@
@property(nonatomic, strong) UIView* backgroundView; @property(nonatomic, strong) UIView* backgroundView;
// Whether a page is loading. // Whether a page is loading.
@property(nonatomic, assign, getter=isLoading) BOOL loading; @property(nonatomic, assign, getter=isLoading) BOOL loading;
// Constraints used for the regular/contracted Toolbar state. // Constraints used for the regular/contracted Toolbar state that will be
// deactivated and replaced by |_expandedToolbarConstraints| when animating the
// toolbar expansion.
@property(nonatomic, strong) NSMutableArray* regularToolbarConstraints; @property(nonatomic, strong) NSMutableArray* regularToolbarConstraints;
// Constraints used to layout the Toolbar to its expanded state. If these are // Constraints used to layout the Toolbar to its expanded state. If these are
// active the locationBarContainer will expand to the size of this VC's view. // active the locationBarContainer will expand to the size of this VC's view.
...@@ -78,6 +81,7 @@ ...@@ -78,6 +81,7 @@
@synthesize stopButton = _stopButton; @synthesize stopButton = _stopButton;
@synthesize voiceSearchButton = _voiceSearchButton; @synthesize voiceSearchButton = _voiceSearchButton;
@synthesize bookmarkButton = _bookmarkButton; @synthesize bookmarkButton = _bookmarkButton;
@synthesize contractButton = _contractButton;
@synthesize voiceSearchEnabled = _voiceSearchEnabled; @synthesize voiceSearchEnabled = _voiceSearchEnabled;
@synthesize progressBar = _progressBar; @synthesize progressBar = _progressBar;
@synthesize expandedToolbarConstraints = _expandedToolbarConstraints; @synthesize expandedToolbarConstraints = _expandedToolbarConstraints;
...@@ -118,18 +122,26 @@ ...@@ -118,18 +122,26 @@
} }
- (void)addToolbarExpansionAnimations:(UIViewPropertyAnimator*)animator { - (void)addToolbarExpansionAnimations:(UIViewPropertyAnimator*)animator {
// iPad should never try to animate.
DCHECK(!IsIPadIdiom());
[NSLayoutConstraint deactivateConstraints:self.regularToolbarConstraints]; [NSLayoutConstraint deactivateConstraints:self.regularToolbarConstraints];
[NSLayoutConstraint activateConstraints:self.expandedToolbarConstraints]; [NSLayoutConstraint activateConstraints:self.expandedToolbarConstraints];
[animator addAnimations:^{ [animator addAnimations:^{
[self.view layoutIfNeeded]; [self.view layoutIfNeeded];
self.contractButton.hidden = NO;
self.contractButton.alpha = 1;
}]; }];
} }
- (void)addToolbarContractionAnimations:(UIViewPropertyAnimator*)animator { - (void)addToolbarContractionAnimations:(UIViewPropertyAnimator*)animator {
// iPad should never try to animate.
DCHECK(!IsIPadIdiom());
[NSLayoutConstraint deactivateConstraints:self.expandedToolbarConstraints]; [NSLayoutConstraint deactivateConstraints:self.expandedToolbarConstraints];
[NSLayoutConstraint activateConstraints:self.regularToolbarConstraints]; [NSLayoutConstraint activateConstraints:self.regularToolbarConstraints];
[animator addAnimations:^{ [animator addAnimations:^{
[self.view layoutIfNeeded]; [self.view layoutIfNeeded];
self.contractButton.hidden = YES;
self.contractButton.alpha = 0;
}]; }];
} }
...@@ -172,26 +184,7 @@ ...@@ -172,26 +184,7 @@
[self.buttonFactory.toolbarConfiguration backgroundColor]; [self.buttonFactory.toolbarConfiguration backgroundColor];
[self setUpToolbarStackView]; [self setUpToolbarStackView];
if (self.locationBarView) { [self setUpToolbarContainerView];
NSLayoutConstraint* locationBarTopAnchorConstraint =
[self.locationBarView.topAnchor
constraintEqualToAnchor:self.locationBarContainer.topAnchor];
[self.locationBarContainer addSubview:self.locationBarView];
NSArray* locationBarViewConstraints = @[
[self.locationBarView.leadingAnchor
constraintEqualToAnchor:self.locationBarContainer.leadingAnchor],
[self.locationBarView.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
[self.locationBarView.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
locationBarTopAnchorConstraint,
];
// Adds
[self.regularToolbarConstraints addObject:locationBarTopAnchorConstraint];
[NSLayoutConstraint activateConstraints:locationBarViewConstraints];
}
[self.locationBarContainer addSubview:self.bookmarkButton];
[self.locationBarContainer addSubview:self.voiceSearchButton];
[self.view addSubview:self.stackView]; [self.view addSubview:self.stackView];
[self.view addSubview:self.progressBar]; [self.view addSubview:self.progressBar];
[self setConstraints]; [self setConstraints];
...@@ -216,12 +209,51 @@ ...@@ -216,12 +209,51 @@
self.stackView.distribution = UIStackViewDistributionFill; self.stackView.distribution = UIStackViewDistributionFill;
} }
// Sets up the LocationContainerView. This contains the locationBarView, and
// other buttons like Voice Search, Bookmarks and Contract Toolbar.
- (void)setUpToolbarContainerView {
if (self.locationBarView) {
[self.locationBarContainer addSubview:self.locationBarView];
// Bookmarks and Voice Search buttons will only be part of the Toolbar on
// iPad. On the other hand the contract button is only needed on non iPad
// devices, since iPad doesn't animate, thus it doesn't need to contract.
if (IsIPadIdiom()) {
[self.locationBarContainer addSubview:self.bookmarkButton];
[self.locationBarContainer addSubview:self.voiceSearchButton];
} else {
[self.locationBarContainer addSubview:self.contractButton];
}
// LocationBarView constraints.
NSLayoutConstraint* locationBarViewTrailingConstraint =
[self.locationBarView.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor];
NSLayoutConstraint* locationBarViewTopConstraint =
[self.locationBarView.topAnchor
constraintEqualToAnchor:self.locationBarContainer.topAnchor];
[self.regularToolbarConstraints addObjectsFromArray:@[
locationBarViewTopConstraint, locationBarViewTrailingConstraint
]];
NSArray* locationBarViewConstraints = @[
[self.locationBarView.leadingAnchor
constraintEqualToAnchor:self.locationBarContainer.leadingAnchor],
[self.locationBarView.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
locationBarViewTrailingConstraint,
locationBarViewTopConstraint,
];
[NSLayoutConstraint activateConstraints:locationBarViewConstraints];
}
}
- (void)setConstraints { - (void)setConstraints {
self.view.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view.bottomAnchor constraintEqualToAnchor:self.topSafeAnchor [self.view.bottomAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kToolbarHeight] constant:kToolbarHeight]
.active = YES; .active = YES;
// ProgressBar constraints.
NSArray* progressBarConstraints = @[ NSArray* progressBarConstraints = @[
[self.progressBar.leadingAnchor [self.progressBar.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor], constraintEqualToAnchor:self.view.leadingAnchor],
...@@ -234,7 +266,8 @@ ...@@ -234,7 +266,8 @@
]; ];
[NSLayoutConstraint activateConstraints:progressBarConstraints]; [NSLayoutConstraint activateConstraints:progressBarConstraints];
NSArray* constraints = @[ // StackView constraints.
NSArray* stackViewConstraints = @[
[self.stackView.heightAnchor [self.stackView.heightAnchor
constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin], constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin],
[self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
...@@ -245,17 +278,38 @@ ...@@ -245,17 +278,38 @@
[self.stackView.trailingAnchor [self.stackView.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor
constant:-kHorizontalMargin], constant:-kHorizontalMargin],
[self.bookmarkButton.centerYAnchor
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor],
[self.voiceSearchButton.centerYAnchor
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor],
[self.voiceSearchButton.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
[self.bookmarkButton.trailingAnchor
constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor],
]; ];
[self.regularToolbarConstraints addObjectsFromArray:constraints]; [self.regularToolbarConstraints addObjectsFromArray:stackViewConstraints];
[NSLayoutConstraint activateConstraints:constraints]; [NSLayoutConstraint activateConstraints:stackViewConstraints];
// LocationBarContainer Buttons constraints.
NSArray* locationBarButtonConstraints;
if (IsIPadIdiom()) {
locationBarButtonConstraints = @[
[self.bookmarkButton.centerYAnchor
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor],
[self.voiceSearchButton.centerYAnchor
constraintEqualToAnchor:self.locationBarContainer.centerYAnchor],
[self.voiceSearchButton.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
[self.bookmarkButton.trailingAnchor
constraintEqualToAnchor:self.voiceSearchButton.leadingAnchor],
];
} else {
NSLayoutConstraint* contractButtonTrailingConstraint =
[self.contractButton.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor
constant:-2 * kTrailingMargin];
[self.regularToolbarConstraints addObject:contractButtonTrailingConstraint];
locationBarButtonConstraints = @[
[self.contractButton.topAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kVerticalMargin],
[self.contractButton.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
contractButtonTrailingConstraint,
];
}
[NSLayoutConstraint activateConstraints:locationBarButtonConstraints];
} }
#pragma mark - Components Setup #pragma mark - Components Setup
...@@ -370,6 +424,16 @@ ...@@ -370,6 +424,16 @@
action:@selector(bookmarkPage) action:@selector(bookmarkPage)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
// Contract button.
self.contractButton = [self.buttonFactory contractToolbarButton];
self.contractButton.visibilityMask = ToolbarComponentVisibilityCompactWidth |
ToolbarComponentVisibilityRegularWidth;
self.contractButton.alpha = 0;
self.contractButton.hidden = YES;
[buttonConstraints
addObject:[self.contractButton.widthAnchor
constraintEqualToConstant:kToolbarButtonWidth]];
// Add buttons to button updater. // Add buttons to button updater.
self.buttonUpdater.backButton = self.backButton; self.buttonUpdater.backButton = self.backButton;
self.buttonUpdater.forwardButton = self.forwardButton; self.buttonUpdater.forwardButton = self.forwardButton;
...@@ -612,6 +676,12 @@ ...@@ -612,6 +676,12 @@
constraintEqualToAnchor:self.view.trailingAnchor], constraintEqualToAnchor:self.view.trailingAnchor],
[self.locationBarView.topAnchor constraintEqualToAnchor:self.topSafeAnchor [self.locationBarView.topAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kVerticalMargin], constant:kVerticalMargin],
[self.locationBarView.trailingAnchor
constraintEqualToAnchor:self.contractButton.leadingAnchor
constant:-kTrailingMargin],
[self.contractButton.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor
constant:-kTrailingMargin],
]; ];
} }
return _expandedToolbarConstraints; return _expandedToolbarConstraints;
......
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