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

Side by Side Diff: chrome/browser/ui/views/autofill/instrument_unmask_prompt_views.cc

Issue 773653002: [Views] Instrument unmasking prompt initial implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remove android changes Created 6 years 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 2014 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 "base/basictypes.h"
6 #include "base/strings/string_util.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/autofill/instrument_unmask_prompt_view.h"
9 #include "chrome/grit/generated_resources.h"
10 #include "components/constrained_window/constrained_window_views.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/resource/resource_bundle.h"
14 #include "ui/views/controls/image_view.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/textfield/textfield.h"
17 #include "ui/views/controls/textfield/textfield_controller.h"
18 #include "ui/views/layout/box_layout.h"
19 #include "ui/views/window/dialog_client_view.h"
20 #include "ui/views/window/dialog_delegate.h"
21
22 namespace autofill {
23
24 namespace {
25
26 class InstrumentUnmaskPromptViews : public InstrumentUnmaskPromptView,
27 views::DialogDelegateView,
28 views::TextfieldController {
29 public:
30 InstrumentUnmaskPromptViews(content::WebContents* web_contents,
31 const UnmaskCallback& finished)
32 : web_contents_(web_contents),
33 finished_(finished),
34 accepted_(false),
35 cvc_(nullptr) {}
36
37 virtual ~InstrumentUnmaskPromptViews() {
please use gerrit instead 2014/12/08 23:41:19 The new convention for overriding virtual destruct
Evan Stade 2014/12/11 19:01:20 Done.
38 finished_.Run(accepted_ ? cvc_->text() : base::string16());
39 }
40
41 void Show() {
42 constrained_window::ShowWebModalDialogViews(this, web_contents_);
43 }
44
45 // views::DialogDelegateView
46 View* GetContentsView() override {
47 InitIfNecessary();
48 return this;
49 }
50
51 ui::ModalType GetModalType() const override { return ui::MODAL_TYPE_CHILD; }
52
53 base::string16 GetWindowTitle() const override {
54 // TODO(estade): fix this.
55 return base::ASCIIToUTF16("Unlocking Visa - 1111");
56 }
57
58 void DeleteDelegate() override {
59 delete this;
60 }
61
62 int GetDialogButtons() const override {
63 return ui::DIALOG_BUTTON_OK | ui::DIALOG_BUTTON_CANCEL;
64 }
65
66 base::string16 GetDialogButtonLabel(ui::DialogButton button) const override {
67 // TODO(estade): fix this.
68 if (button == ui::DIALOG_BUTTON_OK)
69 return base::ASCIIToUTF16("Verify");
70
71 return DialogDelegateView::GetDialogButtonLabel(button);
72 }
73
74 bool ShouldDefaultButtonBeBlue() const override { return true; }
75
76 bool IsDialogButtonEnabled(ui::DialogButton button) const override {
77 if (button == ui::DIALOG_BUTTON_CANCEL)
78 return true;
79
80 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
81
82 base::string16 input_text;
83 base::TrimWhitespace(cvc_->text(), base::TRIM_ALL, &input_text);
84 return input_text.size() == 3 &&
85 base::ContainsOnlyChars(input_text,
86 base::ASCIIToUTF16("0123456789"));
87 }
88
89 views::View* GetInitiallyFocusedView() override { return cvc_; }
90
91 bool Cancel() override {
92 DCHECK_EQ(false, accepted_);
93 return true;
94 }
95
96 bool Accept() override {
97 accepted_ = true;
98 return true;
99 }
100
101 // views::TextfieldController
102 void ContentsChanged(views::Textfield* sender,
103 const base::string16& new_contents) override {
104 GetDialogClientView()->UpdateDialogButtons();
105 }
106
107 private:
108 void InitIfNecessary() {
109 if (has_children())
110 return;
111
112 // TODO(estade): for amex, text and CVC image should be different.
113 SetLayoutManager(
114 new views::BoxLayout(views::BoxLayout::kVertical, 19, 0, 5));
115 AddChildView(new views::Label(base::ASCIIToUTF16(
116 "Enter the three digit verification code from the back of your credit "
117 "card")));
118
119 views::View* cvc_container = new views::View();
120 cvc_container->SetLayoutManager(
121 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5));
122 AddChildView(cvc_container);
123
124 cvc_ = new views::Textfield();
125 cvc_->set_controller(this);
126 cvc_->set_placeholder_text(
127 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC));
128 cvc_->set_default_width_in_chars(10);
129 cvc_container->AddChildView(cvc_);
130
131 views::ImageView* cvc_image = new views::ImageView();
132 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
133 cvc_image->SetImage(rb.GetImageSkiaNamed(IDR_CREDIT_CARD_CVC_HINT));
134 cvc_container->AddChildView(cvc_image);
135 }
136
137 content::WebContents* web_contents_;
138
139 UnmaskCallback finished_;
140
141 // Set to true when the user accepts.
142 bool accepted_;
143
144 views::Textfield* cvc_;
145
146 DISALLOW_COPY_AND_ASSIGN(InstrumentUnmaskPromptViews);
147 };
148
149 } // namespace
150
151 // static
152 InstrumentUnmaskPromptView*
153 InstrumentUnmaskPromptView::CreateAndShow(content::WebContents* web_contents,
154 const UnmaskCallback& finished) {
155 InstrumentUnmaskPromptViews* view =
156 new InstrumentUnmaskPromptViews(web_contents, finished);
157 view->Show();
158 return view;
159 }
160
161 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/instrument_unmask_prompt_view.cc ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698