| 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 } | 60 } |
| 61 if (animation_host_->mutator_host_client()->IsElementInList( | 61 if (animation_host_->mutator_host_client()->IsElementInList( |
| 62 element_id_, ElementListType::PENDING)) { | 62 element_id_, ElementListType::PENDING)) { |
| 63 set_has_element_in_pending_list(true); | 63 set_has_element_in_pending_list(true); |
| 64 } | 64 } |
| 65 } | 65 } |
| 66 | 66 |
| 67 void ElementAnimations::ClearAffectedElementTypes() { | 67 void ElementAnimations::ClearAffectedElementTypes() { |
| 68 DCHECK(animation_host_); | 68 DCHECK(animation_host_); |
| 69 | 69 |
| 70 OnOpacityIsCurrentlyAnimatingChanged(false); |
| 70 if (has_element_in_active_list()) | 71 if (has_element_in_active_list()) |
| 71 OnTransformIsPotentiallyAnimatingChanged(ElementListType::ACTIVE, false); | 72 OnTransformIsPotentiallyAnimatingChanged(ElementListType::ACTIVE, false); |
| 72 set_has_element_in_active_list(false); | 73 set_has_element_in_active_list(false); |
| 73 | 74 |
| 74 if (has_element_in_pending_list()) | 75 if (has_element_in_pending_list()) |
| 75 OnTransformIsPotentiallyAnimatingChanged(ElementListType::PENDING, false); | 76 OnTransformIsPotentiallyAnimatingChanged(ElementListType::PENDING, false); |
| 76 set_has_element_in_pending_list(false); | 77 set_has_element_in_pending_list(false); |
| 77 | 78 |
| 78 animation_host_->DidDeactivateElementAnimations(this); | 79 animation_host_->DidDeactivateElementAnimations(this); |
| 79 UpdateActivation(FORCE_ACTIVATION); | 80 UpdateActivation(FORCE_ACTIVATION); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 | 148 |
| 148 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { | 149 void ElementAnimations::Animate(base::TimeTicks monotonic_time) { |
| 149 DCHECK(!monotonic_time.is_null()); | 150 DCHECK(!monotonic_time.is_null()); |
| 150 if (!has_element_in_active_list() && !has_element_in_pending_list()) | 151 if (!has_element_in_active_list() && !has_element_in_pending_list()) |
| 151 return; | 152 return; |
| 152 | 153 |
| 153 if (needs_to_start_animations_) | 154 if (needs_to_start_animations_) |
| 154 StartAnimations(monotonic_time); | 155 StartAnimations(monotonic_time); |
| 155 TickAnimations(monotonic_time); | 156 TickAnimations(monotonic_time); |
| 156 last_tick_time_ = monotonic_time; | 157 last_tick_time_ = monotonic_time; |
| 158 bool some_opacity_animation_is_now_running = !AllOpacityAnimationsEnded(); |
| 159 if (some_opacity_animation_is_now_running) |
| 160 OnOpacityIsCurrentlyAnimatingChanged(true); |
| 157 } | 161 } |
| 158 | 162 |
| 159 void ElementAnimations::AccumulatePropertyUpdates( | 163 void ElementAnimations::AccumulatePropertyUpdates( |
| 160 base::TimeTicks monotonic_time, | 164 base::TimeTicks monotonic_time, |
| 161 AnimationEvents* events) { | 165 AnimationEvents* events) { |
| 162 if (!events) | 166 if (!events) |
| 163 return; | 167 return; |
| 164 | 168 |
| 165 for (size_t i = 0; i < animations_.size(); ++i) { | 169 for (size_t i = 0; i < animations_.size(); ++i) { |
| 166 Animation* animation = animations_[i].get(); | 170 Animation* animation = animations_[i].get(); |
| (...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 756 NotifyAnimationStarted(started_event); | 760 NotifyAnimationStarted(started_event); |
| 757 else | 761 else |
| 758 events->events_.push_back(started_event); | 762 events->events_.push_back(started_event); |
| 759 } | 763 } |
| 760 } | 764 } |
| 761 } | 765 } |
| 762 } | 766 } |
| 763 | 767 |
| 764 void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) { | 768 void ElementAnimations::MarkFinishedAnimations(base::TimeTicks monotonic_time) { |
| 765 bool finished_transform_animation = false; | 769 bool finished_transform_animation = false; |
| 770 bool finished_opacity_animation = false; |
| 766 for (size_t i = 0; i < animations_.size(); ++i) { | 771 for (size_t i = 0; i < animations_.size(); ++i) { |
| 767 if (!animations_[i]->is_finished() && | 772 if (!animations_[i]->is_finished() && |
| 768 animations_[i]->IsFinishedAt(monotonic_time)) { | 773 animations_[i]->IsFinishedAt(monotonic_time)) { |
| 769 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); | 774 animations_[i]->SetRunState(Animation::FINISHED, monotonic_time); |
| 770 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) { | 775 if (animations_[i]->target_property() == TargetProperty::TRANSFORM) |
| 771 finished_transform_animation = true; | 776 finished_transform_animation = true; |
| 772 } | 777 else if (animations_[i]->target_property() == TargetProperty::OPACITY) |
| 778 finished_opacity_animation = true; |
| 773 } | 779 } |
| 774 } | 780 } |
| 775 if (finished_transform_animation) | 781 if (finished_transform_animation) |
| 776 UpdatePotentiallyAnimatingTransform(); | 782 UpdatePotentiallyAnimatingTransform(); |
| 783 if (finished_opacity_animation && AllOpacityAnimationsEnded()) |
| 784 OnOpacityIsCurrentlyAnimatingChanged(false); |
| 777 } | 785 } |
| 778 | 786 |
| 779 void ElementAnimations::MarkAnimationsForDeletion( | 787 void ElementAnimations::MarkAnimationsForDeletion( |
| 780 base::TimeTicks monotonic_time, | 788 base::TimeTicks monotonic_time, |
| 781 AnimationEvents* events) { | 789 AnimationEvents* events) { |
| 782 bool marked_animations_for_deletions = false; | 790 bool marked_animations_for_deletions = false; |
| 783 std::vector<size_t> animations_with_same_group_id; | 791 std::vector<size_t> animations_with_same_group_id; |
| 784 | 792 |
| 785 animations_with_same_group_id.reserve(animations_.size()); | 793 animations_with_same_group_id.reserve(animations_.size()); |
| 786 // Non-aborted animations are marked for deletion after a corresponding | 794 // Non-aborted animations are marked for deletion after a corresponding |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1103 was_potentially_animating_transform_for_pending_elements != | 1111 was_potentially_animating_transform_for_pending_elements != |
| 1104 potentially_animating_transform_for_pending_elements_; | 1112 potentially_animating_transform_for_pending_elements_; |
| 1105 | 1113 |
| 1106 if (!changed_for_active_elements && !changed_for_pending_elements) | 1114 if (!changed_for_active_elements && !changed_for_pending_elements) |
| 1107 return; | 1115 return; |
| 1108 | 1116 |
| 1109 NotifyClientTransformIsPotentiallyAnimatingChanged( | 1117 NotifyClientTransformIsPotentiallyAnimatingChanged( |
| 1110 changed_for_active_elements, changed_for_pending_elements); | 1118 changed_for_active_elements, changed_for_pending_elements); |
| 1111 } | 1119 } |
| 1112 | 1120 |
| 1121 bool ElementAnimations::AllOpacityAnimationsEnded() { |
| 1122 for (const auto& animation : animations_) { |
| 1123 if (!animation->is_finished() && animation->InEffect(last_tick_time_) && |
| 1124 animation->target_property() == TargetProperty::OPACITY) |
| 1125 return false; |
| 1126 } |
| 1127 return true; |
| 1128 } |
| 1129 |
| 1113 bool ElementAnimations::HasActiveAnimation() const { | 1130 bool ElementAnimations::HasActiveAnimation() const { |
| 1114 for (size_t i = 0; i < animations_.size(); ++i) { | 1131 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1115 if (!animations_[i]->is_finished()) | 1132 if (!animations_[i]->is_finished()) |
| 1116 return true; | 1133 return true; |
| 1117 } | 1134 } |
| 1118 return false; | 1135 return false; |
| 1119 } | 1136 } |
| 1120 | 1137 |
| 1121 bool ElementAnimations::IsPotentiallyAnimatingProperty( | 1138 bool ElementAnimations::IsPotentiallyAnimatingProperty( |
| 1122 TargetProperty::Type target_property, | 1139 TargetProperty::Type target_property, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 if (animations_[i]->id() == animation_id) { | 1174 if (animations_[i]->id() == animation_id) { |
| 1158 animations_[i]->SetRunState(Animation::PAUSED, | 1175 animations_[i]->SetRunState(Animation::PAUSED, |
| 1159 time_offset + animations_[i]->start_time() + | 1176 time_offset + animations_[i]->start_time() + |
| 1160 animations_[i]->time_offset()); | 1177 animations_[i]->time_offset()); |
| 1161 } | 1178 } |
| 1162 } | 1179 } |
| 1163 } | 1180 } |
| 1164 | 1181 |
| 1165 void ElementAnimations::RemoveAnimation(int animation_id) { | 1182 void ElementAnimations::RemoveAnimation(int animation_id) { |
| 1166 bool removed_transform_animation = false; | 1183 bool removed_transform_animation = false; |
| 1184 bool removed_opacity_animation = false; |
| 1167 // Since we want to use the animations that we're going to remove, we need to | 1185 // 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 | 1186 // use a stable_parition here instead of remove_if. Remove_if leaves the |
| 1169 // removed items in an unspecified state. | 1187 // removed items in an unspecified state. |
| 1170 auto animations_to_remove = std::stable_partition( | 1188 auto animations_to_remove = std::stable_partition( |
| 1171 animations_.begin(), animations_.end(), | 1189 animations_.begin(), animations_.end(), |
| 1172 [animation_id](const std::unique_ptr<Animation>& animation) { | 1190 [animation_id](const std::unique_ptr<Animation>& animation) { |
| 1173 return animation->id() != animation_id; | 1191 return animation->id() != animation_id; |
| 1174 }); | 1192 }); |
| 1175 for (auto it = animations_to_remove; it != animations_.end(); ++it) { | 1193 for (auto it = animations_to_remove; it != animations_.end(); ++it) { |
| 1176 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { | 1194 if ((*it)->target_property() == TargetProperty::SCROLL_OFFSET) { |
| 1177 scroll_offset_animation_was_interrupted_ = true; | 1195 scroll_offset_animation_was_interrupted_ = true; |
| 1178 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && | 1196 } else if ((*it)->target_property() == TargetProperty::TRANSFORM && |
| 1179 !(*it)->is_finished()) { | 1197 !(*it)->is_finished()) { |
| 1180 removed_transform_animation = true; | 1198 removed_transform_animation = true; |
| 1199 } else if ((*it)->target_property() == TargetProperty::OPACITY && |
| 1200 !(*it)->is_finished()) { |
| 1201 removed_opacity_animation = true; |
| 1181 } | 1202 } |
| 1182 } | 1203 } |
| 1183 | 1204 |
| 1184 animations_.erase(animations_to_remove, animations_.end()); | 1205 animations_.erase(animations_to_remove, animations_.end()); |
| 1185 UpdateActivation(NORMAL_ACTIVATION); | 1206 UpdateActivation(NORMAL_ACTIVATION); |
| 1186 if (removed_transform_animation) | 1207 if (removed_transform_animation) |
| 1187 UpdatePotentiallyAnimatingTransform(); | 1208 UpdatePotentiallyAnimatingTransform(); |
| 1209 if (removed_opacity_animation && AllOpacityAnimationsEnded()) |
| 1210 OnOpacityIsCurrentlyAnimatingChanged(false); |
| 1188 } | 1211 } |
| 1189 | 1212 |
| 1190 void ElementAnimations::AbortAnimation(int animation_id) { | 1213 void ElementAnimations::AbortAnimation(int animation_id) { |
| 1191 bool aborted_transform_animation = false; | 1214 bool aborted_transform_animation = false; |
| 1215 bool aborted_opacity_animation = false; |
| 1192 if (Animation* animation = GetAnimationById(animation_id)) { | 1216 if (Animation* animation = GetAnimationById(animation_id)) { |
| 1193 if (!animation->is_finished()) { | 1217 if (!animation->is_finished()) { |
| 1194 animation->SetRunState(Animation::ABORTED, last_tick_time_); | 1218 animation->SetRunState(Animation::ABORTED, last_tick_time_); |
| 1195 if (animation->target_property() == TargetProperty::TRANSFORM) | 1219 if (animation->target_property() == TargetProperty::TRANSFORM) |
| 1196 aborted_transform_animation = true; | 1220 aborted_transform_animation = true; |
| 1221 else if (animation->target_property() == TargetProperty::OPACITY) |
| 1222 aborted_opacity_animation = true; |
| 1197 } | 1223 } |
| 1198 } | 1224 } |
| 1199 if (aborted_transform_animation) | 1225 if (aborted_transform_animation) |
| 1200 UpdatePotentiallyAnimatingTransform(); | 1226 UpdatePotentiallyAnimatingTransform(); |
| 1227 if (aborted_opacity_animation && AllOpacityAnimationsEnded()) |
| 1228 OnOpacityIsCurrentlyAnimatingChanged(false); |
| 1201 } | 1229 } |
| 1202 | 1230 |
| 1203 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, | 1231 void ElementAnimations::AbortAnimations(TargetProperty::Type target_property, |
| 1204 bool needs_completion) { | 1232 bool needs_completion) { |
| 1205 if (needs_completion) | 1233 if (needs_completion) |
| 1206 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); | 1234 DCHECK(target_property == TargetProperty::SCROLL_OFFSET); |
| 1207 | 1235 |
| 1208 bool aborted_transform_animation = false; | 1236 bool aborted_transform_animation = false; |
| 1237 bool aborted_opacity_animation = false; |
| 1209 for (size_t i = 0; i < animations_.size(); ++i) { | 1238 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1210 if (animations_[i]->target_property() == target_property && | 1239 if (animations_[i]->target_property() == target_property && |
| 1211 !animations_[i]->is_finished()) { | 1240 !animations_[i]->is_finished()) { |
| 1212 // Currently only impl-only scroll offset animations can be completed on | 1241 // Currently only impl-only scroll offset animations can be completed on |
| 1213 // the main thread. | 1242 // the main thread. |
| 1214 if (needs_completion && animations_[i]->is_impl_only()) { | 1243 if (needs_completion && animations_[i]->is_impl_only()) { |
| 1215 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, | 1244 animations_[i]->SetRunState(Animation::ABORTED_BUT_NEEDS_COMPLETION, |
| 1216 last_tick_time_); | 1245 last_tick_time_); |
| 1217 } else { | 1246 } else { |
| 1218 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); | 1247 animations_[i]->SetRunState(Animation::ABORTED, last_tick_time_); |
| 1219 } | 1248 } |
| 1220 if (target_property == TargetProperty::TRANSFORM) | 1249 if (target_property == TargetProperty::TRANSFORM) |
| 1221 aborted_transform_animation = true; | 1250 aborted_transform_animation = true; |
| 1251 else if (target_property == TargetProperty::OPACITY) |
| 1252 aborted_opacity_animation = true; |
| 1222 } | 1253 } |
| 1223 } | 1254 } |
| 1224 if (aborted_transform_animation) | 1255 if (aborted_transform_animation) |
| 1225 UpdatePotentiallyAnimatingTransform(); | 1256 UpdatePotentiallyAnimatingTransform(); |
| 1257 if (aborted_opacity_animation && AllOpacityAnimationsEnded()) |
| 1258 OnOpacityIsCurrentlyAnimatingChanged(false); |
| 1226 } | 1259 } |
| 1227 | 1260 |
| 1228 Animation* ElementAnimations::GetAnimation( | 1261 Animation* ElementAnimations::GetAnimation( |
| 1229 TargetProperty::Type target_property) const { | 1262 TargetProperty::Type target_property) const { |
| 1230 for (size_t i = 0; i < animations_.size(); ++i) { | 1263 for (size_t i = 0; i < animations_.size(); ++i) { |
| 1231 size_t index = animations_.size() - i - 1; | 1264 size_t index = animations_.size() - i - 1; |
| 1232 if (animations_[index]->target_property() == target_property) | 1265 if (animations_[index]->target_property() == target_property) |
| 1233 return animations_[index].get(); | 1266 return animations_[index].get(); |
| 1234 } | 1267 } |
| 1235 return nullptr; | 1268 return nullptr; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 bool is_animating) { | 1324 bool is_animating) { |
| 1292 DCHECK(element_id()); | 1325 DCHECK(element_id()); |
| 1293 DCHECK(animation_host()); | 1326 DCHECK(animation_host()); |
| 1294 DCHECK(animation_host()->mutator_host_client()); | 1327 DCHECK(animation_host()->mutator_host_client()); |
| 1295 animation_host() | 1328 animation_host() |
| 1296 ->mutator_host_client() | 1329 ->mutator_host_client() |
| 1297 ->ElementTransformIsPotentiallyAnimatingChanged(element_id(), list_type, | 1330 ->ElementTransformIsPotentiallyAnimatingChanged(element_id(), list_type, |
| 1298 is_animating); | 1331 is_animating); |
| 1299 } | 1332 } |
| 1300 | 1333 |
| 1334 void ElementAnimations::OnOpacityIsCurrentlyAnimatingChanged( |
| 1335 bool is_currently_animating) { |
| 1336 DCHECK(element_id()); |
| 1337 DCHECK(animation_host()); |
| 1338 if (animation_host()->mutator_host_client()) |
| 1339 animation_host() |
| 1340 ->mutator_host_client() |
| 1341 ->ElementOpacityIsCurrentlyAnimatingChanged(element_id(), |
| 1342 is_currently_animating); |
| 1343 } |
| 1344 |
| 1301 void ElementAnimations::NotifyPlayersAnimationStarted( | 1345 void ElementAnimations::NotifyPlayersAnimationStarted( |
| 1302 base::TimeTicks monotonic_time, | 1346 base::TimeTicks monotonic_time, |
| 1303 TargetProperty::Type target_property, | 1347 TargetProperty::Type target_property, |
| 1304 int group) { | 1348 int group) { |
| 1305 for (PlayersListNode* node = players_list_->head(); | 1349 for (PlayersListNode* node = players_list_->head(); |
| 1306 node != players_list_->end(); node = node->next()) { | 1350 node != players_list_->end(); node = node->next()) { |
| 1307 AnimationPlayer* player = node->value(); | 1351 AnimationPlayer* player = node->value(); |
| 1308 player->NotifyAnimationStarted(monotonic_time, target_property, group); | 1352 player->NotifyAnimationStarted(monotonic_time, target_property, group); |
| 1309 } | 1353 } |
| 1310 } | 1354 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1351 if (animation_host()) { | 1395 if (animation_host()) { |
| 1352 DCHECK(animation_host()->mutator_host_client()); | 1396 DCHECK(animation_host()->mutator_host_client()); |
| 1353 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 1397 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
| 1354 element_id()); | 1398 element_id()); |
| 1355 } | 1399 } |
| 1356 | 1400 |
| 1357 return gfx::ScrollOffset(); | 1401 return gfx::ScrollOffset(); |
| 1358 } | 1402 } |
| 1359 | 1403 |
| 1360 } // namespace cc | 1404 } // namespace cc |
| OLD | NEW |