Commit e5743ef0 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Fix bug of inconsistent button title for tabs count in toolbar and tab-grid

Add a helper function that returns text for tabs count:
(-inf, 0]   => ""
(0, 100)    => "num"
[100, +inf) => ":)"

Bug: 835801
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Ica4607b10dbd1f241d4e5a07c32128a1f4607db8
Reviewed-on: https://chromium-review.googlesource.com/1172297Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582552}
parent 7ce2f7ab
...@@ -108,15 +108,6 @@ CGPoint RectCenter(CGRect rect) { ...@@ -108,15 +108,6 @@ CGPoint RectCenter(CGRect rect) {
return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect)); return CGPointMake(CGRectGetMidX(rect), CGRectGetMidY(rect));
} }
// Returns the string to use for a numeric item count.
NSString* StringForItemCount(long count) {
if (count == 0)
return @"";
if (count > 99)
return @":-)";
return [NSString stringWithFormat:@"%ld", count];
}
// Convenience method that composes an asset name and returns the correct image // Convenience method that composes an asset name and returns the correct image
// (in template rendering mode) based on the segment name (one of "regular", // (in template rendering mode) based on the segment name (one of "regular",
// "incognito, "remote") and whether the selected state image is needed or not. // "incognito, "remote") and whether the selected state image is needed or not.
...@@ -240,7 +231,7 @@ UIImage* ImageForSegment(NSString* segment, BOOL selected) { ...@@ -240,7 +231,7 @@ UIImage* ImageForSegment(NSString* segment, BOOL selected) {
// visible when the slider is over a segment), and an ivar to store values that // visible when the slider is over a segment), and an ivar to store values that
// are set before the labels are created. // are set before the labels are created.
- (void)setRegularTabCount:(NSUInteger)regularTabCount { - (void)setRegularTabCount:(NSUInteger)regularTabCount {
NSString* regularText = StringForItemCount(regularTabCount); NSString* regularText = TextForTabCount(regularTabCount);
self.regularLabel.text = regularText; self.regularLabel.text = regularText;
self.regularSelectedLabel.text = regularText; self.regularSelectedLabel.text = regularText;
_regularTabCount = regularTabCount; _regularTabCount = regularTabCount;
......
...@@ -127,15 +127,6 @@ UIColor* BackgroundColor() { ...@@ -127,15 +127,6 @@ UIColor* BackgroundColor() {
return [UIColor colorWithRed:0.149 green:0.149 blue:0.164 alpha:1]; return [UIColor colorWithRed:0.149 green:0.149 blue:0.164 alpha:1];
} }
// Returns the string to use for a numeric item count.
NSString* StringForItemCount(long count) {
if (count == 0)
return @"";
if (count > 99)
return @":-)";
return [NSString stringWithFormat:@"%ld", count];
}
} // namespace } // namespace
// Helper class to display a UIButton with the image and text centered // Helper class to display a UIButton with the image and text centered
...@@ -1103,7 +1094,7 @@ NSString* StringForItemCount(long count) { ...@@ -1103,7 +1094,7 @@ NSString* StringForItemCount(long count) {
- (void)tabModelDidChangeTabCount:(TabModel*)model { - (void)tabModelDidChangeTabCount:(TabModel*)model {
if (IsUIRefreshPhase1Enabled()) { if (IsUIRefreshPhase1Enabled()) {
[_tabSwitcherButton setTitle:StringForItemCount(model.count) [_tabSwitcherButton setTitle:TextForTabCount(model.count)
forState:UIControlStateNormal]; forState:UIControlStateNormal];
} }
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/toolbar/buttons/toolbar_constants.h" #import "ios/chrome/browser/ui/toolbar/buttons/toolbar_constants.h"
#import "ios/chrome/browser/ui/toolbar/public/features.h" #import "ios/chrome/browser/ui/toolbar/public/features.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h" #import "ios/chrome/common/ui_util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -37,14 +38,7 @@ const CGFloat kLabelSize = 14; ...@@ -37,14 +38,7 @@ const CGFloat kLabelSize = 14;
// the button's title may be empty or contain an easter egg, but the // the button's title may be empty or contain an easter egg, but the
// accessibility value will always be equal to |tabCount|. // accessibility value will always be equal to |tabCount|.
NSString* tabStripButtonValue = [NSString stringWithFormat:@"%d", tabCount]; NSString* tabStripButtonValue = [NSString stringWithFormat:@"%d", tabCount];
NSString* tabStripButtonTitle = tabStripButtonValue; NSString* tabStripButtonTitle = TextForTabCount(tabCount);
if (tabCount <= 0) {
tabStripButtonTitle = @"";
} else if (tabCount > kShowTabStripButtonMaxTabCount) {
// As an easter egg, show a smiley face instead of the count if the user has
// more than 99 tabs open.
tabStripButtonTitle = @":)";
}
// TODO(crbug.com/799601): Delete this once its not needed. // TODO(crbug.com/799601): Delete this once its not needed.
if (base::FeatureList::IsEnabled(kMemexTabSwitcher)) { if (base::FeatureList::IsEnabled(kMemexTabSwitcher)) {
......
...@@ -236,4 +236,9 @@ void TriggerHapticFeedbackForNotification(UINotificationFeedbackType type); ...@@ -236,4 +236,9 @@ void TriggerHapticFeedbackForNotification(UINotificationFeedbackType type);
// Returns the safeAreaInsets for a given view. // Returns the safeAreaInsets for a given view.
UIEdgeInsets SafeAreaInsetsForView(UIView* view); UIEdgeInsets SafeAreaInsetsForView(UIView* view);
// Returns the text for tabs count to be displayed in toolbar and tab_grid.
// As an easter egg, show a smiley face instead of the count if the user has
// more than 99 tabs open.
NSString* TextForTabCount(long count);
#endif // IOS_CHROME_BROWSER_UI_UIKIT_UI_UTIL_H_ #endif // IOS_CHROME_BROWSER_UI_UIKIT_UI_UTIL_H_
...@@ -661,3 +661,11 @@ UIEdgeInsets SafeAreaInsetsForView(UIView* view) { ...@@ -661,3 +661,11 @@ UIEdgeInsets SafeAreaInsetsForView(UIView* view) {
return UIEdgeInsetsZero; return UIEdgeInsetsZero;
} }
} }
NSString* TextForTabCount(long count) {
if (count <= 0)
return @"";
if (count > 99)
return @":)";
return [NSString stringWithFormat:@"%ld", count];
}
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