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

Side by Side Diff: ui/views/animation/flood_fill_ink_drop_animation.cc

Issue 1832963002: MD - add ripples to DL shelf items (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updates after bruthig chat Created 4 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 #include "ui/views/animation/flood_fill_ink_drop_animation.h" 5 #include "ui/views/animation/flood_fill_ink_drop_animation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "third_party/skia/include/core/SkColor.h" 10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/compositor/layer.h" 11 #include "ui/compositor/layer.h"
12 #include "ui/compositor/layer_animation_sequence.h" 12 #include "ui/compositor/layer_animation_sequence.h"
13 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
14 #include "ui/gfx/geometry/point_conversions.h" 14 #include "ui/gfx/geometry/point_conversions.h"
15 #include "ui/gfx/geometry/vector2d_f.h" 15 #include "ui/gfx/geometry/vector2d_f.h"
16 16
17 namespace { 17 namespace {
18 18
19 // The minimum radius to use when scaling the painted layers. Smaller values 19 // The minimum radius to use when scaling the painted layers. Smaller values
20 // were causing visual anomalies. 20 // were causing visual anomalies.
21 const float kMinRadius = 0.01f; 21 const float kMinRadius = 1.f;
22 22
23 // All the sub animations that are used to animate each of the InkDropStates. 23 // All the sub animations that are used to animate each of the InkDropStates.
24 // These are used to get time durations with 24 // These are used to get time durations with
25 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub 25 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub
26 // animation defines the duration for either a transformation animation or an 26 // animation defines the duration for either a transformation animation or an
27 // opacity animation but there are some exceptions where an entire InkDropState 27 // opacity animation but there are some exceptions where an entire InkDropState
28 // animation consists of only 1 sub animation and it defines the duration for 28 // animation consists of only 1 sub animation and it defines the duration for
29 // both the transformation and opacity animations. 29 // both the transformation and opacity animations.
30 enum InkDropSubAnimations { 30 enum InkDropSubAnimations {
31 // HIDDEN sub animations. 31 // HIDDEN sub animations.
32 32
33 // The HIDDEN sub animation that is fading out to a hidden opacity. 33 // The HIDDEN sub animation that is fading out to a hidden opacity.
34 HIDDEN_FADE_OUT, 34 HIDDEN_FADE_OUT,
35 35
36 // The HIDDEN sub animation that transform the circle to a small one. 36 // The HIDDEN sub animation that transform the circle to a small one.
37 HIDDEN_TRANSFORM, 37 HIDDEN_TRANSFORM,
38 38
39 // ACTION_PENDING sub animations. 39 // ACTION_PENDING sub animations.
40 40
41 // The ACTION_PENDING sub animation that fades in to the visible opacity. 41 // The ACTION_PENDING sub animation that fades in to the visible opacity.
42 ACTION_PENDING_FADE_IN, 42 ACTION_PENDING_FADE_IN,
43 43
44 // The ACTION_PENDING sub animation that transforms the circle to fill the 44 // The ACTION_PENDING sub animation that transforms the circle to fill the
45 // bounds. 45 // bounds.
46 ACTION_PENDING_TRANSFORM, 46 ACTION_PENDING_TRANSFORM,
47 47
48 // QUICK_ACTION sub animations. 48 // ACTION_TRIGGERED sub animations.
49 49
50 // The QUICK_ACTION sub animation that is fading out to a hidden opacity. 50 // The ACTION_TRIGGERED sub animation that is fading out to a hidden opacity.
51 QUICK_ACTION_FADE_OUT, 51 ACTION_TRIGGERED_FADE_OUT,
52 52
53 // SLOW_ACTION_PENDING sub animations. 53 // ALTERNATE_ACTION_PENDING sub animations.
54 54
55 // The SLOW_ACTION_PENDING animation has only one sub animation which animates 55 // The ALTERNATE_ACTION_PENDING animation has only one sub animation which
56 // animates
56 // the circleto fill the bounds at visible opacity. 57 // the circleto fill the bounds at visible opacity.
57 SLOW_ACTION_PENDING, 58 ALTERNATE_ACTION_PENDING,
58 59
59 // SLOW_ACTION sub animations. 60 // ALTERNATE_ACTION_TRIGGERED sub animations.
60 61
61 // The SLOW_ACTION sub animation that is fading out to a hidden opacity. 62 // The ALTERNATE_ACTION_TRIGGERED sub animation that is fading out to a hidden
62 SLOW_ACTION_FADE_OUT, 63 // opacity.
64 ALTERNATE_ACTION_TRIGGERED_FADE_OUT,
63 65
64 // ACTIVATED sub animations. 66 // ACTIVATED sub animations.
65 67
66 // The ACTIVATED sub animation that is fading in to the visible opacity. 68 // The ACTIVATED sub animation that is fading in to the visible opacity.
67 ACTIVATED_FADE_IN, 69 ACTIVATED_FADE_IN,
68 70
69 // The ACTIVATED sub animation that transforms the circle to fill the entire 71 // The ACTIVATED sub animation that transforms the circle to fill the entire
70 // bounds. 72 // bounds.
71 ACTIVATED_TRANSFORM, 73 ACTIVATED_TRANSFORM,
72 74
73 // DEACTIVATED sub animations. 75 // DEACTIVATED sub animations.
74 76
75 // The DEACTIVATED sub animation that is fading out to a hidden opacity. 77 // The DEACTIVATED sub animation that is fading out to a hidden opacity.
76 DEACTIVATED_FADE_OUT, 78 DEACTIVATED_FADE_OUT,
77 }; 79 };
78 80
79 // Duration constants for InkDropStateSubAnimations. See the 81 // Duration constants for InkDropStateSubAnimations. See the
80 // InkDropStateSubAnimations enum documentation for more info. 82 // InkDropStateSubAnimations enum documentation for more info.
81 int kAnimationDurationInMs[] = { 83 int kAnimationDurationInMs[] = {
82 200, // HIDDEN_FADE_OUT 84 200, // HIDDEN_FADE_OUT
83 300, // HIDDEN_TRANSFORM 85 300, // HIDDEN_TRANSFORM
84 0, // ACTION_PENDING_FADE_IN 86 0, // ACTION_PENDING_FADE_IN
85 240, // ACTION_PENDING_TRANSFORM 87 240, // ACTION_PENDING_TRANSFORM
86 300, // QUICK_ACTION_FADE_OUT 88 300, // ACTION_TRIGGERED_FADE_OUT
87 200, // SLOW_ACTION_PENDING 89 200, // ALTERNATE_ACTION_PENDING
88 300, // SLOW_ACTION_FADE_OUT 90 300, // ALTERNATE_ACTION_TRIGGERED_FADE_OUT
89 150, // ACTIVATED_FADE_IN 91 150, // ACTIVATED_FADE_IN
90 200, // ACTIVATED_TRANSFORM 92 200, // ACTIVATED_TRANSFORM
91 300, // DEACTIVATED_FADE_OUT 93 300, // DEACTIVATED_FADE_OUT
92 }; 94 };
93 95
94 // Returns the InkDropState sub animation duration for the given |state|. 96 // Returns the InkDropState sub animation duration for the given |state|.
95 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) { 97 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
96 return base::TimeDelta::FromMilliseconds( 98 return base::TimeDelta::FromMilliseconds(
97 (views::InkDropAnimation::UseFastAnimations() 99 (views::InkDropAnimation::UseFastAnimations()
98 ? 1 100 ? 1
99 : views::InkDropAnimation::kSlowAnimationDurationFactor) * 101 : views::InkDropAnimation::kSlowAnimationDurationFactor) *
100 kAnimationDurationInMs[state]); 102 kAnimationDurationInMs[state]);
101 } 103 }
102 104
103 // Calculates the largest distance from |point| to the corners of a rectangle
104 // with origin (0, 0) and the given |size|.
105 float CalculateLargestDistanceToCorners(const gfx::Size& size,
106 const gfx::Point& point) {
107 const float top_left_distance = gfx::Vector2dF(point.x(), point.y()).Length();
108 const float top_right_distance =
109 gfx::Vector2dF(size.width() - point.x(), point.y()).Length();
110 const float bottom_left_distance =
111 gfx::Vector2dF(point.x(), size.height() - point.y()).Length();
112 const float bottom_right_distance =
113 gfx::Vector2dF(size.width() - point.x(), size.height() - point.y())
114 .Length();
115
116 float largest_distance = std::max(top_left_distance, top_right_distance);
117 largest_distance = std::max(largest_distance, bottom_left_distance);
118 largest_distance = std::max(largest_distance, bottom_right_distance);
119 return largest_distance;
120 }
121
122 } // namespace 105 } // namespace
123 106
124 namespace views { 107 namespace views {
125 108
126 FloodFillInkDropAnimation::FloodFillInkDropAnimation( 109 FloodFillInkDropAnimation::FloodFillInkDropAnimation(
127 const gfx::Size& size, 110 const gfx::Size& size,
128 const gfx::Point& center_point, 111 const gfx::Point& center_point,
129 SkColor color) 112 SkColor color)
130 : size_(size), 113 : size_(size),
131 center_point_(center_point), 114 center_point_(center_point),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 156 }
174 157
175 void FloodFillInkDropAnimation::AnimateStateChange( 158 void FloodFillInkDropAnimation::AnimateStateChange(
176 InkDropState old_ink_drop_state, 159 InkDropState old_ink_drop_state,
177 InkDropState new_ink_drop_state, 160 InkDropState new_ink_drop_state,
178 ui::LayerAnimationObserver* animation_observer) { 161 ui::LayerAnimationObserver* animation_observer) {
179 switch (new_ink_drop_state) { 162 switch (new_ink_drop_state) {
180 case InkDropState::HIDDEN: 163 case InkDropState::HIDDEN:
181 if (!IsVisible()) { 164 if (!IsVisible()) {
182 SetStateToHidden(); 165 SetStateToHidden();
183 break;
184 } else { 166 } else {
185 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT), 167 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT),
186 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 168 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
187 gfx::Tween::EASE_IN_OUT, animation_observer); 169 gfx::Tween::EASE_IN_OUT, animation_observer);
188 const gfx::Transform transform = CalculateTransform(kMinRadius); 170 const gfx::Transform transform = CalculateTransform(kMinRadius);
189 AnimateToTransform(transform, GetAnimationDuration(HIDDEN_TRANSFORM), 171 AnimateToTransform(transform, GetAnimationDuration(HIDDEN_TRANSFORM),
190 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 172 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
191 gfx::Tween::EASE_IN_OUT, animation_observer); 173 gfx::Tween::EASE_IN_OUT, animation_observer);
192 } 174 }
193 break; 175 break;
194 case InkDropState::ACTION_PENDING: { 176 case InkDropState::ACTION_PENDING: {
195 DCHECK(old_ink_drop_state == InkDropState::HIDDEN); 177 DCHECK(old_ink_drop_state == InkDropState::HIDDEN);
196 178
197 AnimateToOpacity(kVisibleOpacity, 179 AnimateToOpacity(kVisibleOpacity,
198 GetAnimationDuration(ACTION_PENDING_FADE_IN), 180 GetAnimationDuration(ACTION_PENDING_FADE_IN),
199 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 181 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
200 gfx::Tween::EASE_IN, animation_observer); 182 gfx::Tween::EASE_IN, animation_observer);
201 AnimateToOpacity(kVisibleOpacity, 183 AnimateToOpacity(kVisibleOpacity,
202 GetAnimationDuration(ACTION_PENDING_TRANSFORM) - 184 GetAnimationDuration(ACTION_PENDING_TRANSFORM) -
203 GetAnimationDuration(ACTION_PENDING_FADE_IN), 185 GetAnimationDuration(ACTION_PENDING_FADE_IN),
204 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 186 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
205 gfx::Tween::EASE_IN, animation_observer); 187 gfx::Tween::EASE_IN, animation_observer);
206 188
207 const gfx::Transform transform = CalculateTransform( 189 AnimateToTransform(GetActivatedTargetTransform(),
208 CalculateLargestDistanceToCorners(size_, center_point_));
209 AnimateToTransform(transform,
210 GetAnimationDuration(ACTION_PENDING_TRANSFORM), 190 GetAnimationDuration(ACTION_PENDING_TRANSFORM),
211 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 191 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
212 gfx::Tween::FAST_OUT_SLOW_IN, animation_observer); 192 gfx::Tween::FAST_OUT_SLOW_IN, animation_observer);
213 break; 193 break;
214 } 194 }
215 case InkDropState::QUICK_ACTION: { 195 case InkDropState::ACTION_TRIGGERED: {
216 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || 196 DCHECK(old_ink_drop_state == InkDropState::HIDDEN ||
217 old_ink_drop_state == InkDropState::ACTION_PENDING); 197 old_ink_drop_state == InkDropState::ACTION_PENDING);
218 if (old_ink_drop_state == InkDropState::HIDDEN) { 198 if (old_ink_drop_state == InkDropState::HIDDEN) {
219 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING, 199 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING,
220 animation_observer); 200 animation_observer);
221 } 201 }
222 AnimateToOpacity(kHiddenOpacity, 202 AnimateToOpacity(kHiddenOpacity,
223 GetAnimationDuration(QUICK_ACTION_FADE_OUT), 203 GetAnimationDuration(ACTION_TRIGGERED_FADE_OUT),
224 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 204 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
225 gfx::Tween::EASE_IN_OUT, animation_observer); 205 gfx::Tween::EASE_IN_OUT, animation_observer);
226 break; 206 break;
227 } 207 }
228 case InkDropState::SLOW_ACTION_PENDING: { 208 case InkDropState::ALTERNATE_ACTION_PENDING: {
229 DCHECK(old_ink_drop_state == InkDropState::ACTION_PENDING); 209 DCHECK(old_ink_drop_state == InkDropState::ACTION_PENDING);
230 AnimateToOpacity(kVisibleOpacity, 210 AnimateToOpacity(kVisibleOpacity,
231 GetAnimationDuration(SLOW_ACTION_PENDING), 211 GetAnimationDuration(ALTERNATE_ACTION_PENDING),
232 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 212 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
233 gfx::Tween::EASE_IN, animation_observer); 213 gfx::Tween::EASE_IN, animation_observer);
234 const gfx::Transform transform = CalculateTransform( 214 AnimateToTransform(GetActivatedTargetTransform(),
235 CalculateLargestDistanceToCorners(size_, center_point_)); 215 GetAnimationDuration(ALTERNATE_ACTION_PENDING),
236 AnimateToTransform(transform, GetAnimationDuration(SLOW_ACTION_PENDING),
237 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 216 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
238 gfx::Tween::EASE_IN_OUT, animation_observer); 217 gfx::Tween::EASE_IN_OUT, animation_observer);
239 break; 218 break;
240 } 219 }
241 case InkDropState::SLOW_ACTION: 220 case InkDropState::ALTERNATE_ACTION_TRIGGERED:
242 DCHECK(old_ink_drop_state == InkDropState::SLOW_ACTION_PENDING); 221 DCHECK(old_ink_drop_state == InkDropState::ALTERNATE_ACTION_PENDING);
243 AnimateToOpacity(kHiddenOpacity, 222 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(
244 GetAnimationDuration(SLOW_ACTION_FADE_OUT), 223 ALTERNATE_ACTION_TRIGGERED_FADE_OUT),
245 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 224 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
246 gfx::Tween::EASE_IN_OUT, animation_observer); 225 gfx::Tween::EASE_IN_OUT, animation_observer);
247 break; 226 break;
248 case InkDropState::ACTIVATED: { 227 case InkDropState::ACTIVATED: {
249 AnimateToOpacity(kVisibleOpacity, GetAnimationDuration(ACTIVATED_FADE_IN), 228 AnimateToOpacity(kVisibleOpacity, GetAnimationDuration(ACTIVATED_FADE_IN),
250 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 229 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
251 gfx::Tween::EASE_IN, animation_observer); 230 gfx::Tween::EASE_IN, animation_observer);
252 AnimateToTransform(GetActivatedTargetTransform(), 231 AnimateToTransform(GetActivatedTargetTransform(),
253 GetAnimationDuration(ACTIVATED_TRANSFORM), 232 GetAnimationDuration(ACTIVATED_TRANSFORM),
254 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 233 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
255 gfx::Tween::EASE_IN_OUT, animation_observer); 234 gfx::Tween::EASE_IN_OUT, animation_observer);
256 break; 235 break;
257 } 236 }
258 case InkDropState::DEACTIVATED: 237 case InkDropState::DEACTIVATED:
259 AnimateToOpacity(kHiddenOpacity, 238 AnimateToOpacity(kHiddenOpacity,
260 GetAnimationDuration(DEACTIVATED_FADE_OUT), 239 GetAnimationDuration(DEACTIVATED_FADE_OUT),
261 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 240 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
262 gfx::Tween::EASE_IN_OUT, animation_observer); 241 gfx::Tween::EASE_IN_OUT, animation_observer);
263 break; 242 break;
264 } 243 }
265 } 244 }
266 245
267 void FloodFillInkDropAnimation::SetStateToHidden() { 246 void FloodFillInkDropAnimation::SetStateToHidden() {
268 gfx::Transform transform = CalculateTransform(kMinRadius); 247 painted_layer_.SetTransform(CalculateTransform(kMinRadius));
269 painted_layer_.SetTransform(transform);
270 root_layer_.SetOpacity(InkDropAnimation::kHiddenOpacity); 248 root_layer_.SetOpacity(InkDropAnimation::kHiddenOpacity);
271 root_layer_.SetVisible(false); 249 root_layer_.SetVisible(false);
272 } 250 }
273 251
274 void FloodFillInkDropAnimation::AbortAllAnimations() { 252 void FloodFillInkDropAnimation::AbortAllAnimations() {
275 root_layer_.GetAnimator()->AbortAllAnimations(); 253 root_layer_.GetAnimator()->AbortAllAnimations();
276 painted_layer_.GetAnimator()->AbortAllAnimations(); 254 painted_layer_.GetAnimator()->AbortAllAnimations();
277 } 255 }
278 256
279 void FloodFillInkDropAnimation::AnimateToTransform( 257 void FloodFillInkDropAnimation::AnimateToTransform(
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 ToRoundedPoint(circle_layer_delegate_.GetCenterPoint()); 307 ToRoundedPoint(circle_layer_delegate_.GetCenterPoint());
330 308
331 gfx::Transform transform = gfx::Transform(); 309 gfx::Transform transform = gfx::Transform();
332 transform.Translate(center_point_.x(), center_point_.y()); 310 transform.Translate(center_point_.x(), center_point_.y());
333 transform.Scale(target_scale, target_scale); 311 transform.Scale(target_scale, target_scale);
334 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); 312 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());
335 313
336 return transform; 314 return transform;
337 } 315 }
338 316
339 gfx::Transform FloodFillInkDropAnimation::GetActivatedTargetTransform() const { 317 gfx::Transform FloodFillInkDropAnimation::GetActivatedTargetTransform() const {
bruthig 2016/04/04 17:20:17 nit: It probably makes sense to rename this now th
Evan Stade 2016/04/04 18:09:09 Done.
318 // TODO(estade): get rid of this 2, but make the fade out start before the
319 // active/action transform is done.
340 return CalculateTransform( 320 return CalculateTransform(
341 CalculateLargestDistanceToCorners(size_, center_point_)); 321 gfx::Vector2dF(size_.width(), size_.height()).Length() / 2);
342 } 322 }
343 323
344 } // namespace views 324 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698