Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: cc/animation/element_animations.cc

Issue 2189813002: ElementAnimations should hold an ObservableList of AnimationPlayers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove FOR_EACH_OBSERVER Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/animation/element_animations.h ('k') | cc/animation/element_animations_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1439 node != players_list_->end(); node = node->next()) { 1433 AnimationPlayer* player;
1440 AnimationPlayer* player = node->value(); 1434 while ((player = it.GetNext()) != nullptr) {
loyso (OOO) 2016/08/05 01:33:28 Code style: No braces {} need for one line (here a
1441 player->NotifyAnimationStarted(monotonic_time, target_property, group); 1435 player->NotifyAnimationStarted(monotonic_time, target_property, group);
1442 } 1436 }
1443 } 1437 }
1444 1438
1445 void ElementAnimations::NotifyPlayersAnimationFinished( 1439 void ElementAnimations::NotifyPlayersAnimationFinished(
1446 base::TimeTicks monotonic_time, 1440 base::TimeTicks monotonic_time,
1447 TargetProperty::Type target_property, 1441 TargetProperty::Type target_property,
1448 int group) { 1442 int group) {
1449 for (PlayersListNode* node = players_list_->head(); 1443 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1450 node != players_list_->end(); node = node->next()) { 1444 AnimationPlayer* player;
1451 AnimationPlayer* player = node->value(); 1445 while ((player = it.GetNext()) != nullptr) {
1452 player->NotifyAnimationFinished(monotonic_time, target_property, group); 1446 player->NotifyAnimationFinished(monotonic_time, target_property, group);
1453 } 1447 }
1454 } 1448 }
1455 1449
1456 void ElementAnimations::NotifyPlayersAnimationAborted( 1450 void ElementAnimations::NotifyPlayersAnimationAborted(
1457 base::TimeTicks monotonic_time, 1451 base::TimeTicks monotonic_time,
1458 TargetProperty::Type target_property, 1452 TargetProperty::Type target_property,
1459 int group) { 1453 int group) {
1460 for (PlayersListNode* node = players_list_->head(); 1454 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1461 node != players_list_->end(); node = node->next()) { 1455 AnimationPlayer* player;
1462 AnimationPlayer* player = node->value(); 1456 while ((player = it.GetNext()) != nullptr) {
1463 player->NotifyAnimationAborted(monotonic_time, target_property, group); 1457 player->NotifyAnimationAborted(monotonic_time, target_property, group);
1464 } 1458 }
1465 } 1459 }
1466 1460
1467 void ElementAnimations::NotifyPlayersAnimationTakeover( 1461 void ElementAnimations::NotifyPlayersAnimationTakeover(
1468 base::TimeTicks monotonic_time, 1462 base::TimeTicks monotonic_time,
1469 TargetProperty::Type target_property, 1463 TargetProperty::Type target_property,
1470 double animation_start_time, 1464 double animation_start_time,
1471 std::unique_ptr<AnimationCurve> curve) { 1465 std::unique_ptr<AnimationCurve> curve) {
1472 DCHECK(curve); 1466 DCHECK(curve);
1473 for (PlayersListNode* node = players_list_->head(); 1467 ElementAnimations::PlayersList::Iterator it(players_list_.get());
1474 node != players_list_->end(); node = node->next()) { 1468 AnimationPlayer* player;
1469 while ((player = it.GetNext()) != nullptr) {
1475 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone(); 1470 std::unique_ptr<AnimationCurve> animation_curve = curve->Clone();
1476 AnimationPlayer* player = node->value();
1477 player->NotifyAnimationTakeover(monotonic_time, target_property, 1471 player->NotifyAnimationTakeover(monotonic_time, target_property,
1478 animation_start_time, 1472 animation_start_time,
1479 std::move(animation_curve)); 1473 std::move(animation_curve));
1480 } 1474 }
1481 } 1475 }
1482 1476
1483 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const { 1477 gfx::ScrollOffset ElementAnimations::ScrollOffsetForAnimation() const {
1484 if (animation_host()) { 1478 if (animation_host()) {
1485 DCHECK(animation_host()->mutator_host_client()); 1479 DCHECK(animation_host()->mutator_host_client());
1486 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation( 1480 return animation_host()->mutator_host_client()->GetScrollOffsetForAnimation(
1487 element_id()); 1481 element_id());
1488 } 1482 }
1489 1483
1490 return gfx::ScrollOffset(); 1484 return gfx::ScrollOffset();
1491 } 1485 }
1492 1486
1493 } // namespace cc 1487 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/element_animations.h ('k') | cc/animation/element_animations_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698