| 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_textfield_(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 controller_->SetCvcEnteredByUser(cvc_textfield_->text()); |
| 102 } |
| 95 controller_->OnSaveButton(); | 103 controller_->OnSaveButton(); |
| 104 } |
| 96 return true; | 105 return true; |
| 97 } | 106 } |
| 98 | 107 |
| 99 bool SaveCardBubbleViews::Cancel() { | 108 bool SaveCardBubbleViews::Cancel() { |
| 100 if (controller_) | 109 if (controller_) |
| 101 controller_->OnCancelButton(); | 110 controller_->OnCancelButton(); |
| 102 return true; | 111 return true; |
| 103 } | 112 } |
| 104 | 113 |
| 105 bool SaveCardBubbleViews::Close() { | 114 bool SaveCardBubbleViews::Close() { |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 card_type_icon->SetTooltipText(card.TypeForDisplay()); | 202 card_type_icon->SetTooltipText(card.TypeForDisplay()); |
| 194 card_type_icon->SetBorder( | 203 card_type_icon->SetBorder( |
| 195 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); | 204 views::CreateSolidBorder(1, SkColorSetA(SK_ColorBLACK, 10))); |
| 196 description_view->AddChildView(card_type_icon); | 205 description_view->AddChildView(card_type_icon); |
| 197 | 206 |
| 198 description_view->AddChildView(new views::Label( | 207 description_view->AddChildView(new views::Label( |
| 199 base::string16(kMidlineEllipsis) + card.LastFourDigits())); | 208 base::string16(kMidlineEllipsis) + card.LastFourDigits())); |
| 200 description_view->AddChildView( | 209 description_view->AddChildView( |
| 201 new views::Label(card.AbbreviatedExpirationDateForDisplay())); | 210 new views::Label(card.AbbreviatedExpirationDateForDisplay())); |
| 202 | 211 |
| 212 // Optionally add CVC request field if CVC was missing. |
| 213 if (controller_->ShouldRequestCvcFromUser()) { |
| 214 view->AddChildView(CreateRequestCvcView().release()); |
| 215 } |
| 216 |
| 203 // Optionally add label that will contain an explanation for upload. | 217 // Optionally add label that will contain an explanation for upload. |
| 204 base::string16 explanation = controller_->GetExplanatoryMessage(); | 218 base::string16 explanation = controller_->GetExplanatoryMessage(); |
| 205 if (!explanation.empty()) { | 219 if (!explanation.empty()) { |
| 206 views::Label* explanation_label = new views::Label(explanation); | 220 views::Label* explanation_label = new views::Label(explanation); |
| 207 explanation_label->SetMultiLine(true); | 221 explanation_label->SetMultiLine(true); |
| 208 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 222 explanation_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 209 view->AddChildView(explanation_label); | 223 view->AddChildView(explanation_label); |
| 210 } | 224 } |
| 211 | 225 |
| 212 return view; | 226 return view; |
| 213 } | 227 } |
| 214 | 228 |
| 229 std::unique_ptr<views::View> SaveCardBubbleViews::CreateRequestCvcView() { |
| 230 std::unique_ptr<View> request_cvc_view = base::MakeUnique<views::View>(); |
| 231 request_cvc_view->SetLayoutManager( |
| 232 base::MakeUnique<views::BoxLayout>(views::BoxLayout::kHorizontal, 0, 0, |
| 233 views::kRelatedButtonHSpacing) |
| 234 .release()); |
| 235 |
| 236 DCHECK(!cvc_textfield_); |
| 237 cvc_textfield_ = new views::Textfield(); |
| 238 cvc_textfield_->set_placeholder_text( |
| 239 l10n_util::GetStringUTF16(IDS_AUTOFILL_DIALOG_PLACEHOLDER_CVC)); |
| 240 cvc_textfield_->set_controller(this); |
| 241 cvc_textfield_->set_default_width_in_chars(kDefaultWidthForCvc); |
| 242 request_cvc_view->AddChildView(cvc_textfield_); |
| 243 |
| 244 std::unique_ptr<views::ImageView> cvc_image = |
| 245 base::MakeUnique<views::ImageView>(); |
| 246 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 247 cvc_image->SetImage( |
| 248 rb.GetImageSkiaNamed(controller_->GetCvcImageResourceId())); |
| 249 request_cvc_view->AddChildView(cvc_image.release()); |
| 250 |
| 251 request_cvc_view->AddChildView(new views::Label( |
| 252 l10n_util::GetStringUTF16(IDS_AUTOFILL_SAVE_CARD_PROMPT_ENTER_CVC))); |
| 253 return request_cvc_view; |
| 254 } |
| 255 |
| 256 bool SaveCardBubbleViews::IsDialogButtonEnabled(ui::DialogButton button) const { |
| 257 if (button == ui::DIALOG_BUTTON_CANCEL) |
| 258 return true; |
| 259 |
| 260 DCHECK_EQ(ui::DIALOG_BUTTON_OK, button); |
| 261 return !cvc_textfield_ || |
| 262 controller_->InputCvcIsValid(cvc_textfield_->text()); |
| 263 } |
| 264 |
| 265 void SaveCardBubbleViews::ContentsChanged(views::Textfield* sender, |
| 266 const base::string16& new_contents) { |
| 267 GetDialogClientView()->UpdateDialogButtons(); |
| 268 } |
| 269 |
| 215 void SaveCardBubbleViews::Init() { | 270 void SaveCardBubbleViews::Init() { |
| 216 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 271 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 217 AddChildView(CreateMainContentView().release()); | 272 AddChildView(CreateMainContentView().release()); |
| 218 } | 273 } |
| 219 | 274 |
| 220 } // namespace autofill | 275 } // namespace autofill |
| OLD | NEW |