diff options
Diffstat (limited to 'ash/shelf/background_animator.cc')
-rw-r--r-- | ash/shelf/background_animator.cc | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ash/shelf/background_animator.cc b/ash/shelf/background_animator.cc new file mode 100644 index 0000000..7b968c8 --- /dev/null +++ b/ash/shelf/background_animator.cc @@ -0,0 +1,57 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/shelf/background_animator.h" + + +namespace ash { +namespace internal { + +namespace { + +// Duration of the background animation. +const int kBackgroundDurationMS = 1000; + +} + +BackgroundAnimator::BackgroundAnimator(BackgroundAnimatorDelegate* delegate, + int min_alpha, + int max_alpha) + : delegate_(delegate), + min_alpha_(min_alpha), + max_alpha_(max_alpha), + ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)), + paints_background_(false), + alpha_(min_alpha) { + animation_.SetSlideDuration(kBackgroundDurationMS); +} + +BackgroundAnimator::~BackgroundAnimator() { +} + +void BackgroundAnimator::SetPaintsBackground(bool value, ChangeType type) { + if (paints_background_ == value) + return; + paints_background_ = value; + if (type == CHANGE_IMMEDIATE && !animation_.is_animating()) { + animation_.Reset(value ? 1.0f : 0.0f); + AnimationProgressed(&animation_); + return; + } + if (paints_background_) + animation_.Show(); + else + animation_.Hide(); +} + +void BackgroundAnimator::AnimationProgressed(const ui::Animation* animation) { + int alpha = animation->CurrentValueBetween(min_alpha_, max_alpha_); + if (alpha_ == alpha) + return; + alpha_ = alpha; + delegate_->UpdateBackground(alpha_); +} + +} // namespace internal +} // namespace ash |