Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: ui/views/animation/ink_drop_animation.h

Issue 1373983002: Enhanced the InkDropRippleImpl to create/destroy InkDropAnimations as needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Based diff delta on dependant branch. Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
57 void RemoveObserver(InkDropAnimationObserver* observer);
sadrul 2015/10/08 01:06:01 - the newline
bruthig 2015/10/08 21:42:55 Done.
58
51 // 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
52 // 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
53 // |ink_drop_state|. Note that some state transitions will also perform an 61 // |ink_drop_state|. Note that some state transitions will also perform an
54 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION) 62 // implicit transition to the another state. e.g. AnimateToState(QUICK_ACTION)
55 // will implicitly transition to the HIDDEN state. 63 // will implicitly transition to the HIDDEN state.
56 void AnimateToState(InkDropState ink_drop_state); 64 void AnimateToState(InkDropState ink_drop_state);
57 65
58 // Sets the |center_point| of the ink drop layer relative to its parent Layer. 66 // Sets the |center_point| of the ink drop layer relative to its parent Layer.
59 void SetCenterPoint(const gfx::Point& center_point); 67 void SetCenterPoint(const gfx::Point& center_point);
60 68
61 private: 69 private:
62 friend class test::InkDropAnimationTestApi; 70 friend class test::InkDropAnimationTestApi;
63 71
64 // Enumeration of the different shapes that compose the ink drop. 72 // Enumeration of the different shapes that compose the ink drop.
65 enum PaintedShape { 73 enum PaintedShape {
66 TOP_LEFT_CIRCLE = 0, 74 TOP_LEFT_CIRCLE = 0,
67 TOP_RIGHT_CIRCLE, 75 TOP_RIGHT_CIRCLE,
68 BOTTOM_RIGHT_CIRCLE, 76 BOTTOM_RIGHT_CIRCLE,
69 BOTTOM_LEFT_CIRCLE, 77 BOTTOM_LEFT_CIRCLE,
70 HORIZONTAL_RECT, 78 HORIZONTAL_RECT,
71 VERTICAL_RECT, 79 VERTICAL_RECT,
72 // The total number of shapes, not an actual shape. 80 // The total number of shapes, not an actual shape.
73 PAINTED_SHAPE_COUNT 81 PAINTED_SHAPE_COUNT
74 }; 82 };
75 83
76 // Type that contains a gfx::Tansform for each of the layers required by the 84 // Type that contains a gfx::Tansform for each of the layers required by the
77 // ink drop. 85 // ink drop.
78 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; 86 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT];
79 87
88 // Animates the ripple to |ink_drop_state| and attaches |observer| to all
89 // LayerAnimationSequence's used.
90 void AnimateToStateInternal(InkDropState ink_drop_state,
91 ui::LayerAnimationObserver* observer);
92
80 // Animates all of the painted shape layers to the specified |transforms| and 93 // Animates all of the painted shape layers to the specified |transforms| and
81 // |opacity|. 94 // |opacity|. The animation will use the given |duration| and
95 // |preemption_strategy|, and |observer| will be added to all
96 // LayerAnimationSequences.
82 void AnimateToTransforms( 97 void AnimateToTransforms(
83 const InkDropTransforms transforms, 98 const InkDropTransforms transforms,
84 float opacity, 99 float opacity,
85 base::TimeDelta duration, 100 base::TimeDelta duration,
86 ui::LayerAnimator::PreemptionStrategy preemption_strategy); 101 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
102 ui::LayerAnimationObserver* observer);
87 103
88 // Resets the Transforms on all the owned Layers to a minimum size. 104 // Updates the Transforms and opacity to the HIDDEN state.
89 void ResetTransformsToMinSize(); 105 void SetStateToHidden();
90 106
91 // Sets the |transforms| on all of the shape layers. Note that this does not 107 // Sets the |transforms| on all of the shape layers. Note that this does not
92 // perform any animation. 108 // perform any animation.
93 void SetTransforms(const InkDropTransforms transforms); 109 void SetTransforms(const InkDropTransforms transforms);
94 110
95 // Sets the opacity of the ink drop. 111 // Sets the opacity of the ink drop.
96 void SetOpacity(float opacity); 112 void SetOpacity(float opacity);
97 113
98 // Updates all of the Transforms in |transforms_out| for a circle of the given 114 // Updates all of the Transforms in |transforms_out| for a circle of the given
99 // |size|. 115 // |size|.
100 void CalculateCircleTransforms(const gfx::Size& size, 116 void CalculateCircleTransforms(const gfx::Size& size,
101 InkDropTransforms* transforms_out) const; 117 InkDropTransforms* transforms_out) const;
102 118
103 // Updates all of the Transforms in |transforms_out| for a rounded rectangle 119 // Updates all of the Transforms in |transforms_out| for a rounded rectangle
104 // of the given |size| and |corner_radius|. 120 // of the given |size| and |corner_radius|.
105 void CalculateRectTransforms(const gfx::Size& size, 121 void CalculateRectTransforms(const gfx::Size& size,
106 float corner_radius, 122 float corner_radius,
107 InkDropTransforms* transforms_out) const; 123 InkDropTransforms* transforms_out) const;
108 124
109 // Updates all of the Transforms in |transforms_out| to the current target 125 // Updates all of the Transforms in |transforms_out| to the current target
110 // Transforms of the Layers. 126 // Transforms of the Layers.
111 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; 127 void GetCurrentTansforms(InkDropTransforms* transforms_out) const;
112 128
113 // Adds and configures a new |painted_shape| layer to |painted_layers_|. 129 // Adds and configures a new |painted_shape| layer to |painted_layers_|.
114 void AddPaintLayer(PaintedShape painted_shape); 130 void AddPaintLayer(PaintedShape painted_shape);
115 131
132 void AbortAllAnimations();
133
134 // The Callback invoked when all of the animation sequences for the specific
135 // |ink_drop_state| animation have started.
varkha 2015/10/06 20:58:38 Can you document |observer|?
bruthig 2015/10/08 21:42:55 Done.
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.
142 bool AnimationEndedCallback(
143 InkDropState ink_drop_state,
144 const ui::CallbackLayerAnimationObserver& observer);
145
116 // Maximum size that an ink drop will be drawn to for any InkDropState whose 146 // Maximum size that an ink drop will be drawn to for any InkDropState whose
117 // final frame should be large. 147 // final frame should be large.
118 gfx::Size large_size_; 148 gfx::Size large_size_;
119 149
120 // Corner radius used to draw the rounded rectangles corner for any 150 // Corner radius used to draw the rounded rectangles corner for any
121 // InkDropState whose final frame should be large. 151 // InkDropState whose final frame should be large.
122 int large_corner_radius_; 152 int large_corner_radius_;
123 153
124 // Maximum size that an ink drop will be drawn to for any InkDropState whose 154 // Maximum size that an ink drop will be drawn to for any InkDropState whose
125 // final frame should be small. 155 // final frame should be small.
(...skipping 13 matching lines...) Expand all
139 // manipulate opacity and location, and its children are used to manipulate 169 // manipulate opacity and location, and its children are used to manipulate
140 // the different painted shapes that compose the ink drop. 170 // the different painted shapes that compose the ink drop.
141 scoped_ptr<ui::Layer> root_layer_; 171 scoped_ptr<ui::Layer> root_layer_;
142 172
143 // ui::Layers for all of the painted shape layers that compose the ink drop. 173 // ui::Layers for all of the painted shape layers that compose the ink drop.
144 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT]; 174 scoped_ptr<ui::Layer> painted_layers_[PAINTED_SHAPE_COUNT];
145 175
146 // The current ink drop state. 176 // The current ink drop state.
147 InkDropState ink_drop_state_; 177 InkDropState ink_drop_state_;
148 178
179 // List of observers to notify when animations have finished.
180 base::ObserverList<InkDropAnimationObserver> observers_;
181
149 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); 182 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation);
150 }; 183 };
151 184
152 } // namespace views 185 } // namespace views
153 186
154 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ 187 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698