File: unified_system_tray_bubble.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 (170 lines) | stat: -rw-r--r-- 5,876 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
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
// Copyright 2018 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_UNIFIED_UNIFIED_SYSTEM_TRAY_BUBBLE_H_
#define ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_BUBBLE_H_

#include <memory>
#include <optional>

#include "ash/public/cpp/keyboard/keyboard_controller_observer.h"
#include "ash/public/cpp/tablet_mode_observer.h"
#include "ash/shelf/shelf_observer.h"
#include "ash/system/screen_layout_observer.h"
#include "ash/system/time/calendar_metrics.h"
#include "ash/system/tray/time_to_click_recorder.h"
#include "ash/system/tray/tray_bubble_base.h"
#include "ash/system/unified/quick_settings_view.h"
#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/widget/widget_observer.h"

namespace ui {
class Event;
}  // namespace ui

namespace views {
class Widget;
}  // namespace views

namespace ash {

class TrayEventFilter;
class UnifiedSystemTray;
class UnifiedSystemTrayController;
class QuickSettingsView;

// Manages the bubble that contains 'QuickSettingsView'.
// Shows the bubble on the constructor, and closes the bubble on the destructor.
// It is possible that the bubble widget is closed on deactivation. In such
// case, this class calls UnifiedSystemTray::CloseBubble() to delete itself.
class ASH_EXPORT UnifiedSystemTrayBubble : public TrayBubbleBase,
                                           public ScreenLayoutObserver,
                                           public ShelfObserver,
                                           public TimeToClickRecorder::Delegate,
                                           public KeyboardControllerObserver,
                                           public TabletModeObserver {
 public:
  explicit UnifiedSystemTrayBubble(UnifiedSystemTray* tray);

  UnifiedSystemTrayBubble(const UnifiedSystemTrayBubble&) = delete;
  UnifiedSystemTrayBubble& operator=(const UnifiedSystemTrayBubble&) = delete;

  ~UnifiedSystemTrayBubble() override;

  // Add observers that can delete `this`. This needs to be done separately
  // after `UnifiedSystemTrayBubble` and `UnifiedMessageCenterBubble` have been
  // completely constructed to prevent crashes. (crbug/1310675)
  void InitializeObservers();

  // Return the bounds of the bubble in the screen.
  gfx::Rect GetBoundsInScreen() const;

  // True if the bubble is active.
  bool IsBubbleActive() const;

  // Show audio settings detailed view.
  void ShowAudioDetailedView();

  // Show display settings detailed view.
  void ShowDisplayDetailedView();

  // Show calendar view.
  void ShowCalendarView(calendar_metrics::CalendarViewShowSource show_source,
                        calendar_metrics::CalendarEventSource event_source);

  // Show network settings detailed view.
  void ShowNetworkDetailedView();

  // Update bubble bounds and focus if necessary.
  void UpdateBubble();

  // Return the current visible height of the tray, even when partially
  // collapsed / expanded.
  int GetCurrentTrayHeight() const;

  // Fire a notification that an accessibility event has occured on this object.
  void NotifyAccessibilityEventDeprecated(ax::mojom::Event event,
                                          bool send_native_event);

  // Whether the bubble is currently showing audio details or display details or
  // calendar view.
  bool ShowingAudioDetailedView() const;
  bool ShowingDisplayDetailedView() const;
  bool ShowingCalendarView() const;

  // TrayBubbleBase:
  TrayBackgroundView* GetTray() const override;
  TrayBubbleView* GetBubbleView() const override;
  views::Widget* GetBubbleWidget() const override;

  // ScreenLayoutObserver:
  void OnDidApplyDisplayChanges() override;

  // views::WidgetObserver:
  void OnWidgetDestroying(views::Widget* widget) override;

  // TimeToClickRecorder::Delegate:
  void RecordTimeToClick() override;

  // TabletModeObserver:
  void OnTabletPhysicalStateChanged() override;

  // ShelfObserver:
  void OnAutoHideStateChanged(ShelfAutoHideState new_state) override;

  // KeyboardControllerObserver:
  void OnKeyboardVisibilityChanged(bool visible) override;

  // Updates the bubble height based on if it's going to show the main page or
  // the detailed page.
  void UpdateBubbleHeight(bool is_showing_detiled_view);

  QuickSettingsView* quick_settings_view() { return quick_settings_view_; }

  UnifiedSystemTrayController* unified_system_tray_controller() {
    return controller_.get();
  }

 private:
  friend class SystemTrayTestApi;
  friend class UnifiedSystemTray;

  void UpdateBubbleBounds();

  // Controller of `QuickSettingsView`. As the view is owned by views hierarchy,
  // we have to own the controller here.
  std::unique_ptr<UnifiedSystemTrayController> controller_;

  // Owner of this class.
  raw_ptr<UnifiedSystemTray> unified_system_tray_;

  // Widget that contains `QuickSettingsView`. Unowned.
  // When the widget is closed by deactivation, `bubble_widget_` pointer is
  // invalidated and we have to delete `UnifiedSystemTrayBubble` by calling
  // `UnifiedSystemTray::CloseBubble()`.
  // In order to do this, we observe `OnWidgetDestroying()`.
  raw_ptr<views::Widget> bubble_widget_ = nullptr;

  // PreTargetHandler of `quick_settings_view_` to record TimeToClick metrics.
  // Owned.
  std::unique_ptr<TimeToClickRecorder> time_to_click_recorder_;

  // The time the bubble is created.
  std::optional<base::TimeTicks> time_opened_;

  raw_ptr<TrayBubbleView> bubble_view_ = nullptr;

  raw_ptr<QuickSettingsView, DanglingUntriaged> quick_settings_view_ = nullptr;

  std::unique_ptr<TrayEventFilter> tray_event_filter_;

  base::WeakPtrFactory<UnifiedSystemTrayBubble> weak_factory_{this};
};

}  // namespace ash

#endif  // ASH_SYSTEM_UNIFIED_UNIFIED_SYSTEM_TRAY_BUBBLE_H_