| 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/element_animations.h" | 5 #include "cc/animation/element_animations.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "cc/animation/animation_delegate.h" | 13 #include "cc/animation/animation_delegate.h" |
| 14 #include "cc/animation/animation_events.h" |
| 14 #include "cc/animation/animation_host.h" | 15 #include "cc/animation/animation_host.h" |
| 15 #include "cc/animation/animation_player.h" | 16 #include "cc/animation/animation_player.h" |
| 16 #include "cc/animation/keyframed_animation_curve.h" | 17 #include "cc/animation/keyframed_animation_curve.h" |
| 17 #include "cc/output/filter_operations.h" | 18 #include "cc/output/filter_operations.h" |
| 18 #include "cc/trees/mutator_host_client.h" | 19 #include "cc/trees/mutator_host_client.h" |
| 19 #include "ui/gfx/geometry/box_f.h" | 20 #include "ui/gfx/geometry/box_f.h" |
| 20 | 21 |
| 21 namespace cc { | 22 namespace cc { |
| 22 | 23 |
| 23 scoped_refptr<ElementAnimations> ElementAnimations::Create() { | 24 scoped_refptr<ElementAnimations> ElementAnimations::Create() { |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 | 152 |
| 152 // Update impl client state. | 153 // Update impl client state. |
| 153 if (needs_update_impl_client_state_) | 154 if (needs_update_impl_client_state_) |
| 154 element_animations_impl->UpdateClientAnimationState(); | 155 element_animations_impl->UpdateClientAnimationState(); |
| 155 needs_update_impl_client_state_ = false; | 156 needs_update_impl_client_state_ = false; |
| 156 | 157 |
| 157 element_animations_impl->UpdateActivation(ActivationType::NORMAL); | 158 element_animations_impl->UpdateActivation(ActivationType::NORMAL); |
| 158 UpdateActivation(ActivationType::NORMAL); | 159 UpdateActivation(ActivationType::NORMAL); |
| 159 } | 160 } |
| 160 | 161 |
| 161 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { | |
| 162 // TODO(loyso): Erase this. Rewrite element_animations_unittest to use | |
| 163 // AnimationPlayer::AddAnimation. | |
| 164 | |
| 165 // Add animation to the first player. | |
| 166 DCHECK(players_list_->might_have_observers()); | |
| 167 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 168 AnimationPlayer* player = it.GetNext(); | |
| 169 DCHECK(player); | |
| 170 player->AddAnimation(std::move(animation)); | |
| 171 } | |
| 172 | |
| 173 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { | 162 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { |
| 174 DCHECK(!monotonic_time.is_null()); | 163 DCHECK(!monotonic_time.is_null()); |
| 175 if (!has_element_in_active_list() && !has_element_in_pending_list()) | 164 if (!has_element_in_active_list() && !has_element_in_pending_list()) |
| 176 return; | 165 return; |
| 177 | 166 |
| 178 { | 167 { |
| 179 // TODO(crbug.com/634916): Shouldn't manually iterate through the list if | 168 // TODO(crbug.com/634916): Shouldn't manually iterate through the list if |
| 180 // base::ObserverList has a callback mechanism. | 169 // base::ObserverList has a callback mechanism. |
| 181 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | 170 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 182 AnimationPlayer* player; | 171 AnimationPlayer* player; |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | 536 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 548 AnimationPlayer* player; | 537 AnimationPlayer* player; |
| 549 while ((player = it.GetNext()) != nullptr) { | 538 while ((player = it.GetNext()) != nullptr) { |
| 550 if (player->has_any_animation()) | 539 if (player->has_any_animation()) |
| 551 return true; | 540 return true; |
| 552 } | 541 } |
| 553 | 542 |
| 554 return false; | 543 return false; |
| 555 } | 544 } |
| 556 | 545 |
| 546 bool ElementAnimations::HasAnyAnimationTargetingProperty( |
| 547 TargetProperty::Type property) const { |
| 548 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 549 AnimationPlayer* player; |
| 550 while ((player = it.GetNext()) != nullptr) { |
| 551 if (player->GetAnimation(property)) |
| 552 return true; |
| 553 } |
| 554 return false; |
| 555 } |
| 556 |
| 557 bool ElementAnimations::IsPotentiallyAnimatingProperty( | 557 bool ElementAnimations::IsPotentiallyAnimatingProperty( |
| 558 TargetProperty::Type target_property, | 558 TargetProperty::Type target_property, |
| 559 ElementListType list_type) const { | 559 ElementListType list_type) const { |
| 560 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | 560 ElementAnimations::PlayersList::Iterator it(players_list_.get()); |
| 561 AnimationPlayer* player; | 561 AnimationPlayer* player; |
| 562 while ((player = it.GetNext()) != nullptr) { | 562 while ((player = it.GetNext()) != nullptr) { |
| 563 if (player->IsPotentiallyAnimatingProperty(target_property, list_type)) | 563 if (player->IsPotentiallyAnimatingProperty(target_property, list_type)) |
| 564 return true; | 564 return true; |
| 565 } | 565 } |
| 566 | 566 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 577 return true; | 577 return true; |
| 578 } | 578 } |
| 579 | 579 |
| 580 return false; | 580 return false; |
| 581 } | 581 } |
| 582 | 582 |
| 583 void ElementAnimations::SetScrollOffsetAnimationWasInterrupted() { | 583 void ElementAnimations::SetScrollOffsetAnimationWasInterrupted() { |
| 584 scroll_offset_animation_was_interrupted_ = true; | 584 scroll_offset_animation_was_interrupted_ = true; |
| 585 } | 585 } |
| 586 | 586 |
| 587 bool ElementAnimations::needs_to_start_animations_for_testing() const { | |
| 588 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 589 AnimationPlayer* player; | |
| 590 while ((player = it.GetNext()) != nullptr) { | |
| 591 if (player->needs_to_start_animations()) | |
| 592 return true; | |
| 593 } | |
| 594 | |
| 595 return false; | |
| 596 } | |
| 597 | |
| 598 void ElementAnimations::PauseAnimation(int animation_id, | |
| 599 base::TimeDelta time_offset) { | |
| 600 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 601 AnimationPlayer* player; | |
| 602 while ((player = it.GetNext()) != nullptr) | |
| 603 player->PauseAnimation(animation_id, time_offset.InSecondsF()); | |
| 604 } | |
| 605 | |
| 606 void ElementAnimations::RemoveAnimation(int animation_id) { | |
| 607 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 608 AnimationPlayer* player; | |
| 609 while ((player = it.GetNext()) != nullptr) | |
| 610 player->RemoveAnimation(animation_id); | |
| 611 } | |
| 612 | |
| 613 void ElementAnimations::AbortAnimation(int animation_id) { | |
| 614 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 615 AnimationPlayer* player; | |
| 616 while ((player = it.GetNext()) != nullptr) | |
| 617 player->AbortAnimation(animation_id); | |
| 618 } | |
| 619 | |
| 620 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, | |
| 621 bool needs_completion) { | |
| 622 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 623 AnimationPlayer* player; | |
| 624 while ((player = it.GetNext()) != nullptr) | |
| 625 player->AbortAnimations(target_property, needs_completion); | |
| 626 } | |
| 627 | |
| 628 Animation* ElementAnimations::GetAnimation( | |
| 629 TargetProperty::Type target_property) const { | |
| 630 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 631 AnimationPlayer* player; | |
| 632 while ((player = it.GetNext()) != nullptr) { | |
| 633 if (Animation* animation = player->GetAnimation(target_property)) | |
| 634 return animation; | |
| 635 } | |
| 636 return nullptr; | |
| 637 } | |
| 638 | |
| 639 Animation* ElementAnimations::GetAnimationById(int animation_id) const { | |
| 640 ElementAnimations::PlayersList::Iterator it(players_list_.get()); | |
| 641 AnimationPlayer* player; | |
| 642 while ((player = it.GetNext()) != nullptr) { | |
| 643 if (Animation* animation = player->GetAnimationById(animation_id)) | |
| 644 return animation; | |
| 645 } | |
| 646 return nullptr; | |
| 647 } | |
| 648 | |
| 649 void ElementAnimations::OnFilterAnimated(ElementListType list_type, | 587 void ElementAnimations::OnFilterAnimated(ElementListType list_type, |
| 650 const FilterOperations& filters) { | 588 const FilterOperations& filters) { |
| 651 DCHECK(element_id()); | 589 DCHECK(element_id()); |
| 652 DCHECK(animation_host()); | 590 DCHECK(animation_host()); |
| 653 DCHECK(animation_host()->mutator_host_client()); | 591 DCHECK(animation_host()->mutator_host_client()); |
| 654 animation_host()->mutator_host_client()->SetElementFilterMutated( | 592 animation_host()->mutator_host_client()->SetElementFilterMutated( |
| 655 element_id(), list_type, filters); | 593 element_id(), list_type, filters); |
| 656 } | 594 } |
| 657 | 595 |
| 658 void ElementAnimations::OnOpacityAnimated(ElementListType list_type, | 596 void ElementAnimations::OnOpacityAnimated(ElementListType list_type, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 687 if (animation_host()) { | 625 if (animation_host()) { |
| 688 DCHECK(animation_host()->mutator_host_client()); | 626 DCHECK(animation_host()->mutator_host_client()); |
| 689 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 627 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
| 690 element_id()); | 628 element_id()); |
| 691 } | 629 } |
| 692 | 630 |
| 693 return gfx::ScrollOffset(); | 631 return gfx::ScrollOffset(); |
| 694 } | 632 } |
| 695 | 633 |
| 696 } // namespace cc | 634 } // namespace cc |
| OLD | NEW |