Update expectations according to build bot status.
[chromium-blink-merge.git] / app / multi_animation.cc
blob703ed85d8076c9b5fb1ba9631ef60c130e11c771
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "app/multi_animation.h"
7 // Default interval, in ms.
8 static const int kDefaultInterval = 20;
10 static int TotalTime(const MultiAnimation::Parts& parts) {
11 int time_ms = 0;
12 for (size_t i = 0; i < parts.size(); ++i)
13 time_ms += parts[i].time_ms;
14 return time_ms;
17 MultiAnimation::MultiAnimation(const Parts& parts)
18 : Animation(base::TimeDelta::FromMilliseconds(kDefaultInterval)),
19 parts_(parts),
20 cycle_time_ms_(TotalTime(parts)),
21 current_value_(0),
22 current_part_index_(0) {
23 DCHECK(!parts_.empty());
26 void MultiAnimation::Step(base::TimeTicks time_now) {
27 double last_value = current_value_;
28 size_t last_index = current_part_index_;
30 int delta = static_cast<int>((time_now - start_time()).InMilliseconds() %
31 cycle_time_ms_);
32 const Part& part = GetPart(&delta, &current_part_index_);
33 double percent = static_cast<double>(delta) /
34 static_cast<double>(part.time_ms);
35 current_value_ = Tween::CalculateValue(part.type, percent);
37 if ((current_value_ != last_value || current_part_index_ != last_index) &&
38 delegate()) {
39 delegate()->AnimationProgressed(this);
43 const MultiAnimation::Part& MultiAnimation::GetPart(int* time_ms,
44 size_t* part_index) {
45 DCHECK(*time_ms < cycle_time_ms_);
47 for (size_t i = 0; i < parts_.size(); ++i) {
48 if (*time_ms < parts_[i].time_ms) {
49 *part_index = i;
50 return parts_[i];
53 *time_ms -= parts_[i].time_ms;
55 NOTREACHED();
56 *time_ms = 0;
57 *part_index = 0;
58 return parts_[0];