| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ |
| 6 #define UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_HOVER_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 "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "ui/gfx/geometry/point.h" | 13 #include "ui/gfx/geometry/point.h" |
| 14 #include "ui/gfx/geometry/point_f.h" | 14 #include "ui/gfx/geometry/point_f.h" |
| 15 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
| 16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 17 #include "ui/views/views_export.h" | 17 #include "ui/views/views_export.h" |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 class Layer; | 20 class Layer; |
| 21 class CallbackLayerAnimationObserver; | 21 class CallbackLayerAnimationObserver; |
| 22 } // namespace ui | 22 } // namespace ui |
| 23 | 23 |
| 24 namespace views { | 24 namespace views { |
| 25 namespace test { | 25 namespace test { |
| 26 class InkDropHoverTestApi; | 26 class InkDropHoverTestApi; |
| 27 } // namespace test | 27 } // namespace test |
| 28 | 28 |
| 29 class RoundedRectangleLayerDelegate; | 29 class RoundedRectangleLayerDelegate; |
| 30 class InkDropHoverObserver; |
| 30 | 31 |
| 31 // Manages fade in/out animations for a painted Layer that is used to provide | 32 // Manages fade in/out animations for a painted Layer that is used to provide |
| 32 // visual feedback on ui::Views for mouse hover states. | 33 // visual feedback on ui::Views for mouse hover states. |
| 33 class VIEWS_EXPORT InkDropHover { | 34 class VIEWS_EXPORT InkDropHover { |
| 34 public: | 35 public: |
| 36 enum AnimationType { FADE_IN, FADE_OUT }; |
| 37 |
| 35 InkDropHover(const gfx::Size& size, | 38 InkDropHover(const gfx::Size& size, |
| 36 int corner_radius, | 39 int corner_radius, |
| 37 const gfx::Point& center_point, | 40 const gfx::Point& center_point, |
| 38 SkColor color); | 41 SkColor color); |
| 39 virtual ~InkDropHover(); | 42 virtual ~InkDropHover(); |
| 40 | 43 |
| 44 void set_observer(InkDropHoverObserver* observer) { observer_ = observer; } |
| 45 |
| 41 void set_explode_size(const gfx::Size& size) { explode_size_ = size; } | 46 void set_explode_size(const gfx::Size& size) { explode_size_ = size; } |
| 42 | 47 |
| 43 // Returns true if the hover animation is either in the process of fading | 48 // Returns true if the hover animation is either in the process of fading |
| 44 // in or is fully visible. | 49 // in or is fully visible. |
| 45 bool IsFadingInOrVisible() const; | 50 bool IsFadingInOrVisible() const; |
| 46 | 51 |
| 47 // Fades in the hover visual over the given |duration|. | 52 // Fades in the hover visual over the given |duration|. |
| 48 void FadeIn(const base::TimeDelta& duration); | 53 void FadeIn(const base::TimeDelta& duration); |
| 49 | 54 |
| 50 // Fades out the hover visual over the given |duration|. If |explode| is true | 55 // Fades out the hover visual over the given |duration|. If |explode| is true |
| 51 // then the hover will animate a size increase in addition to the fade out. | 56 // then the hover will animate a size increase in addition to the fade out. |
| 52 void FadeOut(const base::TimeDelta& duration, bool explode); | 57 void FadeOut(const base::TimeDelta& duration, bool explode); |
| 53 | 58 |
| 54 // The root Layer that can be added in to a Layer tree. | 59 // The root Layer that can be added in to a Layer tree. |
| 55 ui::Layer* layer() { return layer_.get(); } | 60 ui::Layer* layer() { return layer_.get(); } |
| 56 | 61 |
| 57 // Returns a test api to access internals of this. Default implmentations | 62 // Returns a test api to access internals of this. Default implmentations |
| 58 // should return nullptr and test specific subclasses can override to return | 63 // should return nullptr and test specific subclasses can override to return |
| 59 // an instance. | 64 // an instance. |
| 60 virtual test::InkDropHoverTestApi* GetTestApi(); | 65 virtual test::InkDropHoverTestApi* GetTestApi(); |
| 61 | 66 |
| 62 private: | 67 private: |
| 63 friend class test::InkDropHoverTestApi; | 68 friend class test::InkDropHoverTestApi; |
| 64 | 69 |
| 65 enum HoverAnimationType { FADE_IN, FADE_OUT }; | |
| 66 | |
| 67 // Animates a fade in/out as specified by |animation_type| combined with a | 70 // Animates a fade in/out as specified by |animation_type| combined with a |
| 68 // transformation from the |initial_size| to the |target_size| over the given | 71 // transformation from the |initial_size| to the |target_size| over the given |
| 69 // |duration|. | 72 // |duration|. |
| 70 void AnimateFade(HoverAnimationType animation_type, | 73 void AnimateFade(AnimationType animation_type, |
| 71 const base::TimeDelta& duration, | 74 const base::TimeDelta& duration, |
| 72 const gfx::Size& initial_size, | 75 const gfx::Size& initial_size, |
| 73 const gfx::Size& target_size); | 76 const gfx::Size& target_size); |
| 74 | 77 |
| 75 // Calculates the Transform to apply to |layer_| for the given |size|. | 78 // Calculates the Transform to apply to |layer_| for the given |size|. |
| 76 gfx::Transform CalculateTransform(const gfx::Size& size) const; | 79 gfx::Transform CalculateTransform(const gfx::Size& size) const; |
| 77 | 80 |
| 81 // The callback that will be invoked when a fade in/out animation is started. |
| 82 void AnimationStartedCallback( |
| 83 AnimationType animation_type, |
| 84 const ui::CallbackLayerAnimationObserver& observer); |
| 85 |
| 78 // The callback that will be invoked when a fade in/out animation is complete. | 86 // The callback that will be invoked when a fade in/out animation is complete. |
| 79 bool AnimationEndedCallback( | 87 bool AnimationEndedCallback( |
| 80 HoverAnimationType animation_type, | 88 AnimationType animation_type, |
| 81 const ui::CallbackLayerAnimationObserver& observer); | 89 const ui::CallbackLayerAnimationObserver& observer); |
| 82 | 90 |
| 83 // The size of the hover shape when fully faded in. | 91 // The size of the hover shape when fully faded in. |
| 84 gfx::Size size_; | 92 gfx::Size size_; |
| 85 | 93 |
| 86 // The target size of the hover shape when it expands during a fade out | 94 // The target size of the hover shape when it expands during a fade out |
| 87 // animation. | 95 // animation. |
| 88 gfx::Size explode_size_; | 96 gfx::Size explode_size_; |
| 89 | 97 |
| 90 // The center point of the hover shape in the parent Layer's coordinate space. | 98 // The center point of the hover shape in the parent Layer's coordinate space. |
| 91 gfx::PointF center_point_; | 99 gfx::PointF center_point_; |
| 92 | 100 |
| 93 // True if the last animation to be initiated was a FADE_IN, and false | 101 // True if the last animation to be initiated was a FADE_IN, and false |
| 94 // otherwise. | 102 // otherwise. |
| 95 bool last_animation_initiated_was_fade_in_; | 103 bool last_animation_initiated_was_fade_in_; |
| 96 | 104 |
| 97 // The LayerDelegate that paints the hover |layer_|. | 105 // The LayerDelegate that paints the hover |layer_|. |
| 98 std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_; | 106 std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_; |
| 99 | 107 |
| 100 // The visual hover layer that is painted by |layer_delegate_|. | 108 // The visual hover layer that is painted by |layer_delegate_|. |
| 101 std::unique_ptr<ui::Layer> layer_; | 109 std::unique_ptr<ui::Layer> layer_; |
| 102 | 110 |
| 111 InkDropHoverObserver* observer_; |
| 112 |
| 103 DISALLOW_COPY_AND_ASSIGN(InkDropHover); | 113 DISALLOW_COPY_AND_ASSIGN(InkDropHover); |
| 104 }; | 114 }; |
| 105 | 115 |
| 106 } // namespace views | 116 } // namespace views |
| 107 | 117 |
| 108 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 118 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ |
| OLD | NEW |