Commit 19c98807 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add util for the split toolbar mode

This CL adds an util to know when the toolbar is split.

Bug: 804748
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I7d6accb32de848ff2b3e0ff8aef68d7c278aeb9a
Reviewed-on: https://chromium-review.googlesource.com/916194Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#536961}
parent 34dd6fd1
...@@ -116,7 +116,7 @@ NSString* const kActivityServicesSnackbarCategory = ...@@ -116,7 +116,7 @@ NSString* const kActivityServicesSnackbarCategory =
CGRect fromRect = CGRectZero; CGRect fromRect = CGRectZero;
UIView* inView = nil; UIView* inView = nil;
if (IsIPadIdiom() && !IsCompact()) { if (IsIPadIdiom() && !IsCompactWidth()) {
DCHECK(positionProvider); DCHECK(positionProvider);
inView = [positionProvider shareButtonView]; inView = [positionProvider shareButtonView];
fromRect = inView.bounds; fromRect = inView.bounds;
......
...@@ -127,7 +127,7 @@ id<GREYMatcher> PrintButton() { ...@@ -127,7 +127,7 @@ id<GREYMatcher> PrintButton() {
GURL kURL("chrome://version"); GURL kURL("chrome://version");
[ChromeEarlGrey loadURL:kURL]; [ChromeEarlGrey loadURL:kURL];
// Verify that the share button is disabled. // Verify that the share button is disabled.
if (IsCompact()) { if (IsCompactWidth()) {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
} }
id<GREYMatcher> share_button = chrome_test_util::ShareButton(); id<GREYMatcher> share_button = chrome_test_util::ShareButton();
......
...@@ -200,10 +200,11 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -200,10 +200,11 @@ id<GREYMatcher> CloseToolsMenuButton() {
[BookmarksTestCase assertBookmarksWithTitle:bookmarkTitle expectedCount:1]; [BookmarksTestCase assertBookmarksWithTitle:bookmarkTitle expectedCount:1];
NSString* const kStarLitLabel = NSString* const kStarLitLabel =
!IsCompact() ? l10n_util::GetNSString(IDS_TOOLTIP_STAR) !IsCompactWidth()
: l10n_util::GetNSString(IDS_IOS_BOOKMARK_EDIT_SCREEN_TITLE); ? l10n_util::GetNSString(IDS_TOOLTIP_STAR)
: l10n_util::GetNSString(IDS_IOS_BOOKMARK_EDIT_SCREEN_TITLE);
// Verify the star is lit. // Verify the star is lit.
if (IsCompact()) { if (IsCompactWidth()) {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
} }
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kStarLitLabel)] [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kStarLitLabel)]
...@@ -223,11 +224,11 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -223,11 +224,11 @@ id<GREYMatcher> CloseToolsMenuButton() {
[BookmarksTestCase assertBookmarksWithTitle:bookmarkTitle expectedCount:0]; [BookmarksTestCase assertBookmarksWithTitle:bookmarkTitle expectedCount:0];
NSString* const kStarUnlitLabel = NSString* const kStarUnlitLabel =
!IsCompact() ? l10n_util::GetNSString(IDS_TOOLTIP_STAR) !IsCompactWidth() ? l10n_util::GetNSString(IDS_TOOLTIP_STAR)
: l10n_util::GetNSString(IDS_BOOKMARK_ADD_EDITOR_TITLE); : l10n_util::GetNSString(IDS_BOOKMARK_ADD_EDITOR_TITLE);
// Verify the star is not lit. // Verify the star is not lit.
if (IsCompact()) { if (IsCompactWidth()) {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
} }
[[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kStarUnlitLabel)] [[EarlGrey selectElementWithMatcher:grey_accessibilityLabel(kStarUnlitLabel)]
...@@ -235,7 +236,7 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -235,7 +236,7 @@ id<GREYMatcher> CloseToolsMenuButton() {
// TODO(crbug.com/617652): This code should be removed when a common helper // TODO(crbug.com/617652): This code should be removed when a common helper
// is added to close any menus, which should be run as test setup. // is added to close any menus, which should be run as test setup.
if (IsCompact()) { if (IsCompactWidth()) {
[[EarlGrey selectElementWithMatcher:CloseToolsMenuButton()] [[EarlGrey selectElementWithMatcher:CloseToolsMenuButton()]
performAction:grey_tap()]; performAction:grey_tap()];
} }
...@@ -547,7 +548,7 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -547,7 +548,7 @@ id<GREYMatcher> CloseToolsMenuButton() {
performAction:grey_tap()]; performAction:grey_tap()];
// Edit the bookmark. // Edit the bookmark.
if (!IsCompact()) { if (!IsCompactWidth()) {
[[EarlGrey selectElementWithMatcher:StarButton()] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:StarButton()] performAction:grey_tap()];
} else { } else {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
...@@ -3061,7 +3062,7 @@ id<GREYMatcher> CloseToolsMenuButton() { ...@@ -3061,7 +3062,7 @@ id<GREYMatcher> CloseToolsMenuButton() {
// Adds a bookmark for the current tab. Must be called when on a tab. // Adds a bookmark for the current tab. Must be called when on a tab.
+ (void)starCurrentTab { + (void)starCurrentTab {
if (!IsCompact()) { if (!IsCompactWidth()) {
[[EarlGrey selectElementWithMatcher:StarButton()] performAction:grey_tap()]; [[EarlGrey selectElementWithMatcher:StarButton()] performAction:grey_tap()];
} else { } else {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
......
...@@ -248,7 +248,7 @@ CGFloat kShadowOpacity = 0.2f; ...@@ -248,7 +248,7 @@ CGFloat kShadowOpacity = 0.2f;
if (!base::ios::IsRunningOnIOS10OrLater()) { if (!base::ios::IsRunningOnIOS10OrLater()) {
// TODO(crbug.com/620361): Remove the entire method override when iOS 9 is // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is
// dropped. // dropped.
if (IsIPadIdiom() && !IsCompact()) { if (IsIPadIdiom() && !IsCompactWidth()) {
return UIStatusBarStyleLightContent; return UIStatusBarStyleLightContent;
} else { } else {
return UIStatusBarStyleDefault; return UIStatusBarStyleDefault;
......
...@@ -81,7 +81,7 @@ CGFloat kHorizontalMargin = 16.0f; ...@@ -81,7 +81,7 @@ CGFloat kHorizontalMargin = 16.0f;
_stackView.translatesAutoresizingMaskIntoConstraints = NO; _stackView.translatesAutoresizingMaskIntoConstraints = NO;
_stackView.layoutMarginsRelativeArrangement = YES; _stackView.layoutMarginsRelativeArrangement = YES;
CGFloat topAnchorConstant = IsCompact() ? StatusBarHeight() : 0; CGFloat topAnchorConstant = IsCompactWidth() ? StatusBarHeight() : 0;
_topAnchorConstraint = _topAnchorConstraint =
[_stackView.topAnchor constraintEqualToAnchor:self.topAnchor [_stackView.topAnchor constraintEqualToAnchor:self.topAnchor
constant:topAnchorConstant]; constant:topAnchorConstant];
...@@ -128,7 +128,7 @@ CGFloat kHorizontalMargin = 16.0f; ...@@ -128,7 +128,7 @@ CGFloat kHorizontalMargin = 16.0f;
#pragma mark - UITraitEnvironment #pragma mark - UITraitEnvironment
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
self.topAnchorConstraint.constant = IsCompact() ? StatusBarHeight() : 0; self.topAnchorConstraint.constant = IsCompactWidth() ? StatusBarHeight() : 0;
} }
@end @end
...@@ -142,7 +142,7 @@ const CGFloat kRegularLayoutButtonWidth = 168; ...@@ -142,7 +142,7 @@ const CGFloat kRegularLayoutButtonWidth = 168;
} }
- (void)calculateButtonWidth { - (void)calculateButtonWidth {
if (IsCompact()) { if (IsCompactWidth()) {
if ([items_ count] > 0) { if ([items_ count] > 0) {
buttonWidth_ = self.contentView.bounds.size.width / [items_ count]; buttonWidth_ = self.contentView.bounds.size.width / [items_ count];
} else { } else {
......
...@@ -235,7 +235,7 @@ void PageInfoModelBubbleBridge::PerformLayout() { ...@@ -235,7 +235,7 @@ void PageInfoModelBubbleBridge::PerformLayout() {
UIInterfaceOrientation orientation = UIInterfaceOrientation orientation =
[[UIApplication sharedApplication] statusBarOrientation]; [[UIApplication sharedApplication] statusBarOrientation];
viewWidth_ = IsCompact() ? kViewWidthCompact : kViewWidthRegular; viewWidth_ = IsCompactWidth() ? kViewWidthCompact : kViewWidthRegular;
// Special case iPhone landscape. // Special case iPhone landscape.
if (!IsIPadIdiom() && UIInterfaceOrientationIsLandscape(orientation)) if (!IsIPadIdiom() && UIInterfaceOrientationIsLandscape(orientation))
viewWidth_ = kViewWidthiPhoneLandscape; viewWidth_ = kViewWidthiPhoneLandscape;
......
...@@ -112,7 +112,7 @@ const CGFloat kPercentageFromTopForPosition = 0.4; ...@@ -112,7 +112,7 @@ const CGFloat kPercentageFromTopForPosition = 0.4;
NSString* accessibilityInstructionString = @":"; NSString* accessibilityInstructionString = @":";
// Add the images inside the string. // Add the images inside the string.
if (IsCompact() || !IsIPadIdiom()) { if (IsCompactWidth() || !IsIPadIdiom()) {
// TODO(crbug.com/698726): When the share icon is displayed in the toolbar // TODO(crbug.com/698726): When the share icon is displayed in the toolbar
// for landscape iPhone 6+, remove !IsIPadIdiom(). // for landscape iPhone 6+, remove !IsIPadIdiom().
// If the device has a compact display the share menu is accessed from the // If the device has a compact display the share menu is accessed from the
......
...@@ -840,7 +840,7 @@ void SavePasswordsConsumer::OnGetPasswordStoreResults( ...@@ -840,7 +840,7 @@ void SavePasswordsConsumer::OnGetPasswordStoreResults(
UIView* sourceView = nil; UIView* sourceView = nil;
CGRect sourceRect = CGRectZero; CGRect sourceRect = CGRectZero;
if (IsIPadIdiom() && !IsCompact()) { if (IsIPadIdiom() && !IsCompactWidth()) {
NSIndexPath* indexPath = [self.collectionViewModel NSIndexPath* indexPath = [self.collectionViewModel
indexPathForItemType:ItemTypeExportPasswordsButton indexPathForItemType:ItemTypeExportPasswordsButton
sectionIdentifier:SectionIdentifierExportPasswordsButton]; sectionIdentifier:SectionIdentifierExportPasswordsButton];
......
...@@ -163,7 +163,7 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56; ...@@ -163,7 +163,7 @@ const CGFloat kActivityIndicatorDimensionIPhone = 56;
if (!base::ios::IsRunningOnIOS10OrLater()) { if (!base::ios::IsRunningOnIOS10OrLater()) {
// TODO(crbug.com/620361): Remove the entire method override when iOS 9 is // TODO(crbug.com/620361): Remove the entire method override when iOS 9 is
// dropped. // dropped.
if (IsIPadIdiom() && !IsCompact()) { if (IsIPadIdiom() && !IsCompactWidth()) {
return UIStatusBarStyleLightContent; return UIStatusBarStyleLightContent;
} else { } else {
return UIStatusBarStyleDefault; return UIStatusBarStyleDefault;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
// Test switching tabs using the tab strip. // Test switching tabs using the tab strip.
- (void)testTabStripSwitchTabs { - (void)testTabStripSwitchTabs {
// Only iPad has a tab strip. // Only iPad has a tab strip.
if (IsCompact()) { if (IsCompactWidth()) {
return; return;
} }
......
...@@ -109,6 +109,10 @@ ...@@ -109,6 +109,10 @@
} }
- (void)transitionToLocationBarFocusedState:(BOOL)focused { - (void)transitionToLocationBarFocusedState:(BOOL)focused {
if (!IsSplitToolbarMode()) {
// No animation when the toolbar is unsplit.
return;
}
[self.orchestrator transitionToStateFocused:focused animated:YES]; [self.orchestrator transitionToStateFocused:focused animated:YES];
} }
......
...@@ -42,7 +42,7 @@ id<GREYMatcher> FindInPageButton() { ...@@ -42,7 +42,7 @@ id<GREYMatcher> FindInPageButton() {
- (void)testOpenAndCloseToolsMenu { - (void)testOpenAndCloseToolsMenu {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
if (!IsCompact()) { if (!IsCompactWidth()) {
[[EarlGrey [[EarlGrey
selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString( selectElementWithMatcher:grey_accessibilityLabel(l10n_util::GetNSString(
IDS_IOS_TOOLBAR_CLOSE_MENU))] IDS_IOS_TOOLBAR_CLOSE_MENU))]
......
...@@ -48,6 +48,10 @@ bool IsTabSwitcherTabGridEnabled(); ...@@ -48,6 +48,10 @@ bool IsTabSwitcherTabGridEnabled();
// Returns the height of the status bar, accounting for orientation. // Returns the height of the status bar, accounting for orientation.
CGFloat StatusBarHeight(); CGFloat StatusBarHeight();
// Returns whether the toolbar is split between top and bottom toolbar or if it
// is displayed as only one toolbar.
bool IsSplitToolbarMode();
// Returns the closest pixel-aligned value less than |value|, taking the scale // Returns the closest pixel-aligned value less than |value|, taking the scale
// factor into account. At a scale of 1, equivalent to floor(). // factor into account. At a scale of 1, equivalent to floor().
CGFloat AlignValueToPixel(CGFloat value); CGFloat AlignValueToPixel(CGFloat value);
......
...@@ -89,6 +89,10 @@ CGFloat StatusBarHeight() { ...@@ -89,6 +89,10 @@ CGFloat StatusBarHeight() {
return isCompactHeight ? 0 : 20; return isCompactHeight ? 0 : 20;
} }
bool IsSplitToolbarMode() {
return IsCompactWidth() && !IsCompactHeight();
}
CGFloat AlignValueToPixel(CGFloat value) { CGFloat AlignValueToPixel(CGFloat value) {
static CGFloat scale = [[UIScreen mainScreen] scale]; static CGFloat scale = [[UIScreen mainScreen] scale];
return floor(value * scale) / scale; return floor(value * scale) / scale;
......
...@@ -185,11 +185,11 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor, ...@@ -185,11 +185,11 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor,
CGFloat fraction); CGFloat fraction);
// Whether the |environment| has a compact horizontal size class. // Whether the |environment| has a compact horizontal size class.
bool IsCompact(id<UITraitEnvironment> environment); bool IsCompactWidth(id<UITraitEnvironment> environment);
// 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 IsCompact(); bool IsCompactWidth();
// Whether the |environment| has a compact iPad horizontal size class. // Whether the |environment| has a compact iPad horizontal size class.
bool IsCompactTablet(id<UITraitEnvironment> environment); bool IsCompactTablet(id<UITraitEnvironment> environment);
...@@ -198,6 +198,10 @@ bool IsCompactTablet(id<UITraitEnvironment> environment); ...@@ -198,6 +198,10 @@ bool IsCompactTablet(id<UITraitEnvironment> environment);
// iPad horizontal size class. // iPad horizontal size class.
bool IsCompactTablet(); bool IsCompactTablet();
// Whether the main application window's rootViewController has a compact
// vertical size class.
bool IsCompactHeight();
// Returns the current first responder. // Returns the current first responder.
UIResponder* GetFirstResponder(); UIResponder* GetFirstResponder();
......
...@@ -527,22 +527,28 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor, ...@@ -527,22 +527,28 @@ UIColor* InterpolateFromColorToColor(UIColor* firstColor,
alpha:Lerp(a1, a2, fraction)]; alpha:Lerp(a1, a2, fraction)];
} }
bool IsCompact(id<UITraitEnvironment> environment) { bool IsCompactWidth(id<UITraitEnvironment> environment) {
return environment.traitCollection.horizontalSizeClass == return environment.traitCollection.horizontalSizeClass ==
UIUserInterfaceSizeClassCompact; UIUserInterfaceSizeClassCompact;
} }
bool IsCompact() { bool IsCompactWidth() {
UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow; UIWindow* keyWindow = [UIApplication sharedApplication].keyWindow;
return IsCompact(keyWindow); return IsCompactWidth(keyWindow);
} }
bool IsCompactTablet(id<UITraitEnvironment> environment) { bool IsCompactTablet(id<UITraitEnvironment> environment) {
return IsIPadIdiom() && IsCompact(environment); return IsIPadIdiom() && IsCompactWidth(environment);
} }
bool IsCompactTablet() { bool IsCompactTablet() {
return IsIPadIdiom() && IsCompact(); return IsIPadIdiom() && IsCompactWidth();
}
bool IsCompactHeight() {
return [UIApplication sharedApplication]
.keyWindow.traitCollection.verticalSizeClass ==
UIUserInterfaceSizeClassCompact;
} }
// Returns the current first responder. // Returns the current first responder.
......
...@@ -307,7 +307,7 @@ std::unique_ptr<net::test_server::HttpResponse> WindowLocationHashHandlers( ...@@ -307,7 +307,7 @@ std::unique_ptr<net::test_server::HttpResponse> WindowLocationHashHandlers(
assertWithMatcher:grey_notNil()]; assertWithMatcher:grey_notNil()];
// Verify that the forward button is not enabled. // Verify that the forward button is not enabled.
if (IsCompact()) { if (IsCompactWidth()) {
// In horizontally compact environments, the forward button is not visible. // In horizontally compact environments, the forward button is not visible.
[[EarlGrey selectElementWithMatcher:ForwardButton()] [[EarlGrey selectElementWithMatcher:ForwardButton()]
assertWithMatcher:grey_nil()]; assertWithMatcher:grey_nil()];
......
...@@ -129,7 +129,7 @@ id<GREYAction> ScrollDown() { ...@@ -129,7 +129,7 @@ id<GREYAction> ScrollDown() {
+ (void)reload { + (void)reload {
// On iPhone Reload button is a part of tools menu, so open it. // On iPhone Reload button is a part of tools menu, so open it.
if (IsCompact()) { if (IsCompactWidth()) {
[self openToolsMenu]; [self openToolsMenu];
} }
[[EarlGrey selectElementWithMatcher:chrome_test_util::ReloadButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ReloadButton()]
...@@ -137,7 +137,7 @@ id<GREYAction> ScrollDown() { ...@@ -137,7 +137,7 @@ id<GREYAction> ScrollDown() {
} }
+ (void)openShareMenu { + (void)openShareMenu {
if (IsCompact()) { if (IsCompactWidth()) {
[ChromeEarlGreyUI openToolsMenu]; [ChromeEarlGreyUI openToolsMenu];
} }
[[EarlGrey selectElementWithMatcher:chrome_test_util::ShareButton()] [[EarlGrey selectElementWithMatcher:chrome_test_util::ShareButton()]
......
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