| 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 <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 21 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 22 #include "chrome/grit/generated_resources.h" | 22 #include "chrome/grit/generated_resources.h" |
| 23 #include "components/autofill/core/browser/autofill_data_util.h" | 23 #include "components/autofill/core/browser/autofill_data_util.h" |
| 24 #include "components/autofill/core/browser/autofill_type.h" | 24 #include "components/autofill/core/browser/autofill_type.h" |
| 25 #include "components/autofill/core/browser/credit_card.h" | 25 #include "components/autofill/core/browser/credit_card.h" |
| 26 #include "components/autofill/core/browser/field_types.h" | 26 #include "components/autofill/core/browser/field_types.h" |
| 27 #include "components/autofill/core/browser/personal_data_manager.h" | 27 #include "components/autofill/core/browser/personal_data_manager.h" |
| 28 #include "components/autofill/core/browser/validation.h" | 28 #include "components/autofill/core/browser/validation.h" |
| 29 #include "components/autofill/core/common/autofill_clock.h" | 29 #include "components/autofill/core/common/autofill_clock.h" |
| 30 #include "components/autofill/core/common/autofill_constants.h" | 30 #include "components/autofill/core/common/autofill_constants.h" |
| 31 #include "components/payments/content/payment_request.h" | |
| 32 #include "components/payments/content/payment_request_spec.h" | 31 #include "components/payments/content/payment_request_spec.h" |
| 32 #include "components/payments/content/payment_request_state.h" |
| 33 #include "components/strings/grit/components_strings.h" | 33 #include "components/strings/grit/components_strings.h" |
| 34 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 35 #include "ui/native_theme/native_theme.h" | 35 #include "ui/native_theme/native_theme.h" |
| 36 #include "ui/views/controls/image_view.h" | 36 #include "ui/views/controls/image_view.h" |
| 37 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
| 38 #include "ui/views/controls/textfield/textfield.h" | 38 #include "ui/views/controls/textfield/textfield.h" |
| 39 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
| 40 #include "ui/views/view.h" | 40 #include "ui/views/view.h" |
| 41 | 41 |
| 42 namespace payments { | 42 namespace payments { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 73 autofill::AutofillClock::Now().LocalExplode(&now_exploded); | 73 autofill::AutofillClock::Now().LocalExplode(&now_exploded); |
| 74 for (int i = 0; i < kNumberOfExpirationYears; i++) { | 74 for (int i = 0; i < kNumberOfExpirationYears; i++) { |
| 75 years.push_back(base::UTF8ToUTF16(std::to_string(now_exploded.year + i))); | 75 years.push_back(base::UTF8ToUTF16(std::to_string(now_exploded.year + i))); |
| 76 } | 76 } |
| 77 return years; | 77 return years; |
| 78 } | 78 } |
| 79 | 79 |
| 80 } // namespace | 80 } // namespace |
| 81 | 81 |
| 82 CreditCardEditorViewController::CreditCardEditorViewController( | 82 CreditCardEditorViewController::CreditCardEditorViewController( |
| 83 PaymentRequest* request, | 83 PaymentRequestSpec* spec, |
| 84 PaymentRequestState* state, |
| 84 PaymentRequestDialogView* dialog) | 85 PaymentRequestDialogView* dialog) |
| 85 : EditorViewController(request, dialog) {} | 86 : EditorViewController(spec, state, dialog) {} |
| 86 | 87 |
| 87 CreditCardEditorViewController::~CreditCardEditorViewController() {} | 88 CreditCardEditorViewController::~CreditCardEditorViewController() {} |
| 88 | 89 |
| 89 // Creates the "Cards accepted" view with a row of icons at the top of the | 90 // Creates the "Cards accepted" view with a row of icons at the top of the |
| 90 // credit card editor. | 91 // credit card editor. |
| 91 // +----------------------------------------------+ | 92 // +----------------------------------------------+ |
| 92 // | Cards Accepted | | 93 // | Cards Accepted | |
| 93 // | | | 94 // | | |
| 94 // | | VISA | | MC | | AMEX | | | 95 // | | VISA | | MC | | AMEX | | |
| 95 // +----------------------------------------------+ | 96 // +----------------------------------------------+ |
| (...skipping 21 matching lines...) Expand all Loading... |
| 117 | 118 |
| 118 // 8dp padding is required between icons. | 119 // 8dp padding is required between icons. |
| 119 constexpr int kPaddingBetweenCardIcons = 8; | 120 constexpr int kPaddingBetweenCardIcons = 8; |
| 120 std::unique_ptr<views::View> icons_row = base::MakeUnique<views::View>(); | 121 std::unique_ptr<views::View> icons_row = base::MakeUnique<views::View>(); |
| 121 views::BoxLayout* icons_layout = new views::BoxLayout( | 122 views::BoxLayout* icons_layout = new views::BoxLayout( |
| 122 views::BoxLayout::kHorizontal, 0, 0, kPaddingBetweenCardIcons); | 123 views::BoxLayout::kHorizontal, 0, 0, kPaddingBetweenCardIcons); |
| 123 icons_row->SetLayoutManager(icons_layout); | 124 icons_row->SetLayoutManager(icons_layout); |
| 124 | 125 |
| 125 constexpr gfx::Size kCardIconSize = gfx::Size(30, 18); | 126 constexpr gfx::Size kCardIconSize = gfx::Size(30, 18); |
| 126 for (const std::string& supported_network : | 127 for (const std::string& supported_network : |
| 127 request()->spec()->supported_card_networks()) { | 128 spec()->supported_card_networks()) { |
| 128 const std::string autofill_card_type = | 129 const std::string autofill_card_type = |
| 129 autofill::data_util::GetCardTypeForBasicCardPaymentType( | 130 autofill::data_util::GetCardTypeForBasicCardPaymentType( |
| 130 supported_network); | 131 supported_network); |
| 131 std::unique_ptr<views::ImageView> card_icon_view = | 132 std::unique_ptr<views::ImageView> card_icon_view = |
| 132 CreateCardIconView(autofill_card_type); | 133 CreateCardIconView(autofill_card_type); |
| 133 card_icon_view->SetImageSize(kCardIconSize); | 134 card_icon_view->SetImageSize(kCardIconSize); |
| 134 | 135 |
| 135 icons_row->AddChildView(card_icon_view.release()); | 136 icons_row->AddChildView(card_icon_view.release()); |
| 136 } | 137 } |
| 137 view->AddChildView(icons_row.release()); | 138 view->AddChildView(icons_row.release()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 | 184 |
| 184 credit_card.SetRawInfo(field.second.type, | 185 credit_card.SetRawInfo(field.second.type, |
| 185 combobox->GetTextForRow(combobox->selected_index())); | 186 combobox->GetTextForRow(combobox->selected_index())); |
| 186 } | 187 } |
| 187 | 188 |
| 188 // TODO(mathp): Display global error message. | 189 // TODO(mathp): Display global error message. |
| 189 if (!credit_card.IsValid()) | 190 if (!credit_card.IsValid()) |
| 190 return false; | 191 return false; |
| 191 | 192 |
| 192 // Add the card (will not add a duplicate). | 193 // Add the card (will not add a duplicate). |
| 193 request()->state()->GetPersonalDataManager()->AddCreditCard(credit_card); | 194 state()->GetPersonalDataManager()->AddCreditCard(credit_card); |
| 194 | 195 |
| 195 return true; | 196 return true; |
| 196 } | 197 } |
| 197 | 198 |
| 198 std::unique_ptr<ValidationDelegate> | 199 std::unique_ptr<ValidationDelegate> |
| 199 CreditCardEditorViewController::CreateValidationDelegate( | 200 CreditCardEditorViewController::CreateValidationDelegate( |
| 200 const EditorField& field) { | 201 const EditorField& field) { |
| 201 // The supported card networks for non-cc-number types are not passed to avoid | 202 // The supported card networks for non-cc-number types are not passed to avoid |
| 202 // the data copy in the delegate. | 203 // the data copy in the delegate. |
| 203 return base::MakeUnique< | 204 return base::MakeUnique< |
| 204 CreditCardEditorViewController::CreditCardValidationDelegate>( | 205 CreditCardEditorViewController::CreditCardValidationDelegate>( |
| 205 field, this, | 206 field, this, |
| 206 field.type == autofill::CREDIT_CARD_NUMBER | 207 field.type == autofill::CREDIT_CARD_NUMBER |
| 207 ? request()->spec()->supported_card_networks() | 208 ? spec()->supported_card_networks() |
| 208 : std::vector<std::string>()); | 209 : std::vector<std::string>()); |
| 209 } | 210 } |
| 210 | 211 |
| 211 std::unique_ptr<ui::ComboboxModel> | 212 std::unique_ptr<ui::ComboboxModel> |
| 212 CreditCardEditorViewController::GetComboboxModelForType( | 213 CreditCardEditorViewController::GetComboboxModelForType( |
| 213 const autofill::ServerFieldType& type) { | 214 const autofill::ServerFieldType& type) { |
| 214 switch (type) { | 215 switch (type) { |
| 215 case autofill::CREDIT_CARD_EXP_MONTH: { | 216 case autofill::CREDIT_CARD_EXP_MONTH: { |
| 216 int default_index = 0; | 217 int default_index = 0; |
| 217 std::vector<base::string16> months = | 218 std::vector<base::string16> months = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 bool is_required_valid = !field_.required; | 268 bool is_required_valid = !field_.required; |
| 268 const base::string16 displayed_message = | 269 const base::string16 displayed_message = |
| 269 is_required_valid ? base::ASCIIToUTF16("") | 270 is_required_valid ? base::ASCIIToUTF16("") |
| 270 : l10n_util::GetStringUTF16( | 271 : l10n_util::GetStringUTF16( |
| 271 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 272 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 272 controller_->DisplayErrorMessageForField(field_, displayed_message); | 273 controller_->DisplayErrorMessageForField(field_, displayed_message); |
| 273 return is_required_valid; | 274 return is_required_valid; |
| 274 } | 275 } |
| 275 | 276 |
| 276 } // namespace payments | 277 } // namespace payments |
| OLD | NEW |