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"
11 static const int kDefaultThrobDurationMS
= 400;
13 ThrobAnimation::ThrobAnimation(AnimationDelegate
* target
)
14 : SlideAnimation(target
),
15 slide_duration_(GetSlideDuration()),
16 throb_duration_(kDefaultThrobDurationMS
),
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
;
26 SlideAnimation::SetSlideDuration(throb_duration_
);
28 return; // We're already running, we'll cycle when current loop finishes.
31 SlideAnimation::Hide();
33 SlideAnimation::Show();
34 cycles_remaining_
= cycles_til_stop
;
37 void ThrobAnimation::Reset() {
41 void ThrobAnimation::Reset(double value
) {
43 SlideAnimation::Reset(value
);
46 void ThrobAnimation::Show() {
48 SlideAnimation::Show();
51 void ThrobAnimation::Hide() {
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.
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();
73 // We're done throbbing.
79 void ThrobAnimation::ResetForSlide() {
80 SlideAnimation::SetSlideDuration(slide_duration_
);
81 cycles_remaining_
= 0;