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 #ifndef CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_
6 #define CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_
8 #include "base/cancelable_callback.h"
9 #include "base/memory/weak_ptr.h"
10 #include "base/time/time.h"
11 #include "cc/base/cc_export.h"
12 #include "cc/layers/layer_impl.h"
13 #include "ui/gfx/geometry/vector2d_f.h"
17 class ScrollbarAnimationController
;
19 class CC_EXPORT ScrollbarAnimationControllerClient
{
21 virtual void StartAnimatingScrollbarAnimationController(
22 ScrollbarAnimationController
* controller
) = 0;
23 virtual void StopAnimatingScrollbarAnimationController(
24 ScrollbarAnimationController
* controller
) = 0;
25 virtual void PostDelayedScrollbarAnimationTask(const base::Closure
& task
,
26 base::TimeDelta delay
) = 0;
27 virtual void SetNeedsRedrawForScrollbarAnimation() = 0;
30 virtual ~ScrollbarAnimationControllerClient() {}
33 // This abstract class represents the compositor-side analogy of
34 // ScrollbarAnimator. Individual platforms should subclass it to provide
35 // specialized implementation.
36 class CC_EXPORT ScrollbarAnimationController
{
38 virtual ~ScrollbarAnimationController();
40 void Animate(base::TimeTicks now
);
42 virtual void DidScrollBegin();
43 virtual void DidScrollUpdate(bool on_resize
);
44 virtual void DidScrollEnd();
45 virtual void DidMouseMoveOffScrollbar() {}
46 virtual void DidMouseMoveNear(float distance
) {}
49 ScrollbarAnimationController(LayerImpl
* scroll_layer
,
50 ScrollbarAnimationControllerClient
* client
,
51 base::TimeDelta delay_before_starting
,
52 base::TimeDelta resize_delay_before_starting
,
53 base::TimeDelta duration
);
55 virtual void RunAnimationFrame(float progress
) = 0;
57 void StartAnimation();
60 LayerImpl
* scroll_layer_
;
61 ScrollbarAnimationControllerClient
* client_
;
64 // Returns how far through the animation we are as a progress value from
66 float AnimationProgressAtTime(base::TimeTicks now
);
68 void PostDelayedAnimationTask(bool on_resize
);
70 base::TimeTicks last_awaken_time_
;
71 base::TimeDelta delay_before_starting_
;
72 base::TimeDelta resize_delay_before_starting_
;
73 base::TimeDelta duration_
;
77 bool currently_scrolling_
;
78 bool scroll_gesture_has_scrolled_
;
79 base::CancelableClosure delayed_scrollbar_fade_
;
81 base::WeakPtrFactory
<ScrollbarAnimationController
> weak_factory_
;
86 #endif // CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_