Commit 49d0dd31 authored by Ewann's avatar Ewann Committed by Commit Bot

Better vertical positioning of toolbars

- Resizes toolbars.
- Updates fakeOmnibox height.

screenshots:
https://drive.google.com/drive/folders/1VloKJh9nJOi-73XmBTH_QAXQRbTN1wuo?usp=sharing

Bug: 1035850
Change-Id: If97c06b1cb9257fe490a75a4d86b703f6426940b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1978001
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737314}
parent da7ab438
...@@ -187,10 +187,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPad) { ...@@ -187,10 +187,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPad) {
SetAsIPad(); SetAsIPad();
// Action, tests. // Action, tests.
EXPECT_EQ(380, heightForLogoHeader(YES, YES, YES, 0)); EXPECT_EQ(382, heightForLogoHeader(YES, YES, YES, 0));
EXPECT_EQ(404, heightForLogoHeader(YES, NO, YES, 0)); EXPECT_EQ(406, heightForLogoHeader(YES, NO, YES, 0));
EXPECT_EQ(380, heightForLogoHeader(YES, YES, NO, 0)); EXPECT_EQ(382, heightForLogoHeader(YES, YES, NO, 0));
EXPECT_EQ(404, heightForLogoHeader(YES, NO, NO, 0)); EXPECT_EQ(406, heightForLogoHeader(YES, NO, NO, 0));
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) { TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
...@@ -198,10 +198,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) { ...@@ -198,10 +198,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
SetAsIPhonePortrait(); SetAsIPhonePortrait();
// Action, tests. // Action, tests.
EXPECT_EQ(276, heightForLogoHeader(YES, YES, YES, 0)); EXPECT_EQ(278, heightForLogoHeader(YES, YES, YES, 0));
EXPECT_EQ(276, heightForLogoHeader(YES, NO, YES, 0)); EXPECT_EQ(278, heightForLogoHeader(YES, NO, YES, 0));
EXPECT_EQ(276, heightForLogoHeader(YES, YES, NO, 0)); EXPECT_EQ(278, heightForLogoHeader(YES, YES, NO, 0));
EXPECT_EQ(276, heightForLogoHeader(YES, NO, NO, 0)); EXPECT_EQ(278, heightForLogoHeader(YES, NO, NO, 0));
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, NearestAncestor) { TEST_F(ContentSuggestionsCollectionUtilsTest, NearestAncestor) {
......
...@@ -44,6 +44,9 @@ const CGFloat kFakeboxHighlightDuration = 0.4; ...@@ -44,6 +44,9 @@ const CGFloat kFakeboxHighlightDuration = 0.4;
// Fakebox highlight background alpha. // Fakebox highlight background alpha.
const CGFloat kFakeboxHighlightAlpha = 0.06; const CGFloat kFakeboxHighlightAlpha = 0.06;
// Height margin of the fake location bar.
const CGFloat kFakeLocationBarHeightMargin = 2;
// Returns the height of the toolbar based on the preferred content size of the // Returns the height of the toolbar based on the preferred content size of the
// application. // application.
CGFloat ToolbarHeight() { CGFloat ToolbarHeight() {
...@@ -299,6 +302,8 @@ CGFloat ToolbarHeight() { ...@@ -299,6 +302,8 @@ CGFloat ToolbarHeight() {
CGFloat percent = CGFloat percent =
[self searchFieldProgressForOffset:offset safeAreaInsets:safeAreaInsets]; [self searchFieldProgressForOffset:offset safeAreaInsets:safeAreaInsets];
CGFloat toolbarExpandedHeight = ToolbarHeight();
if (!IsSplitToolbarMode(self)) { if (!IsSplitToolbarMode(self)) {
// When Voiceover is running, if the header's alpha is set to 0, voiceover // When Voiceover is running, if the header's alpha is set to 0, voiceover
// can't scroll back to it, and it will never come back into view. To // can't scroll back to it, and it will never come back into view. To
...@@ -308,7 +313,8 @@ CGFloat ToolbarHeight() { ...@@ -308,7 +313,8 @@ CGFloat ToolbarHeight() {
self.alpha = std::max(1 - percent, 0.01); self.alpha = std::max(1 - percent, 0.01);
widthConstraint.constant = searchFieldNormalWidth; widthConstraint.constant = searchFieldNormalWidth;
self.fakeLocationBarHeightConstraint.constant = ToolbarHeight(); self.fakeLocationBarHeightConstraint.constant =
toolbarExpandedHeight - kFakeLocationBarHeightMargin;
self.fakeLocationBar.layer.cornerRadius = self.fakeLocationBar.layer.cornerRadius =
self.fakeLocationBarHeightConstraint.constant / 2; self.fakeLocationBarHeightConstraint.constant / 2;
[self scaleHintLabelForPercent:percent]; [self scaleHintLabelForPercent:percent];
...@@ -329,8 +335,6 @@ CGFloat ToolbarHeight() { ...@@ -329,8 +335,6 @@ CGFloat ToolbarHeight() {
// Grow the background to cover the safeArea top. // Grow the background to cover the safeArea top.
self.fakeToolbarTopConstraint.constant = -safeAreaInsets.top * percent; self.fakeToolbarTopConstraint.constant = -safeAreaInsets.top * percent;
CGFloat toolbarExpandedHeight = ToolbarHeight();
// Calculate the amount to grow the width and height of searchField so that // Calculate the amount to grow the width and height of searchField so that
// its frame covers the entire toolbar area. // its frame covers the entire toolbar area.
CGFloat maxXInset = CGFloat maxXInset =
...@@ -356,9 +360,11 @@ CGFloat ToolbarHeight() { ...@@ -356,9 +360,11 @@ CGFloat ToolbarHeight() {
// collection from times to times. // collection from times to times.
CGFloat kLocationBarHeight = LocationBarHeight( CGFloat kLocationBarHeight = LocationBarHeight(
[UIApplication sharedApplication].preferredContentSizeCategory); [UIApplication sharedApplication].preferredContentSizeCategory);
CGFloat minHeightDiff = kLocationBarHeight - toolbarExpandedHeight; CGFloat minHeightDiff =
self.fakeLocationBarHeightConstraint.constant = kLocationBarHeight + kFakeLocationBarHeightMargin - toolbarExpandedHeight;
toolbarExpandedHeight + minHeightDiff * percent; self.fakeLocationBarHeightConstraint.constant = toolbarExpandedHeight -
kFakeLocationBarHeightMargin +
minHeightDiff * percent;
self.fakeLocationBar.layer.cornerRadius = self.fakeLocationBar.layer.cornerRadius =
self.fakeLocationBarHeightConstraint.constant / 2; self.fakeLocationBarHeightConstraint.constant / 2;
......
...@@ -345,7 +345,7 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) { ...@@ -345,7 +345,7 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
} }
if (IsSplitToolbarMode(self)) { if (IsSplitToolbarMode(self)) {
_bottomToolbarMarginHeight.constant = kAdaptiveToolbarHeight; _bottomToolbarMarginHeight.constant = kSecondaryToolbarHeight;
} else { } else {
_bottomToolbarMarginHeight.constant = 0; _bottomToolbarMarginHeight.constant = 0;
} }
......
...@@ -12,7 +12,7 @@ namespace ntp_header { ...@@ -12,7 +12,7 @@ namespace ntp_header {
const CGFloat kMinHeaderHeight = 62; const CGFloat kMinHeaderHeight = 62;
const CGFloat kAnimationDistance = 42; const CGFloat kAnimationDistance = 42;
const CGFloat kFakeLocationBarTopConstraint = 6; const CGFloat kFakeLocationBarTopConstraint = 4;
const CGFloat kScrolledToTopOmniboxBottomMargin = 4; const CGFloat kScrolledToTopOmniboxBottomMargin = 4;
const CGFloat kHintLabelSidePadding = 37; const CGFloat kHintLabelSidePadding = 37;
const CGFloat kHintLabelHeightMargin = 2; const CGFloat kHintLabelHeightMargin = 2;
......
...@@ -216,7 +216,7 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -216,7 +216,7 @@ const CGFloat kAnimationDuration = 0.15;
.widthAnchor .widthAnchor
constant:-2 * kRegularRegularHorizontalMargin], constant:-2 * kRegularRegularHorizontalMargin],
[self.backgroundView.heightAnchor [self.backgroundView.heightAnchor
constraintEqualToConstant:kAdaptiveToolbarHeight], constraintEqualToConstant:kPrimaryToolbarHeight],
]]; ]];
// Layouts |shadow| around |self.backgroundView|. // Layouts |shadow| around |self.backgroundView|.
AddSameConstraintsToSidesWithInsets( AddSameConstraintsToSidesWithInsets(
...@@ -271,7 +271,7 @@ const CGFloat kAnimationDuration = 0.15; ...@@ -271,7 +271,7 @@ const CGFloat kAnimationDuration = 0.15;
[self.presentedViewController.view.leadingAnchor [self.presentedViewController.view.leadingAnchor
constraintEqualToAnchor:backgroundView.leadingAnchor], constraintEqualToAnchor:backgroundView.leadingAnchor],
[self.presentedViewController.view.heightAnchor [self.presentedViewController.view.heightAnchor
constraintEqualToConstant:kAdaptiveToolbarHeight], constraintEqualToConstant:kPrimaryToolbarHeight],
[self.presentedViewController.view.bottomAnchor [self.presentedViewController.view.bottomAnchor
constraintEqualToAnchor:backgroundView.bottomAnchor], constraintEqualToAnchor:backgroundView.bottomAnchor],
]]; ]];
......
...@@ -66,11 +66,6 @@ ...@@ -66,11 +66,6 @@
// 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.
......
...@@ -36,10 +36,6 @@ ...@@ -36,10 +36,6 @@
@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.
...@@ -99,9 +95,7 @@ ...@@ -99,9 +95,7 @@
@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;
...@@ -218,14 +212,6 @@ ...@@ -218,14 +212,6 @@
// 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) {
[self.locationBarContainer addSubview:self.locationBarView];
}
} }
// Sets the leading stack view. // Sets the leading stack view.
...@@ -334,16 +320,11 @@ ...@@ -334,16 +320,11 @@
self.locationBarHeight = self.locationBarHeight =
[self.locationBarContainer.heightAnchor constraintEqualToConstant:0]; [self.locationBarContainer.heightAnchor constraintEqualToConstant:0];
self.locationBarBottomConstraint = [self.locationBarContainer.bottomAnchor self.locationBarBottomConstraint = [self.locationBarContainer.bottomAnchor
constraintEqualToAnchor:self.extraPaddingGuide.topAnchor]; constraintEqualToAnchor:self.bottomAnchor];
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
......
...@@ -129,13 +129,6 @@ ...@@ -129,13 +129,6 @@
[self.view.collapsedToolbarButton addTarget:self [self.view.collapsedToolbarButton addTarget:self
action:@selector(exitFullscreen) action:@selector(exitFullscreen)
forControlEvents:UIControlEventTouchUpInside]; forControlEvents:UIControlEventTouchUpInside];
if (IsCompactHeight(self)) {
self.view.locationBarExtraBottomPadding.constant =
kAdaptiveLocationBarExtraVerticalMargin;
} else {
self.view.locationBarExtraBottomPadding.constant = 0;
}
} }
- (void)viewDidLoad { - (void)viewDidLoad {
...@@ -264,12 +257,6 @@ ...@@ -264,12 +257,6 @@
(UITraitCollection*)previousTraitCollection { (UITraitCollection*)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.view.locationBarBottomConstraint.constant =
[self verticalMarginForLocationBarForFullscreenProgress: [self verticalMarginForLocationBarForFullscreenProgress:
self.previousFullscreenProgress]; self.previousFullscreenProgress];
...@@ -304,8 +291,8 @@ ...@@ -304,8 +291,8 @@
- (CGFloat)verticalMarginForLocationBarForFullscreenProgress:(CGFloat)progress { - (CGFloat)verticalMarginForLocationBarForFullscreenProgress:(CGFloat)progress {
// The vertical bottom margin for the location bar is such that the location // The vertical bottom margin for the location bar is such that the location
// bar looks visually centered. However, the constraints are not geometrically // bar looks visually centered. However, the constraints are not geometrically
// centering the location bar. It is moved by 0pt (+ 1pt from extra padding) // centering the location bar. It is moved by 0pt in iPhone landscape and by
// in iPhone landscape and by 3pt in all other configurations. // 3pt in all other configurations.
CGFloat fullscreenVerticalMargin = CGFloat fullscreenVerticalMargin =
IsCompactHeight(self) ? 0 : kAdaptiveLocationBarVerticalMarginFullscreen; IsCompactHeight(self) ? 0 : kAdaptiveLocationBarVerticalMarginFullscreen;
return -AlignValueToPixel((kAdaptiveLocationBarVerticalMargin * progress + return -AlignValueToPixel((kAdaptiveLocationBarVerticalMargin * progress +
......
...@@ -66,13 +66,13 @@ extern const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen; ...@@ -66,13 +66,13 @@ extern const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen;
// Additional margin, which should grow only when the preferred content size is // Additional margin, which should grow only when the preferred content size is
// non-default. // non-default.
extern const CGFloat kLocationBarVerticalMarginDynamicType; extern const CGFloat kLocationBarVerticalMarginDynamicType;
// Extra margin for the location bar vertical margin.
extern const CGFloat kAdaptiveLocationBarExtraVerticalMargin;
// Top margin of the top toolbar when the adaptive toolbar is unsplit. // Top margin of the top toolbar when the adaptive toolbar is unsplit.
extern const CGFloat kTopToolbarUnsplitMargin; extern const CGFloat kTopToolbarUnsplitMargin;
// Height of the adaptive toolbars with default font size. // Height of the primary toolbar with default font size.
extern const CGFloat kAdaptiveToolbarHeight; extern const CGFloat kPrimaryToolbarHeight;
// Height of the secondary toolbar with default font size.
extern const CGFloat kSecondaryToolbarHeight;
// Height of the part of the toolbar not scaling up when the user changes the // Height of the part of the toolbar not scaling up when the user changes the
// preferred font size. // preferred font size.
extern const CGFloat kNonDynamicToolbarHeight; extern const CGFloat kNonDynamicToolbarHeight;
......
...@@ -43,13 +43,13 @@ const CGFloat kContractedLocationBarHorizontalMargin = 19; ...@@ -43,13 +43,13 @@ const CGFloat kContractedLocationBarHorizontalMargin = 19;
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 = 10.0f;
const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen = 3.0f; const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen = 3.0f;
const CGFloat kLocationBarVerticalMarginDynamicType = -1.0f; const CGFloat kLocationBarVerticalMarginDynamicType = -1.0f;
const CGFloat kAdaptiveLocationBarExtraVerticalMargin = 1.0f;
const CGFloat kTopToolbarUnsplitMargin = 2; const CGFloat kTopToolbarUnsplitMargin = 6;
const CGFloat kAdaptiveToolbarHeight = 48; const CGFloat kPrimaryToolbarHeight = 50;
const CGFloat kSecondaryToolbarHeight = 44;
const CGFloat kNonDynamicToolbarHeight = 14; const CGFloat kNonDynamicToolbarHeight = 14;
const CGFloat kToolbarHeightFullscreen = 20; const CGFloat kToolbarHeightFullscreen = 20;
const CGFloat kNonDynamicToolbarHeightFullscreen = 3; const CGFloat kNonDynamicToolbarHeightFullscreen = 3;
......
...@@ -50,13 +50,13 @@ CGFloat ToolbarCollapsedHeight(UIContentSizeCategory category) { ...@@ -50,13 +50,13 @@ CGFloat ToolbarCollapsedHeight(UIContentSizeCategory category) {
CGFloat ToolbarExpandedHeight(UIContentSizeCategory category) { CGFloat ToolbarExpandedHeight(UIContentSizeCategory category) {
category = NormalizedCategory(category); category = NormalizedCategory(category);
return Interpolate(category, kAdaptiveToolbarHeight, return Interpolate(category, kPrimaryToolbarHeight, kNonDynamicToolbarHeight);
kNonDynamicToolbarHeight);
} }
CGFloat LocationBarHeight(UIContentSizeCategory category) { CGFloat LocationBarHeight(UIContentSizeCategory category) {
category = NormalizedCategory(category); category = NormalizedCategory(category);
CGFloat verticalMargin = 2 * kAdaptiveLocationBarVerticalMargin; CGFloat verticalMargin =
2 * kAdaptiveLocationBarVerticalMargin - kTopToolbarUnsplitMargin;
CGFloat dynamicTypeVerticalAdjustment = CGFloat dynamicTypeVerticalAdjustment =
(ToolbarClampedFontSizeMultiplier(category) - 1) * (ToolbarClampedFontSizeMultiplier(category) - 1) *
(kLocationBarVerticalMarginDynamicType + (kLocationBarVerticalMarginDynamicType +
......
...@@ -77,7 +77,7 @@ const CGFloat kToolsMenuOffset = -7; ...@@ -77,7 +77,7 @@ const CGFloat kToolsMenuOffset = -7;
#pragma mark - UIView #pragma mark - UIView
- (CGSize)intrinsicContentSize { - (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, kAdaptiveToolbarHeight); return CGSizeMake(UIViewNoIntrinsicMetric, kSecondaryToolbarHeight);
} }
- (void)willMoveToWindow:(UIWindow*)newWindow { - (void)willMoveToWindow:(UIWindow*)newWindow {
......
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