Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / ash / shelf / background_animator.cc
blob288791a6d72190fdfdd6ad8ea576712a6005da95
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/shelf/background_animator.h"
8 namespace ash {
9 namespace {
11 // Duration of the background animation.
12 const int kBackgroundDurationMS = 1000;
16 BackgroundAnimator::BackgroundAnimator(BackgroundAnimatorDelegate* delegate,
17 int min_alpha,
18 int max_alpha)
19 : delegate_(delegate),
20 min_alpha_(min_alpha),
21 max_alpha_(max_alpha),
22 animation_(this),
23 paints_background_(false),
24 alpha_(min_alpha) {
25 animation_.SetSlideDuration(kBackgroundDurationMS);
28 BackgroundAnimator::~BackgroundAnimator() {
31 void BackgroundAnimator::SetDuration(int time_in_ms) {
32 animation_.SetSlideDuration(time_in_ms);
35 void BackgroundAnimator::SetPaintsBackground(
36 bool value, BackgroundAnimatorChangeType type) {
37 if (paints_background_ == value)
38 return;
39 paints_background_ = value;
40 if (type == BACKGROUND_CHANGE_IMMEDIATE && !animation_.is_animating()) {
41 animation_.Reset(value ? 1.0f : 0.0f);
42 AnimationProgressed(&animation_);
43 return;
45 if (paints_background_)
46 animation_.Show();
47 else
48 animation_.Hide();
51 void BackgroundAnimator::AnimationProgressed(const gfx::Animation* animation) {
52 int alpha = animation->CurrentValueBetween(min_alpha_, max_alpha_);
53 if (alpha_ == alpha)
54 return;
55 alpha_ = alpha;
56 delegate_->UpdateBackground(alpha_);
59 } // namespace ash