Commit 5fbf4234 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Change the toolbar to use two stack views

Having two stack views allow the animation to be focused on the location
bar instead of having side effects on the buttons on the side.
It also makes sure the toolbar is respecting the Safe Area on iPhone X
landscape.

Bug: 791933, 791944
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib6f0b3560c825cdfe67f5aca648ee0a2b96044a0
Reviewed-on: https://chromium-review.googlesource.com/807930
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#521742}
parent faacc850
......@@ -32,8 +32,16 @@
@interface ToolbarViewController ()
@property(nonatomic, strong) ToolbarButtonFactory* buttonFactory;
@property(nonatomic, strong) ToolbarButtonUpdater* buttonUpdater;
// The main objects in the view. Positionned as
// [leadingStackView][locationBarContainer][trailingStackView]. The stack views
// contain the buttons which should be shown on each sides of the location bar.
@property(nonatomic, strong) UIStackView* leadingStackView;
@property(nonatomic, strong) UIView* locationBarContainer;
@property(nonatomic, strong) UIStackView* stackView;
@property(nonatomic, strong) UIStackView* trailingStackView;
// Array containing all the toolbar buttons, lazily instantiated.
@property(nonatomic, strong) NSArray<ToolbarButton*>* allButtons;
@property(nonatomic, strong) ToolbarButton* backButton;
@property(nonatomic, strong) ToolbarButton* forwardButton;
@property(nonatomic, strong) ToolbarButton* tabSwitchStripButton;
......@@ -68,13 +76,15 @@
@end
@implementation ToolbarViewController
@synthesize allButtons = _allButtons;
@synthesize backgroundView = _backgroundView;
@synthesize buttonFactory = _buttonFactory;
@synthesize buttonUpdater = _buttonUpdater;
@synthesize dispatcher = _dispatcher;
@synthesize expanded = _expanded;
@synthesize locationBarView = _locationBarView;
@synthesize stackView = _stackView;
@synthesize leadingStackView = _leadingStackView;
@synthesize trailingStackView = _trailingStackView;
@synthesize loading = _loading;
@synthesize locationBarContainer = _locationBarContainer;
@synthesize backButton = _backButton;
......@@ -180,7 +190,9 @@
[self setUpToolbarStackView];
[self setUpLocationBarContainerView];
[self.view addSubview:self.stackView];
[self.view addSubview:self.leadingStackView];
[self.view addSubview:self.locationBarContainer];
[self.view addSubview:self.trailingStackView];
[self.view addSubview:self.shadowView];
[self.view addSubview:self.progressBar];
[self setConstraints];
......@@ -195,14 +207,19 @@
// Sets up the StackView that contains toolbar navigation items.
- (void)setUpToolbarStackView {
self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.backButton, self.forwardButton, self.reloadButton, self.stopButton,
self.locationBarContainer, self.shareButton, self.tabSwitchStripButton,
self.toolsMenuButton
self.leadingStackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.backButton, self.forwardButton, self.reloadButton, self.stopButton
]];
self.stackView.translatesAutoresizingMaskIntoConstraints = NO;
self.stackView.spacing = kStackViewSpacing;
self.stackView.distribution = UIStackViewDistributionFill;
self.leadingStackView.translatesAutoresizingMaskIntoConstraints = NO;
self.leadingStackView.spacing = kStackViewSpacing;
self.leadingStackView.distribution = UIStackViewDistributionFill;
self.trailingStackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.shareButton, self.tabSwitchStripButton, self.toolsMenuButton
]];
self.trailingStackView.translatesAutoresizingMaskIntoConstraints = NO;
self.trailingStackView.spacing = kStackViewSpacing;
self.trailingStackView.distribution = UIStackViewDistributionFill;
}
// Sets up the LocationContainerView. Which contains a StackView containing the
......@@ -235,7 +252,7 @@
.active = YES;
// ProgressBar constraints.
NSArray* progressBarConstraints = @[
[NSLayoutConstraint activateConstraints:@[
[self.progressBar.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor],
[self.progressBar.trailingAnchor
......@@ -244,8 +261,7 @@
constraintEqualToAnchor:self.view.bottomAnchor],
[self.progressBar.heightAnchor
constraintEqualToConstant:kProgressBarHeight],
];
[NSLayoutConstraint activateConstraints:progressBarConstraints];
]];
// Shadow constraints.
[NSLayoutConstraint activateConstraints:@[
......@@ -258,39 +274,68 @@
constraintEqualToConstant:kToolbarShadowHeight],
]];
// StackView constraints. The main Toolbar StackView.
NSArray* stackViewConstraints = @[
[self.stackView.heightAnchor
constraintEqualToConstant:kToolbarHeight - 2 * kVerticalMargin],
[self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
constant:-kVerticalMargin],
[self.stackView.leadingAnchor
constraintEqualToAnchor:self.view.leadingAnchor
// Stack views directly in view constraints. Main StackViews.
// Layout: |-[leadingStackView]-[locationBarContainer]-[trailingStackView]-|.
UILayoutGuide* viewSafeAreaGuide = SafeAreaLayoutGuideForView(self.view);
NSArray* stackViewRegularConstraints = @[
[self.leadingStackView.leadingAnchor
constraintEqualToAnchor:viewSafeAreaGuide.leadingAnchor
constant:kHorizontalMargin],
[self.stackView.trailingAnchor
constraintEqualToAnchor:self.view.trailingAnchor
constant:-kHorizontalMargin],
[self.trailingStackView.trailingAnchor
constraintEqualToAnchor:viewSafeAreaGuide.trailingAnchor
constant:-kHorizontalMargin]
];
[self.regularToolbarConstraints
addObjectsFromArray:stackViewRegularConstraints];
[NSLayoutConstraint activateConstraints:stackViewRegularConstraints];
ApplyVisualConstraintsWithMetrics(
@[
@"H:[leadingStack]-(spacing)-[locationBar]-(spacing)-[trailingStack]",
@"V:[leadingStack(height)]-(margin)-|",
@"V:[trailingStack(height)]-(margin)-|"
],
@{
@"leadingStack" : self.leadingStackView,
@"locationBar" : self.locationBarContainer,
@"trailingStack" : self.trailingStackView
},
@{
@"height" : @(kToolbarHeight - 2 * kVerticalMargin),
@"margin" : @(kVerticalMargin),
@"spacing" : @(kStackViewSpacing)
});
// LocationBarContainer constraints.
NSArray* locationBarRegularConstraints = @[
[self.locationBarContainer.bottomAnchor
constraintEqualToAnchor:self.leadingStackView.bottomAnchor],
[self.locationBarContainer.topAnchor
constraintEqualToAnchor:self.leadingStackView.topAnchor]
];
[self.regularToolbarConstraints addObjectsFromArray:stackViewConstraints];
[NSLayoutConstraint activateConstraints:stackViewConstraints];
[self.regularToolbarConstraints
addObjectsFromArray:locationBarRegularConstraints];
[NSLayoutConstraint activateConstraints:locationBarRegularConstraints];
// LocationBarStackView constraints. The StackView inside the
// LocationBarContainer View.
UILayoutGuide* locationBarContainerSafeAreaGuide =
SafeAreaLayoutGuideForView(self.locationBarContainer);
NSLayoutConstraint* locationBarContainerStackViewTopConstraint =
[self.locationBarContainerStackView.topAnchor
constraintEqualToAnchor:self.locationBarContainer.topAnchor];
NSArray* locationBarViewStackViewConstraints = @[
[NSLayoutConstraint activateConstraints:@[
[self.locationBarContainerStackView.bottomAnchor
constraintEqualToAnchor:self.locationBarContainer.bottomAnchor],
[self.locationBarContainerStackView.leadingAnchor
constraintEqualToAnchor:self.locationBarContainer.leadingAnchor],
constraintEqualToAnchor:locationBarContainerSafeAreaGuide
.leadingAnchor],
[self.locationBarContainerStackView.trailingAnchor
constraintEqualToAnchor:self.locationBarContainer.trailingAnchor],
constraintEqualToAnchor:locationBarContainerSafeAreaGuide
.trailingAnchor],
locationBarContainerStackViewTopConstraint,
];
]];
[self.regularToolbarConstraints
addObject:locationBarContainerStackViewTopConstraint];
[NSLayoutConstraint activateConstraints:locationBarViewStackViewConstraints];
}
#pragma mark - Components Setup
......@@ -602,18 +647,24 @@
// Updates all Buttons visibility to match any recent WebState change.
- (void)updateAllButtonsVisibility {
for (UIView* view in self.stackView.arrangedSubviews) {
if ([view isKindOfClass:[ToolbarButton class]]) {
ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
[button updateHiddenInCurrentSizeClass];
}
for (ToolbarButton* button in self.allButtons) {
[button updateHiddenInCurrentSizeClass];
}
[self.bookmarkButton updateHiddenInCurrentSizeClass];
[self.voiceSearchButton updateHiddenInCurrentSizeClass];
}
#pragma mark - Setters & Getters.
- (NSArray<ToolbarButton*>*)allButtons {
if (!_allButtons) {
_allButtons = [NSArray
arrayWithObjects:self.backButton, self.forwardButton, self.reloadButton,
self.stopButton, self.shareButton,
self.tabSwitchStripButton, self.toolsMenuButton,
self.bookmarkButton, self.voiceSearchButton, nil];
}
return _allButtons;
}
- (UIView*)backgroundView {
if (!_backgroundView) {
_backgroundView = [[UIView alloc] initWithFrame:CGRectZero];
......
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