diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-19 20:46:07 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-19 20:46:07 +0000 |
commit | 7edf5b5462727c06c0232b541c5db549f176d84a (patch) | |
tree | 4a4ac06d13b40e52180ecd6a1fa7c9be977c14f3 /app | |
parent | 948ab987c4bdc1a63a54434276d68bc68b3a0e07 (diff) | |
download | chromium_src-7edf5b5462727c06c0232b541c5db549f176d84a.zip chromium_src-7edf5b5462727c06c0232b541c5db549f176d84a.tar.gz chromium_src-7edf5b5462727c06c0232b541c5db549f176d84a.tar.bz2 |
Tweaks the pinned background tab title change animation per Nicholas's
request.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/3041006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52949 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app')
-rw-r--r-- | app/multi_animation.cc | 9 | ||||
-rw-r--r-- | app/multi_animation.h | 21 | ||||
-rw-r--r-- | app/multi_animation_unittest.cc | 22 |
3 files changed, 47 insertions, 5 deletions
diff --git a/app/multi_animation.cc b/app/multi_animation.cc index 703ed85..14cd7f9 100644 --- a/app/multi_animation.cc +++ b/app/multi_animation.cc @@ -9,8 +9,10 @@ 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) + 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; } @@ -30,8 +32,9 @@ void MultiAnimation::Step(base::TimeTicks time_now) { int delta = static_cast<int>((time_now - start_time()).InMilliseconds() % cycle_time_ms_); const Part& part = GetPart(&delta, ¤t_part_index_); - double percent = static_cast<double>(delta) / - static_cast<double>(part.time_ms); + 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) && diff --git a/app/multi_animation.h b/app/multi_animation.h index ac0ab84..7c9ca6d 100644 --- a/app/multi_animation.h +++ b/app/multi_animation.h @@ -16,11 +16,28 @@ // invoked. class MultiAnimation : public Animation { public: + // Defines part of the animation. Each part consists of the following: + // + // time_ms: the time of the part. + // start_time_ms: the amount of time to offset this part by when calculating + // the percented completed. + // end_time_ms: the end time used to calculate the percentange completed. + // + // In most cases |start_time_ms| = 0 and |end_time_ms| = |time_ms|. But you + // can adjust the start/end for different effects. For example, to run a part + // for 200ms with a % between .25 and .75 use the following three values: 200, + // 100, 400. struct Part { - Part() : time_ms(0), type(Tween::ZERO) {} - Part(int time_ms, Tween::Type type) : time_ms(time_ms), type(type) {} + Part() : time_ms(0), start_time_ms(0), end_time_ms(0), type(Tween::ZERO) {} + Part(int time_ms, Tween::Type type) + : time_ms(time_ms), + start_time_ms(0), + end_time_ms(time_ms), + type(type) {} int time_ms; + int start_time_ms; + int end_time_ms; Tween::Type type; }; diff --git a/app/multi_animation_unittest.cc b/app/multi_animation_unittest.cc index c3990591..fbbf1b0 100644 --- a/app/multi_animation_unittest.cc +++ b/app/multi_animation_unittest.cc @@ -34,3 +34,25 @@ TEST_F(MultiAnimationTest, Basic) { 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); + AnimationContainer::Element* as_element = + static_cast<AnimationContainer::Element*>(&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()); +} |