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 { |
11 | 11 |
12 scoped_ptr<ScrollbarAnimationControllerLinearFade> ScrollbarAnimationControllerL
inearFade::create(LayerImpl* scrollLayer, double fadeoutDelay, double fadeoutLen
gth) | 12 scoped_ptr<ScrollbarAnimationControllerLinearFade> ScrollbarAnimationControllerL
inearFade::create(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::Ti
meDelta fadeoutLength) |
13 { | 13 { |
14 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(scrollLaye
r, fadeoutDelay, fadeoutLength)); | 14 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(scrollLaye
r, fadeoutDelay, fadeoutLength)); |
15 } | 15 } |
16 | 16 |
17 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(L
ayerImpl* scrollLayer, double fadeoutDelay, double fadeoutLength) | 17 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(L
ayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLeng
th) |
18 : ScrollbarAnimationController() | 18 : ScrollbarAnimationController() |
19 , m_scrollLayer(scrollLayer) | 19 , m_scrollLayer(scrollLayer) |
20 , m_pinchGestureInEffect(false) | 20 , m_scrollGestureInProgress(false) |
21 , m_fadeoutDelay(fadeoutDelay) | 21 , m_fadeoutDelay(fadeoutDelay) |
22 , m_fadeoutLength(fadeoutLength) | 22 , m_fadeoutLength(fadeoutLength) |
23 { | 23 { |
24 } | 24 } |
25 | 25 |
26 ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade(
) | 26 ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade(
) |
27 { | 27 { |
28 } | 28 } |
29 | 29 |
| 30 bool ScrollbarAnimationControllerLinearFade::isScrollGestureInProgress() const |
| 31 { |
| 32 return m_scrollGestureInProgress; |
| 33 } |
| 34 |
| 35 bool ScrollbarAnimationControllerLinearFade::isAnimating() const |
| 36 { |
| 37 return !m_lastAwakenTime.is_null(); |
| 38 } |
| 39 |
| 40 base::TimeDelta ScrollbarAnimationControllerLinearFade::delayBeforeStart(base::T
imeTicks now) const |
| 41 { |
| 42 if (now > m_lastAwakenTime + m_fadeoutDelay) |
| 43 return base::TimeDelta(); |
| 44 return m_fadeoutDelay - (now - m_lastAwakenTime); |
| 45 } |
| 46 |
30 bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now) | 47 bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now) |
31 { | 48 { |
32 float opacity = opacityAtTime(now); | 49 float opacity = opacityAtTime(now); |
33 m_scrollLayer->SetScrollbarOpacity(opacity); | 50 m_scrollLayer->SetScrollbarOpacity(opacity); |
34 return opacity; | 51 if (!opacity) |
| 52 m_lastAwakenTime = base::TimeTicks(); |
| 53 return isAnimating() && delayBeforeStart(now) == base::TimeDelta(); |
35 } | 54 } |
36 | 55 |
37 void ScrollbarAnimationControllerLinearFade::didPinchGestureUpdate(base::TimeTic
ks now) | 56 void ScrollbarAnimationControllerLinearFade::didScrollGestureBegin() |
38 { | 57 { |
39 m_pinchGestureInEffect = true; | 58 m_scrollLayer->SetScrollbarOpacity(1); |
| 59 m_scrollGestureInProgress = true; |
| 60 m_lastAwakenTime = base::TimeTicks(); |
40 } | 61 } |
41 | 62 |
42 void ScrollbarAnimationControllerLinearFade::didPinchGestureEnd(base::TimeTicks
now) | 63 void ScrollbarAnimationControllerLinearFade::didScrollGestureEnd(base::TimeTicks
now) |
43 { | 64 { |
44 m_pinchGestureInEffect = false; | 65 m_scrollGestureInProgress = false; |
45 m_lastAwakenTime = now; | 66 m_lastAwakenTime = now; |
46 } | 67 } |
47 | 68 |
48 void ScrollbarAnimationControllerLinearFade::didUpdateScrollOffset(base::TimeTic
ks now) | 69 void ScrollbarAnimationControllerLinearFade::didProgrammaticallyUpdateScroll(bas
e::TimeTicks now) |
49 { | 70 { |
| 71 // Don't set m_scrollGestureInProgress as this scroll is not from a gesture |
| 72 // and we won't receive ScrollEnd. |
| 73 m_scrollLayer->SetScrollbarOpacity(1); |
50 m_lastAwakenTime = now; | 74 m_lastAwakenTime = now; |
51 } | 75 } |
52 | 76 |
53 float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now) | 77 float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now) |
54 { | 78 { |
55 if (m_pinchGestureInEffect) | 79 if (m_scrollGestureInProgress) |
56 return 1; | 80 return 1; |
57 | 81 |
58 if (m_lastAwakenTime.is_null()) | 82 if (m_lastAwakenTime.is_null()) |
59 return 0; | 83 return 0; |
60 | 84 |
61 double delta = (now - m_lastAwakenTime).InSecondsF(); | 85 base::TimeDelta delta = now - m_lastAwakenTime; |
62 | 86 |
63 if (delta <= m_fadeoutDelay) | 87 if (delta <= m_fadeoutDelay) |
64 return 1; | 88 return 1; |
65 if (delta < m_fadeoutDelay + m_fadeoutLength) | 89 if (delta < m_fadeoutDelay + m_fadeoutLength) |
66 return (m_fadeoutDelay + m_fadeoutLength - delta) / m_fadeoutLength; | 90 return (m_fadeoutDelay + m_fadeoutLength - delta).InSecondsF() / m_fadeo
utLength.InSecondsF(); |
67 return 0; | 91 return 0; |
68 } | 92 } |
69 | 93 |
70 } // namespace cc | 94 } // namespace cc |
OLD | NEW |