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

Unified 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: apply loyso's comment 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 side-by-side diff with in-line comments
Download patch
Index: cc/animation/element_animations.cc
diff --git a/cc/animation/element_animations.cc b/cc/animation/element_animations.cc
index 708cdee0b9c274285ce9c9b57de3b4894f121ee4..fc92949fe8ba08826d49863be9d8457649d6c81a 100644
--- a/cc/animation/element_animations.cc
+++ b/cc/animation/element_animations.cc
@@ -111,21 +111,15 @@ void ElementAnimations::ElementUnregistered(ElementId element_id,
}
void ElementAnimations::AddPlayer(AnimationPlayer* player) {
- players_list_->Append(player);
+ players_list_->AddObserver(player);
}
void ElementAnimations::RemovePlayer(AnimationPlayer* player) {
- for (PlayersListNode* node = players_list_->head();
- node != players_list_->end(); node = node->next()) {
- if (node->value() == player) {
- node->RemoveFromList();
- return;
- }
- }
+ players_list_->RemoveObserver(player);
}
bool ElementAnimations::IsEmpty() const {
- return players_list_->empty();
+ return !players_list_->might_have_observers();
}
void ElementAnimations::PushPropertiesTo(
@@ -281,7 +275,7 @@ void ElementAnimations::NotifyAnimationFinished(const AnimationEvent& event) {
void ElementAnimations::NotifyAnimationTakeover(const AnimationEvent& event) {
DCHECK(event.target_property == TargetProperty::SCROLL_OFFSET);
- if (!players_list_->empty()) {
+ if (!IsEmpty()) {
std::unique_ptr<AnimationCurve> animation_curve = event.curve->Clone();
NotifyPlayersAnimationTakeover(event.monotonic_time, event.target_property,
event.animation_start_time,
@@ -1435,33 +1429,25 @@ void ElementAnimations::NotifyPlayersAnimationStarted(
base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
int group) {
- for (PlayersListNode* node = players_list_->head();
- node != players_list_->end(); node = node->next()) {
- AnimationPlayer* player = node->value();
- player->NotifyAnimationStarted(monotonic_time, target_property, group);
- }
+ FOR_EACH_OBSERVER(AnimationPlayer, *players_list_.get(),
+ OnAnimationStarted(monotonic_time, target_property, group));
}
void ElementAnimations::NotifyPlayersAnimationFinished(
base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
int group) {
- for (PlayersListNode* node = players_list_->head();
- node != players_list_->end(); node = node->next()) {
- AnimationPlayer* player = node->value();
- player->NotifyAnimationFinished(monotonic_time, target_property, group);
- }
+ FOR_EACH_OBSERVER(
+ AnimationPlayer, *players_list_.get(),
+ OnAnimationFinished(monotonic_time, target_property, group));
}
void ElementAnimations::NotifyPlayersAnimationAborted(
base::TimeTicks monotonic_time,
TargetProperty::Type target_property,
int group) {
- for (PlayersListNode* node = players_list_->head();
- node != players_list_->end(); node = node->next()) {
- AnimationPlayer* player = node->value();
- player->NotifyAnimationAborted(monotonic_time, target_property, group);
- }
+ FOR_EACH_OBSERVER(AnimationPlayer, *players_list_.get(),
+ OnAnimationAborted(monotonic_time, target_property, group));
}
void ElementAnimations::NotifyPlayersAnimationTakeover(
@@ -1470,13 +1456,13 @@ void ElementAnimations::NotifyPlayersAnimationTakeover(
double animation_start_time,
std::unique_ptr<AnimationCurve> curve) {
DCHECK(curve);
- for (PlayersListNode* node = players_list_->head();
- node != players_list_->end(); node = node->next()) {
+ base::ObserverList<AnimationPlayer>::Iterator it(players_list_.get());
loyso (OOO) 2016/08/05 00:18:48 Use ElementAnimations::PlayersList type here, plea
ymalik 2016/08/05 00:54:04 Totally, Done.
+ AnimationPlayer* player;
+ while ((player = it.GetNext()) != nullptr) {
loyso (OOO) 2016/08/05 00:13:25 Any comment, why this iteration is different and F
ymalik 2016/08/05 00:54:04 We need to call player->OnAnimationTakeover with a
std::unique_ptr<AnimationCurve> animation_curve = curve->Clone();
- AnimationPlayer* player = node->value();
- player->NotifyAnimationTakeover(monotonic_time, target_property,
- animation_start_time,
- std::move(animation_curve));
+ player->OnAnimationTakeover(monotonic_time, target_property,
+ animation_start_time,
+ std::move(animation_curve));
}
}

Powered by Google App Engine
This is Rietveld 408576698