| 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 11 matching lines...) Expand all Loading... |
| 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" | 31 #include "components/payments/content/payment_request.h" |
| 32 #include "components/payments/content/payment_request_spec.h" |
| 32 #include "components/strings/grit/components_strings.h" | 33 #include "components/strings/grit/components_strings.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/native_theme/native_theme.h" | 35 #include "ui/native_theme/native_theme.h" |
| 35 #include "ui/views/controls/image_view.h" | 36 #include "ui/views/controls/image_view.h" |
| 36 #include "ui/views/controls/label.h" | 37 #include "ui/views/controls/label.h" |
| 37 #include "ui/views/controls/textfield/textfield.h" | 38 #include "ui/views/controls/textfield/textfield.h" |
| 38 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
| 39 #include "ui/views/view.h" | 40 #include "ui/views/view.h" |
| 40 | 41 |
| 41 namespace payments { | 42 namespace payments { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 | 117 |
| 117 // 8dp padding is required between icons. | 118 // 8dp padding is required between icons. |
| 118 constexpr int kPaddingBetweenCardIcons = 8; | 119 constexpr int kPaddingBetweenCardIcons = 8; |
| 119 std::unique_ptr<views::View> icons_row = base::MakeUnique<views::View>(); | 120 std::unique_ptr<views::View> icons_row = base::MakeUnique<views::View>(); |
| 120 views::BoxLayout* icons_layout = new views::BoxLayout( | 121 views::BoxLayout* icons_layout = new views::BoxLayout( |
| 121 views::BoxLayout::kHorizontal, 0, 0, kPaddingBetweenCardIcons); | 122 views::BoxLayout::kHorizontal, 0, 0, kPaddingBetweenCardIcons); |
| 122 icons_row->SetLayoutManager(icons_layout); | 123 icons_row->SetLayoutManager(icons_layout); |
| 123 | 124 |
| 124 constexpr gfx::Size kCardIconSize = gfx::Size(30, 18); | 125 constexpr gfx::Size kCardIconSize = gfx::Size(30, 18); |
| 125 for (const std::string& supported_network : | 126 for (const std::string& supported_network : |
| 126 request()->supported_card_networks()) { | 127 request()->spec()->supported_card_networks()) { |
| 127 const std::string autofill_card_type = | 128 const std::string autofill_card_type = |
| 128 autofill::data_util::GetCardTypeForBasicCardPaymentType( | 129 autofill::data_util::GetCardTypeForBasicCardPaymentType( |
| 129 supported_network); | 130 supported_network); |
| 130 std::unique_ptr<views::ImageView> card_icon_view = | 131 std::unique_ptr<views::ImageView> card_icon_view = |
| 131 CreateCardIconView(autofill_card_type); | 132 CreateCardIconView(autofill_card_type); |
| 132 card_icon_view->SetImageSize(kCardIconSize); | 133 card_icon_view->SetImageSize(kCardIconSize); |
| 133 | 134 |
| 134 icons_row->AddChildView(card_icon_view.release()); | 135 icons_row->AddChildView(card_icon_view.release()); |
| 135 } | 136 } |
| 136 view->AddChildView(icons_row.release()); | 137 view->AddChildView(icons_row.release()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 | 183 |
| 183 credit_card.SetRawInfo(field.second.type, | 184 credit_card.SetRawInfo(field.second.type, |
| 184 combobox->GetTextForRow(combobox->selected_index())); | 185 combobox->GetTextForRow(combobox->selected_index())); |
| 185 } | 186 } |
| 186 | 187 |
| 187 // TODO(mathp): Display global error message. | 188 // TODO(mathp): Display global error message. |
| 188 if (!credit_card.IsValid()) | 189 if (!credit_card.IsValid()) |
| 189 return false; | 190 return false; |
| 190 | 191 |
| 191 // Add the card (will not add a duplicate). | 192 // Add the card (will not add a duplicate). |
| 192 request()->personal_data_manager()->AddCreditCard(credit_card); | 193 request()->GetPersonalDataManager()->AddCreditCard(credit_card); |
| 193 | 194 |
| 194 return true; | 195 return true; |
| 195 } | 196 } |
| 196 | 197 |
| 197 std::unique_ptr<ValidationDelegate> | 198 std::unique_ptr<ValidationDelegate> |
| 198 CreditCardEditorViewController::CreateValidationDelegate( | 199 CreditCardEditorViewController::CreateValidationDelegate( |
| 199 const EditorField& field) { | 200 const EditorField& field) { |
| 200 // The supported card networks for non-cc-number types are not passed to avoid | 201 // The supported card networks for non-cc-number types are not passed to avoid |
| 201 // the data copy in the delegate. | 202 // the data copy in the delegate. |
| 202 return base::MakeUnique< | 203 return base::MakeUnique< |
| 203 CreditCardEditorViewController::CreditCardValidationDelegate>( | 204 CreditCardEditorViewController::CreditCardValidationDelegate>( |
| 204 field, this, | 205 field, this, |
| 205 field.type == autofill::CREDIT_CARD_NUMBER | 206 field.type == autofill::CREDIT_CARD_NUMBER |
| 206 ? request()->supported_card_networks() | 207 ? request()->spec()->supported_card_networks() |
| 207 : std::vector<std::string>()); | 208 : std::vector<std::string>()); |
| 208 } | 209 } |
| 209 | 210 |
| 210 std::unique_ptr<ui::ComboboxModel> | 211 std::unique_ptr<ui::ComboboxModel> |
| 211 CreditCardEditorViewController::GetComboboxModelForType( | 212 CreditCardEditorViewController::GetComboboxModelForType( |
| 212 const autofill::ServerFieldType& type) { | 213 const autofill::ServerFieldType& type) { |
| 213 switch (type) { | 214 switch (type) { |
| 214 case autofill::CREDIT_CARD_EXP_MONTH: { | 215 case autofill::CREDIT_CARD_EXP_MONTH: { |
| 215 int default_index = 0; | 216 int default_index = 0; |
| 216 std::vector<base::string16> months = | 217 std::vector<base::string16> months = |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 bool is_required_valid = !field_.required; | 267 bool is_required_valid = !field_.required; |
| 267 const base::string16 displayed_message = | 268 const base::string16 displayed_message = |
| 268 is_required_valid ? base::ASCIIToUTF16("") | 269 is_required_valid ? base::ASCIIToUTF16("") |
| 269 : l10n_util::GetStringUTF16( | 270 : l10n_util::GetStringUTF16( |
| 270 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); | 271 IDS_PAYMENTS_FIELD_REQUIRED_VALIDATION_MESSAGE); |
| 271 controller_->DisplayErrorMessageForField(field_, displayed_message); | 272 controller_->DisplayErrorMessageForField(field_, displayed_message); |
| 272 return is_required_valid; | 273 return is_required_valid; |
| 273 } | 274 } |
| 274 | 275 |
| 275 } // namespace payments | 276 } // namespace payments |
| OLD | NEW |