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