| 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/cc_export.h" | 11 #include "cc/cc_export.h" |
| 12 #include "cc/input/single_scrollbar_animation_controller_thinning.h" | 12 #include "cc/input/single_scrollbar_animation_controller_thinning.h" |
| 13 #include "cc/layers/layer_impl.h" | 13 #include "cc/layers/layer_impl.h" |
| 14 #include "cc/layers/scrollbar_layer_impl_base.h" | 14 #include "cc/layers/scrollbar_layer_impl_base.h" |
| 15 #include "ui/gfx/geometry/vector2d_f.h" | 15 #include "ui/gfx/geometry/vector2d_f.h" |
| 16 | 16 |
| 17 namespace cc { | 17 namespace cc { |
| 18 | 18 |
| 19 class CC_EXPORT ScrollbarAnimationControllerClient { | 19 class CC_EXPORT ScrollbarAnimationControllerClient { |
| 20 public: | 20 public: |
| 21 virtual void PostDelayedScrollbarAnimationTask(const base::Closure& task, | 21 virtual void PostDelayedScrollbarAnimationTask(const base::Closure& task, |
| 22 base::TimeDelta delay) = 0; | 22 base::TimeDelta delay) = 0; |
| 23 virtual void SetNeedsRedrawForScrollbarAnimation() = 0; | 23 virtual void SetNeedsRedrawForScrollbarAnimation() = 0; |
| 24 virtual void SetNeedsAnimateForScrollbarAnimation() = 0; | 24 virtual void SetNeedsAnimateForScrollbarAnimation() = 0; |
| 25 virtual void DidChangeScrollbarVisibility() = 0; | 25 virtual void DidChangeScrollbarVisibility() = 0; |
| 26 virtual ScrollbarSet ScrollbarsFor(int scroll_layer_id) const = 0; | 26 virtual ScrollbarSet ScrollbarsFor(ElementId scroll_element_id) const = 0; |
| 27 | 27 |
| 28 protected: | 28 protected: |
| 29 virtual ~ScrollbarAnimationControllerClient() {} | 29 virtual ~ScrollbarAnimationControllerClient() {} |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // This class show scrollbars when scroll and fade out after an idle delay. | 32 // This class show scrollbars when scroll and fade out after an idle delay. |
| 33 // The fade animations works on both scrollbars and is controlled in this class | 33 // The fade animations works on both scrollbars and is controlled in this class |
| 34 // This class also passes the mouse state to each | 34 // This class also passes the mouse state to each |
| 35 // SingleScrollbarAnimationControllerThinning. The thinning animations are | 35 // SingleScrollbarAnimationControllerThinning. The thinning animations are |
| 36 // independent between vertical/horizontal and are managed by the | 36 // independent between vertical/horizontal and are managed by the |
| 37 // SingleScrollbarAnimationControllerThinnings. | 37 // SingleScrollbarAnimationControllerThinnings. |
| 38 class CC_EXPORT ScrollbarAnimationController { | 38 class CC_EXPORT ScrollbarAnimationController { |
| 39 public: | 39 public: |
| 40 // ScrollbarAnimationController for Android. It only has show & fade out | 40 // ScrollbarAnimationController for Android. It only has show & fade out |
| 41 // animation. | 41 // animation. |
| 42 static std::unique_ptr<ScrollbarAnimationController> | 42 static std::unique_ptr<ScrollbarAnimationController> |
| 43 CreateScrollbarAnimationControllerAndroid( | 43 CreateScrollbarAnimationControllerAndroid( |
| 44 int scroll_layer_id, | 44 ElementId scroll_element_id, |
| 45 ScrollbarAnimationControllerClient* client, | 45 ScrollbarAnimationControllerClient* client, |
| 46 base::TimeDelta fade_out_delay, | 46 base::TimeDelta fade_out_delay, |
| 47 base::TimeDelta fade_out_resize_delay, | 47 base::TimeDelta fade_out_resize_delay, |
| 48 base::TimeDelta fade_out_duration); | 48 base::TimeDelta fade_out_duration); |
| 49 | 49 |
| 50 // ScrollbarAnimationController for Desktop Overlay Scrollbar. It has show & | 50 // ScrollbarAnimationController for Desktop Overlay Scrollbar. It has show & |
| 51 // fade out animation and thinning animation. | 51 // fade out animation and thinning animation. |
| 52 static std::unique_ptr<ScrollbarAnimationController> | 52 static std::unique_ptr<ScrollbarAnimationController> |
| 53 CreateScrollbarAnimationControllerAuraOverlay( | 53 CreateScrollbarAnimationControllerAuraOverlay( |
| 54 int scroll_layer_id, | 54 ElementId scroll_element_id, |
| 55 ScrollbarAnimationControllerClient* client, | 55 ScrollbarAnimationControllerClient* client, |
| 56 base::TimeDelta show_delay, | 56 base::TimeDelta show_delay, |
| 57 base::TimeDelta fade_out_delay, | 57 base::TimeDelta fade_out_delay, |
| 58 base::TimeDelta fade_out_resize_delay, | 58 base::TimeDelta fade_out_resize_delay, |
| 59 base::TimeDelta fade_out_duration, | 59 base::TimeDelta fade_out_duration, |
| 60 base::TimeDelta thinning_duration); | 60 base::TimeDelta thinning_duration); |
| 61 | 61 |
| 62 ~ScrollbarAnimationController(); | 62 ~ScrollbarAnimationController(); |
| 63 | 63 |
| 64 bool ScrollbarsHidden() const; | 64 bool ScrollbarsHidden() const; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 89 // ScrollableArea::showOverlayScrollbars). | 89 // ScrollableArea::showOverlayScrollbars). |
| 90 void DidRequestShowFromMainThread(); | 90 void DidRequestShowFromMainThread(); |
| 91 | 91 |
| 92 bool MouseIsOverScrollbar(ScrollbarOrientation orientation) const; | 92 bool MouseIsOverScrollbar(ScrollbarOrientation orientation) const; |
| 93 bool MouseIsNearScrollbar(ScrollbarOrientation orientation) const; | 93 bool MouseIsNearScrollbar(ScrollbarOrientation orientation) const; |
| 94 bool MouseIsNearAnyScrollbar() const; | 94 bool MouseIsNearAnyScrollbar() const; |
| 95 | 95 |
| 96 static constexpr float kMouseMoveDistanceToTriggerShow = 30.0f; | 96 static constexpr float kMouseMoveDistanceToTriggerShow = 30.0f; |
| 97 | 97 |
| 98 private: | 98 private: |
| 99 ScrollbarAnimationController(int scroll_layer_id, | 99 ScrollbarAnimationController(ElementId scroll_element_id, |
| 100 ScrollbarAnimationControllerClient* client, | 100 ScrollbarAnimationControllerClient* client, |
| 101 base::TimeDelta fade_out_delay, | 101 base::TimeDelta fade_out_delay, |
| 102 base::TimeDelta fade_out_resize_delay, | 102 base::TimeDelta fade_out_resize_delay, |
| 103 base::TimeDelta fade_out_duration); | 103 base::TimeDelta fade_out_duration); |
| 104 | 104 |
| 105 ScrollbarAnimationController(int scroll_layer_id, | 105 ScrollbarAnimationController(ElementId scroll_element_id, |
| 106 ScrollbarAnimationControllerClient* client, | 106 ScrollbarAnimationControllerClient* client, |
| 107 base::TimeDelta show_delay, | 107 base::TimeDelta show_delay, |
| 108 base::TimeDelta fade_out_delay, | 108 base::TimeDelta fade_out_delay, |
| 109 base::TimeDelta fade_out_resize_delay, | 109 base::TimeDelta fade_out_resize_delay, |
| 110 base::TimeDelta fade_out_duration, | 110 base::TimeDelta fade_out_duration, |
| 111 base::TimeDelta thinning_duration); | 111 base::TimeDelta thinning_duration); |
| 112 | 112 |
| 113 ScrollbarSet Scrollbars() const; | 113 ScrollbarSet Scrollbars() const; |
| 114 SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController( | 114 SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController( |
| 115 ScrollbarOrientation) const; | 115 ScrollbarOrientation) const; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 141 // show_delay_ is only for the case where the mouse hovers near the screen | 141 // show_delay_ is only for the case where the mouse hovers near the screen |
| 142 // edge. | 142 // edge. |
| 143 base::TimeDelta show_delay_; | 143 base::TimeDelta show_delay_; |
| 144 base::TimeDelta fade_out_delay_; | 144 base::TimeDelta fade_out_delay_; |
| 145 base::TimeDelta fade_out_resize_delay_; | 145 base::TimeDelta fade_out_resize_delay_; |
| 146 | 146 |
| 147 bool need_trigger_scrollbar_show_; | 147 bool need_trigger_scrollbar_show_; |
| 148 | 148 |
| 149 bool is_animating_; | 149 bool is_animating_; |
| 150 | 150 |
| 151 const int scroll_layer_id_; | 151 const ElementId scroll_element_id_; |
| 152 bool currently_scrolling_; | 152 bool currently_scrolling_; |
| 153 bool show_in_fast_scroll_; | 153 bool show_in_fast_scroll_; |
| 154 | 154 |
| 155 base::CancelableClosure delayed_scrollbar_show_; | 155 base::CancelableClosure delayed_scrollbar_show_; |
| 156 base::CancelableClosure delayed_scrollbar_fade_out_; | 156 base::CancelableClosure delayed_scrollbar_fade_out_; |
| 157 | 157 |
| 158 float opacity_; | 158 float opacity_; |
| 159 base::TimeDelta fade_out_duration_; | 159 base::TimeDelta fade_out_duration_; |
| 160 | 160 |
| 161 const bool show_scrollbars_on_scroll_gesture_; | 161 const bool show_scrollbars_on_scroll_gesture_; |
| 162 const bool need_thinning_animation_; | 162 const bool need_thinning_animation_; |
| 163 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 163 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
| 164 vertical_controller_; | 164 vertical_controller_; |
| 165 std::unique_ptr<SingleScrollbarAnimationControllerThinning> | 165 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
| 166 horizontal_controller_; | 166 horizontal_controller_; |
| 167 | 167 |
| 168 base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_; | 168 base::WeakPtrFactory<ScrollbarAnimationController> weak_factory_; |
| 169 }; | 169 }; |
| 170 | 170 |
| 171 } // namespace cc | 171 } // namespace cc |
| 172 | 172 |
| 173 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ | 173 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_H_ |
| OLD | NEW |