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/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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 progress_overlay_->SetOpacity(animation->GetCurrentValue()); |
danakj
2015/04/07 21:47:04
The animation value is in the range 0-1. So we'd h
| |
330 storage_row_->SetOpacity(1.0 - animation->GetCurrentValue()); | 331 storage_row_->SetOpacity(1.0 - animation->GetCurrentValue()); |
331 } | 332 } |
332 | 333 |
333 void CardUnmaskPromptViews::InitIfNecessary() { | 334 void CardUnmaskPromptViews::InitIfNecessary() { |
334 if (has_children()) | 335 if (has_children()) |
335 return; | 336 return; |
336 | 337 |
337 main_contents_ = new views::View(); | 338 main_contents_ = new views::View(); |
338 main_contents_->SetLayoutManager( | 339 main_contents_->SetLayoutManager( |
339 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 12)); | 340 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 12)); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 return controller_->InputExpirationIsValid( | 450 return controller_->InputExpirationIsValid( |
450 month_input_->GetTextForRow(month_input_->selected_index()), | 451 month_input_->GetTextForRow(month_input_->selected_index()), |
451 year_input_->GetTextForRow(year_input_->selected_index())); | 452 year_input_->GetTextForRow(year_input_->selected_index())); |
452 } | 453 } |
453 | 454 |
454 void CardUnmaskPromptViews::ClosePrompt() { | 455 void CardUnmaskPromptViews::ClosePrompt() { |
455 GetWidget()->Close(); | 456 GetWidget()->Close(); |
456 } | 457 } |
457 | 458 |
458 CardUnmaskPromptViews::FadeOutView::FadeOutView() | 459 CardUnmaskPromptViews::FadeOutView::FadeOutView() |
459 : fade_everything_(false), opacity_(1.0) { | 460 : fade_everything_(false), alpha_(255) { |
460 } | 461 } |
461 CardUnmaskPromptViews::FadeOutView::~FadeOutView() { | 462 CardUnmaskPromptViews::FadeOutView::~FadeOutView() { |
462 } | 463 } |
463 | 464 |
464 void CardUnmaskPromptViews::FadeOutView::PaintChildren( | 465 void CardUnmaskPromptViews::FadeOutView::PaintChildren( |
465 const ui::PaintContext& context) { | 466 const ui::PaintContext& context) { |
466 int alpha = static_cast<int>(255 * opacity_); | 467 ui::CompositingRecorder recorder(context, alpha_); |
467 ui::CompositingRecorder recorder(context, alpha); | |
468 views::View::PaintChildren(context); | 468 views::View::PaintChildren(context); |
469 } | 469 } |
470 | 470 |
471 void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) { | 471 void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) { |
472 if (!fade_everything_ || opacity_ > 0.99) | 472 if (!fade_everything_ || alpha_ == 255) |
473 return views::View::OnPaint(canvas); | 473 return views::View::OnPaint(canvas); |
474 | 474 |
475 canvas->SaveLayerAlpha(0xff * opacity_); | 475 canvas->SaveLayerAlpha(alpha_); |
476 views::View::OnPaint(canvas); | 476 views::View::OnPaint(canvas); |
477 canvas->Restore(); | 477 canvas->Restore(); |
478 } | 478 } |
479 | 479 |
480 void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) { | 480 void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) { |
481 opacity_ = opacity; | 481 DCHECK_GE(opacity, 0.0); |
482 DCHECK_LE(opacity, 1.0); | |
483 alpha_ = gfx::ToRoundedInt(opacity * 255); | |
Peter Kasting
2015/04/07 21:45:30
My intent was to make this function also take an i
| |
482 SchedulePaint(); | 484 SchedulePaint(); |
483 } | 485 } |
484 | 486 |
485 } // namespace autofill | 487 } // namespace autofill |
OLD | NEW |