Commit 06cf7258 authored by danakj's avatar danakj Committed by Commit bot

views: Change CardUnmaskPromptViews::FadeOutView opacity to alpha.

Store an 0-255 alpha value instead of a 0-1 opacity value on the class
since that is what we will use for painting.

R=pkasting

Review URL: https://codereview.chromium.org/1064213002

Cr-Commit-Position: refs/heads/master@{#324220}
parent fc944619
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "ui/compositor/compositing_recorder.h" #include "ui/compositor/compositing_recorder.h"
#include "ui/compositor/paint_context.h" #include "ui/compositor/paint_context.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/controls/button/checkbox.h" #include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/combobox/combobox.h" #include "ui/views/controls/combobox/combobox.h"
...@@ -85,7 +86,7 @@ void CardUnmaskPromptViews::ControllerGone() { ...@@ -85,7 +86,7 @@ void CardUnmaskPromptViews::ControllerGone() {
void CardUnmaskPromptViews::DisableAndWaitForVerification() { void CardUnmaskPromptViews::DisableAndWaitForVerification() {
SetInputsEnabled(false); SetInputsEnabled(false);
progress_overlay_->SetOpacity(0.0); progress_overlay_->SetAlpha(0);
progress_overlay_->SetVisible(true); progress_overlay_->SetVisible(true);
progress_throbber_->Start(); progress_throbber_->Start();
overlay_animation_.Show(); overlay_animation_.Show();
...@@ -109,7 +110,7 @@ void CardUnmaskPromptViews::GotVerificationResult( ...@@ -109,7 +110,7 @@ void CardUnmaskPromptViews::GotVerificationResult(
// TODO(estade): it's somewhat jarring when the error comes back too // TODO(estade): it's somewhat jarring when the error comes back too
// quickly. // quickly.
overlay_animation_.Reset(); overlay_animation_.Reset();
storage_row_->SetOpacity(1.0); storage_row_->SetAlpha(255);
progress_overlay_->SetVisible(false); progress_overlay_->SetVisible(false);
if (allow_retry) { if (allow_retry) {
...@@ -326,8 +327,9 @@ void CardUnmaskPromptViews::OnPerformAction(views::Combobox* combobox) { ...@@ -326,8 +327,9 @@ void CardUnmaskPromptViews::OnPerformAction(views::Combobox* combobox) {
void CardUnmaskPromptViews::AnimationProgressed( void CardUnmaskPromptViews::AnimationProgressed(
const gfx::Animation* animation) { const gfx::Animation* animation) {
progress_overlay_->SetOpacity(animation->GetCurrentValue()); uint8_t alpha = static_cast<uint8_t>(animation->CurrentValueBetween(0, 255));
storage_row_->SetOpacity(1.0 - animation->GetCurrentValue()); progress_overlay_->SetAlpha(alpha);
storage_row_->SetAlpha(255 - alpha);
} }
void CardUnmaskPromptViews::InitIfNecessary() { void CardUnmaskPromptViews::InitIfNecessary() {
...@@ -456,29 +458,28 @@ void CardUnmaskPromptViews::ClosePrompt() { ...@@ -456,29 +458,28 @@ void CardUnmaskPromptViews::ClosePrompt() {
} }
CardUnmaskPromptViews::FadeOutView::FadeOutView() CardUnmaskPromptViews::FadeOutView::FadeOutView()
: fade_everything_(false), opacity_(1.0) { : fade_everything_(false), alpha_(255) {
} }
CardUnmaskPromptViews::FadeOutView::~FadeOutView() { CardUnmaskPromptViews::FadeOutView::~FadeOutView() {
} }
void CardUnmaskPromptViews::FadeOutView::PaintChildren( void CardUnmaskPromptViews::FadeOutView::PaintChildren(
const ui::PaintContext& context) { const ui::PaintContext& context) {
uint8_t alpha = static_cast<uint8_t>(255 * opacity_); ui::CompositingRecorder recorder(context, alpha_);
ui::CompositingRecorder recorder(context, alpha);
views::View::PaintChildren(context); views::View::PaintChildren(context);
} }
void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) { void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) {
if (!fade_everything_ || opacity_ > 0.99) if (!fade_everything_ || alpha_ == 255)
return views::View::OnPaint(canvas); return views::View::OnPaint(canvas);
canvas->SaveLayerAlpha(0xff * opacity_); canvas->SaveLayerAlpha(alpha_);
views::View::OnPaint(canvas); views::View::OnPaint(canvas);
canvas->Restore(); canvas->Restore();
} }
void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) { void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) {
opacity_ = opacity; alpha_ = alpha;
SchedulePaint(); SchedulePaint();
} }
......
...@@ -87,16 +87,17 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView, ...@@ -87,16 +87,17 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
void set_fade_everything(bool fade_everything) { void set_fade_everything(bool fade_everything) {
fade_everything_ = fade_everything; fade_everything_ = fade_everything;
} }
void SetOpacity(double opacity);
// Set the alpha channel for this view. 0 is transparent and 255 is opaque.
void SetAlpha(uint8_t alpha);
private: private:
// Controls whether the background and border are faded out as well. Default // Controls whether the background and border are faded out as well. Default
// is false, meaning only children are faded. // is false, meaning only children are faded.
bool fade_everything_; bool fade_everything_;
// On a scale of 0-1, how much to fade out the contents of this view. 0 is // The alpha channel for this view. 0 is transparent and 255 is opaque.
// totally invisible, 1 is totally visible. uint8_t alpha_;
double opacity_;
DISALLOW_COPY_AND_ASSIGN(FadeOutView); DISALLOW_COPY_AND_ASSIGN(FadeOutView);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment