OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 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 | 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 "cc/scrollbar_animation_controller_linear_fade.h" | 5 #include "cc/scrollbar_animation_controller_linear_fade.h" |
6 | 6 |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "cc/layer_impl.h" | 8 #include "cc/layer_impl.h" |
9 | 9 |
10 namespace cc { | 10 namespace cc { |
(...skipping 10 matching lines...) Expand all Loading... |
21 , m_fadeoutDelay(fadeoutDelay) | 21 , m_fadeoutDelay(fadeoutDelay) |
22 , m_fadeoutLength(fadeoutLength) | 22 , m_fadeoutLength(fadeoutLength) |
23 , m_currentTimeForTesting(0) | 23 , m_currentTimeForTesting(0) |
24 { | 24 { |
25 } | 25 } |
26 | 26 |
27 ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade(
) | 27 ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade(
) |
28 { | 28 { |
29 } | 29 } |
30 | 30 |
| 31 double ScrollbarAnimationControllerLinearFade::secondsBeforeStart(base::TimeTick
s now) const |
| 32 { |
| 33 if (m_lastAwakenTime.is_null()) |
| 34 return -1; |
| 35 |
| 36 double delta = (now - m_lastAwakenTime).InSecondsF(); |
| 37 return std::max(0.0, m_fadeoutDelay - delta); |
| 38 } |
| 39 |
31 bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now) | 40 bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now) |
32 { | 41 { |
33 float opacity = opacityAtTime(now); | 42 float opacity = opacityAtTime(now); |
34 m_scrollLayer->SetScrollbarOpacity(opacity); | 43 m_scrollLayer->SetScrollbarOpacity(opacity); |
35 return opacity; | 44 if (!opacity) |
| 45 m_lastAwakenTime = base::TimeTicks(); |
| 46 return secondsBeforeStart(now) == 0; |
36 } | 47 } |
37 | 48 |
38 void ScrollbarAnimationControllerLinearFade::didPinchGestureUpdate(base::TimeTic
ks now) | 49 void ScrollbarAnimationControllerLinearFade::didPinchGestureUpdate(base::TimeTic
ks now) |
39 { | 50 { |
40 m_pinchGestureInEffect = true; | |
41 } | |
42 | |
43 void ScrollbarAnimationControllerLinearFade::didPinchGestureEnd(base::TimeTicks
now) | |
44 { | |
45 m_pinchGestureInEffect = false; | |
46 m_lastAwakenTime = now; | 51 m_lastAwakenTime = now; |
| 52 m_scrollLayer->SetScrollbarOpacity(1); |
47 } | 53 } |
48 | 54 |
49 void ScrollbarAnimationControllerLinearFade::didUpdateScrollOffset(base::TimeTic
ks now) | 55 void ScrollbarAnimationControllerLinearFade::didUpdateScrollOffset(base::TimeTic
ks now) |
50 { | 56 { |
51 m_lastAwakenTime = now; | 57 m_lastAwakenTime = now; |
| 58 m_scrollLayer->SetScrollbarOpacity(1); |
52 } | 59 } |
53 | 60 |
54 float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now) | 61 float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now) |
55 { | 62 { |
56 if (m_pinchGestureInEffect) | |
57 return 1; | |
58 | |
59 if (m_lastAwakenTime.is_null()) | 63 if (m_lastAwakenTime.is_null()) |
60 return 0; | 64 return 0; |
61 | 65 |
62 double delta = (now - m_lastAwakenTime).InSecondsF(); | 66 double delta = (now - m_lastAwakenTime).InSecondsF(); |
63 | 67 |
64 if (delta <= m_fadeoutDelay) | 68 if (delta <= m_fadeoutDelay) |
65 return 1; | 69 return 1; |
66 if (delta < m_fadeoutDelay + m_fadeoutLength) | 70 if (delta < m_fadeoutDelay + m_fadeoutLength) |
67 return (m_fadeoutDelay + m_fadeoutLength - delta) / m_fadeoutLength; | 71 return (m_fadeoutDelay + m_fadeoutLength - delta) / m_fadeoutLength; |
68 return 0; | 72 return 0; |
69 } | 73 } |
70 | 74 |
71 } // namespace cc | 75 } // namespace cc |
OLD | NEW |