| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/settings/cells/autofill_edit_item.h" | 5 #import "ios/chrome/browser/ui/settings/cells/autofill_edit_item.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 7 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 8 #import "ios/chrome/browser/ui/rtl_geometry.h" | 8 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 9 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 9 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 10 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 10 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 const CGFloat kVerticalPadding = 16; | 21 const CGFloat kVerticalPadding = 16; |
| 22 | 22 |
| 23 // Minimum gap between the label and the text field. | 23 // Minimum gap between the label and the text field. |
| 24 const CGFloat kLabelAndFieldGap = 5; | 24 const CGFloat kLabelAndFieldGap = 5; |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 @implementation AutofillEditItem | 27 @implementation AutofillEditItem |
| 28 | 28 |
| 29 @synthesize textFieldName = _textFieldName; | 29 @synthesize textFieldName = _textFieldName; |
| 30 @synthesize textFieldValue = _textFieldValue; | 30 @synthesize textFieldValue = _textFieldValue; |
| 31 @synthesize cardTypeIcon = _cardTypeIcon; |
| 31 @synthesize textFieldEnabled = _textFieldEnabled; | 32 @synthesize textFieldEnabled = _textFieldEnabled; |
| 32 @synthesize autofillType = _autofillType; | 33 @synthesize autofillType = _autofillType; |
| 33 | 34 |
| 34 - (instancetype)initWithType:(NSInteger)type { | 35 - (instancetype)initWithType:(NSInteger)type { |
| 35 self = [super initWithType:type]; | 36 self = [super initWithType:type]; |
| 36 if (self) { | 37 if (self) { |
| 37 self.cellClass = [AutofillEditCell class]; | 38 self.cellClass = [AutofillEditCell class]; |
| 38 } | 39 } |
| 39 return self; | 40 return self; |
| 40 } | 41 } |
| 41 | 42 |
| 42 #pragma mark CollectionViewItem | 43 #pragma mark CollectionViewItem |
| 43 | 44 |
| 44 - (void)configureCell:(AutofillEditCell*)cell { | 45 - (void)configureCell:(AutofillEditCell*)cell { |
| 45 [super configureCell:cell]; | 46 [super configureCell:cell]; |
| 46 cell.textLabel.text = self.textFieldName; | 47 cell.textLabel.text = self.textFieldName; |
| 47 cell.textField.text = self.textFieldValue; | 48 cell.textField.text = self.textFieldValue; |
| 48 if (self.textFieldName.length) { | 49 if (self.textFieldName.length) { |
| 49 cell.textField.accessibilityIdentifier = | 50 cell.textField.accessibilityIdentifier = |
| 50 [NSString stringWithFormat:@"%@_textField", self.textFieldName]; | 51 [NSString stringWithFormat:@"%@_textField", self.textFieldName]; |
| 51 } | 52 } |
| 52 cell.textField.enabled = self.textFieldEnabled; | 53 cell.textField.enabled = self.textFieldEnabled; |
| 53 cell.textField.textColor = self.textFieldEnabled | 54 cell.textField.textColor = self.textFieldEnabled |
| 54 ? [[MDCPalette cr_bluePalette] tint500] | 55 ? [[MDCPalette cr_bluePalette] tint500] |
| 55 : [[MDCPalette greyPalette] tint500]; | 56 : [[MDCPalette greyPalette] tint500]; |
| 56 [cell.textField addTarget:self | 57 [cell.textField addTarget:self |
| 57 action:@selector(textFieldChanged:) | 58 action:@selector(textFieldChanged:) |
| 58 forControlEvents:UIControlEventEditingChanged]; | 59 forControlEvents:UIControlEventEditingChanged]; |
| 60 cell.cardTypeIconView.image = self.cardTypeIcon; |
| 59 } | 61 } |
| 60 | 62 |
| 61 #pragma mark - Actions | 63 #pragma mark - Actions |
| 62 | 64 |
| 63 - (void)textFieldChanged:(UITextField*)textField { | 65 - (void)textFieldChanged:(UITextField*)textField { |
| 64 self.textFieldValue = textField.text; | 66 self.textFieldValue = textField.text; |
| 65 } | 67 } |
| 66 | 68 |
| 67 @end | 69 @end |
| 68 | 70 |
| 69 @implementation AutofillEditCell | 71 @implementation AutofillEditCell { |
| 72 NSLayoutConstraint* _iconHeightConstraint; |
| 73 NSLayoutConstraint* _iconWidthConstraint; |
| 74 NSLayoutConstraint* _textFieldTrailingConstraint; |
| 75 } |
| 70 | 76 |
| 71 @synthesize textField = _textField; | 77 @synthesize textField = _textField; |
| 72 @synthesize textLabel = _textLabel; | 78 @synthesize textLabel = _textLabel; |
| 79 @synthesize cardTypeIconView = _cardTypeIconView; |
| 73 | 80 |
| 74 - (instancetype)initWithFrame:(CGRect)frame { | 81 - (instancetype)initWithFrame:(CGRect)frame { |
| 75 self = [super initWithFrame:frame]; | 82 self = [super initWithFrame:frame]; |
| 76 if (self) { | 83 if (self) { |
| 77 self.isAccessibilityElement = YES; | 84 self.isAccessibilityElement = YES; |
| 78 self.allowsCellInteractionsWhileEditing = YES; | 85 self.allowsCellInteractionsWhileEditing = YES; |
| 79 UIView* contentView = self.contentView; | 86 UIView* contentView = self.contentView; |
| 80 | 87 |
| 81 _textLabel = [[UILabel alloc] init]; | 88 _textLabel = [[UILabel alloc] init]; |
| 82 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; | 89 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 94 _textField.textColor = [[MDCPalette greyPalette] tint500]; | 101 _textField.textColor = [[MDCPalette greyPalette] tint500]; |
| 95 _textField.autocapitalizationType = UITextAutocapitalizationTypeWords; | 102 _textField.autocapitalizationType = UITextAutocapitalizationTypeWords; |
| 96 _textField.autocorrectionType = UITextAutocorrectionTypeNo; | 103 _textField.autocorrectionType = UITextAutocorrectionTypeNo; |
| 97 _textField.returnKeyType = UIReturnKeyDone; | 104 _textField.returnKeyType = UIReturnKeyDone; |
| 98 _textField.clearButtonMode = UITextFieldViewModeWhileEditing; | 105 _textField.clearButtonMode = UITextFieldViewModeWhileEditing; |
| 99 _textField.contentVerticalAlignment = | 106 _textField.contentVerticalAlignment = |
| 100 UIControlContentVerticalAlignmentCenter; | 107 UIControlContentVerticalAlignmentCenter; |
| 101 _textField.textAlignment = | 108 _textField.textAlignment = |
| 102 UseRTLLayout() ? NSTextAlignmentLeft : NSTextAlignmentRight; | 109 UseRTLLayout() ? NSTextAlignmentLeft : NSTextAlignmentRight; |
| 103 | 110 |
| 111 // Card type icon. |
| 112 _cardTypeIconView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 113 _cardTypeIconView.layer.borderColor = |
| 114 [UIColor colorWithWhite:0.9 alpha:1.0].CGColor; |
| 115 _cardTypeIconView.layer.borderWidth = 1.0; |
| 116 _cardTypeIconView.translatesAutoresizingMaskIntoConstraints = NO; |
| 117 [contentView addSubview:_cardTypeIconView]; |
| 118 |
| 119 // Set up the icons size constraints. They are activated here and updated in |
| 120 // layoutSubviews. |
| 121 _iconHeightConstraint = |
| 122 [_cardTypeIconView.heightAnchor constraintEqualToConstant:0]; |
| 123 _iconWidthConstraint = |
| 124 [_cardTypeIconView.widthAnchor constraintEqualToConstant:0]; |
| 125 |
| 126 _textFieldTrailingConstraint = [_textField.trailingAnchor |
| 127 constraintEqualToAnchor:_cardTypeIconView.leadingAnchor]; |
| 128 |
| 104 // Set up the constraints. | 129 // Set up the constraints. |
| 105 [NSLayoutConstraint activateConstraints:@[ | 130 [NSLayoutConstraint activateConstraints:@[ |
| 106 [_textLabel.leadingAnchor | 131 [_textLabel.leadingAnchor |
| 107 constraintEqualToAnchor:contentView.leadingAnchor | 132 constraintEqualToAnchor:contentView.leadingAnchor |
| 108 constant:kHorizontalPadding], | 133 constant:kHorizontalPadding], |
| 109 [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor | 134 [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor |
| 110 constant:kVerticalPadding], | 135 constant:kVerticalPadding], |
| 111 [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor | 136 [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor |
| 112 constant:-kVerticalPadding], | 137 constant:-kVerticalPadding], |
| 113 [_textField.trailingAnchor | 138 _textFieldTrailingConstraint, |
| 114 constraintEqualToAnchor:contentView.trailingAnchor | |
| 115 constant:-kHorizontalPadding], | |
| 116 [_textField.firstBaselineAnchor | 139 [_textField.firstBaselineAnchor |
| 117 constraintEqualToAnchor:_textLabel.firstBaselineAnchor], | 140 constraintEqualToAnchor:_textLabel.firstBaselineAnchor], |
| 118 [_textField.leadingAnchor | 141 [_textField.leadingAnchor |
| 119 constraintEqualToAnchor:_textLabel.trailingAnchor | 142 constraintEqualToAnchor:_textLabel.trailingAnchor |
| 120 constant:kLabelAndFieldGap], | 143 constant:kLabelAndFieldGap], |
| 144 [_cardTypeIconView.trailingAnchor |
| 145 constraintEqualToAnchor:contentView.trailingAnchor |
| 146 constant:-kHorizontalPadding], |
| 147 [_cardTypeIconView.centerYAnchor |
| 148 constraintEqualToAnchor:contentView.centerYAnchor], |
| 149 _iconHeightConstraint, |
| 150 _iconWidthConstraint, |
| 121 ]]; | 151 ]]; |
| 122 [_textField setContentHuggingPriority:UILayoutPriorityDefaultLow | 152 [_textField setContentHuggingPriority:UILayoutPriorityDefaultLow |
| 123 forAxis:UILayoutConstraintAxisHorizontal]; | 153 forAxis:UILayoutConstraintAxisHorizontal]; |
| 124 } | 154 } |
| 125 return self; | 155 return self; |
| 126 } | 156 } |
| 127 | 157 |
| 158 #pragma mark - UIView |
| 159 |
| 160 - (void)layoutSubviews { |
| 161 if (self.cardTypeIconView.image) { |
| 162 _textFieldTrailingConstraint.constant = -kLabelAndFieldGap; |
| 163 |
| 164 // Set the size constraints of the icon view to the dimensions of the image. |
| 165 _iconHeightConstraint.constant = self.cardTypeIconView.image.size.height; |
| 166 _iconWidthConstraint.constant = self.cardTypeIconView.image.size.width; |
| 167 } else { |
| 168 _textFieldTrailingConstraint.constant = 0; |
| 169 |
| 170 _iconHeightConstraint.constant = 0; |
| 171 _iconWidthConstraint.constant = 0; |
| 172 } |
| 173 |
| 174 [super layoutSubviews]; |
| 175 } |
| 176 |
| 177 #pragma mark - UICollectionReusableView |
| 178 |
| 128 - (void)prepareForReuse { | 179 - (void)prepareForReuse { |
| 129 [super prepareForReuse]; | 180 [super prepareForReuse]; |
| 130 self.textLabel.text = nil; | 181 self.textLabel.text = nil; |
| 131 self.textField.text = nil; | 182 self.textField.text = nil; |
| 132 self.textField.autocapitalizationType = UITextAutocapitalizationTypeWords; | 183 self.textField.autocapitalizationType = UITextAutocapitalizationTypeWords; |
| 133 self.textField.autocorrectionType = UITextAutocorrectionTypeNo; | 184 self.textField.autocorrectionType = UITextAutocorrectionTypeNo; |
| 134 self.textField.returnKeyType = UIReturnKeyDone; | 185 self.textField.returnKeyType = UIReturnKeyDone; |
| 135 self.textField.accessibilityIdentifier = nil; | 186 self.textField.accessibilityIdentifier = nil; |
| 136 self.textField.enabled = NO; | 187 self.textField.enabled = NO; |
| 137 self.textField.delegate = nil; | 188 self.textField.delegate = nil; |
| 138 [self.textField removeTarget:nil | 189 [self.textField removeTarget:nil |
| 139 action:nil | 190 action:nil |
| 140 forControlEvents:UIControlEventAllEvents]; | 191 forControlEvents:UIControlEventAllEvents]; |
| 192 self.cardTypeIconView.image = nil; |
| 141 } | 193 } |
| 142 | 194 |
| 143 #pragma mark - Accessibility | 195 #pragma mark - Accessibility |
| 144 | 196 |
| 145 - (NSString*)accessibilityLabel { | 197 - (NSString*)accessibilityLabel { |
| 146 return [NSString | 198 return [NSString |
| 147 stringWithFormat:@"%@, %@", self.textLabel.text, self.textField.text]; | 199 stringWithFormat:@"%@, %@", self.textLabel.text, self.textField.text]; |
| 148 } | 200 } |
| 149 | 201 |
| 150 @end | 202 @end |
| OLD | NEW |