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/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" |
(...skipping 27 matching lines...) Expand all Loading... |
38 disable_timer_for_test_(false) { | 38 disable_timer_for_test_(false) { |
39 } | 39 } |
40 | 40 |
41 LayerAnimator::~LayerAnimator() { | 41 LayerAnimator::~LayerAnimator() { |
42 for (size_t i = 0; i < running_animations_.size(); ++i) | 42 for (size_t i = 0; i < running_animations_.size(); ++i) |
43 running_animations_[i].sequence->OnAnimatorDestroyed(); | 43 running_animations_[i].sequence->OnAnimatorDestroyed(); |
44 ClearAnimations(); | 44 ClearAnimations(); |
45 } | 45 } |
46 | 46 |
47 // static | 47 // static |
48 bool LayerAnimator::disable_animations_for_test_ = false; | |
49 | |
50 // static | |
51 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { | 48 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { |
52 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); | 49 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); |
53 } | 50 } |
54 | 51 |
55 // static | 52 // static |
56 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { | 53 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { |
57 return new LayerAnimator(kDefaultTransitionDuration); | 54 return new LayerAnimator(kDefaultTransitionDuration); |
58 } | 55 } |
59 | 56 |
60 void LayerAnimator::SetTransform(const Transform& transform) { | 57 void LayerAnimator::SetTransform(const Transform& transform) { |
61 base::TimeDelta duration = transition_duration_; | |
62 if (disable_animations_for_test_) | |
63 duration = base::TimeDelta(); | |
64 StartAnimation(new LayerAnimationSequence( | 58 StartAnimation(new LayerAnimationSequence( |
65 LayerAnimationElement::CreateTransformElement( | 59 LayerAnimationElement::CreateTransformElement( |
66 transform, duration))); | 60 transform, transition_duration_))); |
67 } | 61 } |
68 | 62 |
69 Transform LayerAnimator::GetTargetTransform() const { | 63 Transform LayerAnimator::GetTargetTransform() const { |
70 LayerAnimationElement::TargetValue target(delegate()); | 64 LayerAnimationElement::TargetValue target(delegate()); |
71 GetTargetValue(&target); | 65 GetTargetValue(&target); |
72 return target.transform; | 66 return target.transform; |
73 } | 67 } |
74 | 68 |
75 void LayerAnimator::SetBounds(const gfx::Rect& bounds) { | 69 void LayerAnimator::SetBounds(const gfx::Rect& bounds) { |
76 base::TimeDelta duration = transition_duration_; | |
77 if (disable_animations_for_test_) | |
78 duration = base::TimeDelta(); | |
79 StartAnimation(new LayerAnimationSequence( | 70 StartAnimation(new LayerAnimationSequence( |
80 LayerAnimationElement::CreateBoundsElement( | 71 LayerAnimationElement::CreateBoundsElement( |
81 bounds, duration))); | 72 bounds, transition_duration_))); |
82 } | 73 } |
83 | 74 |
84 gfx::Rect LayerAnimator::GetTargetBounds() const { | 75 gfx::Rect LayerAnimator::GetTargetBounds() const { |
85 LayerAnimationElement::TargetValue target(delegate()); | 76 LayerAnimationElement::TargetValue target(delegate()); |
86 GetTargetValue(&target); | 77 GetTargetValue(&target); |
87 return target.bounds; | 78 return target.bounds; |
88 } | 79 } |
89 | 80 |
90 void LayerAnimator::SetOpacity(float opacity) { | 81 void LayerAnimator::SetOpacity(float opacity) { |
91 base::TimeDelta duration = transition_duration_; | |
92 if (disable_animations_for_test_) | |
93 duration = base::TimeDelta(); | |
94 StartAnimation(new LayerAnimationSequence( | 82 StartAnimation(new LayerAnimationSequence( |
95 LayerAnimationElement::CreateOpacityElement( | 83 LayerAnimationElement::CreateOpacityElement( |
96 opacity, duration))); | 84 opacity, transition_duration_))); |
97 } | 85 } |
98 | 86 |
99 float LayerAnimator::GetTargetOpacity() const { | 87 float LayerAnimator::GetTargetOpacity() const { |
100 LayerAnimationElement::TargetValue target(delegate()); | 88 LayerAnimationElement::TargetValue target(delegate()); |
101 GetTargetValue(&target); | 89 GetTargetValue(&target); |
102 return target.opacity; | 90 return target.opacity; |
103 } | 91 } |
104 | 92 |
105 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { | 93 void LayerAnimator::SetDelegate(LayerAnimationDelegate* delegate) { |
106 DCHECK(delegate); | 94 DCHECK(delegate); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); | 511 ObserverListBase<LayerAnimationObserver>::Iterator it(observers_); |
524 LayerAnimationObserver* obs; | 512 LayerAnimationObserver* obs; |
525 while ((obs = it.GetNext()) != NULL) { | 513 while ((obs = it.GetNext()) != NULL) { |
526 sequence->AddObserver(obs); | 514 sequence->AddObserver(obs); |
527 } | 515 } |
528 } | 516 } |
529 sequence->OnScheduled(); | 517 sequence->OnScheduled(); |
530 } | 518 } |
531 | 519 |
532 } // namespace ui | 520 } // namespace ui |
OLD | NEW |