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

Side by Side Diff: ios/chrome/browser/ui/settings/cells/encryption_item.mm

Issue 2589583003: Upstream Chrome on iOS source code [7/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 2016 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/settings/cells/encryption_item.h"
6
7 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
8 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF ontLoader.h"
9
10 #if !defined(__has_feature) || !__has_feature(objc_arc)
11 #error "This file requires ARC support."
12 #endif
13
14 namespace {
15 // Padding used on the leading and trailing edges of the cell.
16 const CGFloat kHorizontalPadding = 16;
17
18 // Padding used on the top and bottom edges of the cell.
19 const CGFloat kVerticalPadding = 16;
20 } // namespace
21
22 @interface EncryptionCell ()
23
24 // Returns the default text color used for the given |enabled| state.
25 + (UIColor*)defaultTextColorForEnabledState:(BOOL)enabled;
26
27 @end
28
29 @implementation EncryptionItem
30
31 @synthesize accessoryType = _accessoryType;
32 @synthesize text = _text;
33 @synthesize enabled = _enabled;
34
35 - (instancetype)initWithType:(NSInteger)type {
36 self = [super initWithType:type];
37 if (self) {
38 self.cellClass = [EncryptionCell class];
39 self.enabled = YES;
40 self.accessibilityTraits |= UIAccessibilityTraitButton;
41 }
42 return self;
43 }
44
45 - (void)configureCell:(EncryptionCell*)cell {
46 [super configureCell:cell];
47 cell.accessoryType = self.accessoryType;
48 cell.textLabel.text = self.text;
49 cell.textLabel.textColor =
50 [EncryptionCell defaultTextColorForEnabledState:self.enabled];
51 }
52
53 @end
54
55 @implementation EncryptionCell
56
57 @synthesize textLabel = _textLabel;
58
59 + (UIColor*)defaultTextColorForEnabledState:(BOOL)enabled {
60 MDCPalette* grey = [MDCPalette greyPalette];
61 return enabled ? grey.tint900 : grey.tint500;
62 }
63
64 - (instancetype)initWithFrame:(CGRect)frame {
65 self = [super initWithFrame:frame];
66 if (self) {
67 self.isAccessibilityElement = YES;
68
69 _textLabel = [[UILabel alloc] init];
70 _textLabel.translatesAutoresizingMaskIntoConstraints = NO;
71 [self.contentView addSubview:_textLabel];
72
73 _textLabel.font =
74 [[MDFRobotoFontLoader sharedInstance] mediumFontOfSize:14];
75 _textLabel.numberOfLines = 0;
76
77 // Set up the constraints.
78 [NSLayoutConstraint activateConstraints:@[
79 [_textLabel.leadingAnchor
80 constraintEqualToAnchor:self.contentView.leadingAnchor
81 constant:kHorizontalPadding],
82 [_textLabel.trailingAnchor
83 constraintEqualToAnchor:self.contentView.trailingAnchor
84 constant:-kHorizontalPadding],
85 [_textLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor
86 constant:kVerticalPadding],
87 [_textLabel.bottomAnchor
88 constraintEqualToAnchor:self.contentView.bottomAnchor
89 constant:-kVerticalPadding],
90 ]];
91 }
92 return self;
93 }
94
95 - (void)layoutSubviews {
96 // When the accessory type is None, the content view of the cell (and thus)
97 // the labels inside it span larger than when there is a Checkmark accessory
98 // type. That means that toggling the accessory type can induce a rewrapping
99 // of the detail text, which is not visually pleasing. To alleviate that
100 // issue, always lay out the cell as if there was a Checkmark accessory type.
101 //
102 // Force the accessory type to Checkmark for the duration of layout.
103 MDCCollectionViewCellAccessoryType realAccessoryType = self.accessoryType;
104 self.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
105
106 // Implement -layoutSubviews as per instructions in documentation for
107 // +[MDCCollectionViewCell cr_preferredHeightForWidth:forItem:].
108 [super layoutSubviews];
109
110 // Adjust the text label preferredMaxLayoutWidth when the parent's width
111 // changes, for instance on screen rotation.
112 _textLabel.preferredMaxLayoutWidth =
113 CGRectGetWidth(self.contentView.frame) - 2 * kHorizontalPadding;
114
115 // Re-layout with the new preferred width to allow the label to adjust its
116 // height.
117 [super layoutSubviews];
118
119 // Restore the real accessory type at the end of the layout.
120 self.accessoryType = realAccessoryType;
121 }
122
123 - (void)prepareForReuse {
124 [super prepareForReuse];
125 self.accessoryType = MDCCollectionViewCellAccessoryNone;
126 self.textLabel.text = nil;
127 [EncryptionCell defaultTextColorForEnabledState:YES];
128 }
129
130 #pragma mark - UIAccessibility
131
132 - (NSString*)accessibilityLabel {
133 return self.textLabel.text;
134 }
135
136 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698