OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/time/time.h" |
| 6 #include "ui/compositor/layer.h" |
| 7 #include "ui/compositor/layer_animator.h" |
| 8 #include "ui/compositor/test/layer_animator_test_controller.h" |
5 #include "ui/views/animation/ink_drop_animation.h" | 9 #include "ui/views/animation/ink_drop_animation.h" |
6 #include "ui/views/animation/test/ink_drop_animation_test_api.h" | 10 #include "ui/views/animation/test/ink_drop_animation_test_api.h" |
7 | 11 |
8 namespace views { | 12 namespace views { |
9 namespace test { | 13 namespace test { |
10 | 14 |
11 InkDropAnimationTestApi::InkDropAnimationTestApi( | 15 InkDropAnimationTestApi::InkDropAnimationTestApi( |
12 InkDropAnimation* ink_drop_animation) | 16 InkDropAnimation* ink_drop_animation) |
13 : ink_drop_animation_(ink_drop_animation) {} | 17 : ink_drop_animation_(ink_drop_animation) {} |
14 | 18 |
15 InkDropAnimationTestApi::~InkDropAnimationTestApi() {} | 19 InkDropAnimationTestApi::~InkDropAnimationTestApi() {} |
16 | 20 |
| 21 void InkDropAnimationTestApi::SetDisableAnimationTimers(bool disable_timers) { |
| 22 for (ui::LayerAnimator* animator : GetLayerAnimators()) |
| 23 animator->set_disable_timer_for_test(disable_timers); |
| 24 } |
| 25 |
| 26 bool InkDropAnimationTestApi::HasActiveAnimations() const { |
| 27 for (ui::LayerAnimator* animator : GetLayerAnimators()) { |
| 28 if (animator->is_animating()) |
| 29 return true; |
| 30 } |
| 31 return false; |
| 32 } |
| 33 |
| 34 void InkDropAnimationTestApi::CompleteAnimations() { |
| 35 while (HasActiveAnimations()) { |
| 36 // StepAnimations() will only progress the current running animations. Thus |
| 37 // each queued animation will require at least one 'Step' call and we cannot |
| 38 // just use a large duration here. |
| 39 StepAnimations(base::TimeDelta::FromMilliseconds(20)); |
| 40 } |
| 41 } |
| 42 |
| 43 float InkDropAnimationTestApi::GetCurrentOpacity() const { |
| 44 return ink_drop_animation_->GetCurrentOpacity(); |
| 45 } |
| 46 |
17 void InkDropAnimationTestApi::CalculateCircleTransforms( | 47 void InkDropAnimationTestApi::CalculateCircleTransforms( |
18 const gfx::Size& size, | 48 const gfx::Size& size, |
19 InkDropTransforms* transforms_out) const { | 49 InkDropTransforms* transforms_out) const { |
20 ink_drop_animation_->CalculateCircleTransforms(size, transforms_out); | 50 ink_drop_animation_->CalculateCircleTransforms(size, transforms_out); |
21 } | 51 } |
22 void InkDropAnimationTestApi::CalculateRectTransforms( | 52 void InkDropAnimationTestApi::CalculateRectTransforms( |
23 const gfx::Size& size, | 53 const gfx::Size& size, |
24 float corner_radius, | 54 float corner_radius, |
25 InkDropTransforms* transforms_out) const { | 55 InkDropTransforms* transforms_out) const { |
26 ink_drop_animation_->CalculateRectTransforms(size, corner_radius, | 56 ink_drop_animation_->CalculateRectTransforms(size, corner_radius, |
27 transforms_out); | 57 transforms_out); |
28 } | 58 } |
29 | 59 |
| 60 void InkDropAnimationTestApi::StepAnimations(const base::TimeDelta& duration) { |
| 61 for (ui::LayerAnimator* animator : GetLayerAnimators()) { |
| 62 ui::LayerAnimatorTestController controller(animator); |
| 63 controller.StartThreadedAnimationsIfNeeded(); |
| 64 controller.Step(duration); |
| 65 } |
| 66 } |
| 67 |
| 68 std::vector<ui::LayerAnimator*> InkDropAnimationTestApi::GetLayerAnimators() { |
| 69 return static_cast<const InkDropAnimationTestApi*>(this)->GetLayerAnimators(); |
| 70 } |
| 71 |
| 72 std::vector<ui::LayerAnimator*> InkDropAnimationTestApi::GetLayerAnimators() |
| 73 const { |
| 74 std::vector<ui::LayerAnimator*> animators; |
| 75 animators.push_back(ink_drop_animation_->root_layer_->GetAnimator()); |
| 76 for (int i = 0; i < InkDropAnimation::PAINTED_SHAPE_COUNT; ++i) |
| 77 animators.push_back(ink_drop_animation_->painted_layers_[i]->GetAnimator()); |
| 78 return animators; |
| 79 } |
| 80 |
30 } // namespace test | 81 } // namespace test |
31 } // namespace views | 82 } // namespace views |
OLD | NEW |