| 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 #ifndef CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 5 #ifndef CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
| 6 #define CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 6 #define CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/cancelable_callback.h" | 8 #include "base/cancelable_callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| 11 #include "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/input/scrollbar.h" |
| 12 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
| 13 #include "cc/layers/scrollbar_layer_impl_base.h" | 14 #include "cc/layers/scrollbar_layer_impl_base.h" |
| 14 #include "ui/gfx/geometry/vector2d_f.h" | 15 #include "ui/gfx/geometry/vector2d_f.h" |
| 15 | 16 |
| 16 namespace cc { | 17 namespace cc { |
| 17 | 18 |
| 18 class ScrollbarAnimationController; | 19 class ScrollbarAnimationController; |
| 19 | 20 |
| 20 class CC_EXPORT ScrollbarAnimationControllerClient { | 21 class CC_EXPORT ScrollbarAnimationControllerClient { |
| 21 public: | 22 public: |
| 22 virtual void PostDelayedScrollbarAnimationTask(const base::Closure& task, | 23 virtual void PostDelayedScrollbarAnimationTask(const base::Closure& task, |
| 23 base::TimeDelta delay) = 0; | 24 base::TimeDelta delay) = 0; |
| 24 virtual void SetNeedsRedrawForScrollbarAnimation() = 0; | 25 virtual void SetNeedsRedrawForScrollbarAnimation() = 0; |
| 25 virtual void SetNeedsAnimateForScrollbarAnimation() = 0; | 26 virtual void SetNeedsAnimateForScrollbarAnimation() = 0; |
| 26 virtual void DidChangeScrollbarVisibility() = 0; | 27 virtual void DidChangeScrollbarVisibility() = 0; |
| 27 virtual ScrollbarSet ScrollbarsFor(int scroll_layer_id) const = 0; | 28 virtual ScrollbarSet ScrollbarsFor(int scroll_layer_id) const = 0; |
| 28 | 29 |
| 29 protected: | 30 protected: |
| 30 virtual ~ScrollbarAnimationControllerClient() {} | 31 virtual ~ScrollbarAnimationControllerClient() {} |
| 31 }; | 32 }; |
| 32 | 33 |
| 33 // This abstract class represents the compositor-side analogy of | 34 // This abstract class represents the compositor-side analogy of |
| 34 // ScrollbarAnimator. Individual platforms should subclass it to provide | 35 // ScrollbarAnimator. Individual platforms should subclass it to provide |
| 35 // specialized implementation. | 36 // specialized implementation. |
| 36 class CC_EXPORT ScrollbarAnimationController { | 37 class CC_EXPORT ScrollbarAnimationController { |
| 37 public: | 38 public: |
| 38 virtual ~ScrollbarAnimationController(); | 39 virtual ~ScrollbarAnimationController(); |
| 39 | 40 |
| 40 bool Animate(base::TimeTicks now); | 41 virtual bool Animate(base::TimeTicks now); |
| 41 | 42 |
| 42 virtual void DidScrollBegin(); | 43 virtual void DidScrollBegin(); |
| 43 virtual void DidScrollUpdate(bool on_resize); | 44 virtual void DidScrollUpdate(bool on_resize); |
| 44 virtual void DidScrollEnd(); | 45 virtual void DidScrollEnd(); |
| 45 virtual void DidMouseDown() {} | 46 virtual void DidMouseDown() {} |
| 46 virtual void DidMouseUp() {} | 47 virtual void DidMouseUp() {} |
| 47 virtual void DidMouseLeave() {} | 48 virtual void DidMouseLeave() {} |
| 48 virtual void DidMouseMoveNear(float distance) {} | 49 virtual void DidMouseMoveNear(ScrollbarOrientation, float) {} |
| 49 virtual bool ScrollbarsHidden() const; | 50 virtual bool ScrollbarsHidden() const; |
| 50 | 51 |
| 51 protected: | 52 protected: |
| 52 ScrollbarAnimationController(int scroll_layer_id, | 53 ScrollbarAnimationController(int scroll_layer_id, |
| 53 ScrollbarAnimationControllerClient* client, | 54 ScrollbarAnimationControllerClient* client, |
| 54 base::TimeDelta delay_before_starting, | 55 base::TimeDelta delay_before_starting, |
| 55 base::TimeDelta resize_delay_before_starting); | 56 base::TimeDelta resize_delay_before_starting); |
| 56 | 57 |
| 57 virtual void RunAnimationFrame(float progress) = 0; | 58 virtual void RunAnimationFrame(float progress) = 0; |
| 58 virtual const base::TimeDelta& Duration() = 0; | 59 virtual const base::TimeDelta& Duration() = 0; |
| 59 | 60 |
| 60 void StartAnimation(); | 61 virtual void StartAnimation(); |
| 61 void StopAnimation(); | 62 void StopAnimation(); |
| 63 |
| 62 ScrollbarSet Scrollbars() const; | 64 ScrollbarSet Scrollbars() const; |
| 63 | 65 |
| 64 ScrollbarAnimationControllerClient* client_; | 66 ScrollbarAnimationControllerClient* client_; |
| 65 | 67 |
| 66 void PostDelayedAnimationTask(bool on_resize); | 68 void PostDelayedAnimationTask(bool on_resize); |
| 67 | 69 |
| 70 base::CancelableClosure* delayed_scrollbar_fade() { |
| 71 return &delayed_scrollbar_fade_; |
| 72 } |
| 73 |
| 68 int scroll_layer_id() const { return scroll_layer_id_; } | 74 int scroll_layer_id() const { return scroll_layer_id_; } |
| 69 | 75 |
| 76 bool animating() const { return is_animating_; } |
| 77 |
| 70 private: | 78 private: |
| 71 // Returns how far through the animation we are as a progress value from | 79 // Returns how far through the animation we are as a progress value from |
| 72 // 0 to 1. | 80 // 0 to 1. |
| 73 float AnimationProgressAtTime(base::TimeTicks now); | 81 float AnimationProgressAtTime(base::TimeTicks now); |
| 74 | 82 |
| 75 base::TimeTicks last_awaken_time_; | 83 base::TimeTicks last_awaken_time_; |
| 76 base::TimeDelta delay_before_starting_; | 84 base::TimeDelta delay_before_starting_; |
| 77 base::TimeDelta resize_delay_before_starting_; | 85 base::TimeDelta resize_delay_before_starting_; |
| 78 | 86 |
| 79 bool is_animating_; | 87 bool is_animating_; |
| 80 | 88 |
| 81 int scroll_layer_id_; | 89 int scroll_layer_id_; |
| 82 bool currently_scrolling_; | 90 bool currently_scrolling_; |
| 83 bool scroll_gesture_has_scrolled_; | 91 bool scroll_gesture_has_scrolled_; |
| 84 base::CancelableClosure delayed_scrollbar_fade_; | 92 base::CancelableClosure delayed_scrollbar_fade_; |
| 85 | 93 |
| 86 base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_; | 94 base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_; |
| 87 }; | 95 }; |
| 88 | 96 |
| 89 } // namespace cc | 97 } // namespace cc |
| 90 | 98 |
| 91 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 99 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
| OLD | NEW |