Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: ios/chrome/browser/ui/bookmarks/bookmark_folder_table_view_cell.mm

Issue 2586993002: Upstream Chrome on iOS source code [3/11]. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/bookmarks/bookmark_folder_table_view_cell.h"
6
7 #include "base/mac/scoped_nsobject.h"
8 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h"
9 #import "ios/chrome/browser/ui/rtl_geometry.h"
10 #include "ios/chrome/grit/ios_strings.h"
11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
12 #include "ui/base/l10n/l10n_util_mac.h"
13
14 namespace {
15 // The amount in points by which to offset horizontally the text label.
16 const CGFloat kTitleLabelLeadingOffset = 18.0;
17 // The amount in points by which to offset horizontally the image view.
18 const CGFloat kImageViewLeadingOffset = 1.0;
19 // Width by which to indent folder cell's content. This is multiplied by the
20 // |indentationLevel| of the cell.
21 const CGFloat kFolderCellIndentationWidth = 32.0;
22 } // namespace
23
24 @implementation BookmarkFolderTableViewCell
25
26 @synthesize checked = _checked;
27 @synthesize enabled = _enabled;
28
29 + (NSString*)folderCellReuseIdentifier {
30 return @"BookmarkFolderCellReuseIdentifier";
31 }
32
33 + (NSString*)folderCreationCellReuseIdentifier {
34 return @"BookmarkFolderCreationCellReuseIdentifier";
35 }
36
37 + (instancetype)folderCell {
38 base::scoped_nsobject<BookmarkFolderTableViewCell> folderCell(
39 [[[self class] alloc] initWithStyle:UITableViewCellStyleDefault
40 reuseIdentifier:[self folderCellReuseIdentifier]]);
41 folderCell.get().indentationWidth = kFolderCellIndentationWidth;
42 folderCell.get().imageView.image =
43 [UIImage imageNamed:@"bookmark_gray_folder"];
44 return folderCell.autorelease();
45 }
46
47 + (instancetype)folderCreationCell {
48 base::scoped_nsobject<BookmarkFolderTableViewCell> newFolderCell(
49 [[[self class] alloc]
50 initWithStyle:UITableViewCellStyleDefault
51 reuseIdentifier:[self folderCreationCellReuseIdentifier]]);
52 newFolderCell.get().textLabel.text =
53 l10n_util::GetNSString(IDS_IOS_BOOKMARK_CREATE_GROUP);
54 newFolderCell.get().imageView.image =
55 [UIImage imageNamed:@"bookmark_gray_new_folder"];
56 newFolderCell.get().accessibilityIdentifier = @"Create New Folder";
57 return newFolderCell.autorelease();
58 }
59
60 - (instancetype)initWithStyle:(UITableViewCellStyle)style
61 reuseIdentifier:(NSString*)reuseIdentifier {
62 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
63 if (self) {
64 self.textLabel.font = [MDCTypography subheadFont];
65 self.textLabel.textColor = bookmark_utils_ios::darkTextColor();
66 self.selectionStyle = UITableViewCellSelectionStyleGray;
67 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"];
68 self.accessibilityTraits |= UIAccessibilityTraitButton;
69 _enabled = YES;
70 }
71 return self;
72 }
73
74 - (void)setChecked:(BOOL)checked {
75 if (checked != _checked) {
76 _checked = checked;
77 base::scoped_nsobject<UIImageView> checkImageView(
78 checked ? [[UIImageView alloc]
79 initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]]
80 : nil);
81 self.accessoryView = checkImageView;
82 }
83 }
84
85 - (void)setEnabled:(BOOL)enabled {
86 if (enabled != _enabled) {
87 _enabled = enabled;
88 self.userInteractionEnabled = enabled;
89 self.textLabel.enabled = enabled;
90 }
91 }
92
93 - (void)layoutSubviews {
94 [super layoutSubviews];
95
96 // Move the text label as required by the design.
97 UIEdgeInsets insets =
98 UIEdgeInsetsMakeDirected(0, kTitleLabelLeadingOffset, 0, 0);
99 self.textLabel.frame = UIEdgeInsetsInsetRect(self.textLabel.frame, insets);
100
101 // Indent the image. An offset is required in the design.
102 LayoutRect layout = LayoutRectForRectInBoundingRect(self.imageView.frame,
103 self.contentView.bounds);
104 layout.position.leading +=
105 self.indentationWidth * self.indentationLevel + kImageViewLeadingOffset;
106 self.imageView.frame = LayoutRectGetRect(layout);
107 }
108
109 - (void)prepareForReuse {
110 [super prepareForReuse];
111 self.checked = NO;
112 self.enabled = YES;
113 }
114
115 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698