OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/card_unmask_prompt_views.h" | 5 #include "chrome/browser/ui/views/autofill/card_unmask_prompt_views.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 9 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" | 10 #include "chrome/browser/ui/autofill/card_unmask_prompt_controller.h" |
11 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" | 11 #include "chrome/browser/ui/views/autofill/decorated_textfield.h" |
12 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" | 12 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" |
13 #include "chrome/grit/generated_resources.h" | 13 #include "chrome/grit/generated_resources.h" |
14 #include "components/constrained_window/constrained_window_views.h" | 14 #include "components/constrained_window/constrained_window_views.h" |
15 #include "components/web_modal/web_contents_modal_dialog_host.h" | 15 #include "components/web_modal/web_contents_modal_dialog_host.h" |
16 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 16 #include "components/web_modal/web_contents_modal_dialog_manager.h" |
17 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" | 17 #include "components/web_modal/web_contents_modal_dialog_manager_delegate.h" |
18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
19 #include "third_party/skia/include/core/SkColor.h" | 19 #include "third_party/skia/include/core/SkColor.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
23 #include "ui/views/background.h" | 23 #include "ui/views/background.h" |
24 #include "ui/views/controls/button/checkbox.h" | 24 #include "ui/views/controls/button/checkbox.h" |
25 #include "ui/views/controls/combobox/combobox.h" | 25 #include "ui/views/controls/combobox/combobox.h" |
26 #include "ui/views/controls/image_view.h" | 26 #include "ui/views/controls/image_view.h" |
27 #include "ui/views/controls/label.h" | 27 #include "ui/views/controls/label.h" |
| 28 #include "ui/views/controls/throbber.h" |
28 #include "ui/views/layout/box_layout.h" | 29 #include "ui/views/layout/box_layout.h" |
29 #include "ui/views/widget/widget.h" | 30 #include "ui/views/widget/widget.h" |
30 #include "ui/views/window/dialog_client_view.h" | 31 #include "ui/views/window/dialog_client_view.h" |
31 | 32 |
32 namespace autofill { | 33 namespace autofill { |
33 | 34 |
34 // The number of pixels of blank space on the outer horizontal edges of the | 35 // The number of pixels of blank space on the outer horizontal edges of the |
35 // dialog. | 36 // dialog. |
36 const int kEdgePadding = 19; | 37 const int kEdgePadding = 19; |
37 | 38 |
(...skipping 15 matching lines...) Expand all Loading... |
53 main_contents_(nullptr), | 54 main_contents_(nullptr), |
54 permanent_error_label_(nullptr), | 55 permanent_error_label_(nullptr), |
55 input_row_(nullptr), | 56 input_row_(nullptr), |
56 cvc_input_(nullptr), | 57 cvc_input_(nullptr), |
57 month_input_(nullptr), | 58 month_input_(nullptr), |
58 year_input_(nullptr), | 59 year_input_(nullptr), |
59 error_label_(nullptr), | 60 error_label_(nullptr), |
60 storage_row_(nullptr), | 61 storage_row_(nullptr), |
61 storage_checkbox_(nullptr), | 62 storage_checkbox_(nullptr), |
62 progress_overlay_(nullptr), | 63 progress_overlay_(nullptr), |
| 64 progress_throbber_(nullptr), |
63 progress_label_(nullptr), | 65 progress_label_(nullptr), |
64 overlay_animation_(this), | 66 overlay_animation_(this), |
65 weak_ptr_factory_(this) { | 67 weak_ptr_factory_(this) { |
66 } | 68 } |
67 | 69 |
68 CardUnmaskPromptViews::~CardUnmaskPromptViews() { | 70 CardUnmaskPromptViews::~CardUnmaskPromptViews() { |
69 if (controller_) | 71 if (controller_) |
70 controller_->OnUnmaskDialogClosed(); | 72 controller_->OnUnmaskDialogClosed(); |
71 } | 73 } |
72 | 74 |
73 void CardUnmaskPromptViews::Show() { | 75 void CardUnmaskPromptViews::Show() { |
74 constrained_window::ShowWebModalDialogViews(this, | 76 constrained_window::ShowWebModalDialogViews(this, |
75 controller_->GetWebContents()); | 77 controller_->GetWebContents()); |
76 } | 78 } |
77 | 79 |
78 void CardUnmaskPromptViews::ControllerGone() { | 80 void CardUnmaskPromptViews::ControllerGone() { |
79 controller_ = nullptr; | 81 controller_ = nullptr; |
80 ClosePrompt(); | 82 ClosePrompt(); |
81 } | 83 } |
82 | 84 |
83 void CardUnmaskPromptViews::DisableAndWaitForVerification() { | 85 void CardUnmaskPromptViews::DisableAndWaitForVerification() { |
84 SetInputsEnabled(false); | 86 SetInputsEnabled(false); |
85 progress_overlay_->SetOpacity(0.0); | 87 progress_overlay_->SetOpacity(0.0); |
86 progress_overlay_->SetVisible(true); | 88 progress_overlay_->SetVisible(true); |
| 89 progress_throbber_->Start(); |
87 overlay_animation_.Show(); | 90 overlay_animation_.Show(); |
88 GetDialogClientView()->UpdateDialogButtons(); | 91 GetDialogClientView()->UpdateDialogButtons(); |
89 Layout(); | 92 Layout(); |
90 } | 93 } |
91 | 94 |
92 void CardUnmaskPromptViews::GotVerificationResult( | 95 void CardUnmaskPromptViews::GotVerificationResult( |
93 const base::string16& error_message, | 96 const base::string16& error_message, |
94 bool allow_retry) { | 97 bool allow_retry) { |
| 98 progress_throbber_->Stop(); |
95 if (error_message.empty()) { | 99 if (error_message.empty()) { |
96 progress_label_->SetText(l10n_util::GetStringUTF16( | 100 progress_label_->SetText(l10n_util::GetStringUTF16( |
97 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)); | 101 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)); |
| 102 progress_throbber_->SetChecked(true); |
98 base::MessageLoop::current()->PostDelayedTask( | 103 base::MessageLoop::current()->PostDelayedTask( |
99 FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt, | 104 FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt, |
100 weak_ptr_factory_.GetWeakPtr()), | 105 weak_ptr_factory_.GetWeakPtr()), |
101 controller_->GetSuccessMessageDuration()); | 106 controller_->GetSuccessMessageDuration()); |
102 } else { | 107 } else { |
103 // TODO(estade): it's somewhat jarring when the error comes back too | 108 // TODO(estade): it's somewhat jarring when the error comes back too |
104 // quickly. | 109 // quickly. |
105 overlay_animation_.Reset(); | 110 overlay_animation_.Reset(); |
106 storage_row_->SetOpacity(1.0); | 111 storage_row_->SetOpacity(1.0); |
107 progress_overlay_->SetVisible(false); | 112 progress_overlay_->SetVisible(false); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 const gfx::Insets insets = GetInsets(); | 220 const gfx::Insets insets = GetInsets(); |
216 return main_contents_->GetHeightForWidth(width - insets.width()) + | 221 return main_contents_->GetHeightForWidth(width - insets.width()) + |
217 insets.height(); | 222 insets.height(); |
218 } | 223 } |
219 | 224 |
220 void CardUnmaskPromptViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 225 void CardUnmaskPromptViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
221 SkColor bg_color = | 226 SkColor bg_color = |
222 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); | 227 theme->GetSystemColor(ui::NativeTheme::kColorId_DialogBackground); |
223 progress_overlay_->set_background( | 228 progress_overlay_->set_background( |
224 views::Background::CreateSolidBackground(bg_color)); | 229 views::Background::CreateSolidBackground(bg_color)); |
| 230 progress_label_->SetBackgroundColor(bg_color); |
225 } | 231 } |
226 | 232 |
227 ui::ModalType CardUnmaskPromptViews::GetModalType() const { | 233 ui::ModalType CardUnmaskPromptViews::GetModalType() const { |
228 return ui::MODAL_TYPE_CHILD; | 234 return ui::MODAL_TYPE_CHILD; |
229 } | 235 } |
230 | 236 |
231 base::string16 CardUnmaskPromptViews::GetWindowTitle() const { | 237 base::string16 CardUnmaskPromptViews::GetWindowTitle() const { |
232 return controller_->GetWindowTitle(); | 238 return controller_->GetWindowTitle(); |
233 } | 239 } |
234 | 240 |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 // Reserve vertical space for the error label, assuming it's one line. | 395 // Reserve vertical space for the error label, assuming it's one line. |
390 error_label_ = new views::Label(base::ASCIIToUTF16(" ")); | 396 error_label_ = new views::Label(base::ASCIIToUTF16(" ")); |
391 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 397 error_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
392 error_label_->SetEnabledColor(kWarningColor); | 398 error_label_->SetEnabledColor(kWarningColor); |
393 error_label_->SetBorder(views::Border::CreateEmptyBorder(3, 0, 5, 0)); | 399 error_label_->SetBorder(views::Border::CreateEmptyBorder(3, 0, 5, 0)); |
394 controls_container->AddChildView(error_label_); | 400 controls_container->AddChildView(error_label_); |
395 | 401 |
396 progress_overlay_ = new FadeOutView(); | 402 progress_overlay_ = new FadeOutView(); |
397 progress_overlay_->set_fade_everything(true); | 403 progress_overlay_->set_fade_everything(true); |
398 views::BoxLayout* progress_layout = | 404 views::BoxLayout* progress_layout = |
399 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0); | 405 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 5); |
| 406 progress_layout->set_cross_axis_alignment( |
| 407 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); |
400 progress_layout->set_main_axis_alignment( | 408 progress_layout->set_main_axis_alignment( |
401 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); | 409 views::BoxLayout::MAIN_AXIS_ALIGNMENT_CENTER); |
402 progress_layout->set_cross_axis_alignment( | |
403 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
404 progress_overlay_->SetLayoutManager(progress_layout); | 410 progress_overlay_->SetLayoutManager(progress_layout); |
405 | 411 |
406 progress_overlay_->SetVisible(false); | 412 progress_overlay_->SetVisible(false); |
407 AddChildView(progress_overlay_); | 413 AddChildView(progress_overlay_); |
408 | 414 |
| 415 progress_throbber_ = new views::CheckmarkThrobber(); |
| 416 progress_overlay_->AddChildView(progress_throbber_); |
| 417 |
409 progress_label_ = new views::Label(l10n_util::GetStringUTF16( | 418 progress_label_ = new views::Label(l10n_util::GetStringUTF16( |
410 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_IN_PROGRESS)); | 419 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_IN_PROGRESS)); |
| 420 // Material blue. TODO(estade): find an appropriate place for this color. |
| 421 progress_label_->SetEnabledColor(SkColorSetRGB(0x42, 0x85, 0xF4)); |
411 progress_overlay_->AddChildView(progress_label_); | 422 progress_overlay_->AddChildView(progress_label_); |
412 } | 423 } |
413 | 424 |
414 bool CardUnmaskPromptViews::ExpirationDateIsValid() const { | 425 bool CardUnmaskPromptViews::ExpirationDateIsValid() const { |
415 if (!controller_->ShouldRequestExpirationDate()) | 426 if (!controller_->ShouldRequestExpirationDate()) |
416 return true; | 427 return true; |
417 | 428 |
418 return controller_->InputExpirationIsValid( | 429 return controller_->InputExpirationIsValid( |
419 month_input_->GetTextForRow(month_input_->selected_index()), | 430 month_input_->GetTextForRow(month_input_->selected_index()), |
420 year_input_->GetTextForRow(year_input_->selected_index())); | 431 year_input_->GetTextForRow(year_input_->selected_index())); |
(...skipping 28 matching lines...) Expand all Loading... |
449 views::View::OnPaint(canvas); | 460 views::View::OnPaint(canvas); |
450 canvas->Restore(); | 461 canvas->Restore(); |
451 } | 462 } |
452 | 463 |
453 void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) { | 464 void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) { |
454 opacity_ = opacity; | 465 opacity_ = opacity; |
455 SchedulePaint(); | 466 SchedulePaint(); |
456 } | 467 } |
457 | 468 |
458 } // namespace autofill | 469 } // namespace autofill |
OLD | NEW |