Chromium Code Reviews| Index: ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.mm |
| diff --git a/ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.mm b/ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..5d9a9bd82abfaed47beb635bdb51193b9616616c |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.mm |
| @@ -0,0 +1,205 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" |
| + |
| +#include "base/mac/objc_property_releaser.h" |
| +#include "components/strings/grit/components_strings.h" |
| +#include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| +#include "ios/chrome/browser/ui/rtl_geometry.h" |
| +#include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" |
| +#import "ios/chrome/browser/ui/uikit_ui_util.h" |
| +#include "ios/chrome/grit/ios_strings.h" |
| + |
| +// TODO(crbug.com/228521): Remove this once the new command/metric handling is |
| +// implemented. This is a temporary workaround to allow metrics recording to |
| +// distinguish the action. The value used is in the dynamic range (< |
| +// IDC_MinimumLabelValue) to avoid collisions. |
| +#define IDC_TEMP_EDIT_BOOKMARK 3900 |
| + |
| +@implementation ToolsMenuViewToolsCell { |
| + base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewToolsCell; |
| +} |
| + |
| +@synthesize reloadButton = _reloadButton; |
| +@synthesize shareButton = _shareButton; |
| +@synthesize starButton = _starButton; |
| +@synthesize starredButton = _starredButton; |
| +@synthesize stopButton = _stopButton; |
| +@synthesize toolsButton = _toolsButton; |
| + |
| +- (instancetype)initWithCoder:(NSCoder*)aDecoder { |
| + self = [super initWithCoder:aDecoder]; |
| + if (self) |
| + [self commonInitialization]; |
| + |
| + return self; |
| +} |
| + |
| +- (instancetype)initWithFrame:(CGRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) |
| + [self commonInitialization]; |
| + |
| + return self; |
| +} |
| + |
| +- (void)commonInitialization { |
| + _propertyReleaser_ToolsMenuViewToolsCell.Init(self, |
| + [ToolsMenuViewToolsCell class]); |
| + |
| + [self setBackgroundColor:[UIColor whiteColor]]; |
| + [self setOpaque:YES]; |
| + |
| + int star[2][3] = TOOLBAR_IDR_TWO_STATE(STAR); |
| + _starButton = [self newButtonForImageIds:star |
| + commandID:IDC_BOOKMARK_PAGE |
| + accessibilityLabelID:IDS_BOOKMARK_ADD_EDITOR_TITLE |
| + automationName:@"Add Bookmark"]; |
| + |
| + int star_pressed[2][3] = TOOLBAR_IDR_ONE_STATE(STAR_PRESSED); |
| + _starredButton = [self newButtonForImageIds:star_pressed |
| + commandID:IDC_TEMP_EDIT_BOOKMARK |
| + accessibilityLabelID:IDS_IOS_TOOLS_MENU_EDIT_BOOKMARK |
| + automationName:@"Edit Bookmark"]; |
| + |
| + int reload[2][3] = TOOLBAR_IDR_TWO_STATE(RELOAD); |
| + _reloadButton = [self newButtonForImageIds:reload |
| + commandID:IDC_RELOAD |
| + accessibilityLabelID:IDS_IOS_ACCNAME_RELOAD |
| + automationName:@"Reload" |
| + reverseForRTL:YES]; |
| + |
| + int stop[2][3] = TOOLBAR_IDR_TWO_STATE(STOP); |
| + _stopButton = [self newButtonForImageIds:stop |
| + commandID:IDC_STOP |
| + accessibilityLabelID:IDS_IOS_ACCNAME_STOP |
| + automationName:@"Stop"]; |
| + |
| + int share[2][3] = TOOLBAR_IDR_THREE_STATE(SHARE); |
| + _shareButton = [self newButtonForImageIds:share |
| + commandID:IDC_SHARE_PAGE |
| + accessibilityLabelID:IDS_IOS_TOOLS_MENU_SHARE |
| + automationName:@"Stop"]; |
| + int tools[2][3] = TOOLBAR_IDR_ONE_STATE(TOOLS_PRESSED); |
| + _toolsButton = |
| + [self newButtonForImageIds:tools |
| + commandID:IDC_SHOW_TOOLS_MENU |
| + accessibilityLabelID:IDS_IOS_TOOLBAR_CLOSE_MENU |
| + automationName:@"kToolbarToolsMenuButtonIdentifier"]; |
| + |
| + UIView* contentView = [self contentView]; |
| + [contentView setBackgroundColor:[self backgroundColor]]; |
| + [contentView setOpaque:YES]; |
| + |
| + [contentView addSubview:_starredButton]; |
| + [contentView addSubview:_starButton]; |
| + [contentView addSubview:_stopButton]; |
| + [contentView addSubview:_reloadButton]; |
| + [contentView addSubview:_shareButton]; |
| + |
| + [self addConstraints]; |
| +} |
| + |
| +- (UIButton*)newButtonForImageIds:(int[2][3])imageIds |
| + commandID:(int)commandID |
| + accessibilityLabelID:(int)labelID |
| + automationName:(NSString*)name { |
| + return [self newButtonForImageIds:imageIds |
| + commandID:commandID |
| + accessibilityLabelID:labelID |
| + automationName:name |
| + reverseForRTL:NO]; |
| +} |
| + |
| +- (UIButton*)newButtonForImageIds:(int[2][3])imageIds |
| + commandID:(int)commandID |
| + accessibilityLabelID:(int)labelID |
| + automationName:(NSString*)name |
| + reverseForRTL:(BOOL)reverseForRTL { |
| + UIButton* button = [[UIButton alloc] initWithFrame:CGRectZero]; |
| + [button setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| + |
| + if (imageIds[0][0]) { |
| + [button setImage:NativeReversableImage(imageIds[0][0], reverseForRTL) |
| + forState:UIControlStateNormal]; |
| + } |
| + [[button imageView] setContentMode:UIViewContentModeCenter]; |
| + [button setBackgroundColor:[self backgroundColor]]; |
| + [button setTag:commandID]; |
| + [button setOpaque:YES]; |
| + |
| + SetA11yLabelAndUiAutomationName(button, labelID, name); |
| + |
| + if (imageIds[0][1]) { |
| + UIImage* pressedImage = |
| + NativeReversableImage(imageIds[0][1], reverseForRTL); |
| + if (pressedImage) { |
| + [button setImage:pressedImage forState:UIControlStateHighlighted]; |
| + } |
| + } |
| + |
| + if (imageIds[0][2]) { |
| + UIImage* disabledImage = |
| + NativeReversableImage(imageIds[0][2], reverseForRTL); |
| + if (disabledImage) { |
| + [button setImage:disabledImage forState:UIControlStateDisabled]; |
| + } |
| + } |
| + |
| + return button; |
| +} |
| + |
| +- (void)addConstraints { |
| + UIView* contentView = [self contentView]; |
| + |
| + for (UIButton* button in [self allButtons]) { |
| + NSDictionary* view = @{ @"button" : button }; |
| + NSArray* constraints = @[ @"V:|-(0)-[button]-(0)-|", @"H:[button(==48)]" ]; |
| + ApplyVisualConstraints(constraints, view, self); |
| + } |
| + |
| + NSDictionary* views = @{ |
| + @"share" : _shareButton, |
| + @"star" : _starButton, |
| + @"reload" : _reloadButton, |
| + @"starred" : _starredButton, |
| + @"stop" : _stopButton |
| + }; |
| + // Leading offset is 16, minus the button image inset of 12. |
| + NSDictionary* metrics = @{ @"offset" : @4, @"space" : @24 }; |
| + // clang-format off |
| + NSArray* constraints = @[ |
| + @"H:|-(offset)-[share]-(space)-[star]-(space)-[reload]", |
|
lpromero
2017/01/20 09:05:16
Please paste with ⇧⌥⌘V to keep the original indent
sczs
2017/01/20 23:03:15
Done.
Thanks for the tip! Not usually a problem, b
|
| + @"H:[share]-(space)-[starred]", |
| + @"H:[star]-(space)-[stop]" |
| + ]; |
| + // clang-format on |
| + ApplyVisualConstraintsWithMetricsAndOptions( |
| + constraints, views, metrics, LayoutOptionForRTLSupport(), contentView); |
| +} |
| + |
| +// These should be added in display order, so they are animated in display |
| +// order. |
| +- (NSArray*)allButtons { |
| + NSMutableArray* allButtons = [NSMutableArray array]; |
| + if (_shareButton) |
| + [allButtons addObject:_shareButton]; |
| + |
| + if (_starButton) |
| + [allButtons addObject:_starButton]; |
| + |
| + if (_starredButton) |
| + [allButtons addObject:_starredButton]; |
| + |
| + if (_reloadButton) |
| + [allButtons addObject:_reloadButton]; |
| + |
| + if (_stopButton) |
| + [allButtons addObject:_stopButton]; |
| + |
| + return allButtons; |
| +} |
| + |
| +@end |