atom_api_tray.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 ATOM_BROWSER_API_ATOM_API_TRAY_H_
  5. #define ATOM_BROWSER_API_ATOM_API_TRAY_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "atom/browser/api/trackable_object.h"
  10. #include "atom/browser/ui/tray_icon.h"
  11. #include "atom/browser/ui/tray_icon_observer.h"
  12. #include "native_mate/handle.h"
  13. namespace gfx {
  14. class Image;
  15. }
  16. namespace mate {
  17. class Arguments;
  18. class Dictionary;
  19. } // namespace mate
  20. namespace atom {
  21. class TrayIcon;
  22. namespace api {
  23. class Menu;
  24. class NativeImage;
  25. class Tray : public mate::TrackableObject<Tray>, public TrayIconObserver {
  26. public:
  27. static mate::WrappableBase* New(mate::Handle<NativeImage> image,
  28. mate::Arguments* args);
  29. static void BuildPrototype(v8::Isolate* isolate,
  30. v8::Local<v8::FunctionTemplate> prototype);
  31. protected:
  32. Tray(v8::Isolate* isolate,
  33. v8::Local<v8::Object> wrapper,
  34. mate::Handle<NativeImage> image);
  35. ~Tray() override;
  36. // TrayIconObserver:
  37. void OnClicked(const gfx::Rect& bounds,
  38. const gfx::Point& location,
  39. int modifiers) override;
  40. void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
  41. void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
  42. void OnBalloonShow() override;
  43. void OnBalloonClicked() override;
  44. void OnBalloonClosed() override;
  45. void OnDrop() override;
  46. void OnDropFiles(const std::vector<std::string>& files) override;
  47. void OnDropText(const std::string& text) override;
  48. void OnDragEntered() override;
  49. void OnDragExited() override;
  50. void OnDragEnded() override;
  51. void OnMouseEntered(const gfx::Point& location, int modifiers) override;
  52. void OnMouseExited(const gfx::Point& location, int modifiers) override;
  53. void OnMouseMoved(const gfx::Point& location, int modifiers) override;
  54. void SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
  55. void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
  56. void SetToolTip(const std::string& tool_tip);
  57. void SetTitle(const std::string& title);
  58. void SetHighlightMode(TrayIcon::HighlightMode mode);
  59. void SetIgnoreDoubleClickEvents(bool ignore);
  60. bool GetIgnoreDoubleClickEvents();
  61. void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
  62. void PopUpContextMenu(mate::Arguments* args);
  63. void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);
  64. gfx::Rect GetBounds();
  65. private:
  66. v8::Global<v8::Object> menu_;
  67. std::unique_ptr<TrayIcon> tray_icon_;
  68. DISALLOW_COPY_AND_ASSIGN(Tray);
  69. };
  70. } // namespace api
  71. } // namespace atom
  72. #endif // ATOM_BROWSER_API_ATOM_API_TRAY_H_