| 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 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 ElementAnimations::ElementAnimations() | 28 ElementAnimations::ElementAnimations() |
| 29 : players_list_(new PlayersList()), | 29 : players_list_(new PlayersList()), |
| 30 animation_host_(), | 30 animation_host_(), |
| 31 element_id_(), | 31 element_id_(), |
| 32 is_active_(false), | 32 is_active_(false), |
| 33 has_element_in_active_list_(false), | 33 has_element_in_active_list_(false), |
| 34 has_element_in_pending_list_(false), | 34 has_element_in_pending_list_(false), |
| 35 needs_to_start_animations_(false), | 35 needs_to_start_animations_(false), |
| 36 scroll_offset_animation_was_interrupted_(false), | 36 scroll_offset_animation_was_interrupted_(false), |
| 37 currently_running_transform_animation_for_active_elements_(false), |
| 38 currently_running_transform_animation_for_pending_elements_(false), |
| 37 potentially_animating_transform_for_active_elements_(false), | 39 potentially_animating_transform_for_active_elements_(false), |
| 38 potentially_animating_transform_for_pending_elements_(false), | 40 potentially_animating_transform_for_pending_elements_(false), |
| 39 currently_running_opacity_animation_for_active_elements_(false), | 41 currently_running_opacity_animation_for_active_elements_(false), |
| 40 currently_running_opacity_animation_for_pending_elements_(false), | 42 currently_running_opacity_animation_for_pending_elements_(false), |
| 41 potentially_animating_opacity_for_active_elements_(false), | 43 potentially_animating_opacity_for_active_elements_(false), |
| 42 potentially_animating_opacity_for_pending_elements_(false) {} | 44 potentially_animating_opacity_for_pending_elements_(false) {} |
| 43 | 45 |
| 44 ElementAnimations::~ElementAnimations() {} | 46 ElementAnimations::~ElementAnimations() {} |
| 45 | 47 |
| 46 void ElementAnimations::SetAnimationHost(AnimationHost* host) { | 48 void ElementAnimations::SetAnimationHost(AnimationHost* host) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 65 if (animation_host_->mutator_host_client()->IsElementInList( | 67 if (animation_host_->mutator_host_client()->IsElementInList( |
| 66 element_id_, ElementListType::PENDING)) { | 68 element_id_, ElementListType::PENDING)) { |
| 67 set_has_element_in_pending_list(true); | 69 set_has_element_in_pending_list(true); |
| 68 } | 70 } |
| 69 } | 71 } |
| 70 | 72 |
| 71 void ElementAnimations::ClearAffectedElementTypes() { | 73 void ElementAnimations::ClearAffectedElementTypes() { |
| 72 DCHECK(animation_host_); | 74 DCHECK(animation_host_); |
| 73 | 75 |
| 74 if (has_element_in_active_list()) { | 76 if (has_element_in_active_list()) { |
| 75 OnTransformIsPotentiallyAnimatingChanged(ElementListType::ACTIVE, false); | 77 IsAnimatingChanged(ElementListType::ACTIVE, TargetProperty::TRANSFORM, |
| 76 OnOpacityIsAnimatingChanged(ElementListType::ACTIVE, | 78 AnimationChangeType::BOTH, false); |
| 77 AnimationChangeType::BOTH, false); | 79 IsAnimatingChanged(ElementListType::ACTIVE, TargetProperty::OPACITY, |
| 80 AnimationChangeType::BOTH, false); |
| 78 } | 81 } |
| 79 set_has_element_in_active_list(false); | 82 set_has_element_in_active_list(false); |
| 80 | 83 |
| 81 if (has_element_in_pending_list()) { | 84 if (has_element_in_pending_list()) { |
| 82 OnTransformIsPotentiallyAnimatingChanged(ElementListType::PENDING, false); | 85 IsAnimatingChanged(ElementListType::PENDING, TargetProperty::TRANSFORM, |
| 83 OnOpacityIsAnimatingChanged(ElementListType::PENDING, | 86 AnimationChangeType::BOTH, false); |
| 84 AnimationChangeType::BOTH, false); | 87 IsAnimatingChanged(ElementListType::PENDING, TargetProperty::OPACITY, |
| 88 AnimationChangeType::BOTH, false); |
| 85 } | 89 } |
| 86 set_has_element_in_pending_list(false); | 90 set_has_element_in_pending_list(false); |
| 87 | 91 |
| 88 animation_host_->DidDeactivateElementAnimations(this); | 92 animation_host_->DidDeactivateElementAnimations(this); |
| 89 UpdateActivation(FORCE_ACTIVATION); | 93 UpdateActivation(FORCE_ACTIVATION); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void ElementAnimations::ElementRegistered(ElementId element_id, | 96 void ElementAnimations::ElementRegistered(ElementId element_id, |
| 93 ElementListType list_type) { | 97 ElementListType list_type) { |
| 94 DCHECK_EQ(element_id_, element_id); | 98 DCHECK_EQ(element_id_, element_id); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 151 |
| 148 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { | 152 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { |
| 149 bool added_transform_animation = | 153 bool added_transform_animation = |
| 150 animation->target_property() == TargetProperty::TRANSFORM; | 154 animation->target_property() == TargetProperty::TRANSFORM; |
| 151 bool added_opacity_animation = | 155 bool added_opacity_animation = |
| 152 animation->target_property() == TargetProperty::OPACITY; | 156 animation->target_property() == TargetProperty::OPACITY; |
| 153 animations_.push_back(std::move(animation)); | 157 animations_.push_back(std::move(animation)); |
| 154 needs_to_start_animations_ = true; | 158 needs_to_start_animations_ = true; |
| 155 UpdateActivation(NORMAL_ACTIVATION); | 159 UpdateActivation(NORMAL_ACTIVATION); |
| 156 if (added_transform_animation) | 160 if (added_transform_animation) |
| 157 UpdatePotentiallyAnimatingTransform(); | 161 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 158 if (added_opacity_animation) | 162 if (added_opacity_animation) |
| 159 UpdateAnimatingOpacity(); | 163 UpdateAnimationState(TargetProperty::OPACITY); |
| 160 } | 164 } |
| 161 | 165 |
| 162 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { | 166 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { |
| 163 DCHECK(!monotonic_time.is_null()); | 167 DCHECK(!monotonic_time.is_null()); |
| 164 if (!has_element_in_active_list() && !has_element_in_pending_list()) | 168 if (!has_element_in_active_list() && !has_element_in_pending_list()) |
| 165 return; | 169 return; |
| 166 | 170 |
| 167 if (needs_to_start_animations_) | 171 if (needs_to_start_animations_) |
| 168 StartAnimations(monotonic_time); | 172 StartAnimations(monotonic_time); |
| 169 TickAnimations(monotonic_time); | 173 TickAnimations(monotonic_time); |
| 170 last_tick_time_ = monotonic_time; | 174 last_tick_time_ = monotonic_time; |
| 171 UpdateAnimatingOpacity(); | 175 UpdateAnimationState(TargetProperty::OPACITY); |
| 176 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 172 } | 177 } |
| 173 | 178 |
| 174 void ElementAnimations::AccumulatePropertyUpdates( | 179 void ElementAnimations::AccumulatePropertyUpdates( |
| 175 base::TimeTicks monotonic_time, | 180 base::TimeTicks monotonic_time, |
| 176 AnimationEvents* events) { | 181 AnimationEvents* events) { |
| 177 if (!events) | 182 if (!events) |
| 178 return; | 183 return; |
| 179 | 184 |
| 180 for (size_t i = 0; i < animations_.size(); ++i) { | 185 for (size_t i = 0; i < animations_.size(); ++i) { |
| 181 Animation* animation = animations_[i].get(); | 186 Animation* animation = animations_[i].get(); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 281 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { | 286 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { |
| 282 return !animation->affects_active_elements() && | 287 return !animation->affects_active_elements() && |
| 283 !animation->affects_pending_elements(); | 288 !animation->affects_pending_elements(); |
| 284 }; | 289 }; |
| 285 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 290 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), |
| 286 affects_no_elements), | 291 affects_no_elements), |
| 287 animations_.end()); | 292 animations_.end()); |
| 288 scroll_offset_animation_was_interrupted_ = false; | 293 scroll_offset_animation_was_interrupted_ = false; |
| 289 UpdateActivation(NORMAL_ACTIVATION); | 294 UpdateActivation(NORMAL_ACTIVATION); |
| 290 if (changed_transform_animation) | 295 if (changed_transform_animation) |
| 291 UpdatePotentiallyAnimatingTransform(); | 296 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 292 if (changed_opacity_animation) | 297 if (changed_opacity_animation) |
| 293 UpdateAnimatingOpacity(); | 298 UpdateAnimationState(TargetProperty::OPACITY); |
| 294 } | 299 } |
| 295 | 300 |
| 296 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { | 301 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { |
| 297 if (event.is_impl_only) { | 302 if (event.is_impl_only) { |
| 298 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, | 303 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, |
| 299 event.group_id); | 304 event.group_id); |
| 300 return; | 305 return; |
| 301 } | 306 } |
| 302 | 307 |
| 303 for (size_t i = 0; i < animations_.size(); ++i) { | 308 for (size_t i = 0; i < animations_.size(); ++i) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, | 361 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, |
| 357 event.group_id); | 362 event.group_id); |
| 358 if (event.target_property == TargetProperty::TRANSFORM) | 363 if (event.target_property == TargetProperty::TRANSFORM) |
| 359 aborted_transform_animation = true; | 364 aborted_transform_animation = true; |
| 360 else if (event.target_property == TargetProperty::OPACITY) | 365 else if (event.target_property == TargetProperty::OPACITY) |
| 361 aborted_opacity_animation = true; | 366 aborted_opacity_animation = true; |
| 362 break; | 367 break; |
| 363 } | 368 } |
| 364 } | 369 } |
| 365 if (aborted_transform_animation) | 370 if (aborted_transform_animation) |
| 366 UpdatePotentiallyAnimatingTransform(); | 371 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 367 if (aborted_opacity_animation) | 372 if (aborted_opacity_animation) |
| 368 UpdateAnimatingOpacity(); | 373 UpdateAnimationState(TargetProperty::OPACITY); |
| 369 } | 374 } |
| 370 | 375 |
| 371 void ElementAnimations::NotifyAnimationPropertyUpdate( | 376 void ElementAnimations::NotifyAnimationPropertyUpdate( |
| 372 const AnimationEvent& event) { | 377 const AnimationEvent& event) { |
| 373 bool notify_active_elements = true; | 378 bool notify_active_elements = true; |
| 374 bool notify_pending_elements = true; | 379 bool notify_pending_elements = true; |
| 375 switch (event.target_property) { | 380 switch (event.target_property) { |
| 376 case TargetProperty::OPACITY: | 381 case TargetProperty::OPACITY: |
| 377 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, | 382 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, |
| 378 notify_pending_elements); | 383 notify_pending_elements); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 [](const std::unique_ptr<Animation>& animation) { | 647 [](const std::unique_ptr<Animation>& animation) { |
| 643 return animation->run_state() == Animation::WAITING_FOR_DELETION && | 648 return animation->run_state() == Animation::WAITING_FOR_DELETION && |
| 644 !animation->affects_pending_elements(); | 649 !animation->affects_pending_elements(); |
| 645 }; | 650 }; |
| 646 animations.erase( | 651 animations.erase( |
| 647 std::remove_if(animations.begin(), animations.end(), | 652 std::remove_if(animations.begin(), animations.end(), |
| 648 affects_active_only_and_is_waiting_for_deletion), | 653 affects_active_only_and_is_waiting_for_deletion), |
| 649 animations.end()); | 654 animations.end()); |
| 650 | 655 |
| 651 if (removed_transform_animation) | 656 if (removed_transform_animation) |
| 652 element_animations_impl->UpdatePotentiallyAnimatingTransform(); | 657 element_animations_impl->UpdateAnimationState(TargetProperty::TRANSFORM); |
| 653 if (removed_opacity_animation) | 658 if (removed_opacity_animation) |
| 654 element_animations_impl->UpdateAnimatingOpacity(); | 659 element_animations_impl->UpdateAnimationState(TargetProperty::OPACITY); |
| 655 } | 660 } |
| 656 | 661 |
| 657 void ElementAnimations::PushPropertiesToImplThread( | 662 void ElementAnimations::PushPropertiesToImplThread( |
| 658 ElementAnimations* element_animations_impl) { | 663 ElementAnimations* element_animations_impl) { |
| 659 for (size_t i = 0; i < animations_.size(); ++i) { | 664 for (size_t i = 0; i < animations_.size(); ++i) { |
| 660 Animation* current_impl = | 665 Animation* current_impl = |
| 661 element_animations_impl->GetAnimationById(animations_[i]->id()); | 666 element_animations_impl->GetAnimationById(animations_[i]->id()); |
| 662 if (current_impl) | 667 if (current_impl) |
| 663 animations_[i]->PushPropertiesTo(current_impl); | 668 animations_[i]->PushPropertiesTo(current_impl); |
| 664 } | 669 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 799 if (!animations_[i]->is_finished() && | 804 if (!animations_[i]->is_finished() && |
| 800 animations_[i]->IsFinishedAt(monotonic_time)) { | 805 animations_[i]->IsFinishedAt(monotonic_time)) { |
| 801 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 806 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
| 802 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) | 807 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) |
| 803 finished_transform_animation = true; | 808 finished_transform_animation = true; |
| 804 else if (animations_[i]->target_property() == TargetProperty::OPACITY) | 809 else if (animations_[i]->target_property() == TargetProperty::OPACITY) |
| 805 finished_opacity_animation = true; | 810 finished_opacity_animation = true; |
| 806 } | 811 } |
| 807 } | 812 } |
| 808 if (finished_transform_animation) | 813 if (finished_transform_animation) |
| 809 UpdatePotentiallyAnimatingTransform(); | 814 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 810 if (finished_opacity_animation) | 815 if (finished_opacity_animation) |
| 811 UpdateAnimatingOpacity(); | 816 UpdateAnimationState(TargetProperty::OPACITY); |
| 812 } | 817 } |
| 813 | 818 |
| 814 void ElementAnimations::MarkAnimationsForDeletion( | 819 void ElementAnimations::MarkAnimationsForDeletion( |
| 815 base::TimeTicks monotonic_time, | 820 base::TimeTicks monotonic_time, |
| 816 AnimationEvents* events) { | 821 AnimationEvents* events) { |
| 817 bool marked_animations_for_deletions = false; | 822 bool marked_animations_for_deletions = false; |
| 818 std::vector<size_t> animations_with_same_group_id; | 823 std::vector<size_t> animations_with_same_group_id; |
| 819 | 824 |
| 820 animations_with_same_group_id.reserve(animations_.size()); | 825 animations_with_same_group_id.reserve(animations_.size()); |
| 821 // Non-aborted animations are marked for deletion after a corresponding | 826 // Non-aborted animations are marked for deletion after a corresponding |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 953 last_tick_time_); | 958 last_tick_time_); |
| 954 if (animation_impl->target_property() == TargetProperty::TRANSFORM) | 959 if (animation_impl->target_property() == TargetProperty::TRANSFORM) |
| 955 aborted_transform_animation = true; | 960 aborted_transform_animation = true; |
| 956 else if (animation_impl->target_property() == TargetProperty::OPACITY) | 961 else if (animation_impl->target_property() == TargetProperty::OPACITY) |
| 957 aborted_opacity_animation = true; | 962 aborted_opacity_animation = true; |
| 958 } | 963 } |
| 959 } | 964 } |
| 960 } | 965 } |
| 961 | 966 |
| 962 if (aborted_transform_animation) | 967 if (aborted_transform_animation) |
| 963 element_animations_impl->UpdatePotentiallyAnimatingTransform(); | 968 element_animations_impl->UpdateAnimationState(TargetProperty::TRANSFORM); |
| 964 if (aborted_opacity_animation) | 969 if (aborted_opacity_animation) |
| 965 element_animations_impl->UpdateAnimatingOpacity(); | 970 element_animations_impl->UpdateAnimationState(TargetProperty::OPACITY); |
| 966 } | 971 } |
| 967 | 972 |
| 968 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { | 973 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { |
| 969 animations_.erase( | 974 animations_.erase( |
| 970 std::remove_if(animations_.begin(), animations_.end(), | 975 std::remove_if(animations_.begin(), animations_.end(), |
| 971 [](const std::unique_ptr<Animation>& animation) { | 976 [](const std::unique_ptr<Animation>& animation) { |
| 972 return animation->run_state() == | 977 return animation->run_state() == |
| 973 Animation::WAITING_FOR_DELETION; | 978 Animation::WAITING_FOR_DELETION; |
| 974 }), | 979 }), |
| 975 animations_.end()); | 980 animations_.end()); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1096 if (notify_active_elements && has_element_in_active_list()) | 1101 if (notify_active_elements && has_element_in_active_list()) |
| 1097 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); | 1102 OnScrollOffsetAnimated(ElementListType::ACTIVE, scroll_offset); |
| 1098 if (notify_pending_elements && has_element_in_pending_list()) | 1103 if (notify_pending_elements && has_element_in_pending_list()) |
| 1099 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); | 1104 OnScrollOffsetAnimated(ElementListType::PENDING, scroll_offset); |
| 1100 } | 1105 } |
| 1101 | 1106 |
| 1102 void ElementAnimations::NotifyClientAnimationWaitingForDeletion() { | 1107 void ElementAnimations::NotifyClientAnimationWaitingForDeletion() { |
| 1103 OnAnimationWaitingForDeletion(); | 1108 OnAnimationWaitingForDeletion(); |
| 1104 } | 1109 } |
| 1105 | 1110 |
| 1106 void ElementAnimations::NotifyClientTransformIsPotentiallyAnimatingChanged( | 1111 void ElementAnimations::NotifyClientAnimationChanged( |
| 1107 bool notify_active_elements, | 1112 TargetProperty::Type property, |
| 1108 bool notify_pending_elements) { | 1113 ElementListType list_type, |
| 1109 if (notify_active_elements && has_element_in_active_list()) | 1114 bool notify_elements_about_potential_animation, |
| 1110 OnTransformIsPotentiallyAnimatingChanged( | 1115 bool notify_elements_about_running_animation) { |
| 1111 ElementListType::ACTIVE, | 1116 bool notify_elements_about_potential_and_running_animation = |
| 1112 potentially_animating_transform_for_active_elements_); | 1117 notify_elements_about_potential_animation && |
| 1113 if (notify_pending_elements && has_element_in_pending_list()) | 1118 notify_elements_about_running_animation; |
| 1114 OnTransformIsPotentiallyAnimatingChanged( | 1119 bool potentially_animating; |
| 1115 ElementListType::PENDING, | 1120 bool currently_animating; |
| 1116 potentially_animating_transform_for_pending_elements_); | 1121 bool active = list_type == ElementListType::ACTIVE; |
| 1117 } | 1122 switch (property) { |
| 1123 case TargetProperty::OPACITY: |
| 1124 potentially_animating = |
| 1125 active ? potentially_animating_opacity_for_active_elements_ |
| 1126 : potentially_animating_opacity_for_pending_elements_; |
| 1127 currently_animating = |
| 1128 active ? currently_running_opacity_animation_for_active_elements_ |
| 1129 : currently_running_opacity_animation_for_pending_elements_; |
| 1130 break; |
| 1131 case TargetProperty::TRANSFORM: |
| 1132 potentially_animating = |
| 1133 active ? potentially_animating_transform_for_active_elements_ |
| 1134 : potentially_animating_transform_for_pending_elements_; |
| 1135 currently_animating = |
| 1136 active ? currently_running_transform_animation_for_active_elements_ |
| 1137 : currently_running_transform_animation_for_pending_elements_; |
| 1138 break; |
| 1139 default: |
| 1140 break; |
| 1141 } |
| 1118 | 1142 |
| 1119 void ElementAnimations::NotifyClientOpacityAnimationChanged( | 1143 if (notify_elements_about_potential_and_running_animation) { |
| 1120 bool notify_active_elements_about_potential_animation, | 1144 DCHECK_EQ(potentially_animating, currently_animating); |
| 1121 bool notify_pending_elements_about_potential_animation, | 1145 IsAnimatingChanged(list_type, property, AnimationChangeType::BOTH, |
| 1122 bool notify_active_elements_about_running_animation, | 1146 potentially_animating); |
| 1123 bool notify_pending_elements_about_running_animation) { | 1147 } else if (notify_elements_about_potential_animation) { |
| 1124 bool notify_active_elements_about_potential_and_running_animation = | 1148 IsAnimatingChanged(list_type, property, AnimationChangeType::POTENTIAL, |
| 1125 notify_active_elements_about_potential_animation && | 1149 potentially_animating); |
| 1126 notify_active_elements_about_running_animation; | 1150 } else if (notify_elements_about_running_animation) { |
| 1127 bool notify_pending_elements_about_potential_and_running_animation = | 1151 IsAnimatingChanged(list_type, property, AnimationChangeType::RUNNING, |
| 1128 notify_pending_elements_about_potential_animation && | 1152 currently_animating); |
| 1129 notify_pending_elements_about_running_animation; | |
| 1130 if (has_element_in_active_list()) { | |
| 1131 if (notify_active_elements_about_potential_and_running_animation) { | |
| 1132 DCHECK_EQ(potentially_animating_opacity_for_active_elements_, | |
| 1133 currently_running_opacity_animation_for_active_elements_); | |
| 1134 OnOpacityIsAnimatingChanged( | |
| 1135 ElementListType::ACTIVE, AnimationChangeType::BOTH, | |
| 1136 potentially_animating_opacity_for_active_elements_); | |
| 1137 } else if (notify_active_elements_about_potential_animation) { | |
| 1138 OnOpacityIsAnimatingChanged( | |
| 1139 ElementListType::ACTIVE, AnimationChangeType::POTENTIAL, | |
| 1140 potentially_animating_opacity_for_active_elements_); | |
| 1141 } else if (notify_active_elements_about_running_animation) { | |
| 1142 OnOpacityIsAnimatingChanged( | |
| 1143 ElementListType::ACTIVE, AnimationChangeType::RUNNING, | |
| 1144 currently_running_opacity_animation_for_active_elements_); | |
| 1145 } | |
| 1146 } | |
| 1147 if (has_element_in_pending_list()) { | |
| 1148 if (notify_pending_elements_about_potential_and_running_animation) { | |
| 1149 DCHECK_EQ(potentially_animating_opacity_for_pending_elements_, | |
| 1150 currently_running_opacity_animation_for_pending_elements_); | |
| 1151 OnOpacityIsAnimatingChanged( | |
| 1152 ElementListType::PENDING, AnimationChangeType::BOTH, | |
| 1153 potentially_animating_opacity_for_pending_elements_); | |
| 1154 } else if (notify_pending_elements_about_potential_animation) { | |
| 1155 OnOpacityIsAnimatingChanged( | |
| 1156 ElementListType::PENDING, AnimationChangeType::POTENTIAL, | |
| 1157 potentially_animating_opacity_for_pending_elements_); | |
| 1158 } else if (notify_pending_elements_about_running_animation) { | |
| 1159 OnOpacityIsAnimatingChanged( | |
| 1160 ElementListType::PENDING, AnimationChangeType::RUNNING, | |
| 1161 currently_running_opacity_animation_for_pending_elements_); | |
| 1162 } | |
| 1163 } | 1153 } |
| 1164 } | 1154 } |
| 1165 | 1155 |
| 1166 void ElementAnimations::UpdatePotentiallyAnimatingTransform() { | 1156 void ElementAnimations::UpdateAnimationState(TargetProperty::Type property) { |
| 1167 bool was_potentially_animating_transform_for_active_elements = | 1157 bool* currently_running_property_for_active_elements = nullptr; |
| 1168 potentially_animating_transform_for_active_elements_; | 1158 bool* currently_running_property_for_pending_elements = nullptr; |
| 1169 bool was_potentially_animating_transform_for_pending_elements = | 1159 bool* potentially_animating_property_for_active_elements = nullptr; |
| 1170 potentially_animating_transform_for_pending_elements_; | 1160 bool* potentially_animating_property_for_pending_elements = nullptr; |
| 1161 switch (property) { |
| 1162 case TargetProperty::OPACITY: |
| 1163 currently_running_property_for_active_elements = |
| 1164 ¤tly_running_opacity_animation_for_active_elements_; |
| 1165 currently_running_property_for_pending_elements = |
| 1166 ¤tly_running_opacity_animation_for_pending_elements_; |
| 1167 potentially_animating_property_for_active_elements = |
| 1168 &potentially_animating_opacity_for_active_elements_; |
| 1169 potentially_animating_property_for_pending_elements = |
| 1170 &potentially_animating_opacity_for_pending_elements_; |
| 1171 break; |
| 1172 case TargetProperty::TRANSFORM: |
| 1173 currently_running_property_for_active_elements = |
| 1174 ¤tly_running_transform_animation_for_active_elements_; |
| 1175 currently_running_property_for_pending_elements = |
| 1176 ¤tly_running_transform_animation_for_pending_elements_; |
| 1177 potentially_animating_property_for_active_elements = |
| 1178 &potentially_animating_transform_for_active_elements_; |
| 1179 potentially_animating_property_for_pending_elements = |
| 1180 &potentially_animating_transform_for_pending_elements_; |
| 1181 break; |
| 1182 default: |
| 1183 break; |
| 1184 } |
| 1185 bool was_currently_running_animation_for_active_elements = |
| 1186 *currently_running_property_for_active_elements; |
| 1187 bool was_currently_running_animation_for_pending_elements = |
| 1188 *currently_running_property_for_pending_elements; |
| 1189 bool was_potentially_animating_for_active_elements = |
| 1190 *potentially_animating_property_for_active_elements; |
| 1191 bool was_potentially_animating_for_pending_elements = |
| 1192 *potentially_animating_property_for_pending_elements; |
| 1193 *currently_running_property_for_active_elements = false; |
| 1194 *currently_running_property_for_pending_elements = false; |
| 1195 *potentially_animating_property_for_active_elements = false; |
| 1196 *potentially_animating_property_for_pending_elements = false; |
| 1171 | 1197 |
| 1172 potentially_animating_transform_for_active_elements_ = false; | 1198 DCHECK(was_potentially_animating_for_active_elements || |
| 1173 potentially_animating_transform_for_pending_elements_ = false; | 1199 !was_currently_running_animation_for_active_elements); |
| 1200 DCHECK(was_potentially_animating_for_pending_elements || |
| 1201 !was_currently_running_animation_for_pending_elements); |
| 1174 | 1202 |
| 1175 for (const auto& animation : animations_) { | 1203 for (const auto& animation : animations_) { |
| 1176 if (!animation->is_finished() && | 1204 if (!animation->is_finished() && animation->target_property() == property) { |
| 1177 animation->target_property() == TargetProperty::TRANSFORM) { | 1205 *potentially_animating_property_for_active_elements |= |
| 1178 potentially_animating_transform_for_active_elements_ |= | |
| 1179 animation->affects_active_elements(); | 1206 animation->affects_active_elements(); |
| 1180 potentially_animating_transform_for_pending_elements_ |= | 1207 *potentially_animating_property_for_pending_elements |= |
| 1181 animation->affects_pending_elements(); | 1208 animation->affects_pending_elements(); |
| 1182 } | 1209 *currently_running_property_for_active_elements = |
| 1183 } | 1210 *potentially_animating_property_for_active_elements && |
| 1184 | |
| 1185 bool changed_for_active_elements = | |
| 1186 was_potentially_animating_transform_for_active_elements != | |
| 1187 potentially_animating_transform_for_active_elements_; | |
| 1188 bool changed_for_pending_elements = | |
| 1189 was_potentially_animating_transform_for_pending_elements != | |
| 1190 potentially_animating_transform_for_pending_elements_; | |
| 1191 | |
| 1192 if (!changed_for_active_elements && !changed_for_pending_elements) | |
| 1193 return; | |
| 1194 | |
| 1195 NotifyClientTransformIsPotentiallyAnimatingChanged( | |
| 1196 changed_for_active_elements, changed_for_pending_elements); | |
| 1197 } | |
| 1198 | |
| 1199 void ElementAnimations::UpdateAnimatingOpacity() { | |
| 1200 bool was_currently_running_opacity_animation_for_active_elements = | |
| 1201 currently_running_opacity_animation_for_active_elements_; | |
| 1202 bool was_currently_running_opacity_animation_for_pending_elements = | |
| 1203 currently_running_opacity_animation_for_pending_elements_; | |
| 1204 bool was_potentially_animating_opacity_for_active_elements = | |
| 1205 potentially_animating_opacity_for_active_elements_; | |
| 1206 bool was_potentially_animating_opacity_for_pending_elements = | |
| 1207 potentially_animating_opacity_for_pending_elements_; | |
| 1208 | |
| 1209 DCHECK(was_potentially_animating_opacity_for_active_elements || | |
| 1210 !was_currently_running_opacity_animation_for_active_elements); | |
| 1211 DCHECK(was_potentially_animating_opacity_for_pending_elements || | |
| 1212 !was_currently_running_opacity_animation_for_pending_elements); | |
| 1213 currently_running_opacity_animation_for_active_elements_ = false; | |
| 1214 currently_running_opacity_animation_for_pending_elements_ = false; | |
| 1215 potentially_animating_opacity_for_active_elements_ = false; | |
| 1216 potentially_animating_opacity_for_pending_elements_ = false; | |
| 1217 | |
| 1218 for (const auto& animation : animations_) { | |
| 1219 if (!animation->is_finished() && | |
| 1220 animation->target_property() == TargetProperty::OPACITY) { | |
| 1221 potentially_animating_opacity_for_active_elements_ |= | |
| 1222 animation->affects_active_elements(); | |
| 1223 potentially_animating_opacity_for_pending_elements_ |= | |
| 1224 animation->affects_pending_elements(); | |
| 1225 currently_running_opacity_animation_for_active_elements_ = | |
| 1226 potentially_animating_opacity_for_active_elements_ && | |
| 1227 animation->InEffect(last_tick_time_); | 1211 animation->InEffect(last_tick_time_); |
| 1228 currently_running_opacity_animation_for_pending_elements_ = | 1212 *currently_running_property_for_pending_elements = |
| 1229 potentially_animating_opacity_for_pending_elements_ && | 1213 *potentially_animating_property_for_pending_elements && |
| 1230 animation->InEffect(last_tick_time_); | 1214 animation->InEffect(last_tick_time_); |
| 1231 } | 1215 } |
| 1232 } | 1216 } |
| 1233 | 1217 |
| 1234 bool potentially_animating_changed_for_active_elements = | 1218 bool potentially_animating_changed_for_active_elements = |
| 1235 was_potentially_animating_opacity_for_active_elements != | 1219 was_potentially_animating_for_active_elements != |
| 1236 potentially_animating_opacity_for_active_elements_; | 1220 *potentially_animating_property_for_active_elements; |
| 1237 bool potentially_animating_changed_for_pending_elements = | 1221 bool potentially_animating_changed_for_pending_elements = |
| 1238 was_potentially_animating_opacity_for_pending_elements != | 1222 was_potentially_animating_for_pending_elements != |
| 1239 potentially_animating_opacity_for_pending_elements_; | 1223 *potentially_animating_property_for_pending_elements; |
| 1240 bool currently_running_animation_changed_for_active_elements = | 1224 bool currently_running_animation_changed_for_active_elements = |
| 1241 was_currently_running_opacity_animation_for_active_elements != | 1225 was_currently_running_animation_for_active_elements != |
| 1242 currently_running_opacity_animation_for_active_elements_; | 1226 *currently_running_property_for_active_elements; |
| 1243 bool currently_running_animation_changed_for_pending_elements = | 1227 bool currently_running_animation_changed_for_pending_elements = |
| 1244 was_currently_running_opacity_animation_for_pending_elements != | 1228 was_currently_running_animation_for_pending_elements != |
| 1245 currently_running_opacity_animation_for_pending_elements_; | 1229 *currently_running_property_for_pending_elements; |
| 1246 if (!potentially_animating_changed_for_active_elements && | 1230 if (!potentially_animating_changed_for_active_elements && |
| 1247 !potentially_animating_changed_for_pending_elements && | 1231 !potentially_animating_changed_for_pending_elements && |
| 1248 !currently_running_animation_changed_for_active_elements && | 1232 !currently_running_animation_changed_for_active_elements && |
| 1249 !currently_running_animation_changed_for_pending_elements) | 1233 !currently_running_animation_changed_for_pending_elements) |
| 1250 return; | 1234 return; |
| 1251 NotifyClientOpacityAnimationChanged( | 1235 if (has_element_in_active_list()) |
| 1252 potentially_animating_changed_for_active_elements, | 1236 NotifyClientAnimationChanged( |
| 1253 potentially_animating_changed_for_pending_elements, | 1237 property, ElementListType::ACTIVE, |
| 1254 currently_running_animation_changed_for_active_elements, | 1238 potentially_animating_changed_for_active_elements, |
| 1255 currently_running_animation_changed_for_pending_elements); | 1239 currently_running_animation_changed_for_active_elements); |
| 1240 if (has_element_in_pending_list()) |
| 1241 NotifyClientAnimationChanged( |
| 1242 property, ElementListType::PENDING, |
| 1243 potentially_animating_changed_for_pending_elements, |
| 1244 currently_running_animation_changed_for_pending_elements); |
| 1256 } | 1245 } |
| 1257 | 1246 |
| 1258 bool ElementAnimations::HasActiveAnimation() const { | 1247 bool ElementAnimations::HasActiveAnimation() const { |
| 1259 for (size_t i = 0; i < animations_.size(); ++i) { | 1248 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1260 if (!animations_[i]->is_finished()) | 1249 if (!animations_[i]->is_finished()) |
| 1261 return true; | 1250 return true; |
| 1262 } | 1251 } |
| 1263 return false; | 1252 return false; |
| 1264 } | 1253 } |
| 1265 | 1254 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1326 removed_transform_animation = true; | 1315 removed_transform_animation = true; |
| 1327 } else if ((*it)->target_property() == TargetProperty::OPACITY && | 1316 } else if ((*it)->target_property() == TargetProperty::OPACITY && |
| 1328 !(*it)->is_finished()) { | 1317 !(*it)->is_finished()) { |
| 1329 removed_opacity_animation = true; | 1318 removed_opacity_animation = true; |
| 1330 } | 1319 } |
| 1331 } | 1320 } |
| 1332 | 1321 |
| 1333 animations_.erase(animations_to_remove, animations_.end()); | 1322 animations_.erase(animations_to_remove, animations_.end()); |
| 1334 UpdateActivation(NORMAL_ACTIVATION); | 1323 UpdateActivation(NORMAL_ACTIVATION); |
| 1335 if (removed_transform_animation) | 1324 if (removed_transform_animation) |
| 1336 UpdatePotentiallyAnimatingTransform(); | 1325 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 1337 if (removed_opacity_animation) | 1326 if (removed_opacity_animation) |
| 1338 UpdateAnimatingOpacity(); | 1327 UpdateAnimationState(TargetProperty::OPACITY); |
| 1339 } | 1328 } |
| 1340 | 1329 |
| 1341 void ElementAnimations::AbortAnimation(int animation_id) { | 1330 void ElementAnimations::AbortAnimation(int animation_id) { |
| 1342 bool aborted_transform_animation = false; | 1331 bool aborted_transform_animation = false; |
| 1343 bool aborted_opacity_animation = false; | 1332 bool aborted_opacity_animation = false; |
| 1344 if (Animation* animation = GetAnimationById(animation_id)) { | 1333 if (Animation* animation = GetAnimationById(animation_id)) { |
| 1345 if (!animation->is_finished()) { | 1334 if (!animation->is_finished()) { |
| 1346 animation->SetRunState(Animation::ABORTED, last_tick_time_); | 1335 animation->SetRunState(Animation::ABORTED, last_tick_time_); |
| 1347 if (animation->target_property() == TargetProperty::TRANSFORM) | 1336 if (animation->target_property() == TargetProperty::TRANSFORM) |
| 1348 aborted_transform_animation = true; | 1337 aborted_transform_animation = true; |
| 1349 else if (animation->target_property() == TargetProperty::OPACITY) | 1338 else if (animation->target_property() == TargetProperty::OPACITY) |
| 1350 aborted_opacity_animation = true; | 1339 aborted_opacity_animation = true; |
| 1351 } | 1340 } |
| 1352 } | 1341 } |
| 1353 if (aborted_transform_animation) | 1342 if (aborted_transform_animation) |
| 1354 UpdatePotentiallyAnimatingTransform(); | 1343 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 1355 if (aborted_opacity_animation) | 1344 if (aborted_opacity_animation) |
| 1356 UpdateAnimatingOpacity(); | 1345 UpdateAnimationState(TargetProperty::OPACITY); |
| 1357 } | 1346 } |
| 1358 | 1347 |
| 1359 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, | 1348 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, |
| 1360 bool needs_completion) { | 1349 bool needs_completion) { |
| 1361 if (needs_completion) | 1350 if (needs_completion) |
| 1362 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); | 1351 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); |
| 1363 | 1352 |
| 1364 bool aborted_transform_animation = false; | 1353 bool aborted_transform_animation = false; |
| 1365 bool aborted_opacity_animation = false; | 1354 bool aborted_opacity_animation = false; |
| 1366 for (size_t i = 0; i < animations_.size(); ++i) { | 1355 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1367 if (animations_[i]->target_property() == target_property && | 1356 if (animations_[i]->target_property() == target_property && |
| 1368 !animations_[i]->is_finished()) { | 1357 !animations_[i]->is_finished()) { |
| 1369 // Currently only impl-only scroll offset animations can be completed on | 1358 // Currently only impl-only scroll offset animations can be completed on |
| 1370 // the main thread. | 1359 // the main thread. |
| 1371 if (needs_completion && animations_[i]->is_impl_only()) { | 1360 if (needs_completion && animations_[i]->is_impl_only()) { |
| 1372 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, | 1361 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, |
| 1373 last_tick_time_); | 1362 last_tick_time_); |
| 1374 } else { | 1363 } else { |
| 1375 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 1364 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); |
| 1376 } | 1365 } |
| 1377 if (target_property == TargetProperty::TRANSFORM) | 1366 if (target_property == TargetProperty::TRANSFORM) |
| 1378 aborted_transform_animation = true; | 1367 aborted_transform_animation = true; |
| 1379 else if (target_property == TargetProperty::OPACITY) | 1368 else if (target_property == TargetProperty::OPACITY) |
| 1380 aborted_opacity_animation = true; | 1369 aborted_opacity_animation = true; |
| 1381 } | 1370 } |
| 1382 } | 1371 } |
| 1383 if (aborted_transform_animation) | 1372 if (aborted_transform_animation) |
| 1384 UpdatePotentiallyAnimatingTransform(); | 1373 UpdateAnimationState(TargetProperty::TRANSFORM); |
| 1385 if (aborted_opacity_animation) | 1374 if (aborted_opacity_animation) |
| 1386 UpdateAnimatingOpacity(); | 1375 UpdateAnimationState(TargetProperty::OPACITY); |
| 1387 } | 1376 } |
| 1388 | 1377 |
| 1389 Animation* ElementAnimations::GetAnimation( | 1378 Animation* ElementAnimations::GetAnimation( |
| 1390 TargetProperty::Type target_property) const { | 1379 TargetProperty::Type target_property) const { |
| 1391 for (size_t i = 0; i < animations_.size(); ++i) { | 1380 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1392 size_t index = animations_.size() - i - 1; | 1381 size_t index = animations_.size() - i - 1; |
| 1393 if (animations_[index]->target_property() == target_property) | 1382 if (animations_[index]->target_property() == target_property) |
| 1394 return animations_[index].get(); | 1383 return animations_[index].get(); |
| 1395 } | 1384 } |
| 1396 return nullptr; | 1385 return nullptr; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1440 element_id(), list_type, scroll_offset); | 1429 element_id(), list_type, scroll_offset); |
| 1441 } | 1430 } |
| 1442 | 1431 |
| 1443 void ElementAnimations::OnAnimationWaitingForDeletion() { | 1432 void ElementAnimations::OnAnimationWaitingForDeletion() { |
| 1444 // TODO(loyso): Invalidate AnimationHost::SetNeedsPushProperties here. | 1433 // TODO(loyso): Invalidate AnimationHost::SetNeedsPushProperties here. |
| 1445 // But we always do PushProperties in AnimationHost for now. crbug.com/604280 | 1434 // But we always do PushProperties in AnimationHost for now. crbug.com/604280 |
| 1446 DCHECK(animation_host()); | 1435 DCHECK(animation_host()); |
| 1447 animation_host()->OnAnimationWaitingForDeletion(); | 1436 animation_host()->OnAnimationWaitingForDeletion(); |
| 1448 } | 1437 } |
| 1449 | 1438 |
| 1450 void ElementAnimations::OnTransformIsPotentiallyAnimatingChanged( | 1439 void ElementAnimations::IsAnimatingChanged(ElementListType list_type, |
| 1451 ElementListType list_type, | 1440 TargetProperty::Type property, |
| 1452 bool is_animating) { | 1441 AnimationChangeType change_type, |
| 1453 DCHECK(element_id()); | 1442 bool is_animating) { |
| 1454 DCHECK(animation_host()); | |
| 1455 DCHECK(animation_host()->mutator_host_client()); | |
| 1456 animation_host() | |
| 1457 ->mutator_host_client() | |
| 1458 ->ElementTransformIsPotentiallyAnimatingChanged(element_id(), list_type, | |
| 1459 is_animating); | |
| 1460 } | |
| 1461 | |
| 1462 void ElementAnimations::OnOpacityIsAnimatingChanged( | |
| 1463 ElementListType list_type, | |
| 1464 AnimationChangeType change_type, | |
| 1465 bool is_animating) { | |
| 1466 if (!element_id()) | 1443 if (!element_id()) |
| 1467 return; | 1444 return; |
| 1468 DCHECK(animation_host()); | 1445 DCHECK(animation_host()); |
| 1469 if (animation_host()->mutator_host_client()) { | 1446 if (animation_host()->mutator_host_client()) { |
| 1470 animation_host()->mutator_host_client()->ElementOpacityIsAnimatingChanged( | 1447 switch (property) { |
| 1471 element_id(), list_type, change_type, is_animating); | 1448 case TargetProperty::OPACITY: |
| 1449 animation_host() |
| 1450 ->mutator_host_client() |
| 1451 ->ElementOpacityIsAnimatingChanged(element_id(), list_type, |
| 1452 change_type, is_animating); |
| 1453 break; |
| 1454 case TargetProperty::TRANSFORM: |
| 1455 animation_host() |
| 1456 ->mutator_host_client() |
| 1457 ->ElementTransformIsAnimatingChanged(element_id(), list_type, |
| 1458 change_type, is_animating); |
| 1459 break; |
| 1460 default: |
| 1461 break; |
| 1462 } |
| 1472 } | 1463 } |
| 1473 } | 1464 } |
| 1474 | 1465 |
| 1475 void ElementAnimations::NotifyPlayersAnimationStarted( | 1466 void ElementAnimations::NotifyPlayersAnimationStarted( |
| 1476 base::TimeTicks monotonic_time, | 1467 base::TimeTicks monotonic_time, |
| 1477 TargetProperty::Type target_property, | 1468 TargetProperty::Type target_property, |
| 1478 int group) { | 1469 int group) { |
| 1479 for (PlayersListNode* node = players_list_->head(); | 1470 for (PlayersListNode* node = players_list_->head(); |
| 1480 node != players_list_->end(); node = node->next()) { | 1471 node != players_list_->end(); node = node->next()) { |
| 1481 AnimationPlayer* player = node->value(); | 1472 AnimationPlayer* player = node->value(); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1525 if (animation_host()) { | 1516 if (animation_host()) { |
| 1526 DCHECK(animation_host()->mutator_host_client()); | 1517 DCHECK(animation_host()->mutator_host_client()); |
| 1527 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 1518 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
| 1528 element_id()); | 1519 element_id()); |
| 1529 } | 1520 } |
| 1530 | 1521 |
| 1531 return gfx::ScrollOffset(); | 1522 return gfx::ScrollOffset(); |
| 1532 } | 1523 } |
| 1533 | 1524 |
| 1534 } // namespace cc | 1525 } // namespace cc |
| OLD | NEW |