hotseat_transition_animator.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. // Copyright 2019 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 ASH_SHELF_HOTSEAT_TRANSITION_ANIMATOR_H_
  5. #define ASH_SHELF_HOTSEAT_TRANSITION_ANIMATOR_H_
  6. #include "ash/ash_export.h"
  7. #include "ash/public/cpp/shelf_types.h"
  8. #include "base/callback.h"
  9. #include "base/observer_list.h"
  10. #include "base/observer_list_types.h"
  11. #include "ui/compositor/layer_animation_observer.h"
  12. namespace ash {
  13. class ShelfWidget;
  14. // Makes it appear that the background of the shelf and hotseat animate to/from
  15. // one another.
  16. class ASH_EXPORT HotseatTransitionAnimator
  17. : public ui::ImplicitAnimationObserver {
  18. public:
  19. class TestObserver {
  20. public:
  21. virtual ~TestObserver() = default;
  22. virtual void OnTransitionTestAnimationEnded() = 0;
  23. };
  24. class Observer : public base::CheckedObserver {
  25. public:
  26. // Called before hotseat transition animations begin.
  27. virtual void OnHotseatTransitionAnimationWillStart(HotseatState from_state,
  28. HotseatState to_start) {}
  29. // Called when hotseat transition animations end.
  30. virtual void OnHotseatTransitionAnimationEnded(HotseatState from_state,
  31. HotseatState to_start) {}
  32. // Called when hotseat transition animations was aborted.
  33. virtual void OnHotseatTransitionAnimationAborted() {}
  34. };
  35. explicit HotseatTransitionAnimator(ShelfWidget* shelf_widget);
  36. ~HotseatTransitionAnimator() override;
  37. // Called when the hotseat state changes.
  38. void OnHotseatStateChanged(HotseatState old_state, HotseatState new_state);
  39. void AddObserver(Observer* observer);
  40. void RemoveObserver(Observer* observer);
  41. // ui::ImplicitAnimationObserver:
  42. void OnImplicitAnimationsCompleted() override;
  43. void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;
  44. // Enables or enables animations. Disabling the animations will stop in-flight
  45. // animations.
  46. void SetAnimationsEnabledInSessionState(bool enabled);
  47. // Set the test observer to watch for animations completed.
  48. void SetTestObserver(TestObserver* test_observer);
  49. private:
  50. // Starts the animation between |old_state| and |target_state|.
  51. void DoAnimation(HotseatState old_state, HotseatState new_state);
  52. // Whether an animation should occur between |old_state| and |new_state|.
  53. bool ShouldDoAnimation(HotseatState old_state, HotseatState new_state);
  54. // Notifies observers of animation completion.
  55. void NotifyHotseatTransitionAnimationEnded(HotseatState old_state,
  56. HotseatState new_state);
  57. // The widget which owns the HotseatWidget. Owned by Shelf.
  58. ShelfWidget* const shelf_widget_;
  59. // Whether hotseat animations should be animated for the current session
  60. // state.
  61. bool animations_enabled_for_current_session_state_ = false;
  62. // Callback used to notify observers of animation completion.
  63. base::OnceClosure animation_complete_callback_;
  64. base::ObserverList<Observer> observers_;
  65. // A test observer used to wait for the hotseat transition animation.
  66. TestObserver* test_observer_ = nullptr;
  67. base::WeakPtrFactory<HotseatTransitionAnimator> weak_ptr_factory_{this};
  68. };
  69. } // namespace ash
  70. #endif // ASH_SHELF_HOTSEAT_TRANSITION_ANIMATOR_H_