atom_api_tray.h 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. std::string GetTitle();
  59. void SetHighlightMode(TrayIcon::HighlightMode mode);
  60. void SetIgnoreDoubleClickEvents(bool ignore);
  61. bool GetIgnoreDoubleClickEvents();
  62. void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
  63. void PopUpContextMenu(mate::Arguments* args);
  64. void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);
  65. gfx::Rect GetBounds();
  66. private:
  67. v8::Global<v8::Object> menu_;
  68. std::unique_ptr<TrayIcon> tray_icon_;
  69. DISALLOW_COPY_AND_ASSIGN(Tray);
  70. };
  71. } // namespace api
  72. } // namespace atom
  73. #endif // ATOM_BROWSER_API_ATOM_API_TRAY_H_