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

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

Issue 2789843004: [Payments] Upload card UI now has a CVC prompt (Closed)
Patch Set: Address code review comment 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/autofill/save_card_bubble_views.h" 5 #include "chrome/browser/ui/views/autofill/save_card_bubble_views.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "chrome/browser/ui/autofill/save_card_bubble_controller.h" 11 #include "chrome/browser/ui/views/autofill/view_util.h"
12 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
13 #include "components/autofill/core/browser/legal_message_line.h" 13 #include "components/autofill/core/browser/legal_message_line.h"
14 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h"
14 #include "components/strings/grit/components_strings.h" 15 #include "components/strings/grit/components_strings.h"
15 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
16 #include "ui/base/resource/resource_bundle.h" 17 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/views/border.h" 18 #include "ui/views/border.h"
18 #include "ui/views/bubble/bubble_frame_view.h" 19 #include "ui/views/bubble/bubble_frame_view.h"
19 #include "ui/views/controls/button/blue_button.h" 20 #include "ui/views/controls/button/blue_button.h"
20 #include "ui/views/controls/button/label_button.h" 21 #include "ui/views/controls/button/label_button.h"
21 #include "ui/views/controls/label.h" 22 #include "ui/views/controls/label.h"
22 #include "ui/views/controls/link.h" 23 #include "ui/views/controls/link.h"
23 #include "ui/views/controls/styled_label.h" 24 #include "ui/views/controls/styled_label.h"
25 #include "ui/views/controls/textfield/textfield.h"
24 #include "ui/views/layout/box_layout.h" 26 #include "ui/views/layout/box_layout.h"
25 #include "ui/views/layout/layout_constants.h" 27 #include "ui/views/layout/layout_constants.h"
28 #include "ui/views/window/dialog_client_view.h"
26 29
27 namespace autofill { 30 namespace autofill {
28 31
29 namespace { 32 namespace {
30 33
31 // Fixed width of the bubble. 34 // Fixed width of the bubble, in dip.
32 const int kBubbleWidth = 395; 35 const int kBubbleWidth = 395;
33 36
34 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( 37 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel(
35 const LegalMessageLine& line, 38 const LegalMessageLine& line,
36 views::StyledLabelListener* listener) { 39 views::StyledLabelListener* listener) {
37 std::unique_ptr<views::StyledLabel> label( 40 std::unique_ptr<views::StyledLabel> label(
38 new views::StyledLabel(line.text(), listener)); 41 new views::StyledLabel(line.text(), listener));
39 for (const LegalMessageLine::Link& link : line.links()) { 42 for (const LegalMessageLine::Link& link : line.links()) {
40 label->AddStyleRange(link.range, 43 label->AddStyleRange(link.range,
41 views::StyledLabel::RangeStyleInfo::CreateForLink()); 44 views::StyledLabel::RangeStyleInfo::CreateForLink());
42 } 45 }
43 return label; 46 return label;
44 } 47 }
45 48
46 } // namespace 49 } // namespace
47 50
48 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, 51 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view,
49 content::WebContents* web_contents, 52 content::WebContents* web_contents,
50 SaveCardBubbleController* controller) 53 SaveCardBubbleController* controller)
51 : LocationBarBubbleDelegateView(anchor_view, web_contents), 54 : LocationBarBubbleDelegateView(anchor_view, web_contents),
52 controller_(controller), 55 controller_(controller),
56 cvc_textfield_(nullptr),
53 learn_more_link_(nullptr) { 57 learn_more_link_(nullptr) {
54 DCHECK(controller); 58 DCHECK(controller);
55 views::BubbleDialogDelegateView::CreateBubble(this); 59 views::BubbleDialogDelegateView::CreateBubble(this);
56 } 60 }
57 61
58 SaveCardBubbleViews::~SaveCardBubbleViews() {} 62 SaveCardBubbleViews::~SaveCardBubbleViews() {}
59 63
60 void SaveCardBubbleViews::Show(DisplayReason reason) { 64 void SaveCardBubbleViews::Show(DisplayReason reason) {
61 ShowForReason(reason); 65 ShowForReason(reason);
62 } 66 }
(...skipping 22 matching lines...) Expand all
85 89
86 // Add a StyledLabel for each line of the legal message. 90 // Add a StyledLabel for each line of the legal message.
87 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) 91 for (const LegalMessageLine& line : controller_->GetLegalMessageLines())
88 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); 92 view->AddChildView(CreateLegalMessageLineLabel(line, this).release());
89 93
90 return view; 94 return view;
91 } 95 }
92 96
93 bool SaveCardBubbleViews::Accept() { 97 bool SaveCardBubbleViews::Accept() {
94 if (controller_) 98 if (controller_)
95 controller_->OnSaveButton(); 99 controller_->OnSaveButton(cvc_textfield_ ? cvc_textfield_->text()
100 : base::string16());
96 return true; 101 return true;
97 } 102 }
98 103
99 bool SaveCardBubbleViews::Cancel() { 104 bool SaveCardBubbleViews::Cancel() {
100 if (controller_) 105 if (controller_)
101 controller_->OnCancelButton(); 106 controller_->OnCancelButton();
102 return true; 107 return true;
103 } 108 }
104 109
105 bool SaveCardBubbleViews::Close() { 110 bool SaveCardBubbleViews::Close() {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 card_type_icon->SetTooltipText(card.TypeForDisplay()); 198 card_type_icon->SetTooltipText(card.TypeForDisplay());
194 card_type_icon->SetBorder( 199 card_type_icon->SetBorder(
195 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); 200 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10)));
196 description_view->AddChildView(card_type_icon); 201 description_view->AddChildView(card_type_icon);
197 202
198 description_view->AddChildView(new views::Label( 203 description_view->AddChildView(new views::Label(
199 base::string16(kMidlineEllipsis) + card.LastFourDigits())); 204 base::string16(kMidlineEllipsis) + card.LastFourDigits()));
200 description_view->AddChildView( 205 description_view->AddChildView(
201 new views::Label(card.AbbreviatedExpirationDateForDisplay())); 206 new views::Label(card.AbbreviatedExpirationDateForDisplay()));
202 207
208 // Optionally add CVC request field if CVC was missing.
209 if (controller_->ShouldRequestCvcFromUser())
210 view->AddChildView(CreateRequestCvcView().release());
211
203 // Optionally add label that will contain an explanation for upload. 212 // Optionally add label that will contain an explanation for upload.
204 base::string16 explanation = controller_->GetExplanatoryMessage(); 213 base::string16 explanation = controller_->GetExplanatoryMessage();
205 if (!explanation.empty()) { 214 if (!explanation.empty()) {
206 views::Label* explanation_label = new views::Label(explanation); 215 views::Label* explanation_label = new views::Label(explanation);
207 explanation_label->SetMultiLine(true); 216 explanation_label->SetMultiLine(true);
208 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); 217 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
209 view->AddChildView(explanation_label); 218 view->AddChildView(explanation_label);
210 } 219 }
211 220
212 return view; 221 return view;
213 } 222 }
214 223
224 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() {
225 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>();
226 request_cvc_view->SetLayoutManager(new views::BoxLayout(
227 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing));
228
229 DCHECK(!cvc_textfield_);
230 cvc_textfield_ = CreateCvcTextfield();
231 cvc_textfield_->set_controller(this);
232 request_cvc_view->AddChildView(cvc_textfield_);
233
234 views::ImageView* cvc_image = new views::ImageView();
235 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
236 cvc_image->SetImage(
237 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId()));
238 request_cvc_view->AddChildView(cvc_image);
239
240 request_cvc_view->AddChildView(new views::Label(
241 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC)));
242 return request_cvc_view;
243 }
244
245 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const {
246 if (button == ui::DIALOG_BUTTON_CANCEL)
247 return true;
248
249 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button);
250 return !cvc_textfield_ ||
251 controller_->InputCvcIsValid(cvc_textfield_->text());
252 }
253
254 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender,
255 const base::string16& new_contents) {
256 DCHECK_EQ(cvc_textfield_, sender);
257 GetDialogClientView()->UpdateDialogButtons();
258 }
259
215 void SaveCardBubbleViews::Init() { 260 void SaveCardBubbleViews::Init() {
216 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); 261 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
217 AddChildView(CreateMainContentView().release()); 262 AddChildView(CreateMainContentView().release());
218 } 263 }
219 264
220 } // namespace autofill 265 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/save_card_bubble_views.h ('k') | chrome/browser/ui/views/autofill/view_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698