OLD | NEW |
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 "cc/animation/animation_host.h" | 5 #include "cc/animation/animation_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "cc/animation/animation_delegate.h" | 10 #include "cc/animation/animation_delegate.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 const gfx::ScrollOffset& target_offset, | 47 const gfx::ScrollOffset& target_offset, |
48 const gfx::ScrollOffset& current_offset) { | 48 const gfx::ScrollOffset& current_offset) { |
49 scoped_ptr<ScrollOffsetAnimationCurve> curve = | 49 scoped_ptr<ScrollOffsetAnimationCurve> curve = |
50 ScrollOffsetAnimationCurve::Create( | 50 ScrollOffsetAnimationCurve::Create( |
51 target_offset, EaseInOutTimingFunction::Create(), | 51 target_offset, EaseInOutTimingFunction::Create(), |
52 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); | 52 ScrollOffsetAnimationCurve::DurationBehavior::INVERSE_DELTA); |
53 curve->SetInitialValue(current_offset); | 53 curve->SetInitialValue(current_offset); |
54 | 54 |
55 scoped_ptr<Animation> animation = Animation::Create( | 55 scoped_ptr<Animation> animation = Animation::Create( |
56 std::move(curve), AnimationIdProvider::NextAnimationId(), | 56 std::move(curve), AnimationIdProvider::NextAnimationId(), |
57 AnimationIdProvider::NextGroupId(), Animation::SCROLL_OFFSET); | 57 AnimationIdProvider::NextGroupId(), |
| 58 AnimationTargetProperty::SCROLL_OFFSET); |
58 animation->set_is_impl_only(true); | 59 animation->set_is_impl_only(true); |
59 | 60 |
60 DCHECK(scroll_offset_animation_player_); | 61 DCHECK(scroll_offset_animation_player_); |
61 DCHECK(scroll_offset_animation_player_->animation_timeline()); | 62 DCHECK(scroll_offset_animation_player_->animation_timeline()); |
62 | 63 |
63 ReattachScrollOffsetPlayerIfNeeded(layer_id); | 64 ReattachScrollOffsetPlayerIfNeeded(layer_id); |
64 | 65 |
65 scroll_offset_animation_player_->AddAnimation(std::move(animation)); | 66 scroll_offset_animation_player_->AddAnimation(std::move(animation)); |
66 } | 67 } |
67 | 68 |
68 bool ScrollAnimationUpdateTarget(int layer_id, | 69 bool ScrollAnimationUpdateTarget(int layer_id, |
69 const gfx::Vector2dF& scroll_delta, | 70 const gfx::Vector2dF& scroll_delta, |
70 const gfx::ScrollOffset& max_scroll_offset, | 71 const gfx::ScrollOffset& max_scroll_offset, |
71 base::TimeTicks frame_monotonic_time) { | 72 base::TimeTicks frame_monotonic_time) { |
72 DCHECK(scroll_offset_animation_player_); | 73 DCHECK(scroll_offset_animation_player_); |
73 if (!scroll_offset_animation_player_->element_animations()) | 74 if (!scroll_offset_animation_player_->element_animations()) |
74 return false; | 75 return false; |
75 | 76 |
76 DCHECK_EQ(layer_id, scroll_offset_animation_player_->layer_id()); | 77 DCHECK_EQ(layer_id, scroll_offset_animation_player_->layer_id()); |
77 | 78 |
78 Animation* animation = scroll_offset_animation_player_->element_animations() | 79 Animation* animation = |
79 ->layer_animation_controller() | 80 scroll_offset_animation_player_->element_animations() |
80 ->GetAnimation(Animation::SCROLL_OFFSET); | 81 ->layer_animation_controller() |
| 82 ->GetAnimation(AnimationTargetProperty::SCROLL_OFFSET); |
81 if (!animation) { | 83 if (!animation) { |
82 scroll_offset_animation_player_->DetachLayer(); | 84 scroll_offset_animation_player_->DetachLayer(); |
83 return false; | 85 return false; |
84 } | 86 } |
85 | 87 |
86 ScrollOffsetAnimationCurve* curve = | 88 ScrollOffsetAnimationCurve* curve = |
87 animation->curve()->ToScrollOffsetAnimationCurve(); | 89 animation->curve()->ToScrollOffsetAnimationCurve(); |
88 | 90 |
89 gfx::ScrollOffset new_target = | 91 gfx::ScrollOffset new_target = |
90 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); | 92 gfx::ScrollOffsetWithDelta(curve->target_value(), scroll_delta); |
91 new_target.SetToMax(gfx::ScrollOffset()); | 93 new_target.SetToMax(gfx::ScrollOffset()); |
92 new_target.SetToMin(max_scroll_offset); | 94 new_target.SetToMin(max_scroll_offset); |
93 | 95 |
94 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( | 96 curve->UpdateTarget(animation->TrimTimeToCurrentIteration( |
95 frame_monotonic_time).InSecondsF(), | 97 frame_monotonic_time).InSecondsF(), |
96 new_target); | 98 new_target); |
97 | 99 |
98 return true; | 100 return true; |
99 } | 101 } |
100 | 102 |
101 void ScrollAnimationAbort() { | 103 void ScrollAnimationAbort() { |
102 DCHECK(scroll_offset_animation_player_); | 104 DCHECK(scroll_offset_animation_player_); |
103 scroll_offset_animation_player_->AbortAnimations(Animation::SCROLL_OFFSET); | 105 scroll_offset_animation_player_->AbortAnimations( |
| 106 AnimationTargetProperty::SCROLL_OFFSET); |
104 } | 107 } |
105 | 108 |
106 // AnimationDelegate implementation. | 109 // AnimationDelegate implementation. |
107 void NotifyAnimationStarted(base::TimeTicks monotonic_time, | 110 void NotifyAnimationStarted(base::TimeTicks monotonic_time, |
108 Animation::TargetProperty target_property, | 111 AnimationTargetProperty target_property, |
109 int group) override {} | 112 int group) override {} |
110 void NotifyAnimationFinished(base::TimeTicks monotonic_time, | 113 void NotifyAnimationFinished(base::TimeTicks monotonic_time, |
111 Animation::TargetProperty target_property, | 114 AnimationTargetProperty target_property, |
112 int group) override { | 115 int group) override { |
113 DCHECK_EQ(target_property, Animation::SCROLL_OFFSET); | 116 DCHECK_EQ(target_property, AnimationTargetProperty::SCROLL_OFFSET); |
114 DCHECK(animation_host_->mutator_host_client()); | 117 DCHECK(animation_host_->mutator_host_client()); |
115 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); | 118 animation_host_->mutator_host_client()->ScrollOffsetAnimationFinished(); |
116 } | 119 } |
117 void NotifyAnimationAborted(base::TimeTicks monotonic_time, | 120 void NotifyAnimationAborted(base::TimeTicks monotonic_time, |
118 Animation::TargetProperty target_property, | 121 AnimationTargetProperty target_property, |
119 int group) override {} | 122 int group) override {} |
120 | 123 |
121 private: | 124 private: |
122 void ReattachScrollOffsetPlayerIfNeeded(int layer_id) { | 125 void ReattachScrollOffsetPlayerIfNeeded(int layer_id) { |
123 if (scroll_offset_animation_player_->layer_id() != layer_id) { | 126 if (scroll_offset_animation_player_->layer_id() != layer_id) { |
124 if (scroll_offset_animation_player_->layer_id()) | 127 if (scroll_offset_animation_player_->layer_id()) |
125 scroll_offset_animation_player_->DetachLayer(); | 128 scroll_offset_animation_player_->DetachLayer(); |
126 if (layer_id) | 129 if (layer_id) |
127 scroll_offset_animation_player_->AttachLayer(layer_id); | 130 scroll_offset_animation_player_->AttachLayer(layer_id); |
128 } | 131 } |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 return tree_type == LayerTreeType::ACTIVE | 388 return tree_type == LayerTreeType::ACTIVE |
386 ? LayerAnimationController::ObserverType::ACTIVE | 389 ? LayerAnimationController::ObserverType::ACTIVE |
387 : LayerAnimationController::ObserverType::PENDING; | 390 : LayerAnimationController::ObserverType::PENDING; |
388 } | 391 } |
389 | 392 |
390 bool AnimationHost::IsAnimatingFilterProperty(int layer_id, | 393 bool AnimationHost::IsAnimatingFilterProperty(int layer_id, |
391 LayerTreeType tree_type) const { | 394 LayerTreeType tree_type) const { |
392 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 395 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
393 return controller | 396 return controller |
394 ? controller->IsCurrentlyAnimatingProperty( | 397 ? controller->IsCurrentlyAnimatingProperty( |
395 Animation::FILTER, ObserverTypeFromTreeType(tree_type)) | 398 AnimationTargetProperty::FILTER, |
| 399 ObserverTypeFromTreeType(tree_type)) |
396 : false; | 400 : false; |
397 } | 401 } |
398 | 402 |
399 bool AnimationHost::IsAnimatingOpacityProperty(int layer_id, | 403 bool AnimationHost::IsAnimatingOpacityProperty(int layer_id, |
400 LayerTreeType tree_type) const { | 404 LayerTreeType tree_type) const { |
401 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 405 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
402 return controller | 406 return controller |
403 ? controller->IsCurrentlyAnimatingProperty( | 407 ? controller->IsCurrentlyAnimatingProperty( |
404 Animation::OPACITY, ObserverTypeFromTreeType(tree_type)) | 408 AnimationTargetProperty::OPACITY, |
| 409 ObserverTypeFromTreeType(tree_type)) |
405 : false; | 410 : false; |
406 } | 411 } |
407 | 412 |
408 bool AnimationHost::IsAnimatingTransformProperty( | 413 bool AnimationHost::IsAnimatingTransformProperty( |
409 int layer_id, | 414 int layer_id, |
410 LayerTreeType tree_type) const { | 415 LayerTreeType tree_type) const { |
411 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 416 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
412 return controller | 417 return controller |
413 ? controller->IsCurrentlyAnimatingProperty( | 418 ? controller->IsCurrentlyAnimatingProperty( |
414 Animation::TRANSFORM, ObserverTypeFromTreeType(tree_type)) | 419 AnimationTargetProperty::TRANSFORM, |
| 420 ObserverTypeFromTreeType(tree_type)) |
415 : false; | 421 : false; |
416 } | 422 } |
417 | 423 |
418 bool AnimationHost::HasPotentiallyRunningFilterAnimation( | 424 bool AnimationHost::HasPotentiallyRunningFilterAnimation( |
419 int layer_id, | 425 int layer_id, |
420 LayerTreeType tree_type) const { | 426 LayerTreeType tree_type) const { |
421 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 427 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
422 return controller | 428 return controller |
423 ? controller->IsPotentiallyAnimatingProperty( | 429 ? controller->IsPotentiallyAnimatingProperty( |
424 Animation::FILTER, ObserverTypeFromTreeType(tree_type)) | 430 AnimationTargetProperty::FILTER, |
| 431 ObserverTypeFromTreeType(tree_type)) |
425 : false; | 432 : false; |
426 } | 433 } |
427 | 434 |
428 bool AnimationHost::HasPotentiallyRunningOpacityAnimation( | 435 bool AnimationHost::HasPotentiallyRunningOpacityAnimation( |
429 int layer_id, | 436 int layer_id, |
430 LayerTreeType tree_type) const { | 437 LayerTreeType tree_type) const { |
431 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 438 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
432 return controller | 439 return controller |
433 ? controller->IsPotentiallyAnimatingProperty( | 440 ? controller->IsPotentiallyAnimatingProperty( |
434 Animation::OPACITY, ObserverTypeFromTreeType(tree_type)) | 441 AnimationTargetProperty::OPACITY, |
| 442 ObserverTypeFromTreeType(tree_type)) |
435 : false; | 443 : false; |
436 } | 444 } |
437 | 445 |
438 bool AnimationHost::HasPotentiallyRunningTransformAnimation( | 446 bool AnimationHost::HasPotentiallyRunningTransformAnimation( |
439 int layer_id, | 447 int layer_id, |
440 LayerTreeType tree_type) const { | 448 LayerTreeType tree_type) const { |
441 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 449 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
442 return controller | 450 return controller |
443 ? controller->IsPotentiallyAnimatingProperty( | 451 ? controller->IsPotentiallyAnimatingProperty( |
444 Animation::TRANSFORM, ObserverTypeFromTreeType(tree_type)) | 452 AnimationTargetProperty::TRANSFORM, |
| 453 ObserverTypeFromTreeType(tree_type)) |
445 : false; | 454 : false; |
446 } | 455 } |
447 | 456 |
448 bool AnimationHost::HasAnyAnimationTargetingProperty( | 457 bool AnimationHost::HasAnyAnimationTargetingProperty( |
449 int layer_id, | 458 int layer_id, |
450 Animation::TargetProperty property) const { | 459 AnimationTargetProperty property) const { |
451 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 460 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
452 if (!controller) | 461 if (!controller) |
453 return false; | 462 return false; |
454 | 463 |
455 return !!controller->GetAnimation(property); | 464 return !!controller->GetAnimation(property); |
456 } | 465 } |
457 | 466 |
458 bool AnimationHost::FilterIsAnimatingOnImplOnly(int layer_id) const { | 467 bool AnimationHost::FilterIsAnimatingOnImplOnly(int layer_id) const { |
459 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 468 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
460 if (!controller) | 469 if (!controller) |
461 return false; | 470 return false; |
462 | 471 |
463 Animation* animation = controller->GetAnimation(Animation::FILTER); | 472 Animation* animation = |
| 473 controller->GetAnimation(AnimationTargetProperty::FILTER); |
464 return animation && animation->is_impl_only(); | 474 return animation && animation->is_impl_only(); |
465 } | 475 } |
466 | 476 |
467 bool AnimationHost::OpacityIsAnimatingOnImplOnly(int layer_id) const { | 477 bool AnimationHost::OpacityIsAnimatingOnImplOnly(int layer_id) const { |
468 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 478 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
469 if (!controller) | 479 if (!controller) |
470 return false; | 480 return false; |
471 | 481 |
472 Animation* animation = controller->GetAnimation(Animation::OPACITY); | 482 Animation* animation = |
| 483 controller->GetAnimation(AnimationTargetProperty::OPACITY); |
473 return animation && animation->is_impl_only(); | 484 return animation && animation->is_impl_only(); |
474 } | 485 } |
475 | 486 |
476 bool AnimationHost::TransformIsAnimatingOnImplOnly(int layer_id) const { | 487 bool AnimationHost::TransformIsAnimatingOnImplOnly(int layer_id) const { |
477 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 488 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
478 if (!controller) | 489 if (!controller) |
479 return false; | 490 return false; |
480 | 491 |
481 Animation* animation = controller->GetAnimation(Animation::TRANSFORM); | 492 Animation* animation = |
| 493 controller->GetAnimation(AnimationTargetProperty::TRANSFORM); |
482 return animation && animation->is_impl_only(); | 494 return animation && animation->is_impl_only(); |
483 } | 495 } |
484 | 496 |
485 bool AnimationHost::HasFilterAnimationThatInflatesBounds(int layer_id) const { | 497 bool AnimationHost::HasFilterAnimationThatInflatesBounds(int layer_id) const { |
486 LayerAnimationController* controller = GetControllerForLayerId(layer_id); | 498 LayerAnimationController* controller = GetControllerForLayerId(layer_id); |
487 return controller ? controller->HasFilterAnimationThatInflatesBounds() | 499 return controller ? controller->HasFilterAnimationThatInflatesBounds() |
488 : false; | 500 : false; |
489 } | 501 } |
490 | 502 |
491 bool AnimationHost::HasTransformAnimationThatInflatesBounds( | 503 bool AnimationHost::HasTransformAnimationThatInflatesBounds( |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 return scroll_offset_animations_->ScrollAnimationUpdateTarget( | 594 return scroll_offset_animations_->ScrollAnimationUpdateTarget( |
583 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); | 595 layer_id, scroll_delta, max_scroll_offset, frame_monotonic_time); |
584 } | 596 } |
585 | 597 |
586 void AnimationHost::ScrollAnimationAbort() { | 598 void AnimationHost::ScrollAnimationAbort() { |
587 DCHECK(scroll_offset_animations_); | 599 DCHECK(scroll_offset_animations_); |
588 return scroll_offset_animations_->ScrollAnimationAbort(); | 600 return scroll_offset_animations_->ScrollAnimationAbort(); |
589 } | 601 } |
590 | 602 |
591 } // namespace cc | 603 } // namespace cc |
OLD | NEW |