| 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 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" | 5 #include "chrome/browser/ui/views/payments/credit_card_editor_view_controller.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 PaymentRequest* request, | 26 PaymentRequest* request, |
| 27 PaymentRequestDialogView* dialog) | 27 PaymentRequestDialogView* dialog) |
| 28 : EditorViewController(request, dialog) {} | 28 : EditorViewController(request, dialog) {} |
| 29 | 29 |
| 30 CreditCardEditorViewController::~CreditCardEditorViewController() {} | 30 CreditCardEditorViewController::~CreditCardEditorViewController() {} |
| 31 | 31 |
| 32 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { | 32 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { |
| 33 return std::vector<EditorField>{ | 33 return std::vector<EditorField>{ |
| 34 {autofill::CREDIT_CARD_NAME_FULL, | 34 {autofill::CREDIT_CARD_NAME_FULL, |
| 35 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), | 35 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), |
| 36 EditorField::LengthHint::HINT_LONG}, | 36 EditorField::LengthHint::HINT_LONG, true}, |
| 37 {autofill::CREDIT_CARD_NUMBER, | 37 {autofill::CREDIT_CARD_NUMBER, |
| 38 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), | 38 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), |
| 39 EditorField::LengthHint::HINT_LONG}, | 39 EditorField::LengthHint::HINT_LONG, true}, |
| 40 {autofill::CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, | 40 {autofill::CREDIT_CARD_EXP_DATE_2_DIGIT_YEAR, |
| 41 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE), | 41 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_DATE), |
| 42 EditorField::LengthHint::HINT_SHORT}}; | 42 EditorField::LengthHint::HINT_SHORT, true}}; |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool CreditCardEditorViewController::ValidateModelAndSave() { | 45 bool CreditCardEditorViewController::ValidateModelAndSave() { |
| 46 autofill::CreditCard credit_card; | 46 autofill::CreditCard credit_card; |
| 47 credit_card.set_origin(autofill::kSettingsOrigin); | 47 credit_card.set_origin(autofill::kSettingsOrigin); |
| 48 for (const auto& field : text_fields()) { | 48 for (const auto& field : text_fields()) { |
| 49 // ValidatingTextfield* is the key, EditorField is the value. | 49 // ValidatingTextfield* is the key, EditorField is the value. |
| 50 DCHECK_EQ(autofill::CREDIT_CARD, | 50 DCHECK_EQ(autofill::CREDIT_CARD, |
| 51 autofill::AutofillType(field.second.type).group()); | 51 autofill::AutofillType(field.second.type).group()); |
| 52 if (field.first->invalid()) | 52 if (field.first->invalid()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 72 field); | 72 field); |
| 73 } | 73 } |
| 74 | 74 |
| 75 CreditCardEditorViewController::ValidationDelegate::ValidationDelegate( | 75 CreditCardEditorViewController::ValidationDelegate::ValidationDelegate( |
| 76 const EditorField& field) | 76 const EditorField& field) |
| 77 : field_(field) {} | 77 : field_(field) {} |
| 78 CreditCardEditorViewController::ValidationDelegate::~ValidationDelegate() {} | 78 CreditCardEditorViewController::ValidationDelegate::~ValidationDelegate() {} |
| 79 | 79 |
| 80 bool CreditCardEditorViewController::ValidationDelegate::ValidateTextfield( | 80 bool CreditCardEditorViewController::ValidationDelegate::ValidateTextfield( |
| 81 views::Textfield* textfield) { | 81 views::Textfield* textfield) { |
| 82 base::string16 error_message; | 82 if (!textfield->text().empty()) { |
| 83 // TODO(mathp): Display |error_message| around |textfield|. | 83 base::string16 error_message; |
| 84 return autofill::IsValidForType(textfield->text(), field_.type, | 84 // TODO(mathp): Display |error_message| around |textfield|. |
| 85 &error_message); | 85 return autofill::IsValidForType(textfield->text(), field_.type, |
| 86 &error_message); |
| 87 } |
| 88 |
| 89 // TODO(mathp): Display "required" error if applicable. |
| 90 return !field_.required; |
| 86 } | 91 } |
| 87 | 92 |
| 88 } // namespace payments | 93 } // namespace payments |
| OLD | NEW |