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 <string> |
| 9 |
8 #include "base/macros.h" | 10 #include "base/macros.h" |
9 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
10 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
11 #include "base/time/time.h" | 13 #include "base/time/time.h" |
12 #include "ui/compositor/layer_animator.h" | 14 #include "ui/compositor/layer_animator.h" |
| 15 #include "ui/gfx/animation/tween.h" |
| 16 #include "ui/gfx/geometry/point.h" |
13 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
14 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
15 #include "ui/views/animation/ink_drop_state.h" | 19 #include "ui/views/animation/ink_drop_state.h" |
16 #include "ui/views/views_export.h" | 20 #include "ui/views/views_export.h" |
17 | 21 |
18 namespace ui { | 22 namespace ui { |
19 class CallbackLayerAnimationObserver; | 23 class CallbackLayerAnimationObserver; |
20 class Layer; | 24 class Layer; |
21 class LayerAnimationObserver; | 25 class LayerAnimationObserver; |
22 class LayerDelegate; | 26 class LayerDelegate; |
23 } // namespace ui | 27 } // namespace ui |
24 | 28 |
25 namespace views { | 29 namespace views { |
26 class CircleLayerDelegate; | 30 class CircleLayerDelegate; |
27 class InkDropAnimationObserver; | 31 class InkDropAnimationObserver; |
28 class RectangleLayerDelegate; | 32 class RectangleLayerDelegate; |
29 | 33 |
30 namespace test { | 34 namespace test { |
31 class InkDropAnimationTestApi; | 35 class InkDropAnimationTestApi; |
32 } // namespace test | 36 } // namespace test |
33 | 37 |
34 // An ink drop animation that smoothly animates between a circle and a rounded | 38 // An ink drop animation that smoothly animates between a circle and a rounded |
35 // rectangle of different sizes for each of the different InkDropStates. The | 39 // rectangle of different sizes for each of the different InkDropStates. The |
36 // final frame for each InkDropState will be bounded by either a |large_size_| | 40 // final frame for each InkDropState will be bounded by either a |large_size_| |
37 // rectangle or a |small_size_| rectangle. | 41 // rectangle or a |small_size_| rectangle. |
38 // | 42 // |
| 43 // The valid InkDropState transitions are defined below: |
| 44 // |
| 45 // {All InkDropStates} => HIDDEN |
| 46 // HIDDEN => ACTION_PENDING |
| 47 // HIDDEN, ACTION_PENDING => QUICK_ACTION |
| 48 // ACTION_PENDING => SLOW_ACTION_PENDING |
| 49 // SLOW_ACTION_PENDING => SLOW_ACTION |
| 50 // {All InkDropStates} => ACTIVATED |
| 51 // {All InkDropStates} => DEACTIVATED |
| 52 // |
39 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to | 53 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to |
40 // it. | 54 // it. |
41 class VIEWS_EXPORT InkDropAnimation { | 55 class VIEWS_EXPORT InkDropAnimation { |
42 public: | 56 public: |
| 57 // The opacity of the ink drop when it is visible. |
| 58 static const float kVisibleOpacity; |
| 59 |
| 60 // The opacity of the ink drop when it is not visible. |
| 61 static const float kHiddenOpacity; |
| 62 |
43 InkDropAnimation(const gfx::Size& large_size, | 63 InkDropAnimation(const gfx::Size& large_size, |
44 int large_corner_radius, | 64 int large_corner_radius, |
45 const gfx::Size& small_size, | 65 const gfx::Size& small_size, |
46 int small_corner_radius); | 66 int small_corner_radius); |
47 ~InkDropAnimation(); | 67 ~InkDropAnimation(); |
48 | 68 |
49 // The root Layer that can be added in to a Layer tree. | 69 // The root Layer that can be added in to a Layer tree. |
50 ui::Layer* root_layer() { return root_layer_.get(); } | 70 ui::Layer* root_layer() { return root_layer_.get(); } |
51 | 71 |
52 InkDropState ink_drop_state() const { return ink_drop_state_; } | 72 InkDropState ink_drop_state() const { return ink_drop_state_; } |
53 | 73 |
54 void AddObserver(InkDropAnimationObserver* observer); | 74 void AddObserver(InkDropAnimationObserver* observer); |
55 void RemoveObserver(InkDropAnimationObserver* observer); | 75 void RemoveObserver(InkDropAnimationObserver* observer); |
56 | 76 |
57 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It | 77 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. |
58 // 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 | |
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); | 78 void AnimateToState(InkDropState ink_drop_state); |
63 | 79 |
64 // Sets the |center_point| of the ink drop layer relative to its parent Layer. | 80 // Sets the |center_point| of the ink drop layer relative to its parent Layer. |
65 void SetCenterPoint(const gfx::Point& center_point); | 81 void SetCenterPoint(const gfx::Point& center_point); |
66 | 82 |
| 83 // Immediately aborts all in-progress animations and hides the ink drop. |
| 84 // NOTE: This will NOT raise InkDropAnimation(Started|Ended) events for the |
| 85 // state transition to HIDDEN! |
| 86 void HideImmediately(); |
| 87 |
67 private: | 88 private: |
68 friend class test::InkDropAnimationTestApi; | 89 friend class test::InkDropAnimationTestApi; |
69 | 90 |
70 // Enumeration of the different shapes that compose the ink drop. | 91 // Enumeration of the different shapes that compose the ink drop. |
71 enum PaintedShape { | 92 enum PaintedShape { |
72 TOP_LEFT_CIRCLE = 0, | 93 TOP_LEFT_CIRCLE = 0, |
73 TOP_RIGHT_CIRCLE, | 94 TOP_RIGHT_CIRCLE, |
74 BOTTOM_RIGHT_CIRCLE, | 95 BOTTOM_RIGHT_CIRCLE, |
75 BOTTOM_LEFT_CIRCLE, | 96 BOTTOM_LEFT_CIRCLE, |
76 HORIZONTAL_RECT, | 97 HORIZONTAL_RECT, |
77 VERTICAL_RECT, | 98 VERTICAL_RECT, |
78 // The total number of shapes, not an actual shape. | 99 // The total number of shapes, not an actual shape. |
79 PAINTED_SHAPE_COUNT | 100 PAINTED_SHAPE_COUNT |
80 }; | 101 }; |
81 | 102 |
82 // Returns a human readable string for the |painted_shape| value. | 103 // Returns a human readable string for the |painted_shape| value. |
83 static std::string ToLayerName(PaintedShape painted_shape); | 104 static std::string ToLayerName(PaintedShape painted_shape); |
84 | 105 |
85 // Type that contains a gfx::Tansform for each of the layers required by the | 106 // Type that contains a gfx::Tansform for each of the layers required by the |
86 // ink drop. | 107 // ink drop. |
87 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; | 108 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
88 | 109 |
89 // Animates the ripple to |ink_drop_state| and attaches |observer| to all | 110 // Animates the ripple to |ink_drop_state|. |observer| is added to all |
90 // LayerAnimationSequence's used. | 111 // LayerAnimationSequence's used if not null. |
91 void AnimateToStateInternal(InkDropState ink_drop_state, | 112 void AnimateToStateInternal(InkDropState ink_drop_state, |
92 ui::LayerAnimationObserver* observer); | 113 ui::LayerAnimationObserver* observer); |
93 | 114 |
94 // Animates all of the painted shape layers to the specified |transforms| and | 115 // Animates all of the painted shape layers to the specified |transforms|. The |
95 // |opacity|. The animation will use the given |duration| and | 116 // animation will be configured with the given |duration|, |tween|, and |
96 // |preemption_strategy|, and |observer| will be added to all | 117 // |preemption_strategy| values. The |observer| will be added to all |
97 // LayerAnimationSequences. | 118 // LayerAnimationSequences if not null. |
98 void AnimateToTransforms( | 119 void AnimateToTransforms( |
99 const InkDropTransforms transforms, | 120 const InkDropTransforms transforms, |
100 float opacity, | |
101 base::TimeDelta duration, | 121 base::TimeDelta duration, |
102 ui::LayerAnimator::PreemptionStrategy preemption_strategy, | 122 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 123 gfx::Tween::Type tween, |
103 ui::LayerAnimationObserver* observer); | 124 ui::LayerAnimationObserver* observer); |
104 | 125 |
105 // Updates the Transforms and opacity to the HIDDEN state. | 126 // Updates the Transforms and opacity to the HIDDEN state. |
106 void SetStateToHidden(); | 127 void SetStateToHidden(); |
107 | 128 |
108 // Sets the |transforms| on all of the shape layers. Note that this does not | 129 // Sets the |transforms| on all of the shape layers. Note that this does not |
109 // perform any animation. | 130 // perform any animation. |
110 void SetTransforms(const InkDropTransforms transforms); | 131 void SetTransforms(const InkDropTransforms transforms); |
111 | 132 |
| 133 // Gets the opacity of the ink drop. |
| 134 float GetCurrentOpacity() const; |
| 135 |
112 // Sets the opacity of the ink drop. | 136 // Sets the opacity of the ink drop. |
113 void SetOpacity(float opacity); | 137 void SetOpacity(float opacity); |
114 | 138 |
| 139 // Animates all of the painted shape layers to the specified |opacity|. The |
| 140 // animation will be configured with the given |duration|, |tween|, and |
| 141 // |preemption_strategy| values. The |observer| will be added to all |
| 142 // LayerAnimationSequences if not null. |
| 143 void AnimateToOpacity( |
| 144 float opacity, |
| 145 base::TimeDelta duration, |
| 146 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 147 gfx::Tween::Type tween, |
| 148 ui::LayerAnimationObserver* observer); |
| 149 |
115 // Updates all of the Transforms in |transforms_out| for a circle of the given | 150 // Updates all of the Transforms in |transforms_out| for a circle of the given |
116 // |size|. | 151 // |size|. |
117 void CalculateCircleTransforms(const gfx::Size& size, | 152 void CalculateCircleTransforms(const gfx::Size& size, |
118 InkDropTransforms* transforms_out) const; | 153 InkDropTransforms* transforms_out) const; |
119 | 154 |
120 // Updates all of the Transforms in |transforms_out| for a rounded rectangle | 155 // Updates all of the Transforms in |transforms_out| for a rounded rectangle |
121 // of the given |size| and |corner_radius|. | 156 // of the given |size| and |corner_radius|. |
122 void CalculateRectTransforms(const gfx::Size& size, | 157 void CalculateRectTransforms(const gfx::Size& size, |
123 float corner_radius, | 158 float corner_radius, |
124 InkDropTransforms* transforms_out) const; | 159 InkDropTransforms* transforms_out) const; |
125 | 160 |
126 // Updates all of the Transforms in |transforms_out| to the current target | 161 // Updates all of the Transforms in |transforms_out| to the current Transforms |
127 // Transforms of the Layers. | 162 // of the painted shape Layers. |
128 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; | 163 void GetCurrentTransforms(InkDropTransforms* transforms_out) const; |
129 | 164 |
130 // Adds and configures a new |painted_shape| layer to |painted_layers_|. | 165 // Adds and configures a new |painted_shape| layer to |painted_layers_|. |
131 void AddPaintLayer(PaintedShape painted_shape); | 166 void AddPaintLayer(PaintedShape painted_shape); |
132 | 167 |
133 void AbortAllAnimations(); | 168 void AbortAllAnimations(); |
134 | 169 |
135 // The Callback invoked when all of the animation sequences for the specific | 170 // The Callback invoked when all of the animation sequences for the specific |
136 // |ink_drop_state| animation have started. |observer| is the | 171 // |ink_drop_state| animation have started. |observer| is the |
137 // ui::CallbackLayerAnimationObserver which is notifying the callback. | 172 // ui::CallbackLayerAnimationObserver which is notifying the callback. |
138 void AnimationStartedCallback( | 173 void AnimationStartedCallback( |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 | 216 |
182 // List of observers to notify when animations have finished. | 217 // List of observers to notify when animations have finished. |
183 base::ObserverList<InkDropAnimationObserver> observers_; | 218 base::ObserverList<InkDropAnimationObserver> observers_; |
184 | 219 |
185 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | 220 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); |
186 }; | 221 }; |
187 | 222 |
188 } // namespace views | 223 } // namespace views |
189 | 224 |
190 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 225 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
OLD | NEW |