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/transform.h" | 16 #include "ui/gfx/transform.h" |
15 #include "ui/views/animation/ink_drop_state.h" | 17 #include "ui/views/animation/ink_drop_state.h" |
16 #include "ui/views/views_export.h" | 18 #include "ui/views/views_export.h" |
17 | 19 |
18 namespace ui { | 20 namespace ui { |
19 class CallbackLayerAnimationObserver; | 21 class CallbackLayerAnimationObserver; |
20 class Layer; | 22 class Layer; |
21 class LayerAnimationObserver; | 23 class LayerAnimationObserver; |
22 class LayerDelegate; | 24 class LayerDelegate; |
(...skipping 26 matching lines...) Expand all Loading... |
49 // 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. |
50 ui::Layer* root_layer() { return root_layer_.get(); } | 52 ui::Layer* root_layer() { return root_layer_.get(); } |
51 | 53 |
52 InkDropState ink_drop_state() const { return ink_drop_state_; } | 54 InkDropState ink_drop_state() const { return ink_drop_state_; } |
53 | 55 |
54 void AddObserver(InkDropAnimationObserver* observer); | 56 void AddObserver(InkDropAnimationObserver* observer); |
55 void RemoveObserver(InkDropAnimationObserver* observer); | 57 void RemoveObserver(InkDropAnimationObserver* observer); |
56 | 58 |
57 // 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 |
58 // 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 |
59 // |ink_drop_state|. Note that some state transitions will also perform an | 61 // |ink_drop_state|. |
60 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION) | |
61 // will implicitly transition to the HIDDEN state. | |
62 void AnimateToState(InkDropState ink_drop_state); | 62 void AnimateToState(InkDropState ink_drop_state); |
63 | 63 |
64 // 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. |
65 void SetCenterPoint(const gfx::Point& center_point); | 65 void SetCenterPoint(const gfx::Point& center_point); |
66 | 66 |
67 private: | 67 private: |
68 friend class test::InkDropAnimationTestApi; | 68 friend class test::InkDropAnimationTestApi; |
69 | 69 |
70 // Enumeration of the different shapes that compose the ink drop. | 70 // Enumeration of the different shapes that compose the ink drop. |
71 enum PaintedShape { | 71 enum PaintedShape { |
72 TOP_LEFT_CIRCLE = 0, | 72 TOP_LEFT_CIRCLE = 0, |
73 TOP_RIGHT_CIRCLE, | 73 TOP_RIGHT_CIRCLE, |
74 BOTTOM_RIGHT_CIRCLE, | 74 BOTTOM_RIGHT_CIRCLE, |
75 BOTTOM_LEFT_CIRCLE, | 75 BOTTOM_LEFT_CIRCLE, |
76 HORIZONTAL_RECT, | 76 HORIZONTAL_RECT, |
77 VERTICAL_RECT, | 77 VERTICAL_RECT, |
78 // The total number of shapes, not an actual shape. | 78 // The total number of shapes, not an actual shape. |
79 PAINTED_SHAPE_COUNT | 79 PAINTED_SHAPE_COUNT |
80 }; | 80 }; |
81 | 81 |
82 // 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 |
83 // ink drop. | 83 // ink drop. |
84 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; | 84 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
85 | 85 |
86 // 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 |
87 // LayerAnimationSequence's used. | 87 // LayerAnimationSequence's used. |
88 void AnimateToStateInternal(InkDropState ink_drop_state, | 88 void AnimateToStateInternal(InkDropState ink_drop_state, |
89 ui::LayerAnimationObserver* observer); | 89 ui::LayerAnimationObserver* observer); |
90 | 90 |
91 // 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 |
92 // |opacity|. The animation will use the given |duration| and | 92 // animation will use the given |duration|, |preemption_strategy|, and |tween| |
93 // |preemption_strategy|, and |observer| will be added to all | 93 // and |observer| will be added to all LayerAnimationSequences. |
94 // LayerAnimationSequences. | |
95 void AnimateToTransforms( | 94 void AnimateToTransforms( |
96 const InkDropTransforms transforms, | 95 const InkDropTransforms transforms, |
97 float opacity, | |
98 base::TimeDelta duration, | 96 base::TimeDelta duration, |
99 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 97 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 98 gfx::Tween::Type tween, |
100 ui::LayerAnimationObserver* observer); | 99 ui::LayerAnimationObserver* observer); |
101 | 100 |
102 // Updates the Transforms and opacity to the HIDDEN state. | 101 // Updates the Transforms and opacity to the HIDDEN state. |
103 void SetStateToHidden(); | 102 void SetStateToHidden(); |
104 | 103 |
105 // 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 |
106 // perform any animation. | 105 // perform any animation. |
107 void SetTransforms(const InkDropTransforms transforms); | 106 void SetTransforms(const InkDropTransforms transforms); |
108 | 107 |
| 108 // Gets the opacity of the ink drop. |
| 109 float GetCurrentOpacity() const; |
| 110 |
109 // Sets the opacity of the ink drop. | 111 // Sets the opacity of the ink drop. |
110 void SetOpacity(float opacity); | 112 void SetOpacity(float opacity); |
111 | 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 |
112 // 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 |
113 // |size|. | 125 // |size|. |
114 void CalculateCircleTransforms(const gfx::Size& size, | 126 void CalculateCircleTransforms(const gfx::Size& size, |
115 InkDropTransforms* transforms_out) const; | 127 InkDropTransforms* transforms_out) const; |
116 | 128 |
117 // 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 |
118 // of the given |size| and |corner_radius|. | 130 // of the given |size| and |corner_radius|. |
119 void CalculateRectTransforms(const gfx::Size& size, | 131 void CalculateRectTransforms(const gfx::Size& size, |
120 float corner_radius, | 132 float corner_radius, |
121 InkDropTransforms* transforms_out) const; | 133 InkDropTransforms* transforms_out) const; |
122 | 134 |
123 // 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 |
124 // Transforms of the Layers. | 136 // of the Layers. |
125 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; | 137 void GetCurrentTransforms(InkDropTransforms* transforms_out) const; |
126 | 138 |
127 // Adds and configures a new |painted_shape| layer to |painted_layers_|. | 139 // Adds and configures a new |painted_shape| layer to |painted_layers_|. |
128 void AddPaintLayer(PaintedShape painted_shape); | 140 void AddPaintLayer(PaintedShape painted_shape); |
129 | 141 |
130 void AbortAllAnimations(); | 142 void AbortAllAnimations(); |
131 | 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 |
132 // 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 |
133 // |ink_drop_state| animation have started. |observer| is the | 151 // |ink_drop_state| animation have started. |observer| is the |
134 // ui::CallbackLayerAnimationObserver which is notifying the callback. | 152 // ui::CallbackLayerAnimationObserver which is notifying the callback. |
135 void AnimationStartedCallback( | 153 void AnimationStartedCallback( |
136 InkDropState ink_drop_state, | 154 InkDropState ink_drop_state, |
137 const ui::CallbackLayerAnimationObserver& observer); | 155 const ui::CallbackLayerAnimationObserver& observer); |
138 | 156 |
139 // 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 |
140 // |ink_drop_state| animation have finished. |observer| is the | 158 // |ink_drop_state| animation have finished. |observer| is the |
141 // 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... |
178 | 196 |
179 // List of observers to notify when animations have finished. | 197 // List of observers to notify when animations have finished. |
180 base::ObserverList<InkDropAnimationObserver> observers_; | 198 base::ObserverList<InkDropAnimationObserver> observers_; |
181 | 199 |
182 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | 200 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); |
183 }; | 201 }; |
184 | 202 |
185 } // namespace views | 203 } // namespace views |
186 | 204 |
187 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 205 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
OLD | NEW |