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

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

Issue 1882733005: CC Animation: Make LayerAnimationController to have just one value observer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@privatelac
Patch Set: Fix codereview issues. Created 4 years, 8 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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/layer_animation_controller.h" 5 #include "cc/animation/layer_animation_controller.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 10 matching lines...) Expand all
21 #include "cc/output/filter_operations.h" 21 #include "cc/output/filter_operations.h"
22 #include "ui/gfx/geometry/box_f.h" 22 #include "ui/gfx/geometry/box_f.h"
23 #include "ui/gfx/transform.h" 23 #include "ui/gfx/transform.h"
24 24
25 namespace cc { 25 namespace cc {
26 26
27 LayerAnimationController::LayerAnimationController(int id) 27 LayerAnimationController::LayerAnimationController(int id)
28 : host_(0), 28 : host_(0),
29 id_(id), 29 id_(id),
30 is_active_(false), 30 is_active_(false),
31 value_observer_(nullptr),
31 value_provider_(nullptr), 32 value_provider_(nullptr),
32 layer_animation_delegate_(nullptr), 33 layer_animation_delegate_(nullptr),
34 needs_active_value_observations_(false),
35 needs_pending_value_observations_(false),
33 needs_to_start_animations_(false), 36 needs_to_start_animations_(false),
34 scroll_offset_animation_was_interrupted_(false), 37 scroll_offset_animation_was_interrupted_(false),
35 potentially_animating_transform_for_active_observers_(false), 38 potentially_animating_transform_for_active_observers_(false),
36 potentially_animating_transform_for_pending_observers_(false) {} 39 potentially_animating_transform_for_pending_observers_(false) {}
37 40
38 LayerAnimationController::~LayerAnimationController() { 41 LayerAnimationController::~LayerAnimationController() {
39 if (host_) 42 if (host_)
40 host_->UnregisterAnimationController(this); 43 host_->UnregisterAnimationController(this);
41 } 44 }
42 45
(...skipping 435 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 break; 481 break;
479 case TargetProperty::TRANSFORM: 482 case TargetProperty::TRANSFORM:
480 NotifyObserversTransformAnimated( 483 NotifyObserversTransformAnimated(
481 event.transform, notify_active_observers, notify_pending_observers); 484 event.transform, notify_active_observers, notify_pending_observers);
482 break; 485 break;
483 default: 486 default:
484 NOTREACHED(); 487 NOTREACHED();
485 } 488 }
486 } 489 }
487 490
488 void LayerAnimationController::AddValueObserver(
489 LayerAnimationValueObserver* observer) {
490 if (!value_observers_.HasObserver(observer))
491 value_observers_.AddObserver(observer);
492 }
493
494 void LayerAnimationController::RemoveValueObserver(
495 LayerAnimationValueObserver* observer) {
496 value_observers_.RemoveObserver(observer);
497 }
498
499 void LayerAnimationController::AddEventObserver( 491 void LayerAnimationController::AddEventObserver(
500 LayerAnimationEventObserver* observer) { 492 LayerAnimationEventObserver* observer) {
501 if (!event_observers_.HasObserver(observer)) 493 if (!event_observers_.HasObserver(observer))
502 event_observers_.AddObserver(observer); 494 event_observers_.AddObserver(observer);
503 } 495 }
504 496
505 void LayerAnimationController::RemoveEventObserver( 497 void LayerAnimationController::RemoveEventObserver(
506 LayerAnimationEventObserver* observer) { 498 LayerAnimationEventObserver* observer) {
507 event_observers_.RemoveObserver(observer); 499 event_observers_.RemoveObserver(observer);
508 } 500 }
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 host_->DidActivateAnimationController(this); 1167 host_->DidActivateAnimationController(this);
1176 else if (!is_active_ && (was_active || force)) 1168 else if (!is_active_ && (was_active || force))
1177 host_->DidDeactivateAnimationController(this); 1169 host_->DidDeactivateAnimationController(this);
1178 } 1170 }
1179 } 1171 }
1180 1172
1181 void LayerAnimationController::NotifyObserversOpacityAnimated( 1173 void LayerAnimationController::NotifyObserversOpacityAnimated(
1182 float opacity, 1174 float opacity,
1183 bool notify_active_observers, 1175 bool notify_active_observers,
1184 bool notify_pending_observers) { 1176 bool notify_pending_observers) {
1185 if (value_observers_.might_have_observers()) { 1177 if (!value_observer_)
1186 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1178 return;
1187 &value_observers_); 1179 if (notify_active_observers && needs_active_value_observations())
1188 LayerAnimationValueObserver* obs; 1180 value_observer_->OnOpacityAnimated(LayerTreeType::ACTIVE, opacity);
1189 while ((obs = it.GetNext()) != nullptr) { 1181 if (notify_pending_observers && needs_pending_value_observations())
1190 if ((notify_active_observers && notify_pending_observers) || 1182 value_observer_->OnOpacityAnimated(LayerTreeType::PENDING, opacity);
1191 (notify_active_observers && obs->IsActive()) ||
1192 (notify_pending_observers && !obs->IsActive()))
1193 obs->OnOpacityAnimated(opacity);
1194 }
1195 }
1196 } 1183 }
1197 1184
1198 void LayerAnimationController::NotifyObserversTransformAnimated( 1185 void LayerAnimationController::NotifyObserversTransformAnimated(
1199 const gfx::Transform& transform, 1186 const gfx::Transform& transform,
1200 bool notify_active_observers, 1187 bool notify_active_observers,
1201 bool notify_pending_observers) { 1188 bool notify_pending_observers) {
1202 if (value_observers_.might_have_observers()) { 1189 if (!value_observer_)
1203 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1190 return;
1204 &value_observers_); 1191 if (notify_active_observers && needs_active_value_observations())
1205 LayerAnimationValueObserver* obs; 1192 value_observer_->OnTransformAnimated(LayerTreeType::ACTIVE, transform);
1206 while ((obs = it.GetNext()) != nullptr) { 1193 if (notify_pending_observers && needs_pending_value_observations())
1207 if ((notify_active_observers && notify_pending_observers) || 1194 value_observer_->OnTransformAnimated(LayerTreeType::PENDING, transform);
1208 (notify_active_observers && obs->IsActive()) ||
1209 (notify_pending_observers && !obs->IsActive()))
1210 obs->OnTransformAnimated(transform);
1211 }
1212 }
1213 } 1195 }
1214 1196
1215 void LayerAnimationController::NotifyObserversFilterAnimated( 1197 void LayerAnimationController::NotifyObserversFilterAnimated(
1216 const FilterOperations& filters, 1198 const FilterOperations& filters,
1217 bool notify_active_observers, 1199 bool notify_active_observers,
1218 bool notify_pending_observers) { 1200 bool notify_pending_observers) {
1219 if (value_observers_.might_have_observers()) { 1201 if (!value_observer_)
1220 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1202 return;
1221 &value_observers_); 1203 if (notify_active_observers && needs_active_value_observations())
1222 LayerAnimationValueObserver* obs; 1204 value_observer_->OnFilterAnimated(LayerTreeType::ACTIVE, filters);
1223 while ((obs = it.GetNext()) != nullptr) { 1205 if (notify_pending_observers && needs_pending_value_observations())
1224 if ((notify_active_observers && notify_pending_observers) || 1206 value_observer_->OnFilterAnimated(LayerTreeType::PENDING, filters);
1225 (notify_active_observers && obs->IsActive()) ||
1226 (notify_pending_observers && !obs->IsActive()))
1227 obs->OnFilterAnimated(filters);
1228 }
1229 }
1230 } 1207 }
1231 1208
1232 void LayerAnimationController::NotifyObserversScrollOffsetAnimated( 1209 void LayerAnimationController::NotifyObserversScrollOffsetAnimated(
1233 const gfx::ScrollOffset& scroll_offset, 1210 const gfx::ScrollOffset& scroll_offset,
1234 bool notify_active_observers, 1211 bool notify_active_observers,
1235 bool notify_pending_observers) { 1212 bool notify_pending_observers) {
1236 if (value_observers_.might_have_observers()) { 1213 if (!value_observer_)
1237 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1214 return;
1238 &value_observers_); 1215 if (notify_active_observers && needs_active_value_observations())
1239 LayerAnimationValueObserver* obs; 1216 value_observer_->OnScrollOffsetAnimated(LayerTreeType::ACTIVE,
1240 while ((obs = it.GetNext()) != nullptr) { 1217 scroll_offset);
1241 if ((notify_active_observers && notify_pending_observers) || 1218 if (notify_pending_observers && needs_pending_value_observations())
1242 (notify_active_observers && obs->IsActive()) || 1219 value_observer_->OnScrollOffsetAnimated(LayerTreeType::PENDING,
1243 (notify_pending_observers && !obs->IsActive())) 1220 scroll_offset);
1244 obs->OnScrollOffsetAnimated(scroll_offset);
1245 }
1246 }
1247 } 1221 }
1248 1222
1249 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() { 1223 void LayerAnimationController::NotifyObserversAnimationWaitingForDeletion() {
1250 FOR_EACH_OBSERVER(LayerAnimationValueObserver, 1224 if (value_observer_)
1251 value_observers_, 1225 value_observer_->OnAnimationWaitingForDeletion();
1252 OnAnimationWaitingForDeletion());
1253 } 1226 }
1254 1227
1255 void LayerAnimationController:: 1228 void LayerAnimationController::
1256 NotifyObserversTransformIsPotentiallyAnimatingChanged( 1229 NotifyObserversTransformIsPotentiallyAnimatingChanged(
1257 bool notify_active_observers, 1230 bool notify_active_observers,
1258 bool notify_pending_observers) { 1231 bool notify_pending_observers) {
1259 if (value_observers_.might_have_observers()) { 1232 if (!value_observer_)
1260 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1233 return;
1261 &value_observers_); 1234 if (notify_active_observers && needs_active_value_observations())
1262 LayerAnimationValueObserver* obs; 1235 value_observer_->OnTransformIsPotentiallyAnimatingChanged(
1263 while ((obs = it.GetNext()) != nullptr) { 1236 LayerTreeType::ACTIVE,
1264 if (notify_active_observers && obs->IsActive()) 1237 potentially_animating_transform_for_active_observers_);
1265 obs->OnTransformIsPotentiallyAnimatingChanged( 1238 if (notify_pending_observers && needs_pending_value_observations())
1266 potentially_animating_transform_for_active_observers_); 1239 value_observer_->OnTransformIsPotentiallyAnimatingChanged(
1267 else if (notify_pending_observers && !obs->IsActive()) 1240 LayerTreeType::PENDING,
1268 obs->OnTransformIsPotentiallyAnimatingChanged( 1241 potentially_animating_transform_for_pending_observers_);
1269 potentially_animating_transform_for_pending_observers_);
1270 }
1271 }
1272 } 1242 }
1273 1243
1274 bool LayerAnimationController::HasValueObserver() { 1244 bool LayerAnimationController::HasValueObserver() {
1275 if (value_observers_.might_have_observers()) { 1245 if (!value_observer_)
1276 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1246 return false;
1277 &value_observers_); 1247 return needs_active_value_observations() ||
1278 return it.GetNext() != nullptr; 1248 needs_pending_value_observations();
1279 }
1280 return false;
1281 } 1249 }
1282 1250
1283 bool LayerAnimationController::HasActiveValueObserver() { 1251 bool LayerAnimationController::HasActiveValueObserver() {
1284 if (value_observers_.might_have_observers()) { 1252 if (!value_observer_)
1285 base::ObserverListBase<LayerAnimationValueObserver>::Iterator it( 1253 return false;
1286 &value_observers_); 1254 return needs_active_value_observations();
1287 LayerAnimationValueObserver* obs;
1288 while ((obs = it.GetNext()) != nullptr)
1289 if (obs->IsActive())
1290 return true;
1291 }
1292 return false;
1293 } 1255 }
1294 1256
1295 } // namespace cc 1257 } // namespace cc
OLDNEW
« no previous file with comments | « cc/animation/layer_animation_controller.h ('k') | cc/animation/layer_animation_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698