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_HIGHLIGHT_H_ |
6 #define UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ |
7 | 7 |
8 #include <iosfwd> | 8 #include <iosfwd> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
15 #include "ui/gfx/geometry/point_f.h" | 15 #include "ui/gfx/geometry/point_f.h" |
16 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
17 #include "ui/gfx/transform.h" | 17 #include "ui/gfx/transform.h" |
18 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
19 | 19 |
20 namespace ui { | 20 namespace ui { |
21 class Layer; | 21 class Layer; |
22 class CallbackLayerAnimationObserver; | 22 class CallbackLayerAnimationObserver; |
23 } // namespace ui | 23 } // namespace ui |
24 | 24 |
25 namespace views { | 25 namespace views { |
26 namespace test { | 26 namespace test { |
27 class InkDropHoverTestApi; | 27 class InkDropHighlightTestApi; |
28 } // namespace test | 28 } // namespace test |
29 | 29 |
30 class RoundedRectangleLayerDelegate; | 30 class RoundedRectangleLayerDelegate; |
31 class InkDropHoverObserver; | 31 class InkDropHighlightObserver; |
32 | 32 |
33 // Manages fade in/out animations for a painted Layer that is used to provide | 33 // Manages fade in/out animations for a painted Layer that is used to provide |
34 // visual feedback on ui::Views for mouse hover states. | 34 // visual feedback on ui::Views for mouse highlight states. |
bruthig
2016/06/03 02:50:46
nit: Can you update the comment to not be mouse sp
Evan Stade
2016/06/03 03:01:41
Done.
| |
35 class VIEWS_EXPORT InkDropHover { | 35 class VIEWS_EXPORT InkDropHighlight { |
36 public: | 36 public: |
37 enum AnimationType { FADE_IN, FADE_OUT }; | 37 enum AnimationType { FADE_IN, FADE_OUT }; |
38 | 38 |
39 InkDropHover(const gfx::Size& size, | 39 InkDropHighlight(const gfx::Size& size, |
40 int corner_radius, | 40 int corner_radius, |
41 const gfx::Point& center_point, | 41 const gfx::Point& center_point, |
42 SkColor color); | 42 SkColor color); |
43 virtual ~InkDropHover(); | 43 virtual ~InkDropHighlight(); |
44 | 44 |
45 void set_observer(InkDropHoverObserver* observer) { observer_ = observer; } | 45 void set_observer(InkDropHighlightObserver* observer) { |
46 observer_ = observer; | |
47 } | |
46 | 48 |
47 void set_explode_size(const gfx::Size& size) { explode_size_ = size; } | 49 void set_explode_size(const gfx::Size& size) { explode_size_ = size; } |
48 | 50 |
49 // Returns true if the hover animation is either in the process of fading | 51 // Returns true if the highlight animation is either in the process of fading |
50 // in or is fully visible. | 52 // in or is fully visible. |
51 bool IsFadingInOrVisible() const; | 53 bool IsFadingInOrVisible() const; |
52 | 54 |
53 // Fades in the hover visual over the given |duration|. | 55 // Fades in the highlight visual over the given |duration|. |
54 void FadeIn(const base::TimeDelta& duration); | 56 void FadeIn(const base::TimeDelta& duration); |
55 | 57 |
56 // Fades out the hover visual over the given |duration|. If |explode| is true | 58 // Fades out the highlight visual over the given |duration|. If |explode| is |
57 // then the hover will animate a size increase in addition to the fade out. | 59 // true then the highlight will animate a size increase in addition to the |
60 // fade out. | |
58 void FadeOut(const base::TimeDelta& duration, bool explode); | 61 void FadeOut(const base::TimeDelta& duration, bool explode); |
59 | 62 |
60 // The root Layer that can be added in to a Layer tree. | 63 // The root Layer that can be added in to a Layer tree. |
61 ui::Layer* layer() { return layer_.get(); } | 64 ui::Layer* layer() { return layer_.get(); } |
62 | 65 |
63 // Returns a test api to access internals of this. Default implmentations | 66 // Returns a test api to access internals of this. Default implmentations |
64 // should return nullptr and test specific subclasses can override to return | 67 // should return nullptr and test specific subclasses can override to return |
65 // an instance. | 68 // an instance. |
66 virtual test::InkDropHoverTestApi* GetTestApi(); | 69 virtual test::InkDropHighlightTestApi* GetTestApi(); |
67 | 70 |
68 private: | 71 private: |
69 friend class test::InkDropHoverTestApi; | 72 friend class test::InkDropHighlightTestApi; |
70 | 73 |
71 // Animates a fade in/out as specified by |animation_type| combined with a | 74 // Animates a fade in/out as specified by |animation_type| combined with a |
72 // transformation from the |initial_size| to the |target_size| over the given | 75 // transformation from the |initial_size| to the |target_size| over the given |
73 // |duration|. | 76 // |duration|. |
74 void AnimateFade(AnimationType animation_type, | 77 void AnimateFade(AnimationType animation_type, |
75 const base::TimeDelta& duration, | 78 const base::TimeDelta& duration, |
76 const gfx::Size& initial_size, | 79 const gfx::Size& initial_size, |
77 const gfx::Size& target_size); | 80 const gfx::Size& target_size); |
78 | 81 |
79 // Calculates the Transform to apply to |layer_| for the given |size|. | 82 // Calculates the Transform to apply to |layer_| for the given |size|. |
80 gfx::Transform CalculateTransform(const gfx::Size& size) const; | 83 gfx::Transform CalculateTransform(const gfx::Size& size) const; |
81 | 84 |
82 // The callback that will be invoked when a fade in/out animation is started. | 85 // The callback that will be invoked when a fade in/out animation is started. |
83 void AnimationStartedCallback( | 86 void AnimationStartedCallback( |
84 AnimationType animation_type, | 87 AnimationType animation_type, |
85 const ui::CallbackLayerAnimationObserver& observer); | 88 const ui::CallbackLayerAnimationObserver& observer); |
86 | 89 |
87 // The callback that will be invoked when a fade in/out animation is complete. | 90 // The callback that will be invoked when a fade in/out animation is complete. |
88 bool AnimationEndedCallback( | 91 bool AnimationEndedCallback( |
89 AnimationType animation_type, | 92 AnimationType animation_type, |
90 const ui::CallbackLayerAnimationObserver& observer); | 93 const ui::CallbackLayerAnimationObserver& observer); |
91 | 94 |
92 // The size of the hover shape when fully faded in. | 95 // The size of the highlight shape when fully faded in. |
93 gfx::Size size_; | 96 gfx::Size size_; |
94 | 97 |
95 // The target size of the hover shape when it expands during a fade out | 98 // The target size of the highlight shape when it expands during a fade out |
96 // animation. | 99 // animation. |
97 gfx::Size explode_size_; | 100 gfx::Size explode_size_; |
98 | 101 |
99 // The center point of the hover shape in the parent Layer's coordinate space. | 102 // The center point of the highlight shape in the parent Layer's coordinate |
103 // space. | |
100 gfx::PointF center_point_; | 104 gfx::PointF center_point_; |
101 | 105 |
102 // True if the last animation to be initiated was a FADE_IN, and false | 106 // True if the last animation to be initiated was a FADE_IN, and false |
103 // otherwise. | 107 // otherwise. |
104 bool last_animation_initiated_was_fade_in_; | 108 bool last_animation_initiated_was_fade_in_; |
105 | 109 |
106 // The LayerDelegate that paints the hover |layer_|. | 110 // The LayerDelegate that paints the highlight |layer_|. |
107 std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_; | 111 std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_; |
108 | 112 |
109 // The visual hover layer that is painted by |layer_delegate_|. | 113 // The visual highlight layer that is painted by |layer_delegate_|. |
110 std::unique_ptr<ui::Layer> layer_; | 114 std::unique_ptr<ui::Layer> layer_; |
111 | 115 |
112 InkDropHoverObserver* observer_; | 116 InkDropHighlightObserver* observer_; |
113 | 117 |
114 DISALLOW_COPY_AND_ASSIGN(InkDropHover); | 118 DISALLOW_COPY_AND_ASSIGN(InkDropHighlight); |
115 }; | 119 }; |
116 | 120 |
117 // Returns a human readable string for |animation_type|. Useful for logging. | 121 // Returns a human readable string for |animation_type|. Useful for logging. |
118 VIEWS_EXPORT std::string ToString(InkDropHover::AnimationType animation_type); | 122 VIEWS_EXPORT std::string ToString( |
123 InkDropHighlight::AnimationType animation_type); | |
119 | 124 |
120 // This is declared here for use in gtest-based unit tests but is defined in | 125 // This is declared here for use in gtest-based unit tests but is defined in |
121 // the views_test_support target. Depend on that to use this in your unit test. | 126 // the views_test_support target. Depend on that to use this in your unit test. |
122 // This should not be used in production code - call ToString() instead. | 127 // This should not be used in production code - call ToString() instead. |
123 void PrintTo(InkDropHover::AnimationType animation_type, ::std::ostream* os); | 128 void PrintTo(InkDropHighlight::AnimationType animation_type, |
129 ::std::ostream* os); | |
124 | 130 |
125 } // namespace views | 131 } // namespace views |
126 | 132 |
127 #endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_ | 133 #endif // UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_ |
OLD | NEW |