| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/shelf/background_animator.h" | 5 #include "ash/wm/common/background_animator.h" |
| 6 | 6 |
| 7 namespace ash { | 7 namespace ash { |
| 8 namespace { | 8 namespace { |
| 9 | 9 |
| 10 // Duration of the background animation. | 10 // Duration of the background animation. |
| 11 const int kBackgroundDurationMS = 1000; | 11 const int kBackgroundDurationMS = 1000; |
| 12 | |
| 13 } | 12 } |
| 14 | 13 |
| 15 BackgroundAnimator::BackgroundAnimator(BackgroundAnimatorDelegate* delegate, | 14 BackgroundAnimator::BackgroundAnimator(BackgroundAnimatorDelegate* delegate, |
| 16 int min_alpha, | 15 int min_alpha, |
| 17 int max_alpha) | 16 int max_alpha) |
| 18 : delegate_(delegate), | 17 : delegate_(delegate), |
| 19 min_alpha_(min_alpha), | 18 min_alpha_(min_alpha), |
| 20 max_alpha_(max_alpha), | 19 max_alpha_(max_alpha), |
| 21 animation_(this), | 20 animation_(this), |
| 22 paints_background_(false), | 21 paints_background_(false), |
| 23 alpha_(min_alpha) { | 22 alpha_(min_alpha) { |
| 24 animation_.SetSlideDuration(kBackgroundDurationMS); | 23 animation_.SetSlideDuration(kBackgroundDurationMS); |
| 25 } | 24 } |
| 26 | 25 |
| 27 BackgroundAnimator::~BackgroundAnimator() { | 26 BackgroundAnimator::~BackgroundAnimator() {} |
| 28 } | |
| 29 | 27 |
| 30 void BackgroundAnimator::SetDuration(int time_in_ms) { | 28 void BackgroundAnimator::SetDuration(int time_in_ms) { |
| 31 animation_.SetSlideDuration(time_in_ms); | 29 animation_.SetSlideDuration(time_in_ms); |
| 32 } | 30 } |
| 33 | 31 |
| 34 void BackgroundAnimator::SetPaintsBackground( | 32 void BackgroundAnimator::SetPaintsBackground( |
| 35 bool value, BackgroundAnimatorChangeType type) { | 33 bool value, |
| 34 BackgroundAnimatorChangeType type) { |
| 36 if (paints_background_ == value) | 35 if (paints_background_ == value) |
| 37 return; | 36 return; |
| 38 paints_background_ = value; | 37 paints_background_ = value; |
| 39 if (type == BACKGROUND_CHANGE_IMMEDIATE && !animation_.is_animating()) { | 38 if (type == BACKGROUND_CHANGE_IMMEDIATE && !animation_.is_animating()) { |
| 40 animation_.Reset(value ? 1.0f : 0.0f); | 39 animation_.Reset(value ? 1.0f : 0.0f); |
| 41 AnimationProgressed(&animation_); | 40 AnimationProgressed(&animation_); |
| 42 return; | 41 return; |
| 43 } | 42 } |
| 44 if (paints_background_) | 43 if (paints_background_) |
| 45 animation_.Show(); | 44 animation_.Show(); |
| 46 else | 45 else |
| 47 animation_.Hide(); | 46 animation_.Hide(); |
| 48 } | 47 } |
| 49 | 48 |
| 50 void BackgroundAnimator::AnimationProgressed(const gfx::Animation* animation) { | 49 void BackgroundAnimator::AnimationProgressed(const gfx::Animation* animation) { |
| 51 int alpha = animation->CurrentValueBetween(min_alpha_, max_alpha_); | 50 int alpha = animation->CurrentValueBetween(min_alpha_, max_alpha_); |
| 52 if (alpha_ == alpha) | 51 if (alpha_ == alpha) |
| 53 return; | 52 return; |
| 54 alpha_ = alpha; | 53 alpha_ = alpha; |
| 55 delegate_->UpdateBackground(alpha_); | 54 delegate_->UpdateBackground(alpha_); |
| 56 } | 55 } |
| 57 | 56 |
| 58 } // namespace ash | 57 } // namespace ash |
| OLD | NEW |