Chromium Code Reviews| 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 dispatch_async(dispatch_get_main_queue(), ^{ | |
|
lpromero
2017/06/20 16:37:49
It is not clear to me why this is doing.
Moe
2017/06/20 18:00:59
I was experiencing a jumping effect with the curso
| |
| 416 textField.text = field.value; | |
| 417 }); | |
| 413 | 418 |
| 414 // Get the icon that identifies the field value and reload the cell if the | 419 // Get the icon that identifies the field value and reload the cell if the |
| 415 // icon changes. | 420 // icon changes. |
| 416 UIImage* oldIcon = item.identifyingIcon; | 421 UIImage* oldIcon = item.identifyingIcon; |
| 417 item.identifyingIcon = [_dataSource iconIdentifyingEditorField:field]; | 422 item.identifyingIcon = [_dataSource iconIdentifyingEditorField:field]; |
| 418 if (item.identifyingIcon != oldIcon) | 423 if (item.identifyingIcon != oldIcon) { |
| 424 item.textFieldValue = field.value; | |
| 419 [self reconfigureCellsForItems:@[ item ]]; | 425 [self reconfigureCellsForItems:@[ item ]]; |
| 426 } | |
| 420 | 427 |
| 421 return YES; | 428 return NO; |
| 422 } | 429 } |
| 423 | 430 |
| 424 #pragma mark - AutofillEditAccessoryDelegate | 431 #pragma mark - AutofillEditAccessoryDelegate |
| 425 | 432 |
| 426 - (void)nextPressed { | 433 - (void)nextPressed { |
| 427 AutofillEditCell* nextCell = [self nextTextFieldWithOffset:1]; | 434 AutofillEditCell* nextCell = [self nextTextFieldWithOffset:1]; |
| 428 if (nextCell) | 435 if (nextCell) |
| 429 [nextCell.textField becomeFirstResponder]; | 436 [nextCell.textField becomeFirstResponder]; |
| 430 } | 437 } |
| 431 | 438 |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 [_currentEditingCell.textField resignFirstResponder]; | 739 [_currentEditingCell.textField resignFirstResponder]; |
| 733 | 740 |
| 734 if (![self validateForm]) | 741 if (![self validateForm]) |
| 735 return; | 742 return; |
| 736 | 743 |
| 737 [self.delegate paymentRequestEditViewController:self | 744 [self.delegate paymentRequestEditViewController:self |
| 738 didFinishEditingFields:self.fields]; | 745 didFinishEditingFields:self.fields]; |
| 739 } | 746 } |
| 740 | 747 |
| 741 @end | 748 @end |
| OLD | NEW |