atom_api_tray.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. }
  20. namespace atom {
  21. class TrayIcon;
  22. namespace api {
  23. class Menu;
  24. class NativeImage;
  25. class Tray : public mate::TrackableObject<Tray>,
  26. public TrayIconObserver {
  27. public:
  28. static mate::WrappableBase* New(mate::Handle<NativeImage> image,
  29. mate::Arguments* args);
  30. static void BuildPrototype(v8::Isolate* isolate,
  31. v8::Local<v8::FunctionTemplate> prototype);
  32. protected:
  33. Tray(v8::Isolate* isolate, v8::Local<v8::Object> wrapper,
  34. mate::Handle<NativeImage> image);
  35. ~Tray() override;
  36. // TrayIconObserver:
  37. void OnClicked(const gfx::Rect& bounds, int modifiers) override;
  38. void OnDoubleClicked(const gfx::Rect& bounds, int modifiers) override;
  39. void OnRightClicked(const gfx::Rect& bounds, int modifiers) override;
  40. void OnBalloonShow() override;
  41. void OnBalloonClicked() override;
  42. void OnBalloonClosed() override;
  43. void OnDrop() override;
  44. void OnDropFiles(const std::vector<std::string>& files) override;
  45. void OnDropText(const std::string& text) override;
  46. void OnDragEntered() override;
  47. void OnDragExited() override;
  48. void OnDragEnded() override;
  49. void SetImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
  50. void SetPressedImage(v8::Isolate* isolate, mate::Handle<NativeImage> image);
  51. void SetToolTip(const std::string& tool_tip);
  52. void SetTitle(const std::string& title);
  53. void SetHighlightMode(TrayIcon::HighlightMode mode);
  54. void DisplayBalloon(mate::Arguments* args, const mate::Dictionary& options);
  55. void PopUpContextMenu(mate::Arguments* args);
  56. void SetContextMenu(v8::Isolate* isolate, mate::Handle<Menu> menu);
  57. gfx::Rect GetBounds();
  58. private:
  59. v8::Global<v8::Object> menu_;
  60. std::unique_ptr<TrayIcon> tray_icon_;
  61. DISALLOW_COPY_AND_ASSIGN(Tray);
  62. };
  63. } // namespace api
  64. } // namespace atom
  65. #endif // ATOM_BROWSER_API_ATOM_API_TRAY_H_