| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/autofill_profile_edit_collection_view_co
ntroller.h" | 5 #import "ios/chrome/browser/ui/settings/autofill_profile_edit_collection_view_co
ntroller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "components/autofill/core/browser/autofill_profile.h" | 9 #include "components/autofill/core/browser/autofill_profile.h" |
| 10 #include "components/autofill/core/browser/field_types.h" | 10 #include "components/autofill/core/browser/field_types.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, | 56 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, |
| 57 {autofill::ADDRESS_HOME_LINE1, IDS_IOS_AUTOFILL_ADDRESS1, UIReturnKeyNext, | 57 {autofill::ADDRESS_HOME_LINE1, IDS_IOS_AUTOFILL_ADDRESS1, UIReturnKeyNext, |
| 58 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, | 58 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, |
| 59 {autofill::ADDRESS_HOME_LINE2, IDS_IOS_AUTOFILL_ADDRESS2, UIReturnKeyNext, | 59 {autofill::ADDRESS_HOME_LINE2, IDS_IOS_AUTOFILL_ADDRESS2, UIReturnKeyNext, |
| 60 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, | 60 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, |
| 61 {autofill::ADDRESS_HOME_CITY, IDS_IOS_AUTOFILL_CITY, UIReturnKeyNext, | 61 {autofill::ADDRESS_HOME_CITY, IDS_IOS_AUTOFILL_CITY, UIReturnKeyNext, |
| 62 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, | 62 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, |
| 63 {autofill::ADDRESS_HOME_STATE, IDS_IOS_AUTOFILL_STATE, UIReturnKeyNext, | 63 {autofill::ADDRESS_HOME_STATE, IDS_IOS_AUTOFILL_STATE, UIReturnKeyNext, |
| 64 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, | 64 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, |
| 65 {autofill::ADDRESS_HOME_ZIP, IDS_IOS_AUTOFILL_ZIP, UIReturnKeyNext, | 65 {autofill::ADDRESS_HOME_ZIP, IDS_IOS_AUTOFILL_ZIP, UIReturnKeyNext, |
| 66 UIKeyboardTypeNumberPad, UITextAutocapitalizationTypeSentences}, | 66 UIKeyboardTypeDefault, UITextAutocapitalizationTypeAllCharacters}, |
| 67 {autofill::ADDRESS_HOME_COUNTRY, IDS_IOS_AUTOFILL_COUNTRY, UIReturnKeyNext, | 67 {autofill::ADDRESS_HOME_COUNTRY, IDS_IOS_AUTOFILL_COUNTRY, UIReturnKeyNext, |
| 68 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, | 68 UIKeyboardTypeDefault, UITextAutocapitalizationTypeSentences}, |
| 69 {autofill::PHONE_HOME_WHOLE_NUMBER, IDS_IOS_AUTOFILL_PHONE, UIReturnKeyNext, | 69 {autofill::PHONE_HOME_WHOLE_NUMBER, IDS_IOS_AUTOFILL_PHONE, UIReturnKeyNext, |
| 70 UIKeyboardTypePhonePad, UITextAutocapitalizationTypeSentences}, | 70 UIKeyboardTypePhonePad, UITextAutocapitalizationTypeSentences}, |
| 71 {autofill::EMAIL_ADDRESS, IDS_IOS_AUTOFILL_EMAIL, UIReturnKeyDone, | 71 {autofill::EMAIL_ADDRESS, IDS_IOS_AUTOFILL_EMAIL, UIReturnKeyDone, |
| 72 UIKeyboardTypeEmailAddress, UITextAutocapitalizationTypeNone}}; | 72 UIKeyboardTypeEmailAddress, UITextAutocapitalizationTypeNone}}; |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 @interface AutofillProfileEditCollectionViewController () | 76 @interface AutofillProfileEditCollectionViewController () |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 [model addSectionWithIdentifier:SectionIdentifierFields]; | 180 [model addSectionWithIdentifier:SectionIdentifierFields]; |
| 181 for (size_t i = 0; i < arraysize(kFieldsToDisplay); ++i) { | 181 for (size_t i = 0; i < arraysize(kFieldsToDisplay); ++i) { |
| 182 const AutofillFieldDisplayInfo& field = kFieldsToDisplay[i]; | 182 const AutofillFieldDisplayInfo& field = kFieldsToDisplay[i]; |
| 183 AutofillEditItem* item = | 183 AutofillEditItem* item = |
| 184 [[AutofillEditItem alloc] initWithType:ItemTypeField]; | 184 [[AutofillEditItem alloc] initWithType:ItemTypeField]; |
| 185 item.textFieldName = l10n_util::GetNSString(field.displayStringID); | 185 item.textFieldName = l10n_util::GetNSString(field.displayStringID); |
| 186 item.textFieldValue = base::SysUTF16ToNSString(_autofillProfile.GetInfo( | 186 item.textFieldValue = base::SysUTF16ToNSString(_autofillProfile.GetInfo( |
| 187 autofill::AutofillType(field.autofillType), locale)); | 187 autofill::AutofillType(field.autofillType), locale)); |
| 188 item.autofillUIType = AutofillUITypeFromAutofillType(field.autofillType); | 188 item.autofillUIType = AutofillUITypeFromAutofillType(field.autofillType); |
| 189 item.textFieldEnabled = self.editor.editing; | 189 item.textFieldEnabled = self.editor.editing; |
| 190 item.autoCapitalizationType = field.autoCapitalizationType; |
| 191 item.returnKeyType = field.returnKeyType; |
| 192 item.keyboardType = field.keyboardType; |
| 190 [model addItem:item toSectionWithIdentifier:SectionIdentifierFields]; | 193 [model addItem:item toSectionWithIdentifier:SectionIdentifierFields]; |
| 191 } | 194 } |
| 192 } | 195 } |
| 193 | 196 |
| 194 #pragma mark - MDCCollectionViewEditingDelegate | 197 #pragma mark - MDCCollectionViewEditingDelegate |
| 195 | 198 |
| 196 - (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView { | 199 - (BOOL)collectionViewAllowsEditing:(UICollectionView*)collectionView { |
| 197 // The collection view needs to allow editing in order to respond to the Edit | 200 // The collection view needs to allow editing in order to respond to the Edit |
| 198 // button. | 201 // button. |
| 199 return YES; | 202 return YES; |
| 200 } | 203 } |
| 201 | 204 |
| 202 - (BOOL)collectionView:(UICollectionView*)collectionView | 205 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 203 canEditItemAtIndexPath:(NSIndexPath*)indexPath { | 206 canEditItemAtIndexPath:(NSIndexPath*)indexPath { |
| 204 // Items in this collection view are not deletable, so should not be seen | 207 // Items in this collection view are not deletable, so should not be seen |
| 205 // as editable by the collection view. | 208 // as editable by the collection view. |
| 206 return NO; | 209 return NO; |
| 207 } | 210 } |
| 208 | 211 |
| 209 #pragma mark - UICollectionViewDataSource | 212 #pragma mark - UICollectionViewDataSource |
| 210 | 213 |
| 211 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView | 214 - (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView |
| 212 cellForItemAtIndexPath:(NSIndexPath*)indexPath { | 215 cellForItemAtIndexPath:(NSIndexPath*)indexPath { |
| 213 UICollectionViewCell* cell = | 216 UICollectionViewCell* cell = |
| 214 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; | 217 [super collectionView:collectionView cellForItemAtIndexPath:indexPath]; |
| 215 | 218 |
| 216 AutofillEditCell* textFieldCell = | 219 AutofillEditCell* textFieldCell = |
| 217 base::mac::ObjCCastStrict<AutofillEditCell>(cell); | 220 base::mac::ObjCCastStrict<AutofillEditCell>(cell); |
| 218 NSUInteger index = | |
| 219 [self.collectionViewModel indexInItemTypeForIndexPath:indexPath]; | |
| 220 const AutofillFieldDisplayInfo& field = kFieldsToDisplay[index]; | |
| 221 textFieldCell.accessibilityIdentifier = textFieldCell.textLabel.text; | 221 textFieldCell.accessibilityIdentifier = textFieldCell.textLabel.text; |
| 222 textFieldCell.textField.autocapitalizationType = field.autoCapitalizationType; | |
| 223 textFieldCell.textField.returnKeyType = field.returnKeyType; | |
| 224 textFieldCell.textField.keyboardType = field.keyboardType; | |
| 225 textFieldCell.textField.delegate = self; | 222 textFieldCell.textField.delegate = self; |
| 226 return textFieldCell; | 223 return textFieldCell; |
| 227 } | 224 } |
| 228 | 225 |
| 229 #pragma mark - UICollectionViewDelegate | 226 #pragma mark - UICollectionViewDelegate |
| 230 | 227 |
| 231 - (BOOL)collectionView:(UICollectionView*)collectionView | 228 - (BOOL)collectionView:(UICollectionView*)collectionView |
| 232 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 229 shouldSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 233 if (self.editor.editing) { | 230 if (self.editor.editing) { |
| 234 UICollectionViewCell* cell = | 231 UICollectionViewCell* cell = |
| 235 [self.collectionView cellForItemAtIndexPath:indexPath]; | 232 [self.collectionView cellForItemAtIndexPath:indexPath]; |
| 236 AutofillEditCell* textFieldCell = | 233 AutofillEditCell* textFieldCell = |
| 237 base::mac::ObjCCastStrict<AutofillEditCell>(cell); | 234 base::mac::ObjCCastStrict<AutofillEditCell>(cell); |
| 238 [textFieldCell.textField becomeFirstResponder]; | 235 [textFieldCell.textField becomeFirstResponder]; |
| 239 } | 236 } |
| 240 return [super collectionView:collectionView | 237 return [super collectionView:collectionView |
| 241 shouldSelectItemAtIndexPath:indexPath]; | 238 shouldSelectItemAtIndexPath:indexPath]; |
| 242 } | 239 } |
| 243 | 240 |
| 244 @end | 241 @end |
| OLD | NEW |