| 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/autofill/cells/autofill_edit_item.h" | 5 #import "ios/chrome/browser/ui/autofill/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 identifyingIcon = _identifyingIcon; |
| 32 @synthesize inputView = _inputView; | 32 @synthesize inputView = _inputView; |
| 33 @synthesize textFieldEnabled = _textFieldEnabled; | 33 @synthesize textFieldEnabled = _textFieldEnabled; |
| 34 @synthesize autofillUIType = _autofillUIType; | 34 @synthesize autofillUIType = _autofillUIType; |
| 35 @synthesize required = _required; | 35 @synthesize required = _required; |
| 36 | 36 |
| 37 - (instancetype)initWithType:(NSInteger)type { | 37 - (instancetype)initWithType:(NSInteger)type { |
| 38 self = [super initWithType:type]; | 38 self = [super initWithType:type]; |
| 39 if (self) { | 39 if (self) { |
| 40 self.cellClass = [AutofillEditCell class]; | 40 self.cellClass = [AutofillEditCell class]; |
| 41 } | 41 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 55 [NSString stringWithFormat:@"%@_textField", self.textFieldName]; | 55 [NSString stringWithFormat:@"%@_textField", self.textFieldName]; |
| 56 } | 56 } |
| 57 cell.textField.enabled = self.textFieldEnabled; | 57 cell.textField.enabled = self.textFieldEnabled; |
| 58 cell.textField.textColor = self.textFieldEnabled | 58 cell.textField.textColor = self.textFieldEnabled |
| 59 ? [[MDCPalette cr_bluePalette] tint500] | 59 ? [[MDCPalette cr_bluePalette] tint500] |
| 60 : [[MDCPalette greyPalette] tint500]; | 60 : [[MDCPalette greyPalette] tint500]; |
| 61 [cell.textField addTarget:self | 61 [cell.textField addTarget:self |
| 62 action:@selector(textFieldChanged:) | 62 action:@selector(textFieldChanged:) |
| 63 forControlEvents:UIControlEventEditingChanged]; | 63 forControlEvents:UIControlEventEditingChanged]; |
| 64 cell.textField.inputView = self.inputView; | 64 cell.textField.inputView = self.inputView; |
| 65 cell.cardTypeIconView.image = self.cardTypeIcon; | 65 cell.identifyingIconView.image = self.identifyingIcon; |
| 66 } | 66 } |
| 67 | 67 |
| 68 #pragma mark - Actions | 68 #pragma mark - Actions |
| 69 | 69 |
| 70 - (void)textFieldChanged:(UITextField*)textField { | 70 - (void)textFieldChanged:(UITextField*)textField { |
| 71 self.textFieldValue = textField.text; | 71 self.textFieldValue = textField.text; |
| 72 } | 72 } |
| 73 | 73 |
| 74 @end | 74 @end |
| 75 | 75 |
| 76 @implementation AutofillEditCell { | 76 @implementation AutofillEditCell { |
| 77 NSLayoutConstraint* _iconHeightConstraint; | 77 NSLayoutConstraint* _iconHeightConstraint; |
| 78 NSLayoutConstraint* _iconWidthConstraint; | 78 NSLayoutConstraint* _iconWidthConstraint; |
| 79 NSLayoutConstraint* _textFieldTrailingConstraint; | 79 NSLayoutConstraint* _textFieldTrailingConstraint; |
| 80 } | 80 } |
| 81 | 81 |
| 82 @synthesize textField = _textField; | 82 @synthesize textField = _textField; |
| 83 @synthesize textLabel = _textLabel; | 83 @synthesize textLabel = _textLabel; |
| 84 @synthesize cardTypeIconView = _cardTypeIconView; | 84 @synthesize identifyingIconView = _identifyingIconView; |
| 85 | 85 |
| 86 - (instancetype)initWithFrame:(CGRect)frame { | 86 - (instancetype)initWithFrame:(CGRect)frame { |
| 87 self = [super initWithFrame:frame]; | 87 self = [super initWithFrame:frame]; |
| 88 if (self) { | 88 if (self) { |
| 89 self.isAccessibilityElement = YES; | 89 self.isAccessibilityElement = YES; |
| 90 self.allowsCellInteractionsWhileEditing = YES; | 90 self.allowsCellInteractionsWhileEditing = YES; |
| 91 UIView* contentView = self.contentView; | 91 UIView* contentView = self.contentView; |
| 92 | 92 |
| 93 _textLabel = [[UILabel alloc] init]; | 93 _textLabel = [[UILabel alloc] init]; |
| 94 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; | 94 _textLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 107 _textField.autocapitalizationType = UITextAutocapitalizationTypeWords; | 107 _textField.autocapitalizationType = UITextAutocapitalizationTypeWords; |
| 108 _textField.autocorrectionType = UITextAutocorrectionTypeNo; | 108 _textField.autocorrectionType = UITextAutocorrectionTypeNo; |
| 109 _textField.returnKeyType = UIReturnKeyDone; | 109 _textField.returnKeyType = UIReturnKeyDone; |
| 110 _textField.clearButtonMode = UITextFieldViewModeWhileEditing; | 110 _textField.clearButtonMode = UITextFieldViewModeWhileEditing; |
| 111 _textField.contentVerticalAlignment = | 111 _textField.contentVerticalAlignment = |
| 112 UIControlContentVerticalAlignmentCenter; | 112 UIControlContentVerticalAlignmentCenter; |
| 113 _textField.textAlignment = | 113 _textField.textAlignment = |
| 114 UseRTLLayout() ? NSTextAlignmentLeft : NSTextAlignmentRight; | 114 UseRTLLayout() ? NSTextAlignmentLeft : NSTextAlignmentRight; |
| 115 | 115 |
| 116 // Card type icon. | 116 // Card type icon. |
| 117 _cardTypeIconView = [[UIImageView alloc] initWithFrame:CGRectZero]; | 117 _identifyingIconView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 118 _cardTypeIconView.translatesAutoresizingMaskIntoConstraints = NO; | 118 _identifyingIconView.translatesAutoresizingMaskIntoConstraints = NO; |
| 119 [contentView addSubview:_cardTypeIconView]; | 119 [contentView addSubview:_identifyingIconView]; |
| 120 | 120 |
| 121 // Set up the icons size constraints. They are activated here and updated in | 121 // Set up the icons size constraints. They are activated here and updated in |
| 122 // layoutSubviews. | 122 // layoutSubviews. |
| 123 _iconHeightConstraint = | 123 _iconHeightConstraint = |
| 124 [_cardTypeIconView.heightAnchor constraintEqualToConstant:0]; | 124 [_identifyingIconView.heightAnchor constraintEqualToConstant:0]; |
| 125 _iconWidthConstraint = | 125 _iconWidthConstraint = |
| 126 [_cardTypeIconView.widthAnchor constraintEqualToConstant:0]; | 126 [_identifyingIconView.widthAnchor constraintEqualToConstant:0]; |
| 127 | 127 |
| 128 _textFieldTrailingConstraint = [_textField.trailingAnchor | 128 _textFieldTrailingConstraint = [_textField.trailingAnchor |
| 129 constraintEqualToAnchor:_cardTypeIconView.leadingAnchor]; | 129 constraintEqualToAnchor:_identifyingIconView.leadingAnchor]; |
| 130 | 130 |
| 131 // Set up the constraints. | 131 // Set up the constraints. |
| 132 [NSLayoutConstraint activateConstraints:@[ | 132 [NSLayoutConstraint activateConstraints:@[ |
| 133 [_textLabel.leadingAnchor | 133 [_textLabel.leadingAnchor |
| 134 constraintEqualToAnchor:contentView.leadingAnchor | 134 constraintEqualToAnchor:contentView.leadingAnchor |
| 135 constant:kHorizontalPadding], | 135 constant:kHorizontalPadding], |
| 136 [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor | 136 [_textLabel.topAnchor constraintEqualToAnchor:contentView.topAnchor |
| 137 constant:kVerticalPadding], | 137 constant:kVerticalPadding], |
| 138 [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor | 138 [_textLabel.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor |
| 139 constant:-kVerticalPadding], | 139 constant:-kVerticalPadding], |
| 140 _textFieldTrailingConstraint, | 140 _textFieldTrailingConstraint, |
| 141 [_textField.firstBaselineAnchor | 141 [_textField.firstBaselineAnchor |
| 142 constraintEqualToAnchor:_textLabel.firstBaselineAnchor], | 142 constraintEqualToAnchor:_textLabel.firstBaselineAnchor], |
| 143 [_textField.leadingAnchor | 143 [_textField.leadingAnchor |
| 144 constraintEqualToAnchor:_textLabel.trailingAnchor | 144 constraintEqualToAnchor:_textLabel.trailingAnchor |
| 145 constant:kLabelAndFieldGap], | 145 constant:kLabelAndFieldGap], |
| 146 [_cardTypeIconView.trailingAnchor | 146 [_identifyingIconView.trailingAnchor |
| 147 constraintEqualToAnchor:contentView.trailingAnchor | 147 constraintEqualToAnchor:contentView.trailingAnchor |
| 148 constant:-kHorizontalPadding], | 148 constant:-kHorizontalPadding], |
| 149 [_cardTypeIconView.centerYAnchor | 149 [_identifyingIconView.centerYAnchor |
| 150 constraintEqualToAnchor:contentView.centerYAnchor], | 150 constraintEqualToAnchor:contentView.centerYAnchor], |
| 151 _iconHeightConstraint, | 151 _iconHeightConstraint, |
| 152 _iconWidthConstraint, | 152 _iconWidthConstraint, |
| 153 ]]; | 153 ]]; |
| 154 [_textField setContentHuggingPriority:UILayoutPriorityDefaultLow | 154 [_textField setContentHuggingPriority:UILayoutPriorityDefaultLow |
| 155 forAxis:UILayoutConstraintAxisHorizontal]; | 155 forAxis:UILayoutConstraintAxisHorizontal]; |
| 156 } | 156 } |
| 157 return self; | 157 return self; |
| 158 } | 158 } |
| 159 | 159 |
| 160 #pragma mark - UIView | 160 #pragma mark - UIView |
| 161 | 161 |
| 162 - (void)layoutSubviews { | 162 - (void)layoutSubviews { |
| 163 if (self.cardTypeIconView.image) { | 163 if (self.identifyingIconView.image) { |
| 164 _textFieldTrailingConstraint.constant = -kLabelAndFieldGap; | 164 _textFieldTrailingConstraint.constant = -kLabelAndFieldGap; |
| 165 | 165 |
| 166 // Set the size constraints of the icon view to the dimensions of the image. | 166 // Set the size constraints of the icon view to the dimensions of the image. |
| 167 _iconHeightConstraint.constant = self.cardTypeIconView.image.size.height; | 167 _iconHeightConstraint.constant = self.identifyingIconView.image.size.height; |
| 168 _iconWidthConstraint.constant = self.cardTypeIconView.image.size.width; | 168 _iconWidthConstraint.constant = self.identifyingIconView.image.size.width; |
| 169 } else { | 169 } else { |
| 170 _textFieldTrailingConstraint.constant = 0; | 170 _textFieldTrailingConstraint.constant = 0; |
| 171 | 171 |
| 172 _iconHeightConstraint.constant = 0; | 172 _iconHeightConstraint.constant = 0; |
| 173 _iconWidthConstraint.constant = 0; | 173 _iconWidthConstraint.constant = 0; |
| 174 } | 174 } |
| 175 | 175 |
| 176 [super layoutSubviews]; | 176 [super layoutSubviews]; |
| 177 } | 177 } |
| 178 | 178 |
| 179 #pragma mark - UICollectionReusableView | 179 #pragma mark - UICollectionReusableView |
| 180 | 180 |
| 181 - (void)prepareForReuse { | 181 - (void)prepareForReuse { |
| 182 [super prepareForReuse]; | 182 [super prepareForReuse]; |
| 183 self.textLabel.text = nil; | 183 self.textLabel.text = nil; |
| 184 self.textField.text = nil; | 184 self.textField.text = nil; |
| 185 self.textField.autocapitalizationType = UITextAutocapitalizationTypeWords; | 185 self.textField.autocapitalizationType = UITextAutocapitalizationTypeWords; |
| 186 self.textField.autocorrectionType = UITextAutocorrectionTypeNo; | 186 self.textField.autocorrectionType = UITextAutocorrectionTypeNo; |
| 187 self.textField.returnKeyType = UIReturnKeyDone; | 187 self.textField.returnKeyType = UIReturnKeyDone; |
| 188 self.textField.accessibilityIdentifier = nil; | 188 self.textField.accessibilityIdentifier = nil; |
| 189 self.textField.enabled = NO; | 189 self.textField.enabled = NO; |
| 190 self.textField.delegate = nil; | 190 self.textField.delegate = nil; |
| 191 [self.textField removeTarget:nil | 191 [self.textField removeTarget:nil |
| 192 action:nil | 192 action:nil |
| 193 forControlEvents:UIControlEventAllEvents]; | 193 forControlEvents:UIControlEventAllEvents]; |
| 194 self.cardTypeIconView.image = nil; | 194 self.identifyingIconView.image = nil; |
| 195 } | 195 } |
| 196 | 196 |
| 197 #pragma mark - Accessibility | 197 #pragma mark - Accessibility |
| 198 | 198 |
| 199 - (NSString*)accessibilityLabel { | 199 - (NSString*)accessibilityLabel { |
| 200 return [NSString | 200 return [NSString |
| 201 stringWithFormat:@"%@, %@", self.textLabel.text, self.textField.text]; | 201 stringWithFormat:@"%@, %@", self.textLabel.text, self.textField.text]; |
| 202 } | 202 } |
| 203 | 203 |
| 204 @end | 204 @end |
| OLD | NEW |