scoped_animation_duration_scale_mode.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) 2013 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. #ifndef UI_COMPOSITOR_SCOPED_ANIMATION_DURATION_SCALE_MODE_H_
  5. #define UI_COMPOSITOR_SCOPED_ANIMATION_DURATION_SCALE_MODE_H_
  6. #include "ui/compositor/compositor_export.h"
  7. namespace ui {
  8. // Speed up or slow down animations for testing or debugging.
  9. class COMPOSITOR_EXPORT ScopedAnimationDurationScaleMode {
  10. public:
  11. // Anumation duration multipliers.
  12. static constexpr float NORMAL_DURATION = 1.0;
  13. static constexpr float FAST_DURATION = 1.0 / 4; // 4 times faster
  14. static constexpr float SLOW_DURATION = 1.0 * 4.0; // 4 times slower
  15. // A very short but guaranteed non-zero duration for individual tests that
  16. // need to assert things about animations after creating them.
  17. static constexpr float NON_ZERO_DURATION = 1.0 / 20; // 20 times faster
  18. // Animations complete immediately after being created. Used by most tests.
  19. static constexpr float ZERO_DURATION = 0;
  20. explicit ScopedAnimationDurationScaleMode(float scoped_multiplier);
  21. ScopedAnimationDurationScaleMode(const ScopedAnimationDurationScaleMode&) =
  22. delete;
  23. ScopedAnimationDurationScaleMode& operator=(
  24. const ScopedAnimationDurationScaleMode&) = delete;
  25. ~ScopedAnimationDurationScaleMode();
  26. static float duration_multiplier() { return duration_multiplier_; }
  27. static bool is_zero() { return duration_multiplier_ == ZERO_DURATION; }
  28. private:
  29. // This is stored previous multiplier version to restore after scoped scale
  30. // destruction.
  31. const float old_duration_multiplier_;
  32. // This is active global multiplier.
  33. static float duration_multiplier_;
  34. };
  35. } // namespace ui
  36. #endif // UI_COMPOSITOR_SCOPED_ANIMATION_DURATION_SCALE_MODE_H_