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 @@
- (ToolbarButton*)bookmarkToolbarButton;
// VoiceSearch ToolbarButton.
- (ToolbarButton*)voiceSearchButton;
// ContractToolbar ToolbarButton.
- (ToolbarButton*)contractToolbarButton;
// Returns images for Voice Search in an array representing the NORMAL/PRESSED
// state
......
......@@ -49,6 +49,8 @@ const int styleCount = 2;
return self;
}
#pragma mark - Buttons
- (ToolbarButton*)backToolbarButton {
int backButtonImages[styleCount][TOOLBAR_STATE_COUNT] =
TOOLBAR_IDR_THREE_STATE(BACK);
......@@ -223,6 +225,21 @@ const int styleCount = 2;
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 {
// The voice search images can be overridden by the branded image provider.
int imageID;
......
......@@ -20,6 +20,7 @@ extern const CGFloat kIncognitoToolbarBackgroundColor;
extern const CGFloat kVerticalMargin;
extern const CGFloat kHorizontalMargin;
extern const CGFloat kStackViewSpacing;
extern const CGFloat kTrailingMargin;
// Location bar styling.
extern const CGFloat kLocationBarBorderWidth;
......
......@@ -14,6 +14,7 @@ const CGFloat kIncognitoToolbarBackgroundColor = 0x505050;
const CGFloat kVerticalMargin = 7.0f;
const CGFloat kHorizontalMargin = 1.0f;
const CGFloat kStackViewSpacing = 2.0f;
const CGFloat kTrailingMargin = 10.0f;
const CGFloat kLocationBarBorderWidth = 1.0f;
const CGFloat kLocationBarBorderColor = 0xD0D0D0;
......
......@@ -42,6 +42,7 @@
@property(nonatomic, strong) ToolbarButton* stopButton;
@property(nonatomic, strong) ToolbarButton* voiceSearchButton;
@property(nonatomic, strong) ToolbarButton* bookmarkButton;
@property(nonatomic, strong) ToolbarButton* contractButton;
@property(nonatomic, assign) BOOL voiceSearchEnabled;
@property(nonatomic, strong) MDCProgressView* progressBar;
// Background view, used to display the incognito NTP background color on the
......@@ -49,7 +50,9 @@
@property(nonatomic, strong) UIView* backgroundView;
// Whether a page is 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;
// 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.
......@@ -78,6 +81,7 @@
@synthesize stopButton = _stopButton;
@synthesize voiceSearchButton = _voiceSearchButton;
@synthesize bookmarkButton = _bookmarkButton;
@synthesize contractButton = _contractButton;
@synthesize voiceSearchEnabled = _voiceSearchEnabled;
@synthesize progressBar = _progressBar;
@synthesize expandedToolbarConstraints = _expandedToolbarConstraints;
......@@ -118,18 +122,26 @@
}
- (void)addToolbarExpansionAnimations:(UIViewPropertyAnimator*)animator {
// iPad should never try to animate.
DCHECK(!IsIPadIdiom());
[NSLayoutConstraint deactivateConstraints:self.regularToolbarConstraints];
[NSLayoutConstraint activateConstraints:self.expandedToolbarConstraints];
[animator addAnimations:^{
[self.view layoutIfNeeded];
self.contractButton.hidden = NO;
self.contractButton.alpha = 1;
}];
}
- (void)addToolbarContractionAnimations:(UIViewPropertyAnimator*)animator {
// iPad should never try to animate.
DCHECK(!IsIPadIdiom());
[NSLayoutConstraint deactivateConstraints:self.expandedToolbarConstraints];
[NSLayoutConstraint activateConstraints:self.regularToolbarConstraints];
[animator addAnimations:^{
[self.view layoutIfNeeded];
self.contractButton.hidden = YES;
self.contractButton.alpha = 0;
}];
}
......@@ -172,26 +184,7 @@
[self.buttonFactory.toolbarConfiguration backgroundColor];
[self setUpToolbarStackView];
if (self.locationBarView) {
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 setUpToolbarContainerView];
[self.view addSubview:self.stackView];
[self.view addSubview:self.progressBar];
[self setConstraints];
......@@ -216,12 +209,51 @@
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 {
self.view.translatesAutoresizingMaskIntoConstraints = NO;
[self.view.bottomAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kToolbarHeight]
.active = YES;
// ProgressBar constraints.
NSArray* progressBarConstraints = @[
[self.progressBar.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
......@@ -234,7 +266,8 @@
];
[NSLayoutConstraint activateConstraints:progressBarConstraints];
NSArray* constraints = @[
// StackView constraints.
NSArray* stackViewConstraints = @[
[self.stackView.heightAnchor
constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin],
[self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
......@@ -245,17 +278,38 @@
[self.stackView.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor
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];
[NSLayoutConstraint activateConstraints:constraints];
[self.regularToolbarConstraints addObjectsFromArray:stackViewConstraints];
[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
......@@ -370,6 +424,16 @@
action:@selector(bookmarkPage)
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.
self.buttonUpdater.backButton = self.backButton;
self.buttonUpdater.forwardButton = self.forwardButton;
......@@ -612,6 +676,12 @@
constraintEqualToAnchor:self.view.trailingAnchor],
[self.locationBarView.topAnchor constraintEqualToAnchor:self.topSafeAnchor
constant:kVerticalMargin],
[self.locationBarView.trailingAnchor
constraintEqualToAnchor:self.contractButton.leadingAnchor
constant:-kTrailingMargin],
[self.contractButton.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor
constant:-kTrailingMargin],
];
}
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