Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: chrome/browser/ui/views/payments/credit_card_editor_view_controller.cc

Issue 2698353002: [Payments] Add the "Cards accepted" row at the top of CC editor. (Closed)
Patch Set: private Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/native_theme/native_theme.h"
31 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/label.h"
27 #include "ui/views/controls/textfield/textfield.h" 33 #include "ui/views/controls/textfield/textfield.h"
34 #include "ui/views/layout/box_layout.h"
35 #include "ui/views/view.h"
28 36
29 namespace payments { 37 namespace payments {
30 38
31 namespace { 39 namespace {
32 40
33 // Number of years (including the current one) to be shown in the expiration 41 // Number of years (including the current one) to be shown in the expiration
34 // year dropdown. 42 // year dropdown.
35 const int kNumberOfExpirationYears = 10; 43 const int kNumberOfExpirationYears = 10;
36 44
37 // Returns the items that are in the expiration month dropdown. Will return the 45 // Returns the items that are in the expiration month dropdown. Will return the
(...skipping 28 matching lines...) Expand all
66 74
67 } // namespace 75 } // namespace
68 76
69 CreditCardEditorViewController::CreditCardEditorViewController( 77 CreditCardEditorViewController::CreditCardEditorViewController(
70 PaymentRequest* request, 78 PaymentRequest* request,
71 PaymentRequestDialogView* dialog) 79 PaymentRequestDialogView* dialog)
72 : EditorViewController(request, dialog) {} 80 : EditorViewController(request, dialog) {}
73 81
74 CreditCardEditorViewController::~CreditCardEditorViewController() {} 82 CreditCardEditorViewController::~CreditCardEditorViewController() {}
75 83
84 // Creates the "Cards accepted" view with a row of icons at the top of the
85 // credit card editor.
86 // +----------------------------------------------+
87 // | Cards Accepted |
88 // | |
89 // | | VISA | | MC | | AMEX | |
90 // +----------------------------------------------+
91 std::unique_ptr<views::View>
92 CreditCardEditorViewController::CreateHeaderView() {
93 std::unique_ptr<views::View> view = base::MakeUnique<views::View>();
94
95 // 9dp is required between the first and second row.
96 constexpr int kRowVerticalInset = 9;
97 views::BoxLayout* layout = new views::BoxLayout(
98 views::BoxLayout::kVertical, payments::kPaymentRequestRowHorizontalInsets,
99 payments::kPaymentRequestRowVerticalInsets, kRowVerticalInset);
100 layout->set_main_axis_alignment(views::BoxLayout::MAIN_AXIS_ALIGNMENT_START);
101 layout->set_cross_axis_alignment(
102 views::BoxLayout::CROSS_AXIS_ALIGNMENT_START);
103 view->SetLayoutManager(layout);
104
105 // "Cards accepted" label is "disabled" grey.
106 std::unique_ptr<views::Label> label = base::MakeUnique<views::Label>(
107 l10n_util::GetStringUTF16(IDS_PAYMENTS_ACCEPTED_CARDS_LABEL));
108 label->SetDisabledColor(label->GetNativeTheme()->GetSystemColor(
109 ui::NativeTheme::kColorId_LabelDisabledColor));
110 label->SetEnabled(false);
111 view->AddChildView(label.release());
112
113 // 8dp padding is required between icons.
114 constexpr int kPaddingBetweenCardIcons = 8;
115 std::unique_ptr<views::View> icons_row = base::MakeUnique<views::View>();
116 views::BoxLayout* icons_layout = new views::BoxLayout(
117 views::BoxLayout::kHorizontal, 0, 0, kPaddingBetweenCardIcons);
118 icons_row->SetLayoutManager(icons_layout);
119
120 constexpr gfx::Size kCardIconSize = gfx::Size(30, 18);
121 for (const std::string& supported_network :
122 request()->supported_card_networks()) {
123 const std::string autofill_card_type =
124 autofill::data_util::GetCardTypeForBasicCardPaymentType(
125 supported_network);
126 std::unique_ptr<views::ImageView> card_icon_view =
127 CreateCardIconView(autofill_card_type);
128 card_icon_view->SetImageSize(kCardIconSize);
129
130 icons_row->AddChildView(card_icon_view.release());
131 }
132 view->AddChildView(icons_row.release());
133
134 return view;
135 }
136
76 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() { 137 std::vector<EditorField> CreditCardEditorViewController::GetFieldDefinitions() {
77 return std::vector<EditorField>{ 138 return std::vector<EditorField>{
78 {autofill::CREDIT_CARD_NAME_FULL, 139 {autofill::CREDIT_CARD_NAME_FULL,
79 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD), 140 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_NAME_ON_CARD),
80 EditorField::LengthHint::HINT_LONG, /* required= */ true}, 141 EditorField::LengthHint::HINT_LONG, /* required= */ true},
81 {autofill::CREDIT_CARD_NUMBER, 142 {autofill::CREDIT_CARD_NUMBER,
82 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER), 143 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_CREDIT_CARD_NUMBER),
83 EditorField::LengthHint::HINT_LONG, /* required= */ true}, 144 EditorField::LengthHint::HINT_LONG, /* required= */ true},
84 {autofill::CREDIT_CARD_EXP_MONTH, 145 {autofill::CREDIT_CARD_EXP_MONTH,
85 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH), 146 l10n_util::GetStringUTF16(IDS_AUTOFILL_FIELD_LABEL_EXPIRATION_MONTH),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 base::string16 error_message; 236 base::string16 error_message;
176 // TODO(mathp): Display |error_message| around |textfield|. 237 // TODO(mathp): Display |error_message| around |textfield|.
177 return autofill::IsValidForType(value, field_.type, &error_message); 238 return autofill::IsValidForType(value, field_.type, &error_message);
178 } 239 }
179 240
180 // TODO(mathp): Display "required" error if applicable. 241 // TODO(mathp): Display "required" error if applicable.
181 return !field_.required; 242 return !field_.required;
182 } 243 }
183 244
184 } // namespace payments 245 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698