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

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

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 #include "ui/views/animation/ink_drop_animation.h" 5 #include "ui/views/animation/ink_drop_animation.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "third_party/skia/include/core/SkColor.h" 11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/base/ui_base_switches.h" 12 #include "ui/base/ui_base_switches.h"
13 #include "ui/compositor/callback_layer_animation_observer.h" 13 #include "ui/compositor/callback_layer_animation_observer.h"
14 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
15 #include "ui/compositor/layer_animation_sequence.h" 15 #include "ui/compositor/layer_animation_sequence.h"
16 #include "ui/compositor/scoped_layer_animation_settings.h" 16 #include "ui/compositor/scoped_layer_animation_settings.h"
17 #include "ui/gfx/geometry/point3_f.h"
17 #include "ui/gfx/geometry/point_conversions.h" 18 #include "ui/gfx/geometry/point_conversions.h"
19 #include "ui/gfx/geometry/point_f.h"
20 #include "ui/gfx/geometry/vector3d_f.h"
18 #include "ui/gfx/transform_util.h" 21 #include "ui/gfx/transform_util.h"
19 #include "ui/views/animation/ink_drop_animation_observer.h" 22 #include "ui/views/animation/ink_drop_animation_observer.h"
20 #include "ui/views/animation/ink_drop_painted_layer_delegates.h" 23 #include "ui/views/animation/ink_drop_painted_layer_delegates.h"
21 #include "ui/views/view.h" 24 #include "ui/views/view.h"
22 25
23 namespace { 26 namespace {
24 27
25 // The minimum scale factor to use when scaling rectangle layers. Smaller values 28 // The minimum scale factor to use when scaling rectangle layers. Smaller values
26 // were causing visual anomalies. 29 // were causing visual anomalies.
27 const float kMinimumRectScale = 0.0001f; 30 const float kMinimumRectScale = 0.0001f;
28 31
29 // The minimum scale factor to use when scaling circle layers. Smaller values 32 // The minimum scale factor to use when scaling circle layers. Smaller values
30 // were causing visual anomalies. 33 // were causing visual anomalies.
31 const float kMinimumCircleScale = 0.001f; 34 const float kMinimumCircleScale = 0.001f;
32 35
33 // The ink drop color. 36 // The ink drop color.
34 const SkColor kInkDropColor = SK_ColorBLACK; 37 const SkColor kInkDropColor = SK_ColorBLACK;
35 38
36 // The opacity of the ink drop when it is visible. 39 // The opacity of the ink drop when it is visible.
37 const float kVisibleOpacity = 0.14f; 40 const float kVisibleOpacity = 0.11f;
38 41
39 // The opacity of the ink drop when it is not visible. 42 // The opacity of the ink drop when it is not visible.
40 const float kHiddenOpacity = 0.0f; 43 const float kHiddenOpacity = 0.0f;
41 44
42 // Durations for the different InkDropState animations in milliseconds. 45 // All the sub animations that are used to animate each of the InkDropStates.
43 const int kHiddenStateAnimationDurationMs = 1; 46 // These are used to get time durations with
44 const int kActionPendingStateAnimationDurationMs = 500; 47 // GetAnimationDuration(InkDropSubAnimations). Note that in general a sub
45 const int kQuickActionStateAnimationDurationMs = 250; 48 // animation defines the duration for either a transformation animation or an
46 const int kSlowActionPendingStateAnimationDurationMs = 500; 49 // opacity animation but there are some exceptions where an entire InkDropState
47 const int kSlowActionStateAnimationDurationMs = 250; 50 // animation consists of only 1 sub animation and it defines the duration for
48 const int kActivatedStateAnimationDurationMs = 125; 51 // both the transformation and opacity animations.
49 const int kDeactivatedStateAnimationDurationMs = 250; 52 enum InkDropSubAnimations {
53 // HIDDEN sub animations.
54
55 // The HIDDEN sub animation that is fading out to a hidden opacity.
56 HIDDEN_FADE_OUT,
57
58 // The HIDDEN sub animation that transforms the shape to a |small_size_|
59 // circle.
60 HIDDEN_TRANSFORM,
61
62 // ACTION_PENDING sub animations.
63
64 // The ACTION_PENDING sub animation that fades in to the visible opacity.
65 ACTION_PENDING_FADE_IN,
66
67 // The ACTION_PENDING sub animation that transforms the shape to a
68 // |large_size_| circle.
69 ACTION_PENDING_TRANSFORM,
70
71 // QUICK_ACTION sub animations.
72
73 // The QUICK_ACTION sub animation that is fading out to a hidden opacity.
74 QUICK_ACTION_FADE_OUT,
75
76 // The QUICK_ACTION sub animation that transforms the shape to a |large_size_|
77 // circle.
78 QUICK_ACTION_TRANSFORM,
79
80 // SLOW_ACTION_PENDING sub animations.
81
82 // The SLOW_ACTION_PENDING animation has only one sub animation which animates
83 // to a |small_size_| rounded rectangle at visible opacity.
84 SLOW_ACTION_PENDING,
85
86 // SLOW_ACTION sub animations.
87
88 // The SLOW_ACTION sub animation that is fading out to a hidden opacity.
89 SLOW_ACTION_FADE_OUT,
90
91 // The SLOW_ACTION sub animation that transforms the shape to a |large_size_|
92 // rounded rectangle.
93 SLOW_ACTION_TRANSFORM,
94
95 // ACTIVATED sub animations.
96
97 // The ACTIVATED sub animation that transforms the shape to a |large_size_|
98 // circle. This is used when the ink drop is in a HIDDEN state prior to
99 // animating to the ACTIVATED state.
100 ACTIVATED_CIRCLE_TRANSFORM,
101
102 // The ACTIVATED sub animation that transforms the shape to a |small_size_|
103 // rounded rectangle.
104 ACTIVATED_RECT_TRANSFORM,
105
106 // DEACTIVATED sub animations.
107
108 // The DEACTIVATED sub animation that is fading out to a hidden opacity.
109 DEACTIVATED_FADE_OUT,
110
111 // The DEACTIVATED sub animation that transforms the shape to a |large_size_|
112 // rounded rectangle.
113 DEACTIVATED_TRANSFORM,
114 };
115
116 // Duration constants for InkDropStateSubAnimations. See the
117 // InkDropStateSubAnimations enum documentation for more info.
118 const int kHiddenFadeOutDurationMs = 150;
119 const int kHiddenTransformDurationMs = 200;
120 const int kActionPendingFadeInDurationMs = 0;
121 const int kActionPendingTransformDurationMs = 160;
122 const int kQuickActionFadeOutDurationMs = 150;
123 const int kQuickActionTransformDurationMs = 160;
124 const int kSlowActionPendingDurationMs = 200;
125 const int kSlowActionFadeOutDurationMs = 150;
126 const int kSlowActionTransformDurationMs = 200;
127 const int kActivatedCircleTransformDurationMs = 200;
128 const int kActivatedRectTransformDurationMs = 160;
129 const int kDeactivatedFadeOutDurationMs = 150;
130 const int kDeactivatedTransformDurationMs = 200;
131
132 // The scale factor used to burst the QUICK_ACTION bubble as it fades out.
133 const float kQuickActionBurstScale = 1.3f;
50 134
51 // A multiplicative factor used to slow down InkDropState animations. 135 // A multiplicative factor used to slow down InkDropState animations.
52 const int kSlowAnimationDurationFactor = 3; 136 const int kSlowAnimationDurationFactor = 3;
53 137
54 // Checks CommandLine switches to determine if the visual feedback should have 138 // Checks CommandLine switches to determine if the visual feedback should have
55 // a fast animations speed. 139 // a fast animations speed.
56 bool UseFastAnimations() { 140 bool UseFastAnimations() {
57 static bool fast = 141 static bool fast =
58 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII( 142 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
59 (::switches::kMaterialDesignInkDropAnimationSpeed)) != 143 (::switches::kMaterialDesignInkDropAnimationSpeed)) !=
60 ::switches::kMaterialDesignInkDropAnimationSpeedSlow; 144 ::switches::kMaterialDesignInkDropAnimationSpeedSlow;
61 return fast; 145 return fast;
62 } 146 }
63 147
64 // Returns the InkDropState animation duration for the given |state|. 148 // Returns the InkDropState sub animation duration for the given |state|.
65 base::TimeDelta GetAnimationDuration(views::InkDropState state) { 149 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
66 int duration = 0; 150 int duration = 0;
67 switch (state) { 151 switch (state) {
68 case views::InkDropState::HIDDEN: 152 case HIDDEN_FADE_OUT:
69 duration = kHiddenStateAnimationDurationMs; 153 duration = kHiddenFadeOutDurationMs;
70 break; 154 break;
71 case views::InkDropState::ACTION_PENDING: 155 case HIDDEN_TRANSFORM:
72 duration = kActionPendingStateAnimationDurationMs; 156 duration = kHiddenTransformDurationMs;
73 break; 157 break;
74 case views::InkDropState::QUICK_ACTION: 158 case ACTION_PENDING_FADE_IN:
75 duration = kQuickActionStateAnimationDurationMs; 159 duration = kActionPendingFadeInDurationMs;
76 break; 160 break;
77 case views::InkDropState::SLOW_ACTION_PENDING: 161 case ACTION_PENDING_TRANSFORM:
78 duration = kSlowActionPendingStateAnimationDurationMs; 162 duration = kActionPendingTransformDurationMs;
79 break; 163 break;
80 case views::InkDropState::SLOW_ACTION: 164 case QUICK_ACTION_FADE_OUT:
81 duration = kSlowActionStateAnimationDurationMs; 165 duration = kQuickActionFadeOutDurationMs;
82 break; 166 break;
83 case views::InkDropState::ACTIVATED: 167 case QUICK_ACTION_TRANSFORM:
84 duration = kActivatedStateAnimationDurationMs; 168 duration = kQuickActionTransformDurationMs;
85 break; 169 break;
86 case views::InkDropState::DEACTIVATED: 170 case SLOW_ACTION_PENDING:
87 duration = kDeactivatedStateAnimationDurationMs; 171 duration = kSlowActionPendingDurationMs;
172 break;
173 case SLOW_ACTION_TRANSFORM:
174 duration = kSlowActionTransformDurationMs;
175 break;
176 case SLOW_ACTION_FADE_OUT:
177 duration = kSlowActionFadeOutDurationMs;
178 break;
179 case ACTIVATED_CIRCLE_TRANSFORM:
180 duration = kActivatedCircleTransformDurationMs;
181 break;
182 case ACTIVATED_RECT_TRANSFORM:
183 duration = kActivatedRectTransformDurationMs;
184 break;
185 case DEACTIVATED_FADE_OUT:
186 duration = kDeactivatedFadeOutDurationMs;
187 break;
188 case DEACTIVATED_TRANSFORM:
189 duration = kDeactivatedTransformDurationMs;
varkha 2016/01/28 20:50:45 Maybe refactor this into a lookup table in future
bruthig 2016/01/28 22:38:00 Done.
88 break; 190 break;
89 } 191 }
90
91 return base::TimeDelta::FromMilliseconds( 192 return base::TimeDelta::FromMilliseconds(
92 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration); 193 (UseFastAnimations() ? 1 : kSlowAnimationDurationFactor) * duration);
93 } 194 }
94 195
95 // Calculates a Transform for a circle layer. The transform will be set up to 196 // Calculates a Transform for a circle layer. The transform will be set up to
96 // translate the |drawn_center_point| to the origin, scale, and then translate 197 // translate the |drawn_center_point| to the origin, scale, and then translate
97 // to the target point defined by |target_center_x| and |target_center_y|. 198 // to the target point defined by |target_center_x| and |target_center_y|.
98 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, 199 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point,
99 float scale, 200 float scale,
100 float target_center_x, 201 float target_center_x,
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 AnimateToStateInternal(ink_drop_state, animation_observer); 275 AnimateToStateInternal(ink_drop_state, animation_observer);
175 animation_observer->SetActive(); 276 animation_observer->SetActive();
176 } 277 }
177 278
178 void InkDropAnimation::SetCenterPoint(const gfx::Point& center_point) { 279 void InkDropAnimation::SetCenterPoint(const gfx::Point& center_point) {
179 gfx::Transform transform; 280 gfx::Transform transform;
180 transform.Translate(center_point.x(), center_point.y()); 281 transform.Translate(center_point.x(), center_point.y());
181 root_layer_->SetTransform(transform); 282 root_layer_->SetTransform(transform);
182 } 283 }
183 284
285 void InkDropAnimation::HideImmediately() {
286 AbortAllAnimations();
287 SetStateToHidden();
288 ink_drop_state_ = InkDropState::HIDDEN;
289 }
290
184 std::string InkDropAnimation::ToLayerName(PaintedShape painted_shape) { 291 std::string InkDropAnimation::ToLayerName(PaintedShape painted_shape) {
185 switch (painted_shape) { 292 switch (painted_shape) {
186 case TOP_LEFT_CIRCLE: 293 case TOP_LEFT_CIRCLE:
187 return "TOP_LEFT_CIRCLE"; 294 return "TOP_LEFT_CIRCLE";
188 case TOP_RIGHT_CIRCLE: 295 case TOP_RIGHT_CIRCLE:
189 return "TOP_RIGHT_CIRCLE"; 296 return "TOP_RIGHT_CIRCLE";
190 case BOTTOM_RIGHT_CIRCLE: 297 case BOTTOM_RIGHT_CIRCLE:
191 return "BOTTOM_RIGHT_CIRCLE"; 298 return "BOTTOM_RIGHT_CIRCLE";
192 case BOTTOM_LEFT_CIRCLE: 299 case BOTTOM_LEFT_CIRCLE:
193 return "BOTTOM_LEFT_CIRCLE"; 300 return "BOTTOM_LEFT_CIRCLE";
194 case HORIZONTAL_RECT: 301 case HORIZONTAL_RECT:
195 return "HORIZONTAL_RECT"; 302 return "HORIZONTAL_RECT";
196 case VERTICAL_RECT: 303 case VERTICAL_RECT:
197 return "VERTICAL_RECT"; 304 return "VERTICAL_RECT";
198 case PAINTED_SHAPE_COUNT: 305 case PAINTED_SHAPE_COUNT:
199 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used."; 306 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used.";
200 return "PAINTED_SHAPE_COUNT"; 307 return "PAINTED_SHAPE_COUNT";
201 } 308 }
202 return "UNKNOWN"; 309 return "UNKNOWN";
203 } 310 }
204 311
205 void InkDropAnimation::AnimateToStateInternal( 312 void InkDropAnimation::AnimateToStateInternal(
206 InkDropState ink_drop_state, 313 InkDropState ink_drop_state,
207 ui::LayerAnimationObserver* animation_observer) { 314 ui::LayerAnimationObserver* animation_observer) {
315 InkDropState previous_ink_drop_state = ink_drop_state_;
208 ink_drop_state_ = ink_drop_state; 316 ink_drop_state_ = ink_drop_state;
209 317
210 if (ink_drop_state_ == InkDropState::HIDDEN) {
211 // Animating to the HIDDEN state doesn't actually use any
212 // LayerAnimationSequences so we need to explicitly abort any running ones
213 // so that observers receive an InkDropAnimationEnded() event for the
214 // running animation prior to receiving an InkDropAnimationStarted() event
215 // for the HIDDEN 'animation'.
216 AbortAllAnimations();
217 root_layer_->SetVisible(false);
218 SetStateToHidden();
219 return;
220 }
221
222 InkDropTransforms transforms; 318 InkDropTransforms transforms;
223 root_layer_->SetVisible(true); 319 root_layer_->SetVisible(true);
224 320
225 switch (ink_drop_state_) { 321 switch (ink_drop_state_) {
226 case InkDropState::HIDDEN: 322 case InkDropState::HIDDEN:
227 // This case is handled above in a short circuit return. 323 if (GetCurrentOpacity() == kHiddenOpacity) {
324 AbortAllAnimations();
325 break;
326 } else {
327 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT),
328 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
329 gfx::Tween::EASE_IN_OUT, animation_observer);
330 CalculateCircleTransforms(small_size_, &transforms);
331 AnimateToTransforms(
332 transforms, GetAnimationDuration(HIDDEN_TRANSFORM),
333 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
334 gfx::Tween::EASE_IN_OUT, animation_observer);
335 }
228 break; 336 break;
229 case InkDropState::ACTION_PENDING: 337 case InkDropState::ACTION_PENDING:
338 DCHECK(previous_ink_drop_state == InkDropState::HIDDEN);
339 AnimateToOpacity(kVisibleOpacity,
340 GetAnimationDuration(ACTION_PENDING_FADE_IN),
341 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
342 gfx::Tween::EASE_IN, animation_observer);
343 AnimateToOpacity(kVisibleOpacity,
344 GetAnimationDuration(ACTION_PENDING_TRANSFORM),
345 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
346 gfx::Tween::EASE_IN, animation_observer);
230 CalculateCircleTransforms(large_size_, &transforms); 347 CalculateCircleTransforms(large_size_, &transforms);
231 AnimateToTransforms(transforms, kVisibleOpacity, 348 AnimateToTransforms(transforms,
232 GetAnimationDuration(InkDropState::ACTION_PENDING), 349 GetAnimationDuration(ACTION_PENDING_TRANSFORM),
233 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 350 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
234 animation_observer); 351 gfx::Tween::EASE_IN_OUT, animation_observer);
235 break; 352 break;
236 case InkDropState::QUICK_ACTION: 353 case InkDropState::QUICK_ACTION: {
237 CalculateCircleTransforms(large_size_, &transforms); 354 DCHECK(previous_ink_drop_state == InkDropState::HIDDEN ||
238 AnimateToTransforms(transforms, kHiddenOpacity, 355 previous_ink_drop_state == InkDropState::ACTION_PENDING);
239 GetAnimationDuration(InkDropState::QUICK_ACTION), 356 AnimateToOpacity(kHiddenOpacity,
357 GetAnimationDuration(QUICK_ACTION_FADE_OUT),
358 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
359 gfx::Tween::EASE_IN_OUT, animation_observer);
360 gfx::Size s = ScaleToRoundedSize(large_size_, kQuickActionBurstScale);
361 CalculateCircleTransforms(s, &transforms);
362 AnimateToTransforms(transforms,
363 GetAnimationDuration(QUICK_ACTION_TRANSFORM),
364 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
365 gfx::Tween::EASE_IN_OUT, animation_observer);
366 break;
367 }
368 case InkDropState::SLOW_ACTION_PENDING:
369 DCHECK(previous_ink_drop_state == InkDropState::ACTION_PENDING);
370 AnimateToOpacity(kVisibleOpacity,
371 GetAnimationDuration(SLOW_ACTION_PENDING),
372 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
373 gfx::Tween::EASE_IN, animation_observer);
374 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms);
375 AnimateToTransforms(transforms, GetAnimationDuration(SLOW_ACTION_PENDING),
240 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 376 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
241 animation_observer); 377 gfx::Tween::EASE_IN_OUT, animation_observer);
242 break; 378 break;
243 case InkDropState::SLOW_ACTION_PENDING: 379 case InkDropState::SLOW_ACTION: {
380 DCHECK(previous_ink_drop_state == InkDropState::SLOW_ACTION_PENDING);
381 base::TimeDelta visible_duration =
382 GetAnimationDuration(SLOW_ACTION_TRANSFORM) -
383 GetAnimationDuration(SLOW_ACTION_FADE_OUT);
384 AnimateToOpacity(kVisibleOpacity, visible_duration,
385 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
386 gfx::Tween::EASE_IN_OUT, animation_observer);
387 AnimateToOpacity(kHiddenOpacity,
388 GetAnimationDuration(SLOW_ACTION_FADE_OUT),
389 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
390 gfx::Tween::EASE_IN_OUT, animation_observer);
391 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
392 AnimateToTransforms(transforms,
393 GetAnimationDuration(SLOW_ACTION_TRANSFORM),
394 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
395 gfx::Tween::EASE_IN_OUT, animation_observer);
396 break;
397 }
398 case InkDropState::ACTIVATED: {
399 // Animate the opacity so that it cancels any opacity animations already
400 // in progress.
401 AnimateToOpacity(kVisibleOpacity, base::TimeDelta(),
402 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
403 gfx::Tween::EASE_IN_OUT, animation_observer);
404
405 ui::LayerAnimator::PreemptionStrategy rect_transform_preemption_strategy =
406 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET;
407 if (previous_ink_drop_state == InkDropState::HIDDEN) {
408 rect_transform_preemption_strategy =
409 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION;
410 CalculateCircleTransforms(large_size_, &transforms);
411 AnimateToTransforms(
412 transforms, GetAnimationDuration(ACTIVATED_CIRCLE_TRANSFORM),
413 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
414 gfx::Tween::EASE_IN_OUT, animation_observer);
415 } else if (previous_ink_drop_state == InkDropState::ACTION_PENDING) {
416 rect_transform_preemption_strategy =
417 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION;
418 }
419
244 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms); 420 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms);
245 AnimateToTransforms( 421 AnimateToTransforms(transforms,
246 transforms, kVisibleOpacity, 422 GetAnimationDuration(ACTIVATED_RECT_TRANSFORM),
247 GetAnimationDuration(InkDropState::SLOW_ACTION_PENDING), 423 rect_transform_preemption_strategy,
248 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 424 gfx::Tween::EASE_IN_OUT, animation_observer);
249 animation_observer);
250 break; 425 break;
251 case InkDropState::SLOW_ACTION: 426 }
427 case InkDropState::DEACTIVATED: {
428 base::TimeDelta visible_duration =
429 GetAnimationDuration(DEACTIVATED_TRANSFORM) -
430 GetAnimationDuration(DEACTIVATED_FADE_OUT);
431 AnimateToOpacity(kVisibleOpacity, visible_duration,
432 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
433 gfx::Tween::EASE_IN_OUT, animation_observer);
252 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); 434 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
253 AnimateToTransforms(transforms, kHiddenOpacity, 435 AnimateToOpacity(kHiddenOpacity,
254 GetAnimationDuration(InkDropState::SLOW_ACTION), 436 GetAnimationDuration(DEACTIVATED_FADE_OUT),
437 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
438 gfx::Tween::EASE_IN_OUT, animation_observer);
439 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
440 AnimateToTransforms(transforms,
441 GetAnimationDuration(DEACTIVATED_TRANSFORM),
255 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 442 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
256 animation_observer); 443 gfx::Tween::EASE_IN_OUT, animation_observer);
257 break; 444 break;
258 case InkDropState::ACTIVATED: 445 }
259 CalculateRectTransforms(small_size_, small_corner_radius_, &transforms);
260 AnimateToTransforms(transforms, kVisibleOpacity,
261 GetAnimationDuration(InkDropState::ACTIVATED),
262 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
263 animation_observer);
264 break;
265 case InkDropState::DEACTIVATED:
266 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
267 AnimateToTransforms(transforms, kHiddenOpacity,
268 GetAnimationDuration(InkDropState::DEACTIVATED),
269 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
270 animation_observer);
271 break;
272 } 446 }
273 } 447 }
274 448
275 void InkDropAnimation::AnimateToTransforms( 449 void InkDropAnimation::AnimateToTransforms(
276 const InkDropTransforms transforms, 450 const InkDropTransforms transforms,
277 float opacity,
278 base::TimeDelta duration, 451 base::TimeDelta duration,
279 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 452 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
453 gfx::Tween::Type tween,
280 ui::LayerAnimationObserver* animation_observer) { 454 ui::LayerAnimationObserver* animation_observer) {
281 ui::LayerAnimator* root_animator = root_layer_->GetAnimator();
282 ui::ScopedLayerAnimationSettings root_animation(root_animator);
283 root_animation.SetPreemptionStrategy(preemption_strategy);
284 ui::LayerAnimationElement* root_element =
285 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration);
286 ui::LayerAnimationSequence* root_sequence =
287 new ui::LayerAnimationSequence(root_element);
288
289 if (animation_observer)
290 root_sequence->AddObserver(animation_observer);
291
292 root_animator->StartAnimation(root_sequence);
293
294 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { 455 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) {
295 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); 456 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator();
296 ui::ScopedLayerAnimationSettings animation(animator); 457 ui::ScopedLayerAnimationSettings animation(animator);
297 animation.SetPreemptionStrategy(preemption_strategy); 458 animation.SetPreemptionStrategy(preemption_strategy);
459 animation.SetTweenType(tween);
298 ui::LayerAnimationElement* element = 460 ui::LayerAnimationElement* element =
299 ui::LayerAnimationElement::CreateTransformElement(transforms[i], 461 ui::LayerAnimationElement::CreateTransformElement(transforms[i],
300 duration); 462 duration);
301 ui::LayerAnimationSequence* sequence = 463 ui::LayerAnimationSequence* sequence =
302 new ui::LayerAnimationSequence(element); 464 new ui::LayerAnimationSequence(element);
303 465
304 if (animation_observer) 466 if (animation_observer)
305 sequence->AddObserver(animation_observer); 467 sequence->AddObserver(animation_observer);
306 468
307 animator->StartAnimation(sequence); 469 animator->StartAnimation(sequence);
308 } 470 }
309 } 471 }
310 472
311 void InkDropAnimation::SetStateToHidden() { 473 void InkDropAnimation::SetStateToHidden() {
312 InkDropTransforms transforms; 474 InkDropTransforms transforms;
313 // Using a size of 0x0 creates visual anomalies. 475 // Using a size of 0x0 creates visual anomalies.
314 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); 476 CalculateCircleTransforms(gfx::Size(1, 1), &transforms);
315 SetTransforms(transforms); 477 SetTransforms(transforms);
316 SetOpacity(kHiddenOpacity); 478 SetOpacity(kHiddenOpacity);
479 root_layer_->SetVisible(false);
317 } 480 }
318 481
319 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) { 482 void InkDropAnimation::SetTransforms(const InkDropTransforms transforms) {
320 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 483 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
321 painted_layers_[i]->SetTransform(transforms[i]); 484 painted_layers_[i]->SetTransform(transforms[i]);
322 } 485 }
323 486
487 float InkDropAnimation::GetCurrentOpacity() const {
488 return root_layer_->opacity();
489 }
490
324 void InkDropAnimation::SetOpacity(float opacity) { 491 void InkDropAnimation::SetOpacity(float opacity) {
325 root_layer_->SetOpacity(opacity); 492 root_layer_->SetOpacity(opacity);
326 } 493 }
327 494
495 void InkDropAnimation::AnimateToOpacity(
496 float opacity,
497 base::TimeDelta duration,
498 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
499 gfx::Tween::Type tween,
500 ui::LayerAnimationObserver* animation_observer) {
501 ui::LayerAnimator* animator = root_layer_->GetAnimator();
502 ui::ScopedLayerAnimationSettings animation_settings(animator);
503 animation_settings.SetPreemptionStrategy(preemption_strategy);
504 animation_settings.SetTweenType(tween);
505 ui::LayerAnimationElement* animation_element =
506 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration);
507 ui::LayerAnimationSequence* animation_sequence =
508 new ui::LayerAnimationSequence(animation_element);
509
510 if (animation_observer)
511 animation_sequence->AddObserver(animation_observer);
512
513 animator->StartAnimation(animation_sequence);
514 }
515
328 void InkDropAnimation::CalculateCircleTransforms( 516 void InkDropAnimation::CalculateCircleTransforms(
329 const gfx::Size& size, 517 const gfx::Size& size,
330 InkDropTransforms* transforms_out) const { 518 InkDropTransforms* transforms_out) const {
331 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, 519 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f,
332 transforms_out); 520 transforms_out);
333 } 521 }
334 522
335 void InkDropAnimation::CalculateRectTransforms( 523 void InkDropAnimation::CalculateRectTransforms(
336 const gfx::Size& size, 524 const gfx::Size& size,
337 float corner_radius, 525 float corner_radius,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 std::max(kMinimumRectScale, 567 std::max(kMinimumRectScale,
380 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); 568 (size.height() - 2.0f * corner_radius) / rect_delegate_height));
381 569
382 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( 570 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform(
383 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), 571 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()),
384 std::max(kMinimumRectScale, 572 std::max(kMinimumRectScale,
385 (size.width() - 2.0f * corner_radius) / rect_delegate_width), 573 (size.width() - 2.0f * corner_radius) / rect_delegate_width),
386 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); 574 std::max(kMinimumRectScale, size.height() / rect_delegate_height));
387 } 575 }
388 576
389 void InkDropAnimation::GetCurrentTansforms( 577 void InkDropAnimation::GetCurrentTransforms(
390 InkDropTransforms* transforms_out) const { 578 InkDropTransforms* transforms_out) const {
391 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 579 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
392 (*transforms_out)[i] = painted_layers_[i]->GetTargetTransform(); 580 (*transforms_out)[i] = painted_layers_[i]->transform();
393 } 581 }
394 582
395 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { 583 void InkDropAnimation::AddPaintLayer(PaintedShape painted_shape) {
396 ui::LayerDelegate* delegate = nullptr; 584 ui::LayerDelegate* delegate = nullptr;
397 switch (painted_shape) { 585 switch (painted_shape) {
398 case TOP_LEFT_CIRCLE: 586 case TOP_LEFT_CIRCLE:
399 case TOP_RIGHT_CIRCLE: 587 case TOP_RIGHT_CIRCLE:
400 case BOTTOM_RIGHT_CIRCLE: 588 case BOTTOM_RIGHT_CIRCLE:
401 case BOTTOM_LEFT_CIRCLE: 589 case BOTTOM_LEFT_CIRCLE:
402 delegate = circle_layer_delegate_.get(); 590 delegate = circle_layer_delegate_.get();
(...skipping 30 matching lines...) Expand all
433 void InkDropAnimation::AnimationStartedCallback( 621 void InkDropAnimation::AnimationStartedCallback(
434 InkDropState ink_drop_state, 622 InkDropState ink_drop_state,
435 const ui::CallbackLayerAnimationObserver& observer) { 623 const ui::CallbackLayerAnimationObserver& observer) {
436 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_, 624 FOR_EACH_OBSERVER(InkDropAnimationObserver, observers_,
437 InkDropAnimationStarted(ink_drop_state)); 625 InkDropAnimationStarted(ink_drop_state));
438 } 626 }
439 627
440 bool InkDropAnimation::AnimationEndedCallback( 628 bool InkDropAnimation::AnimationEndedCallback(
441 InkDropState ink_drop_state, 629 InkDropState ink_drop_state,
442 const ui::CallbackLayerAnimationObserver& observer) { 630 const ui::CallbackLayerAnimationObserver& observer) {
631 if (ink_drop_state == InkDropState::HIDDEN)
632 SetStateToHidden();
633
443 FOR_EACH_OBSERVER( 634 FOR_EACH_OBSERVER(
444 InkDropAnimationObserver, observers_, 635 InkDropAnimationObserver, observers_,
445 InkDropAnimationEnded(ink_drop_state, 636 InkDropAnimationEnded(ink_drop_state,
446 observer.aborted_count() 637 observer.aborted_count()
447 ? InkDropAnimationObserver::PRE_EMPTED 638 ? InkDropAnimationObserver::PRE_EMPTED
448 : InkDropAnimationObserver::SUCCESS)); 639 : InkDropAnimationObserver::SUCCESS));
449 return true; 640 return true;
450 } 641 }
451 642
452 } // namespace views 643 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698