| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/compositor/layer_animator.h" | 5 #include "ui/compositor/layer_animator.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/animation/animation_id_provider.h" | 10 #include "cc/animation/animation_id_provider.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 base::TimeDelta LayerAnimator::GetTransitionDuration() const { | 108 base::TimeDelta LayerAnimator::GetTransitionDuration() const { |
| 109 return transition_duration_; | 109 return transition_duration_; |
| 110 } | 110 } |
| 111 | 111 |
| 112 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { | 112 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
| 113 if (delegate_ && is_started_) { | 113 if (delegate_ && is_started_) { |
| 114 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 114 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 115 if (collection) | 115 if (collection) |
| 116 collection->StopAnimator(this); | 116 collection->StopAnimator(this); |
| 117 } | 117 } |
| 118 SwitchToLayer(delegate ? delegate->GetCcLayer() : nullptr); |
| 118 delegate_ = delegate; | 119 delegate_ = delegate; |
| 119 if (delegate_ && is_started_) { | 120 if (delegate_ && is_started_) { |
| 120 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); | 121 LayerAnimatorCollection* collection = GetLayerAnimatorCollection(); |
| 121 if (collection) | 122 if (collection) |
| 122 collection->StartAnimator(this); | 123 collection->StartAnimator(this); |
| 123 } | 124 } |
| 124 } | 125 } |
| 125 | 126 |
| 127 void LayerAnimator::SwitchToLayer(scoped_refptr<cc::Layer> new_layer) { |
| 128 if (delegate_) { |
| 129 DCHECK(delegate_->GetCcLayer()); |
| 130 delegate_->GetCcLayer()->RemoveLayerAnimationEventObserver(this); |
| 131 } |
| 132 if (new_layer) |
| 133 new_layer->AddLayerAnimationEventObserver(this); |
| 134 } |
| 135 |
| 126 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { | 136 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
| 127 scoped_refptr<LayerAnimator> retain(this); | 137 scoped_refptr<LayerAnimator> retain(this); |
| 128 OnScheduled(animation); | 138 OnScheduled(animation); |
| 129 if (!StartSequenceImmediately(animation)) { | 139 if (!StartSequenceImmediately(animation)) { |
| 130 // Attempt to preempt a running animation. | 140 // Attempt to preempt a running animation. |
| 131 switch (preemption_strategy_) { | 141 switch (preemption_strategy_) { |
| 132 case IMMEDIATELY_SET_NEW_TARGET: | 142 case IMMEDIATELY_SET_NEW_TARGET: |
| 133 ImmediatelySetNewTarget(animation); | 143 ImmediatelySetNewTarget(animation); |
| 134 break; | 144 break; |
| 135 case IMMEDIATELY_ANIMATE_TO_NEW_TARGET: | 145 case IMMEDIATELY_ANIMATE_TO_NEW_TARGET: |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 running_animations_.erase(running_animations_.begin() + i); | 853 running_animations_.erase(running_animations_.begin() + i); |
| 844 else | 854 else |
| 845 i++; | 855 i++; |
| 846 } | 856 } |
| 847 } | 857 } |
| 848 | 858 |
| 849 LayerAnimatorCollection* LayerAnimator::GetLayerAnimatorCollection() { | 859 LayerAnimatorCollection* LayerAnimator::GetLayerAnimatorCollection() { |
| 850 return delegate_ ? delegate_->GetLayerAnimatorCollection() : NULL; | 860 return delegate_ ? delegate_->GetLayerAnimatorCollection() : NULL; |
| 851 } | 861 } |
| 852 | 862 |
| 863 void LayerAnimator::OnAnimationStarted(const cc::AnimationEvent& event) { |
| 864 OnThreadedAnimationStarted(event); |
| 865 } |
| 866 |
| 853 LayerAnimator::RunningAnimation::RunningAnimation( | 867 LayerAnimator::RunningAnimation::RunningAnimation( |
| 854 const base::WeakPtr<LayerAnimationSequence>& sequence) | 868 const base::WeakPtr<LayerAnimationSequence>& sequence) |
| 855 : sequence_(sequence) { | 869 : sequence_(sequence) { |
| 856 } | 870 } |
| 857 | 871 |
| 858 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 872 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 859 | 873 |
| 860 } // namespace ui | 874 } // namespace ui |
| OLD | NEW |