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 17 matching lines...) Expand all Loading... |
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), | 37 potentially_animating_transform_for_active_elements_(false), |
38 potentially_animating_transform_for_pending_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) {} |
39 | 43 |
40 ElementAnimations::~ElementAnimations() {} | 44 ElementAnimations::~ElementAnimations() {} |
41 | 45 |
42 void ElementAnimations::SetAnimationHost(AnimationHost* host) { | 46 void ElementAnimations::SetAnimationHost(AnimationHost* host) { |
43 animation_host_ = host; | 47 animation_host_ = host; |
44 } | 48 } |
45 | 49 |
46 void ElementAnimations::SetElementId(ElementId element_id) { | 50 void ElementAnimations::SetElementId(ElementId element_id) { |
47 element_id_ = element_id; | 51 element_id_ = element_id; |
48 } | 52 } |
(...skipping 11 matching lines...) Expand all Loading... |
60 } | 64 } |
61 if (animation_host_->mutator_host_client()->IsElementInList( | 65 if (animation_host_->mutator_host_client()->IsElementInList( |
62 element_id_, ElementListType::PENDING)) { | 66 element_id_, ElementListType::PENDING)) { |
63 set_has_element_in_pending_list(true); | 67 set_has_element_in_pending_list(true); |
64 } | 68 } |
65 } | 69 } |
66 | 70 |
67 void ElementAnimations::ClearAffectedElementTypes() { | 71 void ElementAnimations::ClearAffectedElementTypes() { |
68 DCHECK(animation_host_); | 72 DCHECK(animation_host_); |
69 | 73 |
70 if (has_element_in_active_list()) | 74 if (has_element_in_active_list()) { |
71 OnTransformIsPotentiallyAnimatingChanged(ElementListType::ACTIVE, false); | 75 OnTransformIsPotentiallyAnimatingChanged(ElementListType::ACTIVE, false); |
| 76 OnOpacityIsAnimatingChanged(ElementListType::ACTIVE, |
| 77 AnimationChangeType::BOTH, false); |
| 78 } |
72 set_has_element_in_active_list(false); | 79 set_has_element_in_active_list(false); |
73 | 80 |
74 if (has_element_in_pending_list()) | 81 if (has_element_in_pending_list()) { |
75 OnTransformIsPotentiallyAnimatingChanged(ElementListType::PENDING, false); | 82 OnTransformIsPotentiallyAnimatingChanged(ElementListType::PENDING, false); |
| 83 OnOpacityIsAnimatingChanged(ElementListType::PENDING, |
| 84 AnimationChangeType::BOTH, false); |
| 85 } |
76 set_has_element_in_pending_list(false); | 86 set_has_element_in_pending_list(false); |
77 | 87 |
78 animation_host_->DidDeactivateElementAnimations(this); | 88 animation_host_->DidDeactivateElementAnimations(this); |
79 UpdateActivation(FORCE_ACTIVATION); | 89 UpdateActivation(FORCE_ACTIVATION); |
80 } | 90 } |
81 | 91 |
82 void ElementAnimations::ElementRegistered(ElementId element_id, | 92 void ElementAnimations::ElementRegistered(ElementId element_id, |
83 ElementListType list_type) { | 93 ElementListType list_type) { |
84 DCHECK_EQ(element_id_, element_id); | 94 DCHECK_EQ(element_id_, element_id); |
85 | 95 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); | 141 RemoveAnimationsCompletedOnMainThread(element_animations_impl.get()); |
132 | 142 |
133 PushPropertiesToImplThread(element_animations_impl.get()); | 143 PushPropertiesToImplThread(element_animations_impl.get()); |
134 element_animations_impl->UpdateActivation(NORMAL_ACTIVATION); | 144 element_animations_impl->UpdateActivation(NORMAL_ACTIVATION); |
135 UpdateActivation(NORMAL_ACTIVATION); | 145 UpdateActivation(NORMAL_ACTIVATION); |
136 } | 146 } |
137 | 147 |
138 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { | 148 void ElementAnimations::AddAnimation(std::unique_ptr<Animation> animation) { |
139 bool added_transform_animation = | 149 bool added_transform_animation = |
140 animation->target_property() == TargetProperty::TRANSFORM; | 150 animation->target_property() == TargetProperty::TRANSFORM; |
| 151 bool added_opacity_animation = |
| 152 animation->target_property() == TargetProperty::OPACITY; |
141 animations_.push_back(std::move(animation)); | 153 animations_.push_back(std::move(animation)); |
142 needs_to_start_animations_ = true; | 154 needs_to_start_animations_ = true; |
143 UpdateActivation(NORMAL_ACTIVATION); | 155 UpdateActivation(NORMAL_ACTIVATION); |
144 if (added_transform_animation) | 156 if (added_transform_animation) |
145 UpdatePotentiallyAnimatingTransform(); | 157 UpdatePotentiallyAnimatingTransform(); |
| 158 if (added_opacity_animation) |
| 159 UpdateAnimatingOpacity(); |
146 } | 160 } |
147 | 161 |
148 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { | 162 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { |
149 DCHECK(!monotonic_time.is_null()); | 163 DCHECK(!monotonic_time.is_null()); |
150 if (!has_element_in_active_list() && !has_element_in_pending_list()) | 164 if (!has_element_in_active_list() && !has_element_in_pending_list()) |
151 return; | 165 return; |
152 | 166 |
153 if (needs_to_start_animations_) | 167 if (needs_to_start_animations_) |
154 StartAnimations(monotonic_time); | 168 StartAnimations(monotonic_time); |
155 TickAnimations(monotonic_time); | 169 TickAnimations(monotonic_time); |
156 last_tick_time_ = monotonic_time; | 170 last_tick_time_ = monotonic_time; |
| 171 UpdateAnimatingOpacity(); |
157 } | 172 } |
158 | 173 |
159 void ElementAnimations::AccumulatePropertyUpdates( | 174 void ElementAnimations::AccumulatePropertyUpdates( |
160 base::TimeTicks monotonic_time, | 175 base::TimeTicks monotonic_time, |
161 AnimationEvents* events) { | 176 AnimationEvents* events) { |
162 if (!events) | 177 if (!events) |
163 return; | 178 return; |
164 | 179 |
165 for (size_t i = 0; i < animations_.size(); ++i) { | 180 for (size_t i = 0; i < animations_.size(); ++i) { |
166 Animation* animation = animations_[i].get(); | 181 Animation* animation = animations_[i].get(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 PromoteStartedAnimations(last_tick_time_, events); | 259 PromoteStartedAnimations(last_tick_time_, events); |
245 } | 260 } |
246 | 261 |
247 AccumulatePropertyUpdates(last_tick_time_, events); | 262 AccumulatePropertyUpdates(last_tick_time_, events); |
248 | 263 |
249 UpdateActivation(NORMAL_ACTIVATION); | 264 UpdateActivation(NORMAL_ACTIVATION); |
250 } | 265 } |
251 | 266 |
252 void ElementAnimations::ActivateAnimations() { | 267 void ElementAnimations::ActivateAnimations() { |
253 bool changed_transform_animation = false; | 268 bool changed_transform_animation = false; |
| 269 bool changed_opacity_animation = false; |
254 for (size_t i = 0; i < animations_.size(); ++i) { | 270 for (size_t i = 0; i < animations_.size(); ++i) { |
255 if (animations_[i]->affects_active_elements() != | 271 if (animations_[i]->affects_active_elements() != |
256 animations_[i]->affects_pending_elements() && | 272 animations_[i]->affects_pending_elements()) { |
257 animations_[i]->target_property() == TargetProperty::TRANSFORM) | 273 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) |
258 changed_transform_animation = true; | 274 changed_transform_animation = true; |
| 275 else if (animations_[i]->target_property() == TargetProperty::OPACITY) |
| 276 changed_opacity_animation = true; |
| 277 } |
259 animations_[i]->set_affects_active_elements( | 278 animations_[i]->set_affects_active_elements( |
260 animations_[i]->affects_pending_elements()); | 279 animations_[i]->affects_pending_elements()); |
261 } | 280 } |
262 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { | 281 auto affects_no_elements = [](const std::unique_ptr<Animation>& animation) { |
263 return !animation->affects_active_elements() && | 282 return !animation->affects_active_elements() && |
264 !animation->affects_pending_elements(); | 283 !animation->affects_pending_elements(); |
265 }; | 284 }; |
266 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), | 285 animations_.erase(std::remove_if(animations_.begin(), animations_.end(), |
267 affects_no_elements), | 286 affects_no_elements), |
268 animations_.end()); | 287 animations_.end()); |
269 scroll_offset_animation_was_interrupted_ = false; | 288 scroll_offset_animation_was_interrupted_ = false; |
270 UpdateActivation(NORMAL_ACTIVATION); | 289 UpdateActivation(NORMAL_ACTIVATION); |
271 if (changed_transform_animation) | 290 if (changed_transform_animation) |
272 UpdatePotentiallyAnimatingTransform(); | 291 UpdatePotentiallyAnimatingTransform(); |
| 292 if (changed_opacity_animation) |
| 293 UpdateAnimatingOpacity(); |
273 } | 294 } |
274 | 295 |
275 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { | 296 void ElementAnimations::NotifyAnimationStarted(const AnimationEvent& event) { |
276 if (event.is_impl_only) { | 297 if (event.is_impl_only) { |
277 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, | 298 NotifyPlayersAnimationStarted(event.monotonic_time, event.target_property, |
278 event.group_id); | 299 event.group_id); |
279 return; | 300 return; |
280 } | 301 } |
281 | 302 |
282 for (size_t i = 0; i < animations_.size(); ++i) { | 303 for (size_t i = 0; i < animations_.size(); ++i) { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 if (!players_list_->empty()) { | 340 if (!players_list_->empty()) { |
320 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); | 341 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); |
321 NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property, | 342 NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property, |
322 event.animation_start_time, | 343 event.animation_start_time, |
323 std::move(animation_curve)); | 344 std::move(animation_curve)); |
324 } | 345 } |
325 } | 346 } |
326 | 347 |
327 void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { | 348 void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { |
328 bool aborted_transform_animation = false; | 349 bool aborted_transform_animation = false; |
| 350 bool aborted_opacity_animation = false; |
329 for (size_t i = 0; i < animations_.size(); ++i) { | 351 for (size_t i = 0; i < animations_.size(); ++i) { |
330 if (animations_[i]->group() == event.group_id && | 352 if (animations_[i]->group() == event.group_id && |
331 animations_[i]->target_property() == event.target_property) { | 353 animations_[i]->target_property() == event.target_property) { |
332 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); | 354 animations_[i]->SetRunState(Animation::ABORTED, event.monotonic_time); |
333 animations_[i]->set_received_finished_event(true); | 355 animations_[i]->set_received_finished_event(true); |
334 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, | 356 NotifyPlayersAnimationAborted(event.monotonic_time, event.target_property, |
335 event.group_id); | 357 event.group_id); |
336 if (event.target_property == TargetProperty::TRANSFORM) | 358 if (event.target_property == TargetProperty::TRANSFORM) |
337 aborted_transform_animation = true; | 359 aborted_transform_animation = true; |
| 360 else if (event.target_property == TargetProperty::OPACITY) |
| 361 aborted_opacity_animation = true; |
338 break; | 362 break; |
339 } | 363 } |
340 } | 364 } |
341 if (aborted_transform_animation) | 365 if (aborted_transform_animation) |
342 UpdatePotentiallyAnimatingTransform(); | 366 UpdatePotentiallyAnimatingTransform(); |
| 367 if (aborted_opacity_animation) |
| 368 UpdateAnimatingOpacity(); |
343 } | 369 } |
344 | 370 |
345 void ElementAnimations::NotifyAnimationPropertyUpdate( | 371 void ElementAnimations::NotifyAnimationPropertyUpdate( |
346 const AnimationEvent& event) { | 372 const AnimationEvent& event) { |
347 bool notify_active_elements = true; | 373 bool notify_active_elements = true; |
348 bool notify_pending_elements = true; | 374 bool notify_pending_elements = true; |
349 switch (event.target_property) { | 375 switch (event.target_property) { |
350 case TargetProperty::OPACITY: | 376 case TargetProperty::OPACITY: |
351 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, | 377 NotifyClientOpacityAnimated(event.opacity, notify_active_elements, |
352 notify_pending_elements); | 378 notify_pending_elements); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 if (animation->is_impl_only()) { | 616 if (animation->is_impl_only()) { |
591 return (animation->run_state() == Animation::WAITING_FOR_DELETION); | 617 return (animation->run_state() == Animation::WAITING_FOR_DELETION); |
592 } else { | 618 } else { |
593 return !main_thread_element_animations->GetAnimationById(animation->id()); | 619 return !main_thread_element_animations->GetAnimationById(animation->id()); |
594 } | 620 } |
595 } | 621 } |
596 | 622 |
597 void ElementAnimations::RemoveAnimationsCompletedOnMainThread( | 623 void ElementAnimations::RemoveAnimationsCompletedOnMainThread( |
598 ElementAnimations* element_animations_impl) const { | 624 ElementAnimations* element_animations_impl) const { |
599 bool removed_transform_animation = false; | 625 bool removed_transform_animation = false; |
| 626 bool removed_opacity_animation = false; |
600 // Animations removed on the main thread should no longer affect pending | 627 // Animations removed on the main thread should no longer affect pending |
601 // elements, and should stop affecting active elements after the next call | 628 // elements, and should stop affecting active elements after the next call |
602 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed | 629 // to ActivateAnimations. If already WAITING_FOR_DELETION, they can be removed |
603 // immediately. | 630 // immediately. |
604 auto& animations = element_animations_impl->animations_; | 631 auto& animations = element_animations_impl->animations_; |
605 for (const auto& animation : animations) { | 632 for (const auto& animation : animations) { |
606 if (IsCompleted(animation.get(), this)) { | 633 if (IsCompleted(animation.get(), this)) { |
607 animation->set_affects_pending_elements(false); | 634 animation->set_affects_pending_elements(false); |
608 if (animation->target_property() == TargetProperty::TRANSFORM) | 635 if (animation->target_property() == TargetProperty::TRANSFORM) |
609 removed_transform_animation = true; | 636 removed_transform_animation = true; |
| 637 else if (animation->target_property() == TargetProperty::OPACITY) |
| 638 removed_opacity_animation = true; |
610 } | 639 } |
611 } | 640 } |
612 auto affects_active_only_and_is_waiting_for_deletion = | 641 auto affects_active_only_and_is_waiting_for_deletion = |
613 [](const std::unique_ptr<Animation>& animation) { | 642 [](const std::unique_ptr<Animation>& animation) { |
614 return animation->run_state() == Animation::WAITING_FOR_DELETION && | 643 return animation->run_state() == Animation::WAITING_FOR_DELETION && |
615 !animation->affects_pending_elements(); | 644 !animation->affects_pending_elements(); |
616 }; | 645 }; |
617 animations.erase( | 646 animations.erase( |
618 std::remove_if(animations.begin(), animations.end(), | 647 std::remove_if(animations.begin(), animations.end(), |
619 affects_active_only_and_is_waiting_for_deletion), | 648 affects_active_only_and_is_waiting_for_deletion), |
620 animations.end()); | 649 animations.end()); |
621 | 650 |
622 if (removed_transform_animation) | 651 if (removed_transform_animation) |
623 element_animations_impl->UpdatePotentiallyAnimatingTransform(); | 652 element_animations_impl->UpdatePotentiallyAnimatingTransform(); |
| 653 if (removed_opacity_animation) |
| 654 element_animations_impl->UpdateAnimatingOpacity(); |
624 } | 655 } |
625 | 656 |
626 void ElementAnimations::PushPropertiesToImplThread( | 657 void ElementAnimations::PushPropertiesToImplThread( |
627 ElementAnimations* element_animations_impl) { | 658 ElementAnimations* element_animations_impl) { |
628 for (size_t i = 0; i < animations_.size(); ++i) { | 659 for (size_t i = 0; i < animations_.size(); ++i) { |
629 Animation* current_impl = | 660 Animation* current_impl = |
630 element_animations_impl->GetAnimationById(animations_[i]->id()); | 661 element_animations_impl->GetAnimationById(animations_[i]->id()); |
631 if (current_impl) | 662 if (current_impl) |
632 animations_[i]->PushPropertiesTo(current_impl); | 663 animations_[i]->PushPropertiesTo(current_impl); |
633 } | 664 } |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 NotifyAnimationStarted(started_event); | 787 NotifyAnimationStarted(started_event); |
757 else | 788 else |
758 events->events_.push_back(started_event); | 789 events->events_.push_back(started_event); |
759 } | 790 } |
760 } | 791 } |
761 } | 792 } |
762 } | 793 } |
763 | 794 |
764 void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) { | 795 void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) { |
765 bool finished_transform_animation = false; | 796 bool finished_transform_animation = false; |
| 797 bool finished_opacity_animation = false; |
766 for (size_t i = 0; i < animations_.size(); ++i) { | 798 for (size_t i = 0; i < animations_.size(); ++i) { |
767 if (!animations_[i]->is_finished() && | 799 if (!animations_[i]->is_finished() && |
768 animations_[i]->IsFinishedAt(monotonic_time)) { | 800 animations_[i]->IsFinishedAt(monotonic_time)) { |
769 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 801 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
770 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) { | 802 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) |
771 finished_transform_animation = true; | 803 finished_transform_animation = true; |
772 } | 804 else if (animations_[i]->target_property() == TargetProperty::OPACITY) |
| 805 finished_opacity_animation = true; |
773 } | 806 } |
774 } | 807 } |
775 if (finished_transform_animation) | 808 if (finished_transform_animation) |
776 UpdatePotentiallyAnimatingTransform(); | 809 UpdatePotentiallyAnimatingTransform(); |
| 810 if (finished_opacity_animation) |
| 811 UpdateAnimatingOpacity(); |
777 } | 812 } |
778 | 813 |
779 void ElementAnimations::MarkAnimationsForDeletion( | 814 void ElementAnimations::MarkAnimationsForDeletion( |
780 base::TimeTicks monotonic_time, | 815 base::TimeTicks monotonic_time, |
781 AnimationEvents* events) { | 816 AnimationEvents* events) { |
782 bool marked_animations_for_deletions = false; | 817 bool marked_animations_for_deletions = false; |
783 std::vector<size_t> animations_with_same_group_id; | 818 std::vector<size_t> animations_with_same_group_id; |
784 | 819 |
785 animations_with_same_group_id.reserve(animations_.size()); | 820 animations_with_same_group_id.reserve(animations_.size()); |
786 // Non-aborted animations are marked for deletion after a corresponding | 821 // Non-aborted animations are marked for deletion after a corresponding |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 marked_animations_for_deletions = true; | 933 marked_animations_for_deletions = true; |
899 } | 934 } |
900 } | 935 } |
901 if (marked_animations_for_deletions) | 936 if (marked_animations_for_deletions) |
902 NotifyClientAnimationWaitingForDeletion(); | 937 NotifyClientAnimationWaitingForDeletion(); |
903 } | 938 } |
904 | 939 |
905 void ElementAnimations::MarkAbortedAnimationsForDeletion( | 940 void ElementAnimations::MarkAbortedAnimationsForDeletion( |
906 ElementAnimations* element_animations_impl) const { | 941 ElementAnimations* element_animations_impl) const { |
907 bool aborted_transform_animation = false; | 942 bool aborted_transform_animation = false; |
| 943 bool aborted_opacity_animation = false; |
908 auto& animations_impl = element_animations_impl->animations_; | 944 auto& animations_impl = element_animations_impl->animations_; |
909 for (const auto& animation_impl : animations_impl) { | 945 for (const auto& animation_impl : animations_impl) { |
910 // If the animation has been aborted on the main thread, mark it for | 946 // If the animation has been aborted on the main thread, mark it for |
911 // deletion. | 947 // deletion. |
912 if (Animation* animation = GetAnimationById(animation_impl->id())) { | 948 if (Animation* animation = GetAnimationById(animation_impl->id())) { |
913 if (animation->run_state() == Animation::ABORTED) { | 949 if (animation->run_state() == Animation::ABORTED) { |
914 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, | 950 animation_impl->SetRunState(Animation::WAITING_FOR_DELETION, |
915 element_animations_impl->last_tick_time_); | 951 element_animations_impl->last_tick_time_); |
916 animation->SetRunState(Animation::WAITING_FOR_DELETION, | 952 animation->SetRunState(Animation::WAITING_FOR_DELETION, |
917 last_tick_time_); | 953 last_tick_time_); |
918 if (animation_impl->target_property() == TargetProperty::TRANSFORM) { | 954 if (animation_impl->target_property() == TargetProperty::TRANSFORM) |
919 aborted_transform_animation = true; | 955 aborted_transform_animation = true; |
920 } | 956 else if (animation_impl->target_property() == TargetProperty::OPACITY) |
| 957 aborted_opacity_animation = true; |
921 } | 958 } |
922 } | 959 } |
923 } | 960 } |
924 | 961 |
925 if (aborted_transform_animation) | 962 if (aborted_transform_animation) |
926 element_animations_impl->UpdatePotentiallyAnimatingTransform(); | 963 element_animations_impl->UpdatePotentiallyAnimatingTransform(); |
| 964 if (aborted_opacity_animation) |
| 965 element_animations_impl->UpdateAnimatingOpacity(); |
927 } | 966 } |
928 | 967 |
929 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { | 968 void ElementAnimations::PurgeAnimationsMarkedForDeletion() { |
930 animations_.erase( | 969 animations_.erase( |
931 std::remove_if(animations_.begin(), animations_.end(), | 970 std::remove_if(animations_.begin(), animations_.end(), |
932 [](const std::unique_ptr<Animation>& animation) { | 971 [](const std::unique_ptr<Animation>& animation) { |
933 return animation->run_state() == | 972 return animation->run_state() == |
934 Animation::WAITING_FOR_DELETION; | 973 Animation::WAITING_FOR_DELETION; |
935 }), | 974 }), |
936 animations_.end()); | 975 animations_.end()); |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 if (notify_active_elements && has_element_in_active_list()) | 1109 if (notify_active_elements && has_element_in_active_list()) |
1071 OnTransformIsPotentiallyAnimatingChanged( | 1110 OnTransformIsPotentiallyAnimatingChanged( |
1072 ElementListType::ACTIVE, | 1111 ElementListType::ACTIVE, |
1073 potentially_animating_transform_for_active_elements_); | 1112 potentially_animating_transform_for_active_elements_); |
1074 if (notify_pending_elements && has_element_in_pending_list()) | 1113 if (notify_pending_elements && has_element_in_pending_list()) |
1075 OnTransformIsPotentiallyAnimatingChanged( | 1114 OnTransformIsPotentiallyAnimatingChanged( |
1076 ElementListType::PENDING, | 1115 ElementListType::PENDING, |
1077 potentially_animating_transform_for_pending_elements_); | 1116 potentially_animating_transform_for_pending_elements_); |
1078 } | 1117 } |
1079 | 1118 |
| 1119 void ElementAnimations::NotifyClientOpacityAnimationChanged( |
| 1120 bool notify_active_elements_about_potential_animation, |
| 1121 bool notify_pending_elements_about_potential_animation, |
| 1122 bool notify_active_elements_about_running_animation, |
| 1123 bool notify_pending_elements_about_running_animation) { |
| 1124 bool notify_active_elements_about_potential_and_running_animation = |
| 1125 notify_active_elements_about_potential_animation && |
| 1126 notify_active_elements_about_running_animation; |
| 1127 bool notify_pending_elements_about_potential_and_running_animation = |
| 1128 notify_pending_elements_about_potential_animation && |
| 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 } |
| 1164 } |
| 1165 |
1080 void ElementAnimations::UpdatePotentiallyAnimatingTransform() { | 1166 void ElementAnimations::UpdatePotentiallyAnimatingTransform() { |
1081 bool was_potentially_animating_transform_for_active_elements = | 1167 bool was_potentially_animating_transform_for_active_elements = |
1082 potentially_animating_transform_for_active_elements_; | 1168 potentially_animating_transform_for_active_elements_; |
1083 bool was_potentially_animating_transform_for_pending_elements = | 1169 bool was_potentially_animating_transform_for_pending_elements = |
1084 potentially_animating_transform_for_pending_elements_; | 1170 potentially_animating_transform_for_pending_elements_; |
1085 | 1171 |
1086 potentially_animating_transform_for_active_elements_ = false; | 1172 potentially_animating_transform_for_active_elements_ = false; |
1087 potentially_animating_transform_for_pending_elements_ = false; | 1173 potentially_animating_transform_for_pending_elements_ = false; |
1088 | 1174 |
1089 for (const auto& animation : animations_) { | 1175 for (const auto& animation : animations_) { |
(...skipping 13 matching lines...) Expand all Loading... |
1103 was_potentially_animating_transform_for_pending_elements != | 1189 was_potentially_animating_transform_for_pending_elements != |
1104 potentially_animating_transform_for_pending_elements_; | 1190 potentially_animating_transform_for_pending_elements_; |
1105 | 1191 |
1106 if (!changed_for_active_elements && !changed_for_pending_elements) | 1192 if (!changed_for_active_elements && !changed_for_pending_elements) |
1107 return; | 1193 return; |
1108 | 1194 |
1109 NotifyClientTransformIsPotentiallyAnimatingChanged( | 1195 NotifyClientTransformIsPotentiallyAnimatingChanged( |
1110 changed_for_active_elements, changed_for_pending_elements); | 1196 changed_for_active_elements, changed_for_pending_elements); |
1111 } | 1197 } |
1112 | 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_); |
| 1228 currently_running_opacity_animation_for_pending_elements_ = |
| 1229 potentially_animating_opacity_for_pending_elements_ && |
| 1230 animation->InEffect(last_tick_time_); |
| 1231 } |
| 1232 } |
| 1233 |
| 1234 bool potentially_animating_changed_for_active_elements = |
| 1235 was_potentially_animating_opacity_for_active_elements != |
| 1236 potentially_animating_opacity_for_active_elements_; |
| 1237 bool potentially_animating_changed_for_pending_elements = |
| 1238 was_potentially_animating_opacity_for_pending_elements != |
| 1239 potentially_animating_opacity_for_pending_elements_; |
| 1240 bool currently_running_animation_changed_for_active_elements = |
| 1241 was_currently_running_opacity_animation_for_active_elements != |
| 1242 currently_running_opacity_animation_for_active_elements_; |
| 1243 bool currently_running_animation_changed_for_pending_elements = |
| 1244 was_currently_running_opacity_animation_for_pending_elements != |
| 1245 currently_running_opacity_animation_for_pending_elements_; |
| 1246 if (!potentially_animating_changed_for_active_elements && |
| 1247 !potentially_animating_changed_for_pending_elements && |
| 1248 !currently_running_animation_changed_for_active_elements && |
| 1249 !currently_running_animation_changed_for_pending_elements) |
| 1250 return; |
| 1251 NotifyClientOpacityAnimationChanged( |
| 1252 potentially_animating_changed_for_active_elements, |
| 1253 potentially_animating_changed_for_pending_elements, |
| 1254 currently_running_animation_changed_for_active_elements, |
| 1255 currently_running_animation_changed_for_pending_elements); |
| 1256 } |
| 1257 |
1113 bool ElementAnimations::HasActiveAnimation() const { | 1258 bool ElementAnimations::HasActiveAnimation() const { |
1114 for (size_t i = 0; i < animations_.size(); ++i) { | 1259 for (size_t i = 0; i < animations_.size(); ++i) { |
1115 if (!animations_[i]->is_finished()) | 1260 if (!animations_[i]->is_finished()) |
1116 return true; | 1261 return true; |
1117 } | 1262 } |
1118 return false; | 1263 return false; |
1119 } | 1264 } |
1120 | 1265 |
1121 bool ElementAnimations::IsPotentiallyAnimatingProperty( | 1266 bool ElementAnimations::IsPotentiallyAnimatingProperty( |
1122 TargetProperty::Type target_property, | 1267 TargetProperty::Type target_property, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1157 if (animations_[i]->id() == animation_id) { | 1302 if (animations_[i]->id() == animation_id) { |
1158 animations_[i]->SetRunState(Animation::PAUSED, | 1303 animations_[i]->SetRunState(Animation::PAUSED, |
1159 time_offset + animations_[i]->start_time() + | 1304 time_offset + animations_[i]->start_time() + |
1160 animations_[i]->time_offset()); | 1305 animations_[i]->time_offset()); |
1161 } | 1306 } |
1162 } | 1307 } |
1163 } | 1308 } |
1164 | 1309 |
1165 void ElementAnimations::RemoveAnimation(int animation_id) { | 1310 void ElementAnimations::RemoveAnimation(int animation_id) { |
1166 bool removed_transform_animation = false; | 1311 bool removed_transform_animation = false; |
| 1312 bool removed_opacity_animation = false; |
1167 // Since we want to use the animations that we're going to remove, we need to | 1313 // Since we want to use the animations that we're going to remove, we need to |
1168 // use a stable_parition here instead of remove_if. Remove_if leaves the | 1314 // use a stable_parition here instead of remove_if. Remove_if leaves the |
1169 // removed items in an unspecified state. | 1315 // removed items in an unspecified state. |
1170 auto animations_to_remove = std::stable_partition( | 1316 auto animations_to_remove = std::stable_partition( |
1171 animations_.begin(), animations_.end(), | 1317 animations_.begin(), animations_.end(), |
1172 [animation_id](const std::unique_ptr<Animation>& animation) { | 1318 [animation_id](const std::unique_ptr<Animation>& animation) { |
1173 return animation->id() != animation_id; | 1319 return animation->id() != animation_id; |
1174 }); | 1320 }); |
1175 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 1321 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
1176 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { | 1322 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { |
1177 scroll_offset_animation_was_interrupted_ = true; | 1323 scroll_offset_animation_was_interrupted_ = true; |
1178 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && | 1324 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && |
1179 !(*it)->is_finished()) { | 1325 !(*it)->is_finished()) { |
1180 removed_transform_animation = true; | 1326 removed_transform_animation = true; |
| 1327 } else if ((*it)->target_property() == TargetProperty::OPACITY && |
| 1328 !(*it)->is_finished()) { |
| 1329 removed_opacity_animation = true; |
1181 } | 1330 } |
1182 } | 1331 } |
1183 | 1332 |
1184 animations_.erase(animations_to_remove, animations_.end()); | 1333 animations_.erase(animations_to_remove, animations_.end()); |
1185 UpdateActivation(NORMAL_ACTIVATION); | 1334 UpdateActivation(NORMAL_ACTIVATION); |
1186 if (removed_transform_animation) | 1335 if (removed_transform_animation) |
1187 UpdatePotentiallyAnimatingTransform(); | 1336 UpdatePotentiallyAnimatingTransform(); |
| 1337 if (removed_opacity_animation) |
| 1338 UpdateAnimatingOpacity(); |
1188 } | 1339 } |
1189 | 1340 |
1190 void ElementAnimations::AbortAnimation(int animation_id) { | 1341 void ElementAnimations::AbortAnimation(int animation_id) { |
1191 bool aborted_transform_animation = false; | 1342 bool aborted_transform_animation = false; |
| 1343 bool aborted_opacity_animation = false; |
1192 if (Animation* animation = GetAnimationById(animation_id)) { | 1344 if (Animation* animation = GetAnimationById(animation_id)) { |
1193 if (!animation->is_finished()) { | 1345 if (!animation->is_finished()) { |
1194 animation->SetRunState(Animation::ABORTED, last_tick_time_); | 1346 animation->SetRunState(Animation::ABORTED, last_tick_time_); |
1195 if (animation->target_property() == TargetProperty::TRANSFORM) | 1347 if (animation->target_property() == TargetProperty::TRANSFORM) |
1196 aborted_transform_animation = true; | 1348 aborted_transform_animation = true; |
| 1349 else if (animation->target_property() == TargetProperty::OPACITY) |
| 1350 aborted_opacity_animation = true; |
1197 } | 1351 } |
1198 } | 1352 } |
1199 if (aborted_transform_animation) | 1353 if (aborted_transform_animation) |
1200 UpdatePotentiallyAnimatingTransform(); | 1354 UpdatePotentiallyAnimatingTransform(); |
| 1355 if (aborted_opacity_animation) |
| 1356 UpdateAnimatingOpacity(); |
1201 } | 1357 } |
1202 | 1358 |
1203 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, | 1359 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, |
1204 bool needs_completion) { | 1360 bool needs_completion) { |
1205 if (needs_completion) | 1361 if (needs_completion) |
1206 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); | 1362 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); |
1207 | 1363 |
1208 bool aborted_transform_animation = false; | 1364 bool aborted_transform_animation = false; |
| 1365 bool aborted_opacity_animation = false; |
1209 for (size_t i = 0; i < animations_.size(); ++i) { | 1366 for (size_t i = 0; i < animations_.size(); ++i) { |
1210 if (animations_[i]->target_property() == target_property && | 1367 if (animations_[i]->target_property() == target_property && |
1211 !animations_[i]->is_finished()) { | 1368 !animations_[i]->is_finished()) { |
1212 // Currently only impl-only scroll offset animations can be completed on | 1369 // Currently only impl-only scroll offset animations can be completed on |
1213 // the main thread. | 1370 // the main thread. |
1214 if (needs_completion && animations_[i]->is_impl_only()) { | 1371 if (needs_completion && animations_[i]->is_impl_only()) { |
1215 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, | 1372 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, |
1216 last_tick_time_); | 1373 last_tick_time_); |
1217 } else { | 1374 } else { |
1218 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 1375 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); |
1219 } | 1376 } |
1220 if (target_property == TargetProperty::TRANSFORM) | 1377 if (target_property == TargetProperty::TRANSFORM) |
1221 aborted_transform_animation = true; | 1378 aborted_transform_animation = true; |
| 1379 else if (target_property == TargetProperty::OPACITY) |
| 1380 aborted_opacity_animation = true; |
1222 } | 1381 } |
1223 } | 1382 } |
1224 if (aborted_transform_animation) | 1383 if (aborted_transform_animation) |
1225 UpdatePotentiallyAnimatingTransform(); | 1384 UpdatePotentiallyAnimatingTransform(); |
| 1385 if (aborted_opacity_animation) |
| 1386 UpdateAnimatingOpacity(); |
1226 } | 1387 } |
1227 | 1388 |
1228 Animation* ElementAnimations::GetAnimation( | 1389 Animation* ElementAnimations::GetAnimation( |
1229 TargetProperty::Type target_property) const { | 1390 TargetProperty::Type target_property) const { |
1230 for (size_t i = 0; i < animations_.size(); ++i) { | 1391 for (size_t i = 0; i < animations_.size(); ++i) { |
1231 size_t index = animations_.size() - i - 1; | 1392 size_t index = animations_.size() - i - 1; |
1232 if (animations_[index]->target_property() == target_property) | 1393 if (animations_[index]->target_property() == target_property) |
1233 return animations_[index].get(); | 1394 return animations_[index].get(); |
1234 } | 1395 } |
1235 return nullptr; | 1396 return nullptr; |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1291 bool is_animating) { | 1452 bool is_animating) { |
1292 DCHECK(element_id()); | 1453 DCHECK(element_id()); |
1293 DCHECK(animation_host()); | 1454 DCHECK(animation_host()); |
1294 DCHECK(animation_host()->mutator_host_client()); | 1455 DCHECK(animation_host()->mutator_host_client()); |
1295 animation_host() | 1456 animation_host() |
1296 ->mutator_host_client() | 1457 ->mutator_host_client() |
1297 ->ElementTransformIsPotentiallyAnimatingChanged(element_id(), list_type, | 1458 ->ElementTransformIsPotentiallyAnimatingChanged(element_id(), list_type, |
1298 is_animating); | 1459 is_animating); |
1299 } | 1460 } |
1300 | 1461 |
| 1462 void ElementAnimations::OnOpacityIsAnimatingChanged( |
| 1463 ElementListType list_type, |
| 1464 AnimationChangeType change_type, |
| 1465 bool is_animating) { |
| 1466 if (!element_id()) |
| 1467 return; |
| 1468 DCHECK(animation_host()); |
| 1469 if (animation_host()->mutator_host_client()) |
| 1470 animation_host()->mutator_host_client()->ElementOpacityIsAnimatingChanged( |
| 1471 element_id(), list_type, change_type, is_animating); |
| 1472 } |
| 1473 |
1301 void ElementAnimations::NotifyPlayersAnimationStarted( | 1474 void ElementAnimations::NotifyPlayersAnimationStarted( |
1302 base::TimeTicks monotonic_time, | 1475 base::TimeTicks monotonic_time, |
1303 TargetProperty::Type target_property, | 1476 TargetProperty::Type target_property, |
1304 int group) { | 1477 int group) { |
1305 for (PlayersListNode* node = players_list_->head(); | 1478 for (PlayersListNode* node = players_list_->head(); |
1306 node != players_list_->end(); node = node->next()) { | 1479 node != players_list_->end(); node = node->next()) { |
1307 AnimationPlayer* player = node->value(); | 1480 AnimationPlayer* player = node->value(); |
1308 player->NotifyAnimationStarted(monotonic_time, target_property, group); | 1481 player->NotifyAnimationStarted(monotonic_time, target_property, group); |
1309 } | 1482 } |
1310 } | 1483 } |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1351 if (animation_host()) { | 1524 if (animation_host()) { |
1352 DCHECK(animation_host()->mutator_host_client()); | 1525 DCHECK(animation_host()->mutator_host_client()); |
1353 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 1526 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
1354 element_id()); | 1527 element_id()); |
1355 } | 1528 } |
1356 | 1529 |
1357 return gfx::ScrollOffset(); | 1530 return gfx::ScrollOffset(); |
1358 } | 1531 } |
1359 | 1532 |
1360 } // namespace cc | 1533 } // namespace cc |
OLD | NEW |