| 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/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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { | 79 LayerAnimator* LayerAnimator::CreateDefaultAnimator() { |
| 80 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); | 80 return new LayerAnimator(base::TimeDelta::FromMilliseconds(0)); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // static | 83 // static |
| 84 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { | 84 LayerAnimator* LayerAnimator::CreateImplicitAnimator() { |
| 85 return new LayerAnimator( | 85 return new LayerAnimator( |
| 86 base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)); | 86 base::TimeDelta::FromMilliseconds(kDefaultTransitionDurationMs)); |
| 87 } | 87 } |
| 88 | 88 |
| 89 // static |
| 90 scoped_ptr<test::AnimationContainerTestHelper> |
| 91 LayerAnimator::CreateAnimatorHelperForTest() { |
| 92 scoped_ptr<test::AnimationContainerTestHelper> result; |
| 93 result.reset(new test::AnimationContainerTestHelper(GetAnimationContainer())); |
| 94 return result.Pass(); |
| 95 } |
| 96 |
| 89 // This macro provides the implementation for the setter and getter (well, | 97 // This macro provides the implementation for the setter and getter (well, |
| 90 // the getter of the target value) for an animated property. For example, | 98 // the getter of the target value) for an animated property. For example, |
| 91 // it is used for the implementations of SetTransform and GetTargetTransform. | 99 // it is used for the implementations of SetTransform and GetTargetTransform. |
| 92 // It is worth noting that SetFoo avoids invoking the usual animation machinery | 100 // It is worth noting that SetFoo avoids invoking the usual animation machinery |
| 93 // if the transition duration is zero -- in this case we just set the property | 101 // if the transition duration is zero -- in this case we just set the property |
| 94 // on the layer animation delegate immediately. | 102 // on the layer animation delegate immediately. |
| 95 #define ANIMATED_PROPERTY(type, property, name, member_type, member) \ | 103 #define ANIMATED_PROPERTY(type, property, name, member_type, member) \ |
| 96 void LayerAnimator::Set##name(type value) { \ | 104 void LayerAnimator::Set##name(type value) { \ |
| 97 base::TimeDelta duration = GetTransitionDuration(); \ | 105 base::TimeDelta duration = GetTransitionDuration(); \ |
| 98 if (duration == base::TimeDelta() && delegate() && \ | 106 if (duration == base::TimeDelta() && delegate() && \ |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 StartAnimation(*iter); | 184 StartAnimation(*iter); |
| 177 } | 185 } |
| 178 return; | 186 return; |
| 179 } | 187 } |
| 180 | 188 |
| 181 adding_animations_ = true; | 189 adding_animations_ = true; |
| 182 if (!is_animating()) { | 190 if (!is_animating()) { |
| 183 if (GetAnimationContainer()->is_running()) | 191 if (GetAnimationContainer()->is_running()) |
| 184 last_step_time_ = GetAnimationContainer()->last_tick_time(); | 192 last_step_time_ = GetAnimationContainer()->last_tick_time(); |
| 185 else | 193 else |
| 186 last_step_time_ = base::TimeTicks::Now(); | 194 last_step_time_ = GetAnimationContainer()->GetCurrentTime(); |
| 187 } | 195 } |
| 188 | 196 |
| 189 // Collect all the affected properties. | 197 // Collect all the affected properties. |
| 190 LayerAnimationElement::AnimatableProperties animated_properties; | 198 LayerAnimationElement::AnimatableProperties animated_properties; |
| 191 std::vector<LayerAnimationSequence*>::const_iterator iter; | 199 std::vector<LayerAnimationSequence*>::const_iterator iter; |
| 192 for (iter = animations.begin(); iter != animations.end(); ++iter) { | 200 for (iter = animations.begin(); iter != animations.end(); ++iter) { |
| 193 animated_properties.insert((*iter)->properties().begin(), | 201 animated_properties.insert((*iter)->properties().begin(), |
| 194 (*iter)->properties().end()); | 202 (*iter)->properties().end()); |
| 195 } | 203 } |
| 196 | 204 |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 // internally). | 679 // internally). |
| 672 // All LayerAnimators share the same AnimationContainer. Use the | 680 // All LayerAnimators share the same AnimationContainer. Use the |
| 673 // last_tick_time() from there to ensure animations started during the same | 681 // last_tick_time() from there to ensure animations started during the same |
| 674 // event complete at the same time. | 682 // event complete at the same time. |
| 675 base::TimeTicks start_time; | 683 base::TimeTicks start_time; |
| 676 if (is_animating() || adding_animations_) | 684 if (is_animating() || adding_animations_) |
| 677 start_time = last_step_time_; | 685 start_time = last_step_time_; |
| 678 else if (GetAnimationContainer()->is_running()) | 686 else if (GetAnimationContainer()->is_running()) |
| 679 start_time = GetAnimationContainer()->last_tick_time(); | 687 start_time = GetAnimationContainer()->last_tick_time(); |
| 680 else | 688 else |
| 681 start_time = base::TimeTicks::Now(); | 689 start_time = GetAnimationContainer()->GetCurrentTime(); |
| 682 | 690 |
| 683 running_animations_.push_back( | 691 running_animations_.push_back( |
| 684 RunningAnimation(sequence->AsWeakPtr(), start_time)); | 692 RunningAnimation(sequence->AsWeakPtr(), start_time)); |
| 685 | 693 |
| 686 // Need to keep a reference to the animation. | 694 // Need to keep a reference to the animation. |
| 687 AddToQueueIfNotPresent(sequence); | 695 AddToQueueIfNotPresent(sequence); |
| 688 | 696 |
| 689 // Ensure that animations get stepped at their start time. | 697 // Ensure that animations get stepped at their start time. |
| 690 Step(start_time); | 698 Step(start_time); |
| 691 | 699 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 LayerAnimator::RunningAnimation::RunningAnimation( | 757 LayerAnimator::RunningAnimation::RunningAnimation( |
| 750 const base::WeakPtr<LayerAnimationSequence>& sequence, | 758 const base::WeakPtr<LayerAnimationSequence>& sequence, |
| 751 base::TimeTicks start_time) | 759 base::TimeTicks start_time) |
| 752 : sequence_(sequence), | 760 : sequence_(sequence), |
| 753 start_time_(start_time) { | 761 start_time_(start_time) { |
| 754 } | 762 } |
| 755 | 763 |
| 756 LayerAnimator::RunningAnimation::~RunningAnimation() { } | 764 LayerAnimator::RunningAnimation::~RunningAnimation() { } |
| 757 | 765 |
| 758 } // namespace ui | 766 } // namespace ui |
| OLD | NEW |