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

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

Issue 1495753002: Make the material design ripple effect more visible on a quick action (single click or single tap) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Polished for review. Created 4 years, 10 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 <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 in (where * means any
varkha 2016/01/28 20:50:45 nit: below in? nit: Did you want to use '*' below?
bruthig 2016/01/28 22:38:00 Removed mention of '*'.
44 // state):
45 //
46 // {All InkDropStates} => HIDDEN
47 // HIDDEN => ACTION_PENDING
48 // HIDDEN, ACTION_PENDING => QUICK_ACTION
49 // ACTION_PENDING => SLOW_ACTION_PENDING
50 // SLOW_ACTION_PENDING => SLOW_ACTION
51 // {All InkDropStates} => ACTIVATED
52 // {All InkDropStates} => DEACTIVATED
53 //
39 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to 54 // TODO(bruthig): Document the ink drop ripple on chromium.org and add a link to
40 // it. 55 // it.
41 class VIEWS_EXPORT InkDropAnimation { 56 class VIEWS_EXPORT InkDropAnimation {
42 public: 57 public:
43 InkDropAnimation(const gfx::Size& large_size, 58 InkDropAnimation(const gfx::Size& large_size,
44 int large_corner_radius, 59 int large_corner_radius,
45 const gfx::Size& small_size, 60 const gfx::Size& small_size,
46 int small_corner_radius); 61 int small_corner_radius);
47 ~InkDropAnimation(); 62 ~InkDropAnimation();
48 63
49 // The root Layer that can be added in to a Layer tree. 64 // The root Layer that can be added in to a Layer tree.
50 ui::Layer* root_layer() { return root_layer_.get(); } 65 ui::Layer* root_layer() { return root_layer_.get(); }
51 66
52 InkDropState ink_drop_state() const { return ink_drop_state_; } 67 InkDropState ink_drop_state() const { return ink_drop_state_; }
53 68
54 void AddObserver(InkDropAnimationObserver* observer); 69 void AddObserver(InkDropAnimationObserver* observer);
55 void RemoveObserver(InkDropAnimationObserver* observer); 70 void RemoveObserver(InkDropAnimationObserver* observer);
56 71
57 // Animates from the current |ink_drop_state_| to a new |ink_drop_state|. It 72 // 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); 73 void AnimateToState(InkDropState ink_drop_state);
63 74
64 // Sets the |center_point| of the ink drop layer relative to its parent Layer. 75 // Sets the |center_point| of the ink drop layer relative to its parent Layer.
65 void SetCenterPoint(const gfx::Point& center_point); 76 void SetCenterPoint(const gfx::Point& center_point);
66 77
78 // Immediately hides the ink drop and sets the state to InkDropState::HIDDEN.
79 // All in-progress animations will be aborted.
varkha 2016/01/28 20:50:45 Nit: How about "Imediately aborts all in-progress
bruthig 2016/01/28 22:38:00 Done.
80 // NOTE: This will NOT raise InkDropAnimation(Started|Ended) events for the
81 // state transition to HIDDEN!
82 void HideImmediately();
83
67 private: 84 private:
68 friend class test::InkDropAnimationTestApi; 85 friend class test::InkDropAnimationTestApi;
69 86
70 // Enumeration of the different shapes that compose the ink drop. 87 // Enumeration of the different shapes that compose the ink drop.
71 enum PaintedShape { 88 enum PaintedShape {
72 TOP_LEFT_CIRCLE = 0, 89 TOP_LEFT_CIRCLE = 0,
73 TOP_RIGHT_CIRCLE, 90 TOP_RIGHT_CIRCLE,
74 BOTTOM_RIGHT_CIRCLE, 91 BOTTOM_RIGHT_CIRCLE,
75 BOTTOM_LEFT_CIRCLE, 92 BOTTOM_LEFT_CIRCLE,
76 HORIZONTAL_RECT, 93 HORIZONTAL_RECT,
77 VERTICAL_RECT, 94 VERTICAL_RECT,
78 // The total number of shapes, not an actual shape. 95 // The total number of shapes, not an actual shape.
79 PAINTED_SHAPE_COUNT 96 PAINTED_SHAPE_COUNT
80 }; 97 };
81 98
82 // Returns a human readable string for the |painted_shape| value. 99 // Returns a human readable string for the |painted_shape| value.
83 static std::string ToLayerName(PaintedShape painted_shape); 100 static std::string ToLayerName(PaintedShape painted_shape);
84 101
85 // Type that contains a gfx::Tansform for each of the layers required by the 102 // Type that contains a gfx::Tansform for each of the layers required by the
86 // ink drop. 103 // ink drop.
87 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT]; 104 typedef gfx::Transform InkDropTransforms[PAINTED_SHAPE_COUNT];
88 105
89 // Animates the ripple to |ink_drop_state| and attaches |observer| to all 106 // Animates the ripple to |ink_drop_state| and attaches |observer| to all
90 // LayerAnimationSequence's used. 107 // LayerAnimationSequence's used.
91 void AnimateToStateInternal(InkDropState ink_drop_state, 108 void AnimateToStateInternal(InkDropState ink_drop_state,
92 ui::LayerAnimationObserver* observer); 109 ui::LayerAnimationObserver* observer);
93 110
94 // Animates all of the painted shape layers to the specified |transforms| and 111 // Animates all of the painted shape layers to the specified |transforms|. The
95 // |opacity|. The animation will use the given |duration| and 112 // animation will use the given |duration|, |preemption_strategy|, and |tween|
varkha 2016/01/28 20:50:45 Maybe break into a second sentence after |preempti
bruthig 2016/01/28 22:38:00 Re-worded a bit, PTAL
96 // |preemption_strategy|, and |observer| will be added to all 113 // and |observer| will be added to all LayerAnimationSequences.
97 // LayerAnimationSequences.
98 void AnimateToTransforms( 114 void AnimateToTransforms(
99 const InkDropTransforms transforms, 115 const InkDropTransforms transforms,
100 float opacity,
101 base::TimeDelta duration, 116 base::TimeDelta duration,
102 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 117 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
118 gfx::Tween::Type tween,
103 ui::LayerAnimationObserver* observer); 119 ui::LayerAnimationObserver* observer);
104 120
105 // Updates the Transforms and opacity to the HIDDEN state. 121 // Updates the Transforms and opacity to the HIDDEN state.
106 void SetStateToHidden(); 122 void SetStateToHidden();
107 123
108 // Sets the |transforms| on all of the shape layers. Note that this does not 124 // Sets the |transforms| on all of the shape layers. Note that this does not
109 // perform any animation. 125 // perform any animation.
110 void SetTransforms(const InkDropTransforms transforms); 126 void SetTransforms(const InkDropTransforms transforms);
111 127
128 // Gets the opacity of the ink drop.
129 float GetCurrentOpacity() const;
130
112 // Sets the opacity of the ink drop. 131 // Sets the opacity of the ink drop.
113 void SetOpacity(float opacity); 132 void SetOpacity(float opacity);
114 133
134 // Animates all of the painted shape layers to the specified |opacity|. The
135 // animation will use the given |duration|, |preemption_strategy|, and |tween|
136 // and |observer| will be added to all LayerAnimationSequences.
varkha 2016/01/28 20:50:45 s/observer/animation_observer Maybe also break out
bruthig 2016/01/28 22:38:00 Re-worded a bit, PTAL.
137 void AnimateToOpacity(
138 float opacity,
139 base::TimeDelta duration,
140 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
141 gfx::Tween::Type tween,
142 ui::LayerAnimationObserver* animation_observer);
143
115 // Updates all of the Transforms in |transforms_out| for a circle of the given 144 // Updates all of the Transforms in |transforms_out| for a circle of the given
116 // |size|. 145 // |size|.
117 void CalculateCircleTransforms(const gfx::Size& size, 146 void CalculateCircleTransforms(const gfx::Size& size,
118 InkDropTransforms* transforms_out) const; 147 InkDropTransforms* transforms_out) const;
119 148
120 // Updates all of the Transforms in |transforms_out| for a rounded rectangle 149 // Updates all of the Transforms in |transforms_out| for a rounded rectangle
121 // of the given |size| and |corner_radius|. 150 // of the given |size| and |corner_radius|.
122 void CalculateRectTransforms(const gfx::Size& size, 151 void CalculateRectTransforms(const gfx::Size& size,
123 float corner_radius, 152 float corner_radius,
124 InkDropTransforms* transforms_out) const; 153 InkDropTransforms* transforms_out) const;
125 154
126 // Updates all of the Transforms in |transforms_out| to the current target 155 // Updates all of the Transforms in |transforms_out| to the current Transforms
127 // Transforms of the Layers. 156 // of the painted shape Layers.
128 void GetCurrentTansforms(InkDropTransforms* transforms_out) const; 157 void GetCurrentTransforms(InkDropTransforms* transforms_out) const;
129 158
130 // Adds and configures a new |painted_shape| layer to |painted_layers_|. 159 // Adds and configures a new |painted_shape| layer to |painted_layers_|.
131 void AddPaintLayer(PaintedShape painted_shape); 160 void AddPaintLayer(PaintedShape painted_shape);
132 161
133 void AbortAllAnimations(); 162 void AbortAllAnimations();
134 163
135 // The Callback invoked when all of the animation sequences for the specific 164 // The Callback invoked when all of the animation sequences for the specific
136 // |ink_drop_state| animation have started. |observer| is the 165 // |ink_drop_state| animation have started. |observer| is the
137 // ui::CallbackLayerAnimationObserver which is notifying the callback. 166 // ui::CallbackLayerAnimationObserver which is notifying the callback.
138 void AnimationStartedCallback( 167 void AnimationStartedCallback(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 210
182 // List of observers to notify when animations have finished. 211 // List of observers to notify when animations have finished.
183 base::ObserverList<InkDropAnimationObserver> observers_; 212 base::ObserverList<InkDropAnimationObserver> observers_;
184 213
185 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation); 214 DISALLOW_COPY_AND_ASSIGN(InkDropAnimation);
186 }; 215 };
187 216
188 } // namespace views 217 } // namespace views
189 218
190 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_ 219 #endif // UI_VIEWS_ANIMATION_INK_DROP_ANIMATION_H_
OLDNEW
« no previous file with comments | « no previous file | ui/views/animation/ink_drop_animation.cc » ('j') | ui/views/animation/ink_drop_animation.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698