multi_layer_animator_test_controller.cc 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright 2016 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "ui/compositor/test/multi_layer_animator_test_controller.h"
  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"
  9. #include "ui/compositor/test/multi_layer_animator_test_controller_delegate.h"
  10. namespace ui {
  11. namespace test {
  12. MultiLayerAnimatorTestController::MultiLayerAnimatorTestController(
  13. MultiLayerAnimatorTestControllerDelegate* delegate)
  14. : delegate_(delegate) {}
  15. MultiLayerAnimatorTestController::~MultiLayerAnimatorTestController() {}
  16. void MultiLayerAnimatorTestController::SetDisableAnimationTimers(
  17. bool disable_timers) {
  18. for (LayerAnimator* animator : GetLayerAnimators())
  19. animator->set_disable_timer_for_test(disable_timers);
  20. }
  21. bool MultiLayerAnimatorTestController::HasActiveAnimations() const {
  22. for (LayerAnimator* animator : GetLayerAnimators()) {
  23. if (animator->is_animating())
  24. return true;
  25. }
  26. return false;
  27. }
  28. void MultiLayerAnimatorTestController::CompleteAnimations() {
  29. while (HasActiveAnimations()) {
  30. // StepAnimations() will only progress the current running animations. Thus
  31. // each queued animation will require at least one 'Step' call and we cannot
  32. // just use a large duration here.
  33. StepAnimations(base::Milliseconds(20));
  34. }
  35. }
  36. std::vector<LayerAnimator*>
  37. MultiLayerAnimatorTestController::GetLayerAnimators() {
  38. return static_cast<const MultiLayerAnimatorTestController*>(this)
  39. ->GetLayerAnimators();
  40. }
  41. std::vector<LayerAnimator*>
  42. MultiLayerAnimatorTestController::GetLayerAnimators() const {
  43. return delegate_->GetLayerAnimators();
  44. }
  45. void MultiLayerAnimatorTestController::StepAnimations(
  46. const base::TimeDelta& duration) {
  47. for (ui::LayerAnimator* animator : GetLayerAnimators()) {
  48. LayerAnimatorTestController controller(animator);
  49. controller.StartThreadedAnimationsIfNeeded();
  50. controller.Step(duration);
  51. }
  52. }
  53. } // namespace test
  54. } // namespace ui