| 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 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); | 143 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); |
| 144 | 144 |
| 145 PushPropertiesToImplThread(element_animations_impl.get()); | 145 PushPropertiesToImplThread(element_animations_impl.get()); |
| 146 element_animations_impl->UpdateActivation(NORMAL_ACTIVATION); | 146 element_animations_impl->UpdateActivation(NORMAL_ACTIVATION); |
| 147 UpdateActivation(NORMAL_ACTIVATION); | 147 UpdateActivation(NORMAL_ACTIVATION); |
| 148 } | 148 } |
| 149 | 149 |
| 150 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { | 150 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { |
| 151 DCHECK(!animation->is_impl_only() || | 151 DCHECK(!animation->is_impl_only() || |
| 152 animation->target_property() == TargetProperty::SCROLL_OFFSET); | 152 animation->target_property() == TargetProperty::SCROLL_OFFSET); |
| 153 bool added_transform_animation = | 153 TargetProperty::Type target_property = animation->target_property(); |
| 154 animation->target_property() == TargetProperty::TRANSFORM; | |
| 155 bool added_opacity_animation = | |
| 156 animation->target_property() == TargetProperty::OPACITY; | |
| 157 animations_.push_back(std::move(animation)); | 154 animations_.push_back(std::move(animation)); |
| 158 needs_to_start_animations_ = true; | 155 needs_to_start_animations_ = true; |
| 159 UpdateActivation(NORMAL_ACTIVATION); | 156 UpdateActivation(NORMAL_ACTIVATION); |
| 160 if (added_transform_animation) | 157 switch (target_property) { |
| 161 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 158 case TargetProperty::TRANSFORM: |
| 162 if (added_opacity_animation) | 159 case TargetProperty::OPACITY: |
| 163 UpdateClientAnimationState(TargetProperty::OPACITY); | 160 case TargetProperty::FILTER: |
| 161 UpdateClientAnimationState(target_property); |
| 162 break; |
| 163 default: |
| 164 break; |
| 165 } |
| 164 } | 166 } |
| 165 | 167 |
| 166 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { | 168 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { |
| 167 DCHECK(!monotonic_time.is_null()); | 169 DCHECK(!monotonic_time.is_null()); |
| 168 if (!has_element_in_active_list() && !has_element_in_pending_list()) | 170 if (!has_element_in_active_list() && !has_element_in_pending_list()) |
| 169 return; | 171 return; |
| 170 | 172 |
| 171 if (needs_to_start_animations_) | 173 if (needs_to_start_animations_) |
| 172 StartAnimations(monotonic_time); | 174 StartAnimations(monotonic_time); |
| 173 TickAnimations(monotonic_time); | 175 TickAnimations(monotonic_time); |
| 174 last_tick_time_ = monotonic_time; | 176 last_tick_time_ = monotonic_time; |
| 175 UpdateClientAnimationState(TargetProperty::OPACITY); | 177 UpdateClientAnimationState(TargetProperty::OPACITY); |
| 176 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 178 UpdateClientAnimationState(TargetProperty::TRANSFORM); |
| 179 UpdateClientAnimationState(TargetProperty::FILTER); |
| 177 } | 180 } |
| 178 | 181 |
| 179 void ElementAnimations::UpdateState(bool start_ready_animations, | 182 void ElementAnimations::UpdateState(bool start_ready_animations, |
| 180 AnimationEvents* events) { | 183 AnimationEvents* events) { |
| 181 if (!has_element_in_active_list()) | 184 if (!has_element_in_active_list()) |
| 182 return; | 185 return; |
| 183 | 186 |
| 184 // Animate hasn't been called, this happens if an element has been added | 187 // Animate hasn't been called, this happens if an element has been added |
| 185 // between the Commit and Draw phases. | 188 // between the Commit and Draw phases. |
| 186 if (last_tick_time_ == base::TimeTicks()) | 189 if (last_tick_time_ == base::TimeTicks()) |
| 187 return; | 190 return; |
| 188 | 191 |
| 189 if (start_ready_animations) | 192 if (start_ready_animations) |
| 190 PromoteStartedAnimations(last_tick_time_, events); | 193 PromoteStartedAnimations(last_tick_time_, events); |
| 191 | 194 |
| 192 MarkFinishedAnimations(last_tick_time_); | 195 MarkFinishedAnimations(last_tick_time_); |
| 193 MarkAnimationsForDeletion(last_tick_time_, events); | 196 MarkAnimationsForDeletion(last_tick_time_, events); |
| 194 | 197 |
| 195 if (needs_to_start_animations_ && start_ready_animations) { | 198 if (needs_to_start_animations_ && start_ready_animations) { |
| 196 StartAnimations(last_tick_time_); | 199 StartAnimations(last_tick_time_); |
| 197 PromoteStartedAnimations(last_tick_time_, events); | 200 PromoteStartedAnimations(last_tick_time_, events); |
| 198 } | 201 } |
| 199 | 202 |
| 200 UpdateActivation(NORMAL_ACTIVATION); | 203 UpdateActivation(NORMAL_ACTIVATION); |
| 201 } | 204 } |
| 202 | 205 |
| 203 void ElementAnimations::ActivateAnimations() { | 206 void ElementAnimations::ActivateAnimations() { |
| 204 bool changed_transform_animation = false; | 207 bool changed_transform_animation = false; |
| 205 bool changed_opacity_animation = false; | 208 bool changed_opacity_animation = false; |
| 209 bool changed_filter_animation = false; |
| 206 for (size_t i = 0; i < animations_.size(); ++i) { | 210 for (size_t i = 0; i < animations_.size(); ++i) { |
| 207 if (animations_[i]->affects_active_elements() != | 211 if (animations_[i]->affects_active_elements() != |
| 208 animations_[i]->affects_pending_elements()) { | 212 animations_[i]->affects_pending_elements()) { |
| 209 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) | 213 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) |
| 210 changed_transform_animation = true; | 214 changed_transform_animation = true; |
| 211 else if (animations_[i]->target_property() == TargetProperty::OPACITY) | 215 else if (animations_[i]->target_property() == TargetProperty::OPACITY) |
| 212 changed_opacity_animation = true; | 216 changed_opacity_animation = true; |
| 217 else if (animations_[i]->target_property() == TargetProperty::FILTER) |
| 218 changed_filter_animation = true; |
| 213 } | 219 } |
| 214 animations_[i]->set_affects_active_elements( | 220 animations_[i]->set_affects_active_elements( |
| 215 animations_[i]->affects_pending_elements()); | 221 animations_[i]->affects_pending_elements()); |
| 216 } | 222 } |
| 217 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { | 223 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { |
| 218 return !animation->affects_active_elements() && | 224 return !animation->affects_active_elements() && |
| 219 !animation->affects_pending_elements(); | 225 !animation->affects_pending_elements(); |
| 220 }; | 226 }; |
| 221 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 227 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), |
| 222 affects_no_elements), | 228 affects_no_elements), |
| 223 animations_.end()); | 229 animations_.end()); |
| 224 scroll_offset_animation_was_interrupted_ = false; | 230 scroll_offset_animation_was_interrupted_ = false; |
| 225 UpdateActivation(NORMAL_ACTIVATION); | 231 UpdateActivation(NORMAL_ACTIVATION); |
| 226 if (changed_transform_animation) | 232 if (changed_transform_animation) |
| 227 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 233 UpdateClientAnimationState(TargetProperty::TRANSFORM); |
| 228 if (changed_opacity_animation) | 234 if (changed_opacity_animation) |
| 229 UpdateClientAnimationState(TargetProperty::OPACITY); | 235 UpdateClientAnimationState(TargetProperty::OPACITY); |
| 236 if (changed_filter_animation) |
| 237 UpdateClientAnimationState(TargetProperty::FILTER); |
| 230 } | 238 } |
| 231 | 239 |
| 232 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { | 240 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { |
| 233 if (event.is_impl_only) { | 241 if (event.is_impl_only) { |
| 234 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, | 242 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, |
| 235 event.group_id); | 243 event.group_id); |
| 236 return; | 244 return; |
| 237 } | 245 } |
| 238 | 246 |
| 239 for (size_t i = 0; i < animations_.size(); ++i) { | 247 for (size_t i = 0; i < animations_.size(); ++i) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET); | 283 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET); |
| 276 if (!players_list_->empty()) { | 284 if (!players_list_->empty()) { |
| 277 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); | 285 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); |
| 278 NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property, | 286 NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property, |
| 279 event.animation_start_time, | 287 event.animation_start_time, |
| 280 std::move(animation_curve)); | 288 std::move(animation_curve)); |
| 281 } | 289 } |
| 282 } | 290 } |
| 283 | 291 |
| 284 void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { | 292 void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { |
| 285 bool aborted_transform_animation = false; | |
| 286 bool aborted_opacity_animation = false; | |
| 287 for (size_t i = 0; i < animations_.size(); ++i) { | 293 for (size_t i = 0; i < animations_.size(); ++i) { |
| 288 if (animations_[i]->group() == event.group_id && | 294 if (animations_[i]->group() == event.group_id && |
| 289 animations_[i]->target_property() == event.target_property) { | 295 animations_[i]->target_property() == event.target_property) { |
| 290 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); | 296 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); |
| 291 animations_[i]->set_received_finished_event(true); | 297 animations_[i]->set_received_finished_event(true); |
| 292 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, | 298 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, |
| 293 event.group_id); | 299 event.group_id); |
| 294 if (event.target_property == TargetProperty::TRANSFORM) | |
| 295 aborted_transform_animation = true; | |
| 296 else if (event.target_property == TargetProperty::OPACITY) | |
| 297 aborted_opacity_animation = true; | |
| 298 break; | 300 break; |
| 299 } | 301 } |
| 300 } | 302 } |
| 301 if (aborted_transform_animation) | 303 switch (event.target_property) { |
| 302 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 304 case TargetProperty::TRANSFORM: |
| 303 if (aborted_opacity_animation) | 305 case TargetProperty::OPACITY: |
| 304 UpdateClientAnimationState(TargetProperty::OPACITY); | 306 case TargetProperty::FILTER: |
| 307 UpdateClientAnimationState(event.target_property); |
| 308 break; |
| 309 default: |
| 310 break; |
| 311 } |
| 305 } | 312 } |
| 306 | 313 |
| 307 void ElementAnimations::NotifyAnimationPropertyUpdate( | 314 void ElementAnimations::NotifyAnimationPropertyUpdate( |
| 308 const AnimationEvent& event) { | 315 const AnimationEvent& event) { |
| 309 bool notify_active_elements = true; | 316 bool notify_active_elements = true; |
| 310 bool notify_pending_elements = true; | 317 bool notify_pending_elements = true; |
| 311 switch (event.target_property) { | 318 switch (event.target_property) { |
| 312 case TargetProperty::OPACITY: | 319 case TargetProperty::OPACITY: |
| 313 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, | 320 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, |
| 314 notify_pending_elements); | 321 notify_pending_elements); |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 return (animation->run_state() == Animation::WAITING_FOR_DELETION); | 560 return (animation->run_state() == Animation::WAITING_FOR_DELETION); |
| 554 } else { | 561 } else { |
| 555 return !main_thread_element_animations->GetAnimationById(animation->id()); | 562 return !main_thread_element_animations->GetAnimationById(animation->id()); |
| 556 } | 563 } |
| 557 } | 564 } |
| 558 | 565 |
| 559 void ElementAnimations::RemoveAnimationsCompletedOnMainThread( | 566 void ElementAnimations::RemoveAnimationsCompletedOnMainThread( |
| 560 ElementAnimations* element_animations_impl) const { | 567 ElementAnimations* element_animations_impl) const { |
| 561 bool removed_transform_animation = false; | 568 bool removed_transform_animation = false; |
| 562 bool removed_opacity_animation = false; | 569 bool removed_opacity_animation = false; |
| 570 bool removed_filter_animation = false; |
| 563 // Animations removed on the main thread should no longer affect pending | 571 // Animations removed on the main thread should no longer affect pending |
| 564 // elements, and should stop affecting active elements after the next call | 572 // elements, and should stop affecting active elements after the next call |
| 565 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed | 573 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed |
| 566 // immediately. | 574 // immediately. |
| 567 auto& animations = element_animations_impl->animations_; | 575 auto& animations = element_animations_impl->animations_; |
| 568 for (const auto& animation : animations) { | 576 for (const auto& animation : animations) { |
| 569 if (IsCompleted(animation.get(), this)) { | 577 if (IsCompleted(animation.get(), this)) { |
| 570 animation->set_affects_pending_elements(false); | 578 animation->set_affects_pending_elements(false); |
| 571 if (animation->target_property() == TargetProperty::TRANSFORM) | 579 if (animation->target_property() == TargetProperty::TRANSFORM) |
| 572 removed_transform_animation = true; | 580 removed_transform_animation = true; |
| 573 else if (animation->target_property() == TargetProperty::OPACITY) | 581 else if (animation->target_property() == TargetProperty::OPACITY) |
| 574 removed_opacity_animation = true; | 582 removed_opacity_animation = true; |
| 583 else if (animation->target_property() == TargetProperty::FILTER) |
| 584 removed_filter_animation = true; |
| 575 } | 585 } |
| 576 } | 586 } |
| 577 auto affects_active_only_and_is_waiting_for_deletion = | 587 auto affects_active_only_and_is_waiting_for_deletion = |
| 578 [](const std::unique_ptr<Animation>& animation) { | 588 [](const std::unique_ptr<Animation>& animation) { |
| 579 return animation->run_state() == Animation::WAITING_FOR_DELETION && | 589 return animation->run_state() == Animation::WAITING_FOR_DELETION && |
| 580 !animation->affects_pending_elements(); | 590 !animation->affects_pending_elements(); |
| 581 }; | 591 }; |
| 582 animations.erase( | 592 animations.erase( |
| 583 std::remove_if(animations.begin(), animations.end(), | 593 std::remove_if(animations.begin(), animations.end(), |
| 584 affects_active_only_and_is_waiting_for_deletion), | 594 affects_active_only_and_is_waiting_for_deletion), |
| 585 animations.end()); | 595 animations.end()); |
| 586 | 596 |
| 587 if (removed_transform_animation) | 597 if (removed_transform_animation) { |
| 588 element_animations_impl->UpdateClientAnimationState( | 598 element_animations_impl->UpdateClientAnimationState( |
| 589 TargetProperty::TRANSFORM); | 599 TargetProperty::TRANSFORM); |
| 590 if (removed_opacity_animation) | 600 } |
| 601 if (removed_opacity_animation) { |
| 591 element_animations_impl->UpdateClientAnimationState( | 602 element_animations_impl->UpdateClientAnimationState( |
| 592 TargetProperty::OPACITY); | 603 TargetProperty::OPACITY); |
| 604 } |
| 605 if (removed_filter_animation) { |
| 606 element_animations_impl->UpdateClientAnimationState(TargetProperty::FILTER); |
| 607 } |
| 593 } | 608 } |
| 594 | 609 |
| 595 void ElementAnimations::PushPropertiesToImplThread( | 610 void ElementAnimations::PushPropertiesToImplThread( |
| 596 ElementAnimations* element_animations_impl) { | 611 ElementAnimations* element_animations_impl) { |
| 597 for (size_t i = 0; i < animations_.size(); ++i) { | 612 for (size_t i = 0; i < animations_.size(); ++i) { |
| 598 Animation* current_impl = | 613 Animation* current_impl = |
| 599 element_animations_impl->GetAnimationById(animations_[i]->id()); | 614 element_animations_impl->GetAnimationById(animations_[i]->id()); |
| 600 if (current_impl) | 615 if (current_impl) |
| 601 animations_[i]->PushPropertiesTo(current_impl); | 616 animations_[i]->PushPropertiesTo(current_impl); |
| 602 } | 617 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 else | 741 else |
| 727 events->events_.push_back(started_event); | 742 events->events_.push_back(started_event); |
| 728 } | 743 } |
| 729 } | 744 } |
| 730 } | 745 } |
| 731 } | 746 } |
| 732 | 747 |
| 733 void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) { | 748 void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) { |
| 734 bool finished_transform_animation = false; | 749 bool finished_transform_animation = false; |
| 735 bool finished_opacity_animation = false; | 750 bool finished_opacity_animation = false; |
| 751 bool finished_filter_animation = false; |
| 736 for (size_t i = 0; i < animations_.size(); ++i) { | 752 for (size_t i = 0; i < animations_.size(); ++i) { |
| 737 if (!animations_[i]->is_finished() && | 753 if (!animations_[i]->is_finished() && |
| 738 animations_[i]->IsFinishedAt(monotonic_time)) { | 754 animations_[i]->IsFinishedAt(monotonic_time)) { |
| 739 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 755 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
| 740 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) | 756 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) |
| 741 finished_transform_animation = true; | 757 finished_transform_animation = true; |
| 742 else if (animations_[i]->target_property() == TargetProperty::OPACITY) | 758 else if (animations_[i]->target_property() == TargetProperty::OPACITY) |
| 743 finished_opacity_animation = true; | 759 finished_opacity_animation = true; |
| 760 else if (animations_[i]->target_property() == TargetProperty::FILTER) |
| 761 finished_filter_animation = true; |
| 744 } | 762 } |
| 745 } | 763 } |
| 746 if (finished_transform_animation) | 764 if (finished_transform_animation) |
| 747 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 765 UpdateClientAnimationState(TargetProperty::TRANSFORM); |
| 748 if (finished_opacity_animation) | 766 if (finished_opacity_animation) |
| 749 UpdateClientAnimationState(TargetProperty::OPACITY); | 767 UpdateClientAnimationState(TargetProperty::OPACITY); |
| 768 if (finished_filter_animation) |
| 769 UpdateClientAnimationState(TargetProperty::FILTER); |
| 750 } | 770 } |
| 751 | 771 |
| 752 void ElementAnimations::MarkAnimationsForDeletion( | 772 void ElementAnimations::MarkAnimationsForDeletion( |
| 753 base::TimeTicks monotonic_time, | 773 base::TimeTicks monotonic_time, |
| 754 AnimationEvents* events) { | 774 AnimationEvents* events) { |
| 755 bool marked_animations_for_deletions = false; | 775 bool marked_animations_for_deletions = false; |
| 756 std::vector<size_t> animations_with_same_group_id; | 776 std::vector<size_t> animations_with_same_group_id; |
| 757 | 777 |
| 758 animations_with_same_group_id.reserve(animations_.size()); | 778 animations_with_same_group_id.reserve(animations_.size()); |
| 759 // Non-aborted animations are marked for deletion after a corresponding | 779 // Non-aborted animations are marked for deletion after a corresponding |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 } | 892 } |
| 873 } | 893 } |
| 874 if (marked_animations_for_deletions) | 894 if (marked_animations_for_deletions) |
| 875 NotifyClientAnimationWaitingForDeletion(); | 895 NotifyClientAnimationWaitingForDeletion(); |
| 876 } | 896 } |
| 877 | 897 |
| 878 void ElementAnimations::MarkAbortedAnimationsForDeletion( | 898 void ElementAnimations::MarkAbortedAnimationsForDeletion( |
| 879 ElementAnimations* element_animations_impl) const { | 899 ElementAnimations* element_animations_impl) const { |
| 880 bool aborted_transform_animation = false; | 900 bool aborted_transform_animation = false; |
| 881 bool aborted_opacity_animation = false; | 901 bool aborted_opacity_animation = false; |
| 902 bool aborted_filter_animation = false; |
| 882 auto& animations_impl = element_animations_impl->animations_; | 903 auto& animations_impl = element_animations_impl->animations_; |
| 883 for (const auto& animation_impl : animations_impl) { | 904 for (const auto& animation_impl : animations_impl) { |
| 884 // If the animation has been aborted on the main thread, mark it for | 905 // If the animation has been aborted on the main thread, mark it for |
| 885 // deletion. | 906 // deletion. |
| 886 if (Animation* animation = GetAnimationById(animation_impl->id())) { | 907 if (Animation* animation = GetAnimationById(animation_impl->id())) { |
| 887 if (animation->run_state() == Animation::ABORTED) { | 908 if (animation->run_state() == Animation::ABORTED) { |
| 888 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, | 909 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, |
| 889 element_animations_impl->last_tick_time_); | 910 element_animations_impl->last_tick_time_); |
| 890 animation->SetRunState(Animation::WAITING_FOR_DELETION, | 911 animation->SetRunState(Animation::WAITING_FOR_DELETION, |
| 891 last_tick_time_); | 912 last_tick_time_); |
| 892 if (animation_impl->target_property() == TargetProperty::TRANSFORM) | 913 if (animation_impl->target_property() == TargetProperty::TRANSFORM) |
| 893 aborted_transform_animation = true; | 914 aborted_transform_animation = true; |
| 894 else if (animation_impl->target_property() == TargetProperty::OPACITY) | 915 else if (animation_impl->target_property() == TargetProperty::OPACITY) |
| 895 aborted_opacity_animation = true; | 916 aborted_opacity_animation = true; |
| 917 else if (animation_impl->target_property() == TargetProperty::FILTER) |
| 918 aborted_filter_animation = true; |
| 896 } | 919 } |
| 897 } | 920 } |
| 898 } | 921 } |
| 899 | 922 |
| 900 if (aborted_transform_animation) | 923 if (aborted_transform_animation) { |
| 901 element_animations_impl->UpdateClientAnimationState( | 924 element_animations_impl->UpdateClientAnimationState( |
| 902 TargetProperty::TRANSFORM); | 925 TargetProperty::TRANSFORM); |
| 903 if (aborted_opacity_animation) | 926 } |
| 927 if (aborted_opacity_animation) { |
| 904 element_animations_impl->UpdateClientAnimationState( | 928 element_animations_impl->UpdateClientAnimationState( |
| 905 TargetProperty::OPACITY); | 929 TargetProperty::OPACITY); |
| 930 } |
| 931 if (aborted_filter_animation) { |
| 932 element_animations_impl->UpdateClientAnimationState(TargetProperty::FILTER); |
| 933 } |
| 906 } | 934 } |
| 907 | 935 |
| 908 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { | 936 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { |
| 909 animations_.erase( | 937 animations_.erase( |
| 910 std::remove_if(animations_.begin(), animations_.end(), | 938 std::remove_if(animations_.begin(), animations_.end(), |
| 911 [](const std::unique_ptr<Animation>& animation) { | 939 [](const std::unique_ptr<Animation>& animation) { |
| 912 return animation->run_state() == | 940 return animation->run_state() == |
| 913 Animation::WAITING_FOR_DELETION; | 941 Animation::WAITING_FOR_DELETION; |
| 914 }), | 942 }), |
| 915 animations_.end()); | 943 animations_.end()); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1049 bool notify_elements_about_potential_animation, | 1077 bool notify_elements_about_potential_animation, |
| 1050 bool notify_elements_about_running_animation) { | 1078 bool notify_elements_about_running_animation) { |
| 1051 struct PropertyAnimationState* animation_state = nullptr; | 1079 struct PropertyAnimationState* animation_state = nullptr; |
| 1052 switch (property) { | 1080 switch (property) { |
| 1053 case TargetProperty::OPACITY: | 1081 case TargetProperty::OPACITY: |
| 1054 animation_state = &opacity_animation_state_; | 1082 animation_state = &opacity_animation_state_; |
| 1055 break; | 1083 break; |
| 1056 case TargetProperty::TRANSFORM: | 1084 case TargetProperty::TRANSFORM: |
| 1057 animation_state = &transform_animation_state_; | 1085 animation_state = &transform_animation_state_; |
| 1058 break; | 1086 break; |
| 1087 case TargetProperty::FILTER: |
| 1088 animation_state = &filter_animation_state_; |
| 1089 break; |
| 1059 default: | 1090 default: |
| 1060 NOTREACHED(); | 1091 NOTREACHED(); |
| 1061 break; | 1092 break; |
| 1062 } | 1093 } |
| 1063 | 1094 |
| 1064 bool notify_elements_about_potential_and_running_animation = | 1095 bool notify_elements_about_potential_and_running_animation = |
| 1065 notify_elements_about_potential_animation && | 1096 notify_elements_about_potential_animation && |
| 1066 notify_elements_about_running_animation; | 1097 notify_elements_about_running_animation; |
| 1067 bool active = list_type == ElementListType::ACTIVE; | 1098 bool active = list_type == ElementListType::ACTIVE; |
| 1068 if (notify_elements_about_potential_and_running_animation) { | 1099 if (notify_elements_about_potential_and_running_animation) { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1093 void ElementAnimations::UpdateClientAnimationState( | 1124 void ElementAnimations::UpdateClientAnimationState( |
| 1094 TargetProperty::Type property) { | 1125 TargetProperty::Type property) { |
| 1095 struct PropertyAnimationState* animation_state = nullptr; | 1126 struct PropertyAnimationState* animation_state = nullptr; |
| 1096 switch (property) { | 1127 switch (property) { |
| 1097 case TargetProperty::OPACITY: | 1128 case TargetProperty::OPACITY: |
| 1098 animation_state = &opacity_animation_state_; | 1129 animation_state = &opacity_animation_state_; |
| 1099 break; | 1130 break; |
| 1100 case TargetProperty::TRANSFORM: | 1131 case TargetProperty::TRANSFORM: |
| 1101 animation_state = &transform_animation_state_; | 1132 animation_state = &transform_animation_state_; |
| 1102 break; | 1133 break; |
| 1134 case TargetProperty::FILTER: |
| 1135 animation_state = &filter_animation_state_; |
| 1136 break; |
| 1103 default: | 1137 default: |
| 1104 NOTREACHED(); | 1138 NOTREACHED(); |
| 1105 break; | 1139 break; |
| 1106 } | 1140 } |
| 1107 bool was_currently_running_animation_for_active_elements = | 1141 bool was_currently_running_animation_for_active_elements = |
| 1108 animation_state->currently_running_for_active_elements; | 1142 animation_state->currently_running_for_active_elements; |
| 1109 bool was_currently_running_animation_for_pending_elements = | 1143 bool was_currently_running_animation_for_pending_elements = |
| 1110 animation_state->currently_running_for_pending_elements; | 1144 animation_state->currently_running_for_pending_elements; |
| 1111 bool was_potentially_animating_for_active_elements = | 1145 bool was_potentially_animating_for_active_elements = |
| 1112 animation_state->potentially_animating_for_active_elements; | 1146 animation_state->potentially_animating_for_active_elements; |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1211 animations_[i]->SetRunState(Animation::PAUSED, | 1245 animations_[i]->SetRunState(Animation::PAUSED, |
| 1212 time_offset + animations_[i]->start_time() + | 1246 time_offset + animations_[i]->start_time() + |
| 1213 animations_[i]->time_offset()); | 1247 animations_[i]->time_offset()); |
| 1214 } | 1248 } |
| 1215 } | 1249 } |
| 1216 } | 1250 } |
| 1217 | 1251 |
| 1218 void ElementAnimations::RemoveAnimation(int animation_id) { | 1252 void ElementAnimations::RemoveAnimation(int animation_id) { |
| 1219 bool removed_transform_animation = false; | 1253 bool removed_transform_animation = false; |
| 1220 bool removed_opacity_animation = false; | 1254 bool removed_opacity_animation = false; |
| 1255 bool removed_filter_animation = false; |
| 1221 // Since we want to use the animations that we're going to remove, we need to | 1256 // Since we want to use the animations that we're going to remove, we need to |
| 1222 // use a stable_parition here instead of remove_if. Remove_if leaves the | 1257 // use a stable_parition here instead of remove_if. Remove_if leaves the |
| 1223 // removed items in an unspecified state. | 1258 // removed items in an unspecified state. |
| 1224 auto animations_to_remove = std::stable_partition( | 1259 auto animations_to_remove = std::stable_partition( |
| 1225 animations_.begin(), animations_.end(), | 1260 animations_.begin(), animations_.end(), |
| 1226 [animation_id](const std::unique_ptr<Animation>& animation) { | 1261 [animation_id](const std::unique_ptr<Animation>& animation) { |
| 1227 return animation->id() != animation_id; | 1262 return animation->id() != animation_id; |
| 1228 }); | 1263 }); |
| 1229 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 1264 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
| 1230 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { | 1265 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { |
| 1231 scroll_offset_animation_was_interrupted_ = true; | 1266 scroll_offset_animation_was_interrupted_ = true; |
| 1232 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && | 1267 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && |
| 1233 !(*it)->is_finished()) { | 1268 !(*it)->is_finished()) { |
| 1234 removed_transform_animation = true; | 1269 removed_transform_animation = true; |
| 1235 } else if ((*it)->target_property() == TargetProperty::OPACITY && | 1270 } else if ((*it)->target_property() == TargetProperty::OPACITY && |
| 1236 !(*it)->is_finished()) { | 1271 !(*it)->is_finished()) { |
| 1237 removed_opacity_animation = true; | 1272 removed_opacity_animation = true; |
| 1273 } else if ((*it)->target_property() == TargetProperty::FILTER && |
| 1274 !(*it)->is_finished()) { |
| 1275 removed_filter_animation = true; |
| 1238 } | 1276 } |
| 1239 } | 1277 } |
| 1240 | 1278 |
| 1241 animations_.erase(animations_to_remove, animations_.end()); | 1279 animations_.erase(animations_to_remove, animations_.end()); |
| 1242 UpdateActivation(NORMAL_ACTIVATION); | 1280 UpdateActivation(NORMAL_ACTIVATION); |
| 1243 if (removed_transform_animation) | 1281 if (removed_transform_animation) |
| 1244 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 1282 UpdateClientAnimationState(TargetProperty::TRANSFORM); |
| 1245 if (removed_opacity_animation) | 1283 if (removed_opacity_animation) |
| 1246 UpdateClientAnimationState(TargetProperty::OPACITY); | 1284 UpdateClientAnimationState(TargetProperty::OPACITY); |
| 1285 if (removed_filter_animation) |
| 1286 UpdateClientAnimationState(TargetProperty::FILTER); |
| 1247 } | 1287 } |
| 1248 | 1288 |
| 1249 void ElementAnimations::AbortAnimation(int animation_id) { | 1289 void ElementAnimations::AbortAnimation(int animation_id) { |
| 1250 bool aborted_transform_animation = false; | |
| 1251 bool aborted_opacity_animation = false; | |
| 1252 if (Animation* animation = GetAnimationById(animation_id)) { | 1290 if (Animation* animation = GetAnimationById(animation_id)) { |
| 1253 if (!animation->is_finished()) { | 1291 if (!animation->is_finished()) { |
| 1254 animation->SetRunState(Animation::ABORTED, last_tick_time_); | 1292 animation->SetRunState(Animation::ABORTED, last_tick_time_); |
| 1255 if (animation->target_property() == TargetProperty::TRANSFORM) | 1293 switch (animation->target_property()) { |
| 1256 aborted_transform_animation = true; | 1294 case TargetProperty::TRANSFORM: |
| 1257 else if (animation->target_property() == TargetProperty::OPACITY) | 1295 case TargetProperty::OPACITY: |
| 1258 aborted_opacity_animation = true; | 1296 case TargetProperty::FILTER: |
| 1297 UpdateClientAnimationState(animation->target_property()); |
| 1298 break; |
| 1299 default: |
| 1300 break; |
| 1301 } |
| 1259 } | 1302 } |
| 1260 } | 1303 } |
| 1261 if (aborted_transform_animation) | |
| 1262 UpdateClientAnimationState(TargetProperty::TRANSFORM); | |
| 1263 if (aborted_opacity_animation) | |
| 1264 UpdateClientAnimationState(TargetProperty::OPACITY); | |
| 1265 } | 1304 } |
| 1266 | 1305 |
| 1267 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, | 1306 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, |
| 1268 bool needs_completion) { | 1307 bool needs_completion) { |
| 1269 if (needs_completion) | 1308 if (needs_completion) |
| 1270 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); | 1309 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); |
| 1271 | 1310 |
| 1272 bool aborted_transform_animation = false; | 1311 bool aborted_animation = false; |
| 1273 bool aborted_opacity_animation = false; | |
| 1274 for (size_t i = 0; i < animations_.size(); ++i) { | 1312 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1275 if (animations_[i]->target_property() == target_property && | 1313 if (animations_[i]->target_property() == target_property && |
| 1276 !animations_[i]->is_finished()) { | 1314 !animations_[i]->is_finished()) { |
| 1277 // Currently only impl-only scroll offset animations can be completed on | 1315 // Currently only impl-only scroll offset animations can be completed on |
| 1278 // the main thread. | 1316 // the main thread. |
| 1279 if (needs_completion && animations_[i]->is_impl_only()) { | 1317 if (needs_completion && animations_[i]->is_impl_only()) { |
| 1280 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, | 1318 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, |
| 1281 last_tick_time_); | 1319 last_tick_time_); |
| 1282 } else { | 1320 } else { |
| 1283 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 1321 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); |
| 1284 } | 1322 } |
| 1285 if (target_property == TargetProperty::TRANSFORM) | 1323 aborted_animation = true; |
| 1286 aborted_transform_animation = true; | |
| 1287 else if (target_property == TargetProperty::OPACITY) | |
| 1288 aborted_opacity_animation = true; | |
| 1289 } | 1324 } |
| 1290 } | 1325 } |
| 1291 if (aborted_transform_animation) | 1326 if (aborted_animation) { |
| 1292 UpdateClientAnimationState(TargetProperty::TRANSFORM); | 1327 switch (target_property) { |
| 1293 if (aborted_opacity_animation) | 1328 case TargetProperty::TRANSFORM: |
| 1294 UpdateClientAnimationState(TargetProperty::OPACITY); | 1329 case TargetProperty::OPACITY: |
| 1330 case TargetProperty::FILTER: |
| 1331 UpdateClientAnimationState(target_property); |
| 1332 break; |
| 1333 default: |
| 1334 break; |
| 1335 } |
| 1336 } |
| 1295 } | 1337 } |
| 1296 | 1338 |
| 1297 Animation* ElementAnimations::GetAnimation( | 1339 Animation* ElementAnimations::GetAnimation( |
| 1298 TargetProperty::Type target_property) const { | 1340 TargetProperty::Type target_property) const { |
| 1299 for (size_t i = 0; i < animations_.size(); ++i) { | 1341 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1300 size_t index = animations_.size() - i - 1; | 1342 size_t index = animations_.size() - i - 1; |
| 1301 if (animations_[index]->target_property() == target_property) | 1343 if (animations_[index]->target_property() == target_property) |
| 1302 return animations_[index].get(); | 1344 return animations_[index].get(); |
| 1303 } | 1345 } |
| 1304 return nullptr; | 1346 return nullptr; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1369 ->mutator_host_client() | 1411 ->mutator_host_client() |
| 1370 ->ElementOpacityIsAnimatingChanged(element_id(), list_type, | 1412 ->ElementOpacityIsAnimatingChanged(element_id(), list_type, |
| 1371 change_type, is_animating); | 1413 change_type, is_animating); |
| 1372 break; | 1414 break; |
| 1373 case TargetProperty::TRANSFORM: | 1415 case TargetProperty::TRANSFORM: |
| 1374 animation_host() | 1416 animation_host() |
| 1375 ->mutator_host_client() | 1417 ->mutator_host_client() |
| 1376 ->ElementTransformIsAnimatingChanged(element_id(), list_type, | 1418 ->ElementTransformIsAnimatingChanged(element_id(), list_type, |
| 1377 change_type, is_animating); | 1419 change_type, is_animating); |
| 1378 break; | 1420 break; |
| 1421 case TargetProperty::FILTER: |
| 1422 animation_host() |
| 1423 ->mutator_host_client() |
| 1424 ->ElementFilterIsAnimatingChanged(element_id(), list_type, |
| 1425 change_type, is_animating); |
| 1426 break; |
| 1379 default: | 1427 default: |
| 1380 NOTREACHED(); | 1428 NOTREACHED(); |
| 1381 break; | 1429 break; |
| 1382 } | 1430 } |
| 1383 } | 1431 } |
| 1384 } | 1432 } |
| 1385 | 1433 |
| 1386 void ElementAnimations::NotifyPlayersAnimationStarted( | 1434 void ElementAnimations::NotifyPlayersAnimationStarted( |
| 1387 base::TimeTicks monotonic_time, | 1435 base::TimeTicks monotonic_time, |
| 1388 TargetProperty::Type target_property, | 1436 TargetProperty::Type target_property, |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1436 if (animation_host()) { | 1484 if (animation_host()) { |
| 1437 DCHECK(animation_host()->mutator_host_client()); | 1485 DCHECK(animation_host()->mutator_host_client()); |
| 1438 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 1486 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
| 1439 element_id()); | 1487 element_id()); |
| 1440 } | 1488 } |
| 1441 | 1489 |
| 1442 return gfx::ScrollOffset(); | 1490 return gfx::ScrollOffset(); |
| 1443 } | 1491 } |
| 1444 | 1492 |
| 1445 } // namespace cc | 1493 } // namespace cc |
| OLD | NEW |