Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_tools_cell.h" | |
| 6 | |
| 7 #include "base/mac/objc_property_releaser.h" | |
| 8 #include "components/strings/grit/components_strings.h" | |
| 9 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | |
| 10 #include "ios/chrome/browser/ui/rtl_geometry.h" | |
| 11 #include "ios/chrome/browser/ui/toolbar/toolbar_resource_macros.h" | |
| 12 #import "ios/chrome/browser/ui/uikit_ui_util.h" | |
| 13 #include "ios/chrome/grit/ios_strings.h" | |
| 14 | |
| 15 // TODO(crbug.com/228521): Remove this once the new command/metric handling is | |
| 16 // implemented. This is a temporary workaround to allow metrics recording to | |
| 17 // distinguish the action. The value used is in the dynamic range (< | |
| 18 // IDC_MinimumLabelValue) to avoid collisions. | |
| 19 #define IDC_TEMP_EDIT_BOOKMARK 3900 | |
| 20 | |
| 21 @implementation ToolsMenuViewToolsCell { | |
| 22 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewToolsCell; | |
| 23 } | |
| 24 | |
| 25 @synthesize reloadButton = _reloadButton; | |
| 26 @synthesize shareButton = _shareButton; | |
| 27 @synthesize starButton = _starButton; | |
| 28 @synthesize starredButton = _starredButton; | |
| 29 @synthesize stopButton = _stopButton; | |
| 30 @synthesize toolsButton = _toolsButton; | |
| 31 | |
| 32 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | |
| 33 self = [super initWithCoder:aDecoder]; | |
| 34 if (self) | |
| 35 [self commonInitialization]; | |
| 36 | |
| 37 return self; | |
| 38 } | |
| 39 | |
| 40 - (instancetype)initWithFrame:(CGRect)frame { | |
| 41 self = [super initWithFrame:frame]; | |
| 42 if (self) | |
| 43 [self commonInitialization]; | |
| 44 | |
| 45 return self; | |
| 46 } | |
| 47 | |
| 48 - (void)commonInitialization { | |
| 49 _propertyReleaser_ToolsMenuViewToolsCell.Init(self, | |
| 50 [ToolsMenuViewToolsCell class]); | |
| 51 | |
| 52 [self setBackgroundColor:[UIColor whiteColor]]; | |
| 53 [self setOpaque:YES]; | |
| 54 | |
| 55 int star[2][3] = TOOLBAR_IDR_TWO_STATE(STAR); | |
| 56 _starButton = [self newButtonForImageIds:star | |
| 57 commandID:IDC_BOOKMARK_PAGE | |
| 58 accessibilityLabelID:IDS_BOOKMARK_ADD_EDITOR_TITLE | |
| 59 automationName:@"Add Bookmark"]; | |
| 60 | |
| 61 int star_pressed[2][3] = TOOLBAR_IDR_ONE_STATE(STAR_PRESSED); | |
| 62 _starredButton = [self newButtonForImageIds:star_pressed | |
| 63 commandID:IDC_TEMP_EDIT_BOOKMARK | |
| 64 accessibilityLabelID:IDS_IOS_TOOLS_MENU_EDIT_BOOKMARK | |
| 65 automationName:@"Edit Bookmark"]; | |
| 66 | |
| 67 int reload[2][3] = TOOLBAR_IDR_TWO_STATE(RELOAD); | |
| 68 _reloadButton = [self newButtonForImageIds:reload | |
| 69 commandID:IDC_RELOAD | |
| 70 accessibilityLabelID:IDS_IOS_ACCNAME_RELOAD | |
| 71 automationName:@"Reload" | |
| 72 reverseForRTL:YES]; | |
| 73 | |
| 74 int stop[2][3] = TOOLBAR_IDR_TWO_STATE(STOP); | |
| 75 _stopButton = [self newButtonForImageIds:stop | |
| 76 commandID:IDC_STOP | |
| 77 accessibilityLabelID:IDS_IOS_ACCNAME_STOP | |
| 78 automationName:@"Stop"]; | |
| 79 | |
| 80 int share[2][3] = TOOLBAR_IDR_THREE_STATE(SHARE); | |
| 81 _shareButton = [self newButtonForImageIds:share | |
| 82 commandID:IDC_SHARE_PAGE | |
| 83 accessibilityLabelID:IDS_IOS_TOOLS_MENU_SHARE | |
| 84 automationName:@"Stop"]; | |
| 85 int tools[2][3] = TOOLBAR_IDR_ONE_STATE(TOOLS_PRESSED); | |
| 86 _toolsButton = | |
| 87 [self newButtonForImageIds:tools | |
| 88 commandID:IDC_SHOW_TOOLS_MENU | |
| 89 accessibilityLabelID:IDS_IOS_TOOLBAR_CLOSE_MENU | |
| 90 automationName:@"kToolbarToolsMenuButtonIdentifier"]; | |
| 91 | |
| 92 UIView* contentView = [self contentView]; | |
| 93 [contentView setBackgroundColor:[self backgroundColor]]; | |
| 94 [contentView setOpaque:YES]; | |
| 95 | |
| 96 [contentView addSubview:_starredButton]; | |
| 97 [contentView addSubview:_starButton]; | |
| 98 [contentView addSubview:_stopButton]; | |
| 99 [contentView addSubview:_reloadButton]; | |
| 100 [contentView addSubview:_shareButton]; | |
| 101 | |
| 102 [self addConstraints]; | |
| 103 } | |
| 104 | |
| 105 - (UIButton*)newButtonForImageIds:(int[2][3])imageIds | |
| 106 commandID:(int)commandID | |
| 107 accessibilityLabelID:(int)labelID | |
| 108 automationName:(NSString*)name { | |
| 109 return [self newButtonForImageIds:imageIds | |
| 110 commandID:commandID | |
| 111 accessibilityLabelID:labelID | |
| 112 automationName:name | |
| 113 reverseForRTL:NO]; | |
| 114 } | |
| 115 | |
| 116 - (UIButton*)newButtonForImageIds:(int[2][3])imageIds | |
| 117 commandID:(int)commandID | |
| 118 accessibilityLabelID:(int)labelID | |
| 119 automationName:(NSString*)name | |
| 120 reverseForRTL:(BOOL)reverseForRTL { | |
| 121 UIButton* button = [[UIButton alloc] initWithFrame:CGRectZero]; | |
| 122 [button setTranslatesAutoresizingMaskIntoConstraints:NO]; | |
| 123 | |
| 124 if (imageIds[0][0]) { | |
| 125 [button setImage:NativeReversableImage(imageIds[0][0], reverseForRTL) | |
| 126 forState:UIControlStateNormal]; | |
| 127 } | |
| 128 [[button imageView] setContentMode:UIViewContentModeCenter]; | |
| 129 [button setBackgroundColor:[self backgroundColor]]; | |
| 130 [button setTag:commandID]; | |
| 131 [button setOpaque:YES]; | |
| 132 | |
| 133 SetA11yLabelAndUiAutomationName(button, labelID, name); | |
| 134 | |
| 135 if (imageIds[0][1]) { | |
| 136 UIImage* pressedImage = | |
| 137 NativeReversableImage(imageIds[0][1], reverseForRTL); | |
| 138 if (pressedImage) { | |
| 139 [button setImage:pressedImage forState:UIControlStateHighlighted]; | |
| 140 } | |
| 141 } | |
| 142 | |
| 143 if (imageIds[0][2]) { | |
| 144 UIImage* disabledImage = | |
| 145 NativeReversableImage(imageIds[0][2], reverseForRTL); | |
| 146 if (disabledImage) { | |
| 147 [button setImage:disabledImage forState:UIControlStateDisabled]; | |
| 148 } | |
| 149 } | |
| 150 | |
| 151 return button; | |
| 152 } | |
| 153 | |
| 154 - (void)addConstraints { | |
| 155 UIView* contentView = [self contentView]; | |
| 156 | |
| 157 for (UIButton* button in [self allButtons]) { | |
| 158 NSDictionary* view = @{ @"button" : button }; | |
| 159 NSArray* constraints = @[ @"V:|-(0)-[button]-(0)-|", @"H:[button(==48)]" ]; | |
| 160 ApplyVisualConstraints(constraints, view, self); | |
| 161 } | |
| 162 | |
| 163 NSDictionary* views = @{ | |
| 164 @"share" : _shareButton, | |
| 165 @"star" : _starButton, | |
| 166 @"reload" : _reloadButton, | |
| 167 @"starred" : _starredButton, | |
| 168 @"stop" : _stopButton | |
| 169 }; | |
| 170 // Leading offset is 16, minus the button image inset of 12. | |
| 171 NSDictionary* metrics = @{ @"offset" : @4, @"space" : @24 }; | |
| 172 // clang-format off | |
| 173 NSArray* constraints = @[ | |
| 174 @"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
| |
| 175 @"H:[share]-(space)-[starred]", | |
| 176 @"H:[star]-(space)-[stop]" | |
| 177 ]; | |
| 178 // clang-format on | |
| 179 ApplyVisualConstraintsWithMetricsAndOptions( | |
| 180 constraints, views, metrics, LayoutOptionForRTLSupport(), contentView); | |
| 181 } | |
| 182 | |
| 183 // These should be added in display order, so they are animated in display | |
| 184 // order. | |
| 185 - (NSArray*)allButtons { | |
| 186 NSMutableArray* allButtons = [NSMutableArray array]; | |
| 187 if (_shareButton) | |
| 188 [allButtons addObject:_shareButton]; | |
| 189 | |
| 190 if (_starButton) | |
| 191 [allButtons addObject:_starButton]; | |
| 192 | |
| 193 if (_starredButton) | |
| 194 [allButtons addObject:_starredButton]; | |
| 195 | |
| 196 if (_reloadButton) | |
| 197 [allButtons addObject:_reloadButton]; | |
| 198 | |
| 199 if (_stopButton) | |
| 200 [allButtons addObject:_stopButton]; | |
| 201 | |
| 202 return allButtons; | |
| 203 } | |
| 204 | |
| 205 @end | |
| OLD | NEW |