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_ANIMATION_H_ | 5 #ifndef UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 6 #define UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
7 | 7 |
8 #include "base/macros.h" | 8 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "base/time/time.h" | 11 #include "base/time/time.h" |
12 #include "ui/compositor/layer_animator.h" | 12 #include "ui/compositor/layer_animator.h" |
| 13 #include "ui/gfx/animation/tween.h" |
| 14 #include "ui/gfx/geometry/point.h" |
13 #include "ui/gfx/geometry/size.h" | 15 #include "ui/gfx/geometry/size.h" |
14 #include "ui/gfx/geometry/size_f.h" | |
15 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
16 #include "ui/views/animation/ink_drop_state.h" | 17 #include "ui/views/animation/ink_drop_state.h" |
17 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
18 | 19 |
19 namespace ui { | 20 namespace ui { |
20 class CallbackLayerAnimationObserver; | 21 class CallbackLayerAnimationObserver; |
21 class Layer; | 22 class Layer; |
22 class LayerAnimationObserver; | 23 class LayerAnimationObserver; |
23 class LayerDelegate; | 24 class LayerDelegate; |
24 } // namespace ui | 25 } // namespace ui |
(...skipping 25 matching lines...) Expand all Loading... |
50 // The root Layer that can be added in to a Layer tree. | 51 // The root Layer that can be added in to a Layer tree. |
51 ui::Layer* root_layer() { return root_layer_.get(); } | 52 ui::Layer* root_layer() { return root_layer_.get(); } |
52 | 53 |
53 InkDropState ink_drop_state() const { return ink_drop_state_; } | 54 InkDropState ink_drop_state() const { return ink_drop_state_; } |
54 | 55 |
55 void AddObserver(InkDropAnimationObserver* observer); | 56 void AddObserver(InkDropAnimationObserver* observer); |
56 void RemoveObserver(InkDropAnimationObserver* observer); | 57 void RemoveObserver(InkDropAnimationObserver* observer); |
57 | 58 |
58 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It | 59 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It |
59 // is possible to animate from any |ink_drop_state_| to any new | 60 // is possible to animate from any |ink_drop_state_| to any new |
60 // |ink_drop_state|. Note that some state transitions will also perform an | 61 // |ink_drop_state|. |
61 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION) | |
62 // will implicitly transition to the HIDDEN state. | |
63 void AnimateToState(InkDropState ink_drop_state); | 62 void AnimateToState(InkDropState ink_drop_state); |
64 | 63 |
65 // Sets the |center_point| of the ink drop layer relative to its parent Layer. | 64 // Sets the |center_point| of the ink drop layer relative to its parent Layer. |
66 void SetCenterPoint(const gfx::Point& center_point); | 65 void SetCenterPoint(const gfx::Point& center_point); |
67 | 66 |
68 private: | 67 private: |
69 friend class test::InkDropAnimationTestApi; | 68 friend class test::InkDropAnimationTestApi; |
70 | 69 |
71 // Enumeration of the different shapes that compose the ink drop. | 70 // Enumeration of the different shapes that compose the ink drop. |
72 enum PaintedShape { | 71 enum PaintedShape { |
73 TOP_LEFT_CIRCLE = 0, | 72 TOP_LEFT_CIRCLE = 0, |
74 TOP_RIGHT_CIRCLE, | 73 TOP_RIGHT_CIRCLE, |
75 BOTTOM_RIGHT_CIRCLE, | 74 BOTTOM_RIGHT_CIRCLE, |
76 BOTTOM_LEFT_CIRCLE, | 75 BOTTOM_LEFT_CIRCLE, |
77 HORIZONTAL_RECT, | 76 HORIZONTAL_RECT, |
78 VERTICAL_RECT, | 77 VERTICAL_RECT, |
79 // The total number of shapes, not an actual shape. | 78 // The total number of shapes, not an actual shape. |
80 PAINTED_SHAPE_COUNT | 79 PAINTED_SHAPE_COUNT |
81 }; | 80 }; |
82 | 81 |
83 // Type that contains a gfx::Tansform for each of the layers required by the | 82 // Type that contains a gfx::Tansform for each of the layers required by the |
84 // ink drop. | 83 // ink drop. |
85 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; | 84 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
86 | 85 |
87 // Animates the ripple to |ink_drop_state| and attaches |observer| to all | 86 // Animates the ripple to |ink_drop_state| and attaches |observer| to all |
88 // LayerAnimationSequence's used. | 87 // LayerAnimationSequence's used. |
89 void AnimateToStateInternal(InkDropState ink_drop_state, | 88 void AnimateToStateInternal(InkDropState ink_drop_state, |
90 ui::LayerAnimationObserver* observer); | 89 ui::LayerAnimationObserver* observer); |
91 | 90 |
92 // Animates all of the painted shape layers to the specified |transforms| and | 91 // Animates all of the painted shape layers to the specified |transforms|. The |
93 // |opacity|. The animation will use the given |duration| and | 92 // animation will use the given |duration|, |preemption_strategy|, and |tween| |
94 // |preemption_strategy|, and |observer| will be added to all | 93 // and |observer| will be added to all LayerAnimationSequences. |
95 // LayerAnimationSequences. | |
96 void AnimateToTransforms( | 94 void AnimateToTransforms( |
97 const InkDropTransforms transforms, | 95 const InkDropTransforms transforms, |
98 float opacity, | |
99 base::TimeDelta duration, | 96 base::TimeDelta duration, |
100 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 97 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 98 gfx::Tween::Type tween, |
101 ui::LayerAnimationObserver* observer); | 99 ui::LayerAnimationObserver* observer); |
102 | 100 |
103 // Updates the Transforms and opacity to the HIDDEN state. | 101 // Updates the Transforms and opacity to the HIDDEN state. |
104 void SetStateToHidden(); | 102 void SetStateToHidden(); |
105 | 103 |
106 // Sets the |transforms| on all of the shape layers. Note that this does not | 104 // Sets the |transforms| on all of the shape layers. Note that this does not |
107 // perform any animation. | 105 // perform any animation. |
108 void SetTransforms(const InkDropTransforms transforms); | 106 void SetTransforms(const InkDropTransforms transforms); |
109 | 107 |
| 108 // Gets the opacity of the ink drop. |
| 109 float GetCurrentOpacity() const; |
| 110 |
110 // Sets the opacity of the ink drop. | 111 // Sets the opacity of the ink drop. |
111 void SetOpacity(float opacity); | 112 void SetOpacity(float opacity); |
112 | 113 |
| 114 // Animates all of the painted shape layers to the specified |opacity|. The |
| 115 // animation will use the given |duration|, |preemption_strategy|, and |tween| |
| 116 // and |observer| will be added to all LayerAnimationSequences. |
| 117 void AnimateToOpacity( |
| 118 float opacity, |
| 119 base::TimeDelta duration, |
| 120 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 121 gfx::Tween::Type tween, |
| 122 ui::LayerAnimationObserver* animation_observer); |
| 123 |
113 // Updates all of the Transforms in |transforms_out| for a circle of the given | 124 // Updates all of the Transforms in |transforms_out| for a circle of the given |
114 // |size|. | 125 // |size|. |
115 void CalculateCircleTransforms(const gfx::Size& size, | 126 void CalculateCircleTransforms(const gfx::Size& size, |
116 InkDropTransforms* transforms_out) const; | 127 InkDropTransforms* transforms_out) const; |
117 | 128 |
118 // Updates all of the Transforms in |transforms_out| for a rounded rectangle | 129 // Updates all of the Transforms in |transforms_out| for a rounded rectangle |
119 // of the given |size| and |corner_radius|. | 130 // of the given |size| and |corner_radius|. |
120 void CalculateRectTransforms(const gfx::Size& size, | 131 void CalculateRectTransforms(const gfx::Size& size, |
121 float corner_radius, | 132 float corner_radius, |
122 InkDropTransforms* transforms_out) const; | 133 InkDropTransforms* transforms_out) const; |
123 | 134 |
124 // Updates all of the Transforms in |transforms_out| to the current target | 135 // Updates all of the Transforms in |transforms_out| to the current Transforms |
125 // Transforms of the Layers. | 136 // of the Layers. |
126 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; | 137 void GetCurrentTransforms(InkDropTransforms* transforms_out) const; |
127 | 138 |
128 // Adds and configures a new |painted_shape| layer to |painted_layers_|. | 139 // Adds and configures a new |painted_shape| layer to |painted_layers_|. |
129 void AddPaintLayer(PaintedShape painted_shape); | 140 void AddPaintLayer(PaintedShape painted_shape); |
130 | 141 |
131 void AbortAllAnimations(); | 142 void AbortAllAnimations(); |
132 | 143 |
| 144 // Calculates an estimated distance ratio between 0.0 and 1.0 that estimates |
| 145 // how close the painted shape |transforms| are away from the final |
| 146 // QUICK_ACTION transforms. |
| 147 float CalculateDistanceEstimateToQuickAction( |
| 148 const InkDropTransforms& transforms) const; |
| 149 |
133 // The Callback invoked when all of the animation sequences for the specific | 150 // The Callback invoked when all of the animation sequences for the specific |
134 // |ink_drop_state| animation have started. |observer| is the | 151 // |ink_drop_state| animation have started. |observer| is the |
135 // ui::CallbackLayerAnimationObserver which is notifying the callback. | 152 // ui::CallbackLayerAnimationObserver which is notifying the callback. |
136 void AnimationStartedCallback( | 153 void AnimationStartedCallback( |
137 InkDropState ink_drop_state, | 154 InkDropState ink_drop_state, |
138 const ui::CallbackLayerAnimationObserver& observer); | 155 const ui::CallbackLayerAnimationObserver& observer); |
139 | 156 |
140 // The Callback invoked when all of the animation sequences for the specific | 157 // The Callback invoked when all of the animation sequences for the specific |
141 // |ink_drop_state| animation have finished. |observer| is the | 158 // |ink_drop_state| animation have finished. |observer| is the |
142 // ui::CallbackLayerAnimationObserver which is notifying the callback. | 159 // ui::CallbackLayerAnimationObserver which is notifying the callback. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 196 |
180 // List of observers to notify when animations have finished. | 197 // List of observers to notify when animations have finished. |
181 base::ObserverList<InkDropAnimationObserver> observers_; | 198 base::ObserverList<InkDropAnimationObserver> observers_; |
182 | 199 |
183 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | 200 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); |
184 }; | 201 }; |
185 | 202 |
186 } // namespace views | 203 } // namespace views |
187 | 204 |
188 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 205 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
OLD | NEW |