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