| 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 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 if (list_type == ElementListType::ACTIVE) | 104 if (list_type == ElementListType::ACTIVE) |
| 105 set_has_element_in_active_list(false); | 105 set_has_element_in_active_list(false); |
| 106 else | 106 else |
| 107 set_has_element_in_pending_list(false); | 107 set_has_element_in_pending_list(false); |
| 108 | 108 |
| 109 if (!has_element_in_any_list()) | 109 if (!has_element_in_any_list()) |
| 110 animation_host_->DidDeactivateElementAnimations(this); | 110 animation_host_->DidDeactivateElementAnimations(this); |
| 111 } | 111 } |
| 112 | 112 |
| 113 void ElementAnimations::AddPlayer(AnimationPlayer* player) { | 113 void ElementAnimations::AddPlayer(AnimationPlayer* player) { |
| 114 players_list_->Append(player); | 114 players_list_->AddObserver(player); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void ElementAnimations::RemovePlayer(AnimationPlayer* player) { | 117 void ElementAnimations::RemovePlayer(AnimationPlayer* player) { |
| 118 for (PlayersListNode* node = players_list_->head(); | 118 players_list_->RemoveObserver(player); |
| 119 node != players_list_->end(); node = node->next()) { | |
| 120 if (node->value() == player) { | |
| 121 node->RemoveFromList(); | |
| 122 return; | |
| 123 } | |
| 124 } | |
| 125 } | 119 } |
| 126 | 120 |
| 127 bool ElementAnimations::IsEmpty() const { | 121 bool ElementAnimations::IsEmpty() const { |
| 128 return players_list_->empty(); | 122 return !players_list_->might_have_observers(); |
| 129 } | 123 } |
| 130 | 124 |
| 131 void ElementAnimations::PushPropertiesTo( | 125 void ElementAnimations::PushPropertiesTo( |
| 132 scoped_refptr<ElementAnimations> element_animations_impl) { | 126 scoped_refptr<ElementAnimations> element_animations_impl) { |
| 133 DCHECK_NE(this, element_animations_impl); | 127 DCHECK_NE(this, element_animations_impl); |
| 134 if (!has_any_animation() && !element_animations_impl->has_any_animation()) | 128 if (!has_any_animation() && !element_animations_impl->has_any_animation()) |
| 135 return; | 129 return; |
| 136 MarkAbortedAnimationsForDeletion(element_animations_impl.get()); | 130 MarkAbortedAnimationsForDeletion(element_animations_impl.get()); |
| 137 PurgeAnimationsMarkedForDeletion(); | 131 PurgeAnimationsMarkedForDeletion(); |
| 138 PushNewAnimationsToImplThread(element_animations_impl.get()); | 132 PushNewAnimationsToImplThread(element_animations_impl.get()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 NotifyPlayersAnimationFinished(event.monotonic_time, | 268 NotifyPlayersAnimationFinished(event.monotonic_time, |
| 275 event.target_property, event.group_id); | 269 event.target_property, event.group_id); |
| 276 | 270 |
| 277 return; | 271 return; |
| 278 } | 272 } |
| 279 } | 273 } |
| 280 } | 274 } |
| 281 | 275 |
| 282 void ElementAnimations::NotifyAnimationTakeover(const AnimationEvent& event) { | 276 void ElementAnimations::NotifyAnimationTakeover(const AnimationEvent& event) { |
| 283 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET); | 277 DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET); |
| 284 if (!players_list_->empty()) { | 278 if (!IsEmpty()) { |
| 285 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); | 279 std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone(); |
| 286 NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property, | 280 NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property, |
| 287 event.animation_start_time, | 281 event.animation_start_time, |
| 288 std::move(animation_curve)); | 282 std::move(animation_curve)); |
| 289 } | 283 } |
| 290 } | 284 } |
| 291 | 285 |
| 292 void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { | 286 void ElementAnimations::NotifyAnimationAborted(const AnimationEvent& event) { |
| 293 for (size_t i = 0; i < animations_.size(); ++i) { | 287 for (size_t i = 0; i < animations_.size(); ++i) { |
| 294 if (animations_[i]->group() == event.group_id && | 288 if (animations_[i]->group() == event.group_id && |
| (...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1428 NOTREACHED(); | 1422 NOTREACHED(); |
| 1429 break; | 1423 break; |
| 1430 } | 1424 } |
| 1431 } | 1425 } |
| 1432 } | 1426 } |
| 1433 | 1427 |
| 1434 void ElementAnimations::NotifyPlayersAnimationStarted( | 1428 void ElementAnimations::NotifyPlayersAnimationStarted( |
| 1435 base::TimeTicks monotonic_time, | 1429 base::TimeTicks monotonic_time, |
| 1436 TargetProperty::Type target_property, | 1430 TargetProperty::Type target_property, |
| 1437 int group) { | 1431 int group) { |
| 1438 for (PlayersListNode* node = players_list_->head(); | 1432 FOR_EACH_OBSERVER(AnimationPlayer, *players_list_.get(), |
| 1439 node != players_list_->end(); node = node->next()) { | 1433 OnAnimationStarted(monotonic_time, target_property, group)); |
| 1440 AnimationPlayer* player = node->value(); | |
| 1441 player->NotifyAnimationStarted(monotonic_time, target_property, group); | |
| 1442 } | |
| 1443 } | 1434 } |
| 1444 | 1435 |
| 1445 void ElementAnimations::NotifyPlayersAnimationFinished( | 1436 void ElementAnimations::NotifyPlayersAnimationFinished( |
| 1446 base::TimeTicks monotonic_time, | 1437 base::TimeTicks monotonic_time, |
| 1447 TargetProperty::Type target_property, | 1438 TargetProperty::Type target_property, |
| 1448 int group) { | 1439 int group) { |
| 1449 for (PlayersListNode* node = players_list_->head(); | 1440 FOR_EACH_OBSERVER( |
| 1450 node != players_list_->end(); node = node->next()) { | 1441 AnimationPlayer, *players_list_.get(), |
| 1451 AnimationPlayer* player = node->value(); | 1442 OnAnimationFinished(monotonic_time, target_property, group)); |
| 1452 player->NotifyAnimationFinished(monotonic_time, target_property, group); | |
| 1453 } | |
| 1454 } | 1443 } |
| 1455 | 1444 |
| 1456 void ElementAnimations::NotifyPlayersAnimationAborted( | 1445 void ElementAnimations::NotifyPlayersAnimationAborted( |
| 1457 base::TimeTicks monotonic_time, | 1446 base::TimeTicks monotonic_time, |
| 1458 TargetProperty::Type target_property, | 1447 TargetProperty::Type target_property, |
| 1459 int group) { | 1448 int group) { |
| 1460 for (PlayersListNode* node = players_list_->head(); | 1449 FOR_EACH_OBSERVER(AnimationPlayer, *players_list_.get(), |
| 1461 node != players_list_->end(); node = node->next()) { | 1450 OnAnimationAborted(monotonic_time, target_property, group)); |
| 1462 AnimationPlayer* player = node->value(); | |
| 1463 player->NotifyAnimationAborted(monotonic_time, target_property, group); | |
| 1464 } | |
| 1465 } | 1451 } |
| 1466 | 1452 |
| 1467 void ElementAnimations::NotifyPlayersAnimationTakeover( | 1453 void ElementAnimations::NotifyPlayersAnimationTakeover( |
| 1468 base::TimeTicks monotonic_time, | 1454 base::TimeTicks monotonic_time, |
| 1469 TargetProperty::Type target_property, | 1455 TargetProperty::Type target_property, |
| 1470 double animation_start_time, | 1456 double animation_start_time, |
| 1471 std::unique_ptr<AnimationCurve> curve) { | 1457 std::unique_ptr<AnimationCurve> curve) { |
| 1472 DCHECK(curve); | 1458 DCHECK(curve); |
| 1473 for (PlayersListNode* node = players_list_->head(); | 1459 base::ObserverList<AnimationPlayer>::Iterator it(players_list_.get()); |
| 1474 node != players_list_->end(); node = node->next()) { | 1460 AnimationPlayer* player; |
| 1461 while ((player = it.GetNext()) != nullptr) { |
| 1475 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone(); | 1462 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone(); |
| 1476 AnimationPlayer* player = node->value(); | 1463 player->OnAnimationTakeover(monotonic_time, target_property, |
| 1477 player->NotifyAnimationTakeover(monotonic_time, target_property, | 1464 animation_start_time, |
| 1478 animation_start_time, | 1465 std::move(animation_curve)); |
| 1479 std::move(animation_curve)); | |
| 1480 } | 1466 } |
| 1481 } | 1467 } |
| 1482 | 1468 |
| 1483 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const { | 1469 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const { |
| 1484 if (animation_host()) { | 1470 if (animation_host()) { |
| 1485 DCHECK(animation_host()->mutator_host_client()); | 1471 DCHECK(animation_host()->mutator_host_client()); |
| 1486 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( | 1472 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( |
| 1487 element_id()); | 1473 element_id()); |
| 1488 } | 1474 } |
| 1489 | 1475 |
| 1490 return gfx::ScrollOffset(); | 1476 return gfx::ScrollOffset(); |
| 1491 } | 1477 } |
| 1492 | 1478 |
| 1493 } // namespace cc | 1479 } // namespace cc |
| OLD | NEW |