File: progress_indicator_animation_registry.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 (126 lines) | stat: -rw-r--r-- 5,482 bytes parent folder | download | duplicates (7)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// Copyright 2022 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_SYSTEM_PROGRESS_INDICATOR_PROGRESS_INDICATOR_ANIMATION_REGISTRY_H_
#define ASH_SYSTEM_PROGRESS_INDICATOR_PROGRESS_INDICATOR_ANIMATION_REGISTRY_H_

#include <map>
#include <memory>

#include "ash/ash_export.h"
#include "ash/system/progress_indicator/progress_icon_animation.h"
#include "ash/system/progress_indicator/progress_ring_animation.h"
#include "base/callback_list.h"
#include "base/functional/callback_forward.h"
#include "base/functional/function_ref.h"

namespace ash {

// A registry for progress indicator animations.
//
// Since animations are owned by the registry, they can be shared across
// different UI components as well have a lifetime which is decoupled from UI
// component lifetime.
//
// Supported animation types:
//   * Progress icon animation - independently drive the animation of properties
//     for a progress indicator's inner icon, as opposed to progress ring
//     animations which independently drive the animation of properties for a
//     progress indicator's outer ring.
//   * Progress ring animation - independently drive the animation of properties
//     for a progress indicator's outer ring, as opposed to progress icon
//     animations which independently drive the animation of properties for a
//     progress indicator's inner icon.
class ASH_EXPORT ProgressIndicatorAnimationRegistry {
 public:
  ProgressIndicatorAnimationRegistry();
  ProgressIndicatorAnimationRegistry(
      const ProgressIndicatorAnimationRegistry&) = delete;
  ProgressIndicatorAnimationRegistry& operator=(
      const ProgressIndicatorAnimationRegistry&) = delete;
  ~ProgressIndicatorAnimationRegistry();

  using AnimationKey = intptr_t;

  // Returns the specified `ptr` as an animation key.
  static AnimationKey AsAnimationKey(const void* ptr);

  using ProgressIconAnimationChangedCallbackList =
      base::RepeatingCallbackList<void(ProgressIconAnimation*)>;

  // Adds the specified `callback` to be notified of changes to the progress
  // icon animation associated with the specified `key`. The `callback` will
  // continue to receive events so long as both `this` and the returned
  // subscription exist.
  base::CallbackListSubscription AddProgressIconAnimationChangedCallbackForKey(
      AnimationKey key,
      ProgressIconAnimationChangedCallbackList::CallbackType callback);

  using ProgressRingAnimationChangedCallbackList =
      base::RepeatingCallbackList<void(ProgressRingAnimation*)>;

  // Adds the specified `callback` to be notified of changes to the progress
  // ring animation associated with the specified `key`. The `callback` will
  // continue to receive events so long as both `this` and the returned
  // subscription exist.
  base::CallbackListSubscription AddProgressRingAnimationChangedCallbackForKey(
      AnimationKey key,
      ProgressRingAnimationChangedCallbackList::CallbackType callback);

  // Returns the progress icon animation registered for the specified `key`.
  // NOTE: This may return `nullptr` if no such animation is registered.
  ProgressIconAnimation* GetProgressIconAnimationForKey(AnimationKey key);

  // Returns the progress ring animation registered for the specified `key`.
  // NOTE: This may return `nullptr` if no such animation is registered.
  ProgressRingAnimation* GetProgressRingAnimationForKey(AnimationKey key);

  // Sets and returns the progress icon animation registered for the specified
  // `key`. NOTE: `animation` may be `nullptr` to unregister `key`.
  ProgressIconAnimation* SetProgressIconAnimationForKey(
      AnimationKey key,
      std::unique_ptr<ProgressIconAnimation> animation);

  // Sets and returns the progress ring animation registered for the specified
  // `key`. NOTE: `animation` may be `nullptr` to unregister `key`.
  ProgressRingAnimation* SetProgressRingAnimationForKey(
      AnimationKey key,
      std::unique_ptr<ProgressRingAnimation> animation);

  // Erases all animations for all keys.
  void EraseAllAnimations();

  // Erases all animations for the specified `key`.
  void EraseAllAnimationsForKey(AnimationKey key);

  // Erases all animations for all keys for which the specified `predicate`
  // returns `true`.
  void EraseAllAnimationsForKeyIf(
      base::FunctionRef<bool(AnimationKey key)> predicate);

 private:
  // Mapping of keys to their associated progress icon animations.
  std::map<AnimationKey, std::unique_ptr<ProgressIconAnimation>>
      icon_animations_by_key_;

  // Mapping of keys to their associated icon animation changed callback lists.
  // Whenever an animation for a given key is changed, the callback list for
  // that key will be notified.
  std::map<AnimationKey, ProgressIconAnimationChangedCallbackList>
      icon_animation_changed_callback_lists_by_key_;

  // Mapping of keys to their associated progress ring animations.
  std::map<AnimationKey, std::unique_ptr<ProgressRingAnimation>>
      ring_animations_by_key_;

  // Mapping of keys to their associated ring animation changed callback lists.
  // Whenever an animation for a given key is changed, the callback list for
  // that key will be notified.
  std::map<AnimationKey, ProgressRingAnimationChangedCallbackList>
      ring_animation_changed_callback_lists_by_key_;
};

}  // namespace ash

#endif  // ASH_SYSTEM_PROGRESS_INDICATOR_PROGRESS_INDICATOR_ANIMATION_REGISTRY_H_