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/scrollbar_animation_controller_linear_fade.h" | |
6 | |
7 #include "base/time.h" | |
8 #include "cc/layer_impl.h" | |
9 | |
10 namespace cc { | |
11 | |
12 scoped_ptr<ScrollbarAnimationControllerLinearFade> ScrollbarAnimationControllerL
inearFade::create(LayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::Ti
meDelta fadeoutLength) | |
13 { | |
14 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(scrollLaye
r, fadeoutDelay, fadeoutLength)); | |
15 } | |
16 | |
17 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(L
ayerImpl* scrollLayer, base::TimeDelta fadeoutDelay, base::TimeDelta fadeoutLeng
th) | |
18 : ScrollbarAnimationController() | |
19 , m_scrollLayer(scrollLayer) | |
20 , m_scrollGestureInProgress(false) | |
21 , m_fadeoutDelay(fadeoutDelay) | |
22 , m_fadeoutLength(fadeoutLength) | |
23 { | |
24 } | |
25 | |
26 ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade(
) | |
27 { | |
28 } | |
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 | |
47 bool ScrollbarAnimationControllerLinearFade::animate(base::TimeTicks now) | |
48 { | |
49 float opacity = opacityAtTime(now); | |
50 m_scrollLayer->SetScrollbarOpacity(opacity); | |
51 if (!opacity) | |
52 m_lastAwakenTime = base::TimeTicks(); | |
53 return isAnimating() && delayBeforeStart(now) == base::TimeDelta(); | |
54 } | |
55 | |
56 void ScrollbarAnimationControllerLinearFade::didScrollGestureBegin() | |
57 { | |
58 m_scrollLayer->SetScrollbarOpacity(1); | |
59 m_scrollGestureInProgress = true; | |
60 m_lastAwakenTime = base::TimeTicks(); | |
61 } | |
62 | |
63 void ScrollbarAnimationControllerLinearFade::didScrollGestureEnd(base::TimeTicks
now) | |
64 { | |
65 m_scrollGestureInProgress = false; | |
66 m_lastAwakenTime = now; | |
67 } | |
68 | |
69 void ScrollbarAnimationControllerLinearFade::didProgrammaticallyUpdateScroll(bas
e::TimeTicks now) | |
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); | |
74 m_lastAwakenTime = now; | |
75 } | |
76 | |
77 float ScrollbarAnimationControllerLinearFade::opacityAtTime(base::TimeTicks now) | |
78 { | |
79 if (m_scrollGestureInProgress) | |
80 return 1; | |
81 | |
82 if (m_lastAwakenTime.is_null()) | |
83 return 0; | |
84 | |
85 base::TimeDelta delta = now - m_lastAwakenTime; | |
86 | |
87 if (delta <= m_fadeoutDelay) | |
88 return 1; | |
89 if (delta < m_fadeoutDelay + m_fadeoutLength) | |
90 return (m_fadeoutDelay + m_fadeoutLength - delta).InSecondsF() / m_fadeo
utLength.InSecondsF(); | |
91 return 0; | |
92 } | |
93 | |
94 } // namespace cc | |
OLD | NEW |