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 #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" |
| 11 #include "base/strings/stringprintf.h" | 11 #include "base/strings/stringprintf.h" |
| 12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" | 14 #include "chrome/browser/ui/views/payments/payment_request_dialog_view.h" |
| 15 #include "chrome/browser/ui/views/payments/payment_request_views_util.h" | |
| 15 #include "chrome/browser/ui/views/payments/preselected_combobox_model.h" | 16 #include "chrome/browser/ui/views/payments/preselected_combobox_model.h" |
| 16 #include "chrome/browser/ui/views/payments/validating_combobox.h" | 17 #include "chrome/browser/ui/views/payments/validating_combobox.h" |
| 17 #include "chrome/browser/ui/views/payments/validating_textfield.h" | 18 #include "chrome/browser/ui/views/payments/validating_textfield.h" |
| 18 #include "chrome/grit/generated_resources.h" | 19 #include "chrome/grit/generated_resources.h" |
| 20 #include "components/autofill/core/browser/autofill_data_util.h" | |
| 19 #include "components/autofill/core/browser/autofill_type.h" | 21 #include "components/autofill/core/browser/autofill_type.h" |
| 20 #include "components/autofill/core/browser/credit_card.h" | 22 #include "components/autofill/core/browser/credit_card.h" |
| 21 #include "components/autofill/core/browser/field_types.h" | 23 #include "components/autofill/core/browser/field_types.h" |
| 22 #include "components/autofill/core/browser/validation.h" | 24 #include "components/autofill/core/browser/validation.h" |
| 23 #include "components/autofill/core/common/autofill_clock.h" | 25 #include "components/autofill/core/common/autofill_clock.h" |
| 24 #include "components/autofill/core/common/autofill_constants.h" | 26 #include "components/autofill/core/common/autofill_constants.h" |
| 25 #include "components/payments/payment_request.h" | 27 #include "components/payments/payment_request.h" |
| 28 #include "components/strings/grit/components_strings.h" | |
| 26 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | |
| 31 #include "ui/native_theme/native_theme.h" | |
| 32 #include "ui/views/border.h" | |
| 33 #include "ui/views/controls/image_view.h" | |
| 34 #include "ui/views/controls/label.h" | |
| 27 #include "ui/views/controls/textfield/textfield.h" | 35 #include "ui/views/controls/textfield/textfield.h" |
| 36 #include "ui/views/layout/box_layout.h" | |
| 37 #include "ui/views/view.h" | |
| 28 | 38 |
| 29 namespace payments { | 39 namespace payments { |
| 30 | 40 |
| 31 namespace { | 41 namespace { |
| 32 | 42 |
| 33 // Number of years (including the current one) to be shown in the expiration | 43 // Number of years (including the current one) to be shown in the expiration |
| 34 // year dropdown. | 44 // year dropdown. |
| 35 const int kNumberOfExpirationYears = 10; | 45 const int kNumberOfExpirationYears = 10; |
| 36 | 46 |
| 37 // Returns the items that are in the expiration month dropdown. Will return the | 47 // Returns the items that are in the expiration month dropdown. Will return the |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 66 | 76 |
| 67 } // namespace | 77 } // namespace |
| 68 | 78 |
| 69 CreditCardEditorViewController::CreditCardEditorViewController( | 79 CreditCardEditorViewController::CreditCardEditorViewController( |
| 70 PaymentRequest* request, | 80 PaymentRequest* request, |
| 71 PaymentRequestDialogView* dialog) | 81 PaymentRequestDialogView* dialog) |
| 72 : EditorViewController(request, dialog) {} | 82 : EditorViewController(request, dialog) {} |
| 73 | 83 |
| 74 CreditCardEditorViewController::~CreditCardEditorViewController() {} | 84 CreditCardEditorViewController::~CreditCardEditorViewController() {} |
| 75 | 85 |
| 86 // Creates the "Cards accepted" view with a row of icons at the top of the | |
| 87 // credit card editor. | |
| 88 // +----------------------------------------------+ | |
| 89 // | Cards Accepted | | |
| 90 // | | | |
| 91 // | | VISA | | MC | | AMEX | | | |
| 92 // +----------------------------------------------+ | |
| 93 views::View* CreditCardEditorViewController::CreateHeaderView() { | |
|
please use gerrit instead
2017/02/16 22:16:07
std::unique_ptr<views::View>
Mathieu
2017/02/17 15:06:47
Done.
| |
| 94 views::View* view = new views::View(); | |
|
please use gerrit instead
2017/02/16 22:16:06
Ditto
Mathieu
2017/02/17 15:06:47
Done.
| |
| 95 | |
| 96 // 9dp is required between the first and second row. | |
| 97 constexpr int kRowVerticalInset = 9; | |
| 98 views::BoxLayout* layout = new views::BoxLayout( | |
|
please use gerrit instead
2017/02/16 22:16:07
Would be nice to use std::unique_ptr<views::BoxLay
Mathieu
2017/02/17 15:06:46
I've kept "new" for the layouts, to follow convent
| |
| 99 views::BoxLayout::kVertical, payments::kPaymentRequestRowHorizontalInsets, | |
| 100 payments::kPaymentRequestRowVerticalInsets, kRowVerticalInset); | |
| 101 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START); | |
| 102 layout->set_cross_axis_alignment( | |
| 103 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START); | |
| 104 view->SetLayoutManager(layout); | |
| 105 | |
| 106 // "Cards accepted" label is "disabled" grey. | |
| 107 views::Label* label = new views::Label( | |
|
please use gerrit instead
2017/02/16 22:16:07
uniqe_ptr...
Mathieu
2017/02/17 15:06:47
Done.
| |
| 108 l10n_util::GetStringUTF16(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL)); | |
| 109 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor( | |
| 110 ui::NativeTheme::kColorId_LabelDisabledColor)); | |
| 111 label->SetEnabled(false); | |
| 112 view->AddChildView(label); | |
| 113 | |
| 114 // 8dp padding is required between icons. | |
| 115 constexpr int kPaddingBetweenCardIcons = 8; | |
| 116 views::View* icons_row = new views::View(); | |
|
please use gerrit instead
2017/02/16 22:16:08
unique_ptr?
Mathieu
2017/02/17 15:06:47
Done.
| |
| 117 views::BoxLayout* icons_layout = new views::BoxLayout( | |
|
please use gerrit instead
2017/02/16 22:16:08
unique_ptr!
Mathieu
2017/02/17 15:06:46
Done.
| |
| 118 views::BoxLayout::kHorizontal, 0, 0, kPaddingBetweenCardIcons); | |
| 119 icons_row->SetLayoutManager(icons_layout); | |
| 120 | |
| 121 constexpr gfx::Size kCardIconSize = gfx::Size(30, 18); | |
| 122 for (const std::string& supported_network : | |
| 123 request()->supported_card_networks()) { | |
| 124 views::ImageView* card_icon_view = new views::ImageView(); | |
|
please use gerrit instead
2017/02/16 22:16:07
.
Mathieu
2017/02/17 15:06:46
Done.
| |
| 125 | |
| 126 card_icon_view->set_interactive(false); | |
| 127 const std::string autofill_card_type = | |
| 128 autofill::data_util::GetCardTypeForBasicCardPaymentType( | |
| 129 supported_network); | |
| 130 card_icon_view->SetImage( | |
| 131 ResourceBundle::GetSharedInstance() | |
| 132 .GetImageNamed( | |
| 133 autofill::data_util::GetPaymentRequestData(autofill_card_type) | |
| 134 .icon_resource_id) | |
| 135 .AsImageSkia()); | |
| 136 card_icon_view->SetTooltipText( | |
| 137 autofill::CreditCard::TypeForDisplay(autofill_card_type)); | |
| 138 card_icon_view->SetBorder( | |
| 139 views::CreateRoundedRectBorder(1, 3, SK_ColorLTGRAY)); | |
| 140 card_icon_view->SetImageSize(kCardIconSize); | |
| 141 | |
| 142 icons_row->AddChildView(card_icon_view); | |
| 143 } | |
| 144 view->AddChildView(icons_row); | |
| 145 | |
| 146 return view; | |
| 147 } | |
| 148 | |
| 76 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { | 149 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { |
| 77 return std::vector<EditorField>{ | 150 return std::vector<EditorField>{ |
| 78 {autofill::CREDIT_CARD_NAME_FULL, | 151 {autofill::CREDIT_CARD_NAME_FULL, |
| 79 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), | 152 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), |
| 80 EditorField::LengthHint::HINT_LONG, /* required= */ true}, | 153 EditorField::LengthHint::HINT_LONG, /* required= */ true}, |
| 81 {autofill::CREDIT_CARD_NUMBER, | 154 {autofill::CREDIT_CARD_NUMBER, |
| 82 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), | 155 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), |
| 83 EditorField::LengthHint::HINT_LONG, /* required= */ true}, | 156 EditorField::LengthHint::HINT_LONG, /* required= */ true}, |
| 84 {autofill::CREDIT_CARD_EXP_MONTH, | 157 {autofill::CREDIT_CARD_EXP_MONTH, |
| 85 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH), | 158 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH), |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 base::string16 error_message; | 248 base::string16 error_message; |
| 176 // TODO(mathp): Display |error_message| around |textfield|. | 249 // TODO(mathp): Display |error_message| around |textfield|. |
| 177 return autofill::IsValidForType(value, field_.type, &error_message); | 250 return autofill::IsValidForType(value, field_.type, &error_message); |
| 178 } | 251 } |
| 179 | 252 |
| 180 // TODO(mathp): Display "required" error if applicable. | 253 // TODO(mathp): Display "required" error if applicable. |
| 181 return !field_.required; | 254 return !field_.required; |
| 182 } | 255 } |
| 183 | 256 |
| 184 } // namespace payments | 257 } // namespace payments |
| OLD | NEW |