electron/shell/browser/api/electron_api_tray.h

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

120 lines
4 KiB
C
Raw Normal View History

// Copyright (c) 2014 GitHub, Inc.
2014-05-30 15:57:54 +00:00
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_
#define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_
2014-05-30 15:57:54 +00:00
2016-07-04 06:08:55 +00:00
#include <memory>
#include <optional>
#include <string>
#include <vector>
#include "gin/handle.h"
#include "gin/wrappable.h"
#include "shell/browser/event_emitter_mixin.h"
#include "shell/browser/javascript_environment.h"
#include "shell/browser/ui/tray_icon.h"
#include "shell/browser/ui/tray_icon_observer.h"
#include "shell/common/gin_converters/guid_converter.h"
#include "shell/common/gin_helper/cleaned_up_at_exit.h"
#include "shell/common/gin_helper/constructible.h"
#include "shell/common/gin_helper/error_thrower.h"
2022-02-24 19:03:59 +00:00
#include "shell/common/gin_helper/pinnable.h"
2014-05-30 15:57:54 +00:00
namespace gfx {
class Image;
2014-05-30 15:57:54 +00:00
}
namespace gin_helper {
2014-11-28 10:39:30 +00:00
class Dictionary;
}
2014-11-28 10:06:51 +00:00
2022-06-29 19:55:47 +00:00
namespace electron::api {
2014-05-30 15:57:54 +00:00
class Menu;
class Tray : public gin::Wrappable<Tray>,
public gin_helper::EventEmitterMixin<Tray>,
public gin_helper::Constructible<Tray>,
public gin_helper::CleanedUpAtExit,
2022-02-24 19:03:59 +00:00
public gin_helper::Pinnable<Tray>,
public TrayIconObserver {
2014-05-30 15:57:54 +00:00
public:
// gin_helper::Constructible
static gin::Handle<Tray> New(gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> image,
std::optional<UUID> guid,
gin::Arguments* args);
static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
static const char* GetClassName() { return "Tray"; }
// gin::Wrappable
static gin::WrapperInfo kWrapperInfo;
const char* GetTypeName() override;
2014-05-30 15:57:54 +00:00
// disable copy
Tray(const Tray&) = delete;
Tray& operator=(const Tray&) = delete;
private:
Tray(v8::Isolate* isolate,
v8::Local<v8::Value> image,
std::optional<UUID> guid);
~Tray() override;
2014-05-30 15:57:54 +00:00
// TrayIconObserver:
2017-10-05 02:49:26 +00:00
void OnClicked(const gfx::Rect& bounds,
const gfx::Point& location,
int modifiers) override;
void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
2015-07-29 06:25:12 +00:00
void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
void OnMiddleClicked(const gfx::Rect& bounds, int modifiers) override;
void OnBalloonShow() override;
void OnBalloonClicked() override;
void OnBalloonClosed() override;
2015-11-10 16:02:50 +00:00
void OnDrop() override;
void OnDropFiles(const std::vector<std::string>& files) override;
2016-07-14 17:21:39 +00:00
void OnDropText(const std::string& text) override;
void OnDragEntered() override;
void OnDragExited() override;
2015-11-10 16:02:50 +00:00
void OnDragEnded() override;
void OnMouseUp(const gfx::Point& location, int modifiers) override;
void OnMouseDown(const gfx::Point& location, int modifiers) override;
void OnMouseEntered(const gfx::Point& location, int modifiers) override;
void OnMouseExited(const gfx::Point& location, int modifiers) override;
void OnMouseMoved(const gfx::Point& location, int modifiers) override;
2014-06-02 03:08:29 +00:00
// JS API:
void Destroy();
bool IsDestroyed();
void SetImage(v8::Isolate* isolate, v8::Local<v8::Value> image);
void SetPressedImage(v8::Isolate* isolate, v8::Local<v8::Value> image);
void SetToolTip(const std::string& tool_tip);
void SetTitle(const std::string& title,
const std::optional<gin_helper::Dictionary>& options,
gin::Arguments* args);
std::string GetTitle();
void SetIgnoreDoubleClickEvents(bool ignore);
bool GetIgnoreDoubleClickEvents();
void DisplayBalloon(gin_helper::ErrorThrower thrower,
const gin_helper::Dictionary& options);
void RemoveBalloon();
2019-08-09 14:43:48 +00:00
void Focus();
void PopUpContextMenu(gin::Arguments* args);
void CloseContextMenu();
void SetContextMenu(gin_helper::ErrorThrower thrower,
v8::Local<v8::Value> arg);
2016-06-21 06:40:30 +00:00
gfx::Rect GetBounds();
2014-05-30 15:57:54 +00:00
2020-04-03 00:22:46 +00:00
bool CheckAlive();
v8::Global<v8::Value> menu_;
2016-05-23 01:59:39 +00:00
std::unique_ptr<TrayIcon> tray_icon_;
2014-05-30 15:57:54 +00:00
};
2022-06-29 19:55:47 +00:00
} // namespace electron::api
2014-05-30 15:57:54 +00:00
#endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_