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