File: glic_status_icon.h

package info (click to toggle)
chromium 138.0.7204.183-1~deb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-proposed-updates
  • size: 6,080,960 kB
  • sloc: cpp: 34,937,079; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,954; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,811; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (91 lines) | stat: -rw-r--r-- 3,357 bytes parent folder | download | duplicates (4)
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
// Copyright 2024 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_BACKGROUND_GLIC_GLIC_STATUS_ICON_H_
#define CHROME_BROWSER_BACKGROUND_GLIC_GLIC_STATUS_ICON_H_

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/glic/glic_profile_manager.h"
#include "chrome/browser/glic/widget/glic_window_controller.h"
#include "chrome/browser/status_icons/status_icon_menu_model.h"
#include "chrome/browser/status_icons/status_icon_observer.h"
#include "chrome/browser/ui/browser_list_observer.h"
#include "ui/native_theme/native_theme_observer.h"

class StatusIcon;
class StatusIconMenuModel;
class StatusTray;
class Browser;

namespace glic {

class GlicController;

// This class abstracts away the details for creating a status tray icon and it
// context menu for the glic background mode manager. It is responsible for
// notifying the GlicController when the UI needs to be shown in response to the
// status icon being clicked or menu item being triggered.
class GlicStatusIcon : public StatusIconObserver,
                       public StatusIconMenuModel::Delegate,
                       public ui::NativeThemeObserver,
                       public BrowserListObserver,
                       public GlicProfileManager::Observer,
                       public GlicWindowController::StateObserver {
 public:
  explicit GlicStatusIcon(GlicController* controller, StatusTray* status_tray);
  ~GlicStatusIcon() override;

  // StatusIconObserver
  void OnStatusIconClicked() override;

  // StatusIconMenuModel::Delegate
  void ExecuteCommand(int command_id, int event_flags) override;

  // ui::NativeThemeObserver:
  void OnNativeThemeUpdated(ui::NativeTheme* observed_theme) override;

  // BrowserListObserver:
  void OnBrowserAdded(Browser* browser) override;
  void OnBrowserRemoved(Browser* browser) override;

  // GlicProfileManager::Observer
  // TODO(crbug.com/404311796): would ideally observe window show/hide via the
  // profile manager, directly.
  void OnLastActiveGlicProfileChanged(Profile* profile) override;

  // GlicWindowController::StateObserver
  // TODO(crbug.com/404311796): would ideally observe window show/hide via the
  // profile manager, directly.
  void PanelStateChanged(const mojom::PanelState& panel_state,
                         Browser* attached_browser) override;

  void UpdateHotkey(const ui::Accelerator& hotkey);

  void UpdateVisibilityOfExitInContextMenu();
  void UpdateVisibilityOfShowAndCloseInContextMenu();

  StatusIconMenuModel* GetContextMenuForTesting() { return context_menu_; }

 private:
  std::unique_ptr<StatusIconMenuModel> CreateStatusIconMenu();

  raw_ptr<GlicController> controller_;

  base::ScopedObservation<ui::NativeTheme, ui::NativeThemeObserver>
      native_theme_observer_{this};
  base::ScopedObservation<GlicProfileManager, GlicProfileManager::Observer>
      profile_observer_{this};
  base::ScopedObservation<GlicWindowController,
                          GlicWindowController::StateObserver>
      panel_state_observer_{this};

  raw_ptr<StatusTray> status_tray_;
  raw_ptr<StatusIcon> status_icon_;
  raw_ptr<StatusIconMenuModel> context_menu_;
};

}  // namespace glic

#endif  // CHROME_BROWSER_BACKGROUND_GLIC_GLIC_STATUS_ICON_H_