File: user_nudge_controller.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 (112 lines) | stat: -rw-r--r-- 3,982 bytes parent folder | download | duplicates (5)
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
// Copyright 2021 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_CAPTURE_MODE_USER_NUDGE_CONTROLLER_H_
#define ASH_CAPTURE_MODE_USER_NUDGE_CONTROLLER_H_

#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/scoped_observation.h"
#include "base/timer/timer.h"
#include "ui/compositor/layer.h"
#include "ui/views/widget/widget_observer.h"

namespace aura {
class Window;
}  // namespace aura

namespace views {
class View;
class Widget;
}  // namespace views

namespace ash {

class CaptureModeSession;

// Controls the user nudge animation and toast widget which are used to draw the
// user's attention towards the given `view_to_be_highlighted`. In the current
// iteration, this view is the partial button on the capture mode bar, and the
// desire is to inform users about the newly added sunfish feature.
class UserNudgeController : public views::WidgetObserver {
 public:
  UserNudgeController(CaptureModeSession* session,
                      views::View* view_to_be_highlighted);
  UserNudgeController(const UserNudgeController&) = delete;
  UserNudgeController& operator=(const UserNudgeController&) = delete;
  ~UserNudgeController() override;

  bool is_visible() const { return is_visible_; }
  void set_should_dismiss_nudge_forever(bool value) {
    should_dismiss_nudge_forever_ = value;
  }
  bool should_dismiss_nudge_forever() const {
    return should_dismiss_nudge_forever_;
  }

  // Repositions the animation layers such that they're correctly parented with
  // the correct bounds on the correct display.
  void Reposition();

  // Animates the animation layers towards the given visibility state `visible`.
  void SetVisible(bool visible);

  // views::WidgetObserver:
  void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override;

 private:
  // Triggers all the nudge animations performed by the below functions.
  void PerformNudgeAnimations();

  // Animates the base ring (which is a circle highlight around the
  // `view_to_be_highlighted_`) in a way that grabs the user's attention.
  void PerformBaseRingAnimation();

  // Animates the ripple ring (which is another circle highlight around the
  // `view_to_be_highlighted_` but animates to a bigger size while fading out).
  void PerformRippleRingAnimation();

  // Scales up the `view_to_be_highlighted_` itself so its icon appears to be
  // growing with the base ring animation.
  void PerformViewScaleAnimation();

  // Called back when the base ring animation finishes so that we can schedule
  // a repeat of this animation after a certain delay using `timer_`.
  void OnBaseRingAnimationEnded();

  // This is the window that will be used to as the parent of our animation
  // layers (`base_ring_` and `ripple_ring_`).
  aura::Window* GetParentWindow();

  // The session that owns `this`. Guaranteed to be non null for the lifetime of
  // `this`.
  const raw_ptr<CaptureModeSession> capture_session_;

  // The view to which we're trying to grab the user's attention.
  const raw_ptr<views::View> view_to_be_highlighted_;

  // These are the two animation layers that will be used to highlight
  // `view_to_be_highlighted_` to nudge the user towards it.
  ui::Layer base_ring_{ui::LAYER_SOLID_COLOR};
  ui::Layer ripple_ring_{ui::LAYER_SOLID_COLOR};

  // The timer used to repeat the nudge animation after a certain delay.
  base::OneShotTimer timer_;

  // The current visibility state of the nudge elements.
  bool is_visible_ = false;

  // If set to true, we will set a user pref to disable this nudge forever at
  // the time when `this` is destroyed.
  bool should_dismiss_nudge_forever_ = false;

  base::ScopedObservation<views::Widget, views::WidgetObserver>
      widget_observation_{this};

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

}  // namespace ash

#endif  // ASH_CAPTURE_MODE_USER_NUDGE_CONTROLLER_H_