OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/payments/payment_request_edit_view_controller.h" | 5 #import "ios/chrome/browser/ui/payments/payment_request_edit_view_controller.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "base/mac/foundation_util.h" | 8 #import "base/mac/foundation_util.h" |
9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
10 #include "components/strings/grit/components_strings.h" | 10 #include "components/strings/grit/components_strings.h" |
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 AutofillEditCell* nextCell = [self nextTextFieldWithOffset:1]; | 377 AutofillEditCell* nextCell = [self nextTextFieldWithOffset:1]; |
378 if (nextCell) | 378 if (nextCell) |
379 [self nextPressed]; | 379 [self nextPressed]; |
380 else | 380 else |
381 [self closePressed]; | 381 [self closePressed]; |
382 | 382 |
383 return NO; | 383 return NO; |
384 } | 384 } |
385 | 385 |
386 // This method is called as the text is being typed in, pasted, or deleted. Asks | 386 // This method is called as the text is being typed in, pasted, or deleted. Asks |
387 // the delegate if the text should be changed. Should always return YES. During | 387 // the delegate if the text should be changed. Should always return NO. During |
388 // typing/pasting text, |newText| contains one or more new characters. When user | 388 // typing/pasting text, |newText| contains one or more new characters. When user |
389 // deletes text, |newText| is empty. |range| is the range of characters to be | 389 // deletes text, |newText| is empty. |range| is the range of characters to be |
390 // replaced. | 390 // replaced. |
391 - (BOOL)textField:(UITextField*)textField | 391 - (BOOL)textField:(UITextField*)textField |
392 shouldChangeCharactersInRange:(NSRange)range | 392 shouldChangeCharactersInRange:(NSRange)range |
393 replacementString:(NSString*)newText { | 393 replacementString:(NSString*)newText { |
394 CollectionViewModel* model = self.collectionViewModel; | 394 CollectionViewModel* model = self.collectionViewModel; |
395 | 395 |
396 DCHECK(_currentEditingCell == AutofillEditCellForTextField(textField)); | 396 DCHECK(_currentEditingCell == AutofillEditCellForTextField(textField)); |
397 | 397 |
398 NSIndexPath* indexPath = [self indexPathForCurrentTextField]; | 398 NSIndexPath* indexPath = [self indexPathForCurrentTextField]; |
399 NSInteger sectionIdentifier = | 399 NSInteger sectionIdentifier = |
400 [model sectionIdentifierForSection:[indexPath section]]; | 400 [model sectionIdentifierForSection:[indexPath section]]; |
401 AutofillEditItem* item = base::mac::ObjCCastStrict<AutofillEditItem>( | 401 AutofillEditItem* item = base::mac::ObjCCastStrict<AutofillEditItem>( |
402 [model itemAtIndexPath:indexPath]); | 402 [model itemAtIndexPath:indexPath]); |
403 | 403 |
404 // Find the respective editor field and update its value. | 404 // Find the respective editor field and update its value to the proposed text. |
405 NSNumber* key = [NSNumber numberWithInt:sectionIdentifier]; | 405 NSNumber* key = [NSNumber numberWithInt:sectionIdentifier]; |
406 EditorField* field = self.fieldsMap[key]; | 406 EditorField* field = self.fieldsMap[key]; |
407 DCHECK(field); | 407 DCHECK(field); |
408 // Obtain the text being typed. | 408 field.value = [textField.text stringByReplacingCharactersInRange:range |
409 NSString* updatedText = | 409 withString:newText]; |
410 [textField.text stringByReplacingCharactersInRange:range | 410 |
411 withString:newText]; | 411 // Format the proposed text if necessary. |
412 field.value = updatedText; | 412 [_dataSource formatValueForEditorField:field]; |
| 413 |
| 414 // Since this method is returning NO, update the text field's value now. |
| 415 textField.text = field.value; |
413 | 416 |
414 // Get the icon that identifies the field value and reload the cell if the | 417 // Get the icon that identifies the field value and reload the cell if the |
415 // icon changes. | 418 // icon changes. |
416 UIImage* oldIcon = item.identifyingIcon; | 419 UIImage* oldIcon = item.identifyingIcon; |
417 item.identifyingIcon = [_dataSource iconIdentifyingEditorField:field]; | 420 item.identifyingIcon = [_dataSource iconIdentifyingEditorField:field]; |
418 if (item.identifyingIcon != oldIcon) | 421 if (item.identifyingIcon != oldIcon) { |
| 422 item.textFieldValue = field.value; |
419 [self reconfigureCellsForItems:@[ item ]]; | 423 [self reconfigureCellsForItems:@[ item ]]; |
| 424 } |
420 | 425 |
421 return YES; | 426 return NO; |
422 } | 427 } |
423 | 428 |
424 #pragma mark - AutofillEditAccessoryDelegate | 429 #pragma mark - AutofillEditAccessoryDelegate |
425 | 430 |
426 - (void)nextPressed { | 431 - (void)nextPressed { |
427 AutofillEditCell* nextCell = [self nextTextFieldWithOffset:1]; | 432 AutofillEditCell* nextCell = [self nextTextFieldWithOffset:1]; |
428 if (nextCell) | 433 if (nextCell) |
429 [nextCell.textField becomeFirstResponder]; | 434 [nextCell.textField becomeFirstResponder]; |
430 } | 435 } |
431 | 436 |
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
732 [_currentEditingCell.textField resignFirstResponder]; | 737 [_currentEditingCell.textField resignFirstResponder]; |
733 | 738 |
734 if (![self validateForm]) | 739 if (![self validateForm]) |
735 return; | 740 return; |
736 | 741 |
737 [self.delegate paymentRequestEditViewController:self | 742 [self.delegate paymentRequestEditViewController:self |
738 didFinishEditingFields:self.fields]; | 743 didFinishEditingFields:self.fields]; |
739 } | 744 } |
740 | 745 |
741 @end | 746 @end |
OLD | NEW |