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_folder_table_view_cell.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_table_view_cell.h" |
6 | 6 |
| 7 #include "base/mac/scoped_nsobject.h" |
7 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 8 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
8 #import "ios/chrome/browser/ui/rtl_geometry.h" | 9 #import "ios/chrome/browser/ui/rtl_geometry.h" |
9 #include "ios/chrome/grit/ios_strings.h" | 10 #include "ios/chrome/grit/ios_strings.h" |
10 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
11 #include "ui/base/l10n/l10n_util_mac.h" | 12 #include "ui/base/l10n/l10n_util_mac.h" |
12 | 13 |
13 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
14 #error "This file requires ARC support." | |
15 #endif | |
16 | |
17 namespace { | 14 namespace { |
18 // The amount in points by which to offset horizontally the text label. | 15 // The amount in points by which to offset horizontally the text label. |
19 const CGFloat kTitleLabelLeadingOffset = 18.0; | 16 const CGFloat kTitleLabelLeadingOffset = 18.0; |
20 // The amount in points by which to offset horizontally the image view. | 17 // The amount in points by which to offset horizontally the image view. |
21 const CGFloat kImageViewLeadingOffset = 1.0; | 18 const CGFloat kImageViewLeadingOffset = 1.0; |
22 // Width by which to indent folder cell's content. This is multiplied by the | 19 // Width by which to indent folder cell's content. This is multiplied by the |
23 // |indentationLevel| of the cell. | 20 // |indentationLevel| of the cell. |
24 const CGFloat kFolderCellIndentationWidth = 32.0; | 21 const CGFloat kFolderCellIndentationWidth = 32.0; |
25 } // namespace | 22 } // namespace |
26 | 23 |
27 @implementation BookmarkFolderTableViewCell | 24 @implementation BookmarkFolderTableViewCell |
28 | 25 |
29 @synthesize checked = _checked; | 26 @synthesize checked = _checked; |
30 @synthesize enabled = _enabled; | 27 @synthesize enabled = _enabled; |
31 | 28 |
32 + (NSString*)folderCellReuseIdentifier { | 29 + (NSString*)folderCellReuseIdentifier { |
33 return @"BookmarkFolderCellReuseIdentifier"; | 30 return @"BookmarkFolderCellReuseIdentifier"; |
34 } | 31 } |
35 | 32 |
36 + (NSString*)folderCreationCellReuseIdentifier { | 33 + (NSString*)folderCreationCellReuseIdentifier { |
37 return @"BookmarkFolderCreationCellReuseIdentifier"; | 34 return @"BookmarkFolderCreationCellReuseIdentifier"; |
38 } | 35 } |
39 | 36 |
40 + (instancetype)folderCell { | 37 + (instancetype)folderCell { |
41 BookmarkFolderTableViewCell* folderCell = | 38 base::scoped_nsobject<BookmarkFolderTableViewCell> folderCell( |
42 [[[self class] alloc] initWithStyle:UITableViewCellStyleDefault | 39 [[[self class] alloc] initWithStyle:UITableViewCellStyleDefault |
43 reuseIdentifier:[self folderCellReuseIdentifier]]; | 40 reuseIdentifier:[self folderCellReuseIdentifier]]); |
44 folderCell.indentationWidth = kFolderCellIndentationWidth; | 41 folderCell.get().indentationWidth = kFolderCellIndentationWidth; |
45 folderCell.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; | 42 folderCell.get().imageView.image = |
46 return folderCell = nil; | 43 [UIImage imageNamed:@"bookmark_gray_folder"]; |
| 44 return folderCell.autorelease(); |
47 } | 45 } |
48 | 46 |
49 + (instancetype)folderCreationCell { | 47 + (instancetype)folderCreationCell { |
50 BookmarkFolderTableViewCell* newFolderCell = [[[self class] alloc] | 48 base::scoped_nsobject<BookmarkFolderTableViewCell> newFolderCell( |
51 initWithStyle:UITableViewCellStyleDefault | 49 [[[self class] alloc] |
52 reuseIdentifier:[self folderCreationCellReuseIdentifier]]; | 50 initWithStyle:UITableViewCellStyleDefault |
53 newFolderCell.textLabel.text = | 51 reuseIdentifier:[self folderCreationCellReuseIdentifier]]); |
| 52 newFolderCell.get().textLabel.text = |
54 l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP); | 53 l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP); |
55 newFolderCell.imageView.image = | 54 newFolderCell.get().imageView.image = |
56 [UIImage imageNamed:@"bookmark_gray_new_folder"]; | 55 [UIImage imageNamed:@"bookmark_gray_new_folder"]; |
57 newFolderCell.accessibilityIdentifier = @"Create New Folder"; | 56 newFolderCell.get().accessibilityIdentifier = @"Create New Folder"; |
58 return newFolderCell = nil; | 57 return newFolderCell.autorelease(); |
59 } | 58 } |
60 | 59 |
61 - (instancetype)initWithStyle:(UITableViewCellStyle)style | 60 - (instancetype)initWithStyle:(UITableViewCellStyle)style |
62 reuseIdentifier:(NSString*)reuseIdentifier { | 61 reuseIdentifier:(NSString*)reuseIdentifier { |
63 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; | 62 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; |
64 if (self) { | 63 if (self) { |
65 self.textLabel.font = [MDCTypography subheadFont]; | 64 self.textLabel.font = [MDCTypography subheadFont]; |
66 self.textLabel.textColor = bookmark_utils_ios::darkTextColor(); | 65 self.textLabel.textColor = bookmark_utils_ios::darkTextColor(); |
67 self.selectionStyle = UITableViewCellSelectionStyleGray; | 66 self.selectionStyle = UITableViewCellSelectionStyleGray; |
68 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; | 67 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; |
69 self.accessibilityTraits |= UIAccessibilityTraitButton; | 68 self.accessibilityTraits |= UIAccessibilityTraitButton; |
70 _enabled = YES; | 69 _enabled = YES; |
71 } | 70 } |
72 return self; | 71 return self; |
73 } | 72 } |
74 | 73 |
75 - (void)setChecked:(BOOL)checked { | 74 - (void)setChecked:(BOOL)checked { |
76 if (checked != _checked) { | 75 if (checked != _checked) { |
77 _checked = checked; | 76 _checked = checked; |
78 UIImageView* checkImageView = | 77 base::scoped_nsobject<UIImageView> checkImageView( |
79 checked ? [[UIImageView alloc] | 78 checked ? [[UIImageView alloc] |
80 initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]] | 79 initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]] |
81 : nil; | 80 : nil); |
82 self.accessoryView = checkImageView; | 81 self.accessoryView = checkImageView; |
83 } | 82 } |
84 } | 83 } |
85 | 84 |
86 - (void)setEnabled:(BOOL)enabled { | 85 - (void)setEnabled:(BOOL)enabled { |
87 if (enabled != _enabled) { | 86 if (enabled != _enabled) { |
88 _enabled = enabled; | 87 _enabled = enabled; |
89 self.userInteractionEnabled = enabled; | 88 self.userInteractionEnabled = enabled; |
90 self.textLabel.enabled = enabled; | 89 self.textLabel.enabled = enabled; |
91 } | 90 } |
(...skipping 15 matching lines...) Expand all Loading... |
107 self.imageView.frame = LayoutRectGetRect(layout); | 106 self.imageView.frame = LayoutRectGetRect(layout); |
108 } | 107 } |
109 | 108 |
110 - (void)prepareForReuse { | 109 - (void)prepareForReuse { |
111 [super prepareForReuse]; | 110 [super prepareForReuse]; |
112 self.checked = NO; | 111 self.checked = NO; |
113 self.enabled = YES; | 112 self.enabled = YES; |
114 } | 113 } |
115 | 114 |
116 @end | 115 @end |
OLD | NEW |