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

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

Issue 2779283002: [Web Payments] Implement the CVC Unmask dialog. (Closed)
Patch Set: Created 3 years, 8 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/payments/cvc_unmask_view_controller.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/views/payments/payment_request_views_util.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/autofill/core/browser/credit_card.h"
11 #include "components/grit/components_scaled_resources.h"
12 #include "components/strings/grit/components_strings.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/views/controls/button/md_text_button.h"
16 #include "ui/views/controls/textfield/textfield.h"
17 #include "ui/views/layout/fill_layout.h"
18 #include "ui/views/layout/grid_layout.h"
19
20 namespace payments {
21
22 enum class Tags {
23 CONFIRM_TAG = static_cast<int>(PaymentRequestCommonTags::PAY_BUTTON_TAG),
24 };
25
26 CvcUnmaskViewController::CvcUnmaskViewController(
27 PaymentRequestSpec* spec,
28 PaymentRequestState* state,
29 PaymentRequestDialogView* dialog,
30 const base::string16& masked_card_number,
31 const std::string& card_type)
32 : PaymentRequestSheetController(spec, state, dialog),
33 masked_card_number_(masked_card_number),
34 card_type_(card_type) {}
35
36 CvcUnmaskViewController::~CvcUnmaskViewController() {
37 for (Observer& observer : observer_list_) {
38 observer.OnClosed();
39 }
40 }
41
42 void CvcUnmaskViewController::AddObserver(Observer* observer) {
43 observer_list_.AddObserver(observer);
44 }
45
46 base::string16 CvcUnmaskViewController::GetSheetTitle() {
47 return l10n_util::GetStringFUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_TITLE,
48 masked_card_number_);
49 }
50
51 void CvcUnmaskViewController::FillContentView(views::View* content_view) {
52 std::unique_ptr<views::GridLayout> layout =
53 base::MakeUnique<views::GridLayout>(content_view);
54 layout->SetInsets(
55 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets,
56 kPaymentRequestRowVerticalInsets, kPaymentRequestRowHorizontalInsets);
57
58 views::ColumnSet* instructions_columns = layout->AddColumnSet(0);
59 instructions_columns->AddColumn(views::GridLayout::Alignment::LEADING,
60 views::GridLayout::Alignment::LEADING, 1,
61 views::GridLayout::SizeType::USE_PREF, 0, 0);
62
63 layout->StartRow(0, 0);
64 std::unique_ptr<views::Label> instructions = base::MakeUnique<views::Label>(
65 l10n_util::GetStringUTF16(IDS_AUTOFILL_CARD_UNMASK_PROMPT_INSTRUCTIONS));
66 instructions->SetMultiLine(true);
67 instructions->SetHorizontalAlignment(gfx::ALIGN_LEFT);
68 layout->AddView(instructions.release());
69
70 layout->AddPaddingRow(0, 22);
71
72 views::ColumnSet* cvc_field_columns = layout->AddColumnSet(1);
73 cvc_field_columns->AddColumn(views::GridLayout::Alignment::LEADING,
74 views::GridLayout::Alignment::BASELINE, 0,
75 views::GridLayout::SizeType::FIXED, 32, 32);
76 cvc_field_columns->AddPaddingColumn(0, 16);
77 cvc_field_columns->AddColumn(views::GridLayout::Alignment::FILL,
78 views::GridLayout::Alignment::BASELINE, 0,
79 views::GridLayout::SizeType::FIXED, 80, 80);
80
81 layout->StartRow(0, 1);
82 std::unique_ptr<views::ImageView> cvc_image =
83 base::MakeUnique<views::ImageView>();
84 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
85 // TODO(anthonyvd): Consider using
86 // CardUnmaskPromptControllerImpl::GetCvcImageRid.
87 cvc_image->SetImage(
88 rb.GetImageSkiaNamed(card_type_ == autofill::kAmericanExpressCard
89 ? IDR_CREDIT_CARD_CVC_HINT_AMEX
90 : IDR_CREDIT_CARD_CVC_HINT));
91 layout->AddView(cvc_image.release());
92
93 std::unique_ptr<views::Textfield> cvc_field =
94 base::MakeUnique<views::Textfield>();
95 cvc_field_ = cvc_field.get();
96 layout->AddView(cvc_field.release());
97
98 content_view->SetLayoutManager(layout.release());
99 }
100
101 std::unique_ptr<views::Button> CvcUnmaskViewController::CreatePrimaryButton() {
102 std::unique_ptr<views::Button> button(
103 views::MdTextButton::CreateSecondaryUiBlueButton(
104 this, l10n_util::GetStringUTF16(IDS_CONFIRM)));
105 button->set_tag(static_cast<int>(Tags::CONFIRM_TAG));
106 return button;
107 }
108
109 void CvcUnmaskViewController::ButtonPressed(views::Button* sender,
110 const ui::Event& event) {
111 switch (sender->tag()) {
112 case static_cast<int>(Tags::CONFIRM_TAG):
113 RaiseOnCvcConfirmed();
Mathieu 2017/03/30 14:37:32 Raise is not immediately clear, change name? Noti
114 break;
115 default:
116 PaymentRequestSheetController::ButtonPressed(sender, event);
117 }
118 }
119
120 void CvcUnmaskViewController::RaiseOnCvcConfirmed() {
121 const base::string16& cvc = cvc_field_->text();
122 for (Observer& observer : observer_list_) {
123 observer.OnCvcConfirmed(cvc);
124 }
125 }
126
127 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698