Commit 6c65ed08 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Fix NTP positioning with multiwindow

This CL makes sure that the correct trait collection is used when
checking if the NTP is displaying one or two toolbars.
With multiwindow, it is not possible to directly check the key window.

Fixed: 1128527
Change-Id: I79a441b1a186c755b7cc979f527e807f10aa3a29
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2422955
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809718}
parent 7351e5fe
...@@ -46,8 +46,11 @@ ...@@ -46,8 +46,11 @@
+ (void)resetWhatsNewPromo; + (void)resetWhatsNewPromo;
// Returns the width the search field is supposed to have when the collection // Returns the width the search field is supposed to have when the collection
// has |collectionWidth|. // has |collectionWidth|. |traitCollection| is the trait collection of the view
+ (CGFloat)searchFieldWidthForCollectionWidth:(CGFloat)collectionWidth; // displaying the omnibox, its Size Class is used in the computation.
+ (CGFloat)searchFieldWidthForCollectionWidth:(CGFloat)collectionWidth
traitCollection:
(UITraitCollection*)traitCollection;
// Returns the collection view. // Returns the collection view.
+ (UICollectionView*)collectionView; + (UICollectionView*)collectionView;
......
...@@ -178,8 +178,11 @@ ContentSuggestion CreateSuggestion(Category category, ...@@ -178,8 +178,11 @@ ContentSuggestion CreateSuggestion(Category category,
ios::NotificationPromo::MigrateUserPrefs(local_state); ios::NotificationPromo::MigrateUserPrefs(local_state);
} }
+ (CGFloat)searchFieldWidthForCollectionWidth:(CGFloat)collectionWidth { + (CGFloat)searchFieldWidthForCollectionWidth:(CGFloat)collectionWidth
return content_suggestions::searchFieldWidth(collectionWidth); traitCollection:
(UITraitCollection*)traitCollection {
return content_suggestions::searchFieldWidth(collectionWidth,
traitCollection);
} }
+ (UICollectionView*)collectionView { + (UICollectionView*)collectionView {
......
...@@ -14,26 +14,35 @@ extern const int kSearchFieldBackgroundColor; ...@@ -14,26 +14,35 @@ extern const int kSearchFieldBackgroundColor;
extern const CGFloat kHintTextScale; extern const CGFloat kHintTextScale;
// Returns the proper height for the doodle. |logoIsShowing| refers to the // Returns the proper height for the doodle. |logoIsShowing| refers to the
// Google logo or the doodle. // Google logo or the doodle. The SizeClass of the |traitCollection| of the view
CGFloat doodleHeight(BOOL logoIsShowing); // displaying the doodle is used in the computation.
CGFloat doodleHeight(BOOL logoIsShowing, UITraitCollection* traitCollection);
// Returns the proper margin to the top of the header for the doodle. // 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 // If |toolbarPresent| is true, the top margin include a space to display the
// toolbar. Adds |topInset| to non-RxR displays. // toolbar. Adds |topInset| to non-RxR displays. The SizeClass of the
CGFloat doodleTopMargin(BOOL toolbarPresent, CGFloat topInset); // |traitCollection| of the view displaying the doodle is used.
CGFloat doodleTopMargin(BOOL toolbarPresent,
CGFloat topInset,
UITraitCollection* traitCollection);
// Returns the proper margin to the bottom of the doodle for the search field. // Returns the proper margin to the bottom of the doodle for the search field.
CGFloat searchFieldTopMargin(); CGFloat searchFieldTopMargin();
// Returns the proper width for the search field inside a view with a |width|. // Returns the proper width for the search field inside a view with a |width|.
CGFloat searchFieldWidth(CGFloat superviewWidth); // The SizeClass of the |traitCollection| of the view displaying the search
// field is used in the computation.
CGFloat searchFieldWidth(CGFloat superviewWidth,
UITraitCollection* traitCollection);
// TODO(crbug.com/761817): Remove |toolbarPresent| once the transition to the // TODO(crbug.com/761817): Remove |toolbarPresent| once the transition to the
// new architecture is completed. // new architecture is completed.
// Returns the expected height of the header. |logoIsShowing| refers to the // Returns the expected height of the header. |logoIsShowing| refers to the
// Google logo or the doodle. |promoCanShow| represents whether a what's new // Google logo or the doodle. |promoCanShow| represents whether a what's new
// promo can be displayed. |toolbarPresent| represent whether the height should // promo can be displayed. |toolbarPresent| represent whether the height should
// take into account a space to show the toolbar. // take into account a space to show the toolbar. The SizeClass of the
// |traitCollection| of the view displaying the logo is used in the computation.
CGFloat heightForLogoHeader(BOOL logoIsShowing, CGFloat heightForLogoHeader(BOOL logoIsShowing,
BOOL promoCanShow, BOOL promoCanShow,
BOOL toolbarPresent, BOOL toolbarPresent,
CGFloat topInset); CGFloat topInset,
UITraitCollection* traitCollection);
// Configure the |searchHintLabel| for the fake omnibox. |hintLabelContainer| // Configure the |searchHintLabel| for the fake omnibox. |hintLabelContainer|
// is added to the |searchTapTarget| with autolayout and |searchHintLabel| is // is added to the |searchTapTarget| with autolayout and |searchHintLabel| is
// added to |hintLabelContainer| with autoresizing. This is done due to the // added to |hintLabelContainer| with autoresizing. This is done due to the
......
...@@ -58,17 +58,19 @@ namespace content_suggestions { ...@@ -58,17 +58,19 @@ namespace content_suggestions {
const int kSearchFieldBackgroundColor = 0xF1F3F4; const int kSearchFieldBackgroundColor = 0xF1F3F4;
const CGFloat kHintTextScale = 0.15; const CGFloat kHintTextScale = 0.15;
CGFloat doodleHeight(BOOL logoIsShowing) { CGFloat doodleHeight(BOOL logoIsShowing, UITraitCollection* traitCollection) {
if (!IsRegularXRegularSizeClass() && !logoIsShowing) if (!IsRegularXRegularSizeClass(traitCollection) && !logoIsShowing)
return kNonGoogleSearchDoodleHeight; return kNonGoogleSearchDoodleHeight;
return kGoogleSearchDoodleHeight; return kGoogleSearchDoodleHeight;
} }
CGFloat doodleTopMargin(BOOL toolbarPresent, CGFloat topInset) { CGFloat doodleTopMargin(BOOL toolbarPresent,
if (!IsCompactWidth() && !IsCompactHeight()) CGFloat topInset,
UITraitCollection* traitCollection) {
if (IsRegularXRegularSizeClass(traitCollection))
return kDoodleTopMarginRegularXRegular; return kDoodleTopMarginRegularXRegular;
if (IsCompactHeight()) if (IsCompactHeight(traitCollection))
return topInset; return topInset;
return topInset + kDoodleTopMarginOther + return topInset + kDoodleTopMarginOther +
AlignValueToPixel(kDoodleScaledTopMarginOther * AlignValueToPixel(kDoodleScaledTopMarginOther *
...@@ -79,8 +81,9 @@ CGFloat searchFieldTopMargin() { ...@@ -79,8 +81,9 @@ CGFloat searchFieldTopMargin() {
return kSearchFieldTopMargin; return kSearchFieldTopMargin;
} }
CGFloat searchFieldWidth(CGFloat superviewWidth) { CGFloat searchFieldWidth(CGFloat superviewWidth,
if (!IsCompactWidth() && !IsCompactHeight()) UITraitCollection* traitCollection) {
if (!IsCompactWidth(traitCollection) && !IsCompactHeight(traitCollection))
return kSearchFieldLarge; return kSearchFieldLarge;
// Special case for narrow sizes. // Special case for narrow sizes.
...@@ -90,14 +93,15 @@ CGFloat searchFieldWidth(CGFloat superviewWidth) { ...@@ -90,14 +93,15 @@ CGFloat searchFieldWidth(CGFloat superviewWidth) {
CGFloat heightForLogoHeader(BOOL logoIsShowing, CGFloat heightForLogoHeader(BOOL logoIsShowing,
BOOL promoCanShow, BOOL promoCanShow,
BOOL toolbarPresent, BOOL toolbarPresent,
CGFloat topInset) { CGFloat topInset,
UITraitCollection* traitCollection) {
CGFloat headerHeight = CGFloat headerHeight =
doodleTopMargin(toolbarPresent, topInset) + doodleHeight(logoIsShowing) + doodleTopMargin(toolbarPresent, topInset, traitCollection) +
searchFieldTopMargin() + doodleHeight(logoIsShowing, traitCollection) + searchFieldTopMargin() +
ToolbarExpandedHeight( ToolbarExpandedHeight(
[UIApplication sharedApplication].preferredContentSizeCategory) + [UIApplication sharedApplication].preferredContentSizeCategory) +
kNTPSearchFieldBottomPadding; kNTPSearchFieldBottomPadding;
if (!IsRegularXRegularSizeClass()) { if (!IsRegularXRegularSizeClass(traitCollection)) {
return headerHeight; return headerHeight;
} }
if (!logoIsShowing) { if (!logoIsShowing) {
......
...@@ -21,86 +21,41 @@ CGFloat kTopInset = 20; ...@@ -21,86 +21,41 @@ CGFloat kTopInset = 20;
class ContentSuggestionsCollectionUtilsTest : public PlatformTest { class ContentSuggestionsCollectionUtilsTest : public PlatformTest {
public: public:
void SetAsIPad() { UITraitCollection* IPadTraitCollection() {
UITraitCollection* horizontalRegular = [UITraitCollection UITraitCollection* horizontalRegular = [UITraitCollection
traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular]; traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
UITraitCollection* verticalRegular = [UITraitCollection UITraitCollection* verticalRegular = [UITraitCollection
traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular]; traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular];
UITraitCollection* custom_trait_collection = return [UITraitCollection traitCollectionWithTraitsFromCollections:@[
[UITraitCollection traitCollectionWithTraitsFromCollections:@[ verticalRegular, horizontalRegular
verticalRegular, horizontalRegular ]];
]];
SetSwizzlersUp(custom_trait_collection, UIUserInterfaceIdiomPad,
UIInterfaceOrientationPortrait);
} }
void SetAsIPhoneLandscape() { UITraitCollection* IPhoneLandscapeTraitCollection() {
UITraitCollection* horizontalCompact = [UITraitCollection UITraitCollection* horizontalCompact = [UITraitCollection
traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]; traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
UITraitCollection* verticalCompact = [UITraitCollection UITraitCollection* verticalCompact = [UITraitCollection
traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassCompact]; traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassCompact];
UITraitCollection* custom_trait_collection = return [UITraitCollection traitCollectionWithTraitsFromCollections:@[
[UITraitCollection traitCollectionWithTraitsFromCollections:@[ verticalCompact, horizontalCompact
verticalCompact, horizontalCompact ]];
]];
SetSwizzlersUp(custom_trait_collection, UIUserInterfaceIdiomPhone,
UIInterfaceOrientationLandscapeLeft);
} }
void SetAsIPhonePortrait() { UITraitCollection* IPhonePortraitTraitCollection() {
UITraitCollection* horizontalCompact = [UITraitCollection UITraitCollection* horizontalCompact = [UITraitCollection
traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact]; traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassCompact];
UITraitCollection* verticalRegular = [UITraitCollection UITraitCollection* verticalRegular = [UITraitCollection
traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular]; traitCollectionWithVerticalSizeClass:UIUserInterfaceSizeClassRegular];
UITraitCollection* custom_trait_collection = return [UITraitCollection traitCollectionWithTraitsFromCollections:@[
[UITraitCollection traitCollectionWithTraitsFromCollections:@[ verticalRegular, horizontalCompact
verticalRegular, horizontalCompact ]];
]];
SetSwizzlersUp(custom_trait_collection, UIUserInterfaceIdiomPhone,
UIInterfaceOrientationPortrait);
}
private:
// Sets up the swizzler for the different parameters passed.
void SetSwizzlersUp(UITraitCollection* custom_trait_collection,
UIUserInterfaceIdiom custom_interface,
UIInterfaceOrientation custom_orientation) {
customTraitCollection_ = custom_trait_collection;
trait_swizzler_ = std::make_unique<ScopedBlockSwizzler>(
[UIWindow class], @selector(traitCollection),
^UITraitCollection*(id self) {
return customTraitCollection_;
});
device_type_swizzler_ = std::make_unique<ScopedBlockSwizzler>(
[UIDevice class], @selector(userInterfaceIdiom),
^UIUserInterfaceIdiom(id self) {
return custom_interface;
});
orientation_swizzler_ = std::make_unique<ScopedBlockSwizzler>(
[UIApplication class], @selector(statusBarOrientation),
^UIInterfaceOrientation(id self) {
return custom_orientation;
});
} }
UITraitCollection* customTraitCollection_;
std::unique_ptr<ScopedBlockSwizzler> trait_swizzler_;
std::unique_ptr<ScopedBlockSwizzler> device_type_swizzler_;
std::unique_ptr<ScopedBlockSwizzler> orientation_swizzler_;
}; };
TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPad) { TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPad) {
// Setup.
SetAsIPad();
// Action. // Action.
CGFloat height = doodleHeight(YES); CGFloat height = doodleHeight(YES, IPadTraitCollection());
CGFloat topMargin = doodleTopMargin(YES, kTopInset); CGFloat topMargin = doodleTopMargin(YES, kTopInset, IPadTraitCollection());
// Test. // Test.
EXPECT_EQ(120, height); EXPECT_EQ(120, height);
...@@ -108,13 +63,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPad) { ...@@ -108,13 +63,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPad) {
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhonePortrait) { TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhonePortrait) {
// Setup.
SetAsIPhonePortrait();
// Action. // Action.
CGFloat heightLogo = doodleHeight(YES); CGFloat heightLogo = doodleHeight(YES, IPhonePortraitTraitCollection());
CGFloat heightNoLogo = doodleHeight(NO); CGFloat heightNoLogo = doodleHeight(NO, IPhonePortraitTraitCollection());
CGFloat topMargin = doodleTopMargin(YES, kTopInset); CGFloat topMargin =
doodleTopMargin(YES, kTopInset, IPhonePortraitTraitCollection());
// Test. // Test.
EXPECT_EQ(120, heightLogo); EXPECT_EQ(120, heightLogo);
...@@ -123,13 +76,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhonePortrait) { ...@@ -123,13 +76,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhonePortrait) {
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhoneLandscape) { TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhoneLandscape) {
// Setup.
SetAsIPhoneLandscape();
// Action. // Action.
CGFloat heightLogo = doodleHeight(YES); CGFloat heightLogo = doodleHeight(YES, IPhoneLandscapeTraitCollection());
CGFloat heightNoLogo = doodleHeight(NO); CGFloat heightNoLogo = doodleHeight(NO, IPhoneLandscapeTraitCollection());
CGFloat topMargin = doodleTopMargin(YES, kTopInset); CGFloat topMargin =
doodleTopMargin(YES, kTopInset, IPhoneLandscapeTraitCollection());
// Test. // Test.
EXPECT_EQ(120, heightLogo); EXPECT_EQ(120, heightLogo);
...@@ -139,13 +90,13 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhoneLandscape) { ...@@ -139,13 +90,13 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, doodleFrameIPhoneLandscape) {
TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPad) { TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPad) {
// Setup. // Setup.
SetAsIPad();
CGFloat width = 500; CGFloat width = 500;
CGFloat largeIPadWidth = 1366; CGFloat largeIPadWidth = 1366;
// Action. // Action.
CGFloat resultWidth = searchFieldWidth(width); CGFloat resultWidth = searchFieldWidth(width, IPadTraitCollection());
CGFloat resultWidthLargeIPad = searchFieldWidth(largeIPadWidth); CGFloat resultWidthLargeIPad =
searchFieldWidth(largeIPadWidth, IPadTraitCollection());
CGFloat topMargin = searchFieldTopMargin(); CGFloat topMargin = searchFieldTopMargin();
// Test. // Test.
...@@ -156,11 +107,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPad) { ...@@ -156,11 +107,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPad) {
TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhonePortrait) { TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhonePortrait) {
// Setup. // Setup.
SetAsIPhonePortrait();
CGFloat width = 500; CGFloat width = 500;
// Action. // Action.
CGFloat resultWidth = searchFieldWidth(width); CGFloat resultWidth =
searchFieldWidth(width, IPhonePortraitTraitCollection());
CGFloat topMargin = searchFieldTopMargin(); CGFloat topMargin = searchFieldTopMargin();
// Test. // Test.
...@@ -170,11 +121,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhonePortrait) { ...@@ -170,11 +121,11 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhonePortrait) {
TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhoneLandscape) { TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhoneLandscape) {
// Setup. // Setup.
SetAsIPhoneLandscape();
CGFloat width = 500; CGFloat width = 500;
// Action. // Action.
CGFloat resultWidth = searchFieldWidth(width); CGFloat resultWidth =
searchFieldWidth(width, IPhoneLandscapeTraitCollection());
CGFloat topMargin = searchFieldTopMargin(); CGFloat topMargin = searchFieldTopMargin();
// Test. // Test.
...@@ -183,25 +134,23 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhoneLandscape) { ...@@ -183,25 +134,23 @@ TEST_F(ContentSuggestionsCollectionUtilsTest, searchFieldFrameIPhoneLandscape) {
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPad) { TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPad) {
// Setup.
SetAsIPad();
// Action, tests. // Action, tests.
EXPECT_EQ(382, heightForLogoHeader(YES, YES, YES, 0)); EXPECT_EQ(382, heightForLogoHeader(YES, YES, YES, 0, IPadTraitCollection()));
EXPECT_EQ(406, heightForLogoHeader(YES, NO, YES, 0)); EXPECT_EQ(406, heightForLogoHeader(YES, NO, YES, 0, IPadTraitCollection()));
EXPECT_EQ(382, heightForLogoHeader(YES, YES, NO, 0)); EXPECT_EQ(382, heightForLogoHeader(YES, YES, NO, 0, IPadTraitCollection()));
EXPECT_EQ(406, heightForLogoHeader(YES, NO, NO, 0)); EXPECT_EQ(406, heightForLogoHeader(YES, NO, NO, 0, IPadTraitCollection()));
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) { TEST_F(ContentSuggestionsCollectionUtilsTest, heightForLogoHeaderIPhone) {
// Setup.
SetAsIPhonePortrait();
// Action, tests. // Action, tests.
EXPECT_EQ(278, heightForLogoHeader(YES, YES, YES, 0)); EXPECT_EQ(278, heightForLogoHeader(YES, YES, YES, 0,
EXPECT_EQ(278, heightForLogoHeader(YES, NO, YES, 0)); IPhonePortraitTraitCollection()));
EXPECT_EQ(278, heightForLogoHeader(YES, YES, NO, 0)); EXPECT_EQ(278, heightForLogoHeader(YES, NO, YES, 0,
EXPECT_EQ(278, heightForLogoHeader(YES, NO, NO, 0)); IPhonePortraitTraitCollection()));
EXPECT_EQ(278, heightForLogoHeader(YES, YES, NO, 0,
IPhonePortraitTraitCollection()));
EXPECT_EQ(278, heightForLogoHeader(YES, NO, NO, 0,
IPhonePortraitTraitCollection()));
} }
TEST_F(ContentSuggestionsCollectionUtilsTest, NearestAncestor) { TEST_F(ContentSuggestionsCollectionUtilsTest, NearestAncestor) {
......
...@@ -313,7 +313,7 @@ CGFloat ToolbarHeight() { ...@@ -313,7 +313,7 @@ CGFloat ToolbarHeight() {
return; return;
CGFloat searchFieldNormalWidth = CGFloat searchFieldNormalWidth =
content_suggestions::searchFieldWidth(contentWidth); content_suggestions::searchFieldWidth(contentWidth, self.traitCollection);
CGFloat percent = CGFloat percent =
[self searchFieldProgressForOffset:offset safeAreaInsets:safeAreaInsets]; [self searchFieldProgressForOffset:offset safeAreaInsets:safeAreaInsets];
......
...@@ -133,7 +133,7 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -133,7 +133,7 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
void (^transition)(id<UIViewControllerTransitionCoordinatorContext>) = void (^transition)(id<UIViewControllerTransitionCoordinatorContext>) =
^(id<UIViewControllerTransitionCoordinatorContext> context) { ^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Ensure omnibox is reset when not a regular tablet. // Ensure omnibox is reset when not a regular tablet.
if (IsSplitToolbarMode()) { if (IsSplitToolbarMode(newCollection)) {
[self.toolbarDelegate setScrollProgressForTabletOmnibox:1]; [self.toolbarDelegate setScrollProgressForTabletOmnibox:1];
} }
// Fake Tap button only needs to work in portrait. Disable the button // Fake Tap button only needs to work in portrait. Disable the button
...@@ -161,7 +161,7 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -161,7 +161,7 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
safeAreaInsets:safeAreaInsets] safeAreaInsets:safeAreaInsets]
// RxR with no logo hides the fakebox, so always show the omnibox. // RxR with no logo hides the fakebox, so always show the omnibox.
: 1; : 1;
if (!IsSplitToolbarMode()) { if (!IsSplitToolbarMode(self)) {
[self.toolbarDelegate setScrollProgressForTabletOmnibox:progress]; [self.toolbarDelegate setScrollProgressForTabletOmnibox:progress];
} else { } else {
// Ensure omnibox is reset when not a regular tablet. // Ensure omnibox is reset when not a regular tablet.
...@@ -182,7 +182,7 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -182,7 +182,7 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
- (void)updateFakeOmniboxForWidth:(CGFloat)width { - (void)updateFakeOmniboxForWidth:(CGFloat)width {
self.fakeOmniboxWidthConstraint.constant = self.fakeOmniboxWidthConstraint.constant =
content_suggestions::searchFieldWidth(width); content_suggestions::searchFieldWidth(width, self.traitCollection);
} }
- (void)unfocusOmnibox { - (void)unfocusOmnibox {
...@@ -200,13 +200,15 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -200,13 +200,15 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
// Update the doodle top margin to the new -doodleTopMargin value. // Update the doodle top margin to the new -doodleTopMargin value.
- (void)updateConstraints { - (void)updateConstraints {
self.doodleTopMarginConstraint.constant = self.doodleTopMarginConstraint.constant =
content_suggestions::doodleTopMargin(YES, [self topInset]); content_suggestions::doodleTopMargin(YES, [self topInset],
self.traitCollection);
[self.headerView updateForTopSafeAreaInset:[self topInset]]; [self.headerView updateForTopSafeAreaInset:[self topInset]];
} }
- (CGFloat)pinnedOffsetY { - (CGFloat)pinnedOffsetY {
CGFloat headerHeight = content_suggestions::heightForLogoHeader( CGFloat headerHeight = content_suggestions::heightForLogoHeader(
self.logoIsShowing, self.promoCanShow, YES, [self topInset]); self.logoIsShowing, self.promoCanShow, YES, [self topInset],
self.traitCollection);
CGFloat offsetY = CGFloat offsetY =
headerHeight - ntp_header::kScrolledToTopOmniboxBottomMargin; headerHeight - ntp_header::kScrolledToTopOmniboxBottomMargin;
...@@ -231,7 +233,8 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -231,7 +233,8 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
- (CGFloat)headerHeight { - (CGFloat)headerHeight {
return content_suggestions::heightForLogoHeader( return content_suggestions::heightForLogoHeader(
self.logoIsShowing, self.promoCanShow, YES, [self topInset]); self.logoIsShowing, self.promoCanShow, YES, [self topInset],
self.traitCollection);
} }
#pragma mark - ContentSuggestionsHeaderProvider #pragma mark - ContentSuggestionsHeaderProvider
...@@ -271,7 +274,8 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -271,7 +274,8 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
0, width - safeAreaInsets.left - safeAreaInsets.right); 0, width - safeAreaInsets.left - safeAreaInsets.right);
self.fakeOmniboxWidthConstraint = [self.fakeOmnibox.widthAnchor self.fakeOmniboxWidthConstraint = [self.fakeOmnibox.widthAnchor
constraintEqualToConstant:content_suggestions::searchFieldWidth(width)]; constraintEqualToConstant:content_suggestions::searchFieldWidth(
width, self.traitCollection)];
[self addConstraintsForLogoView:self.logoVendor.view [self addConstraintsForLogoView:self.logoVendor.view
fakeOmnibox:self.fakeOmnibox fakeOmnibox:self.fakeOmnibox
andHeaderView:self.headerView]; andHeaderView:self.headerView];
...@@ -461,7 +465,8 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -461,7 +465,8 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
// shows fakebox if the logo is visible and hides otherwise // shows fakebox if the logo is visible and hides otherwise
- (void)updateFakeboxDisplay { - (void)updateFakeboxDisplay {
[self.doodleHeightConstraint [self.doodleHeightConstraint
setConstant:content_suggestions::doodleHeight(self.logoIsShowing)]; setConstant:content_suggestions::doodleHeight(self.logoIsShowing,
self.traitCollection)];
self.fakeOmnibox.hidden = self.fakeOmnibox.hidden =
IsRegularXRegularSizeClass(self) && !self.logoIsShowing; IsRegularXRegularSizeClass(self) && !self.logoIsShowing;
[self.collectionSynchronizer invalidateLayout]; [self.collectionSynchronizer invalidateLayout];
...@@ -493,10 +498,10 @@ const NSString* kScribbleFakeboxElementId = @"fakebox"; ...@@ -493,10 +498,10 @@ const NSString* kScribbleFakeboxElementId = @"fakebox";
self.doodleTopMarginConstraint = [logoView.topAnchor self.doodleTopMarginConstraint = [logoView.topAnchor
constraintEqualToAnchor:headerView.topAnchor constraintEqualToAnchor:headerView.topAnchor
constant:content_suggestions::doodleTopMargin( constant:content_suggestions::doodleTopMargin(
YES, [self topInset])]; YES, [self topInset], self.traitCollection)];
self.doodleHeightConstraint = [logoView.heightAnchor self.doodleHeightConstraint = [logoView.heightAnchor
constraintEqualToConstant:content_suggestions::doodleHeight( constraintEqualToConstant:content_suggestions::doodleHeight(
self.logoIsShowing)]; self.logoIsShowing, self.traitCollection)];
self.fakeOmniboxHeightConstraint = [fakeOmnibox.heightAnchor self.fakeOmniboxHeightConstraint = [fakeOmnibox.heightAnchor
constraintEqualToConstant:ToolbarExpandedHeight( constraintEqualToConstant:ToolbarExpandedHeight(
self.traitCollection self.traitCollection
......
...@@ -591,8 +591,8 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix = ...@@ -591,8 +591,8 @@ NSString* const kContentSuggestionsMostVisitedAccessibilityIdentifierPrefix =
parentInset.right = margin; parentInset.right = margin;
} else if (self.styler.cellStyle == MDCCollectionViewCellStyleCard) { } else if (self.styler.cellStyle == MDCCollectionViewCellStyleCard) {
CGFloat collectionWidth = collectionView.bounds.size.width; CGFloat collectionWidth = collectionView.bounds.size.width;
CGFloat maxCardWidth = CGFloat maxCardWidth = content_suggestions::searchFieldWidth(
content_suggestions::searchFieldWidth(collectionWidth); collectionWidth, self.traitCollection);
CGFloat margin = CGFloat margin =
MAX(0, (collectionView.frame.size.width - maxCardWidth) / 2); MAX(0, (collectionView.frame.size.width - maxCardWidth) / 2);
parentInset.left = margin; parentInset.left = margin;
......
...@@ -237,13 +237,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) { ...@@ -237,13 +237,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) {
EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug."); EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug.");
} }
[ChromeEarlGreyUI waitForAppToIdle]; [ChromeEarlGreyUI waitForAppToIdle];
UIEdgeInsets safeArea = UICollectionView* collectionView =
[ContentSuggestionsAppInterface collectionView].safeAreaInsets; [ContentSuggestionsAppInterface collectionView];
CGFloat collectionWidth = CGRectGetWidth(UIEdgeInsetsInsetRect( UIEdgeInsets safeArea = collectionView.safeAreaInsets;
[ContentSuggestionsAppInterface collectionView].bounds, safeArea)); CGFloat collectionWidth =
CGRectGetWidth(UIEdgeInsetsInsetRect(collectionView.bounds, safeArea));
GREYAssertTrue(collectionWidth > 0, @"The collection width is nil."); GREYAssertTrue(collectionWidth > 0, @"The collection width is nil.");
CGFloat fakeOmniboxWidth = [ContentSuggestionsAppInterface CGFloat fakeOmniboxWidth = [ContentSuggestionsAppInterface
searchFieldWidthForCollectionWidth:collectionWidth]; searchFieldWidthForCollectionWidth:collectionWidth
traitCollection:collectionView.traitCollection];
[[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)]; assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
...@@ -257,13 +259,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) { ...@@ -257,13 +259,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) {
[ChromeEarlGreyUI waitForAppToIdle]; [ChromeEarlGreyUI waitForAppToIdle];
safeArea = [ContentSuggestionsAppInterface collectionView].safeAreaInsets; collectionView = [ContentSuggestionsAppInterface collectionView];
CGFloat collectionWidthAfterRotation = CGRectGetWidth(UIEdgeInsetsInsetRect( safeArea = collectionView.safeAreaInsets;
[ContentSuggestionsAppInterface collectionView].bounds, safeArea)); CGFloat collectionWidthAfterRotation =
CGRectGetWidth(UIEdgeInsetsInsetRect(collectionView.bounds, safeArea));
GREYAssertNotEqual(collectionWidth, collectionWidthAfterRotation, GREYAssertNotEqual(collectionWidth, collectionWidthAfterRotation,
@"The collection width has not changed."); @"The collection width has not changed.");
fakeOmniboxWidth = [ContentSuggestionsAppInterface fakeOmniboxWidth = [ContentSuggestionsAppInterface
searchFieldWidthForCollectionWidth:collectionWidthAfterRotation]; searchFieldWidthForCollectionWidth:collectionWidthAfterRotation
traitCollection:collectionView.traitCollection];
[[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)]; assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
...@@ -278,13 +282,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) { ...@@ -278,13 +282,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) {
EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug."); EARL_GREY_TEST_DISABLED(@"Disabled for iPad due to device rotation bug.");
} }
[ChromeEarlGreyUI waitForAppToIdle]; [ChromeEarlGreyUI waitForAppToIdle];
UIEdgeInsets safeArea = UICollectionView* collectionView =
[ContentSuggestionsAppInterface collectionView].safeAreaInsets; [ContentSuggestionsAppInterface collectionView];
CGFloat collectionWidth = CGRectGetWidth(UIEdgeInsetsInsetRect( UIEdgeInsets safeArea = collectionView.safeAreaInsets;
[ContentSuggestionsAppInterface collectionView].bounds, safeArea)); CGFloat collectionWidth =
CGRectGetWidth(UIEdgeInsetsInsetRect(collectionView.bounds, safeArea));
GREYAssertTrue(collectionWidth > 0, @"The collection width is nil."); GREYAssertTrue(collectionWidth > 0, @"The collection width is nil.");
CGFloat fakeOmniboxWidth = [ContentSuggestionsAppInterface CGFloat fakeOmniboxWidth = [ContentSuggestionsAppInterface
searchFieldWidthForCollectionWidth:collectionWidth]; searchFieldWidthForCollectionWidth:collectionWidth
traitCollection:collectionView.traitCollection];
[[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)]; assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
...@@ -303,13 +309,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) { ...@@ -303,13 +309,15 @@ id<GREYMatcher> OmniboxWidthBetween(CGFloat width, CGFloat margin) {
[[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsDoneButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::SettingsDoneButton()]
performAction:grey_tap()]; performAction:grey_tap()];
safeArea = [ContentSuggestionsAppInterface collectionView].safeAreaInsets; collectionView = [ContentSuggestionsAppInterface collectionView];
CGFloat collectionWidthAfterRotation = CGRectGetWidth(UIEdgeInsetsInsetRect( safeArea = collectionView.safeAreaInsets;
[ContentSuggestionsAppInterface collectionView].bounds, safeArea)); CGFloat collectionWidthAfterRotation =
CGRectGetWidth(UIEdgeInsetsInsetRect(collectionView.bounds, safeArea));
GREYAssertNotEqual(collectionWidth, collectionWidthAfterRotation, GREYAssertNotEqual(collectionWidth, collectionWidthAfterRotation,
@"The collection width has not changed."); @"The collection width has not changed.");
fakeOmniboxWidth = [ContentSuggestionsAppInterface fakeOmniboxWidth = [ContentSuggestionsAppInterface
searchFieldWidthForCollectionWidth:collectionWidthAfterRotation]; searchFieldWidthForCollectionWidth:collectionWidthAfterRotation
traitCollection:collectionView.traitCollection];
[[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()] [[EarlGrey selectElementWithMatcher:chrome_test_util::FakeOmnibox()]
assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)]; assertWithMatcher:OmniboxWidth(fakeOmniboxWidth)];
......
...@@ -202,6 +202,9 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor, ...@@ -202,6 +202,9 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor,
// Whether the |environment| has a compact horizontal size class. // Whether the |environment| has a compact horizontal size class.
bool IsCompactWidth(id<UITraitEnvironment> environment); bool IsCompactWidth(id<UITraitEnvironment> environment);
// Whether the |traitCollection| has a compact horizontal size class.
bool IsCompactWidth(UITraitCollection* traitCollection);
// Whether the main application window's rootViewController has a compact // Whether the main application window's rootViewController has a compact
// horizontal size class. // horizontal size class.
bool IsCompactWidth(); bool IsCompactWidth();
...@@ -220,6 +223,9 @@ bool IsCompactHeight(); ...@@ -220,6 +223,9 @@ bool IsCompactHeight();
// Whether the |environment| has a compact vertical size class. // Whether the |environment| has a compact vertical size class.
bool IsCompactHeight(id<UITraitEnvironment> environment); bool IsCompactHeight(id<UITraitEnvironment> environment);
// Whether the |traitCollection| has a compact vertical size class.
bool IsCompactHeight(UITraitCollection* traitCollection);
// Whether toolbar should be shown in compact mode. // Whether toolbar should be shown in compact mode.
bool ShouldShowCompactToolbar(); bool ShouldShowCompactToolbar();
// Whether toolbar should be shown in compact mode in |traitCollection|. // Whether toolbar should be shown in compact mode in |traitCollection|.
...@@ -243,6 +249,10 @@ bool IsSplitToolbarMode(); ...@@ -243,6 +249,10 @@ bool IsSplitToolbarMode();
// toolbar or if it is displayed as only one toolbar. // toolbar or if it is displayed as only one toolbar.
bool IsSplitToolbarMode(id<UITraitEnvironment> environment); bool IsSplitToolbarMode(id<UITraitEnvironment> environment);
// Returns whether the |traitCollection|'s toolbar is split between top and
// bottom toolbar or if it is displayed as only one toolbar.
bool IsSplitToolbarMode(UITraitCollection* traitCollection);
// Returns the current first responder for keyWindow. // Returns the current first responder for keyWindow.
UIResponder* GetFirstResponder(); UIResponder* GetFirstResponder();
......
...@@ -572,8 +572,11 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor, ...@@ -572,8 +572,11 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor,
} }
bool IsCompactWidth(id<UITraitEnvironment> environment) { bool IsCompactWidth(id<UITraitEnvironment> environment) {
return environment.traitCollection.horizontalSizeClass == return IsCompactWidth(environment.traitCollection);
UIUserInterfaceSizeClassCompact; }
bool IsCompactWidth(UITraitCollection* traitCollection) {
return traitCollection.horizontalSizeClass == UIUserInterfaceSizeClassCompact;
} }
bool IsCompactWidth() { bool IsCompactWidth() {
...@@ -594,8 +597,11 @@ bool IsCompactHeight() { ...@@ -594,8 +597,11 @@ bool IsCompactHeight() {
} }
bool IsCompactHeight(id<UITraitEnvironment> environment) { bool IsCompactHeight(id<UITraitEnvironment> environment) {
return environment.traitCollection.verticalSizeClass == return IsCompactHeight(environment.traitCollection);
UIUserInterfaceSizeClassCompact; }
bool IsCompactHeight(UITraitCollection* traitCollection) {
return traitCollection.verticalSizeClass == UIUserInterfaceSizeClassCompact;
} }
bool IsRegularXRegularSizeClass() { bool IsRegularXRegularSizeClass() {
...@@ -621,11 +627,16 @@ bool ShouldShowCompactToolbar() { ...@@ -621,11 +627,16 @@ bool ShouldShowCompactToolbar() {
} }
bool IsSplitToolbarMode() { bool IsSplitToolbarMode() {
return IsCompactWidth() && !IsCompactHeight(); return IsSplitToolbarMode(
[UIApplication sharedApplication].keyWindow.traitCollection);
} }
bool IsSplitToolbarMode(id<UITraitEnvironment> environment) { bool IsSplitToolbarMode(id<UITraitEnvironment> environment) {
return IsCompactWidth(environment) && !IsCompactHeight(environment); return IsSplitToolbarMode(environment.traitCollection);
}
bool IsSplitToolbarMode(UITraitCollection* traitCollection) {
return IsCompactWidth(traitCollection) && !IsCompactHeight(traitCollection);
} }
UIView* GetFirstResponderSubview(UIView* view) { UIView* GetFirstResponderSubview(UIView* view) {
......
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