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