summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-07 17:33:39 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-07 17:33:39 +0000
commitf676780687464428e340d008a0d1ca13d9944628 (patch)
tree489e8bd8188e31a7f6c53f15e8d1d9c6ba36d023 /app
parent3b65bfd55c56cf8a6db025087d937494f49dc15f (diff)
downloadchromium_src-f676780687464428e340d008a0d1ca13d9944628.zip
chromium_src-f676780687464428e340d008a0d1ca13d9944628.tar.gz
chromium_src-f676780687464428e340d008a0d1ca13d9944628.tar.bz2
Move animation code to new ui/base/animation directory.
BUG=none TEST=none TBR=brettw Review URL: http://codereview.chromium.org/6154001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70743 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r--app/animation.cc120
-rw-r--r--app/animation_container.cc100
-rw-r--r--app/animation_container_unittest.cc122
-rw-r--r--app/animation_unittest.cc142
-rw-r--r--app/app.gyp4
-rw-r--r--app/app_base.gypi16
-rw-r--r--app/linear_animation.cc92
-rw-r--r--app/multi_animation.cc84
-rw-r--r--app/multi_animation_unittest.cc89
-rw-r--r--app/slide_animation.cc110
-rw-r--r--app/slide_animation_unittest.cc30
-rw-r--r--app/throb_animation.cc77
-rw-r--r--app/tween.cc82
13 files changed, 0 insertions, 1068 deletions
diff --git a/app/animation.cc b/app/animation.cc
deleted file mode 100644
index ff20117..0000000
--- a/app/animation.cc
+++ /dev/null
@@ -1,120 +0,0 @@
-// 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/animation.h"
-
-#include "app/animation_container.h"
-#include "app/animation_delegate.h"
-#include "app/tween.h"
-#include "gfx/rect.h"
-
-#if defined(OS_WIN)
-#include "base/win/windows_version.h"
-#endif
-
-Animation::Animation(base::TimeDelta timer_interval)
- : timer_interval_(timer_interval),
- is_animating_(false),
- delegate_(NULL) {
-}
-
-Animation::~Animation() {
- // 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);
-}
-
-void Animation::Start() {
- if (is_animating_)
- return;
-
- if (!container_.get())
- container_ = new AnimationContainer();
-
- is_animating_ = true;
-
- container_->Start(this);
-
- AnimationStarted();
-}
-
-void Animation::Stop() {
- if (!is_animating_)
- return;
-
- is_animating_ = false;
-
- // Notify the container first as the delegate may delete us.
- container_->Stop(this);
-
- AnimationStopped();
-
- if (delegate_) {
- if (ShouldSendCanceledFromStop())
- delegate_->AnimationCanceled(this);
- else
- delegate_->AnimationEnded(this);
- }
-}
-
-double Animation::CurrentValueBetween(double start, double target) const {
- return Tween::ValueBetween(GetCurrentValue(), start, target);
-}
-
-int Animation::CurrentValueBetween(int start, int target) const {
- return Tween::ValueBetween(GetCurrentValue(), start, target);
-}
-
-gfx::Rect Animation::CurrentValueBetween(const gfx::Rect& start_bounds,
- const gfx::Rect& target_bounds) const {
- return Tween::ValueBetween(GetCurrentValue(), start_bounds, target_bounds);
-}
-
-void Animation::SetContainer(AnimationContainer* container) {
- if (container == container_.get())
- return;
-
- if (is_animating_)
- container_->Stop(this);
-
- if (container)
- container_ = container;
- else
- container_ = new AnimationContainer();
-
- if (is_animating_)
- container_->Start(this);
-}
-
-// static
-bool Animation::ShouldRenderRichAnimation() {
-#if defined(OS_WIN)
- if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
- BOOL result;
- // Get "Turn off all unnecessary animations" value.
- if (::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)) {
- // There seems to be a typo in the MSDN document (as of May 2009):
- // http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx
- // The document states that the result is TRUE when animations are
- // _disabled_, but in fact, it is TRUE when they are _enabled_.
- return !!result;
- }
- }
- return !::GetSystemMetrics(SM_REMOTESESSION);
-#endif
- return true;
-}
-
-bool Animation::ShouldSendCanceledFromStop() {
- return false;
-}
-
-void Animation::SetStartTime(base::TimeTicks start_time) {
- start_time_ = start_time;
-}
-
-base::TimeDelta Animation::GetTimerInterval() const {
- return timer_interval_;
-}
diff --git a/app/animation_container.cc b/app/animation_container.cc
deleted file mode 100644
index cba3d4b..0000000
--- a/app/animation_container.cc
+++ /dev/null
@@ -1,100 +0,0 @@
-// 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/animation_container.h"
-
-#include "app/animation_container_element.h"
-#include "app/animation_container_observer.h"
-
-using base::TimeDelta;
-using base::TimeTicks;
-
-AnimationContainer::AnimationContainer()
- : last_tick_time_(TimeTicks::Now()),
- observer_(NULL) {
-}
-
-AnimationContainer::~AnimationContainer() {
- // The animations own us and stop themselves before being deleted. If
- // elements_ is not empty, something is wrong.
- DCHECK(elements_.empty());
-}
-
-void AnimationContainer::Start(AnimationContainerElement* element) {
- DCHECK(elements_.count(element) == 0); // Start should only be invoked if the
- // element isn't running.
-
- if (elements_.empty()) {
- last_tick_time_ = TimeTicks::Now();
- SetMinTimerInterval(element->GetTimerInterval());
- } else if (element->GetTimerInterval() < min_timer_interval_) {
- SetMinTimerInterval(element->GetTimerInterval());
- }
-
- element->SetStartTime(last_tick_time_);
- elements_.insert(element);
-}
-
-void AnimationContainer::Stop(AnimationContainerElement* element) {
- DCHECK(elements_.count(element) > 0); // The element must be running.
-
- elements_.erase(element);
-
- if (elements_.empty()) {
- timer_.Stop();
- if (observer_)
- observer_->AnimationContainerEmpty(this);
- } else {
- TimeDelta min_timer_interval = GetMinInterval();
- if (min_timer_interval > min_timer_interval_)
- SetMinTimerInterval(min_timer_interval);
- }
-}
-
-void AnimationContainer::Run() {
- // 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 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 (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);
- }
-
- if (observer_)
- observer_->AnimationContainerProgressed(this);
-}
-
-void AnimationContainer::SetMinTimerInterval(base::TimeDelta delta) {
- // 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(!elements_.empty());
-
- TimeDelta min;
- 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_unittest.cc b/app/animation_container_unittest.cc
deleted file mode 100644
index 5aa3be6..0000000
--- a/app/animation_container_unittest.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-// 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/animation_container.h"
-#include "app/animation_container_observer.h"
-#include "app/linear_animation.h"
-#include "app/test_animation_delegate.h"
-#include "base/scoped_ptr.h"
-#include "testing/gmock/include/gmock/gmock.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-using testing::AtLeast;
-
-namespace {
-
-class MockObserver : public AnimationContainerObserver {
- public:
- MockObserver() {}
-
- MOCK_METHOD1(AnimationContainerProgressed, void(AnimationContainer*));
- MOCK_METHOD1(AnimationContainerEmpty, void(AnimationContainer*));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockObserver);
-};
-
-class TestAnimation : public LinearAnimation {
- public:
- explicit TestAnimation(AnimationDelegate* delegate)
- : LinearAnimation(20, 20, delegate) {
- }
-
- virtual void AnimateToState(double state) {
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(TestAnimation);
-};
-
-} // namespace
-
-class AnimationContainerTest: public testing::Test {
- private:
- MessageLoopForUI message_loop_;
-};
-
-// Makes sure the animation ups the ref count of the container and releases it
-// appropriately.
-TEST_F(AnimationContainerTest, Ownership) {
- TestAnimationDelegate delegate;
- scoped_refptr<AnimationContainer> container(new AnimationContainer());
- scoped_ptr<Animation> animation(new TestAnimation(&delegate));
- animation->SetContainer(container.get());
- // Setting the container should up the ref count.
- EXPECT_FALSE(container->HasOneRef());
-
- animation.reset();
-
- // Releasing the animation should decrement the ref count.
- EXPECT_TRUE(container->HasOneRef());
-}
-
-// Makes sure multiple animations are managed correctly.
-TEST_F(AnimationContainerTest, Multi) {
- TestAnimationDelegate delegate1;
- TestAnimationDelegate delegate2;
-
- scoped_refptr<AnimationContainer> container(new AnimationContainer());
- TestAnimation animation1(&delegate1);
- TestAnimation animation2(&delegate2);
- animation1.SetContainer(container.get());
- animation2.SetContainer(container.get());
-
- // Start both animations.
- animation1.Start();
- EXPECT_TRUE(container->is_running());
- animation2.Start();
- EXPECT_TRUE(container->is_running());
-
- // Run the message loop the delegate quits the message loop when notified.
- MessageLoop::current()->Run();
-
- // Both timers should have finished.
- EXPECT_TRUE(delegate1.finished());
- EXPECT_TRUE(delegate2.finished());
-
- // And the container should no longer be runnings.
- EXPECT_FALSE(container->is_running());
-}
-
-// Makes sure observer is notified appropriately.
-TEST_F(AnimationContainerTest, Observer) {
- MockObserver observer;
- TestAnimationDelegate delegate1;
-
- scoped_refptr<AnimationContainer> container(new AnimationContainer());
- container->set_observer(&observer);
- TestAnimation animation1(&delegate1);
- animation1.SetContainer(container.get());
-
- // We expect to get these two calls: the animation progressed, and then when
- // the animation completed the container went empty.
- EXPECT_CALL(observer, AnimationContainerProgressed(container.get())).Times(
- AtLeast(1));
- EXPECT_CALL(observer, AnimationContainerEmpty(container.get())).Times(1);
-
- // Start the animation.
- animation1.Start();
- EXPECT_TRUE(container->is_running());
-
- // Run the message loop. The delegate quits the message loop when notified.
- MessageLoop::current()->Run();
-
- // The timer should have finished.
- EXPECT_TRUE(delegate1.finished());
-
- // And the container should no longer be running.
- EXPECT_FALSE(container->is_running());
-
- container->set_observer(NULL);
-}
diff --git a/app/animation_unittest.cc b/app/animation_unittest.cc
deleted file mode 100644
index a4ab2fe..0000000
--- a/app/animation_unittest.cc
+++ /dev/null
@@ -1,142 +0,0 @@
-// 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/animation_delegate.h"
-#include "app/linear_animation.h"
-#include "app/test_animation_delegate.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-#if defined(OS_WIN)
-#include "base/win/windows_version.h"
-#endif
-
-class AnimationTest: public testing::Test {
- private:
- MessageLoopForUI message_loop_;
-};
-
-namespace {
-
-///////////////////////////////////////////////////////////////////////////////
-// RunAnimation
-
-class RunAnimation : public LinearAnimation {
- public:
- RunAnimation(int frame_rate, AnimationDelegate* delegate)
- : LinearAnimation(frame_rate, delegate) {
- }
-
- virtual void AnimateToState(double state) {
- EXPECT_LE(0.0, state);
- EXPECT_GE(1.0, state);
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// CancelAnimation
-
-class CancelAnimation : public LinearAnimation {
- public:
- CancelAnimation(int duration, int frame_rate, AnimationDelegate* delegate)
- : LinearAnimation(duration, frame_rate, delegate) {
- }
-
- virtual void AnimateToState(double state) {
- if (state >= 0.5)
- Stop();
- }
-};
-
-///////////////////////////////////////////////////////////////////////////////
-// 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) {
- TestAnimationDelegate ad;
- RunAnimation a1(150, &ad);
- a1.SetDuration(2000);
- a1.Start();
- MessageLoop::current()->Run();
-
- EXPECT_TRUE(ad.finished());
- EXPECT_FALSE(ad.canceled());
-}
-
-TEST_F(AnimationTest, CancelCase) {
- TestAnimationDelegate ad;
- CancelAnimation a2(2000, 150, &ad);
- a2.Start();
- MessageLoop::current()->Run();
-
- EXPECT_TRUE(ad.finished());
- 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 (base::win::GetVersion() >= base::win::VERSION_VISTA) {
- BOOL result;
- ASSERT_NE(
- 0, ::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0));
- // ShouldRenderRichAnimation() should check the SPI_GETCLIENTAREAANIMATION
- // value on Vista.
- EXPECT_EQ(!!result, Animation::ShouldRenderRichAnimation());
- } else {
- // On XP, the function should check the SM_REMOTESESSION value.
- EXPECT_EQ(!::GetSystemMetrics(SM_REMOTESESSION),
- Animation::ShouldRenderRichAnimation());
- }
-#else
- EXPECT_TRUE(Animation::ShouldRenderRichAnimation());
-#endif
-}
diff --git a/app/app.gyp b/app/app.gyp
index bac326b..8bcc0e3 100644
--- a/app/app.gyp
+++ b/app/app.gyp
@@ -38,16 +38,12 @@
'<(libjpeg_gyp_path):libjpeg',
],
'sources': [
- 'animation_container_unittest.cc',
- 'animation_unittest.cc',
'clipboard/clipboard_unittest.cc',
'data_pack_unittest.cc',
'l10n_util_mac_unittest.mm',
'l10n_util_unittest.cc',
- 'multi_animation_unittest.cc',
'os_exchange_data_win_unittest.cc',
'run_all_unittests.cc',
- 'slide_animation_unittest.cc',
'sql/connection_unittest.cc',
'sql/statement_unittest.cc',
'sql/transaction_unittest.cc',
diff --git a/app/app_base.gypi b/app/app_base.gypi
index 6bcad0e..3f27573 100644
--- a/app/app_base.gypi
+++ b/app/app_base.gypi
@@ -91,12 +91,6 @@
# Files that are not required for Win64 Native Client loader
'active_window_watcher_x.cc',
'active_window_watcher_x.h',
- 'animation_container.cc',
- 'animation_container.h',
- 'animation_container_element.h',
- 'animation_container_observer.h',
- 'animation.cc',
- 'animation.h',
'bidi_line_iterator.cc',
'clipboard/clipboard.cc',
'clipboard/clipboard.h',
@@ -161,8 +155,6 @@
'l10n_util_posix.cc',
'l10n_util_win.cc',
'l10n_util_win.h',
- 'linear_animation.cc',
- 'linear_animation.h',
'mac/nsimage_cache.h',
'mac/nsimage_cache.mm',
'mac/scoped_nsdisable_screen_updates.h',
@@ -176,8 +168,6 @@
'menus/simple_menu_model.cc',
'menus/simple_menu_model.h',
'message_box_flags.h',
- 'multi_animation.cc',
- 'multi_animation.h',
'os_exchange_data_provider_gtk.cc',
'os_exchange_data_provider_gtk.h',
'os_exchange_data_provider_win.cc',
@@ -190,8 +180,6 @@
'resource_bundle_mac.mm',
'resource_bundle_posix.cc',
'resource_bundle_win.cc',
- 'slide_animation.cc',
- 'slide_animation.h',
'sql/connection.cc',
'sql/connection.h',
'sql/diagnostic_error_delegate.h',
@@ -217,10 +205,6 @@
'text_elider.h',
'theme_provider.cc',
'theme_provider.h',
- 'throb_animation.cc',
- 'throb_animation.h',
- 'tween.cc',
- 'tween.h',
'view_prop.cc',
'view_prop.h',
'win/drag_source.cc',
diff --git a/app/linear_animation.cc b/app/linear_animation.cc
deleted file mode 100644
index 5eb05dd..0000000
--- a/app/linear_animation.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// 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"
-#include "app/animation_delegate.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/multi_animation.cc b/app/multi_animation.cc
deleted file mode 100644
index f43470e..0000000
--- a/app/multi_animation.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// 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/multi_animation.h"
-
-#include "app/animation_delegate.h"
-#include "base/logging.h"
-
-// Default interval, in ms.
-static const int kDefaultInterval = 20;
-
-static int TotalTime(const MultiAnimation::Parts& parts) {
- int time_ms = 0;
- for (size_t i = 0; i < parts.size(); ++i) {
- DCHECK(parts[i].end_time_ms - parts[i].start_time_ms >= parts[i].time_ms);
- time_ms += parts[i].time_ms;
- }
- return time_ms;
-}
-
-MultiAnimation::MultiAnimation(const Parts& parts)
- : Animation(base::TimeDelta::FromMilliseconds(kDefaultInterval)),
- parts_(parts),
- cycle_time_ms_(TotalTime(parts)),
- current_value_(0),
- current_part_index_(0),
- continuous_(true) {
- DCHECK(!parts_.empty());
-}
-
-MultiAnimation::~MultiAnimation() {}
-
-double MultiAnimation::GetCurrentValue() const {
- return current_value_;
-}
-
-void MultiAnimation::Step(base::TimeTicks time_now) {
- double last_value = current_value_;
- size_t last_index = current_part_index_;
-
- int delta = static_cast<int>((time_now - start_time()).InMilliseconds());
- if (delta >= cycle_time_ms_ && !continuous_) {
- current_part_index_ = parts_.size() - 1;
- current_value_ = Tween::CalculateValue(parts_[current_part_index_].type, 1);
- Stop();
- return;
- }
- delta %= cycle_time_ms_;
- const Part& part = GetPart(&delta, &current_part_index_);
- double percent = static_cast<double>(delta + part.start_time_ms) /
- static_cast<double>(part.end_time_ms);
- DCHECK(percent <= 1);
- current_value_ = Tween::CalculateValue(part.type, percent);
-
- if ((current_value_ != last_value || current_part_index_ != last_index) &&
- delegate()) {
- delegate()->AnimationProgressed(this);
- }
-}
-
-void MultiAnimation::SetStartTime(base::TimeTicks start_time) {
- Animation::SetStartTime(start_time);
- current_value_ = 0;
- current_part_index_ = 0;
-}
-
-const MultiAnimation::Part& MultiAnimation::GetPart(int* time_ms,
- size_t* part_index) {
- DCHECK(*time_ms < cycle_time_ms_);
-
- for (size_t i = 0; i < parts_.size(); ++i) {
- if (*time_ms < parts_[i].time_ms) {
- *part_index = i;
- return parts_[i];
- }
-
- *time_ms -= parts_[i].time_ms;
- }
- NOTREACHED();
- *time_ms = 0;
- *part_index = 0;
- return parts_[0];
-}
diff --git a/app/multi_animation_unittest.cc b/app/multi_animation_unittest.cc
deleted file mode 100644
index 393b01c..0000000
--- a/app/multi_animation_unittest.cc
+++ /dev/null
@@ -1,89 +0,0 @@
-// 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/animation_container_element.h"
-#include "app/multi_animation.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-typedef testing::Test MultiAnimationTest;
-
-TEST_F(MultiAnimationTest, Basic) {
- // Create a MultiAnimation with two parts.
- MultiAnimation::Parts parts;
- parts.push_back(MultiAnimation::Part(100, Tween::LINEAR));
- parts.push_back(MultiAnimation::Part(100, Tween::EASE_OUT));
-
- MultiAnimation animation(parts);
- AnimationContainerElement* as_element =
- static_cast<AnimationContainerElement*>(&animation);
- as_element->SetStartTime(base::TimeTicks());
-
- // Step to 50, which is half way through the first part.
- as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(50));
- EXPECT_EQ(.5, animation.GetCurrentValue());
-
- // Step to 120, which is 20% through the second part.
- as_element->Step(base::TimeTicks() +
- base::TimeDelta::FromMilliseconds(120));
- EXPECT_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
- animation.GetCurrentValue());
-
- // Step to 320, which is 20% through the second part.
- as_element->Step(base::TimeTicks() +
- base::TimeDelta::FromMilliseconds(320));
- EXPECT_EQ(Tween::CalculateValue(Tween::EASE_OUT, .2),
- animation.GetCurrentValue());
-}
-
-TEST_F(MultiAnimationTest, DifferingStartAndEnd) {
- // Create a MultiAnimation with two parts.
- MultiAnimation::Parts parts;
- parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
- parts[0].start_time_ms = 100;
- parts[0].end_time_ms = 400;
-
- MultiAnimation animation(parts);
- AnimationContainerElement* as_element =
- static_cast<AnimationContainerElement*>(&animation);
- as_element->SetStartTime(base::TimeTicks());
-
- // Step to 0. Because the start_time is 100, this should be 100ms into the
- // animation
- as_element->Step(base::TimeTicks());
- EXPECT_EQ(.25, animation.GetCurrentValue());
-
- // Step to 100, which is effectively 200ms into the animation.
- as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(100));
- EXPECT_EQ(.5, animation.GetCurrentValue());
-}
-
-// Makes sure multi-animation stops if cycles is false.
-TEST_F(MultiAnimationTest, DontCycle) {
- MultiAnimation::Parts parts;
- parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
- MultiAnimation animation(parts);
- AnimationContainerElement* as_element =
- static_cast<AnimationContainerElement*>(&animation);
- as_element->SetStartTime(base::TimeTicks());
- animation.set_continuous(false);
-
- // Step to 300, which is greater than the cycle time.
- as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
- EXPECT_EQ(1.0, animation.GetCurrentValue());
- EXPECT_FALSE(animation.is_animating());
-}
-
-// Makes sure multi-animation cycles correctly.
-TEST_F(MultiAnimationTest, Cycle) {
- MultiAnimation::Parts parts;
- parts.push_back(MultiAnimation::Part(200, Tween::LINEAR));
- MultiAnimation animation(parts);
- AnimationContainerElement* as_element =
- static_cast<AnimationContainerElement*>(&animation);
- as_element->SetStartTime(base::TimeTicks());
-
- // Step to 300, which is greater than the cycle time.
- as_element->Step(base::TimeTicks() + base::TimeDelta::FromMilliseconds(300));
- EXPECT_EQ(.5, animation.GetCurrentValue());
-}
diff --git a/app/slide_animation.cc b/app/slide_animation.cc
deleted file mode 100644
index 9029fd8..0000000
--- a/app/slide_animation.cc
+++ /dev/null
@@ -1,110 +0,0 @@
-// 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/slide_animation.h"
-
-#include <math.h>
-
-// How many frames per second to target.
-static const int kDefaultFramerateHz = 50;
-
-// How long animations should take by default.
-static const int kDefaultDurationMs = 120;
-
-SlideAnimation::SlideAnimation(AnimationDelegate* target)
- : LinearAnimation(kDefaultFramerateHz, target),
- target_(target),
- tween_type_(Tween::EASE_OUT),
- showing_(false),
- value_start_(0),
- value_end_(0),
- value_current_(0),
- slide_duration_(kDefaultDurationMs) {
-}
-
-SlideAnimation::~SlideAnimation() {
-}
-
-void SlideAnimation::Reset() {
- Reset(0);
-}
-
-void SlideAnimation::Reset(double value) {
- Stop();
- showing_ = static_cast<bool>(value == 1);
- value_current_ = value;
-}
-
-void SlideAnimation::Show() {
- // If we're already showing (or fully shown), we have nothing to do.
- if (showing_)
- return;
-
- showing_ = true;
- value_start_ = value_current_;
- value_end_ = 1.0;
-
- // Make sure we actually have something to do.
- if (slide_duration_ == 0) {
- AnimateToState(1.0); // Skip to the end of the animation.
- return;
- } else if (value_current_ == value_end_) {
- return;
- }
-
- // This will also reset the currently-occuring animation.
- SetDuration(static_cast<int>(slide_duration_ * (1 - value_current_)));
- Start();
-}
-
-void SlideAnimation::Hide() {
- // If we're already hiding (or hidden), we have nothing to do.
- if (!showing_)
- return;
-
- showing_ = false;
- value_start_ = value_current_;
- value_end_ = 0.0;
-
- // Make sure we actually have something to do.
- if (slide_duration_ == 0) {
- AnimateToState(0.0); // Skip to the end of the animation.
- return;
- } else if (value_current_ == value_end_) {
- return;
- }
-
- // This will also reset the currently-occuring animation.
- SetDuration(static_cast<int>(slide_duration_ * value_current_));
- Start();
-}
-
-void SlideAnimation::SetSlideDuration(int duration) {
- slide_duration_ = duration;
-}
-
-double SlideAnimation::GetCurrentValue() const {
- return value_current_;
-}
-
-void SlideAnimation::AnimateToState(double state) {
- if (state > 1.0)
- state = 1.0;
-
- state = Tween::CalculateValue(tween_type_, state);
-
- value_current_ = value_start_ + (value_end_ - value_start_) * state;
-
- // Implement snapping.
- 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
- // take any rounding error chances.
- if ((value_end_ >= value_start_ && value_current_ > value_end_) ||
- (value_end_ < value_start_ && value_current_ < value_end_)) {
- value_current_ = value_end_;
- }
-}
diff --git a/app/slide_animation_unittest.cc b/app/slide_animation_unittest.cc
deleted file mode 100644
index d34b975..0000000
--- a/app/slide_animation_unittest.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// 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/slide_animation.h"
-#include "app/test_animation_delegate.h"
-#include "base/scoped_ptr.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-class SlideAnimationTest: public testing::Test {
- private:
- MessageLoopForUI message_loop_;
-};
-
-// Tests that delegate is not notified when animation is running and is deleted.
-// (Such a scenario would cause problems for BoundsAnimator).
-TEST_F(SlideAnimationTest, DontNotifyOnDelete) {
- TestAnimationDelegate delegate;
- scoped_ptr<SlideAnimation> animation(new SlideAnimation(&delegate));
-
- // Start the animation.
- animation->Show();
-
- // Delete the animation.
- animation.reset();
-
- // Make sure the delegate wasn't notified.
- EXPECT_FALSE(delegate.finished());
- EXPECT_FALSE(delegate.canceled());
-}
diff --git a/app/throb_animation.cc b/app/throb_animation.cc
deleted file mode 100644
index 9ce8f5b..0000000
--- a/app/throb_animation.cc
+++ /dev/null
@@ -1,77 +0,0 @@
-// 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/throb_animation.h"
-
-#include <limits>
-
-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_til_stop = cycles_til_stop >= 0 ? cycles_til_stop :
- std::numeric_limits<int>::max();
- cycles_remaining_ = cycles_til_stop;
- throbbing_ = true;
- SlideAnimation::SetSlideDuration(throb_duration_);
- if (is_animating())
- 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::SetSlideDuration(int duration) {
- slide_duration_ = duration;
-}
-
-void ThrobAnimation::Step(base::TimeTicks time_now) {
- LinearAnimation::Step(time_now);
-
- 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_--;
- 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;
-}
diff --git a/app/tween.cc b/app/tween.cc
deleted file mode 100644
index 610e01a..0000000
--- a/app/tween.cc
+++ /dev/null
@@ -1,82 +0,0 @@
-// 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 "base/logging.h"
-#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()));
-}