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. 4 5 #include "ash/shelf/background_animator.h" 6 7 8 namespace ash { 9 namespace internal { 10 11 namespace { 12 13 // Duration of the background animation. 14 const int kBackgroundDurationMS = 1000; 15 16 } 17 18 BackgroundAnimator::BackgroundAnimator(BackgroundAnimatorDelegate* delegate, 19 int min_alpha, 20 int max_alpha) 21 : delegate_(delegate), 22 min_alpha_(min_alpha), 23 max_alpha_(max_alpha), 24 animation_(this), 25 paints_background_(false), 26 alpha_(min_alpha) { 27 animation_.SetSlideDuration(kBackgroundDurationMS); 28 } 29 30 BackgroundAnimator::~BackgroundAnimator() { 31 } 32 33 void BackgroundAnimator::SetDuration(int time_in_ms) { 34 animation_.SetSlideDuration(time_in_ms); 35 } 36 37 void BackgroundAnimator::SetPaintsBackground( 38 bool value, BackgroundAnimatorChangeType type) { 39 if (paints_background_ == value) 40 return; 41 paints_background_ = value; 42 if (type == BACKGROUND_CHANGE_IMMEDIATE && !animation_.is_animating()) { 43 animation_.Reset(value ? 1.0f : 0.0f); 44 AnimationProgressed(&animation_); 45 return; 46 } 47 if (paints_background_) 48 animation_.Show(); 49 else 50 animation_.Hide(); 51 } 52 53 void BackgroundAnimator::AnimationProgressed(const gfx::Animation* animation) { 54 int alpha = animation->CurrentValueBetween(min_alpha_, max_alpha_); 55 if (alpha_ == alpha) 56 return; 57 alpha_ = alpha; 58 delegate_->UpdateBackground(alpha_); 59 } 60 61 } // namespace internal 62 } // namespace ash 63