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