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

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

Issue 1064213002: views: Change CardUnmaskPromptViews::FadeOutView opacity to alpha. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: alpha-view: gfx Created 5 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
« no previous file with comments | « chrome/browser/ui/views/autofill/card_unmask_prompt_views.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/compositor/compositing_recorder.h" 22 #include "ui/compositor/compositing_recorder.h"
23 #include "ui/compositor/paint_context.h" 23 #include "ui/compositor/paint_context.h"
24 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/geometry/safe_integer_conversions.h"
25 #include "ui/views/background.h" 26 #include "ui/views/background.h"
26 #include "ui/views/controls/button/checkbox.h" 27 #include "ui/views/controls/button/checkbox.h"
27 #include "ui/views/controls/combobox/combobox.h" 28 #include "ui/views/controls/combobox/combobox.h"
28 #include "ui/views/controls/image_view.h" 29 #include "ui/views/controls/image_view.h"
29 #include "ui/views/controls/label.h" 30 #include "ui/views/controls/label.h"
30 #include "ui/views/controls/throbber.h" 31 #include "ui/views/controls/throbber.h"
31 #include "ui/views/layout/box_layout.h" 32 #include "ui/views/layout/box_layout.h"
32 #include "ui/views/widget/widget.h" 33 #include "ui/views/widget/widget.h"
33 #include "ui/views/window/dialog_client_view.h" 34 #include "ui/views/window/dialog_client_view.h"
34 35
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 controller_->GetWebContents()); 79 controller_->GetWebContents());
79 } 80 }
80 81
81 void CardUnmaskPromptViews::ControllerGone() { 82 void CardUnmaskPromptViews::ControllerGone() {
82 controller_ = nullptr; 83 controller_ = nullptr;
83 ClosePrompt(); 84 ClosePrompt();
84 } 85 }
85 86
86 void CardUnmaskPromptViews::DisableAndWaitForVerification() { 87 void CardUnmaskPromptViews::DisableAndWaitForVerification() {
87 SetInputsEnabled(false); 88 SetInputsEnabled(false);
88 progress_overlay_->SetOpacity(0.0); 89 progress_overlay_->SetAlpha(0);
89 progress_overlay_->SetVisible(true); 90 progress_overlay_->SetVisible(true);
90 progress_throbber_->Start(); 91 progress_throbber_->Start();
91 overlay_animation_.Show(); 92 overlay_animation_.Show();
92 GetDialogClientView()->UpdateDialogButtons(); 93 GetDialogClientView()->UpdateDialogButtons();
93 Layout(); 94 Layout();
94 } 95 }
95 96
96 void CardUnmaskPromptViews::GotVerificationResult( 97 void CardUnmaskPromptViews::GotVerificationResult(
97 const base::string16& error_message, 98 const base::string16& error_message,
98 bool allow_retry) { 99 bool allow_retry) {
99 progress_throbber_->Stop(); 100 progress_throbber_->Stop();
100 if (error_message.empty()) { 101 if (error_message.empty()) {
101 progress_label_->SetText(l10n_util::GetStringUTF16( 102 progress_label_->SetText(l10n_util::GetStringUTF16(
102 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS)); 103 IDS_AUTOFILL_CARD_UNMASK_VERIFICATION_SUCCESS));
103 progress_throbber_->SetChecked(true); 104 progress_throbber_->SetChecked(true);
104 base::MessageLoop::current()->PostDelayedTask( 105 base::MessageLoop::current()->PostDelayedTask(
105 FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt, 106 FROM_HERE, base::Bind(&CardUnmaskPromptViews::ClosePrompt,
106 weak_ptr_factory_.GetWeakPtr()), 107 weak_ptr_factory_.GetWeakPtr()),
107 controller_->GetSuccessMessageDuration()); 108 controller_->GetSuccessMessageDuration());
108 } else { 109 } else {
109 // TODO(estade): it's somewhat jarring when the error comes back too 110 // TODO(estade): it's somewhat jarring when the error comes back too
110 // quickly. 111 // quickly.
111 overlay_animation_.Reset(); 112 overlay_animation_.Reset();
112 storage_row_->SetOpacity(1.0); 113 storage_row_->SetAlpha(255);
113 progress_overlay_->SetVisible(false); 114 progress_overlay_->SetVisible(false);
114 115
115 if (allow_retry) { 116 if (allow_retry) {
116 SetInputsEnabled(true); 117 SetInputsEnabled(true);
117 118
118 // If there is more than one input showing, don't mark anything as 119 // If there is more than one input showing, don't mark anything as
119 // invalid since we don't know the location of the problem. 120 // invalid since we don't know the location of the problem.
120 if (!controller_->ShouldRequestExpirationDate()) 121 if (!controller_->ShouldRequestExpirationDate())
121 cvc_input_->SetInvalid(true); 122 cvc_input_->SetInvalid(true);
122 123
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 year_input_->SetInvalid(true); 320 year_input_->SetInvalid(true);
320 SetRetriableErrorMessage(l10n_util::GetStringUTF16( 321 SetRetriableErrorMessage(l10n_util::GetStringUTF16(
321 IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE)); 322 IDS_AUTOFILL_CARD_UNMASK_INVALID_EXPIRATION_DATE));
322 } 323 }
323 324
324 GetDialogClientView()->UpdateDialogButtons(); 325 GetDialogClientView()->UpdateDialogButtons();
325 } 326 }
326 327
327 void CardUnmaskPromptViews::AnimationProgressed( 328 void CardUnmaskPromptViews::AnimationProgressed(
328 const gfx::Animation* animation) { 329 const gfx::Animation* animation) {
329 progress_overlay_->SetOpacity(animation->GetCurrentValue()); 330 uint8_t alpha = gfx::ToRoundedInt(255 * animation->GetCurrentValue());
Peter Kasting 2015/04/07 22:29:42 Use CurrentValueBetween instead and make the cast
danakj 2015/04/07 22:36:43 Done.
330 storage_row_->SetOpacity(1.0 - animation->GetCurrentValue()); 331 progress_overlay_->SetOpacity(alpha);
332 storage_row_->SetOpacity(255 - alpha);
331 } 333 }
332 334
333 void CardUnmaskPromptViews::InitIfNecessary() { 335 void CardUnmaskPromptViews::InitIfNecessary() {
334 if (has_children()) 336 if (has_children())
335 return; 337 return;
336 338
337 main_contents_ = new views::View(); 339 main_contents_ = new views::View();
338 main_contents_->SetLayoutManager( 340 main_contents_->SetLayoutManager(
339 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 12)); 341 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 12));
340 AddChildView(main_contents_); 342 AddChildView(main_contents_);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 return controller_->InputExpirationIsValid( 451 return controller_->InputExpirationIsValid(
450 month_input_->GetTextForRow(month_input_->selected_index()), 452 month_input_->GetTextForRow(month_input_->selected_index()),
451 year_input_->GetTextForRow(year_input_->selected_index())); 453 year_input_->GetTextForRow(year_input_->selected_index()));
452 } 454 }
453 455
454 void CardUnmaskPromptViews::ClosePrompt() { 456 void CardUnmaskPromptViews::ClosePrompt() {
455 GetWidget()->Close(); 457 GetWidget()->Close();
456 } 458 }
457 459
458 CardUnmaskPromptViews::FadeOutView::FadeOutView() 460 CardUnmaskPromptViews::FadeOutView::FadeOutView()
459 : fade_everything_(false), opacity_(1.0) { 461 : fade_everything_(false), alpha_(255) {
460 } 462 }
461 CardUnmaskPromptViews::FadeOutView::~FadeOutView() { 463 CardUnmaskPromptViews::FadeOutView::~FadeOutView() {
462 } 464 }
463 465
464 void CardUnmaskPromptViews::FadeOutView::PaintChildren( 466 void CardUnmaskPromptViews::FadeOutView::PaintChildren(
465 const ui::PaintContext& context) { 467 const ui::PaintContext& context) {
466 uint8_t alpha = static_cast<uint8_t>(255 * opacity_); 468 ui::CompositingRecorder recorder(context, alpha_);
467 ui::CompositingRecorder recorder(context, alpha);
468 views::View::PaintChildren(context); 469 views::View::PaintChildren(context);
469 } 470 }
470 471
471 void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) { 472 void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) {
472 if (!fade_everything_ || opacity_ > 0.99) 473 if (!fade_everything_ || alpha_ == 255)
473 return views::View::OnPaint(canvas); 474 return views::View::OnPaint(canvas);
474 475
475 canvas->SaveLayerAlpha(0xff * opacity_); 476 canvas->SaveLayerAlpha(alpha_);
476 views::View::OnPaint(canvas); 477 views::View::OnPaint(canvas);
477 canvas->Restore(); 478 canvas->Restore();
478 } 479 }
479 480
480 void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) { 481 void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) {
481 opacity_ = opacity; 482 alpha_ = alpha;
482 SchedulePaint(); 483 SchedulePaint();
483 } 484 }
484 485
485 } // namespace autofill 486 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/card_unmask_prompt_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698