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