electron_api_tray.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Copyright (c) 2014 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_
  5. #define ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "gin/handle.h"
  10. #include "gin/wrappable.h"
  11. #include "shell/browser/event_emitter_mixin.h"
  12. #include "shell/browser/javascript_environment.h"
  13. #include "shell/browser/ui/tray_icon.h"
  14. #include "shell/browser/ui/tray_icon_observer.h"
  15. #include "shell/common/gin_converters/guid_converter.h"
  16. #include "shell/common/gin_helper/cleaned_up_at_exit.h"
  17. #include "shell/common/gin_helper/constructible.h"
  18. #include "shell/common/gin_helper/error_thrower.h"
  19. #include "shell/common/gin_helper/pinnable.h"
  20. namespace gfx {
  21. class Image;
  22. }
  23. namespace gin_helper {
  24. class Dictionary;
  25. }
  26. namespace electron::api {
  27. class Menu;
  28. class Tray : public gin::Wrappable<Tray>,
  29. public gin_helper::EventEmitterMixin<Tray>,
  30. public gin_helper::Constructible<Tray>,
  31. public gin_helper::CleanedUpAtExit,
  32. public gin_helper::Pinnable<Tray>,
  33. public TrayIconObserver {
  34. public:
  35. // gin_helper::Constructible
  36. static gin::Handle<Tray> New(gin_helper::ErrorThrower thrower,
  37. v8::Local<v8::Value> image,
  38. absl::optional<UUID> guid,
  39. gin::Arguments* args);
  40. static void FillObjectTemplate(v8::Isolate*, v8::Local<v8::ObjectTemplate>);
  41. static const char* GetClassName() { return "Tray"; }
  42. // gin::Wrappable
  43. static gin::WrapperInfo kWrapperInfo;
  44. const char* GetTypeName() override;
  45. // disable copy
  46. Tray(const Tray&) = delete;
  47. Tray& operator=(const Tray&) = delete;
  48. private:
  49. Tray(v8::Isolate* isolate,
  50. v8::Local<v8::Value> image,
  51. absl::optional<UUID> guid);
  52. ~Tray() override;
  53. // TrayIconObserver:
  54. void OnClicked(const gfx::Rect& bounds,
  55. const gfx::Point& location,
  56. int modifiers) override;
  57. void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
  58. void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
  59. void OnBalloonShow() override;
  60. void OnBalloonClicked() override;
  61. void OnBalloonClosed() override;
  62. void OnDrop() override;
  63. void OnDropFiles(const std::vector<std::string>& files) override;
  64. void OnDropText(const std::string& text) override;
  65. void OnDragEntered() override;
  66. void OnDragExited() override;
  67. void OnDragEnded() override;
  68. void OnMouseUp(const gfx::Point& location, int modifiers) override;
  69. void OnMouseDown(const gfx::Point& location, int modifiers) override;
  70. void OnMouseEntered(const gfx::Point& location, int modifiers) override;
  71. void OnMouseExited(const gfx::Point& location, int modifiers) override;
  72. void OnMouseMoved(const gfx::Point& location, int modifiers) override;
  73. // JS API:
  74. void Destroy();
  75. bool IsDestroyed();
  76. void SetImage(v8::Isolate* isolate, v8::Local<v8::Value> image);
  77. void SetPressedImage(v8::Isolate* isolate, v8::Local<v8::Value> image);
  78. void SetToolTip(const std::string& tool_tip);
  79. void SetTitle(const std::string& title,
  80. const absl::optional<gin_helper::Dictionary>& options,
  81. gin::Arguments* args);
  82. std::string GetTitle();
  83. void SetIgnoreDoubleClickEvents(bool ignore);
  84. bool GetIgnoreDoubleClickEvents();
  85. void DisplayBalloon(gin_helper::ErrorThrower thrower,
  86. const gin_helper::Dictionary& options);
  87. void RemoveBalloon();
  88. void Focus();
  89. void PopUpContextMenu(gin::Arguments* args);
  90. void CloseContextMenu();
  91. void SetContextMenu(gin_helper::ErrorThrower thrower,
  92. v8::Local<v8::Value> arg);
  93. gfx::Rect GetBounds();
  94. bool CheckAlive();
  95. v8::Global<v8::Value> menu_;
  96. std::unique_ptr<TrayIcon> tray_icon_;
  97. };
  98. } // namespace electron::api
  99. #endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_