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/time/time.h" | 11 #include "base/time/time.h" |
11 #include "ui/compositor/layer_animator.h" | 12 #include "ui/compositor/layer_animator.h" |
12 #include "ui/gfx/geometry/size.h" | 13 #include "ui/gfx/geometry/size.h" |
13 #include "ui/gfx/geometry/size_f.h" | 14 #include "ui/gfx/geometry/size_f.h" |
14 #include "ui/gfx/transform.h" | 15 #include "ui/gfx/transform.h" |
15 #include "ui/views/animation/ink_drop_state.h" | 16 #include "ui/views/animation/ink_drop_state.h" |
16 #include "ui/views/views_export.h" | 17 #include "ui/views/views_export.h" |
17 | 18 |
18 namespace ui { | 19 namespace ui { |
| 20 class CallbackLayerAnimationObserver; |
19 class Layer; | 21 class Layer; |
| 22 class LayerAnimationObserver; |
20 class LayerDelegate; | 23 class LayerDelegate; |
21 } // namespace ui | 24 } // namespace ui |
22 | 25 |
23 namespace views { | 26 namespace views { |
24 class CircleLayerDelegate; | 27 class CircleLayerDelegate; |
| 28 class InkDropAnimationObserver; |
25 class RectangleLayerDelegate; | 29 class RectangleLayerDelegate; |
26 | 30 |
27 namespace test { | 31 namespace test { |
28 class InkDropAnimationTestApi; | 32 class InkDropAnimationTestApi; |
29 } // namespace test | 33 } // namespace test |
30 | 34 |
31 // An ink drop animation that smoothly animates between a circle and a rounded | 35 // An ink drop animation that smoothly animates between a circle and a rounded |
32 // rectangle of different sizes for each of the different InkDropStates. The | 36 // rectangle of different sizes for each of the different InkDropStates. The |
33 // final frame for each InkDropState will be bounded by either a |large_size_| | 37 // final frame for each InkDropState will be bounded by either a |large_size_| |
34 // rectangle or a |small_size_| rectangle. | 38 // rectangle or a |small_size_| rectangle. |
35 // | 39 // |
36 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to | 40 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to |
37 // it. | 41 // it. |
38 class VIEWS_EXPORT InkDropAnimation { | 42 class VIEWS_EXPORT InkDropAnimation { |
39 public: | 43 public: |
40 InkDropAnimation(const gfx::Size& large_size, | 44 InkDropAnimation(const gfx::Size& large_size, |
41 int large_corner_radius, | 45 int large_corner_radius, |
42 const gfx::Size& small_size, | 46 const gfx::Size& small_size, |
43 int small_corner_radius); | 47 int small_corner_radius); |
44 ~InkDropAnimation(); | 48 ~InkDropAnimation(); |
45 | 49 |
46 // The root Layer that can be added in to a Layer tree. | 50 // The root Layer that can be added in to a Layer tree. |
47 ui::Layer* root_layer() { return root_layer_.get(); } | 51 ui::Layer* root_layer() { return root_layer_.get(); } |
48 | 52 |
49 InkDropState ink_drop_state() const { return ink_drop_state_; } | 53 InkDropState ink_drop_state() const { return ink_drop_state_; } |
50 | 54 |
| 55 void AddObserver(InkDropAnimationObserver* observer); |
| 56 void RemoveObserver(InkDropAnimationObserver* observer); |
| 57 |
51 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It | 58 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It |
52 // is possible to animate from any |ink_drop_state_| to any new | 59 // is possible to animate from any |ink_drop_state_| to any new |
53 // |ink_drop_state|. Note that some state transitions will also perform an | 60 // |ink_drop_state|. Note that some state transitions will also perform an |
54 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION) | 61 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION) |
55 // will implicitly transition to the HIDDEN state. | 62 // will implicitly transition to the HIDDEN state. |
56 void AnimateToState(InkDropState ink_drop_state); | 63 void AnimateToState(InkDropState ink_drop_state); |
57 | 64 |
58 // Sets the |center_point| of the ink drop layer relative to its parent Layer. | 65 // Sets the |center_point| of the ink drop layer relative to its parent Layer. |
59 void SetCenterPoint(const gfx::Point& center_point); | 66 void SetCenterPoint(const gfx::Point& center_point); |
60 | 67 |
61 private: | 68 private: |
62 friend class test::InkDropAnimationTestApi; | 69 friend class test::InkDropAnimationTestApi; |
63 | 70 |
64 // Enumeration of the different shapes that compose the ink drop. | 71 // Enumeration of the different shapes that compose the ink drop. |
65 enum PaintedShape { | 72 enum PaintedShape { |
66 TOP_LEFT_CIRCLE = 0, | 73 TOP_LEFT_CIRCLE = 0, |
67 TOP_RIGHT_CIRCLE, | 74 TOP_RIGHT_CIRCLE, |
68 BOTTOM_RIGHT_CIRCLE, | 75 BOTTOM_RIGHT_CIRCLE, |
69 BOTTOM_LEFT_CIRCLE, | 76 BOTTOM_LEFT_CIRCLE, |
70 HORIZONTAL_RECT, | 77 HORIZONTAL_RECT, |
71 VERTICAL_RECT, | 78 VERTICAL_RECT, |
72 // The total number of shapes, not an actual shape. | 79 // The total number of shapes, not an actual shape. |
73 PAINTED_SHAPE_COUNT | 80 PAINTED_SHAPE_COUNT |
74 }; | 81 }; |
75 | 82 |
76 // Type that contains a gfx::Tansform for each of the layers required by the | 83 // Type that contains a gfx::Tansform for each of the layers required by the |
77 // ink drop. | 84 // ink drop. |
78 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; | 85 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; |
79 | 86 |
| 87 // Animates the ripple to |ink_drop_state| and attaches |observer| to all |
| 88 // LayerAnimationSequence's used. |
| 89 void AnimateToStateInternal(InkDropState ink_drop_state, |
| 90 ui::LayerAnimationObserver* observer); |
| 91 |
80 // Animates all of the painted shape layers to the specified |transforms| and | 92 // Animates all of the painted shape layers to the specified |transforms| and |
81 // |opacity|. | 93 // |opacity|. The animation will use the given |duration| and |
| 94 // |preemption_strategy|, and |observer| will be added to all |
| 95 // LayerAnimationSequences. |
82 void AnimateToTransforms( | 96 void AnimateToTransforms( |
83 const InkDropTransforms transforms, | 97 const InkDropTransforms transforms, |
84 float opacity, | 98 float opacity, |
85 base::TimeDelta duration, | 99 base::TimeDelta duration, |
86 ui::LayerAnimator::PreemptionStrategy preemption_strategy); | 100 ui::LayerAnimator::PreemptionStrategy preemption_strategy, |
| 101 ui::LayerAnimationObserver* observer); |
87 | 102 |
88 // Resets the Transforms on all the owned Layers to a minimum size. | 103 // Updates the Transforms and opacity to the HIDDEN state. |
89 void ResetTransformsToMinSize(); | 104 void SetStateToHidden(); |
90 | 105 |
91 // Sets the |transforms| on all of the shape layers. Note that this does not | 106 // Sets the |transforms| on all of the shape layers. Note that this does not |
92 // perform any animation. | 107 // perform any animation. |
93 void SetTransforms(const InkDropTransforms transforms); | 108 void SetTransforms(const InkDropTransforms transforms); |
94 | 109 |
95 // Sets the opacity of the ink drop. | 110 // Sets the opacity of the ink drop. |
96 void SetOpacity(float opacity); | 111 void SetOpacity(float opacity); |
97 | 112 |
98 // Updates all of the Transforms in |transforms_out| for a circle of the given | 113 // Updates all of the Transforms in |transforms_out| for a circle of the given |
99 // |size|. | 114 // |size|. |
100 void CalculateCircleTransforms(const gfx::Size& size, | 115 void CalculateCircleTransforms(const gfx::Size& size, |
101 InkDropTransforms* transforms_out) const; | 116 InkDropTransforms* transforms_out) const; |
102 | 117 |
103 // Updates all of the Transforms in |transforms_out| for a rounded rectangle | 118 // Updates all of the Transforms in |transforms_out| for a rounded rectangle |
104 // of the given |size| and |corner_radius|. | 119 // of the given |size| and |corner_radius|. |
105 void CalculateRectTransforms(const gfx::Size& size, | 120 void CalculateRectTransforms(const gfx::Size& size, |
106 float corner_radius, | 121 float corner_radius, |
107 InkDropTransforms* transforms_out) const; | 122 InkDropTransforms* transforms_out) const; |
108 | 123 |
109 // Updates all of the Transforms in |transforms_out| to the current target | 124 // Updates all of the Transforms in |transforms_out| to the current target |
110 // Transforms of the Layers. | 125 // Transforms of the Layers. |
111 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; | 126 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; |
112 | 127 |
113 // Adds and configures a new |painted_shape| layer to |painted_layers_|. | 128 // Adds and configures a new |painted_shape| layer to |painted_layers_|. |
114 void AddPaintLayer(PaintedShape painted_shape); | 129 void AddPaintLayer(PaintedShape painted_shape); |
115 | 130 |
| 131 void AbortAllAnimations(); |
| 132 |
| 133 // The Callback invoked when all of the animation sequences for the specific |
| 134 // |ink_drop_state| animation have started. |observer| is the |
| 135 // ui::CallbackLayerAnimationObserver which is notifying the callback. |
| 136 void AnimationStartedCallback( |
| 137 InkDropState ink_drop_state, |
| 138 const ui::CallbackLayerAnimationObserver& observer); |
| 139 |
| 140 // The Callback invoked when all of the animation sequences for the specific |
| 141 // |ink_drop_state| animation have finished. |observer| is the |
| 142 // ui::CallbackLayerAnimationObserver which is notifying the callback. |
| 143 bool AnimationEndedCallback( |
| 144 InkDropState ink_drop_state, |
| 145 const ui::CallbackLayerAnimationObserver& observer); |
| 146 |
116 // Maximum size that an ink drop will be drawn to for any InkDropState whose | 147 // Maximum size that an ink drop will be drawn to for any InkDropState whose |
117 // final frame should be large. | 148 // final frame should be large. |
118 gfx::Size large_size_; | 149 gfx::Size large_size_; |
119 | 150 |
120 // Corner radius used to draw the rounded rectangles corner for any | 151 // Corner radius used to draw the rounded rectangles corner for any |
121 // InkDropState whose final frame should be large. | 152 // InkDropState whose final frame should be large. |
122 int large_corner_radius_; | 153 int large_corner_radius_; |
123 | 154 |
124 // Maximum size that an ink drop will be drawn to for any InkDropState whose | 155 // Maximum size that an ink drop will be drawn to for any InkDropState whose |
125 // final frame should be small. | 156 // final frame should be small. |
(...skipping 13 matching lines...) Expand all Loading... |
139 // manipulate opacity and location, and its children are used to manipulate | 170 // manipulate opacity and location, and its children are used to manipulate |
140 // the different painted shapes that compose the ink drop. | 171 // the different painted shapes that compose the ink drop. |
141 scoped_ptr<ui::Layer> root_layer_; | 172 scoped_ptr<ui::Layer> root_layer_; |
142 | 173 |
143 // ui::Layers for all of the painted shape layers that compose the ink drop. | 174 // ui::Layers for all of the painted shape layers that compose the ink drop. |
144 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; | 175 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; |
145 | 176 |
146 // The current ink drop state. | 177 // The current ink drop state. |
147 InkDropState ink_drop_state_; | 178 InkDropState ink_drop_state_; |
148 | 179 |
| 180 // List of observers to notify when animations have finished. |
| 181 base::ObserverList<InkDropAnimationObserver> observers_; |
| 182 |
149 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); | 183 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); |
150 }; | 184 }; |
151 | 185 |
152 } // namespace views | 186 } // namespace views |
153 | 187 |
154 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ | 188 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ |
OLD | NEW |