From 220705c2b06962462e471b28ad85c76c0f9c3080 Mon Sep 17 00:00:00 2001 From: "ben@chromium.org" Date: Tue, 5 May 2009 04:52:11 +0000 Subject: Move *Animation to app/ http://crbug.com/11387 Review URL: http://codereview.chromium.org/109001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15275 0039d316-1c4b-4281-b951-d872f2087c98 --- app/throb_animation.cc | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 app/throb_animation.cc (limited to 'app/throb_animation.cc') diff --git a/app/throb_animation.cc b/app/throb_animation.cc new file mode 100644 index 0000000..28b5763 --- /dev/null +++ b/app/throb_animation.cc @@ -0,0 +1,68 @@ +// Copyright (c) 2006-2008 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 "app/throb_animation.h" + +static const int kDefaultThrobDurationMS = 400; + +ThrobAnimation::ThrobAnimation(AnimationDelegate* target) + : SlideAnimation(target), + slide_duration_(GetSlideDuration()), + throb_duration_(kDefaultThrobDurationMS), + cycles_remaining_(0), + throbbing_(false) { +} + +void ThrobAnimation::StartThrobbing(int cycles_til_stop) { + cycles_remaining_ = cycles_til_stop; + throbbing_ = true; + SlideAnimation::SetSlideDuration(throb_duration_); + if (IsAnimating()) + return; // We're already running, we'll cycle when current loop finishes. + + if (IsShowing()) + SlideAnimation::Hide(); + else + SlideAnimation::Show(); + cycles_remaining_ = cycles_til_stop; +} + +void ThrobAnimation::Reset() { + ResetForSlide(); + SlideAnimation::Reset(); +} + +void ThrobAnimation::Show() { + ResetForSlide(); + SlideAnimation::Show(); +} + +void ThrobAnimation::Hide() { + ResetForSlide(); + SlideAnimation::Hide(); +} + +void ThrobAnimation::Step() { + Animation::Step(); + if (!IsAnimating() && throbbing_) { + // Were throbbing a finished a cycle. Start the next cycle unless we're at + // the end of the cycles, in which case we stop. + cycles_remaining_--; + if (IsShowing()) { + // We want to stop hidden, hence this doesn't check cycles_remaining_. + SlideAnimation::Hide(); + } else if (cycles_remaining_ > 0) { + SlideAnimation::Show(); + } else { + // We're done throbbing. + throbbing_ = false; + } + } +} + +void ThrobAnimation::ResetForSlide() { + SlideAnimation::SetSlideDuration(slide_duration_); + cycles_remaining_ = 0; + throbbing_ = false; +} -- cgit v1.1