OLD | NEW |
---|---|
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" | |
12 #include "components/autofill/core/browser/credit_card.h" | 11 #include "components/autofill/core/browser/credit_card.h" |
13 #include "components/autofill/core/browser/legal_message_line.h" | 12 #include "components/autofill/core/browser/legal_message_line.h" |
13 #include "components/autofill/core/browser/ui/save_card_bubble_controller.h" | |
14 #include "components/strings/grit/components_strings.h" | 14 #include "components/strings/grit/components_strings.h" |
15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
16 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/views/border.h" | 17 #include "ui/views/border.h" |
18 #include "ui/views/bubble/bubble_frame_view.h" | 18 #include "ui/views/bubble/bubble_frame_view.h" |
19 #include "ui/views/controls/button/blue_button.h" | 19 #include "ui/views/controls/button/blue_button.h" |
20 #include "ui/views/controls/button/label_button.h" | 20 #include "ui/views/controls/button/label_button.h" |
21 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
22 #include "ui/views/controls/link.h" | 22 #include "ui/views/controls/link.h" |
23 #include "ui/views/controls/styled_label.h" | 23 #include "ui/views/controls/styled_label.h" |
24 #include "ui/views/controls/textfield/textfield.h" | |
24 #include "ui/views/layout/box_layout.h" | 25 #include "ui/views/layout/box_layout.h" |
25 #include "ui/views/layout/layout_constants.h" | 26 #include "ui/views/layout/layout_constants.h" |
27 #include "ui/views/window/dialog_client_view.h" | |
26 | 28 |
27 namespace autofill { | 29 namespace autofill { |
28 | 30 |
29 namespace { | 31 namespace { |
30 | 32 |
31 // Fixed width of the bubble. | 33 // Fixed width of the bubble. |
32 const int kBubbleWidth = 395; | 34 const int kBubbleWidth = 395; |
35 // Fixed width of the CVC TextField. | |
36 const int kDefaultWidthForCvc = 8; | |
33 | 37 |
34 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( | 38 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( |
35 const LegalMessageLine& line, | 39 const LegalMessageLine& line, |
36 views::StyledLabelListener* listener) { | 40 views::StyledLabelListener* listener) { |
37 std::unique_ptr<views::StyledLabel> label( | 41 std::unique_ptr<views::StyledLabel> label( |
38 new views::StyledLabel(line.text(), listener)); | 42 new views::StyledLabel(line.text(), listener)); |
39 for (const LegalMessageLine::Link& link : line.links()) { | 43 for (const LegalMessageLine::Link& link : line.links()) { |
40 label->AddStyleRange(link.range, | 44 label->AddStyleRange(link.range, |
41 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 45 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
42 } | 46 } |
43 return label; | 47 return label; |
44 } | 48 } |
45 | 49 |
46 } // namespace | 50 } // namespace |
47 | 51 |
48 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, | 52 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, |
49 content::WebContents* web_contents, | 53 content::WebContents* web_contents, |
50 SaveCardBubbleController* controller) | 54 SaveCardBubbleController* controller) |
51 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 55 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
52 controller_(controller), | 56 controller_(controller), |
57 cvc_input_(nullptr), | |
53 learn_more_link_(nullptr) { | 58 learn_more_link_(nullptr) { |
54 DCHECK(controller); | 59 DCHECK(controller); |
55 views::BubbleDialogDelegateView::CreateBubble(this); | 60 views::BubbleDialogDelegateView::CreateBubble(this); |
56 } | 61 } |
57 | 62 |
58 SaveCardBubbleViews::~SaveCardBubbleViews() {} | 63 SaveCardBubbleViews::~SaveCardBubbleViews() {} |
59 | 64 |
60 void SaveCardBubbleViews::Show(DisplayReason reason) { | 65 void SaveCardBubbleViews::Show(DisplayReason reason) { |
61 ShowForReason(reason); | 66 ShowForReason(reason); |
62 } | 67 } |
(...skipping 21 matching lines...) Expand all Loading... | |
84 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 89 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
85 | 90 |
86 // Add a StyledLabel for each line of the legal message. | 91 // Add a StyledLabel for each line of the legal message. |
87 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) | 92 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) |
88 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); | 93 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); |
89 | 94 |
90 return view; | 95 return view; |
91 } | 96 } |
92 | 97 |
93 bool SaveCardBubbleViews::Accept() { | 98 bool SaveCardBubbleViews::Accept() { |
94 if (controller_) | 99 if (controller_) { |
100 if (controller_->ShouldRequestCvcFromUser()) { | |
101 const base::string16& cvc = cvc_input_->text(); | |
102 controller_->SetCvcEnteredByUser(cvc); | |
Mathieu
2017/04/03 19:46:09
controller_->SetCvcEnteredByUser(cvc_input_->text(
Jared Saul
2017/04/03 21:19:17
Done.
| |
103 } | |
95 controller_->OnSaveButton(); | 104 controller_->OnSaveButton(); |
105 } | |
96 return true; | 106 return true; |
97 } | 107 } |
98 | 108 |
99 bool SaveCardBubbleViews::Cancel() { | 109 bool SaveCardBubbleViews::Cancel() { |
100 if (controller_) | 110 if (controller_) |
101 controller_->OnCancelButton(); | 111 controller_->OnCancelButton(); |
102 return true; | 112 return true; |
103 } | 113 } |
104 | 114 |
105 bool SaveCardBubbleViews::Close() { | 115 bool SaveCardBubbleViews::Close() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 card_type_icon->SetTooltipText(card.TypeForDisplay()); | 203 card_type_icon->SetTooltipText(card.TypeForDisplay()); |
194 card_type_icon->SetBorder( | 204 card_type_icon->SetBorder( |
195 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); | 205 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); |
196 description_view->AddChildView(card_type_icon); | 206 description_view->AddChildView(card_type_icon); |
197 | 207 |
198 description_view->AddChildView(new views::Label( | 208 description_view->AddChildView(new views::Label( |
199 base::string16(kMidlineEllipsis) + card.LastFourDigits())); | 209 base::string16(kMidlineEllipsis) + card.LastFourDigits())); |
200 description_view->AddChildView( | 210 description_view->AddChildView( |
201 new views::Label(card.AbbreviatedExpirationDateForDisplay())); | 211 new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
202 | 212 |
213 // Optionally add CVC request field if CVC was missing. | |
214 if (controller_->ShouldRequestCvcFromUser()) { | |
215 view->AddChildView(CreateRequestCvcView().release()); | |
216 } | |
217 | |
203 // Optionally add label that will contain an explanation for upload. | 218 // Optionally add label that will contain an explanation for upload. |
204 base::string16 explanation = controller_->GetExplanatoryMessage(); | 219 base::string16 explanation = controller_->GetExplanatoryMessage(); |
205 if (!explanation.empty()) { | 220 if (!explanation.empty()) { |
206 views::Label* explanation_label = new views::Label(explanation); | 221 views::Label* explanation_label = new views::Label(explanation); |
207 explanation_label->SetMultiLine(true); | 222 explanation_label->SetMultiLine(true); |
208 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 223 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
209 view->AddChildView(explanation_label); | 224 view->AddChildView(explanation_label); |
210 } | 225 } |
211 | 226 |
212 return view; | 227 return view; |
213 } | 228 } |
214 | 229 |
230 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { | |
231 std::unique_ptr<View> request_cvc_view(new View()); | |
Mathieu
2017/04/03 19:46:09
std::unique_ptr<View> request_cvc_view = base::Mak
Jared Saul
2017/04/03 21:19:18
Done.
| |
232 request_cvc_view->SetLayoutManager(new views::BoxLayout( | |
Mathieu
2017/04/03 19:46:09
please use the same pattern for BoxLayout... MakeU
Jared Saul
2017/04/03 21:19:18
How's this?
| |
233 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); | |
234 | |
235 DCHECK(!cvc_input_); | |
236 cvc_input_ = new views::Textfield(); | |
237 cvc_input_->set_placeholder_text( | |
238 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)); | |
239 cvc_input_->set_controller(this); | |
240 cvc_input_->set_default_width_in_chars(kDefaultWidthForCvc); | |
241 request_cvc_view->AddChildView(cvc_input_); | |
242 | |
243 views::ImageView* cvc_image = new views::ImageView(); | |
Mathieu
2017/04/03 19:46:09
std::unique_ptr, MakeUnique and .release()
Jared Saul
2017/04/03 21:19:18
Done.
| |
244 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
245 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); | |
246 request_cvc_view->AddChildView(cvc_image); | |
247 | |
248 request_cvc_view->AddChildView(new views::Label( | |
249 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); | |
250 return request_cvc_view; | |
251 } | |
252 | |
253 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { | |
254 if (button == ui::DIALOG_BUTTON_CANCEL) | |
255 return true; | |
256 | |
257 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); | |
258 return !controller_->ShouldRequestCvcFromUser() || | |
Mathieu
2017/04/03 19:46:09
return !cvc_input_ || controller_->InputCvcIsValid
Jared Saul
2017/04/03 21:19:18
Done.
| |
259 (cvc_input_->enabled() && | |
260 controller_->InputCvcIsValid(cvc_input_->text())); | |
261 } | |
262 | |
263 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, | |
264 const base::string16& new_contents) { | |
265 GetDialogClientView()->UpdateDialogButtons(); | |
266 } | |
267 | |
215 void SaveCardBubbleViews::Init() { | 268 void SaveCardBubbleViews::Init() { |
216 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 269 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
217 AddChildView(CreateMainContentView().release()); | 270 AddChildView(CreateMainContentView().release()); |
218 } | 271 } |
219 | 272 |
220 } // namespace autofill | 273 } // namespace autofill |
OLD | NEW |