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 3 // found in the LICENSE file. 4 5 #include "cc/animation/animation_registrar.h" 6 7 #include "cc/animation/layer_animation_controller.h" 8 9 namespace cc { 10 11 AnimationRegistrar::AnimationRegistrar() {} 12 13 AnimationRegistrar::~AnimationRegistrar() { 14 AnimationControllerMap copy = all_animation_controllers_; 15 for (AnimationControllerMap::iterator iter = copy.begin(); 16 iter != copy.end(); 17 ++iter) 18 (*iter).second->SetAnimationRegistrar(NULL); 19 } 20 21 scoped_refptr<LayerAnimationController> 22 AnimationRegistrar::GetAnimationControllerForId(int id) { 23 scoped_refptr<LayerAnimationController> to_return; 24 if (!ContainsKey(all_animation_controllers_, id)) { 25 to_return = LayerAnimationController::Create(id); 26 to_return->SetAnimationRegistrar(this); 27 all_animation_controllers_[id] = to_return.get(); 28 } else { 29 to_return = all_animation_controllers_[id]; 30 } 31 return to_return; 32 } 33 34 void AnimationRegistrar::DidActivateAnimationController( 35 LayerAnimationController* controller) { 36 active_animation_controllers_[controller->id()] = controller; 37 } 38 39 void AnimationRegistrar::DidDeactivateAnimationController( 40 LayerAnimationController* controller) { 41 if (ContainsKey(active_animation_controllers_, controller->id())) 42 active_animation_controllers_.erase(controller->id()); 43 } 44 45 void AnimationRegistrar::RegisterAnimationController( 46 LayerAnimationController* controller) { 47 all_animation_controllers_[controller->id()] = controller; 48 } 49 50 void AnimationRegistrar::UnregisterAnimationController( 51 LayerAnimationController* controller) { 52 if (ContainsKey(all_animation_controllers_, controller->id())) 53 all_animation_controllers_.erase(controller->id()); 54 DidDeactivateAnimationController(controller); 55 } 56 57 } // namespace cc 58