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; |
33 | 35 |
34 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( | 36 std::unique_ptr<views::StyledLabel> CreateLegalMessageLineLabel( |
35 const LegalMessageLine& line, | 37 const LegalMessageLine& line, |
36 views::StyledLabelListener* listener) { | 38 views::StyledLabelListener* listener) { |
37 std::unique_ptr<views::StyledLabel> label( | 39 std::unique_ptr<views::StyledLabel> label( |
38 new views::StyledLabel(line.text(), listener)); | 40 new views::StyledLabel(line.text(), listener)); |
39 for (const LegalMessageLine::Link& link : line.links()) { | 41 for (const LegalMessageLine::Link& link : line.links()) { |
40 label->AddStyleRange(link.range, | 42 label->AddStyleRange(link.range, |
41 views::StyledLabel::RangeStyleInfo::CreateForLink()); | 43 views::StyledLabel::RangeStyleInfo::CreateForLink()); |
42 } | 44 } |
43 return label; | 45 return label; |
44 } | 46 } |
45 | 47 |
46 } // namespace | 48 } // namespace |
47 | 49 |
48 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, | 50 SaveCardBubbleViews::SaveCardBubbleViews(views::View* anchor_view, |
49 content::WebContents* web_contents, | 51 content::WebContents* web_contents, |
50 SaveCardBubbleController* controller) | 52 SaveCardBubbleController* controller) |
51 : LocationBarBubbleDelegateView(anchor_view, web_contents), | 53 : LocationBarBubbleDelegateView(anchor_view, web_contents), |
52 controller_(controller), | 54 controller_(controller), |
55 cvc_input_(nullptr), | |
53 learn_more_link_(nullptr) { | 56 learn_more_link_(nullptr) { |
54 DCHECK(controller); | 57 DCHECK(controller); |
55 views::BubbleDialogDelegateView::CreateBubble(this); | 58 views::BubbleDialogDelegateView::CreateBubble(this); |
56 } | 59 } |
57 | 60 |
58 SaveCardBubbleViews::~SaveCardBubbleViews() {} | 61 SaveCardBubbleViews::~SaveCardBubbleViews() {} |
59 | 62 |
60 void SaveCardBubbleViews::Show(DisplayReason reason) { | 63 void SaveCardBubbleViews::Show(DisplayReason reason) { |
61 ShowForReason(reason); | 64 ShowForReason(reason); |
62 } | 65 } |
(...skipping 21 matching lines...) Expand all Loading... | |
84 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 87 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
85 | 88 |
86 // Add a StyledLabel for each line of the legal message. | 89 // Add a StyledLabel for each line of the legal message. |
87 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) | 90 for (const LegalMessageLine& line : controller_->GetLegalMessageLines()) |
88 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); | 91 view->AddChildView(CreateLegalMessageLineLabel(line, this).release()); |
89 | 92 |
90 return view; | 93 return view; |
91 } | 94 } |
92 | 95 |
93 bool SaveCardBubbleViews::Accept() { | 96 bool SaveCardBubbleViews::Accept() { |
94 if (controller_) | 97 if (controller_) { |
98 if (controller_->ShouldRequestCvcFromUser()) { | |
99 const base::string16& cvc = cvc_input_->text(); | |
100 controller_->SetUserProvidedCvc(cvc); | |
101 } | |
95 controller_->OnSaveButton(); | 102 controller_->OnSaveButton(); |
103 } | |
96 return true; | 104 return true; |
97 } | 105 } |
98 | 106 |
99 bool SaveCardBubbleViews::Cancel() { | 107 bool SaveCardBubbleViews::Cancel() { |
100 if (controller_) | 108 if (controller_) |
101 controller_->OnCancelButton(); | 109 controller_->OnCancelButton(); |
102 return true; | 110 return true; |
103 } | 111 } |
104 | 112 |
105 bool SaveCardBubbleViews::Close() { | 113 bool SaveCardBubbleViews::Close() { |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 card_type_icon->SetTooltipText(card.TypeForDisplay()); | 201 card_type_icon->SetTooltipText(card.TypeForDisplay()); |
194 card_type_icon->SetBorder( | 202 card_type_icon->SetBorder( |
195 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); | 203 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); |
196 description_view->AddChildView(card_type_icon); | 204 description_view->AddChildView(card_type_icon); |
197 | 205 |
198 description_view->AddChildView(new views::Label( | 206 description_view->AddChildView(new views::Label( |
199 base::string16(kMidlineEllipsis) + card.LastFourDigits())); | 207 base::string16(kMidlineEllipsis) + card.LastFourDigits())); |
200 description_view->AddChildView( | 208 description_view->AddChildView( |
201 new views::Label(card.AbbreviatedExpirationDateForDisplay())); | 209 new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
202 | 210 |
211 // Optionally add CVC request field if CVC was missing. | |
212 if (controller_->ShouldRequestCvcFromUser()) { | |
213 views::View* request_cvc_view = new views::View(); | |
214 request_cvc_view->SetLayoutManager(new views::BoxLayout( | |
215 views::BoxLayout::kHorizontal, 0, 0, views::kRelatedButtonHSpacing)); | |
216 DCHECK(!cvc_input_); | |
217 cvc_input_ = new views::Textfield(); | |
218 cvc_input_->set_placeholder_text( | |
219 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)); | |
220 cvc_input_->set_controller(this); | |
221 cvc_input_->set_default_width_in_chars(8); | |
csashi
2017/03/31 21:48:15
s/8/kDefaultWidthForCVC?
Jared Saul
2017/04/01 04:18:02
Sure. Not 100% sure where this goes so I put it i
| |
222 request_cvc_view->AddChildView(cvc_input_); | |
223 views::ImageView* cvc_image = new views::ImageView(); | |
224 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
225 cvc_image->SetImage(rb.GetImageSkiaNamed(controller_->GetCvcImageRid())); | |
226 request_cvc_view->AddChildView(cvc_image); | |
227 request_cvc_view->AddChildView(new views::Label( | |
228 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); | |
csashi
2017/03/31 21:48:15
May be add a helper for creating this new view?
Jared Saul
2017/04/01 04:18:02
Done.
| |
229 view->AddChildView(request_cvc_view); | |
230 } | |
231 | |
203 // Optionally add label that will contain an explanation for upload. | 232 // Optionally add label that will contain an explanation for upload. |
204 base::string16 explanation = controller_->GetExplanatoryMessage(); | 233 base::string16 explanation = controller_->GetExplanatoryMessage(); |
205 if (!explanation.empty()) { | 234 if (!explanation.empty()) { |
206 views::Label* explanation_label = new views::Label(explanation); | 235 views::Label* explanation_label = new views::Label(explanation); |
207 explanation_label->SetMultiLine(true); | 236 explanation_label->SetMultiLine(true); |
208 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 237 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
209 view->AddChildView(explanation_label); | 238 view->AddChildView(explanation_label); |
210 } | 239 } |
211 | 240 |
212 return view; | 241 return view; |
213 } | 242 } |
214 | 243 |
244 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { | |
245 if (button == ui::DIALOG_BUTTON_CANCEL) | |
246 return true; | |
247 | |
248 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); | |
249 return !controller_->ShouldRequestCvcFromUser() || | |
250 (cvc_input_->enabled() && | |
251 controller_->InputCvcIsValid(cvc_input_->text())); | |
252 } | |
253 | |
254 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, | |
255 const base::string16& new_contents) { | |
256 GetDialogClientView()->UpdateDialogButtons(); | |
csashi
2017/03/31 21:48:15
For my understanding, can you confirm that UpdateD
Jared Saul
2017/04/01 04:18:02
Not sure what you mean. Whenever the user changes
| |
257 } | |
258 | |
215 void SaveCardBubbleViews::Init() { | 259 void SaveCardBubbleViews::Init() { |
216 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 260 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
217 AddChildView(CreateMainContentView().release()); | 261 AddChildView(CreateMainContentView().release()); |
218 } | 262 } |
219 | 263 |
220 } // namespace autofill | 264 } // namespace autofill |
OLD | NEW |