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

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: worth reviewing 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;
Evan Stade 2016/03/31 03:41:27 this was the source of the problematic sizing (it
bruthig 2016/03/31 19:39:03 Acknowledged.
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.
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 93
94 // Returns the InkDropState sub animation duration for the given |state|. 94 // Returns the InkDropState sub animation duration for the given |state|.
95 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) { 95 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
96 return base::TimeDelta::FromMilliseconds( 96 return base::TimeDelta::FromMilliseconds(
97 (views::InkDropAnimation::UseFastAnimations() 97 (views::InkDropAnimation::UseFastAnimations()
98 ? 1 98 ? 1
99 : views::InkDropAnimation::kSlowAnimationDurationFactor) * 99 : views::InkDropAnimation::kSlowAnimationDurationFactor) *
100 kAnimationDurationInMs[state]); 100 kAnimationDurationInMs[state]);
101 } 101 }
102 102
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,
Evan Stade 2016/03/31 03:41:27 This calculation is a bit overkill for any centerp
bruthig 2016/03/31 19:39:03 Yes this is definitely overkill for ripples that a
Evan Stade 2016/03/31 21:07:38 With this change, the speed is not constant WRT th
bruthig 2016/03/31 22:46:19 I need to digest this a bit more.
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 103 } // namespace
123 104
124 namespace views { 105 namespace views {
125 106
126 FloodFillInkDropAnimation::FloodFillInkDropAnimation( 107 FloodFillInkDropAnimation::FloodFillInkDropAnimation(
127 const gfx::Size& size, 108 const gfx::Size& size,
128 const gfx::Point& center_point, 109 const gfx::Point& center_point,
129 SkColor color) 110 SkColor color)
130 : size_(size), 111 : size_(size),
131 center_point_(center_point), 112 center_point_(center_point),
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 154 }
174 155
175 void FloodFillInkDropAnimation::AnimateStateChange( 156 void FloodFillInkDropAnimation::AnimateStateChange(
176 InkDropState old_ink_drop_state, 157 InkDropState old_ink_drop_state,
177 InkDropState new_ink_drop_state, 158 InkDropState new_ink_drop_state,
178 ui::LayerAnimationObserver* animation_observer) { 159 ui::LayerAnimationObserver* animation_observer) {
179 switch (new_ink_drop_state) { 160 switch (new_ink_drop_state) {
180 case InkDropState::HIDDEN: 161 case InkDropState::HIDDEN:
181 if (!IsVisible()) { 162 if (!IsVisible()) {
182 SetStateToHidden(); 163 SetStateToHidden();
183 break;
184 } else { 164 } else {
185 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT), 165 AnimateToOpacity(kHiddenOpacity, GetAnimationDuration(HIDDEN_FADE_OUT),
186 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 166 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
187 gfx::Tween::EASE_IN_OUT, animation_observer); 167 gfx::Tween::EASE_IN_OUT, animation_observer);
188 const gfx::Transform transform = CalculateTransform(kMinRadius);
189 AnimateToTransform(transform, GetAnimationDuration(HIDDEN_TRANSFORM),
Evan Stade 2016/03/31 03:41:27 I got rid of this because it looked weird on the s
bruthig 2016/03/31 19:39:03 This was a very intentional choice and I feel like
Evan Stade 2016/03/31 21:07:38 IIUC, you're saying that there's no visual distinc
bruthig 2016/03/31 22:46:19 Correct. You can try this out on the "Home" butto
Evan Stade 2016/04/01 19:03:13 ah ok. So if I change DownloadItemViewMd's sequenc
190 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
191 gfx::Tween::EASE_IN_OUT, animation_observer);
192 } 168 }
193 break; 169 break;
194 case InkDropState::ACTION_PENDING: { 170 case InkDropState::ACTION_PENDING: {
195 DCHECK(old_ink_drop_state == InkDropState::HIDDEN); 171 DCHECK(old_ink_drop_state == InkDropState::HIDDEN);
196 172
197 AnimateToOpacity(kVisibleOpacity, 173 AnimateToOpacity(kVisibleOpacity,
198 GetAnimationDuration(ACTION_PENDING_FADE_IN), 174 GetAnimationDuration(ACTION_PENDING_FADE_IN),
199 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 175 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
200 gfx::Tween::EASE_IN, animation_observer); 176 gfx::Tween::EASE_IN, animation_observer);
201 AnimateToOpacity(kVisibleOpacity, 177 AnimateToOpacity(kVisibleOpacity,
202 GetAnimationDuration(ACTION_PENDING_TRANSFORM) - 178 GetAnimationDuration(ACTION_PENDING_TRANSFORM) -
203 GetAnimationDuration(ACTION_PENDING_FADE_IN), 179 GetAnimationDuration(ACTION_PENDING_FADE_IN),
204 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 180 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
205 gfx::Tween::EASE_IN, animation_observer); 181 gfx::Tween::EASE_IN, animation_observer);
206 182
207 const gfx::Transform transform = CalculateTransform( 183 AnimateToTransform(GetActivatedTargetTransform(),
208 CalculateLargestDistanceToCorners(size_, center_point_));
209 AnimateToTransform(transform,
210 GetAnimationDuration(ACTION_PENDING_TRANSFORM), 184 GetAnimationDuration(ACTION_PENDING_TRANSFORM),
211 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 185 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
212 gfx::Tween::FAST_OUT_SLOW_IN, animation_observer); 186 gfx::Tween::FAST_OUT_SLOW_IN, animation_observer);
213 break; 187 break;
214 } 188 }
215 case InkDropState::QUICK_ACTION: { 189 case InkDropState::QUICK_ACTION: {
216 DCHECK(old_ink_drop_state == InkDropState::HIDDEN || 190 DCHECK(old_ink_drop_state == InkDropState::HIDDEN ||
217 old_ink_drop_state == InkDropState::ACTION_PENDING); 191 old_ink_drop_state == InkDropState::ACTION_PENDING);
218 if (old_ink_drop_state == InkDropState::HIDDEN) { 192 if (old_ink_drop_state == InkDropState::HIDDEN) {
219 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING, 193 AnimateStateChange(old_ink_drop_state, InkDropState::ACTION_PENDING,
220 animation_observer); 194 animation_observer);
221 } 195 }
222 AnimateToOpacity(kHiddenOpacity, 196 AnimateToOpacity(kHiddenOpacity,
223 GetAnimationDuration(QUICK_ACTION_FADE_OUT), 197 GetAnimationDuration(QUICK_ACTION_FADE_OUT),
224 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 198 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
225 gfx::Tween::EASE_IN_OUT, animation_observer); 199 gfx::Tween::EASE_IN_OUT, animation_observer);
226 break; 200 break;
227 } 201 }
228 case InkDropState::SLOW_ACTION_PENDING: { 202 case InkDropState::SLOW_ACTION_PENDING: {
229 DCHECK(old_ink_drop_state == InkDropState::ACTION_PENDING); 203 DCHECK(old_ink_drop_state == InkDropState::ACTION_PENDING);
230 AnimateToOpacity(kVisibleOpacity, 204 AnimateToOpacity(kVisibleOpacity,
231 GetAnimationDuration(SLOW_ACTION_PENDING), 205 GetAnimationDuration(SLOW_ACTION_PENDING),
232 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 206 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
233 gfx::Tween::EASE_IN, animation_observer); 207 gfx::Tween::EASE_IN, animation_observer);
234 const gfx::Transform transform = CalculateTransform( 208 AnimateToTransform(GetActivatedTargetTransform(),
235 CalculateLargestDistanceToCorners(size_, center_point_)); 209 GetAnimationDuration(SLOW_ACTION_PENDING),
236 AnimateToTransform(transform, GetAnimationDuration(SLOW_ACTION_PENDING),
237 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 210 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
238 gfx::Tween::EASE_IN_OUT, animation_observer); 211 gfx::Tween::EASE_IN_OUT, animation_observer);
239 break; 212 break;
240 } 213 }
241 case InkDropState::SLOW_ACTION: 214 case InkDropState::SLOW_ACTION:
242 DCHECK(old_ink_drop_state == InkDropState::SLOW_ACTION_PENDING); 215 DCHECK(old_ink_drop_state == InkDropState::SLOW_ACTION_PENDING);
243 AnimateToOpacity(kHiddenOpacity, 216 AnimateToOpacity(kHiddenOpacity,
244 GetAnimationDuration(SLOW_ACTION_FADE_OUT), 217 GetAnimationDuration(SLOW_ACTION_FADE_OUT),
245 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 218 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
246 gfx::Tween::EASE_IN_OUT, animation_observer); 219 gfx::Tween::EASE_IN_OUT, animation_observer);
(...skipping 11 matching lines...) Expand all
258 case InkDropState::DEACTIVATED: 231 case InkDropState::DEACTIVATED:
259 AnimateToOpacity(kHiddenOpacity, 232 AnimateToOpacity(kHiddenOpacity,
260 GetAnimationDuration(DEACTIVATED_FADE_OUT), 233 GetAnimationDuration(DEACTIVATED_FADE_OUT),
261 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION, 234 ui::LayerAnimator::ENQUEUE_NEW_ANIMATION,
262 gfx::Tween::EASE_IN_OUT, animation_observer); 235 gfx::Tween::EASE_IN_OUT, animation_observer);
263 break; 236 break;
264 } 237 }
265 } 238 }
266 239
267 void FloodFillInkDropAnimation::SetStateToHidden() { 240 void FloodFillInkDropAnimation::SetStateToHidden() {
268 gfx::Transform transform = CalculateTransform(kMinRadius); 241 painted_layer_.SetTransform(CalculateTransform(kMinRadius));
269 painted_layer_.SetTransform(transform);
270 root_layer_.SetOpacity(InkDropAnimation::kHiddenOpacity); 242 root_layer_.SetOpacity(InkDropAnimation::kHiddenOpacity);
271 root_layer_.SetVisible(false); 243 root_layer_.SetVisible(false);
272 } 244 }
273 245
274 void FloodFillInkDropAnimation::AbortAllAnimations() { 246 void FloodFillInkDropAnimation::AbortAllAnimations() {
275 root_layer_.GetAnimator()->AbortAllAnimations(); 247 root_layer_.GetAnimator()->AbortAllAnimations();
276 painted_layer_.GetAnimator()->AbortAllAnimations(); 248 painted_layer_.GetAnimator()->AbortAllAnimations();
277 } 249 }
278 250
279 void FloodFillInkDropAnimation::AnimateToTransform( 251 void FloodFillInkDropAnimation::AnimateToTransform(
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 gfx::Transform transform = gfx::Transform(); 303 gfx::Transform transform = gfx::Transform();
332 transform.Translate(center_point_.x(), center_point_.y()); 304 transform.Translate(center_point_.x(), center_point_.y());
333 transform.Scale(target_scale, target_scale); 305 transform.Scale(target_scale, target_scale);
334 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); 306 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());
335 307
336 return transform; 308 return transform;
337 } 309 }
338 310
339 gfx::Transform FloodFillInkDropAnimation::GetActivatedTargetTransform() const { 311 gfx::Transform FloodFillInkDropAnimation::GetActivatedTargetTransform() const {
340 return CalculateTransform( 312 return CalculateTransform(
341 CalculateLargestDistanceToCorners(size_, center_point_)); 313 gfx::Vector2dF(size_.width(), size_.height()).Length());
342 } 314 }
343 315
344 } // namespace views 316 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698