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
) {
12 for (size_t i
= 0; i
< parts
.size(); ++i
)
13 time_ms
+= parts
[i
].time_ms
;
17 MultiAnimation::MultiAnimation(const Parts
& parts
)
18 : Animation(base::TimeDelta::FromMilliseconds(kDefaultInterval
)),
20 cycle_time_ms_(TotalTime(parts
)),
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() %
32 const Part
& part
= GetPart(&delta
, ¤t_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
) &&
39 delegate()->AnimationProgressed(this);
43 const MultiAnimation::Part
& MultiAnimation::GetPart(int* time_ms
,
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
) {
53 *time_ms
-= parts_
[i
].time_ms
;