File: ui_lock_controller.h

package info (click to toggle)
chromium 120.0.6099.224-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 6,112,112 kB
  • sloc: cpp: 32,907,025; ansic: 8,148,123; javascript: 3,679,536; python: 2,031,248; asm: 959,718; java: 804,675; xml: 617,256; sh: 111,417; objc: 100,835; perl: 88,443; cs: 53,032; makefile: 29,579; fortran: 24,137; php: 21,162; tcl: 21,147; sql: 20,809; ruby: 17,735; pascal: 12,864; yacc: 8,045; lisp: 3,388; lex: 1,323; ada: 727; awk: 329; jsp: 267; csh: 117; exp: 43; sed: 37
file content (122 lines) | stat: -rw-r--r-- 4,423 bytes parent folder | download
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
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_EXO_UI_LOCK_CONTROLLER_H_
#define COMPONENTS_EXO_UI_LOCK_CONTROLLER_H_

#include "ash/shell.h"
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "components/exo/seat_observer.h"
#include "components/exo/wm_helper.h"
#include "ui/base/user_activity/user_activity_observer.h"
#include "ui/events/event_handler.h"

class FullscreenControlPopup;

namespace exo {

class Pointer;
class Seat;

extern const base::TimeDelta kLongPressEscapeDuration;

// Helps users to break out of various kinds of "locks" that a window may hold
// (fullscreen, pointer lock).
//
// In some cases this is achieved by pressing and holding Escape, similar to
// Chromium's Keyboard Lock feature
// (see https://chromestatus.com/feature/5642959835889664). In other cases we
// nudge the user to use Overview.
class UILockController : public ui::EventHandler,
                         public SeatObserver,
                         public ash::SessionObserver,
                         public WMHelper::PowerObserver,
                         public ui::UserActivityObserver {
 public:
  // Interface for classes that display notifications based on UI lock states.
  class Notifier : public base::CheckedObserver {
   public:
    // Called when any UI-lock-related notifications must be shown again.
    //
    // If a state that normally shows a notification on entry is currently
    // active, show that notification again. Otherwise, reset any cooldowns
    // so that the notification will show next time.
    virtual void NotifyAgain() = 0;

    virtual void OnUILockControllerDestroying() = 0;
  };

  explicit UILockController(Seat* seat);
  UILockController(const UILockController&) = delete;
  UILockController& operator=(const UILockController&) = delete;
  ~UILockController() override;

  // Overridden from ui::EventHandler:
  void OnKeyEvent(ui::KeyEvent* event) override;

  // Overridden from WMHelper::PowerObserver:
  void SuspendDone() override;
  void ScreenBrightnessChanged(double percent) override;
  void LidEventReceived(bool opened) override;

  // Overridden from ash::SessionObserver:
  void OnLockStateChanged(bool locked) override;

  // Overridden from SeatObserver:
  void OnSurfaceFocused(Surface* gained_focus,
                        Surface* lost_focus,
                        bool has_focued_surface) override;
  void OnPointerCaptureEnabled(Pointer* pointer,
                               aura::Window* capture_window) override;
  void OnPointerCaptureDisabled(Pointer* pointer,
                                aura::Window* capture_window) override;

  // Overridden from ui::UserActivityObserver:
  void OnUserActivity(const ui::Event* event) override;

  views::Widget* GetEscNotificationForTesting(aura::Window* window);
  views::Widget* GetPointerCaptureNotificationForTesting(aura::Window* window);
  FullscreenControlPopup* GetExitPopupForTesting(aura::Window* window);

  void AddObserver(Notifier* notifier);
  void RemoveObserver(Notifier* notifier);

 private:
  void ReshowAllNotifications();

  void OnEscapeKey(bool pressed);
  void OnEscapeHeld();
  void StopTimer();

  raw_ptr<Seat, ExperimentalAsh> seat_;
  base::OneShotTimer exit_fullscreen_timer_;

  // Whether the screen brightness is low enough to make the display dark.
  bool device_in_dark_ = false;

  // The surface which was focused when |exit_fullscreen_timer_| started
  // running, or nullptr if the timer isn't running. Do not dereference; may
  // dangle if the Surface is destroyed while the timer is running. Valid only
  // for comparison purposes.
  raw_ptr<Surface, ExperimentalAsh> focused_surface_to_unlock_ = nullptr;

  // Pointers currently being captured.
  base::flat_set<raw_ptr<Pointer>> captured_pointers_;

  base::ObserverList<Notifier> notifiers_;

  // Time of last user-generated input event. Used to display notifications
  // again if the user goes idle and then becomes active again.
  //
  // Note TimeTicks may stand still if the device is suspended, but that's OK
  // because device suspend/resume events also retrigger notifications.
  base::TimeTicks last_activity_time_;
};

}  // namespace exo

#endif  // COMPONENTS_EXO_UI_LOCK_CONTROLLER_H_