Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / cc / animation / scrollbar_animation_controller.h
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 #ifndef CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_
6 #define CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_
7
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 "ui/gfx/vector2d_f.h"
13
14 namespace cc {
15
16 class CC_EXPORT ScrollbarAnimationControllerClient {
17  public:
18   virtual ~ScrollbarAnimationControllerClient() {}
19
20   virtual void PostDelayedScrollbarFade(const base::Closure& start_fade,
21                                         base::TimeDelta delay) = 0;
22   virtual void SetNeedsScrollbarAnimationFrame() = 0;
23 };
24
25 // This abstract class represents the compositor-side analogy of
26 // ScrollbarAnimator.  Individual platforms should subclass it to provide
27 // specialized implementation.
28 class CC_EXPORT ScrollbarAnimationController {
29  public:
30   virtual ~ScrollbarAnimationController();
31
32   void Animate(base::TimeTicks now);
33
34   virtual void DidScrollBegin();
35   virtual void DidScrollUpdate();
36   virtual void DidScrollEnd();
37   virtual void DidMouseMoveOffScrollbar() {}
38   virtual void DidMouseMoveNear(float distance) {}
39
40  protected:
41   ScrollbarAnimationController(ScrollbarAnimationControllerClient* client,
42                                base::TimeDelta delay_before_starting,
43                                base::TimeDelta duration);
44
45   virtual void RunAnimationFrame(float progress) = 0;
46
47   void StartAnimation();
48   void StopAnimation();
49
50  private:
51   // Returns how far through the animation we are as a progress value from
52   // 0 to 1.
53   float AnimationProgressAtTime(base::TimeTicks now);
54
55   void PostDelayedFade();
56
57   ScrollbarAnimationControllerClient* client_;
58   base::TimeTicks last_awaken_time_;
59   base::TimeDelta delay_before_starting_;
60   base::TimeDelta duration_;
61   bool is_animating_;
62
63   bool currently_scrolling_;
64   bool scroll_gesture_has_scrolled_;
65   base::CancelableClosure delayed_scrollbar_fade_;
66
67   base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_;
68 };
69
70 }  // namespace cc
71
72 #endif  // CC_ANIMATION_SCROLLBAR_ANIMATION_CONTROLLER_H_