File: hotseat_transition_animator.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (93 lines) | stat: -rw-r--r-- 3,408 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SHELF_HOTSEAT_TRANSITION_ANIMATOR_H_
#define ASH_SHELF_HOTSEAT_TRANSITION_ANIMATOR_H_

#include "ash/ash_export.h"
#include "ash/public/cpp/shelf_types.h"
#include "base/functional/callback.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "base/observer_list_types.h"
#include "ui/compositor/layer_animation_observer.h"

namespace ash {
class ShelfWidget;

// Makes it appear that the background of the shelf and hotseat animate to/from
// one another.
class ASH_EXPORT HotseatTransitionAnimator
    : public ui::ImplicitAnimationObserver {
 public:
  class TestObserver {
   public:
    virtual ~TestObserver() = default;
    virtual void OnTransitionTestAnimationEnded() = 0;
  };

  class Observer : public base::CheckedObserver {
   public:
    // Called before hotseat transition animations begin.
    virtual void OnHotseatTransitionAnimationWillStart(HotseatState from_state,
                                                       HotseatState to_start) {}
    // Called when hotseat transition animations end.
    virtual void OnHotseatTransitionAnimationEnded(HotseatState from_state,
                                                   HotseatState to_start) {}
    // Called when hotseat transition animations was aborted.
    virtual void OnHotseatTransitionAnimationAborted() {}
  };

  explicit HotseatTransitionAnimator(ShelfWidget* shelf_widget);
  ~HotseatTransitionAnimator() override;

  // Called when the hotseat state changes.
  void OnHotseatStateChanged(HotseatState old_state, HotseatState new_state);

  void AddObserver(Observer* observer);
  void RemoveObserver(Observer* observer);

  // ui::ImplicitAnimationObserver:
  void OnImplicitAnimationsCompleted() override;
  void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override;

  // Enables or enables animations. Disabling the animations will stop in-flight
  // animations.
  void SetAnimationsEnabledInSessionState(bool enabled);

  // Set the test observer to watch for animations completed.
  void SetTestObserver(TestObserver* test_observer);

 private:
  // Starts the animation between |old_state| and |target_state|.
  void DoAnimation(HotseatState old_state, HotseatState new_state);

  // Whether an animation should occur between |old_state| and |new_state|.
  bool ShouldDoAnimation(HotseatState old_state, HotseatState new_state);

  // Notifies observers of animation completion.
  void NotifyHotseatTransitionAnimationEnded(HotseatState old_state,
                                             HotseatState new_state);

  // The widget which owns the HotseatWidget. Owned by Shelf.
  const raw_ptr<ShelfWidget> shelf_widget_;

  // Whether hotseat animations should be animated for the current session
  // state.
  bool animations_enabled_for_current_session_state_ = false;

  // Callback used to notify observers of animation completion.
  base::OnceClosure animation_complete_callback_;

  base::ObserverList<Observer> observers_;

  // A test observer used to wait for the hotseat transition animation.
  raw_ptr<TestObserver> test_observer_ = nullptr;

  base::WeakPtrFactory<HotseatTransitionAnimator> weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_SHELF_HOTSEAT_TRANSITION_ANIMATOR_H_