| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 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 "app/throb_animation.h" | |
| 6 | |
| 7 #include <limits> | |
| 8 | |
| 9 static const int kDefaultThrobDurationMS = 400; | |
| 10 | |
| 11 ThrobAnimation::ThrobAnimation(AnimationDelegate* target) | |
| 12 : SlideAnimation(target), | |
| 13 slide_duration_(GetSlideDuration()), | |
| 14 throb_duration_(kDefaultThrobDurationMS), | |
| 15 cycles_remaining_(0), | |
| 16 throbbing_(false) { | |
| 17 } | |
| 18 | |
| 19 void ThrobAnimation::StartThrobbing(int cycles_til_stop) { | |
| 20 cycles_til_stop = cycles_til_stop >= 0 ? cycles_til_stop : | |
| 21 std::numeric_limits<int>::max(); | |
| 22 cycles_remaining_ = cycles_til_stop; | |
| 23 throbbing_ = true; | |
| 24 SlideAnimation::SetSlideDuration(throb_duration_); | |
| 25 if (is_animating()) | |
| 26 return; // We're already running, we'll cycle when current loop finishes. | |
| 27 | |
| 28 if (IsShowing()) | |
| 29 SlideAnimation::Hide(); | |
| 30 else | |
| 31 SlideAnimation::Show(); | |
| 32 cycles_remaining_ = cycles_til_stop; | |
| 33 } | |
| 34 | |
| 35 void ThrobAnimation::Reset() { | |
| 36 ResetForSlide(); | |
| 37 SlideAnimation::Reset(); | |
| 38 } | |
| 39 | |
| 40 void ThrobAnimation::Show() { | |
| 41 ResetForSlide(); | |
| 42 SlideAnimation::Show(); | |
| 43 } | |
| 44 | |
| 45 void ThrobAnimation::Hide() { | |
| 46 ResetForSlide(); | |
| 47 SlideAnimation::Hide(); | |
| 48 } | |
| 49 | |
| 50 void ThrobAnimation::SetSlideDuration(int duration) { | |
| 51 slide_duration_ = duration; | |
| 52 } | |
| 53 | |
| 54 void ThrobAnimation::Step(base::TimeTicks time_now) { | |
| 55 LinearAnimation::Step(time_now); | |
| 56 | |
| 57 if (!is_animating() && throbbing_) { | |
| 58 // Were throbbing a finished a cycle. Start the next cycle unless we're at | |
| 59 // the end of the cycles, in which case we stop. | |
| 60 cycles_remaining_--; | |
| 61 if (IsShowing()) { | |
| 62 // We want to stop hidden, hence this doesn't check cycles_remaining_. | |
| 63 SlideAnimation::Hide(); | |
| 64 } else if (cycles_remaining_ > 0) { | |
| 65 SlideAnimation::Show(); | |
| 66 } else { | |
| 67 // We're done throbbing. | |
| 68 throbbing_ = false; | |
| 69 } | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 void ThrobAnimation::ResetForSlide() { | |
| 74 SlideAnimation::SetSlideDuration(slide_duration_); | |
| 75 cycles_remaining_ = 0; | |
| 76 throbbing_ = false; | |
| 77 } | |
| OLD | NEW |