| 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/bookmarks/bookmark_menu_cell.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_cell.h" |
| 6 | 6 |
| 7 #include "base/mac/objc_property_releaser.h" | |
| 8 #include "base/mac/scoped_nsobject.h" | |
| 9 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" | 7 #import "ios/chrome/browser/ui/bookmarks/bookmark_menu_item.h" |
| 10 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 8 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 11 #include "ios/chrome/browser/ui/rtl_geometry.h" | 9 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 12 #include "ios/chrome/browser/ui/ui_util.h" | 10 #include "ios/chrome/browser/ui/ui_util.h" |
| 13 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 11 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 14 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 12 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 15 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 13 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 16 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 14 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 17 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
| 18 namespace { | 20 namespace { |
| 19 CGFloat kTrailingMargin = 16.0; | 21 CGFloat kTrailingMargin = 16.0; |
| 20 } // namespace | 22 } // namespace |
| 21 | 23 |
| 22 @interface BookmarkMenuCell () { | 24 @interface BookmarkMenuCell () |
| 23 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkMenuCell; | |
| 24 } | |
| 25 // Set to YES if the cell can be selected. | 25 // Set to YES if the cell can be selected. |
| 26 @property(nonatomic, assign) BOOL isSelectable; | 26 @property(nonatomic, assign) BOOL isSelectable; |
| 27 // Set to YES if the cell should animate on selection. | 27 // Set to YES if the cell should animate on selection. |
| 28 @property(nonatomic, assign) BOOL shouldAnimateHighlight; | 28 @property(nonatomic, assign) BOOL shouldAnimateHighlight; |
| 29 // Icon view. | 29 // Icon view. |
| 30 @property(nonatomic, assign) UIImageView* iconView; | 30 @property(nonatomic, weak) UIImageView* iconView; |
| 31 // Text label. | 31 // Text label. |
| 32 @property(nonatomic, assign) UILabel* itemLabel; | 32 @property(nonatomic, weak) UILabel* itemLabel; |
| 33 // Separator view. Displayed at 1 pixel height on top for some cells. | 33 // Separator view. Displayed at 1 pixel height on top for some cells. |
| 34 @property(nonatomic, assign) UIView* separatorView; | 34 @property(nonatomic, weak) UIView* separatorView; |
| 35 @end | 35 @end |
| 36 | 36 |
| 37 @implementation BookmarkMenuCell | 37 @implementation BookmarkMenuCell |
| 38 @synthesize isSelectable = _isSelectable; | 38 @synthesize isSelectable = _isSelectable; |
| 39 @synthesize shouldAnimateHighlight = _shouldAnimateHighlight; | 39 @synthesize shouldAnimateHighlight = _shouldAnimateHighlight; |
| 40 @synthesize iconView = _iconView; | 40 @synthesize iconView = _iconView; |
| 41 @synthesize itemLabel = _itemLabel; | 41 @synthesize itemLabel = _itemLabel; |
| 42 @synthesize separatorView = _separatorView; | 42 @synthesize separatorView = _separatorView; |
| 43 @synthesize inkView = _inkView; | 43 @synthesize inkView = _inkView; |
| 44 | 44 |
| 45 - (instancetype)initWithStyle:(UITableViewCellStyle)style | 45 - (instancetype)initWithStyle:(UITableViewCellStyle)style |
| 46 reuseIdentifier:(NSString*)reuseIdentifier { | 46 reuseIdentifier:(NSString*)reuseIdentifier { |
| 47 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | 47 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; |
| 48 if (self) { | 48 if (self) { |
| 49 _propertyReleaser_BookmarkMenuCell.Init(self, [BookmarkMenuCell class]); | |
| 50 | |
| 51 // Create icon view. | 49 // Create icon view. |
| 52 base::scoped_nsobject<UIImageView> iconView([[UIImageView alloc] init]); | 50 UIImageView* iconView = [[UIImageView alloc] init]; |
| 53 _iconView = iconView; | 51 _iconView = iconView; |
| 54 | 52 |
| 55 // Create item label. | 53 // Create item label. |
| 56 base::scoped_nsobject<UILabel> itemLabel([[UILabel alloc] init]); | 54 UILabel* itemLabel = [[UILabel alloc] init]; |
| 57 _itemLabel = itemLabel; | 55 _itemLabel = itemLabel; |
| 58 | 56 |
| 59 self.contentView.layoutMargins = UIEdgeInsetsMakeDirected( | 57 self.contentView.layoutMargins = UIEdgeInsetsMakeDirected( |
| 60 0, bookmark_utils_ios::menuMargin, 0, kTrailingMargin); | 58 0, bookmark_utils_ios::menuMargin, 0, kTrailingMargin); |
| 61 | 59 |
| 62 // Create stack view. | 60 // Create stack view. |
| 63 UIStackView* contentStack = [[[UIStackView alloc] | 61 UIStackView* contentStack = |
| 64 initWithArrangedSubviews:@[ iconView, itemLabel ]] autorelease]; | 62 [[UIStackView alloc] initWithArrangedSubviews:@[ iconView, itemLabel ]]; |
| 65 [self.contentView addSubview:contentStack]; | 63 [self.contentView addSubview:contentStack]; |
| 66 | 64 |
| 67 contentStack.spacing = bookmark_utils_ios::titleToIconDistance; | 65 contentStack.spacing = bookmark_utils_ios::titleToIconDistance; |
| 68 contentStack.alignment = UIStackViewAlignmentCenter; | 66 contentStack.alignment = UIStackViewAlignmentCenter; |
| 69 | 67 |
| 70 // Configure stack view layout. | 68 // Configure stack view layout. |
| 71 contentStack.translatesAutoresizingMaskIntoConstraints = NO; | 69 contentStack.translatesAutoresizingMaskIntoConstraints = NO; |
| 72 UIView* contentView = self.contentView; | 70 UIView* contentView = self.contentView; |
| 73 | 71 |
| 74 UILayoutGuide* marginsGuide = contentView.layoutMarginsGuide; | 72 UILayoutGuide* marginsGuide = contentView.layoutMarginsGuide; |
| 75 [NSLayoutConstraint activateConstraints:@[ | 73 [NSLayoutConstraint activateConstraints:@[ |
| 76 [contentStack.centerYAnchor | 74 [contentStack.centerYAnchor |
| 77 constraintEqualToAnchor:contentView.centerYAnchor], | 75 constraintEqualToAnchor:contentView.centerYAnchor], |
| 78 [contentStack.leadingAnchor | 76 [contentStack.leadingAnchor |
| 79 constraintEqualToAnchor:marginsGuide.leadingAnchor], | 77 constraintEqualToAnchor:marginsGuide.leadingAnchor], |
| 80 [contentStack.trailingAnchor | 78 [contentStack.trailingAnchor |
| 81 constraintLessThanOrEqualToAnchor:marginsGuide.trailingAnchor] | 79 constraintLessThanOrEqualToAnchor:marginsGuide.trailingAnchor] |
| 82 ]]; | 80 ]]; |
| 83 | 81 |
| 84 // Create the ink view. | 82 // Create the ink view. |
| 85 _inkView = [[MDCInkView alloc] initWithFrame:self.bounds]; | 83 _inkView = [[MDCInkView alloc] initWithFrame:self.bounds]; |
| 86 [self addSubview:_inkView]; | 84 [self addSubview:_inkView]; |
| 87 | 85 |
| 88 // Add separator view. | 86 // Add separator view. |
| 89 base::scoped_nsobject<UIView> separatorView( | 87 UIView* separatorView = [[UIView alloc] initWithFrame:CGRectZero]; |
| 90 [[UIView alloc] initWithFrame:CGRectZero]); | |
| 91 [self.contentView addSubview:separatorView]; | 88 [self.contentView addSubview:separatorView]; |
| 92 _separatorView = separatorView; | 89 _separatorView = separatorView; |
| 93 | 90 |
| 94 CGFloat pixelSize = 1 / [[UIScreen mainScreen] scale]; | 91 CGFloat pixelSize = 1 / [[UIScreen mainScreen] scale]; |
| 95 [NSLayoutConstraint activateConstraints:@[ | 92 [NSLayoutConstraint activateConstraints:@[ |
| 96 [_separatorView.leadingAnchor | 93 [_separatorView.leadingAnchor |
| 97 constraintEqualToAnchor:contentView.leadingAnchor], | 94 constraintEqualToAnchor:contentView.leadingAnchor], |
| 98 [_separatorView.trailingAnchor | 95 [_separatorView.trailingAnchor |
| 99 constraintEqualToAnchor:contentView.trailingAnchor], | 96 constraintEqualToAnchor:contentView.trailingAnchor], |
| 100 [_separatorView.heightAnchor constraintEqualToConstant:pixelSize], | 97 [_separatorView.heightAnchor constraintEqualToConstant:pixelSize], |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 // If there is no icon, hide the icon image view so that stack view redraws | 165 // If there is no icon, hide the icon image view so that stack view redraws |
| 169 // without the icon, and vice versa. | 166 // without the icon, and vice versa. |
| 170 self.iconView.hidden = (self.iconView.image == nil); | 167 self.iconView.hidden = (self.iconView.image == nil); |
| 171 } | 168 } |
| 172 | 169 |
| 173 + (NSString*)reuseIdentifier { | 170 + (NSString*)reuseIdentifier { |
| 174 return @"BookmarkMenuCell"; | 171 return @"BookmarkMenuCell"; |
| 175 } | 172 } |
| 176 | 173 |
| 177 @end | 174 @end |
| OLD | NEW |