OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gfx/compositor/layer_animator.h" | 5 #include "ui/gfx/compositor/layer_animator.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ui/base/animation/animation_container.h" | 10 #include "ui/base/animation/animation_container.h" |
11 #include "ui/gfx/compositor/compositor.h" | 11 #include "ui/gfx/compositor/compositor.h" |
| 12 #include "ui/gfx/compositor/dummy_layer_animation_delegate.h" |
12 #include "ui/gfx/compositor/layer.h" | 13 #include "ui/gfx/compositor/layer.h" |
13 #include "ui/gfx/compositor/layer_animation_delegate.h" | 14 #include "ui/gfx/compositor/layer_animation_delegate.h" |
14 #include "ui/gfx/compositor/layer_animation_sequence.h" | 15 #include "ui/gfx/compositor/layer_animation_sequence.h" |
15 | 16 |
16 namespace ui { | 17 namespace ui { |
17 | 18 |
18 class LayerAnimator; | 19 class LayerAnimator; |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 54 |
54 void LayerAnimator::SetTransform(const Transform& transform) { | 55 void LayerAnimator::SetTransform(const Transform& transform) { |
55 if (transition_duration_ == base::TimeDelta()) | 56 if (transition_duration_ == base::TimeDelta()) |
56 delegate_->SetTransformFromAnimation(transform); | 57 delegate_->SetTransformFromAnimation(transform); |
57 else | 58 else |
58 StartAnimation(new LayerAnimationSequence( | 59 StartAnimation(new LayerAnimationSequence( |
59 LayerAnimationElement::CreateTransformElement(transform, | 60 LayerAnimationElement::CreateTransformElement(transform, |
60 transition_duration_))); | 61 transition_duration_))); |
61 } | 62 } |
62 | 63 |
| 64 Transform LayerAnimator::GetTargetTransform() const { |
| 65 DummyLayerAnimationDelegate dummy(*delegate_); |
| 66 SetTarget(&dummy); |
| 67 return dummy.GetTransformForAnimation(); |
| 68 } |
| 69 |
63 void LayerAnimator::SetBounds(const gfx::Rect& bounds) { | 70 void LayerAnimator::SetBounds(const gfx::Rect& bounds) { |
64 if (transition_duration_ == base::TimeDelta()) | 71 if (transition_duration_ == base::TimeDelta()) |
65 delegate_->SetBoundsFromAnimation(bounds); | 72 delegate_->SetBoundsFromAnimation(bounds); |
66 else | 73 else |
67 StartAnimation(new LayerAnimationSequence( | 74 StartAnimation(new LayerAnimationSequence( |
68 LayerAnimationElement::CreateBoundsElement(bounds, | 75 LayerAnimationElement::CreateBoundsElement(bounds, |
69 transition_duration_))); | 76 transition_duration_))); |
70 } | 77 } |
71 | 78 |
| 79 gfx::Rect LayerAnimator::GetTargetBounds() const { |
| 80 DummyLayerAnimationDelegate dummy(*delegate_); |
| 81 SetTarget(&dummy); |
| 82 return dummy.GetBoundsForAnimation(); |
| 83 } |
| 84 |
72 void LayerAnimator::SetOpacity(float opacity) { | 85 void LayerAnimator::SetOpacity(float opacity) { |
73 if (transition_duration_ == base::TimeDelta()) | 86 if (transition_duration_ == base::TimeDelta()) |
74 delegate_->SetOpacityFromAnimation(opacity); | 87 delegate_->SetOpacityFromAnimation(opacity); |
75 else | 88 else |
76 StartAnimation(new LayerAnimationSequence( | 89 StartAnimation(new LayerAnimationSequence( |
77 LayerAnimationElement::CreateOpacityElement(opacity, | 90 LayerAnimationElement::CreateOpacityElement(opacity, |
78 transition_duration_))); | 91 transition_duration_))); |
79 } | 92 } |
80 | 93 |
| 94 float LayerAnimator::GetTargetOpacity() const { |
| 95 DummyLayerAnimationDelegate dummy(*delegate_); |
| 96 SetTarget(&dummy); |
| 97 return dummy.GetOpacityForAnimation(); |
| 98 } |
| 99 |
81 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { | 100 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
82 DCHECK(delegate); | 101 DCHECK(delegate); |
83 delegate_ = delegate; | 102 delegate_ = delegate; |
84 } | 103 } |
85 | 104 |
86 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { | 105 void LayerAnimator::StartAnimation(LayerAnimationSequence* animation) { |
87 if (!StartSequenceImmediately(animation)) { | 106 if (!StartSequenceImmediately(animation)) { |
88 // Attempt to preempt a running animation. | 107 // Attempt to preempt a running animation. |
89 switch (preemption_strategy_) { | 108 switch (preemption_strategy_) { |
90 case IMMEDIATELY_SET_NEW_TARGET: | 109 case IMMEDIATELY_SET_NEW_TARGET: |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 452 |
434 // Need to keep a reference to the animation. | 453 // Need to keep a reference to the animation. |
435 AddToQueueIfNotPresent(sequence); | 454 AddToQueueIfNotPresent(sequence); |
436 | 455 |
437 // Ensure that animations get stepped at their start time. | 456 // Ensure that animations get stepped at their start time. |
438 Step(start_time); | 457 Step(start_time); |
439 | 458 |
440 return true; | 459 return true; |
441 } | 460 } |
442 | 461 |
| 462 void LayerAnimator::SetTarget(LayerAnimationDelegate* delegate) const { |
| 463 for (RunningAnimations::const_iterator iter = running_animations_.begin(); |
| 464 iter != running_animations_.end(); ++iter) { |
| 465 (*iter).sequence->SetTarget(delegate); |
| 466 } |
| 467 |
| 468 for (AnimationQueue::const_iterator iter = animation_queue_.begin(); |
| 469 iter != animation_queue_.end(); ++iter) { |
| 470 (*iter)->SetTarget(delegate); |
| 471 } |
| 472 } |
| 473 |
443 } // namespace ui | 474 } // namespace ui |
OLD | NEW |