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 { 10 11 // Duration of the background animation. 12 const int kBackgroundDurationMS = 1000; 13 14 } 15 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); 26 } 27 28 BackgroundAnimator::~BackgroundAnimator() { 29 } 30 31 void BackgroundAnimator::SetDuration(int time_in_ms) { 32 animation_.SetSlideDuration(time_in_ms); 33 } 34 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; 44 } 45 if (paints_background_) 46 animation_.Show(); 47 else 48 animation_.Hide(); 49 } 50 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_); 57 } 58 59 } // namespace ash 60