Commit 8c3ace00 authored by Justin Cohen's avatar Justin Cohen Committed by Commit Bot

[ios] Remove StatusBarHeight from ContentSuggestionsCollectionUtils.

Bug: 883770
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: I2b7a57e57047677304ba572b9648e998563a8d39
Reviewed-on: https://chromium-review.googlesource.com/c/1256442
Commit-Queue: Justin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#596211}
parent 5cf2125a
......@@ -30,8 +30,8 @@ CGFloat centeredTilesMarginForWidth(CGFloat width);
CGFloat doodleHeight(BOOL logoIsShowing);
// Returns the proper margin to the top of the header for the doodle.
// If |toolbarPresent| is true, the top margin include a space to display the
// toolbar.
CGFloat doodleTopMargin(BOOL toolbarPresent);
// toolbar. Adds |topInset| to non-RxR displays.
CGFloat doodleTopMargin(BOOL toolbarPresent, CGFloat topInset);
// Returns the proper margin to the bottom of the doodle for the search field.
CGFloat searchFieldTopMargin();
// Returns the proper width for the search field inside a view with a |width|.
......@@ -44,7 +44,8 @@ CGFloat searchFieldWidth(CGFloat superviewWidth);
// take into account a space to show the toolbar.
CGFloat heightForLogoHeader(BOOL logoIsShowing,
BOOL promoCanShow,
BOOL toolbarPresent);
BOOL toolbarPresent,
CGFloat topInset);
// Configure the |searchHintLabel| for the fake omnibox. |hintLabelContainer|
// is added to the |searchTapTarget| with autolayout and |searchHintLabel| is
// added to |hintLabelContainer| with autoresizing. This is done due to the
......
......@@ -108,10 +108,10 @@ CGFloat doodleHeight(BOOL logoIsShowing) {
return kGoogleSearchDoodleHeight;
}
CGFloat doodleTopMargin(BOOL toolbarPresent) {
CGFloat doodleTopMargin(BOOL toolbarPresent, CGFloat topInset) {
if (!IsCompactWidth() && !IsCompactHeight())
return kDoodleTopMarginRegularXRegular;
return StatusBarHeight() + kDoodleTopMarginOther;
return topInset + kDoodleTopMarginOther;
}
CGFloat searchFieldTopMargin() {
......@@ -128,8 +128,9 @@ CGFloat searchFieldWidth(CGFloat superviewWidth) {
CGFloat heightForLogoHeader(BOOL logoIsShowing,
BOOL promoCanShow,
BOOL toolbarPresent) {
CGFloat headerHeight = doodleTopMargin(toolbarPresent) +
BOOL toolbarPresent,
CGFloat topInset) {
CGFloat headerHeight = doodleTopMargin(toolbarPresent, topInset) +
doodleHeight(logoIsShowing) + searchFieldTopMargin() +
kSearchFieldHeight + kNTPSearchFieldBottomPadding;
if (!IsRegularXRegularSizeClass()) {
......
......@@ -17,6 +17,8 @@
namespace content_suggestions {
CGFloat kTopInset = 20;
class ContentSuggestionsCollectionUtilsTest : public PlatformTest {
public:
void SetAsIPad() {
......@@ -107,7 +109,7 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPad) {
// Action.
CGFloat height = doodleHeight(YES);
CGFloat topMargin = doodleTopMargin(YES);
CGFloat topMargin = doodleTopMargin(YES, kTopInset);
// Test.
EXPECT_EQ(120, height);
......@@ -122,12 +124,12 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhonePortrait) {
// Action.
CGFloat heightLogo = doodleHeight(YES);
CGFloat heightNoLogo = doodleHeight(NO);
CGFloat topMargin = doodleTopMargin(YES);
CGFloat topMargin = doodleTopMargin(YES, kTopInset);
// Test.
EXPECT_EQ(120, heightLogo);
EXPECT_EQ(60, heightNoLogo);
EXPECT_EQ(58, topMargin);
EXPECT_EQ(58 + kTopInset, topMargin);
}
TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhoneLandscape) {
......@@ -138,12 +140,12 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhoneLandscape) {
// Action.
CGFloat heightLogo = doodleHeight(YES);
CGFloat heightNoLogo = doodleHeight(NO);
CGFloat topMargin = doodleTopMargin(YES);
CGFloat topMargin = doodleTopMargin(YES, kTopInset);
// Test.
EXPECT_EQ(120, heightLogo);
EXPECT_EQ(60, heightNoLogo);
EXPECT_EQ(58, topMargin);
EXPECT_EQ(58 + kTopInset, topMargin);
}
TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPad) {
......@@ -198,10 +200,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPad) {
SetAsIPad();
// Action, tests.
EXPECT_EQ(380, heightForLogoHeader(YES, YES, YES));
EXPECT_EQ(404, heightForLogoHeader(YES, NO, YES));
EXPECT_EQ(380, heightForLogoHeader(YES, YES, NO));
EXPECT_EQ(404, heightForLogoHeader(YES, NO, NO));
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));
}
TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
......@@ -209,10 +211,10 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
SetAsIPhone();
// Action, tests.
EXPECT_EQ(276, heightForLogoHeader(YES, YES, YES));
EXPECT_EQ(276, heightForLogoHeader(YES, NO, YES));
EXPECT_EQ(276, heightForLogoHeader(YES, YES, NO));
EXPECT_EQ(276, heightForLogoHeader(YES, NO, NO));
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));
}
TEST_F(ContentSuggestionsCollectionUtilsTest, SizeIPhone6) {
......
......@@ -130,7 +130,6 @@ using base::UserMetricsAction;
if (IsSplitToolbarMode()) {
[self.toolbarDelegate setScrollProgressForTabletOmnibox:1];
}
[self updateConstraints];
};
[coordinator animateAlongsideTransition:transition completion:nil];
......@@ -193,33 +192,25 @@ using base::UserMetricsAction;
// Update the doodle top margin to the new -doodleTopMargin value.
- (void)updateConstraints {
self.doodleTopMarginConstraint.constant =
content_suggestions::doodleTopMargin(YES);
content_suggestions::doodleTopMargin(YES, [self topInset]);
}
- (CGFloat)pinnedOffsetY {
CGFloat headerHeight = content_suggestions::heightForLogoHeader(
self.logoIsShowing, self.promoCanShow, YES);
self.logoIsShowing, self.promoCanShow, YES, [self topInset]);
CGFloat offsetY =
headerHeight - ntp_header::kScrolledToTopOmniboxBottomMargin;
if (!IsRegularXRegularSizeClass(self)) {
CGFloat top = 0;
if (@available(iOS 11, *)) {
top = self.parentViewController.view.safeAreaInsets.top;
} else {
// TODO(crbug.com/826369) Replace this when the NTP is contained by the
// BVC with |self.parentViewController.topLayoutGuide.length|.
top = StatusBarHeight();
}
offsetY -= ntp_header::ToolbarHeight() + top;
offsetY -= ntp_header::ToolbarHeight() + [self topInset];
}
return offsetY;
}
- (CGFloat)headerHeight {
return content_suggestions::heightForLogoHeader(self.logoIsShowing,
self.promoCanShow, YES);
return content_suggestions::heightForLogoHeader(
self.logoIsShowing, self.promoCanShow, YES, [self topInset]);
}
#pragma mark - ContentSuggestionsHeaderProvider
......@@ -410,7 +401,8 @@ using base::UserMetricsAction;
andHeaderView:(UIView*)headerView {
self.doodleTopMarginConstraint = [logoView.topAnchor
constraintEqualToAnchor:headerView.topAnchor
constant:content_suggestions::doodleTopMargin(YES)];
constant:content_suggestions::doodleTopMargin(
YES, [self topInset])];
self.doodleHeightConstraint = [logoView.heightAnchor
constraintEqualToConstant:content_suggestions::doodleHeight(
self.logoIsShowing)];
......@@ -451,6 +443,15 @@ using base::UserMetricsAction;
[self.collectionSynchronizer shiftTilesUpWithCompletionBlock:completionBlock];
}
- (CGFloat)topInset {
if (@available(iOS 11, *))
return self.parentViewController.view.safeAreaInsets.top;
// TODO(crbug.com/826369) Replace this when the NTP is contained by the
// BVC with |self.parentViewController.topLayoutGuide.length|.
return StatusBarHeight();
}
#pragma mark - LogoAnimationControllerOwnerOwner
- (id<LogoAnimationControllerOwner>)logoAnimationControllerOwner {
......
......@@ -295,6 +295,7 @@ const CGFloat kCardBorderRadius = 11;
[self correctMissingSafeArea];
[self.headerSynchronizer
updateFakeOmniboxOnNewWidth:self.collectionView.bounds.size.width];
[self.headerSynchronizer updateConstraints];
}
#pragma mark - UICollectionViewDelegate
......
......@@ -314,7 +314,11 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self updateToolbarMargins];
}
- (void)safeAreaInsetsDidChange {
[super safeAreaInsetsDidChange];
[self updateToolbarMargins];
}
......@@ -340,8 +344,13 @@ NSAttributedString* FormatHTMLListForUILabel(NSString* listString) {
if (IsRegularXRegularSizeClass(self)) {
_topToolbarMarginHeight.constant = 0;
} else {
_topToolbarMarginHeight.constant =
StatusBarHeight() + kAdaptiveToolbarHeight;
CGFloat topInset = 0;
if (@available(iOS 11, *)) {
topInset = self.safeAreaInsets.top;
} else {
topInset = StatusBarHeight();
}
_topToolbarMarginHeight.constant = topInset + kAdaptiveToolbarHeight;
}
if (IsSplitToolbarMode(self)) {
......
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