Commit b6b687f8 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Update the style of the TabGrid PopupMenu

This CL changes the style of the PopupMenu associated with the tab grid
button. If the action is destructive (closing the/all tabs), the action
is tinted in red.
Also it adds the same icon for closing all incognito tabs as the one for
opening a new incognito tab.

Bug: 831152
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I84617985d0811d431e38ee58391dd22df1cfb8f0
Reviewed-on: https://chromium-review.googlesource.com/1051709Reviewed-by: default avatarOlivier Robin <olivierrobin@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#557854}
parent 7c357e04
......@@ -22,6 +22,9 @@
// Text to be displayed in the badge. Set to nil to hide the badge. The text
// badge is only displayed if the numbered badge is hidden.
@property(nonatomic, copy) NSString* badgeText;
// Whether the item is associated with a destructive action. If |YES|, then a
// specific styling is applied.
@property(nonatomic, assign) BOOL destructiveAction;
@end
......@@ -34,6 +37,10 @@
// Title label for the cell.
@property(nonatomic, strong, readonly) UILabel* titleLabel;
// Whether the cell is associated with a destructive action. If |YES|, then a
// specific styling is applied.
@property(nonatomic, assign) BOOL destructiveAction;
// Sets the number on the badge number.
- (void)setBadgeNumber:(NSInteger)badgeNumber;
// Sets the text of the badge text. Hides the badge text if |badgeText| is nil.
......
......@@ -20,7 +20,8 @@
#endif
namespace {
const int kEnabledColor = 0x1A73E8;
const int kEnabledDefaultColor = 0x1A73E8;
const int kEnabledDestructiveColor = 0xEA4334;
const CGFloat kImageLength = 28;
const CGFloat kCellHeight = 44;
const CGFloat kInnerMargin = 11;
......@@ -40,6 +41,7 @@ NSString* const kToolsMenuTextBadgeAccessibilityIdentifier =
@synthesize image = _image;
@synthesize title = _title;
@synthesize enabled = _enabled;
@synthesize destructiveAction = _destructiveAction;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
......@@ -57,6 +59,7 @@ NSString* const kToolsMenuTextBadgeAccessibilityIdentifier =
cell.imageView.image = self.image;
cell.accessibilityTraits = UIAccessibilityTraitButton;
cell.userInteractionEnabled = self.enabled;
cell.destructiveAction = self.destructiveAction;
[cell setBadgeNumber:self.badgeNumber];
[cell setBadgeText:self.badgeText];
}
......@@ -94,6 +97,9 @@ NSString* const kToolsMenuTextBadgeAccessibilityIdentifier =
@property(nonatomic, strong) TextBadgeView* textBadgeView;
// Constraints between the trailing of the label and the badges.
@property(nonatomic, strong) NSLayoutConstraint* titleToBadgeConstraint;
// Color for the title and the image.
@property(nonatomic, strong, readonly) UIColor* contentColor;
@end
@implementation PopupMenuToolsCell
......@@ -103,6 +109,7 @@ NSString* const kToolsMenuTextBadgeAccessibilityIdentifier =
@synthesize textBadgeView = _textBadgeView;
@synthesize titleLabel = _titleLabel;
@synthesize titleToBadgeConstraint = _titleToBadgeConstraint;
@synthesize destructiveAction = _destructiveAction;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
......@@ -219,6 +226,18 @@ NSString* const kToolsMenuTextBadgeAccessibilityIdentifier =
}
}
- (void)setDestructiveAction:(BOOL)destructiveAction {
_destructiveAction = destructiveAction;
self.titleLabel.textColor = self.contentColor;
self.imageView.tintColor = self.contentColor;
}
- (UIColor*)contentColor {
if (self.destructiveAction)
return UIColorFromRGB(kEnabledDestructiveColor);
return UIColorFromRGB(kEnabledDefaultColor);
}
- (void)layoutSubviews {
[super layoutSubviews];
......@@ -253,8 +272,8 @@ NSString* const kToolsMenuTextBadgeAccessibilityIdentifier =
- (void)setUserInteractionEnabled:(BOOL)userInteractionEnabled {
[super setUserInteractionEnabled:userInteractionEnabled];
if (userInteractionEnabled) {
self.titleLabel.textColor = UIColorFromRGB(kEnabledColor);
self.imageView.tintColor = UIColorFromRGB(kEnabledColor);
self.titleLabel.textColor = self.contentColor;
self.imageView.tintColor = self.contentColor;
} else {
self.titleLabel.textColor = [[self class] disabledColor];
self.imageView.tintColor = [[self class] disabledColor];
......
......@@ -550,15 +550,19 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
- (void)createTabGridMenuItems {
NSMutableArray* items = [NSMutableArray arrayWithArray:[self itemsForNewTab]];
if (self.isIncognito) {
[items addObject:CreateTableViewItem(
IDS_IOS_TOOLS_MENU_CLOSE_ALL_INCOGNITO_TABS,
PopupMenuActionCloseAllIncognitoTabs, nil,
kToolsMenuCloseAllIncognitoTabsId)];
PopupMenuToolsItem* closeAllIncognitoTabs = CreateTableViewItem(
IDS_IOS_TOOLS_MENU_CLOSE_ALL_INCOGNITO_TABS,
PopupMenuActionCloseAllIncognitoTabs, @"popup_menu_new_incognito_tab",
kToolsMenuCloseAllIncognitoTabsId);
closeAllIncognitoTabs.destructiveAction = YES;
[items addObject:closeAllIncognitoTabs];
}
[items addObject:CreateTableViewItem(
IDS_IOS_TOOLS_MENU_CLOSE_TAB, PopupMenuActionCloseTab,
@"popup_menu_close_tab", kToolsMenuCloseTabId)];
PopupMenuToolsItem* closeTab =
CreateTableViewItem(IDS_IOS_TOOLS_MENU_CLOSE_TAB, PopupMenuActionCloseTab,
@"popup_menu_close_tab", kToolsMenuCloseTabId);
closeTab.destructiveAction = YES;
[items addObject:closeTab];
self.items = @[ items ];
}
......
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