| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ | 5 #ifndef CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ |
| 6 #define CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ | 6 #define CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
| 12 #include "cc/cc_export.h" | 12 #include "cc/cc_export.h" |
| 13 #include "cc/input/scrollbar.h" | 13 #include "cc/input/scrollbar.h" |
| 14 #include "cc/layers/layer_impl.h" | 14 #include "cc/layers/layer_impl.h" |
| 15 #include "cc/layers/scrollbar_layer_impl_base.h" | 15 #include "cc/layers/scrollbar_layer_impl_base.h" |
| 16 #include "ui/gfx/geometry/vector2d_f.h" | 16 #include "ui/gfx/geometry/vector2d_f.h" |
| 17 | 17 |
| 18 namespace cc { | 18 namespace cc { |
| 19 | 19 |
| 20 class ScrollbarAnimationControllerClient; | 20 class ScrollbarAnimationControllerClient; |
| 21 | 21 |
| 22 // ScrollbarAnimationControllerThinning for one scrollbar | 22 // ScrollbarAnimationControllerThinning for one scrollbar |
| 23 class CC_EXPORT SingleScrollbarAnimationControllerThinning { | 23 class CC_EXPORT SingleScrollbarAnimationControllerThinning { |
| 24 public: | 24 public: |
| 25 static constexpr float kIdleThicknessScale = 0.4f; | 25 static constexpr float kIdleThicknessScale = 0.4f; |
| 26 static constexpr float kDefaultMouseMoveDistanceToTriggerAnimation = 25.f; | 26 static constexpr float kMouseMoveDistanceToTriggerExpand = 25.f; |
| 27 | 27 |
| 28 static std::unique_ptr<SingleScrollbarAnimationControllerThinning> Create( | 28 static std::unique_ptr<SingleScrollbarAnimationControllerThinning> Create( |
| 29 ElementId scroll_element_id, | 29 ElementId scroll_element_id, |
| 30 ScrollbarOrientation orientation, | 30 ScrollbarOrientation orientation, |
| 31 ScrollbarAnimationControllerClient* client, | 31 ScrollbarAnimationControllerClient* client, |
| 32 base::TimeDelta thinning_duration); | 32 base::TimeDelta thinning_duration); |
| 33 | 33 |
| 34 ~SingleScrollbarAnimationControllerThinning() {} | 34 ~SingleScrollbarAnimationControllerThinning() {} |
| 35 | 35 |
| 36 bool mouse_is_over_scrollbar() const { return mouse_is_over_scrollbar_; } | 36 bool mouse_is_over_scrollbar_thumb() const { |
| 37 bool mouse_is_near_scrollbar() const { return mouse_is_near_scrollbar_; } | 37 return mouse_is_over_scrollbar_thumb_; |
| 38 } |
| 39 bool mouse_is_near_scrollbar_thumb() const { |
| 40 return mouse_is_near_scrollbar_thumb_; |
| 41 } |
| 42 bool mouse_is_near_scrollbar_track() const { |
| 43 return mouse_is_near_scrollbar_track_; |
| 44 } |
| 45 |
| 38 bool captured() const { return captured_; } | 46 bool captured() const { return captured_; } |
| 39 | 47 |
| 40 bool Animate(base::TimeTicks now); | 48 bool Animate(base::TimeTicks now); |
| 41 void StartAnimation(); | 49 void StartAnimation(); |
| 42 void StopAnimation(); | 50 void StopAnimation(); |
| 43 | 51 |
| 44 void UpdateThumbThicknessScale(); | 52 void UpdateThumbThicknessScale(); |
| 45 | 53 |
| 46 void DidMouseDown(); | 54 void DidMouseDown(); |
| 47 void DidMouseUp(); | 55 void DidMouseUp(); |
| 48 void DidMouseLeave(); | 56 void DidMouseLeave(); |
| 49 void DidMouseMoveNear(float distance); | 57 void DidMouseMove(const gfx::PointF& device_viewport_point); |
| 50 | 58 |
| 51 private: | 59 private: |
| 52 SingleScrollbarAnimationControllerThinning( | 60 SingleScrollbarAnimationControllerThinning( |
| 53 ElementId scroll_element_id, | 61 ElementId scroll_element_id, |
| 54 ScrollbarOrientation orientation, | 62 ScrollbarOrientation orientation, |
| 55 ScrollbarAnimationControllerClient* client, | 63 ScrollbarAnimationControllerClient* client, |
| 56 base::TimeDelta thinning_duration); | 64 base::TimeDelta thinning_duration); |
| 57 | 65 |
| 66 ScrollbarLayerImplBase* GetScrollbar() const; |
| 58 float AnimationProgressAtTime(base::TimeTicks now); | 67 float AnimationProgressAtTime(base::TimeTicks now); |
| 59 void RunAnimationFrame(float progress); | 68 void RunAnimationFrame(float progress); |
| 60 const base::TimeDelta& Duration(); | 69 const base::TimeDelta& Duration(); |
| 61 | 70 |
| 62 // Describes whether the current animation should INCREASE (thicken) | 71 // Describes whether the current animation should INCREASE (thicken) |
| 63 // a bar or DECREASE it (thin). | 72 // a bar or DECREASE it (thin). |
| 64 enum AnimationChange { NONE, INCREASE, DECREASE }; | 73 enum AnimationChange { NONE, INCREASE, DECREASE }; |
| 65 float ThumbThicknessScaleAt(float progress); | 74 float ThumbThicknessScaleAt(float progress); |
| 66 | 75 |
| 67 float AdjustScale(float new_value, | 76 float AdjustScale(float new_value, |
| 68 float current_value, | 77 float current_value, |
| 69 AnimationChange animation_change, | 78 AnimationChange animation_change, |
| 70 float min_value, | 79 float min_value, |
| 71 float max_value); | 80 float max_value); |
| 72 void ApplyThumbThicknessScale(float thumb_thickness_scale); | 81 void ApplyThumbThicknessScale(float thumb_thickness_scale); |
| 73 | 82 |
| 74 ScrollbarAnimationControllerClient* client_; | 83 ScrollbarAnimationControllerClient* client_; |
| 75 | 84 |
| 76 base::TimeTicks last_awaken_time_; | 85 base::TimeTicks last_awaken_time_; |
| 77 bool is_animating_; | 86 bool is_animating_; |
| 78 | 87 |
| 79 ElementId scroll_element_id_; | 88 ElementId scroll_element_id_; |
| 80 | 89 |
| 81 ScrollbarOrientation orientation_; | 90 ScrollbarOrientation orientation_; |
| 82 bool captured_; | 91 bool captured_; |
| 83 bool mouse_is_over_scrollbar_; | 92 bool mouse_is_over_scrollbar_thumb_; |
| 84 bool mouse_is_near_scrollbar_; | 93 bool mouse_is_near_scrollbar_thumb_; |
| 94 bool mouse_is_near_scrollbar_track_; |
| 85 // Are we narrowing or thickening the bars. | 95 // Are we narrowing or thickening the bars. |
| 86 AnimationChange thickness_change_; | 96 AnimationChange thickness_change_; |
| 87 | 97 |
| 88 base::TimeDelta thinning_duration_; | 98 base::TimeDelta thinning_duration_; |
| 89 | 99 |
| 90 DISALLOW_COPY_AND_ASSIGN(SingleScrollbarAnimationControllerThinning); | 100 DISALLOW_COPY_AND_ASSIGN(SingleScrollbarAnimationControllerThinning); |
| 91 }; | 101 }; |
| 92 | 102 |
| 93 } // namespace cc | 103 } // namespace cc |
| 94 | 104 |
| 95 #endif // CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ | 105 #endif // CC_INPUT_SINGLE_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ |
| OLD | NEW |