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