| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" | 5 #import "ios/chrome/browser/ui/tools_menu/tools_menu_view_item.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/mac/objc_release_properties.h" | 8 #include "base/mac/objc_property_releaser.h" |
| 9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 9 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 10 #include "ui/base/l10n/l10n_util.h" | 10 #include "ui/base/l10n/l10n_util.h" |
| 11 | 11 |
| 12 namespace { | 12 namespace { |
| 13 const CGFloat kToolsMenuItemHorizontalMargin = 16; | 13 const CGFloat kToolsMenuItemHorizontalMargin = 16; |
| 14 // Increase the margin for RTL so the labels don't overlap the tools icon. | 14 // Increase the margin for RTL so the labels don't overlap the tools icon. |
| 15 const CGFloat kToolsMenuItemHorizontalMarginRTL = 25; | 15 const CGFloat kToolsMenuItemHorizontalMarginRTL = 25; |
| 16 static NSString* const kMenuItemCellID = @"MenuItemCellID"; | 16 static NSString* const kMenuItemCellID = @"MenuItemCellID"; |
| 17 } | 17 } |
| 18 | 18 |
| 19 @implementation ToolsMenuViewItem | 19 @implementation ToolsMenuViewItem { |
| 20 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewItem; |
| 21 } |
| 20 | 22 |
| 21 @synthesize accessibilityIdentifier = _accessibilityIdentifier; | 23 @synthesize accessibilityIdentifier = _accessibilityIdentifier; |
| 22 @synthesize active = _active; | 24 @synthesize active = _active; |
| 23 @synthesize title = _title; | 25 @synthesize title = _title; |
| 24 @synthesize tag = _tag; | 26 @synthesize tag = _tag; |
| 25 @synthesize tableViewCell = _tableViewCell; | 27 @synthesize tableViewCell = _tableViewCell; |
| 26 | 28 |
| 27 - (id)init { | 29 - (id)init { |
| 28 self = [super init]; | 30 self = [super init]; |
| 29 if (self) { | 31 if (self) { |
| 32 _propertyReleaser_ToolsMenuViewItem.Init(self, [ToolsMenuViewItem class]); |
| 30 _active = YES; | 33 _active = YES; |
| 31 } | 34 } |
| 32 | 35 |
| 33 return self; | 36 return self; |
| 34 } | 37 } |
| 35 | 38 |
| 36 - (void)dealloc { | |
| 37 base::mac::ReleaseProperties(self); | |
| 38 [super dealloc]; | |
| 39 } | |
| 40 | |
| 41 + (NSString*)cellID { | 39 + (NSString*)cellID { |
| 42 return kMenuItemCellID; | 40 return kMenuItemCellID; |
| 43 } | 41 } |
| 44 | 42 |
| 45 + (Class)cellClass { | 43 + (Class)cellClass { |
| 46 return [ToolsMenuViewCell class]; | 44 return [ToolsMenuViewCell class]; |
| 47 } | 45 } |
| 48 | 46 |
| 49 + (instancetype)menuItemWithTitle:(NSString*)title | 47 + (instancetype)menuItemWithTitle:(NSString*)title |
| 50 accessibilityIdentifier:(NSString*)accessibilityIdentifier | 48 accessibilityIdentifier:(NSString*)accessibilityIdentifier |
| 51 command:(int)commandID { | 49 command:(int)commandID { |
| 52 ToolsMenuViewItem* menuItem = [[[self alloc] init] autorelease]; | 50 ToolsMenuViewItem* menuItem = [[[self alloc] init] autorelease]; |
| 53 [menuItem setAccessibilityLabel:title]; | 51 [menuItem setAccessibilityLabel:title]; |
| 54 [menuItem setAccessibilityIdentifier:accessibilityIdentifier]; | 52 [menuItem setAccessibilityIdentifier:accessibilityIdentifier]; |
| 55 [menuItem setTag:commandID]; | 53 [menuItem setTag:commandID]; |
| 56 [menuItem setTitle:title]; | 54 [menuItem setTitle:title]; |
| 57 | 55 |
| 58 return menuItem; | 56 return menuItem; |
| 59 } | 57 } |
| 60 | 58 |
| 61 @end | 59 @end |
| 62 | 60 |
| 63 @implementation ToolsMenuViewCell | 61 @implementation ToolsMenuViewCell { |
| 62 base::mac::ObjCPropertyReleaser _propertyReleaser_ToolsMenuViewCell; |
| 63 } |
| 64 | 64 |
| 65 @synthesize title = _title; | 65 @synthesize title = _title; |
| 66 @synthesize horizontalMargin = _horizontalMargin; | 66 @synthesize horizontalMargin = _horizontalMargin; |
| 67 | 67 |
| 68 - (instancetype)initWithCoder:(NSCoder*)aDecoder { | 68 - (instancetype)initWithCoder:(NSCoder*)aDecoder { |
| 69 self = [super initWithCoder:aDecoder]; | 69 self = [super initWithCoder:aDecoder]; |
| 70 if (self) | 70 if (self) |
| 71 [self commonInitialization]; | 71 [self commonInitialization]; |
| 72 | 72 |
| 73 return self; | 73 return self; |
| 74 } | 74 } |
| 75 | 75 |
| 76 - (instancetype)initWithFrame:(CGRect)frame { | 76 - (instancetype)initWithFrame:(CGRect)frame { |
| 77 self = [super initWithFrame:frame]; | 77 self = [super initWithFrame:frame]; |
| 78 if (self) | 78 if (self) |
| 79 [self commonInitialization]; | 79 [self commonInitialization]; |
| 80 | 80 |
| 81 return self; | 81 return self; |
| 82 } | 82 } |
| 83 | 83 |
| 84 - (void)commonInitialization { | 84 - (void)commonInitialization { |
| 85 _propertyReleaser_ToolsMenuViewCell.Init(self, [ToolsMenuViewCell class]); |
| 85 _horizontalMargin = !base::i18n::IsRTL() ? kToolsMenuItemHorizontalMargin | 86 _horizontalMargin = !base::i18n::IsRTL() ? kToolsMenuItemHorizontalMargin |
| 86 : kToolsMenuItemHorizontalMarginRTL; | 87 : kToolsMenuItemHorizontalMarginRTL; |
| 87 [self setBackgroundColor:[UIColor whiteColor]]; | 88 [self setBackgroundColor:[UIColor whiteColor]]; |
| 88 [self setOpaque:YES]; | 89 [self setOpaque:YES]; |
| 89 } | 90 } |
| 90 | 91 |
| 91 - (void)dealloc { | |
| 92 base::mac::ReleaseProperties(self); | |
| 93 [super dealloc]; | |
| 94 } | |
| 95 | |
| 96 - (void)prepareForReuse { | 92 - (void)prepareForReuse { |
| 97 [super prepareForReuse]; | 93 [super prepareForReuse]; |
| 98 [_title setText:nil]; | 94 [_title setText:nil]; |
| 99 [self setAccessibilityIdentifier:nil]; | 95 [self setAccessibilityIdentifier:nil]; |
| 100 [self setAccessibilityLabel:nil]; | 96 [self setAccessibilityLabel:nil]; |
| 101 } | 97 } |
| 102 | 98 |
| 103 - (void)initializeTitleView { | 99 - (void)initializeTitleView { |
| 104 _title = [[UILabel alloc] initWithFrame:self.bounds]; | 100 _title = [[UILabel alloc] initWithFrame:self.bounds]; |
| 105 [_title setTranslatesAutoresizingMaskIntoConstraints:NO]; | 101 [_title setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 [_title setText:[item title]]; | 150 [_title setText:[item title]]; |
| 155 [self setAccessibilityIdentifier:[item accessibilityIdentifier]]; | 151 [self setAccessibilityIdentifier:[item accessibilityIdentifier]]; |
| 156 [self setAccessibilityLabel:[item accessibilityLabel]]; | 152 [self setAccessibilityLabel:[item accessibilityLabel]]; |
| 157 [self setAccessibilityTraits:traits]; | 153 [self setAccessibilityTraits:traits]; |
| 158 [self setIsAccessibilityElement:YES]; | 154 [self setIsAccessibilityElement:YES]; |
| 159 [self setTag:[item tag]]; | 155 [self setTag:[item tag]]; |
| 160 item.tableViewCell = self; | 156 item.tableViewCell = self; |
| 161 } | 157 } |
| 162 | 158 |
| 163 @end | 159 @end |
| OLD | NEW |