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