diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 03:43:55 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 03:43:55 +0000 |
commit | 4ce7e15da651c6221720e33dc8c500830d4b6b8a (patch) | |
tree | 376ef1d7e7951dae3376e65f4edee9e7367adc89 | |
parent | 5ee3ca64cdf2d00f82a1bc36f36e8ab5e520b4de (diff) | |
download | chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.zip chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.gz chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.bz2 |
Refactors animation to allow for cleaner subclassing. I'm doing this
for creating a different animation subclass (which you'll see
shortly).
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1961001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46433 0039d316-1c4b-4281-b951-d872f2087c98
50 files changed, 622 insertions, 405 deletions
diff --git a/app/animation.cc b/app/animation.cc index 5e9d10c..2dc2bcf6 100644 --- a/app/animation.cc +++ b/app/animation.cc @@ -4,120 +4,87 @@ #include "app/animation.h" -#include "app/animation_container.h" +#include "app/tween.h" #include "gfx/rect.h" #if defined(OS_WIN) #include "base/win_util.h" #endif -using base::Time; -using base::TimeDelta; - -Animation::Animation(int frame_rate, - AnimationDelegate* delegate) - : animating_(false), - frame_rate_(frame_rate), - timer_interval_(CalculateInterval(frame_rate)), - state_(0.0), - delegate_(delegate) { -} - -Animation::Animation(int duration, - int frame_rate, - AnimationDelegate* delegate) - : animating_(false), - frame_rate_(frame_rate), - timer_interval_(CalculateInterval(frame_rate)), - duration_(TimeDelta::FromMilliseconds(duration)), - state_(0.0), - delegate_(delegate) { - - SetDuration(duration); +Animation::Animation(base::TimeDelta timer_interval) + : timer_interval_(timer_interval), + is_animating_(false), + delegate_(NULL) { } Animation::~Animation() { - if (animating_) + // Don't send out notification from the destructor. Chances are the delegate + // owns us and is being deleted as well. + if (is_animating_) container_->Stop(this); } -double Animation::GetCurrentValue() const { - // Default is linear relationship, subclass to adapt. - return state_; -} +void Animation::Start() { + if (is_animating_) + return; -double Animation::CurrentValueBetween(double start, double target) const { - return start + (target - start) * GetCurrentValue(); -} + if (!container_.get()) + container_ = new AnimationContainer(); -int Animation::CurrentValueBetween(int start, int target) const { - return static_cast<int>(CurrentValueBetween(static_cast<double>(start), - static_cast<double>(target))); -} + is_animating_ = true; -gfx::Rect Animation::CurrentValueBetween(const gfx::Rect& start_bounds, - const gfx::Rect& target_bounds) const { - return gfx::Rect(CurrentValueBetween(start_bounds.x(), target_bounds.x()), - CurrentValueBetween(start_bounds.y(), target_bounds.y()), - CurrentValueBetween(start_bounds.width(), - target_bounds.width()), - CurrentValueBetween(start_bounds.height(), - target_bounds.height())); + container_->Start(this); + + AnimationStarted(); } -void Animation::Start() { - if (!animating_) { - if (!container_.get()) - container_ = new AnimationContainer(); +void Animation::Stop() { + if (!is_animating_) + return; - animating_ = true; + is_animating_ = false; - container_->Start(this); + // Notify the container first as the delegate may delete us. + container_->Stop(this); - if (delegate_) - delegate_->AnimationStarted(this); + AnimationStopped(); + + if (delegate_) { + if (ShouldSendCanceledFromStop()) + delegate_->AnimationCanceled(this); + else + delegate_->AnimationEnded(this); } } -void Animation::Stop() { - if (animating_) { - animating_ = false; +double Animation::CurrentValueBetween(double start, double target) const { + return Tween::ValueBetween(GetCurrentValue(), start, target); +} - // Notify the container first as the delegate may delete us. - container_->Stop(this); +int Animation::CurrentValueBetween(int start, int target) const { + return Tween::ValueBetween(GetCurrentValue(), start, target); - if (delegate_) { - if (state_ >= 1.0) - delegate_->AnimationEnded(this); - else - delegate_->AnimationCanceled(this); - } - } } -void Animation::End() { - if (animating_) { - animating_ = false; +gfx::Rect Animation::CurrentValueBetween(const gfx::Rect& start_bounds, + const gfx::Rect& target_bounds) const { + return Tween::ValueBetween(GetCurrentValue(), start_bounds, target_bounds); +} - // Notify the container first as the delegate may delete us. - container_->Stop(this); +void Animation::SetContainer(AnimationContainer* container) { + if (container == container_.get()) + return; - AnimateToState(1.0); - if (delegate_) - delegate_->AnimationEnded(this); - } -} + if (is_animating_) + container_->Stop(this); -bool Animation::IsAnimating() const { - return animating_; -} + if (container) + container_ = container; + else + container_ = new AnimationContainer(); -void Animation::SetDuration(int duration) { - duration_ = TimeDelta::FromMilliseconds(duration); - if (duration_ < timer_interval_) - duration_ = timer_interval_; - if (animating_) - start_time_ = container_->last_tick_time(); + if (is_animating_) + container_->Start(this); } // static @@ -139,41 +106,6 @@ bool Animation::ShouldRenderRichAnimation() { return true; } -void Animation::SetContainer(AnimationContainer* container) { - if (container == container_.get()) - return; - - if (animating_) - container_->Stop(this); - - if (container) - container_ = container; - else - container_ = new AnimationContainer(); - - if (animating_) - container_->Start(this); -} - -void Animation::Step(base::TimeTicks time_now) { - TimeDelta elapsed_time = time_now - start_time_; - state_ = static_cast<double>(elapsed_time.InMicroseconds()) / - static_cast<double>(duration_.InMicroseconds()); - if (state_ >= 1.0) - state_ = 1.0; - - AnimateToState(state_); - - if (delegate_) - delegate_->AnimationProgressed(this); - - if (state_ == 1.0) - Stop(); -} - -TimeDelta Animation::CalculateInterval(int frame_rate) { - int timer_interval = 1000000 / frame_rate; - if (timer_interval < 10000) - timer_interval = 10000; - return TimeDelta::FromMicroseconds(timer_interval); +void Animation::SetStartTime(base::TimeTicks start_time) { + start_time_ = start_time; } diff --git a/app/animation.h b/app/animation.h index c483e1d..5c672c9 100644 --- a/app/animation.h +++ b/app/animation.h @@ -1,32 +1,26 @@ // Copyright (c) 2010 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. -// Inspired by NSAnimation #ifndef APP_ANIMATION_H_ #define APP_ANIMATION_H_ +#include "app/animation_container.h" #include "base/ref_counted.h" #include "base/time.h" -class Animation; -class AnimationContainer; - namespace gfx { class Rect; } +class Animation; + // AnimationDelegate // // Implement this interface when you want to receive notifications about the // state of an animation. -// class AnimationDelegate { public: - // Called when an animation has started. - virtual void AnimationStarted(const Animation* animation) { - } - // Called when an animation has completed. virtual void AnimationEnded(const Animation* animation) { } @@ -43,41 +37,26 @@ class AnimationDelegate { virtual ~AnimationDelegate() {} }; -// Animation -// -// This class provides a basic implementation of an object that uses a timer -// to increment its state over the specified time and frame-rate. To -// actually do something useful with this you need to subclass it and override -// AnimateToState and optionally GetCurrentValue to update your state. -// -// The Animation notifies a delegate when events of interest occur. -// -// The practice is to instantiate a subclass and call Init and any other -// initialization specific to the subclass, and then call |Start|. The -// animation uses the current thread's message loop. +// Base class used in implementing animations. You only need use this class if +// you're implementing a new animation type, otherwise you'll likely want one of +// LinearAnimation, SlideAnimation, ThrobAnimation or MultiAnimation. // -class Animation { +// To subclass override Step, which is invoked as the animation progresses and +// GetCurrentValue() to return the value appropriate to the animation. +class Animation : public AnimationContainer::Element { public: - // Initializes everything except the duration. - // - // Caller must make sure to call SetDuration() if they use this - // constructor; it is preferable to use the full one, but sometimes - // duration can change between calls to Start() and we need to - // expose this interface. - Animation(int frame_rate, AnimationDelegate* delegate); - - // Initializes all fields. - Animation(int duration, int frame_rate, AnimationDelegate* delegate); + explicit Animation(base::TimeDelta timer_interval); virtual ~Animation(); - // Called when the animation progresses. Subclasses override this to - // efficiently update their state. - virtual void AnimateToState(double state) = 0; + // Starts the animation. Does nothing if the animation is already running. + void Start(); + + // Stops the animation. Does nothing if the animation is not running. + void Stop(); // Gets the value for the current state, according to the animation - // curve in use. This class provides only for a linear relationship, - // however subclasses can override this to provide others. - virtual double GetCurrentValue() const; + // curve in use. + virtual double GetCurrentValue() const = 0; // Convenience for returning a value between |start| and |target| based on // the current value. This is (target - start) * GetCurrentValue() + start. @@ -86,27 +65,6 @@ class Animation { gfx::Rect CurrentValueBetween(const gfx::Rect& start_bounds, const gfx::Rect& target_bounds) const; - // Start the animation. - void Start(); - - // Stop the animation. - void Stop(); - - // Skip to the end of the current animation. - void End(); - - // Return whether this animation is animating. - bool IsAnimating() const; - - // Changes the length of the animation. This resets the current - // state of the animation to the beginning. - void SetDuration(int duration); - - // Returns true if rich animations should be rendered. - // Looks at session type (e.g. remote desktop) and accessibility settings - // to give guidance for heavy animations such as "start download" arrow. - static bool ShouldRenderRichAnimation(); - // Sets the delegate. void set_delegate(AnimationDelegate* delegate) { delegate_ = delegate; } @@ -114,39 +72,53 @@ class Animation { // creating a new AnimationContainer. void SetContainer(AnimationContainer* container); + bool is_animating() const { return is_animating_; } + base::TimeDelta timer_interval() const { return timer_interval_; } - protected: - // Invoked by the AnimationContainer when the animation is running to advance - // the animation. Use |time_now| rather than Time::Now to avoid multiple - // animations running at the same time diverging. - virtual void Step(base::TimeTicks time_now); + // Returns true if rich animations should be rendered. + // Looks at session type (e.g. remote desktop) and accessibility settings + // to give guidance for heavy animations such as "start download" arrow. + static bool ShouldRenderRichAnimation(); - // Calculates the timer interval from the constructor list. - base::TimeDelta CalculateInterval(int frame_rate); + protected: + // Invoked from Start to allow subclasses to prepare for the animation. + virtual void AnimationStarted() {} - private: - friend class AnimationContainer; + // Invoked from Stop after we're removed from the container but before the + // delegate has been invoked. + virtual void AnimationStopped() {} - // Invoked from AnimationContainer when started. - void set_start_time(base::TimeTicks start_time) { start_time_ = start_time; } + // Invoked from stop to determine if cancel should be invoked. If this returns + // true the delegate is notified the animation was canceled, otherwise the + // delegate is notified the animation stopped. + virtual bool ShouldSendCanceledFromStop() { return false; } - // Whether or not we are currently animating. - bool animating_; + AnimationContainer* container() { return container_.get(); } + base::TimeTicks start_time() const { return start_time_; } + AnimationDelegate* delegate() { return delegate_; } - int frame_rate_; - base::TimeDelta timer_interval_; - base::TimeDelta duration_; + // AnimationContainer::Element overrides + virtual void SetStartTime(base::TimeTicks start_time); + virtual void Step(base::TimeTicks time_now) = 0; + virtual base::TimeDelta GetTimerInterval() const { return timer_interval_; } - // Current state, on a scale from 0.0 to 1.0. - double state_; + private: + // Interval for the animation. + const base::TimeDelta timer_interval_; - base::TimeTicks start_time_; + // If true we're running. + bool is_animating_; + // Our delegate; may be null. AnimationDelegate* delegate_; + // Container we're in. If non-null we're animating. scoped_refptr<AnimationContainer> container_; + // Time we started at. + base::TimeTicks start_time_; + DISALLOW_COPY_AND_ASSIGN(Animation); }; diff --git a/app/animation_container.cc b/app/animation_container.cc index 221b453..2b41913 100644 --- a/app/animation_container.cc +++ b/app/animation_container.cc @@ -16,31 +16,31 @@ AnimationContainer::AnimationContainer() AnimationContainer::~AnimationContainer() { // The animations own us and stop themselves before being deleted. If - // animations_ is not empty, something is wrong. - DCHECK(animations_.empty()); + // elements_ is not empty, something is wrong. + DCHECK(elements_.empty()); } -void AnimationContainer::Start(Animation* animation) { - DCHECK(animations_.count(animation) == 0); // Start should only be invoked - // if the animation isn't running. +void AnimationContainer::Start(Element* element) { + DCHECK(elements_.count(element) == 0); // Start should only be invoked if the + // element isn't running. - if (animations_.empty()) { + if (elements_.empty()) { last_tick_time_ = TimeTicks::Now(); - SetMinTimerInterval(animation->timer_interval()); - } else if (animation->timer_interval() < min_timer_interval_) { - SetMinTimerInterval(animation->timer_interval()); + SetMinTimerInterval(element->GetTimerInterval()); + } else if (element->GetTimerInterval() < min_timer_interval_) { + SetMinTimerInterval(element->GetTimerInterval()); } - animation->set_start_time(last_tick_time_); - animations_.insert(animation); + element->SetStartTime(last_tick_time_); + elements_.insert(element); } -void AnimationContainer::Stop(Animation* animation) { - DCHECK(animations_.count(animation) > 0); // The animation must be running. +void AnimationContainer::Stop(Element* element) { + DCHECK(elements_.count(element) > 0); // The element must be running. - animations_.erase(animation); + elements_.erase(element); - if (animations_.empty()) { + if (elements_.empty()) { timer_.Stop(); if (observer_) observer_->AnimationContainerEmpty(this); @@ -52,25 +52,24 @@ void AnimationContainer::Stop(Animation* animation) { } void AnimationContainer::Run() { - // We notify the observer after updating all the animations. If all the - // animations are deleted as a result of updating then our ref count would go - // to zero and we would be deleted before we notify our observer. We add a - // reference to ourself here to make sure we're still valid after running all - // the animations. + // We notify the observer after updating all the elements. If all the elements + // are deleted as a result of updating then our ref count would go to zero and + // we would be deleted before we notify our observer. We add a reference to + // ourself here to make sure we're still valid after running all the elements. scoped_refptr<AnimationContainer> this_ref(this); TimeTicks current_time = TimeTicks::Now(); last_tick_time_ = current_time; - // Make a copy of the animations to iterate over so that if any animations - // are removed as part of invoking Step there aren't any problems. - Animations animations = animations_; + // Make a copy of the elements to iterate over so that if any elements are + // removed as part of invoking Step there aren't any problems. + Elements elements = elements_; - for (Animations::const_iterator i = animations.begin(); - i != animations.end(); ++i) { - // Make sure the animation is still valid. - if (animations_.find(*i) != animations_.end()) + for (Elements::const_iterator i = elements.begin(); + i != elements.end(); ++i) { + // Make sure the element is still valid. + if (elements_.find(*i) != elements_.end()) (*i)->Step(current_time); } @@ -79,22 +78,22 @@ void AnimationContainer::Run() { } void AnimationContainer::SetMinTimerInterval(base::TimeDelta delta) { - // This doesn't take into account how far along current animation is, but that - // shouldn't be a problem for uses of Animation/AnimationContainer. + // This doesn't take into account how far along the current element is, but + // that shouldn't be a problem for uses of Animation/AnimationContainer. timer_.Stop(); min_timer_interval_ = delta; timer_.Start(min_timer_interval_, this, &AnimationContainer::Run); } TimeDelta AnimationContainer::GetMinInterval() { - DCHECK(!animations_.empty()); + DCHECK(!elements_.empty()); TimeDelta min; - Animations::const_iterator i = animations_.begin(); - min = (*i)->timer_interval(); - for (++i; i != animations_.end(); ++i) { - if ((*i)->timer_interval() < min) - min = (*i)->timer_interval(); + Elements::const_iterator i = elements_.begin(); + min = (*i)->GetTimerInterval(); + for (++i; i != elements_.end(); ++i) { + if ((*i)->GetTimerInterval() < min) + min = (*i)->GetTimerInterval(); } return min; } diff --git a/app/animation_container.h b/app/animation_container.h index fcb3fad..98abf28 100644 --- a/app/animation_container.h +++ b/app/animation_container.h @@ -11,8 +11,6 @@ #include "base/time.h" #include "base/timer.h" -class Animation; - // AnimationContainer is used by Animation to manage the underlying timer. // Internally each Animation creates a single AnimationContainer. You can // group a set of Animations into the same AnimationContainer by way of @@ -36,31 +34,53 @@ class AnimationContainer : public base::RefCounted<AnimationContainer> { virtual void AnimationContainerEmpty(AnimationContainer* container) = 0; }; + // Interface for the elements the AnimationContainer contains. This is + // implemented by Animation. + class Element { + public: + // Sets the start of the animation. This is invoked from + // AnimationContainer::Start. + virtual void SetStartTime(base::TimeTicks start_time) = 0; + + // Invoked when the animation is to progress. + virtual void Step(base::TimeTicks time_now) = 0; + + // Returns the time interval of the animation. If an Element needs to change + // this it should first invoke Stop, then Start. + virtual base::TimeDelta GetTimerInterval() const = 0; + + protected: + virtual ~Element() {} + }; + AnimationContainer(); + // Invoked by Animation when it needs to start. Starts the timer if necessary. + // NOTE: This is invoked by Animation for you, you shouldn't invoke this + // directly. + void Start(Element* animation); + + // Invoked by Animation when it needs to stop. If there are no more animations + // running the timer stops. + // NOTE: This is invoked by Animation for you, you shouldn't invoke this + // directly. + void Stop(Element* animation); + void set_observer(Observer* observer) { observer_ = observer; } // The time the last animation ran at. base::TimeTicks last_tick_time() const { return last_tick_time_; } // Are there any timers running? - bool is_running() const { return !animations_.empty(); } + bool is_running() const { return !elements_.empty(); } private: - friend class Animation; friend class base::RefCounted<AnimationContainer>; - typedef std::set<Animation*> Animations; + typedef std::set<Element*> Elements; ~AnimationContainer(); - // Invoked by Animation when it needs to start. Starts the timer if necessary. - void Start(Animation* animation); - - // Invoked by Animation when it needs to stop. If there are no more animations - // running the timer stops. - void Stop(Animation* animation); - // Timer callback method. void Run(); @@ -76,8 +96,8 @@ class AnimationContainer : public base::RefCounted<AnimationContainer> { // . The time the last animation ran at (::Run was invoked). base::TimeTicks last_tick_time_; - // Set of animations being managed. - Animations animations_; + // Set of elements (animations) being managed. + Elements elements_; // Minimum interval the timers run at. base::TimeDelta min_timer_interval_; diff --git a/app/animation_container_unittest.cc b/app/animation_container_unittest.cc index 4046ae3..e4253c6 100644 --- a/app/animation_container_unittest.cc +++ b/app/animation_container_unittest.cc @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "app/animation.h" #include "app/animation_container.h" +#include "app/linear_animation.h" #include "app/test_animation_delegate.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -23,10 +23,10 @@ class MockObserver : public AnimationContainer::Observer { DISALLOW_COPY_AND_ASSIGN(MockObserver); }; -class TestAnimation : public Animation { +class TestAnimation : public LinearAnimation { public: TestAnimation(AnimationDelegate* delegate) - : Animation(20, 20, delegate) { + : LinearAnimation(20, 20, delegate) { } virtual void AnimateToState(double state) { diff --git a/app/animation_unittest.cc b/app/animation_unittest.cc index 30f9b52..df0b262b 100644 --- a/app/animation_unittest.cc +++ b/app/animation_unittest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "app/animation.h" +#include "app/linear_animation.h" #include "app/test_animation_delegate.h" #if defined(OS_WIN) #include "base/win_util.h" @@ -14,13 +14,15 @@ class AnimationTest: public testing::Test { MessageLoopForUI message_loop_; }; +namespace { + /////////////////////////////////////////////////////////////////////////////// // RunAnimation -class RunAnimation : public Animation { +class RunAnimation : public LinearAnimation { public: RunAnimation(int frame_rate, AnimationDelegate* delegate) - : Animation(frame_rate, delegate) { + : LinearAnimation(frame_rate, delegate) { } virtual void AnimateToState(double state) { @@ -32,10 +34,10 @@ class RunAnimation : public Animation { /////////////////////////////////////////////////////////////////////////////// // CancelAnimation -class CancelAnimation : public Animation { +class CancelAnimation : public LinearAnimation { public: CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate) - : Animation(duration, frame_rate, delegate) { + : LinearAnimation(duration, frame_rate, delegate) { } virtual void AnimateToState(double state) { @@ -45,6 +47,35 @@ class CancelAnimation : public Animation { }; /////////////////////////////////////////////////////////////////////////////// +// EndAnimation + +class EndAnimation : public LinearAnimation { + public: + EndAnimation(int duration, int frame_rate, AnimationDelegate* delegate) + : LinearAnimation(duration, frame_rate, delegate) { + } + + virtual void AnimateToState(double state) { + if (state >= 0.5) + End(); + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// DeletingAnimationDelegate + +// AnimationDelegate implementation that deletes the animation in ended. +class DeletingAnimationDelegate : public AnimationDelegate { + public: + virtual void AnimationEnded(const Animation* animation) { + delete animation; + MessageLoop::current()->Quit(); + } +}; + +} // namespace + +/////////////////////////////////////////////////////////////////////////////// // LinearCase TEST_F(AnimationTest, RunCase) { @@ -68,6 +99,27 @@ TEST_F(AnimationTest, CancelCase) { EXPECT_TRUE(ad.canceled()); } +// Lets an animation run, invoking End part way through and make sure we get the +// right delegate methods invoked. +TEST_F(AnimationTest, EndCase) { + TestAnimationDelegate ad; + EndAnimation a2(2000, 150, &ad); + a2.Start(); + MessageLoop::current()->Run(); + + EXPECT_TRUE(ad.finished()); + EXPECT_FALSE(ad.canceled()); +} + +// Runs an animation with a delegate that deletes the animation in end. +TEST_F(AnimationTest, DeleteFromEnd) { + DeletingAnimationDelegate delegate; + RunAnimation* animation = new RunAnimation(150, &delegate); + animation->Start(); + MessageLoop::current()->Run(); + // delegate should have deleted animation. +} + TEST_F(AnimationTest, ShouldRenderRichAnimation) { #if defined(OS_WIN) if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) { diff --git a/app/app_base.gypi b/app/app_base.gypi index 0c68721..b28bc2b 100644 --- a/app/app_base.gypi +++ b/app/app_base.gypi @@ -146,6 +146,8 @@ 'l10n_util_posix.cc', 'l10n_util_win.cc', 'l10n_util_win.h', + 'linear_animation.cc', + 'linear_animation.h', 'menus/accelerator.h', 'menus/accelerator_gtk.h', 'menus/menu_model.cc', @@ -194,6 +196,8 @@ 'theme_provider.h', 'throb_animation.cc', 'throb_animation.h', + 'tween.cc', + 'tween.h', 'x11_util.cc', 'x11_util.h', 'x11_util_internal.h', diff --git a/app/linear_animation.cc b/app/linear_animation.cc new file mode 100644 index 0000000..35974af --- /dev/null +++ b/app/linear_animation.cc @@ -0,0 +1,91 @@ +// Copyright (c) 2010 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/linear_animation.h" + +#include <math.h> + +#include "app/animation_container.h" + +using base::Time; +using base::TimeDelta; + +static TimeDelta CalculateInterval(int frame_rate) { + int timer_interval = 1000000 / frame_rate; + if (timer_interval < 10000) + timer_interval = 10000; + return TimeDelta::FromMicroseconds(timer_interval); +} + +LinearAnimation::LinearAnimation(int frame_rate, + AnimationDelegate* delegate) + : Animation(CalculateInterval(frame_rate)), + state_(0.0), + in_end_(false) { + set_delegate(delegate); +} + +LinearAnimation::LinearAnimation(int duration, + int frame_rate, + AnimationDelegate* delegate) + : Animation(CalculateInterval(frame_rate)), + duration_(TimeDelta::FromMilliseconds(duration)), + state_(0.0), + in_end_(false) { + set_delegate(delegate); + SetDuration(duration); +} + +double LinearAnimation::GetCurrentValue() const { + // Default is linear relationship, subclass to adapt. + return state_; +} + +void LinearAnimation::End() { + if (!is_animating()) + return; + + // NOTE: We don't use AutoReset here as Stop may end up deleting us (by way + // of the delegate). + in_end_ = true; + Stop(); +} + +void LinearAnimation::SetDuration(int duration) { + duration_ = TimeDelta::FromMilliseconds(duration); + if (duration_ < timer_interval()) + duration_ = timer_interval(); + if (is_animating()) + SetStartTime(container()->last_tick_time()); +} + +void LinearAnimation::Step(base::TimeTicks time_now) { + TimeDelta elapsed_time = time_now - start_time(); + state_ = static_cast<double>(elapsed_time.InMicroseconds()) / + static_cast<double>(duration_.InMicroseconds()); + if (state_ >= 1.0) + state_ = 1.0; + + AnimateToState(state_); + + if (delegate()) + delegate()->AnimationProgressed(this); + + if (state_ == 1.0) + Stop(); +} + +void LinearAnimation::AnimationStopped() { + if (!in_end_) + return; + + in_end_ = false; + // Set state_ to ensure we send ended to delegate and not canceled. + state_ = 1; + AnimateToState(1.0); +} + +bool LinearAnimation::ShouldSendCanceledFromStop() { + return state_ != 1; +} diff --git a/app/linear_animation.h b/app/linear_animation.h new file mode 100644 index 0000000..c4f5707 --- /dev/null +++ b/app/linear_animation.h @@ -0,0 +1,70 @@ +// Copyright (c) 2010 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. +// Inspired by NSAnimation + +#ifndef APP_LINEAR_ANIMATION_H_ +#define APP_LINEAR_ANIMATION_H_ + +#include "app/animation.h" +#include "base/time.h" + +class AnimationDelegate; + +// Linear time bounded animation. As the animation progresses AnimateToState is +// invoked. +class LinearAnimation : public Animation { + public: + // Initializes everything except the duration. + // + // Caller must make sure to call SetDuration() if they use this + // constructor; it is preferable to use the full one, but sometimes + // duration can change between calls to Start() and we need to + // expose this interface. + LinearAnimation(int frame_rate, AnimationDelegate* delegate); + + // Initializes all fields. + LinearAnimation(int duration, int frame_rate, AnimationDelegate* delegate); + + // Gets the value for the current state, according to the animation curve in + // use. This class provides only for a linear relationship, however subclasses + // can override this to provide others. + virtual double GetCurrentValue() const; + + // Skip to the end of the current animation. + void End(); + + // Changes the length of the animation. This resets the current + // state of the animation to the beginning. + void SetDuration(int duration); + + protected: + // Called when the animation progresses. Subclasses override this to + // efficiently update their state. + virtual void AnimateToState(double state) = 0; + + // Invoked by the AnimationContainer when the animation is running to advance + // the animation. Use |time_now| rather than Time::Now to avoid multiple + // animations running at the same time diverging. + virtual void Step(base::TimeTicks time_now); + + // Overriden to advance to the end (if End was invoked). + virtual void AnimationStopped(); + + // Overriden to return true if state is not 1. + virtual bool ShouldSendCanceledFromStop(); + + private: + base::TimeDelta duration_; + + // Current state, on a scale from 0.0 to 1.0. + double state_; + + // If true, we're in end. This is used to determine if the animation should + // be advanced to the end from AnimationStopped. + bool in_end_; + + DISALLOW_COPY_AND_ASSIGN(LinearAnimation); +}; + +#endif // APP_LINEAR_ANIMATION_H_ diff --git a/app/slide_animation.cc b/app/slide_animation.cc index ca468d2..c79e3ec 100644 --- a/app/slide_animation.cc +++ b/app/slide_animation.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -13,9 +13,9 @@ static const int kDefaultFramerateHz = 50; static const int kDefaultDurationMs = 120; SlideAnimation::SlideAnimation(AnimationDelegate* target) - : Animation(kDefaultFramerateHz, target), + : LinearAnimation(kDefaultFramerateHz, target), target_(target), - tween_type_(EASE_OUT), + tween_type_(Tween::EASE_OUT), showing_(false), value_start_(0), value_end_(0), @@ -84,36 +84,13 @@ void SlideAnimation::AnimateToState(double state) { if (state > 1.0) state = 1.0; - // Make our animation ease-out. - switch (tween_type_) { - case EASE_IN: - state = pow(state, 2); - break; - case EASE_IN_OUT: - if (state < 0.5) - state = pow(state * 2, 2) / 2.0; - else - state = 1.0 - (pow((state - 1.0) * 2, 2) / 2.0); - break; - case FAST_IN_OUT: - state = (pow(state - 0.5, 3) + 0.125) / 0.25; - break; - case NONE: - // state remains linear. - break; - case EASE_OUT_SNAP: - state = 0.95 * (1.0 - pow(1.0 - state, 2)); - break; - case EASE_OUT: - default: - state = 1.0 - pow(1.0 - state, 2); - break; - } + state = Tween::CalculateValue(tween_type_, state); value_current_ = value_start_ + (value_end_ - value_start_) * state; // Implement snapping. - if (tween_type_ == EASE_OUT_SNAP && fabs(value_current_ - value_end_) <= 0.06) + if (tween_type_ == Tween::EASE_OUT_SNAP && + fabs(value_current_ - value_end_) <= 0.06) value_current_ = value_end_; // Correct for any overshoot (while state may be capped at 1.0, let's not diff --git a/app/slide_animation.h b/app/slide_animation.h index 3cf32d9..0b42792 100644 --- a/app/slide_animation.h +++ b/app/slide_animation.h @@ -1,11 +1,12 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. #ifndef APP_SLIDE_ANIMATION_H_ #define APP_SLIDE_ANIMATION_H_ -#include "app/animation.h" +#include "app/linear_animation.h" +#include "app/tween.h" // Slide Animation // @@ -34,24 +35,15 @@ // } // } // void Layout() { -// if (animation_->IsAnimating()) { +// if (animation_->is_animating()) { // hover_image_.SetOpacity(animation_->GetCurrentValue()); // } // } // private: // scoped_ptr<SlideAnimation> animation_; // } -class SlideAnimation : public Animation { +class SlideAnimation : public LinearAnimation { public: - enum TweenType { - NONE, // Linear. - EASE_OUT, // Fast in, slow out (default). - EASE_IN, // Slow in, fast out. - EASE_IN_OUT, // Slow in and out, fast in the middle. - FAST_IN_OUT, // Fast in and out, slow in the middle. - EASE_OUT_SNAP, // Fast in, slow out, snap to final value. - }; - explicit SlideAnimation(AnimationDelegate* target); virtual ~SlideAnimation(); @@ -70,7 +62,7 @@ class SlideAnimation : public Animation { // the slide is considered. virtual void SetSlideDuration(int duration) { slide_duration_ = duration; } int GetSlideDuration() const { return slide_duration_; } - void SetTweenType(TweenType tween_type) { tween_type_ = tween_type; } + void SetTweenType(Tween::Type tween_type) { tween_type_ = tween_type; } double GetCurrentValue() const { return value_current_; } bool IsShowing() const { return showing_; } @@ -82,7 +74,7 @@ class SlideAnimation : public Animation { AnimationDelegate* target_; - TweenType tween_type_; + Tween::Type tween_type_; // Used to determine which way the animation is going. bool showing_; diff --git a/app/test_animation_delegate.h b/app/test_animation_delegate.h index 76f0f3e..0d9554b 100644 --- a/app/test_animation_delegate.h +++ b/app/test_animation_delegate.h @@ -15,9 +15,6 @@ class TestAnimationDelegate : public AnimationDelegate { TestAnimationDelegate() : canceled_(false), finished_(false) { } - virtual void AnimationStarted(const Animation* animation) { - } - virtual void AnimationEnded(const Animation* animation) { finished_ = true; MessageLoop::current()->Quit(); diff --git a/app/throb_animation.cc b/app/throb_animation.cc index e8e5730..922d77d 100644 --- a/app/throb_animation.cc +++ b/app/throb_animation.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -18,7 +18,7 @@ void ThrobAnimation::StartThrobbing(int cycles_til_stop) { cycles_remaining_ = cycles_til_stop; throbbing_ = true; SlideAnimation::SetSlideDuration(throb_duration_); - if (IsAnimating()) + if (is_animating()) return; // We're already running, we'll cycle when current loop finishes. if (IsShowing()) @@ -44,9 +44,9 @@ void ThrobAnimation::Hide() { } void ThrobAnimation::Step(base::TimeTicks time_now) { - Animation::Step(time_now); + LinearAnimation::Step(time_now); - if (!IsAnimating() && throbbing_) { + if (!is_animating() && 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_--; diff --git a/app/tween.cc b/app/tween.cc new file mode 100644 index 0000000..57cd83e --- /dev/null +++ b/app/tween.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2010 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/tween.h" + +#include <math.h> + +#if defined(OS_WIN) +#include <float.h> +#endif + +#include "gfx/rect.h" + +// static +double Tween::CalculateValue(Tween::Type type, double state) { + DCHECK_GE(state, 0); + DCHECK_LE(state, 1); + + switch (type) { + case EASE_IN: + return pow(state, 2); + + case EASE_IN_OUT: + if (state < 0.5) + return pow(state * 2, 2) / 2.0; + return 1.0 - (pow((state - 1.0) * 2, 2) / 2.0); + + case FAST_IN_OUT: + return (pow(state - 0.5, 3) + 0.125) / 0.25; + + case LINEAR: + return state; + + case EASE_OUT_SNAP: + state = 0.95 * (1.0 - pow(1.0 - state, 2)); + break; + + case EASE_OUT: + return 1.0 - pow(1.0 - state, 2); + + case ZERO: + return 0; + } + + NOTREACHED(); + return state; +} + +// static +double Tween::ValueBetween(double value, double start, double target) { + return start + (target - start) * value; +} + +// static +int Tween::ValueBetween(double value, int start, int target) { + if (start == target) + return start; + double delta = static_cast<double>(target - start); + if (delta < 0) + delta--; + else + delta++; +#if defined(OS_WIN) + return start + static_cast<int>(value * _nextafter(delta, 0)); +#else + return start + static_cast<int>(value * nextafter(delta, 0)); +#endif +} + +// static +gfx::Rect Tween::ValueBetween(double value, + const gfx::Rect& start_bounds, + const gfx::Rect& target_bounds) { + return gfx::Rect(ValueBetween(value, start_bounds.x(), target_bounds.x()), + ValueBetween(value, start_bounds.y(), target_bounds.y()), + ValueBetween(value, start_bounds.width(), + target_bounds.width()), + ValueBetween(value, start_bounds.height(), + target_bounds.height())); +} diff --git a/app/tween.h b/app/tween.h new file mode 100644 index 0000000..41785ef6 --- /dev/null +++ b/app/tween.h @@ -0,0 +1,43 @@ +// Copyright (c) 2010 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. + +#ifndef APP_TWEEN_H_ +#define APP_TWEEN_H_ + +#include "base/logging.h" + +namespace gfx { +class Rect; +} + +class Tween { + public: + enum Type { + LINEAR, // Linear. + EASE_OUT, // Fast in, slow out (default). + EASE_IN, // Slow in, fast out. + EASE_IN_OUT, // Slow in and out, fast in the middle. + FAST_IN_OUT, // Fast in and out, slow in the middle. + EASE_OUT_SNAP, // Fast in, slow out, snap to final value. + ZERO, // Returns a value of 0 always. + }; + + // Returns the value based on the tween type. |state| is from 0-1. + static double CalculateValue(Type type, double state); + + // Conveniences for getting a value between a start and end point. + static double ValueBetween(double value, double start, double target); + static int ValueBetween(double value, int start, int target); + static gfx::Rect ValueBetween(double value, + const gfx::Rect& start_bounds, + const gfx::Rect& target_bounds); + + private: + Tween(); + ~Tween(); + + DISALLOW_COPY_AND_ASSIGN(Tween); +}; + +#endif // APP_TWEEN_H_ diff --git a/chrome/browser/chromeos/panels/panel_scroller.cc b/chrome/browser/chromeos/panels/panel_scroller.cc index ec681f3..daaa3fc 100644 --- a/chrome/browser/chromeos/panels/panel_scroller.cc +++ b/chrome/browser/chromeos/panels/panel_scroller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this +// Copyright (c) 2010 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. @@ -26,7 +26,7 @@ PanelScroller::PanelScroller() ALLOW_THIS_IN_INITIALIZER_LIST(animation_(this)), animated_scroll_begin_(0), animated_scroll_end_(0) { - animation_.SetTweenType(SlideAnimation::EASE_IN_OUT); + animation_.SetTweenType(Tween::EASE_IN_OUT); animation_.SetSlideDuration(300); Panel* panel = new Panel; @@ -237,9 +237,6 @@ void PanelScroller::ScrollToPanel(int index) { animation_.Show(); } -void PanelScroller::AnimationEnded(const Animation* animation) { -} - void PanelScroller::AnimationProgressed(const Animation* animation) { scroll_pos_ = static_cast<int>( static_cast<double>(animated_scroll_end_ - animated_scroll_begin_) * @@ -248,6 +245,3 @@ void PanelScroller::AnimationProgressed(const Animation* animation) { Layout(); SchedulePaint(); } - -void PanelScroller::AnimationCanceled(const Animation* animation) { -} diff --git a/chrome/browser/chromeos/panels/panel_scroller.h b/chrome/browser/chromeos/panels/panel_scroller.h index a3db3db..51eedff 100644 --- a/chrome/browser/chromeos/panels/panel_scroller.h +++ b/chrome/browser/chromeos/panels/panel_scroller.h @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this +// Copyright (c) 2010 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. @@ -38,9 +38,7 @@ class PanelScroller : public views::View, public AnimationDelegate { struct Panel; // AnimationDelegate overrides. - virtual void AnimationEnded(const Animation* animation); virtual void AnimationProgressed(const Animation* animation); - virtual void AnimationCanceled(const Animation* animation); // Scrolls to the panel at the given index. It will be moved to the top. void ScrollToPanel(int index); diff --git a/chrome/browser/chromeos/status/network_menu_button.cc b/chrome/browser/chromeos/status/network_menu_button.cc index 8cb7eba..dea19d8 100644 --- a/chrome/browser/chromeos/status/network_menu_button.cc +++ b/chrome/browser/chromeos/status/network_menu_button.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -34,7 +34,7 @@ NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)), ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { animation_connecting_.SetThrobDuration(kThrobDuration); - animation_connecting_.SetTweenType(SlideAnimation::NONE); + animation_connecting_.SetTweenType(Tween::LINEAR); NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); } @@ -185,7 +185,7 @@ void NetworkMenuButton::DrawPressed(gfx::Canvas* canvas) { // If ethernet connected and not current connecting, then show ethernet // pressed icon. Otherwise, show the bars pressed icon. if (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() && - !animation_connecting_.IsAnimating()) + !animation_connecting_.is_animating()) canvas->DrawBitmapInt(IconForDisplay( *ResourceBundle::GetSharedInstance(). GetBitmapNamed(IDR_STATUSBAR_NETWORK_WIRED_PRESSED), SkBitmap()), @@ -230,19 +230,19 @@ void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { // figure out if we are to also draw the extra image. int downloading_index = -1; int uploading_index = -1; - if (!animation_connecting_.IsAnimating()) { + if (!animation_connecting_.is_animating()) { // For network animation, we only show animation in one direction. // So when we are hiding, we just use 1 minus the value. // We have kNumWifiImages + 1 number of states. For the first state, where // we are not adding any images, we set the index to -1. - if (animation_downloading_.IsAnimating()) { + if (animation_downloading_.is_animating()) { double value_downloading = animation_downloading_.IsShowing() ? animation_downloading_.GetCurrentValue() : 1.0 - animation_downloading_.GetCurrentValue(); downloading_index = static_cast<int>(value_downloading * nextafter(static_cast<float>(kNumWifiImages + 1), 0)) - 1; } - if (animation_uploading_.IsAnimating()) { + if (animation_uploading_.is_animating()) { double value_uploading = animation_uploading_.IsShowing() ? animation_uploading_.GetCurrentValue() : 1.0 - animation_uploading_.GetCurrentValue(); @@ -299,7 +299,7 @@ void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { if (CrosLibrary::Get()->EnsureLoaded()) { if (cros->wifi_connecting() || cros->cellular_connecting()) { // Start the connecting animation if not running. - if (!animation_connecting_.IsAnimating()) { + if (!animation_connecting_.is_animating()) { animation_connecting_.Reset(); animation_connecting_.StartThrobbing(std::numeric_limits<int>::max()); SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1)); diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 236123f..eed763f 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -392,7 +392,7 @@ int BookmarkBarGtk::GetHeight() { } bool BookmarkBarGtk::IsAnimating() { - return slide_animation_->IsAnimating(); + return slide_animation_->is_animating(); } bool BookmarkBarGtk::OnNewTabPage() { diff --git a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc index 694e502..65fe134 100644 --- a/chrome/browser/gtk/browser_actions_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_actions_toolbar_gtk.cc @@ -855,6 +855,6 @@ gboolean BrowserActionsToolbarGtk::OnOverflowMenuButtonPress( } void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { - if (!resize_animation_.IsAnimating()) + if (!resize_animation_.is_animating()) UpdateChevronVisibility(); } diff --git a/chrome/browser/gtk/download_item_gtk.cc b/chrome/browser/gtk/download_item_gtk.cc index 5260d0f..2439943 100644 --- a/chrome/browser/gtk/download_item_gtk.cc +++ b/chrome/browser/gtk/download_item_gtk.cc @@ -361,7 +361,7 @@ void DownloadItemGtk::OnDownloadUpdated(DownloadItem* download) { complete_animation_.reset(new SlideAnimation(this)); complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); - complete_animation_->SetTweenType(SlideAnimation::NONE); + complete_animation_->SetTweenType(Tween::LINEAR); complete_animation_->Show(); break; case DownloadItem::IN_PROGRESS: @@ -792,7 +792,7 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, // Create a transparent canvas. gfx::CanvasPaint canvas(event, false); if (complete_animation_.get()) { - if (complete_animation_->IsAnimating()) { + if (complete_animation_->is_animating()) { download_util::PaintDownloadComplete(&canvas, widget->allocation.x, widget->allocation.y, complete_animation_->GetCurrentValue(), @@ -822,7 +822,7 @@ gboolean DownloadItemGtk::OnProgressAreaExpose(GtkWidget* widget, gboolean DownloadItemGtk::OnMenuButtonPressEvent(GtkWidget* button, GdkEvent* event) { // Stop any completion animation. - if (complete_animation_.get() && complete_animation_->IsAnimating()) + if (complete_animation_.get() && complete_animation_->is_animating()) complete_animation_->End(); if (event->type == GDK_BUTTON_PRESS) { diff --git a/chrome/browser/gtk/download_started_animation_gtk.cc b/chrome/browser/gtk/download_started_animation_gtk.cc index 1e10348..5343ac2 100644 --- a/chrome/browser/gtk/download_started_animation_gtk.cc +++ b/chrome/browser/gtk/download_started_animation_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -6,7 +6,7 @@ #include <gtk/gtk.h> -#include "app/animation.h" +#include "app/linear_animation.h" #include "app/resource_bundle.h" #include "base/message_loop.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -28,7 +28,7 @@ const int kFrameRateHz = 60; // the frame. const double kMoveFraction = 1.0 / 3.0; -class DownloadStartedAnimationGtk : public Animation, +class DownloadStartedAnimationGtk : public LinearAnimation, public NotificationObserver { public: explicit DownloadStartedAnimationGtk(TabContents* tab_contents); @@ -78,7 +78,7 @@ class DownloadStartedAnimationGtk : public Animation, DownloadStartedAnimationGtk::DownloadStartedAnimationGtk( TabContents* tab_contents) - : Animation(kMoveTimeMs, kFrameRateHz, NULL), + : LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL), tab_contents_(tab_contents) { static GdkPixbuf* kDownloadImage = NULL; if (!kDownloadImage) { diff --git a/chrome/browser/gtk/hover_controller_gtk.cc b/chrome/browser/gtk/hover_controller_gtk.cc index 0737a97..3adf686 100644 --- a/chrome/browser/gtk/hover_controller_gtk.cc +++ b/chrome/browser/gtk/hover_controller_gtk.cc @@ -67,7 +67,7 @@ void HoverControllerGtk::AnimationProgressed(const Animation* animation) { return; // Ignore the hover animation if we are throbbing. - if (animation == &hover_animation_ && throb_animation_.IsAnimating()) + if (animation == &hover_animation_ && throb_animation_.is_animating()) return; gtk_chrome_button_set_hover_state(GTK_CHROME_BUTTON(button_), diff --git a/chrome/browser/gtk/slide_animator_gtk.cc b/chrome/browser/gtk/slide_animator_gtk.cc index 2c1549d..ff20c40 100644 --- a/chrome/browser/gtk/slide_animator_gtk.cc +++ b/chrome/browser/gtk/slide_animator_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -60,7 +60,7 @@ SlideAnimatorGtk::SlideAnimatorGtk(GtkWidget* child, animation_.reset(new SlideAnimation(this)); // Default tween type is EASE_OUT. if (linear) - animation_->SetTweenType(SlideAnimation::NONE); + animation_->SetTweenType(Tween::LINEAR); if (duration != 0) animation_->SetSlideDuration(duration); } @@ -111,7 +111,7 @@ bool SlideAnimatorGtk::IsClosing() { } bool SlideAnimatorGtk::IsAnimating() { - return animation_->IsAnimating(); + return animation_->is_animating(); } void SlideAnimatorGtk::AnimationProgressed(const Animation* animation) { diff --git a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc index bffadd5..f221c0e 100644 --- a/chrome/browser/gtk/tabs/dragged_tab_gtk.cc +++ b/chrome/browser/gtk/tabs/dragged_tab_gtk.cc @@ -125,7 +125,7 @@ void DraggedTabGtk::AnimateToBounds(const gfx::Rect& bounds, animation_end_bounds_ = bounds; close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs); - close_animation_.SetTweenType(SlideAnimation::EASE_OUT); + close_animation_.SetTweenType(Tween::EASE_OUT); if (!close_animation_.IsShowing()) { close_animation_.Reset(); close_animation_.Show(); diff --git a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc index 20307d3..c8a0e6b 100644 --- a/chrome/browser/gtk/tabs/tab_renderer_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_renderer_gtk.cc @@ -200,11 +200,11 @@ void TabRendererGtk::LoadingAnimation::Observe( // FaviconCrashAnimation // // A custom animation subclass to manage the favicon crash animation. -class TabRendererGtk::FavIconCrashAnimation : public Animation, +class TabRendererGtk::FavIconCrashAnimation : public LinearAnimation, public AnimationDelegate { public: explicit FavIconCrashAnimation(TabRendererGtk* target) - : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(1000, 25, this)), target_(target) { } virtual ~FavIconCrashAnimation() {} @@ -501,7 +501,7 @@ void TabRendererGtk::StartMiniTabTitleAnimation() { mini_title_animation_->SetThrobDuration(kMiniTitleChangeThrobDuration); } - if (!mini_title_animation_->IsAnimating()) { + if (!mini_title_animation_->is_animating()) { mini_title_animation_->StartThrobbing(2); } else if (mini_title_animation_->cycles_remaining() <= 2) { // The title changed while we're already animating. Add at most one more @@ -575,7 +575,7 @@ void TabRendererGtk::StopCrashAnimation() { } bool TabRendererGtk::IsPerformingCrashAnimation() const { - return crash_animation_.get() && crash_animation_->IsAnimating(); + return crash_animation_.get() && crash_animation_->is_animating(); } void TabRendererGtk::SetFavIconHidingOffset(int offset) { @@ -986,7 +986,7 @@ CustomDrawButton* TabRendererGtk::MakeCloseButton() { } double TabRendererGtk::GetThrobValue() { - if (mini_title_animation_.get() && mini_title_animation_->IsAnimating()) { + if (mini_title_animation_.get() && mini_title_animation_->is_animating()) { return mini_title_animation_->GetCurrentValue() * kMiniTitleChangeThrobOpacity; } @@ -1045,7 +1045,7 @@ void TabRendererGtk::OnSizeAllocate(GtkWidget* widget, gboolean TabRendererGtk::OnEnterNotifyEvent(GtkWidget* widget, GdkEventCrossing* event, TabRendererGtk* tab) { - tab->hover_animation_->SetTweenType(SlideAnimation::EASE_OUT); + tab->hover_animation_->SetTweenType(Tween::EASE_OUT); tab->hover_animation_->Show(); return FALSE; } @@ -1054,7 +1054,7 @@ gboolean TabRendererGtk::OnEnterNotifyEvent(GtkWidget* widget, gboolean TabRendererGtk::OnLeaveNotifyEvent(GtkWidget* widget, GdkEventCrossing* event, TabRendererGtk* tab) { - tab->hover_animation_->SetTweenType(SlideAnimation::EASE_IN); + tab->hover_animation_->SetTweenType(Tween::EASE_IN); tab->hover_animation_->Hide(); return FALSE; } diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 8d1d1c8..7b3bf73 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -130,7 +130,7 @@ class TabStripGtk::TabAnimation : public AnimationDelegate { void Start() { animation_.SetSlideDuration(GetDuration()); - animation_.SetTweenType(SlideAnimation::EASE_OUT); + animation_.SetTweenType(Tween::EASE_OUT); if (!animation_.IsShowing()) { animation_.Reset(); animation_.Show(); diff --git a/chrome/browser/gtk/translate_infobars.cc b/chrome/browser/gtk/translate_infobars.cc index 7870e52..63878e2 100644 --- a/chrome/browser/gtk/translate_infobars.cc +++ b/chrome/browser/gtk/translate_infobars.cc @@ -149,7 +149,7 @@ TranslateInfoBar::TranslateInfoBar(TranslateInfoBarDelegate* delegate) swapped_language_placeholders_(false) { // Initialize slide animation for transitioning to and from error state. error_animation_.reset(new SlideAnimation(this)); - error_animation_->SetTweenType(SlideAnimation::NONE); + error_animation_->SetTweenType(Tween::LINEAR); error_animation_->SetSlideDuration(500); BuildWidgets(); diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 4f71b75..f569ff9 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -522,7 +522,7 @@ AutocompletePopupContentsView::~AutocompletePopupContentsView() { } gfx::Rect AutocompletePopupContentsView::GetPopupBounds() const { - if (!size_animation_.IsAnimating()) + if (!size_animation_.is_animating()) return target_bounds_; gfx::Rect current_frame_bounds = start_bounds_; diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index e67d212..d6b1690 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -1104,7 +1104,7 @@ void BookmarkBarView::WriteDragData(View* sender, } int BookmarkBarView::GetDragOperations(View* sender, const gfx::Point& p) { - if (size_animation_->IsAnimating() || + if (size_animation_->is_animating() || (size_animation_->GetCurrentValue() == 0 && !OnNewTabPage())) { // Don't let the user drag while animating open or we're closed (and not on // the new tab page, on the new tab page size_animation_ is always 0). This diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h index 6eb975c..b23641b 100644 --- a/chrome/browser/views/bookmark_bar_view.h +++ b/chrome/browser/views/bookmark_bar_view.h @@ -157,7 +157,7 @@ class BookmarkBarView : public DetachableToolbarView, int GetToolbarOverlap(bool return_max); // Whether or not we are animating. - bool IsAnimating() { return size_animation_->IsAnimating(); } + bool is_animating() { return size_animation_->is_animating(); } // SlideAnimationDelegate implementation. void AnimationProgressed(const Animation* animation); diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc index c74e333..f4132bb 100644 --- a/chrome/browser/views/browser_actions_container.cc +++ b/chrome/browser/views/browser_actions_container.cc @@ -952,7 +952,7 @@ void BrowserActionsContainer::BrowserActionAdded(Extension* extension, // in the header for why we do this. suppress_chevron_ = !chevron_->IsVisible(); - Animate(SlideAnimation::NONE, target_size); + Animate(Tween::LINEAR, target_size); } } @@ -990,7 +990,7 @@ void BrowserActionsContainer::BrowserActionRemoved(Extension* extension) { int target_size = ClampToNearestIconCount(IconCountToWidth(visible_actions), true); - Animate(SlideAnimation::EASE_OUT, target_size); + Animate(Tween::EASE_OUT, target_size); return; } } @@ -1048,8 +1048,7 @@ int BrowserActionsContainer::ContainerMinSize() const { return resize_gripper_->width() + chevron_->width() + kChevronRightMargin; } -void BrowserActionsContainer::Animate( - SlideAnimation::TweenType tween_type, int target_size) { +void BrowserActionsContainer::Animate(Tween::Type tween_type, int target_size) { if (!disable_animations_during_testing_) { // Animate! We have to set the animation_target_size_ after calling Reset(), // because that could end up calling AnimationEnded which clears the value. @@ -1093,7 +1092,7 @@ void BrowserActionsContainer::OnResize(int resize_amount, bool done_resizing) { container_size_.set_width(new_width); animation_target_size_ = ClampToNearestIconCount(new_width, true); resize_animation_->Reset(); - resize_animation_->SetTweenType(SlideAnimation::EASE_OUT); + resize_animation_->SetTweenType(Tween::EASE_OUT); resize_animation_->Show(); } } diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h index ac263ef..a4334f3 100644 --- a/chrome/browser/views/browser_actions_container.h +++ b/chrome/browser/views/browser_actions_container.h @@ -428,7 +428,7 @@ class BrowserActionsContainer // Animate to the target value (unless testing, in which case we go straight // to the target size). - void Animate(SlideAnimation::TweenType tween_type, int target_size); + void Animate(Tween::Type type, int target_size); // Returns true if this extension should be shown in this toolbar. This can // return false if we are in an incognito window and the extension is disabled diff --git a/chrome/browser/views/download_item_view.cc b/chrome/browser/views/download_item_view.cc index 4ae499e..b38f4e7 100644 --- a/chrome/browser/views/download_item_view.cc +++ b/chrome/browser/views/download_item_view.cc @@ -359,7 +359,7 @@ void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { StopDownloadProgress(); complete_animation_.reset(new SlideAnimation(this)); complete_animation_->SetSlideDuration(kCompleteAnimationDurationMs); - complete_animation_->SetTweenType(SlideAnimation::NONE); + complete_animation_->SetTweenType(Tween::LINEAR); complete_animation_->Show(); if (status_text.empty()) show_status_text_ = false; @@ -655,7 +655,7 @@ void DownloadItemView::Paint(gfx::Canvas* canvas) { download_util::SMALL); } else if (download_->state() == DownloadItem::COMPLETE && complete_animation_.get() && - complete_animation_->IsAnimating()) { + complete_animation_->is_animating()) { download_util::PaintDownloadComplete(canvas, this, 0, 0, complete_animation_->GetCurrentValue(), download_util::SMALL); @@ -783,7 +783,7 @@ bool DownloadItemView::OnMousePressed(const views::MouseEvent& event) { return true; // Stop any completion animation. - if (complete_animation_.get() && complete_animation_->IsAnimating()) + if (complete_animation_.get() && complete_animation_->is_animating()) complete_animation_->End(); if (event.IsOnlyLeftMouseButton()) { diff --git a/chrome/browser/views/download_shelf_view.cc b/chrome/browser/views/download_shelf_view.cc index ff6346d..d727d43 100644 --- a/chrome/browser/views/download_shelf_view.cc +++ b/chrome/browser/views/download_shelf_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -165,7 +165,7 @@ gfx::Size DownloadShelfView::GetPreferredSize() { prefsize.Enlarge(kDownloadPadding, 0); } prefsize.Enlarge(0, kTopBottomPadding + kTopBottomPadding); - if (shelf_animation_->IsAnimating()) { + if (shelf_animation_->is_animating()) { prefsize.set_height(static_cast<int>( static_cast<double>(prefsize.height()) * shelf_animation_->GetCurrentValue())); @@ -252,7 +252,7 @@ void DownloadShelfView::Layout() { // Figure out width of item. int item_width = view_size.width(); - if (new_item_animation_->IsAnimating() && ri == download_views_.rbegin()) { + if (new_item_animation_->is_animating() && ri == download_views_.rbegin()) { item_width = static_cast<int>(static_cast<double>(view_size.width()) * new_item_animation_->GetCurrentValue()); } diff --git a/chrome/browser/views/download_started_animation_win.cc b/chrome/browser/views/download_started_animation_win.cc index 8f05c46..eb63f1c 100644 --- a/chrome/browser/views/download_started_animation_win.cc +++ b/chrome/browser/views/download_started_animation_win.cc @@ -4,7 +4,7 @@ #include "chrome/browser/download/download_started_animation.h" -#include "app/animation.h" +#include "app/linear_animation.h" #include "app/resource_bundle.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/notification_registrar.h" @@ -32,7 +32,7 @@ namespace { // provided on the constructor, while simultaneously fading it out. To use, // simply call "new DownloadStartAnimation"; the class cleans itself up when it // finishes animating. -class DownloadStartedAnimationWin : public Animation, +class DownloadStartedAnimationWin : public LinearAnimation, public NotificationObserver, public views::ImageView { public: @@ -74,7 +74,7 @@ class DownloadStartedAnimationWin : public Animation, DownloadStartedAnimationWin::DownloadStartedAnimationWin( TabContents* tab_contents) - : Animation(kMoveTimeMs, kFrameRateHz, NULL), + : LinearAnimation(kMoveTimeMs, kFrameRateHz, NULL), popup_(NULL), tab_contents_(tab_contents) { static SkBitmap* kDownloadImage = NULL; diff --git a/chrome/browser/views/dropdown_bar_host.cc b/chrome/browser/views/dropdown_bar_host.cc index e16074c..b722979 100644 --- a/chrome/browser/views/dropdown_bar_host.cc +++ b/chrome/browser/views/dropdown_bar_host.cc @@ -92,7 +92,7 @@ void DropdownBarHost::SetFocusAndSelection() { } bool DropdownBarHost::IsAnimating() const { - return animation_->IsAnimating(); + return animation_->is_animating(); } void DropdownBarHost::Hide(bool animate) { diff --git a/chrome/browser/views/extensions/extension_shelf.cc b/chrome/browser/views/extensions/extension_shelf.cc index 571e21d..e06b494 100644 --- a/chrome/browser/views/extensions/extension_shelf.cc +++ b/chrome/browser/views/extensions/extension_shelf.cc @@ -434,7 +434,7 @@ void ExtensionShelf::Toolstrip::LayoutWindow() { } gfx::Size window_size = GetPreferredSize(); - if (mole_animation_->IsAnimating()) { + if (mole_animation_->is_animating()) { // We only want to animate the body of the mole window. When we're // expanding, this is everything except for the handle. When we're // collapsing, this is everything except for the handle and the toolstrip. @@ -455,7 +455,7 @@ void ExtensionShelf::Toolstrip::LayoutWindow() { // Now figure out where to place the window on the screen. Since it's a top- // level widget, we need to do some coordinate conversion to get this right. gfx::Point origin(-kToolstripPadding, 0); - if (expanded_ || mole_animation_->IsAnimating()) { + if (expanded_ || mole_animation_->is_animating()) { origin.set_y(GetShelfView()->height() - window_size.height()); views::View::ConvertPointToView(GetShelfView(), shelf_->GetRootView(), &origin); @@ -665,7 +665,7 @@ void ExtensionShelf::Toolstrip::ShowShelfHandle() { void ExtensionShelf::Toolstrip::HideShelfHandle(int delay_ms) { StopHandleTimer(); - if (!handle_visible() || dragging_ || mole_animation_->IsAnimating()) + if (!handle_visible() || dragging_ || mole_animation_->is_animating()) return; if (delay_ms) { MessageLoop::current()->PostDelayedTask(FROM_HERE, diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 203b921..ade9dc0 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -890,10 +890,7 @@ bool BrowserView::IsBookmarkBarVisible() const { } bool BrowserView::IsBookmarkBarAnimating() const { - if (bookmark_bar_view_.get() && - bookmark_bar_view_->IsAnimating()) - return true; - return false; + return bookmark_bar_view_.get() && bookmark_bar_view_->is_animating(); } bool BrowserView::IsToolbarVisible() const { diff --git a/chrome/browser/views/infobars/infobars.cc b/chrome/browser/views/infobars/infobars.cc index dd4354e..ead3d97 100644 --- a/chrome/browser/views/infobars/infobars.cc +++ b/chrome/browser/views/infobars/infobars.cc @@ -136,7 +136,7 @@ InfoBar::InfoBar(InfoBarDelegate* delegate) AddChildView(close_button_); animation_.reset(new SlideAnimation(this)); - animation_->SetTweenType(SlideAnimation::NONE); + animation_->SetTweenType(Tween::LINEAR); } InfoBar::~InfoBar() { diff --git a/chrome/browser/views/infobars/translate_infobars.cc b/chrome/browser/views/infobars/translate_infobars.cc index 3bebe90..7cc9f11 100644 --- a/chrome/browser/views/infobars/translate_infobars.cc +++ b/chrome/browser/views/infobars/translate_infobars.cc @@ -261,7 +261,7 @@ TranslateInfoBar::TranslateInfoBar(TranslateInfoBarDelegate* delegate) // Initialize slide animation for transitioning to and from error state. error_animation_.reset(new SlideAnimation(this)); - error_animation_->SetTweenType(SlideAnimation::NONE); + error_animation_->SetTweenType(Tween::LINEAR); error_animation_->SetSlideDuration(500); // Initialize icon. @@ -564,7 +564,7 @@ void TranslateInfoBar::Layout() { void TranslateInfoBar::PaintBackground(gfx::Canvas* canvas) { // If we're not animating, simply paint background for current state. - if (!error_animation_->IsAnimating()) { + if (!error_animation_->is_animating()) { GetBackground(state_)->Paint(canvas, this); return; } diff --git a/chrome/browser/views/status_bubble_views.cc b/chrome/browser/views/status_bubble_views.cc index ff874f2..a44ef96 100644 --- a/chrome/browser/views/status_bubble_views.cc +++ b/chrome/browser/views/status_bubble_views.cc @@ -6,7 +6,7 @@ #include <algorithm> -#include "app/animation.h" +#include "app/linear_animation.h" #include "app/l10n_util.h" #include "app/resource_bundle.h" #include "app/text_elider.h" @@ -68,12 +68,12 @@ static const int kMaxExpansionStepDurationMS = 150; // StatusView manages the display of the bubble, applying text changes and // fading in or out the bubble as required. class StatusBubbleViews::StatusView : public views::Label, - public Animation, + public LinearAnimation, public AnimationDelegate { public: StatusView(StatusBubble* status_bubble, views::Widget* popup, ThemeProvider* theme_provider) - : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(kFramerate, this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(kFramerate, this)), stage_(BUBBLE_HIDDEN), style_(STYLE_STANDARD), ALLOW_THIS_IN_INITIALIZER_LIST(timer_factory_(this)), @@ -310,7 +310,7 @@ void StatusBubbleViews::StatusView::StartShowing() { // Animation functions. double StatusBubbleViews::StatusView::GetCurrentOpacity() { return opacity_start_ + (opacity_end_ - opacity_start_) * - Animation::GetCurrentValue(); + LinearAnimation::GetCurrentValue(); } void StatusBubbleViews::StatusView::SetOpacity(double opacity) { @@ -465,12 +465,12 @@ void StatusBubbleViews::StatusView::Paint(gfx::Canvas* canvas) { // Manages the expansion and contraction of the status bubble as it accommodates // URLs too long to fit in the standard bubble. Changes are passed through the // StatusView to paint. -class StatusBubbleViews::StatusViewExpander : public Animation, +class StatusBubbleViews::StatusViewExpander : public LinearAnimation, public AnimationDelegate { public: StatusViewExpander(StatusBubble* status_bubble, StatusView* status_view) - : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(kFramerate, this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(kFramerate, this)), status_bubble_(status_bubble), status_view_(status_view), expansion_start_(0), @@ -530,7 +530,7 @@ void StatusBubbleViews::StatusViewExpander::StartExpansion( int StatusBubbleViews::StatusViewExpander::GetCurrentBubbleWidth() { return static_cast<int>(expansion_start_ + - (expansion_end_ - expansion_start_) * Animation::GetCurrentValue()); + (expansion_end_ - expansion_start_) * LinearAnimation::GetCurrentValue()); } void StatusBubbleViews::StatusViewExpander::SetBubbleWidth(int width) { diff --git a/chrome/browser/views/tabs/dragged_tab_view.cc b/chrome/browser/views/tabs/dragged_tab_view.cc index 6b9306e..adf9a2b 100644 --- a/chrome/browser/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/views/tabs/dragged_tab_view.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -71,7 +71,7 @@ DraggedTabView::DraggedTabView(TabContents* datasource, } DraggedTabView::~DraggedTabView() { - if (close_animation_.IsAnimating()) + if (close_animation_.is_animating()) close_animation_.Stop(); GetParent()->RemoveChildView(this); container_->CloseNow(); @@ -154,7 +154,7 @@ void DraggedTabView::AnimateToBounds(const gfx::Rect& bounds, animation_end_bounds_ = bounds; close_animation_.SetSlideDuration(kAnimateToBoundsDurationMs); - close_animation_.SetTweenType(SlideAnimation::EASE_OUT); + close_animation_.SetTweenType(Tween::EASE_OUT); if (!close_animation_.IsShowing()) { close_animation_.Reset(); close_animation_.Show(); diff --git a/chrome/browser/views/tabs/side_tab.cc b/chrome/browser/views/tabs/side_tab.cc index dfa18e1..54795fb 100644 --- a/chrome/browser/views/tabs/side_tab.cc +++ b/chrome/browser/views/tabs/side_tab.cc @@ -165,7 +165,7 @@ void SideTab::Paint(gfx::Canvas* canvas) { SkPaint paint; SkAlpha opacity = kBackgroundTabAlpha; - if (hover_animation_->IsAnimating()) + if (hover_animation_->is_animating()) opacity = static_cast<SkAlpha>(hover_animation_->GetCurrentValue() * 255); paint.setColor(SkColorSetARGB(kBackgroundTabAlpha, 255, 255, 255)); @@ -181,12 +181,12 @@ gfx::Size SideTab::GetPreferredSize() { } void SideTab::OnMouseEntered(const views::MouseEvent& event) { - hover_animation_->SetTweenType(SlideAnimation::EASE_OUT); + hover_animation_->SetTweenType(Tween::EASE_OUT); hover_animation_->Show(); } void SideTab::OnMouseExited(const views::MouseEvent& event) { - hover_animation_->SetTweenType(SlideAnimation::EASE_IN); + hover_animation_->SetTweenType(Tween::EASE_IN); hover_animation_->Hide(); } diff --git a/chrome/browser/views/tabs/tab_renderer.cc b/chrome/browser/views/tabs/tab_renderer.cc index 8b5a1d8..13aeff9 100644 --- a/chrome/browser/views/tabs/tab_renderer.cc +++ b/chrome/browser/views/tabs/tab_renderer.cc @@ -222,11 +222,11 @@ class TabCloseButton : public views::ImageButton { // FaviconCrashAnimation // // A custom animation subclass to manage the favicon crash animation. -class TabRenderer::FavIconCrashAnimation : public Animation, +class TabRenderer::FavIconCrashAnimation : public LinearAnimation, public AnimationDelegate { public: explicit FavIconCrashAnimation(TabRenderer* target) - : ALLOW_THIS_IN_INITIALIZER_LIST(Animation(1000, 25, this)), + : ALLOW_THIS_IN_INITIALIZER_LIST(LinearAnimation(1000, 25, this)), target_(target) { } virtual ~FavIconCrashAnimation() {} @@ -394,8 +394,7 @@ void TabRenderer::StartPulse() { } void TabRenderer::StopPulse() { - if (pulse_animation_->IsAnimating()) - pulse_animation_->Stop(); + pulse_animation_->Stop(); } void TabRenderer::StartMiniTabTitleAnimation() { @@ -404,7 +403,7 @@ void TabRenderer::StartMiniTabTitleAnimation() { mini_title_animation_->SetThrobDuration(kMiniTitleChangeThrobDuration); } - if (!mini_title_animation_->IsAnimating()) { + if (!mini_title_animation_->is_animating()) { mini_title_animation_->StartThrobbing(2); } else if (mini_title_animation_->cycles_remaining() <= 2) { // The title changed while we're already animating. Add at most one more @@ -449,7 +448,7 @@ void TabRenderer::PaintIcon(gfx::Canvas* canvas) { // effect separately. int size = data_.favicon.width(); if (mini() && mini_title_animation_.get() && - mini_title_animation_->IsAnimating()) { + mini_title_animation_->is_animating()) { int throb_size = mini_title_animation_->CurrentValueBetween( size, kMiniTitleChangeMaxFaviconSize); x -= (throb_size - size) / 2; @@ -507,12 +506,12 @@ std::wstring TabRenderer::GetTitle() const { } void TabRenderer::OnMouseEntered(const views::MouseEvent& e) { - hover_animation_->SetTweenType(SlideAnimation::EASE_OUT); + hover_animation_->SetTweenType(Tween::EASE_OUT); hover_animation_->Show(); } void TabRenderer::OnMouseExited(const views::MouseEvent& e) { - hover_animation_->SetTweenType(SlideAnimation::EASE_IN); + hover_animation_->SetTweenType(Tween::EASE_IN); hover_animation_->Hide(); } @@ -930,7 +929,7 @@ double TabRenderer::GetThrobValue() { if (data_.alpha != 1) return data_.alpha; - if (pulse_animation_->IsAnimating()) + if (pulse_animation_->is_animating()) return pulse_animation_->GetCurrentValue() * kHoverOpacity; return hover_animation_.get() ? @@ -954,7 +953,7 @@ void TabRenderer::StopCrashAnimation() { } bool TabRenderer::IsPerformingCrashAnimation() const { - return crash_animation_ && crash_animation_->IsAnimating(); + return crash_animation_ && crash_animation_->is_animating(); } void TabRenderer::SetFavIconHidingOffset(int offset) { diff --git a/chrome/browser/views/tabs/tab_strip.cc b/chrome/browser/views/tabs/tab_strip.cc index a6e11d3..ced65ab 100644 --- a/chrome/browser/views/tabs/tab_strip.cc +++ b/chrome/browser/views/tabs/tab_strip.cc @@ -1529,7 +1529,7 @@ void TabStrip::NewTabAnimation2Done() { SlideAnimation* animation = new SlideAnimation(NULL); animation->SetSlideDuration(kNewTab3DurationMs); - animation->SetTweenType(SlideAnimation::EASE_IN_OUT); + animation->SetTweenType(Tween::EASE_IN_OUT); // BoundsAnimator takes ownership of animation. bounds_animator_.SetAnimationForView(tab_data_.back().tab, animation); diff --git a/views/animation/bounds_animator.cc b/views/animation/bounds_animator.cc index 40cae9c..6a16af5 100644 --- a/views/animation/bounds_animator.cc +++ b/views/animation/bounds_animator.cc @@ -126,7 +126,7 @@ SlideAnimation* BoundsAnimator::CreateAnimation() { SlideAnimation* animation = new SlideAnimation(this); animation->SetContainer(container_.get()); animation->SetSlideDuration(kAnimationDuration); - animation->SetTweenType(SlideAnimation::EASE_OUT); + animation->SetTweenType(Tween::EASE_OUT); return animation; } diff --git a/views/controls/button/custom_button.cc b/views/controls/button/custom_button.cc index ffa5a46..534c8a4 100644 --- a/views/controls/button/custom_button.cc +++ b/views/controls/button/custom_button.cc @@ -20,7 +20,7 @@ CustomButton::~CustomButton() { void CustomButton::SetState(ButtonState state) { if (state != state_) { - if (animate_on_state_change_ || !hover_animation_->IsAnimating()) { + if (animate_on_state_change_ || !hover_animation_->is_animating()) { animate_on_state_change_ = true; if (state_ == BS_NORMAL && state == BS_HOT) { // Button is hovered from a normal state, start hover animation. diff --git a/views/controls/button/image_button.cc b/views/controls/button/image_button.cc index 245942a..0565fae 100644 --- a/views/controls/button/image_button.cc +++ b/views/controls/button/image_button.cc @@ -93,7 +93,7 @@ void ImageButton::Paint(gfx::Canvas* canvas) { SkBitmap ImageButton::GetImageToPaint() { SkBitmap img; - if (!images_[BS_HOT].isNull() && hover_animation_->IsAnimating()) { + if (!images_[BS_HOT].isNull() && hover_animation_->is_animating()) { img = SkBitmapOperations::CreateBlendedBitmap(images_[BS_NORMAL], images_[BS_HOT], hover_animation_->GetCurrentValue()); } else { diff --git a/views/controls/button/text_button.cc b/views/controls/button/text_button.cc index 6435be1..40d4d68 100644 --- a/views/controls/button/text_button.cc +++ b/views/controls/button/text_button.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -241,7 +241,7 @@ void TextButton::Paint(gfx::Canvas* canvas, bool for_drag) { if (!for_drag) { PaintBackground(canvas); - if (show_highlighted_ && hover_animation_->IsAnimating()) { + if (show_highlighted_ && hover_animation_->is_animating()) { // Draw the hover bitmap into an offscreen buffer, then blend it // back into the current canvas. canvas->saveLayerAlpha(NULL, |