electron_api_tray.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. // gin::Wrappable
  42. static gin::WrapperInfo kWrapperInfo;
  43. // disable copy
  44. Tray(const Tray&) = delete;
  45. Tray& operator=(const Tray&) = delete;
  46. private:
  47. Tray(v8::Isolate* isolate,
  48. v8::Local<v8::Value> image,
  49. absl::optional<UUID> guid);
  50. ~Tray() override;
  51. // TrayIconObserver:
  52. void OnClicked(const gfx::Rect& bounds,
  53. const gfx::Point& location,
  54. int modifiers) override;
  55. void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
  56. void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
  57. void OnBalloonShow() override;
  58. void OnBalloonClicked() override;
  59. void OnBalloonClosed() override;
  60. void OnDrop() override;
  61. void OnDropFiles(const std::vector<std::string>& files) override;
  62. void OnDropText(const std::string& text) override;
  63. void OnDragEntered() override;
  64. void OnDragExited() override;
  65. void OnDragEnded() override;
  66. void OnMouseUp(const gfx::Point& location, int modifiers) override;
  67. void OnMouseDown(const gfx::Point& location, int modifiers) override;
  68. void OnMouseEntered(const gfx::Point& location, int modifiers) override;
  69. void OnMouseExited(const gfx::Point& location, int modifiers) override;
  70. void OnMouseMoved(const gfx::Point& location, int modifiers) override;
  71. // JS API:
  72. void Destroy();
  73. bool IsDestroyed();
  74. void SetImage(v8::Isolate* isolate, v8::Local<v8::Value> image);
  75. void SetPressedImage(v8::Isolate* isolate, v8::Local<v8::Value> image);
  76. void SetToolTip(const std::string& tool_tip);
  77. void SetTitle(const std::string& title,
  78. const absl::optional<gin_helper::Dictionary>& options,
  79. gin::Arguments* args);
  80. std::string GetTitle();
  81. void SetIgnoreDoubleClickEvents(bool ignore);
  82. bool GetIgnoreDoubleClickEvents();
  83. void DisplayBalloon(gin_helper::ErrorThrower thrower,
  84. const gin_helper::Dictionary& options);
  85. void RemoveBalloon();
  86. void Focus();
  87. void PopUpContextMenu(gin::Arguments* args);
  88. void CloseContextMenu();
  89. void SetContextMenu(gin_helper::ErrorThrower thrower,
  90. v8::Local<v8::Value> arg);
  91. gfx::Rect GetBounds();
  92. bool CheckAlive();
  93. v8::Global<v8::Value> menu_;
  94. std::unique_ptr<TrayIcon> tray_icon_;
  95. };
  96. } // namespace electron::api
  97. #endif // ELECTRON_SHELL_BROWSER_API_ELECTRON_API_TRAY_H_