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

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

Issue 1937103003: Rename of InkDropAnimation classes to InkDropRipple. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed test_ink_drop_animation_observer.h from views.gyp and doc update. Created 4 years, 7 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/square_ink_drop_animation.h" 5 #include "ui/views/animation/square_ink_drop_ripple.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
11 #include "ui/compositor/layer_animation_sequence.h" 11 #include "ui/compositor/layer_animation_sequence.h"
12 #include "ui/compositor/scoped_layer_animation_settings.h" 12 #include "ui/compositor/scoped_layer_animation_settings.h"
13 #include "ui/gfx/geometry/point3_f.h" 13 #include "ui/gfx/geometry/point3_f.h"
14 #include "ui/gfx/geometry/point_conversions.h" 14 #include "ui/gfx/geometry/point_conversions.h"
15 #include "ui/gfx/geometry/point_f.h" 15 #include "ui/gfx/geometry/point_f.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 200, // ALTERNATE_ACTION_TRIGGERED_TRANSFORM 120 200, // ALTERNATE_ACTION_TRIGGERED_TRANSFORM
121 200, // ACTIVATED_CIRCLE_TRANSFORM 121 200, // ACTIVATED_CIRCLE_TRANSFORM
122 160, // ACTIVATED_RECT_TRANSFORM 122 160, // ACTIVATED_RECT_TRANSFORM
123 150, // DEACTIVATED_FADE_OUT 123 150, // DEACTIVATED_FADE_OUT
124 200, // DEACTIVATED_TRANSFORM 124 200, // DEACTIVATED_TRANSFORM
125 }; 125 };
126 126
127 // Returns the InkDropState sub animation duration for the given |state|. 127 // Returns the InkDropState sub animation duration for the given |state|.
128 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) { 128 base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
129 return base::TimeDelta::FromMilliseconds( 129 return base::TimeDelta::FromMilliseconds(
130 (views::InkDropAnimation::UseFastAnimations() 130 (views::InkDropRipple::UseFastAnimations()
131 ? 1 131 ? 1
132 : views::InkDropAnimation::kSlowAnimationDurationFactor) * 132 : views::InkDropRipple::kSlowAnimationDurationFactor) *
133 kAnimationDurationInMs[state]); 133 kAnimationDurationInMs[state]);
134 } 134 }
135 135
136 // Calculates a Transform for a circle layer. The transform will be set up to 136 // Calculates a Transform for a circle layer. The transform will be set up to
137 // translate the |drawn_center_point| to the origin, scale, and then translate 137 // translate the |drawn_center_point| to the origin, scale, and then translate
138 // to the target point defined by |target_center_x| and |target_center_y|. 138 // to the target point defined by |target_center_x| and |target_center_y|.
139 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point, 139 gfx::Transform CalculateCircleTransform(const gfx::Point& drawn_center_point,
140 float scale, 140 float scale,
141 float target_center_x, 141 float target_center_x,
142 float target_center_y) { 142 float target_center_y) {
(...skipping 13 matching lines...) Expand all
156 gfx::Transform transform; 156 gfx::Transform transform;
157 transform.Scale(x_scale, y_scale); 157 transform.Scale(x_scale, y_scale);
158 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y()); 158 transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());
159 return transform; 159 return transform;
160 } 160 }
161 161
162 } // namespace 162 } // namespace
163 163
164 namespace views { 164 namespace views {
165 165
166 SquareInkDropAnimation::SquareInkDropAnimation(const gfx::Size& large_size, 166 SquareInkDropRipple::SquareInkDropRipple(const gfx::Size& large_size,
167 int large_corner_radius, 167 int large_corner_radius,
168 const gfx::Size& small_size, 168 const gfx::Size& small_size,
169 int small_corner_radius, 169 int small_corner_radius,
170 const gfx::Point& center_point, 170 const gfx::Point& center_point,
171 SkColor color) 171 SkColor color)
172 : large_size_(large_size), 172 : large_size_(large_size),
173 large_corner_radius_(large_corner_radius), 173 large_corner_radius_(large_corner_radius),
174 small_size_(small_size), 174 small_size_(small_size),
175 small_corner_radius_(small_corner_radius), 175 small_corner_radius_(small_corner_radius),
176 circle_layer_delegate_(new CircleLayerDelegate( 176 circle_layer_delegate_(new CircleLayerDelegate(
177 color, 177 color,
178 std::min(large_size_.width(), large_size_.height()) / 2)), 178 std::min(large_size_.width(), large_size_.height()) / 2)),
179 rect_layer_delegate_(new RectangleLayerDelegate(color, large_size_)), 179 rect_layer_delegate_(new RectangleLayerDelegate(color, large_size_)),
180 root_layer_(ui::LAYER_NOT_DRAWN) { 180 root_layer_(ui::LAYER_NOT_DRAWN) {
181 root_layer_.set_name("SquareInkDropAnimation:ROOT_LAYER"); 181 root_layer_.set_name("SquareInkDropRipple:ROOT_LAYER");
182 182
183 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 183 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
184 AddPaintLayer(static_cast<PaintedShape>(i)); 184 AddPaintLayer(static_cast<PaintedShape>(i));
185 185
186 root_layer_.SetMasksToBounds(false); 186 root_layer_.SetMasksToBounds(false);
187 root_layer_.SetBounds(gfx::Rect(large_size_)); 187 root_layer_.SetBounds(gfx::Rect(large_size_));
188 188
189 gfx::Transform transform; 189 gfx::Transform transform;
190 transform.Translate(center_point.x(), center_point.y()); 190 transform.Translate(center_point.x(), center_point.y());
191 root_layer_.SetTransform(transform); 191 root_layer_.SetTransform(transform);
192 192
193 SetStateToHidden(); 193 SetStateToHidden();
194 } 194 }
195 195
196 SquareInkDropAnimation::~SquareInkDropAnimation() { 196 SquareInkDropRipple::~SquareInkDropRipple() {
197 // Explicitly aborting all the animations ensures all callbacks are invoked 197 // Explicitly aborting all the animations ensures all callbacks are invoked
198 // while this instance still exists. 198 // while this instance still exists.
199 AbortAllAnimations(); 199 AbortAllAnimations();
200 } 200 }
201 201
202 void SquareInkDropAnimation::SnapToActivated() { 202 void SquareInkDropRipple::SnapToActivated() {
203 InkDropAnimation::SnapToActivated(); 203 InkDropRipple::SnapToActivated();
204 SetOpacity(kVisibleOpacity); 204 SetOpacity(kVisibleOpacity);
205 InkDropTransforms transforms; 205 InkDropTransforms transforms;
206 GetActivatedTargetTransforms(&transforms); 206 GetActivatedTargetTransforms(&transforms);
207 SetTransforms(transforms); 207 SetTransforms(transforms);
208 } 208 }
209 209
210 ui::Layer* SquareInkDropAnimation::GetRootLayer() { 210 ui::Layer* SquareInkDropRipple::GetRootLayer() {
211 return &root_layer_; 211 return &root_layer_;
212 } 212 }
213 213
214 bool SquareInkDropAnimation::IsVisible() const { 214 bool SquareInkDropRipple::IsVisible() const {
215 return root_layer_.visible(); 215 return root_layer_.visible();
216 } 216 }
217 217
218 float SquareInkDropAnimation::GetCurrentOpacity() const { 218 float SquareInkDropRipple::GetCurrentOpacity() const {
219 return root_layer_.opacity(); 219 return root_layer_.opacity();
220 } 220 }
221 221
222 std::string SquareInkDropAnimation::ToLayerName(PaintedShape painted_shape) { 222 std::string SquareInkDropRipple::ToLayerName(PaintedShape painted_shape) {
223 switch (painted_shape) { 223 switch (painted_shape) {
224 case TOP_LEFT_CIRCLE: 224 case TOP_LEFT_CIRCLE:
225 return "TOP_LEFT_CIRCLE"; 225 return "TOP_LEFT_CIRCLE";
226 case TOP_RIGHT_CIRCLE: 226 case TOP_RIGHT_CIRCLE:
227 return "TOP_RIGHT_CIRCLE"; 227 return "TOP_RIGHT_CIRCLE";
228 case BOTTOM_RIGHT_CIRCLE: 228 case BOTTOM_RIGHT_CIRCLE:
229 return "BOTTOM_RIGHT_CIRCLE"; 229 return "BOTTOM_RIGHT_CIRCLE";
230 case BOTTOM_LEFT_CIRCLE: 230 case BOTTOM_LEFT_CIRCLE:
231 return "BOTTOM_LEFT_CIRCLE"; 231 return "BOTTOM_LEFT_CIRCLE";
232 case HORIZONTAL_RECT: 232 case HORIZONTAL_RECT:
233 return "HORIZONTAL_RECT"; 233 return "HORIZONTAL_RECT";
234 case VERTICAL_RECT: 234 case VERTICAL_RECT:
235 return "VERTICAL_RECT"; 235 return "VERTICAL_RECT";
236 case PAINTED_SHAPE_COUNT: 236 case PAINTED_SHAPE_COUNT:
237 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used."; 237 NOTREACHED() << "The PAINTED_SHAPE_COUNT value should never be used.";
238 return "PAINTED_SHAPE_COUNT"; 238 return "PAINTED_SHAPE_COUNT";
239 } 239 }
240 return "UNKNOWN"; 240 return "UNKNOWN";
241 } 241 }
242 242
243 void SquareInkDropAnimation::AnimateStateChange( 243 void SquareInkDropRipple::AnimateStateChange(
244 InkDropState old_ink_drop_state, 244 InkDropState old_ink_drop_state,
245 InkDropState new_ink_drop_state, 245 InkDropState new_ink_drop_state,
246 ui::LayerAnimationObserver* animation_observer) { 246 ui::LayerAnimationObserver* animation_observer) {
247 InkDropTransforms transforms; 247 InkDropTransforms transforms;
248 248
249 switch (new_ink_drop_state) { 249 switch (new_ink_drop_state) {
250 case InkDropState::HIDDEN: 250 case InkDropState::HIDDEN:
251 if (!IsVisible()) { 251 if (!IsVisible()) {
252 SetStateToHidden(); 252 SetStateToHidden();
253 break; 253 break;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms); 372 CalculateRectTransforms(large_size_, large_corner_radius_, &transforms);
373 AnimateToTransforms(transforms, 373 AnimateToTransforms(transforms,
374 GetAnimationDuration(DEACTIVATED_TRANSFORM), 374 GetAnimationDuration(DEACTIVATED_TRANSFORM),
375 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET, 375 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET,
376 gfx::Tween::EASE_IN_OUT, animation_observer); 376 gfx::Tween::EASE_IN_OUT, animation_observer);
377 break; 377 break;
378 } 378 }
379 } 379 }
380 } 380 }
381 381
382 void SquareInkDropAnimation::SetStateToHidden() { 382 void SquareInkDropRipple::SetStateToHidden() {
383 InkDropTransforms transforms; 383 InkDropTransforms transforms;
384 // Use non-zero size to avoid visual anomalies. 384 // Use non-zero size to avoid visual anomalies.
385 CalculateCircleTransforms(gfx::Size(1, 1), &transforms); 385 CalculateCircleTransforms(gfx::Size(1, 1), &transforms);
386 SetTransforms(transforms); 386 SetTransforms(transforms);
387 root_layer_.SetOpacity(InkDropAnimation::kHiddenOpacity); 387 root_layer_.SetOpacity(InkDropRipple::kHiddenOpacity);
388 root_layer_.SetVisible(false); 388 root_layer_.SetVisible(false);
389 } 389 }
390 390
391 void SquareInkDropAnimation::AbortAllAnimations() { 391 void SquareInkDropRipple::AbortAllAnimations() {
392 root_layer_.GetAnimator()->AbortAllAnimations(); 392 root_layer_.GetAnimator()->AbortAllAnimations();
393 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 393 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
394 painted_layers_[i]->GetAnimator()->AbortAllAnimations(); 394 painted_layers_[i]->GetAnimator()->AbortAllAnimations();
395 } 395 }
396 396
397 void SquareInkDropAnimation::AnimateToTransforms( 397 void SquareInkDropRipple::AnimateToTransforms(
398 const InkDropTransforms transforms, 398 const InkDropTransforms transforms,
399 base::TimeDelta duration, 399 base::TimeDelta duration,
400 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 400 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
401 gfx::Tween::Type tween, 401 gfx::Tween::Type tween,
402 ui::LayerAnimationObserver* animation_observer) { 402 ui::LayerAnimationObserver* animation_observer) {
403 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) { 403 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) {
404 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator(); 404 ui::LayerAnimator* animator = painted_layers_[i]->GetAnimator();
405 ui::ScopedLayerAnimationSettings animation(animator); 405 ui::ScopedLayerAnimationSettings animation(animator);
406 animation.SetPreemptionStrategy(preemption_strategy); 406 animation.SetPreemptionStrategy(preemption_strategy);
407 animation.SetTweenType(tween); 407 animation.SetTweenType(tween);
408 ui::LayerAnimationElement* element = 408 ui::LayerAnimationElement* element =
409 ui::LayerAnimationElement::CreateTransformElement(transforms[i], 409 ui::LayerAnimationElement::CreateTransformElement(transforms[i],
410 duration); 410 duration);
411 ui::LayerAnimationSequence* sequence = 411 ui::LayerAnimationSequence* sequence =
412 new ui::LayerAnimationSequence(element); 412 new ui::LayerAnimationSequence(element);
413 413
414 if (animation_observer) 414 if (animation_observer)
415 sequence->AddObserver(animation_observer); 415 sequence->AddObserver(animation_observer);
416 416
417 animator->StartAnimation(sequence); 417 animator->StartAnimation(sequence);
418 } 418 }
419 } 419 }
420 420
421 void SquareInkDropAnimation::SetTransforms(const InkDropTransforms transforms) { 421 void SquareInkDropRipple::SetTransforms(const InkDropTransforms transforms) {
422 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 422 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
423 painted_layers_[i]->SetTransform(transforms[i]); 423 painted_layers_[i]->SetTransform(transforms[i]);
424 } 424 }
425 425
426 void SquareInkDropAnimation::SetOpacity(float opacity) { 426 void SquareInkDropRipple::SetOpacity(float opacity) {
427 root_layer_.SetOpacity(opacity); 427 root_layer_.SetOpacity(opacity);
428 } 428 }
429 429
430 void SquareInkDropAnimation::AnimateToOpacity( 430 void SquareInkDropRipple::AnimateToOpacity(
431 float opacity, 431 float opacity,
432 base::TimeDelta duration, 432 base::TimeDelta duration,
433 ui::LayerAnimator::PreemptionStrategy preemption_strategy, 433 ui::LayerAnimator::PreemptionStrategy preemption_strategy,
434 gfx::Tween::Type tween, 434 gfx::Tween::Type tween,
435 ui::LayerAnimationObserver* animation_observer) { 435 ui::LayerAnimationObserver* animation_observer) {
436 ui::LayerAnimator* animator = root_layer_.GetAnimator(); 436 ui::LayerAnimator* animator = root_layer_.GetAnimator();
437 ui::ScopedLayerAnimationSettings animation_settings(animator); 437 ui::ScopedLayerAnimationSettings animation_settings(animator);
438 animation_settings.SetPreemptionStrategy(preemption_strategy); 438 animation_settings.SetPreemptionStrategy(preemption_strategy);
439 animation_settings.SetTweenType(tween); 439 animation_settings.SetTweenType(tween);
440 ui::LayerAnimationElement* animation_element = 440 ui::LayerAnimationElement* animation_element =
441 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration); 441 ui::LayerAnimationElement::CreateOpacityElement(opacity, duration);
442 ui::LayerAnimationSequence* animation_sequence = 442 ui::LayerAnimationSequence* animation_sequence =
443 new ui::LayerAnimationSequence(animation_element); 443 new ui::LayerAnimationSequence(animation_element);
444 444
445 if (animation_observer) 445 if (animation_observer)
446 animation_sequence->AddObserver(animation_observer); 446 animation_sequence->AddObserver(animation_observer);
447 447
448 animator->StartAnimation(animation_sequence); 448 animator->StartAnimation(animation_sequence);
449 } 449 }
450 450
451 void SquareInkDropAnimation::CalculateCircleTransforms( 451 void SquareInkDropRipple::CalculateCircleTransforms(
452 const gfx::Size& size, 452 const gfx::Size& size,
453 InkDropTransforms* transforms_out) const { 453 InkDropTransforms* transforms_out) const {
454 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f, 454 CalculateRectTransforms(size, std::min(size.width(), size.height()) / 2.0f,
455 transforms_out); 455 transforms_out);
456 } 456 }
457 457
458 void SquareInkDropAnimation::CalculateRectTransforms( 458 void SquareInkDropRipple::CalculateRectTransforms(
459 const gfx::Size& size, 459 const gfx::Size& size,
460 float corner_radius, 460 float corner_radius,
461 InkDropTransforms* transforms_out) const { 461 InkDropTransforms* transforms_out) const {
462 DCHECK_GE(size.width() / 2.0f, corner_radius) 462 DCHECK_GE(size.width() / 2.0f, corner_radius)
463 << "The circle's diameter should not be greater than the total width."; 463 << "The circle's diameter should not be greater than the total width.";
464 DCHECK_GE(size.height() / 2.0f, corner_radius) 464 DCHECK_GE(size.height() / 2.0f, corner_radius)
465 << "The circle's diameter should not be greater than the total height."; 465 << "The circle's diameter should not be greater than the total height.";
466 466
467 // The shapes are drawn such that their center points are not at the origin. 467 // The shapes are drawn such that their center points are not at the origin.
468 // Thus we use the CalculateCircleTransform() and CalculateRectTransform() 468 // Thus we use the CalculateCircleTransform() and CalculateRectTransform()
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 std::max(kMinimumRectScale, 502 std::max(kMinimumRectScale,
503 (size.height() - 2.0f * corner_radius) / rect_delegate_height)); 503 (size.height() - 2.0f * corner_radius) / rect_delegate_height));
504 504
505 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform( 505 (*transforms_out)[VERTICAL_RECT] = CalculateRectTransform(
506 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()), 506 ToRoundedPoint(rect_layer_delegate_->GetCenterPoint()),
507 std::max(kMinimumRectScale, 507 std::max(kMinimumRectScale,
508 (size.width() - 2.0f * corner_radius) / rect_delegate_width), 508 (size.width() - 2.0f * corner_radius) / rect_delegate_width),
509 std::max(kMinimumRectScale, size.height() / rect_delegate_height)); 509 std::max(kMinimumRectScale, size.height() / rect_delegate_height));
510 } 510 }
511 511
512 void SquareInkDropAnimation::GetCurrentTransforms( 512 void SquareInkDropRipple::GetCurrentTransforms(
513 InkDropTransforms* transforms_out) const { 513 InkDropTransforms* transforms_out) const {
514 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i) 514 for (int i = 0; i < PAINTED_SHAPE_COUNT; ++i)
515 (*transforms_out)[i] = painted_layers_[i]->transform(); 515 (*transforms_out)[i] = painted_layers_[i]->transform();
516 } 516 }
517 517
518 void SquareInkDropAnimation::GetActivatedTargetTransforms( 518 void SquareInkDropRipple::GetActivatedTargetTransforms(
519 InkDropTransforms* transforms_out) const { 519 InkDropTransforms* transforms_out) const {
520 CalculateRectTransforms(small_size_, small_corner_radius_, transforms_out); 520 CalculateRectTransforms(small_size_, small_corner_radius_, transforms_out);
521 } 521 }
522 522
523 void SquareInkDropAnimation::AddPaintLayer(PaintedShape painted_shape) { 523 void SquareInkDropRipple::AddPaintLayer(PaintedShape painted_shape) {
524 ui::LayerDelegate* delegate = nullptr; 524 ui::LayerDelegate* delegate = nullptr;
525 switch (painted_shape) { 525 switch (painted_shape) {
526 case TOP_LEFT_CIRCLE: 526 case TOP_LEFT_CIRCLE:
527 case TOP_RIGHT_CIRCLE: 527 case TOP_RIGHT_CIRCLE:
528 case BOTTOM_RIGHT_CIRCLE: 528 case BOTTOM_RIGHT_CIRCLE:
529 case BOTTOM_LEFT_CIRCLE: 529 case BOTTOM_LEFT_CIRCLE:
530 delegate = circle_layer_delegate_.get(); 530 delegate = circle_layer_delegate_.get();
531 break; 531 break;
532 case HORIZONTAL_RECT: 532 case HORIZONTAL_RECT:
533 case VERTICAL_RECT: 533 case VERTICAL_RECT:
(...skipping 12 matching lines...) Expand all
546 layer->set_delegate(delegate); 546 layer->set_delegate(delegate);
547 layer->SetVisible(true); 547 layer->SetVisible(true);
548 layer->SetOpacity(1.0); 548 layer->SetOpacity(1.0);
549 layer->SetMasksToBounds(false); 549 layer->SetMasksToBounds(false);
550 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape)); 550 layer->set_name("PAINTED_SHAPE_COUNT:" + ToLayerName(painted_shape));
551 551
552 painted_layers_[painted_shape].reset(layer); 552 painted_layers_[painted_shape].reset(layer);
553 } 553 }
554 554
555 } // namespace views 555 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/animation/square_ink_drop_ripple.h ('k') | ui/views/animation/square_ink_drop_ripple_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698