blob: 6b1c8100550ad1f4541133bbc955369278b20a46 [file] [log] [blame]
Avi Drissman4a8573c2022-09-09 19:35:541// Copyright 2012 The Chromium Authors
[email protected]ccb55cf52010-03-06 22:02:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
6#define CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
7
dcheng4af48582016-04-19 00:29:358#include <memory>
Jan Wilken Dörriead587c32021-03-11 14:09:279#include <string>
dcheng4af48582016-04-19 00:29:3510
[email protected]61ee62872010-03-31 16:08:5611#include "base/observer_list.h"
avi664c07b2015-12-26 02:18:3112#include "build/build_config.h"
[email protected]f528059f2013-08-28 08:23:5913#include "chrome/browser/status_icons/status_icon_menu_model.h"
[email protected]ccb55cf52010-03-06 22:02:0414
[email protected]7f1f1762012-10-03 15:51:0215namespace gfx {
16class ImageSkia;
Tom Anderson513e0162025-01-09 04:09:4417struct VectorIcon;
[email protected]7f1f1762012-10-03 15:51:0218}
[email protected]ccb55cf52010-03-06 22:02:0419
johnme92956172015-10-15 16:54:1220namespace message_center {
21struct NotifierId;
22}
23
[email protected]8a7923f2012-05-23 14:51:1824class StatusIconObserver;
25
[email protected]ccb55cf52010-03-06 22:02:0426class StatusIcon {
27 public:
[email protected]9979f5d2010-08-20 04:52:4428 StatusIcon();
Peter Boström53c6c5952021-09-17 09:41:2629
30 StatusIcon(const StatusIcon&) = delete;
31 StatusIcon& operator=(const StatusIcon&) = delete;
32
[email protected]9979f5d2010-08-20 04:52:4433 virtual ~StatusIcon();
[email protected]ccb55cf52010-03-06 22:02:0434
35 // Sets the image associated with this status icon.
[email protected]7f1f1762012-10-03 15:51:0236 virtual void SetImage(const gfx::ImageSkia& image) = 0;
Tom Anderson513e0162025-01-09 04:09:4437 virtual void SetIcon(const gfx::VectorIcon& icon);
[email protected]ccb55cf52010-03-06 22:02:0438
[email protected]b6c510aa2013-07-31 23:36:1439 // Sets the hover text for this status icon. This is also used as the label
40 // for the menu item which is created as a replacement for the status icon
41 // click action on platforms that do not support custom click actions for the
42 // status icon (e.g. Ubuntu Unity).
Jan Wilken Dörriedec99122021-03-11 18:02:3043 virtual void SetToolTip(const std::u16string& tool_tip) = 0;
[email protected]ccb55cf52010-03-06 22:02:0444
[email protected]6f9eac92011-03-06 17:49:0245 // Displays a notification balloon with the specified contents.
[email protected]a25fd452011-10-26 10:45:0846 // Depending on the platform it might not appear by the icon tray.
johnme92956172015-10-15 16:54:1247 virtual void DisplayBalloon(
48 const gfx::ImageSkia& icon,
Jan Wilken Dörriedec99122021-03-11 18:02:3049 const std::u16string& title,
50 const std::u16string& contents,
johnme92956172015-10-15 16:54:1251 const message_center::NotifierId& notifier_id) = 0;
[email protected]6f9eac92011-03-06 17:49:0252
[email protected]9979f5d2010-08-20 04:52:4453 // Set the context menu for this icon. The icon takes ownership of the passed
54 // context menu. Passing NULL results in no menu at all.
dcheng4af48582016-04-19 00:29:3555 void SetContextMenu(std::unique_ptr<StatusIconMenuModel> menu);
[email protected]9979f5d2010-08-20 04:52:4456
[email protected]9979f5d2010-08-20 04:52:4457 // Adds/Removes an observer for clicks on the status icon. If an observer is
58 // registered, then left clicks on the status icon will result in the observer
59 // being called, otherwise, both left and right clicks will display the
60 // context menu (if any).
[email protected]8a7923f2012-05-23 14:51:1861 void AddObserver(StatusIconObserver* observer);
62 void RemoveObserver(StatusIconObserver* observer);
[email protected]a24642a2010-03-24 21:29:0563
[email protected]9979f5d2010-08-20 04:52:4464 // Returns true if there are registered click observers.
[email protected]8a7923f2012-05-23 14:51:1865 bool HasObservers() const;
[email protected]9979f5d2010-08-20 04:52:4466
[email protected]a24642a2010-03-24 21:29:0567 // Dispatches a click event to the observers.
68 void DispatchClickEvent();
Xiaohan Wang1c69fe62022-01-16 01:35:5169#if BUILDFLAG(IS_WIN)
[email protected]963b13c2013-06-22 14:10:4170 void DispatchBalloonClickEvent();
71#endif
[email protected]a24642a2010-03-24 21:29:0572
[email protected]caea05f42014-04-25 02:34:5873 // Attempts to make the status icon directly visible on system UI. Currently
74 // this only applies to Windows, where status icons are hidden by default
75 // inside an overflow window.
76 // WARNING: This currently uses undocumented Windows APIs and spawns a worker
77 // thread to do it. Use sparingly.
78 virtual void ForceVisible();
79
Charles Mengf071d0662024-12-17 00:36:3680#if BUILDFLAG(IS_MAC)
81 // On mac, if there is a menu, by default primary click will open it and not
82 // call DispatchClickEvent(). Use this function to make the menu open on
83 // secondary click, and dispatch the click event on left click.
84 virtual void SetOpenMenuWithSecondaryClick(
85 bool open_menu_with_secondary_click);
Charles Meng8af381b2025-01-13 21:06:5886
87 // Use template property on the status icon image so that it changes color
88 // based on contrast with the wallpaper.
89 virtual void SetImageTemplate(bool is_template);
Charles Mengf071d0662024-12-17 00:36:3690#endif
91
Alison Gale5fd20b9a2025-01-28 22:29:2492 StatusIconMenuModel* GetContextMenuForTesting();
93
[email protected]9979f5d2010-08-20 04:52:4494 protected:
95 // Invoked after a call to SetContextMenu() to let the platform-specific
96 // subclass update the native context menu based on the new model. If NULL is
97 // passed, subclass should destroy the native context menu.
[email protected]f528059f2013-08-28 08:23:5998 virtual void UpdatePlatformContextMenu(StatusIconMenuModel* model) = 0;
[email protected]9979f5d2010-08-20 04:52:4499
[email protected]a24642a2010-03-24 21:29:05100 private:
Trent Apteda250ec3ab2018-08-19 08:52:19101 base::ObserverList<StatusIconObserver>::Unchecked observers_;
[email protected]8a7923f2012-05-23 14:51:18102
[email protected]9979f5d2010-08-20 04:52:44103 // Context menu, if any.
dcheng4af48582016-04-19 00:29:35104 std::unique_ptr<StatusIconMenuModel> context_menu_contents_;
[email protected]ccb55cf52010-03-06 22:02:04105};
106
[email protected]ccb55cf52010-03-06 22:02:04107#endif // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_