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 @@
#include "ui/compositor/compositing_recorder.h"
#include "ui/compositor/paint_context.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/safe_integer_conversions.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/combobox/combobox.h"
......@@ -85,7 +86,7 @@ void CardUnmaskPromptViews::ControllerGone() {
void CardUnmaskPromptViews::DisableAndWaitForVerification() {
SetInputsEnabled(false);
progress_overlay_->SetOpacity(0.0);
progress_overlay_->SetAlpha(0);
progress_overlay_->SetVisible(true);
progress_throbber_->Start();
overlay_animation_.Show();
......@@ -109,7 +110,7 @@ void CardUnmaskPromptViews::GotVerificationResult(
// TODO(estade): it's somewhat jarring when the error comes back too
// quickly.
overlay_animation_.Reset();
storage_row_->SetOpacity(1.0);
storage_row_->SetAlpha(255);
progress_overlay_->SetVisible(false);
if (allow_retry) {
......@@ -326,8 +327,9 @@ void CardUnmaskPromptViews::OnPerformAction(views::Combobox* combobox) {
void CardUnmaskPromptViews::AnimationProgressed(
const gfx::Animation* animation) {
progress_overlay_->SetOpacity(animation->GetCurrentValue());
storage_row_->SetOpacity(1.0 - animation->GetCurrentValue());
uint8_t alpha = static_cast<uint8_t>(animation->CurrentValueBetween(0, 255));
progress_overlay_->SetAlpha(alpha);
storage_row_->SetAlpha(255 - alpha);
}
void CardUnmaskPromptViews::InitIfNecessary() {
......@@ -456,29 +458,28 @@ void CardUnmaskPromptViews::ClosePrompt() {
}
CardUnmaskPromptViews::FadeOutView::FadeOutView()
: fade_everything_(false), opacity_(1.0) {
: fade_everything_(false), alpha_(255) {
}
CardUnmaskPromptViews::FadeOutView::~FadeOutView() {
}
void CardUnmaskPromptViews::FadeOutView::PaintChildren(
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);
}
void CardUnmaskPromptViews::FadeOutView::OnPaint(gfx::Canvas* canvas) {
if (!fade_everything_ || opacity_ > 0.99)
if (!fade_everything_ || alpha_ == 255)
return views::View::OnPaint(canvas);
canvas->SaveLayerAlpha(0xff * opacity_);
canvas->SaveLayerAlpha(alpha_);
views::View::OnPaint(canvas);
canvas->Restore();
}
void CardUnmaskPromptViews::FadeOutView::SetOpacity(double opacity) {
opacity_ = opacity;
void CardUnmaskPromptViews::FadeOutView::SetAlpha(uint8_t alpha) {
alpha_ = alpha;
SchedulePaint();
}
......
......@@ -87,16 +87,17 @@ class CardUnmaskPromptViews : public CardUnmaskPromptView,
void set_fade_everything(bool 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:
// Controls whether the background and border are faded out as well. Default
// is false, meaning only children are faded.
bool fade_everything_;
// On a scale of 0-1, how much to fade out the contents of this view. 0 is
// totally invisible, 1 is totally visible.
double opacity_;
// The alpha channel for this view. 0 is transparent and 255 is opaque.
uint8_t alpha_;
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