File: status_icon.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 (107 lines) | stat: -rw-r--r-- 3,779 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
// Copyright 2012 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_STATUS_ICONS_STATUS_ICON_H_
#define CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_

#include <memory>
#include <string>

#include "base/observer_list.h"
#include "build/build_config.h"
#include "chrome/browser/status_icons/status_icon_menu_model.h"

namespace gfx {
class ImageSkia;
struct VectorIcon;
}

namespace message_center {
struct NotifierId;
}

class StatusIconObserver;

class StatusIcon {
 public:
  StatusIcon();

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

  virtual ~StatusIcon();

  // Sets the image associated with this status icon.
  virtual void SetImage(const gfx::ImageSkia& image) = 0;
  virtual void SetIcon(const gfx::VectorIcon& icon);

  // Sets the hover text for this status icon. This is also used as the label
  // for the menu item which is created as a replacement for the status icon
  // click action on platforms that do not support custom click actions for the
  // status icon (e.g. Ubuntu Unity).
  virtual void SetToolTip(const std::u16string& tool_tip) = 0;

  // Displays a notification balloon with the specified contents.
  // Depending on the platform it might not appear by the icon tray.
  virtual void DisplayBalloon(
      const gfx::ImageSkia& icon,
      const std::u16string& title,
      const std::u16string& contents,
      const message_center::NotifierId& notifier_id) = 0;

  // Set the context menu for this icon. The icon takes ownership of the passed
  // context menu. Passing NULL results in no menu at all.
  void SetContextMenu(std::unique_ptr<StatusIconMenuModel> menu);

  // Adds/Removes an observer for clicks on the status icon. If an observer is
  // registered, then left clicks on the status icon will result in the observer
  // being called, otherwise, both left and right clicks will display the
  // context menu (if any).
  void AddObserver(StatusIconObserver* observer);
  void RemoveObserver(StatusIconObserver* observer);

  // Returns true if there are registered click observers.
  bool HasObservers() const;

  // Dispatches a click event to the observers.
  void DispatchClickEvent();
#if BUILDFLAG(IS_WIN)
  void DispatchBalloonClickEvent();
#endif

  // Attempts to make the status icon directly visible on system UI.  Currently
  // this only applies to Windows, where status icons are hidden by default
  // inside an overflow window.
  // WARNING: This currently uses undocumented Windows APIs and spawns a worker
  // thread to do it.  Use sparingly.
  virtual void ForceVisible();

#if BUILDFLAG(IS_MAC)
  // On mac, if there is a menu, by default primary click will open it and not
  // call DispatchClickEvent(). Use this function to make the menu open on
  // secondary click, and dispatch the click event on left click.
  virtual void SetOpenMenuWithSecondaryClick(
      bool open_menu_with_secondary_click);

  // Use template property on the status icon image so that it changes color
  // based on contrast with the wallpaper.
  virtual void SetImageTemplate(bool is_template);
#endif

  StatusIconMenuModel* GetContextMenuForTesting();

 protected:
  // Invoked after a call to SetContextMenu() to let the platform-specific
  // subclass update the native context menu based on the new model. If NULL is
  // passed, subclass should destroy the native context menu.
  virtual void UpdatePlatformContextMenu(StatusIconMenuModel* model) = 0;

 private:
  base::ObserverList<StatusIconObserver>::Unchecked observers_;

  // Context menu, if any.
  std::unique_ptr<StatusIconMenuModel> context_menu_contents_;
};

#endif  // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_