Chromium Code Reviews| 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_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ | 5 #ifndef CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ |
| 6 #define CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ | 6 #define CC_INPUT_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 "cc/base/cc_export.h" | 11 #include "cc/base/cc_export.h" |
| 12 #include "cc/input/scrollbar_animation_controller.h" | 12 #include "cc/input/scrollbar_animation_controller.h" |
| 13 #include "cc/input/single_scrollbar_animation_controller_thinning.h" | |
| 13 | 14 |
| 14 namespace cc { | 15 namespace cc { |
| 15 | 16 |
| 16 // Scrollbar animation that partially fades and thins after an idle delay, | 17 // Scrollbar animation that partially fades and thins after an idle delay, |
| 17 // and reacts to mouse movements. | 18 // and reacts to mouse movements. |
|
bokan
2017/01/20 18:57:25
Add to this comment an explanation of how this cla
| |
| 19 | |
| 20 // TODO(chaopeng) clean up the inheritance hierarchy after | |
| 21 // ScrollbarAnimationControllerLinearFade merge into | |
| 22 // ScrollbarAnimationControllerThinning so we can remove the empty overrides and | |
| 23 // NOTREACHED() checks. | |
| 18 class CC_EXPORT ScrollbarAnimationControllerThinning | 24 class CC_EXPORT ScrollbarAnimationControllerThinning |
| 19 : public ScrollbarAnimationController { | 25 : public ScrollbarAnimationController { |
| 20 public: | 26 public: |
| 21 static std::unique_ptr<ScrollbarAnimationControllerThinning> Create( | 27 static std::unique_ptr<ScrollbarAnimationControllerThinning> Create( |
| 22 int scroll_layer_id, | 28 int scroll_layer_id, |
| 23 ScrollbarAnimationControllerClient* client, | 29 ScrollbarAnimationControllerClient* client, |
| 24 base::TimeDelta delay_before_starting, | 30 base::TimeDelta delay_before_starting, |
| 25 base::TimeDelta resize_delay_before_starting, | 31 base::TimeDelta resize_delay_before_starting, |
| 26 base::TimeDelta fade_duration, | 32 base::TimeDelta fade_duration, |
| 27 base::TimeDelta thinning_duration); | 33 base::TimeDelta thinning_duration); |
| 28 | 34 |
| 29 ~ScrollbarAnimationControllerThinning() override; | 35 ~ScrollbarAnimationControllerThinning() override; |
| 30 | 36 |
| 31 void set_mouse_move_distance_for_test(float distance) { | 37 void set_mouse_move_distance_for_test(float distance); |
| 32 mouse_move_distance_to_trigger_animation_ = distance; | |
| 33 } | |
| 34 bool mouse_is_over_scrollbar() const { return mouse_is_over_scrollbar_; } | |
| 35 bool mouse_is_near_scrollbar() const { return mouse_is_near_scrollbar_; } | |
| 36 | 38 |
| 39 bool mouse_is_over_scrollbar(ScrollbarOrientation orientation) const; | |
| 40 bool mouse_is_near_scrollbar(ScrollbarOrientation orientation) const; | |
| 41 bool mouse_is_near_any_scrollbar() const; | |
| 42 | |
| 43 bool Animate(base::TimeTicks now) override; | |
| 37 void DidScrollUpdate(bool on_resize) override; | 44 void DidScrollUpdate(bool on_resize) override; |
| 38 void DidScrollEnd() override; | 45 void DidScrollEnd() override; |
| 39 | |
| 40 void DidMouseDown() override; | 46 void DidMouseDown() override; |
| 41 void DidMouseUp() override; | 47 void DidMouseUp() override; |
| 42 void DidMouseLeave() override; | 48 void DidMouseLeave() override; |
| 43 void DidMouseMoveNear(float distance) override; | 49 void DidMouseMoveNear(ScrollbarOrientation orientation, |
| 50 float distance) override; | |
| 44 bool ScrollbarsHidden() const override; | 51 bool ScrollbarsHidden() const override; |
| 45 | 52 |
| 46 protected: | 53 private: |
| 47 ScrollbarAnimationControllerThinning( | 54 ScrollbarAnimationControllerThinning( |
| 48 int scroll_layer_id, | 55 int scroll_layer_id, |
| 49 ScrollbarAnimationControllerClient* client, | 56 ScrollbarAnimationControllerClient* client, |
| 50 base::TimeDelta delay_before_starting, | 57 base::TimeDelta delay_before_starting, |
| 51 base::TimeDelta resize_delay_before_starting, | 58 base::TimeDelta resize_delay_before_starting, |
| 52 base::TimeDelta fade_duration, | 59 base::TimeDelta fade_duration, |
| 53 base::TimeDelta thinning_duration); | 60 base::TimeDelta thinning_duration); |
| 54 | 61 |
| 62 SingleScrollbarAnimationControllerThinning& GetScrollbarAnimationController( | |
| 63 ScrollbarOrientation) const; | |
| 64 | |
| 65 void ApplyOpacity(float opacity); | |
| 66 bool Captured() const; | |
| 55 void RunAnimationFrame(float progress) override; | 67 void RunAnimationFrame(float progress) override; |
| 56 const base::TimeDelta& Duration() override; | 68 const base::TimeDelta& Duration() override; |
| 57 | 69 |
| 58 private: | 70 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
| 59 // Describes whether the current animation should INCREASE (thicken) | 71 vertical_controller_; |
| 60 // a bar or DECREASE it (thin). | 72 std::unique_ptr<SingleScrollbarAnimationControllerThinning> |
| 61 enum AnimationChange { NONE, INCREASE, DECREASE }; | 73 horizontal_controller_; |
| 62 enum AnimatingProperty { OPACITY, THICKNESS }; | |
| 63 float ThumbThicknessScaleAt(float progress); | |
| 64 float AdjustScale(float new_value, | |
| 65 float current_value, | |
| 66 AnimationChange animation_change, | |
| 67 float min_value, | |
| 68 float max_value); | |
| 69 void ApplyOpacity(float opacity); | |
| 70 void ApplyThumbThicknessScale(float thumb_thickness_scale); | |
| 71 | |
| 72 void SetCurrentAnimatingProperty(AnimatingProperty property); | |
| 73 | 74 |
| 74 float opacity_; | 75 float opacity_; |
| 75 bool captured_; | |
| 76 bool mouse_is_over_scrollbar_; | |
| 77 bool mouse_is_near_scrollbar_; | |
| 78 // Are we narrowing or thickening the bars. | |
| 79 AnimationChange thickness_change_; | |
| 80 // How close should the mouse be to the scrollbar before we thicken it. | |
| 81 float mouse_move_distance_to_trigger_animation_; | |
| 82 | |
| 83 base::TimeDelta fade_duration_; | 76 base::TimeDelta fade_duration_; |
| 84 base::TimeDelta thinning_duration_; | |
| 85 | |
| 86 AnimatingProperty current_animating_property_; | |
| 87 | 77 |
| 88 DISALLOW_COPY_AND_ASSIGN(ScrollbarAnimationControllerThinning); | 78 DISALLOW_COPY_AND_ASSIGN(ScrollbarAnimationControllerThinning); |
| 89 }; | 79 }; |
| 90 | 80 |
| 91 } // namespace cc | 81 } // namespace cc |
| 92 | 82 |
| 93 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ | 83 #endif // CC_INPUT_SCROLLBAR_ANIMATION_CONTROLLER_THINNING_H_ |
| OLD | NEW |