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