2014-10-31 12:17:05 -06:00
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-05-29 20:31:27 -06:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_UI_TRAY_ICON_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_UI_TRAY_ICON_H_
|
2014-05-29 20:31:27 -06:00
|
|
|
|
|
|
|
#include <string>
|
2015-07-18 22:12:28 -06:00
|
|
|
#include <vector>
|
2014-05-29 20:31:27 -06:00
|
|
|
|
2014-06-01 21:08:29 -06:00
|
|
|
#include "base/observer_list.h"
|
2020-02-04 13:19:40 -07:00
|
|
|
#include "shell/browser/ui/electron_menu_model.h"
|
2019-06-19 14:46:59 -06:00
|
|
|
#include "shell/browser/ui/tray_icon_observer.h"
|
2020-01-30 22:37:03 -07:00
|
|
|
#include "shell/common/gin_converters/guid_converter.h"
|
2015-05-03 21:43:05 -06:00
|
|
|
#include "ui/gfx/geometry/rect.h"
|
2014-05-29 20:31:27 -06:00
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
namespace electron {
|
2014-05-29 20:31:27 -06:00
|
|
|
|
|
|
|
class TrayIcon {
|
|
|
|
public:
|
2024-01-10 15:23:35 -07:00
|
|
|
static TrayIcon* Create(std::optional<UUID> guid);
|
2014-05-29 20:31:27 -06:00
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2016-05-20 01:55:22 -06:00
|
|
|
using ImageType = HICON;
|
|
|
|
#else
|
|
|
|
using ImageType = const gfx::Image&;
|
|
|
|
#endif
|
|
|
|
|
2014-05-30 09:57:54 -06:00
|
|
|
virtual ~TrayIcon();
|
|
|
|
|
2021-11-03 05:41:45 -06:00
|
|
|
// disable copy
|
|
|
|
TrayIcon(const TrayIcon&) = delete;
|
|
|
|
TrayIcon& operator=(const TrayIcon&) = delete;
|
|
|
|
|
2014-05-29 20:31:27 -06:00
|
|
|
// Sets the image associated with this status icon.
|
2016-05-20 01:55:22 -06:00
|
|
|
virtual void SetImage(ImageType image) = 0;
|
2014-05-29 20:31:27 -06:00
|
|
|
|
|
|
|
// Sets the image associated with this status icon when pressed.
|
2016-05-20 01:55:22 -06:00
|
|
|
virtual void SetPressedImage(ImageType image);
|
2014-05-29 20:31:27 -06:00
|
|
|
|
|
|
|
// 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::string& tool_tip) = 0;
|
|
|
|
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_MAC)
|
2019-03-18 13:40:34 -06:00
|
|
|
// Set/Get flag determining whether to ignore double click events.
|
2018-05-03 01:43:46 -06:00
|
|
|
virtual void SetIgnoreDoubleClickEvents(bool ignore) = 0;
|
|
|
|
virtual bool GetIgnoreDoubleClickEvents() = 0;
|
2019-03-18 13:40:34 -06:00
|
|
|
|
2020-08-23 15:39:29 -06:00
|
|
|
struct TitleOptions {
|
|
|
|
std::string font_type;
|
|
|
|
};
|
|
|
|
|
2019-03-18 13:40:34 -06:00
|
|
|
// Set/Get title displayed next to status icon in the status bar.
|
2020-08-23 15:39:29 -06:00
|
|
|
virtual void SetTitle(const std::string& title,
|
|
|
|
const TitleOptions& options) = 0;
|
2019-03-18 13:40:34 -06:00
|
|
|
virtual std::string GetTitle() = 0;
|
2018-05-03 01:43:46 -06:00
|
|
|
#endif
|
2018-04-01 19:07:26 -06:00
|
|
|
|
2020-10-27 11:51:45 -06:00
|
|
|
enum class IconType { kNone, kInfo, kWarning, kError, kCustom };
|
2019-08-08 15:43:33 -06:00
|
|
|
|
|
|
|
struct BalloonOptions {
|
2020-10-27 11:51:45 -06:00
|
|
|
IconType icon_type = IconType::kCustom;
|
2022-02-09 19:58:52 -07:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2019-08-08 15:43:33 -06:00
|
|
|
HICON icon = nullptr;
|
|
|
|
#else
|
|
|
|
gfx::Image icon;
|
|
|
|
#endif
|
2021-03-16 10:18:45 -06:00
|
|
|
std::u16string title;
|
|
|
|
std::u16string content;
|
2019-08-08 15:43:33 -06:00
|
|
|
bool large_icon = true;
|
|
|
|
bool no_sound = false;
|
|
|
|
bool respect_quiet_time = false;
|
|
|
|
|
|
|
|
BalloonOptions();
|
|
|
|
};
|
|
|
|
|
2014-11-28 03:30:43 -07:00
|
|
|
// Displays a notification balloon with the specified contents.
|
|
|
|
// Depending on the platform it might not appear by the icon tray.
|
2019-08-08 15:43:33 -06:00
|
|
|
virtual void DisplayBalloon(const BalloonOptions& options);
|
2014-11-28 03:30:43 -07:00
|
|
|
|
2019-08-05 09:52:47 -06:00
|
|
|
// Removes the notification balloon.
|
|
|
|
virtual void RemoveBalloon();
|
|
|
|
|
2019-08-09 08:43:48 -06:00
|
|
|
// Returns focus to the taskbar notification area.
|
|
|
|
virtual void Focus();
|
|
|
|
|
2015-12-02 03:43:11 -07:00
|
|
|
// Popups the menu.
|
|
|
|
virtual void PopUpContextMenu(const gfx::Point& pos,
|
2023-08-01 00:07:30 -06:00
|
|
|
base::WeakPtr<ElectronMenuModel> menu_model);
|
2015-07-15 20:50:53 -06:00
|
|
|
|
2020-01-22 16:25:17 -07:00
|
|
|
virtual void CloseContextMenu();
|
|
|
|
|
2014-05-29 20:31:27 -06:00
|
|
|
// Set the context menu for this icon.
|
2023-06-09 17:08:36 -06:00
|
|
|
virtual void SetContextMenu(raw_ptr<ElectronMenuModel> menu_model) = 0;
|
2014-05-29 20:31:27 -06:00
|
|
|
|
2016-06-21 00:40:30 -06:00
|
|
|
// Returns the bounds of tray icon.
|
|
|
|
virtual gfx::Rect GetBounds();
|
|
|
|
|
2014-06-01 21:08:29 -06:00
|
|
|
void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
|
|
|
|
void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
|
2016-06-21 00:40:30 -06:00
|
|
|
|
2017-10-04 20:49:26 -06:00
|
|
|
void NotifyClicked(const gfx::Rect& = gfx::Rect(),
|
|
|
|
const gfx::Point& location = gfx::Point(),
|
|
|
|
int modifiers = 0);
|
2015-07-27 04:15:51 -06:00
|
|
|
void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
2023-09-27 12:21:15 -06:00
|
|
|
void NotifyMiddleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
|
2014-11-28 04:42:57 -07:00
|
|
|
void NotifyBalloonShow();
|
2014-11-28 03:50:31 -07:00
|
|
|
void NotifyBalloonClicked();
|
2014-11-28 04:42:57 -07:00
|
|
|
void NotifyBalloonClosed();
|
2015-07-27 04:15:51 -06:00
|
|
|
void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
|
2015-07-28 22:01:27 -06:00
|
|
|
int modifiers = 0);
|
2015-11-10 09:02:50 -07:00
|
|
|
void NotifyDrop();
|
2015-10-17 23:32:13 -06:00
|
|
|
void NotifyDropFiles(const std::vector<std::string>& files);
|
2016-07-14 11:21:39 -06:00
|
|
|
void NotifyDropText(const std::string& text);
|
2015-11-05 18:02:24 -07:00
|
|
|
void NotifyDragEntered();
|
|
|
|
void NotifyDragExited();
|
2015-11-10 09:02:50 -07:00
|
|
|
void NotifyDragEnded();
|
2020-01-17 09:28:34 -07:00
|
|
|
void NotifyMouseUp(const gfx::Point& location = gfx::Point(),
|
|
|
|
int modifiers = 0);
|
|
|
|
void NotifyMouseDown(const gfx::Point& location = gfx::Point(),
|
|
|
|
int modifiers = 0);
|
2017-06-28 13:09:12 -06:00
|
|
|
void NotifyMouseEntered(const gfx::Point& location = gfx::Point(),
|
|
|
|
int modifiers = 0);
|
|
|
|
void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
|
|
|
|
int modifiers = 0);
|
2017-08-26 12:04:58 -06:00
|
|
|
void NotifyMouseMoved(const gfx::Point& location = gfx::Point(),
|
2018-04-17 19:44:10 -06:00
|
|
|
int modifiers = 0);
|
2014-06-01 21:08:29 -06:00
|
|
|
|
2014-05-29 20:31:27 -06:00
|
|
|
protected:
|
|
|
|
TrayIcon();
|
|
|
|
|
|
|
|
private:
|
2015-09-02 01:16:49 -06:00
|
|
|
base::ObserverList<TrayIconObserver> observers_;
|
2014-05-29 20:31:27 -06:00
|
|
|
};
|
|
|
|
|
2019-06-19 15:23:04 -06:00
|
|
|
} // namespace electron
|
2014-05-29 20:31:27 -06:00
|
|
|
|
2021-11-22 00:34:31 -07:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_UI_TRAY_ICON_H_
|