diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 20:02:18 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-05 20:02:18 +0000 |
commit | d40c8492826ae9ac77b12c2cff7fbceb2075a772 (patch) | |
tree | a4ec160749f7f644654e9cb9165e8a1283b4574a /app/multi_animation.cc | |
parent | 379f172c0f5573f49b03a72a22f917f3c2d3caae (diff) | |
download | chromium_src-d40c8492826ae9ac77b12c2cff7fbceb2075a772.zip chromium_src-d40c8492826ae9ac77b12c2cff7fbceb2075a772.tar.gz chromium_src-d40c8492826ae9ac77b12c2cff7fbceb2075a772.tar.bz2 |
Changes the mini tab title animation.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/1902005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/multi_animation.cc')
-rw-r--r-- | app/multi_animation.cc | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/app/multi_animation.cc b/app/multi_animation.cc new file mode 100644 index 0000000..703ed85 --- /dev/null +++ b/app/multi_animation.cc @@ -0,0 +1,59 @@ +// 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" + +// 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) + 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) { + DCHECK(!parts_.empty()); +} + +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() % + cycle_time_ms_); + const Part& part = GetPart(&delta, ¤t_part_index_); + double percent = static_cast<double>(delta) / + static_cast<double>(part.time_ms); + current_value_ = Tween::CalculateValue(part.type, percent); + + if ((current_value_ != last_value || current_part_index_ != last_index) && + delegate()) { + delegate()->AnimationProgressed(this); + } +} + +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]; +} |