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) {
SetAsIPad();
// Action, tests.
EXPECT_EQ(380, heightForLogoHeader(YES, YES, YES, 0));
EXPECT_EQ(404, heightForLogoHeader(YES, NO, YES, 0));
EXPECT_EQ(380, heightForLogoHeader(YES, YES, NO, 0));
EXPECT_EQ(404, heightForLogoHeader(YES, NO, NO, 0));
EXPECT_EQ(382, heightForLogoHeader(YES, YES, YES, 0));
EXPECT_EQ(406, heightForLogoHeader(YES, NO, YES, 0));
EXPECT_EQ(382, heightForLogoHeader(YES, YES, NO, 0));
EXPECT_EQ(406, heightForLogoHeader(YES, NO, NO, 0));
}
TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
......@@ -198,10 +198,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
SetAsIPhonePortrait();
// Action, tests.
EXPECT_EQ(276, heightForLogoHeader(YES, YES, YES, 0));
EXPECT_EQ(276, heightForLogoHeader(YES, NO, YES, 0));
EXPECT_EQ(276, heightForLogoHeader(YES, YES, NO, 0));
EXPECT_EQ(276, heightForLogoHeader(YES, NO, NO, 0));
EXPECT_EQ(278, heightForLogoHeader(YES, YES, YES, 0));
EXPECT_EQ(278, heightForLogoHeader(YES, NO, YES, 0));
EXPECT_EQ(278, heightForLogoHeader(YES, YES, NO, 0));
EXPECT_EQ(278, heightForLogoHeader(YES, NO, NO, 0));
}
TEST_F(ContentSuggestionsCollectionUtilsTest, NearestAncestor) {
......
......@@ -44,6 +44,9 @@ const CGFloat kFakeboxHighlightDuration = 0.4;
// Fakebox highlight background alpha.
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
// application.
CGFloat ToolbarHeight() {
......@@ -299,6 +302,8 @@ CGFloat ToolbarHeight() {
CGFloat percent =
[self searchFieldProgressForOffset:offset safeAreaInsets:safeAreaInsets];
CGFloat toolbarExpandedHeight = ToolbarHeight();
if (!IsSplitToolbarMode(self)) {
// 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
......@@ -308,7 +313,8 @@ CGFloat ToolbarHeight() {
self.alpha = std::max(1 - percent, 0.01);
widthConstraint.constant = searchFieldNormalWidth;
self.fakeLocationBarHeightConstraint.constant = ToolbarHeight();
self.fakeLocationBarHeightConstraint.constant =
toolbarExpandedHeight - kFakeLocationBarHeightMargin;
self.fakeLocationBar.layer.cornerRadius =
self.fakeLocationBarHeightConstraint.constant / 2;
[self scaleHintLabelForPercent:percent];
......@@ -329,8 +335,6 @@ CGFloat ToolbarHeight() {
// Grow the background to cover the safeArea top.
self.fakeToolbarTopConstraint.constant = -safeAreaInsets.top * percent;
CGFloat toolbarExpandedHeight = ToolbarHeight();
// Calculate the amount to grow the width and height of searchField so that
// its frame covers the entire toolbar area.
CGFloat maxXInset =
......@@ -356,9 +360,11 @@ CGFloat ToolbarHeight() {
// collection from times to times.
CGFloat kLocationBarHeight = LocationBarHeight(
[UIApplication sharedApplication].preferredContentSizeCategory);
CGFloat minHeightDiff = kLocationBarHeight - toolbarExpandedHeight;
self.fakeLocationBarHeightConstraint.constant =
toolbarExpandedHeight + minHeightDiff * percent;
CGFloat minHeightDiff =
kLocationBarHeight + kFakeLocationBarHeightMargin - toolbarExpandedHeight;
self.fakeLocationBarHeightConstraint.constant = toolbarExpandedHeight -
kFakeLocationBarHeightMargin +
minHeightDiff * percent;
self.fakeLocationBar.layer.cornerRadius =
self.fakeLocationBarHeightConstraint.constant / 2;
......
......@@ -345,7 +345,7 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
}
if (IsSplitToolbarMode(self)) {
_bottomToolbarMarginHeight.constant = kAdaptiveToolbarHeight;
_bottomToolbarMarginHeight.constant = kSecondaryToolbarHeight;
} else {
_bottomToolbarMarginHeight.constant = 0;
}
......
......@@ -12,7 +12,7 @@ namespace ntp_header {
const CGFloat kMinHeaderHeight = 62;
const CGFloat kAnimationDistance = 42;
const CGFloat kFakeLocationBarTopConstraint = 6;
const CGFloat kFakeLocationBarTopConstraint = 4;
const CGFloat kScrolledToTopOmniboxBottomMargin = 4;
const CGFloat kHintLabelSidePadding = 37;
const CGFloat kHintLabelHeightMargin = 2;
......
......@@ -216,7 +216,7 @@ const CGFloat kAnimationDuration = 0.15;
.widthAnchor
constant:-2 * kRegularRegularHorizontalMargin],
[self.backgroundView.heightAnchor
constraintEqualToConstant:kAdaptiveToolbarHeight],
constraintEqualToConstant:kPrimaryToolbarHeight],
]];
// Layouts |shadow| around |self.backgroundView|.
AddSameConstraintsToSidesWithInsets(
......@@ -271,7 +271,7 @@ const CGFloat kAnimationDuration = 0.15;
[self.presentedViewController.view.leadingAnchor
constraintEqualToAnchor:backgroundView.leadingAnchor],
[self.presentedViewController.view.heightAnchor
constraintEqualToConstant:kAdaptiveToolbarHeight],
constraintEqualToConstant:kPrimaryToolbarHeight],
[self.presentedViewController.view.bottomAnchor
constraintEqualToAnchor:backgroundView.bottomAnchor],
]];
......
......@@ -66,11 +66,6 @@
// Constraint for the bottom of the location bar.
@property(nonatomic, strong, readwrite)
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
// to be set before calling this.
......
......@@ -36,10 +36,6 @@
@property(nonatomic, strong, readwrite) UIView* locationBarContainer;
// The height of the container for the location bar, redefined as readwrite.
@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
// should only contain ToolbarButtons. Redefined as readwrite.
......@@ -99,9 +95,7 @@
@synthesize locationBarView = _locationBarView;
@synthesize fakeOmniboxTarget = _fakeOmniboxTarget;
@synthesize locationBarBottomConstraint = _locationBarBottomConstraint;
@synthesize locationBarExtraBottomPadding = _locationBarExtraBottomPadding;
@synthesize locationBarHeight = _locationBarHeight;
@synthesize extraPaddingGuide = _extraPaddingGuide;
@synthesize buttonFactory = _buttonFactory;
@synthesize allButtons = _allButtons;
@synthesize progressBar = _progressBar;
......@@ -218,14 +212,6 @@
// The location bar shouldn't have vibrancy.
[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.
......@@ -334,16 +320,11 @@
self.locationBarHeight =
[self.locationBarContainer.heightAnchor constraintEqualToConstant:0];
self.locationBarBottomConstraint = [self.locationBarContainer.bottomAnchor
constraintEqualToAnchor:self.extraPaddingGuide.topAnchor];
self.locationBarExtraBottomPadding =
[self.extraPaddingGuide.heightAnchor constraintEqualToConstant:0];
constraintEqualToAnchor:self.bottomAnchor];
[NSLayoutConstraint activateConstraints:@[
self.locationBarBottomConstraint,
self.locationBarHeight,
self.locationBarExtraBottomPadding,
[self.extraPaddingGuide.bottomAnchor
constraintEqualToAnchor:self.bottomAnchor],
]];
[self.contractedConstraints addObjectsFromArray:@[
[self.locationBarContainer.trailingAnchor
......
......@@ -129,13 +129,6 @@
[self.view.collapsedToolbarButton addTarget:self
action:@selector(exitFullscreen)
forControlEvents:UIControlEventTouchUpInside];
if (IsCompactHeight(self)) {
self.view.locationBarExtraBottomPadding.constant =
kAdaptiveLocationBarExtraVerticalMargin;
} else {
self.view.locationBarExtraBottomPadding.constant = 0;
}
}
- (void)viewDidLoad {
......@@ -264,12 +257,6 @@
(UITraitCollection*)previousTraitCollection {
[self.delegate
viewControllerTraitCollectionDidChange:previousTraitCollection];
if (IsCompactHeight(self)) {
self.view.locationBarExtraBottomPadding.constant =
kAdaptiveLocationBarExtraVerticalMargin;
} else {
self.view.locationBarExtraBottomPadding.constant = 0;
}
self.view.locationBarBottomConstraint.constant =
[self verticalMarginForLocationBarForFullscreenProgress:
self.previousFullscreenProgress];
......@@ -304,8 +291,8 @@
- (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.
// centering the location bar. It is moved by 0pt in iPhone landscape and by
// 3pt in all other configurations.
CGFloat fullscreenVerticalMargin =
IsCompactHeight(self) ? 0 : kAdaptiveLocationBarVerticalMarginFullscreen;
return -AlignValueToPixel((kAdaptiveLocationBarVerticalMargin * progress +
......
......@@ -66,13 +66,13 @@ extern const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen;
// Additional margin, which should grow only when the preferred content size is
// non-default.
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.
extern const CGFloat kTopToolbarUnsplitMargin;
// Height of the adaptive toolbars with default font size.
extern const CGFloat kAdaptiveToolbarHeight;
// Height of the primary toolbar with default font size.
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
// preferred font size.
extern const CGFloat kNonDynamicToolbarHeight;
......
......@@ -43,13 +43,13 @@ const CGFloat kContractedLocationBarHorizontalMargin = 19;
const CGFloat kAdaptiveLocationBarBackgroundAlpha = 0.09;
const CGFloat kAdaptiveLocationBarBackgroundAlphaIncognito = 0.12;
const CGFloat kAdaptiveLocationBarVerticalMargin = 6.0f;
const CGFloat kAdaptiveLocationBarVerticalMargin = 10.0f;
const CGFloat kAdaptiveLocationBarVerticalMarginFullscreen = 3.0f;
const CGFloat kLocationBarVerticalMarginDynamicType = -1.0f;
const CGFloat kAdaptiveLocationBarExtraVerticalMargin = 1.0f;
const CGFloat kTopToolbarUnsplitMargin = 2;
const CGFloat kAdaptiveToolbarHeight = 48;
const CGFloat kTopToolbarUnsplitMargin = 6;
const CGFloat kPrimaryToolbarHeight = 50;
const CGFloat kSecondaryToolbarHeight = 44;
const CGFloat kNonDynamicToolbarHeight = 14;
const CGFloat kToolbarHeightFullscreen = 20;
const CGFloat kNonDynamicToolbarHeightFullscreen = 3;
......
......@@ -50,13 +50,13 @@ CGFloat ToolbarCollapsedHeight(UIContentSizeCategory category) {
CGFloat ToolbarExpandedHeight(UIContentSizeCategory category) {
category = NormalizedCategory(category);
return Interpolate(category, kAdaptiveToolbarHeight,
kNonDynamicToolbarHeight);
return Interpolate(category, kPrimaryToolbarHeight, kNonDynamicToolbarHeight);
}
CGFloat LocationBarHeight(UIContentSizeCategory category) {
category = NormalizedCategory(category);
CGFloat verticalMargin = 2 * kAdaptiveLocationBarVerticalMargin;
CGFloat verticalMargin =
2 * kAdaptiveLocationBarVerticalMargin - kTopToolbarUnsplitMargin;
CGFloat dynamicTypeVerticalAdjustment =
(ToolbarClampedFontSizeMultiplier(category) - 1) *
(kLocationBarVerticalMarginDynamicType +
......
......@@ -77,7 +77,7 @@ const CGFloat kToolsMenuOffset = -7;
#pragma mark - UIView
- (CGSize)intrinsicContentSize {
return CGSizeMake(UIViewNoIntrinsicMetric, kAdaptiveToolbarHeight);
return CGSizeMake(UIViewNoIntrinsicMetric, kSecondaryToolbarHeight);
}
- (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