OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2012 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. | |
4 | |
5 #include "cc/top_controls_animation.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "cc/timing_function.h" | |
9 | |
10 using base::TimeDelta; | |
11 using base::TimeTicks; | |
12 | |
13 namespace cc { | |
14 | |
15 scoped_ptr<TopControlsAnimation> TopControlsAnimation::create( | |
16 float startScrollOffset, | |
17 float topControlsHeight, | |
18 TimeTicks startTime, | |
19 TimeDelta maxDuration) { | |
20 return make_scoped_ptr(new TopControlsAnimation( | |
21 startScrollOffset, topControlsHeight, startTime, maxDuration)); | |
22 } | |
23 | |
24 TopControlsAnimation::TopControlsAnimation(float startScrollOffset, | |
25 float topControlsHeight, | |
26 TimeTicks startTime, | |
27 TimeDelta maxDuration) | |
28 : start_scroll_offset_(startScrollOffset), | |
29 top_controls_height_(topControlsHeight), | |
30 direction_(1), | |
31 start_time_(startTime), | |
32 max_duration_(maxDuration) { | |
33 timing_function_ = EaseTimingFunction::create(); | |
34 } | |
35 | |
36 TopControlsAnimation::~TopControlsAnimation() { | |
37 } | |
38 | |
39 void TopControlsAnimation::setDirection(bool showing) { | |
40 direction_ = showing ? 1 : -1; | |
41 } | |
42 | |
43 float TopControlsAnimation::scrollOffsetAtTime(TimeTicks time) const { | |
44 TimeDelta elapsed_time = time - start_time_; | |
45 float offsetDelta = timing_function_->getValue( | |
46 elapsed_time.InSecondsF() / max_duration_.InSecondsF()) | |
47 * direction_ * top_controls_height_; | |
48 return start_scroll_offset_ + offsetDelta; | |
49 } | |
50 | |
51 bool TopControlsAnimation::isAnimationCompleteAtTime(TimeTicks time) const { | |
52 float scrollOffset = scrollOffsetAtTime(time); | |
53 if (direction_ == 1) | |
54 return scrollOffset >= 0; | |
55 else | |
56 return scrollOffset <= -top_controls_height_; | |
aelias_OOO_until_Jul13
2012/12/19 08:31:18
It would be simpler to just compare max_duration_
Ted C
2012/12/19 21:34:17
I'd prefer to keep it comparing against expected h
| |
57 } | |
58 | |
59 } // namespace cc | |
OLD | NEW |