Commit 776ec84b authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Adjust toolbar height in fullscreen

This CL adjusts the toolbar height in fullscreen.
It also adjusts the vertical position of the location bar, in fullscreen
and outside of fullscreen. This is needed to have something which looks
visually balanced.

Bug: 868901, 865820
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ib8da381737b4660554a5fb68a213b99860f117d0
Reviewed-on: https://chromium-review.googlesource.com/1156602
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579793}
parent f57e8226
...@@ -63,6 +63,11 @@ ...@@ -63,6 +63,11 @@
// Constraint for the bottom of the location bar. // Constraint for the bottom of the location bar.
@property(nonatomic, strong, readwrite) @property(nonatomic, strong, readwrite)
NSLayoutConstraint* locationBarBottomConstraint; NSLayoutConstraint* locationBarBottomConstraint;
// Constraint for extra padding on the bottom of the location bar. This padding
// is considered as "extra" as it is added to the one defined in
// |locationBarBottomConstraint|. See comment for -[PrimaryToolbarViewController
// verticalMarginForLocationBarForFullscreenProgress:] for more explanations.
@property(nonatomic, strong) NSLayoutConstraint* locationBarExtraBottomPadding;
// Sets all the subviews and constraints of the view. The |topSafeAnchor| needs // Sets all the subviews and constraints of the view. The |topSafeAnchor| needs
// to be set before calling this. // to be set before calling this.
......
...@@ -35,6 +35,10 @@ ...@@ -35,6 +35,10 @@
@property(nonatomic, strong, readwrite) UIView* locationBarContainer; @property(nonatomic, strong, readwrite) UIView* locationBarContainer;
// The height of the container for the location bar, redefined as readwrite. // The height of the container for the location bar, redefined as readwrite.
@property(nonatomic, strong, readwrite) NSLayoutConstraint* locationBarHeight; @property(nonatomic, strong, readwrite) NSLayoutConstraint* locationBarHeight;
// The layout guide used to give extra padding at the bottom for the location
// bar. This padding is considered as "extra" as it is added to the one defined
// in |locationBarBottomConstraint|.
@property(nonatomic, strong) UILayoutGuide* extraPaddingGuide;
// StackView containing the leading buttons (relative to the location bar). It // StackView containing the leading buttons (relative to the location bar). It
// should only contain ToolbarButtons. Redefined as readwrite. // should only contain ToolbarButtons. Redefined as readwrite.
...@@ -88,7 +92,9 @@ ...@@ -88,7 +92,9 @@
@synthesize locationBarView = _locationBarView; @synthesize locationBarView = _locationBarView;
@synthesize fakeOmniboxTarget = _fakeOmniboxTarget; @synthesize fakeOmniboxTarget = _fakeOmniboxTarget;
@synthesize locationBarBottomConstraint = _locationBarBottomConstraint; @synthesize locationBarBottomConstraint = _locationBarBottomConstraint;
@synthesize locationBarExtraBottomPadding = _locationBarExtraBottomPadding;
@synthesize locationBarHeight = _locationBarHeight; @synthesize locationBarHeight = _locationBarHeight;
@synthesize extraPaddingGuide = _extraPaddingGuide;
@synthesize buttonFactory = _buttonFactory; @synthesize buttonFactory = _buttonFactory;
@synthesize allButtons = _allButtons; @synthesize allButtons = _allButtons;
@synthesize progressBar = _progressBar; @synthesize progressBar = _progressBar;
...@@ -224,6 +230,10 @@ ...@@ -224,6 +230,10 @@
// The location bar shouldn't have vibrancy. // The location bar shouldn't have vibrancy.
[self addSubview:self.locationBarContainer]; [self addSubview:self.locationBarContainer];
// Add layout guide to add extra padding for the location bar if needed.
self.extraPaddingGuide = [[UILayoutGuide alloc] init];
[self addLayoutGuide:self.extraPaddingGuide];
if (self.locationBarView) { if (self.locationBarView) {
[self.locationBarContainer addSubview:self.locationBarView]; [self.locationBarContainer addSubview:self.locationBarView];
} }
...@@ -317,11 +327,17 @@ ...@@ -317,11 +327,17 @@
constraintEqualToConstant:kAdaptiveToolbarHeight - constraintEqualToConstant:kAdaptiveToolbarHeight -
2 * kAdaptiveLocationBarVerticalMargin]; 2 * kAdaptiveLocationBarVerticalMargin];
self.locationBarBottomConstraint = [self.locationBarContainer.bottomAnchor self.locationBarBottomConstraint = [self.locationBarContainer.bottomAnchor
constraintEqualToAnchor:self.bottomAnchor constraintEqualToAnchor:self.extraPaddingGuide.topAnchor
constant:-kAdaptiveLocationBarVerticalMargin]; constant:-kAdaptiveLocationBarVerticalMargin];
self.locationBarExtraBottomPadding =
[self.extraPaddingGuide.heightAnchor constraintEqualToConstant:0];
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
self.locationBarBottomConstraint, self.locationBarBottomConstraint,
self.locationBarHeight, self.locationBarHeight,
self.locationBarExtraBottomPadding,
[self.extraPaddingGuide.bottomAnchor
constraintEqualToAnchor:self.bottomAnchor],
]]; ]];
[self.contractedConstraints addObjectsFromArray:@[ [self.contractedConstraints addObjectsFromArray:@[
[self.locationBarContainer.trailingAnchor [self.locationBarContainer.trailingAnchor
......
...@@ -30,12 +30,15 @@ ...@@ -30,12 +30,15 @@
// Redefined to be a PrimaryToolbarView. // Redefined to be a PrimaryToolbarView.
@property(nonatomic, strong) PrimaryToolbarView* view; @property(nonatomic, strong) PrimaryToolbarView* view;
@property(nonatomic, assign) BOOL isNTP; @property(nonatomic, assign) BOOL isNTP;
// The last fullscreen progress registered.
@property(nonatomic, assign) CGFloat previousFullscreenProgress;
@end @end
@implementation PrimaryToolbarViewController @implementation PrimaryToolbarViewController
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize isNTP = _isNTP; @synthesize isNTP = _isNTP;
@synthesize previousFullscreenProgress = _previousFullscreenProgress;
@dynamic view; @dynamic view;
#pragma mark - Public #pragma mark - Public
...@@ -98,6 +101,13 @@ ...@@ -98,6 +101,13 @@
// This method cannot be called from the init as the topSafeAnchor can only be // This method cannot be called from the init as the topSafeAnchor can only be
// set to topLayoutGuide after the view creation on iOS 10. // set to topLayoutGuide after the view creation on iOS 10.
[self.view setUp]; [self.view setUp];
if (IsCompactHeight(self)) {
self.view.locationBarExtraBottomPadding.constant =
kAdaptiveLocationBarExtraVerticalMargin;
} else {
self.view.locationBarExtraBottomPadding.constant = 0;
}
} }
- (void)didMoveToParentViewController:(UIViewController*)parent { - (void)didMoveToParentViewController:(UIViewController*)parent {
...@@ -111,6 +121,15 @@ ...@@ -111,6 +121,15 @@
[super traitCollectionDidChange:previousTraitCollection]; [super traitCollectionDidChange:previousTraitCollection];
[self.delegate [self.delegate
viewControllerTraitCollectionDidChange:previousTraitCollection]; viewControllerTraitCollectionDidChange:previousTraitCollection];
if (IsCompactHeight(self)) {
self.view.locationBarExtraBottomPadding.constant =
kAdaptiveLocationBarExtraVerticalMargin;
} else {
self.view.locationBarExtraBottomPadding.constant = 0;
}
self.view.locationBarBottomConstraint.constant =
[self verticalMarginForLocationBarForFullscreenProgress:
self.previousFullscreenProgress];
} }
#pragma mark - Property accessors #pragma mark - Property accessors
...@@ -148,10 +167,11 @@ ...@@ -148,10 +167,11 @@
kToolbarHeightFullscreen) * kToolbarHeightFullscreen) *
progress); progress);
self.view.locationBarBottomConstraint.constant = self.view.locationBarBottomConstraint.constant =
-AlignValueToPixel(kAdaptiveLocationBarVerticalMargin * progress); [self verticalMarginForLocationBarForFullscreenProgress:progress];
self.view.locationBarContainer.backgroundColor = self.view.locationBarContainer.backgroundColor =
[self.buttonFactory.toolbarConfiguration [self.buttonFactory.toolbarConfiguration
locationBarBackgroundColorWithVisibility:alphaValue]; locationBarBackgroundColorWithVisibility:alphaValue];
self.previousFullscreenProgress = progress;
} }
- (void)updateForFullscreenEnabled:(BOOL)enabled { - (void)updateForFullscreenEnabled:(BOOL)enabled {
...@@ -221,6 +241,19 @@ ...@@ -221,6 +241,19 @@
#pragma mark - Private #pragma mark - Private
// Returns the vertical margin to the location bar based on fullscreen
// |progress|, aligned to the nearest pixel.
- (CGFloat)verticalMarginForLocationBarForFullscreenProgress:(CGFloat)progress {
// The vertical bottom margin for the location bar is such that the location
// bar looks visually centered. However, the constraints are not geometrically
// centering the location bar. It is moved by 0pt (+ 1pt from extra padding)
// in iPhone landscape and by 3pt in all other configurations.
CGFloat fullscreenVerticalMargin =
IsCompactHeight(self) ? 0 : kAdaptiveLocationBarVerticalMarginFullscreen;
return -AlignValueToPixel(kAdaptiveLocationBarVerticalMargin * progress +
fullscreenVerticalMargin * (1 - progress));
}
// Deactivates the constraints on the location bar positioning. // Deactivates the constraints on the location bar positioning.
- (void)deactivateViewLocationBarConstraints { - (void)deactivateViewLocationBarConstraints {
[NSLayoutConstraint deactivateConstraints:self.view.contractedConstraints]; [NSLayoutConstraint deactivateConstraints:self.view.contractedConstraints];
......
...@@ -90,6 +90,9 @@ extern const CGFloat kAdaptiveLocationBarCornerRadius; ...@@ -90,6 +90,9 @@ extern const CGFloat kAdaptiveLocationBarCornerRadius;
extern const CGFloat kAdaptiveLocationBarBackgroundAlpha; extern const CGFloat kAdaptiveLocationBarBackgroundAlpha;
extern const CGFloat kAdaptiveLocationBarBackgroundAlphaIncognito; extern const CGFloat kAdaptiveLocationBarBackgroundAlphaIncognito;
extern const CGFloat kAdaptiveLocationBarVerticalMargin; extern const CGFloat kAdaptiveLocationBarVerticalMargin;
extern const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen;
// Extra margin for the location bar vertical margin.
extern const CGFloat kAdaptiveLocationBarExtraVerticalMargin;
// Height of the toolbar. // Height of the toolbar.
extern const CGFloat kToolbarHeight; extern const CGFloat kToolbarHeight;
......
...@@ -68,11 +68,13 @@ const CGFloat kAdaptiveLocationBarCornerRadius = 18; ...@@ -68,11 +68,13 @@ const CGFloat kAdaptiveLocationBarCornerRadius = 18;
const CGFloat kAdaptiveLocationBarBackgroundAlpha = 0.09; const CGFloat kAdaptiveLocationBarBackgroundAlpha = 0.09;
const CGFloat kAdaptiveLocationBarBackgroundAlphaIncognito = 0.12; const CGFloat kAdaptiveLocationBarBackgroundAlphaIncognito = 0.12;
const CGFloat kAdaptiveLocationBarVerticalMargin = 6.0f; const CGFloat kAdaptiveLocationBarVerticalMargin = 6.0f;
const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen = 3.0f;
const CGFloat kAdaptiveLocationBarExtraVerticalMargin = 1.0f;
const CGFloat kToolbarHeight = 56; const CGFloat kToolbarHeight = 56;
const CGFloat kTopToolbarUnsplitMargin = 2; const CGFloat kTopToolbarUnsplitMargin = 2;
const CGFloat kAdaptiveToolbarHeight = 48; const CGFloat kAdaptiveToolbarHeight = 48;
const CGFloat kToolbarHeightFullscreen = 30; const CGFloat kToolbarHeightFullscreen = 20;
NSString* const kToolbarToolsMenuButtonIdentifier = NSString* const kToolbarToolsMenuButtonIdentifier =
@"kToolbarToolsMenuButtonIdentifier"; @"kToolbarToolsMenuButtonIdentifier";
......
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