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.
5 #include "cc/scrollbar_animation_controller_linear_fade.h"
7 #include "cc/scrollbar_layer_impl.h"
11 scoped_ptr
<ScrollbarAnimationControllerLinearFade
> ScrollbarAnimationControllerLinearFade::create(LayerImpl
* scrollLayer
, double fadeoutDelay
, double fadeoutLength
)
13 return make_scoped_ptr(new ScrollbarAnimationControllerLinearFade(scrollLayer
, fadeoutDelay
, fadeoutLength
));
16 ScrollbarAnimationControllerLinearFade::ScrollbarAnimationControllerLinearFade(LayerImpl
* scrollLayer
, double fadeoutDelay
, double fadeoutLength
)
17 : ScrollbarAnimationController(scrollLayer
)
18 , m_lastAwakenTime(-100000000) // arbitrary invalid timestamp
19 , m_pinchGestureInEffect(false)
20 , m_fadeoutDelay(fadeoutDelay
)
21 , m_fadeoutLength(fadeoutLength
)
25 ScrollbarAnimationControllerLinearFade::~ScrollbarAnimationControllerLinearFade()
29 bool ScrollbarAnimationControllerLinearFade::animate(double monotonicTime
)
31 float opacity
= opacityAtTime(monotonicTime
);
32 if (horizontalScrollbarLayer())
33 horizontalScrollbarLayer()->setOpacity(opacity
);
34 if (verticalScrollbarLayer())
35 verticalScrollbarLayer()->setOpacity(opacity
);
39 void ScrollbarAnimationControllerLinearFade::didPinchGestureUpdateAtTime(double)
41 m_pinchGestureInEffect
= true;
44 void ScrollbarAnimationControllerLinearFade::didPinchGestureEndAtTime(double monotonicTime
)
46 m_pinchGestureInEffect
= false;
47 m_lastAwakenTime
= monotonicTime
;
50 void ScrollbarAnimationControllerLinearFade::updateScrollOffsetAtTime(LayerImpl
* scrollLayer
, double monotonicTime
)
52 gfx::Vector2dF previousPos
= currentOffset();
53 ScrollbarAnimationController::updateScrollOffsetAtTime(scrollLayer
, monotonicTime
);
55 if (previousPos
== currentOffset())
58 m_lastAwakenTime
= monotonicTime
;
61 float ScrollbarAnimationControllerLinearFade::opacityAtTime(double monotonicTime
)
63 if (m_pinchGestureInEffect
)
66 double delta
= monotonicTime
- m_lastAwakenTime
;
68 if (delta
<= m_fadeoutDelay
)
70 if (delta
< m_fadeoutDelay
+ m_fadeoutLength
)
71 return (m_fadeoutDelay
+ m_fadeoutLength
- delta
) / m_fadeoutLength
;