OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/base/animation/multi_animation.h" | 5 #include "ui/base/animation/multi_animation.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/base/animation/animation_delegate.h" | 8 #include "ui/base/animation/animation_delegate.h" |
9 | 9 |
10 namespace ui { | 10 namespace ui { |
11 | 11 |
12 // Default interval, in ms. | 12 // Default interval, in ms. |
13 static const int kDefaultInterval = 20; | 13 static const int kDefaultInterval = 20; |
14 | 14 |
15 static int TotalTime(const MultiAnimation::Parts& parts) { | 15 static int TotalTime(const MultiAnimation::Parts& parts) { |
16 int time_ms = 0; | 16 int time_ms = 0; |
17 for (size_t i = 0; i < parts.size(); ++i) { | 17 for (size_t i = 0; i < parts.size(); ++i) { |
18 DCHECK(parts[i].end_time_ms - parts[i].start_time_ms >= parts[i].time_ms); | 18 DCHECK(parts[i].end_time_ms - parts[i].start_time_ms >= parts[i].time_ms); |
19 time_ms += parts[i].time_ms; | 19 time_ms += parts[i].time_ms; |
20 } | 20 } |
21 return time_ms; | 21 return time_ms; |
22 } | 22 } |
23 | 23 |
24 MultiAnimation::MultiAnimation(const Parts& parts) | 24 MultiAnimation::MultiAnimation(const Parts& parts, |
25 : Animation(base::TimeDelta::FromMilliseconds(kDefaultInterval)), | 25 base::TimeDelta timer_interval) |
26 : Animation(timer_interval), | |
26 parts_(parts), | 27 parts_(parts), |
27 cycle_time_ms_(TotalTime(parts)), | 28 cycle_time_ms_(TotalTime(parts)), |
28 current_value_(0), | 29 current_value_(0), |
29 current_part_index_(0), | 30 current_part_index_(0), |
30 continuous_(true) { | 31 continuous_(true) { |
31 DCHECK(!parts_.empty()); | 32 DCHECK(!parts_.empty()); |
32 } | 33 } |
33 | 34 |
34 MultiAnimation::~MultiAnimation() {} | 35 MultiAnimation::~MultiAnimation() {} |
35 | 36 |
37 // static. | |
38 base::TimeDelta MultiAnimation::GetDefaultTimerInterval() { | |
39 return base::TimeDelta::FromMilliseconds(kDefaultTimerInterval); | |
sky
2012/10/25 23:14:31
kDefaultInterval
| |
40 } | |
41 | |
36 double MultiAnimation::GetCurrentValue() const { | 42 double MultiAnimation::GetCurrentValue() const { |
37 return current_value_; | 43 return current_value_; |
38 } | 44 } |
39 | 45 |
40 void MultiAnimation::Step(base::TimeTicks time_now) { | 46 void MultiAnimation::Step(base::TimeTicks time_now) { |
41 double last_value = current_value_; | 47 double last_value = current_value_; |
42 size_t last_index = current_part_index_; | 48 size_t last_index = current_part_index_; |
43 | 49 |
44 int delta = static_cast<int>((time_now - start_time()).InMilliseconds()); | 50 int delta = static_cast<int>((time_now - start_time()).InMilliseconds()); |
45 if (delta >= cycle_time_ms_ && !continuous_) { | 51 if (delta >= cycle_time_ms_ && !continuous_) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 | 85 |
80 *time_ms -= parts_[i].time_ms; | 86 *time_ms -= parts_[i].time_ms; |
81 } | 87 } |
82 NOTREACHED(); | 88 NOTREACHED(); |
83 *time_ms = 0; | 89 *time_ms = 0; |
84 *part_index = 0; | 90 *part_index = 0; |
85 return parts_[0]; | 91 return parts_[0]; |
86 } | 92 } |
87 | 93 |
88 } // namespace ui | 94 } // namespace ui |
OLD | NEW |