Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / ui / gfx / animation / throb_animation.cc
blob0a88aa7d9c43cf374a3a6b8e00f5501b9e8f6b23
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 "ui/gfx/animation/throb_animation.h"
7 #include <limits>
9 namespace gfx {
11 static const int kDefaultThrobDurationMS = 400;
13 ThrobAnimation::ThrobAnimation(AnimationDelegate* target)
14 : SlideAnimation(target),
15 slide_duration_(GetSlideDuration()),
16 throb_duration_(kDefaultThrobDurationMS),
17 cycles_remaining_(0),
18 throbbing_(false) {
21 void ThrobAnimation::StartThrobbing(int cycles_til_stop) {
22 cycles_til_stop = cycles_til_stop >= 0 ? cycles_til_stop :
23 std::numeric_limits<int>::max();
24 cycles_remaining_ = cycles_til_stop;
25 throbbing_ = true;
26 SlideAnimation::SetSlideDuration(throb_duration_);
27 if (is_animating())
28 return; // We're already running, we'll cycle when current loop finishes.
30 if (IsShowing())
31 SlideAnimation::Hide();
32 else
33 SlideAnimation::Show();
34 cycles_remaining_ = cycles_til_stop;
37 void ThrobAnimation::Reset() {
38 Reset(0);
41 void ThrobAnimation::Reset(double value) {
42 ResetForSlide();
43 SlideAnimation::Reset(value);
46 void ThrobAnimation::Show() {
47 ResetForSlide();
48 SlideAnimation::Show();
51 void ThrobAnimation::Hide() {
52 ResetForSlide();
53 SlideAnimation::Hide();
56 void ThrobAnimation::SetSlideDuration(int duration) {
57 slide_duration_ = duration;
60 void ThrobAnimation::Step(base::TimeTicks time_now) {
61 LinearAnimation::Step(time_now);
63 if (!is_animating() && throbbing_) {
64 // Were throbbing a finished a cycle. Start the next cycle unless we're at
65 // the end of the cycles, in which case we stop.
66 cycles_remaining_--;
67 if (IsShowing()) {
68 // We want to stop hidden, hence this doesn't check cycles_remaining_.
69 SlideAnimation::Hide();
70 } else if (cycles_remaining_ > 0) {
71 SlideAnimation::Show();
72 } else {
73 // We're done throbbing.
74 throbbing_ = false;
79 void ThrobAnimation::ResetForSlide() {
80 SlideAnimation::SetSlideDuration(slide_duration_);
81 cycles_remaining_ = 0;
82 throbbing_ = false;
85 } // namespace gfx