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