tray_icon_cocoa.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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_UI_TRAY_ICON_COCOA_H_
  5. #define ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_
  6. #import <Cocoa/Cocoa.h>
  7. #include <string>
  8. #include "atom/browser/ui/tray_icon.h"
  9. #include "base/mac/scoped_nsobject.h"
  10. @class AtomMenuController;
  11. @class StatusItemView;
  12. namespace atom {
  13. class TrayIconCocoa : public TrayIcon, public AtomMenuModel::Observer {
  14. public:
  15. TrayIconCocoa();
  16. ~TrayIconCocoa() override;
  17. void SetImage(const gfx::Image& image) override;
  18. void SetPressedImage(const gfx::Image& image) override;
  19. void SetToolTip(const std::string& tool_tip) override;
  20. void SetTitle(const std::string& title) override;
  21. std::string GetTitle() override;
  22. void SetHighlightMode(TrayIcon::HighlightMode mode) override;
  23. void SetIgnoreDoubleClickEvents(bool ignore) override;
  24. bool GetIgnoreDoubleClickEvents() override;
  25. void PopUpOnUI(AtomMenuModel* menu_model);
  26. void PopUpContextMenu(const gfx::Point& pos,
  27. AtomMenuModel* menu_model) override;
  28. void SetContextMenu(AtomMenuModel* menu_model) override;
  29. gfx::Rect GetBounds() override;
  30. protected:
  31. // AtomMenuModel::Observer:
  32. void OnMenuWillClose() override;
  33. private:
  34. // Atom custom view for NSStatusItem.
  35. base::scoped_nsobject<StatusItemView> status_item_view_;
  36. // Status menu shown when right-clicking the system icon.
  37. base::scoped_nsobject<AtomMenuController> menu_;
  38. // Used for unregistering observer.
  39. AtomMenuModel* menu_model_ = nullptr; // weak ref.
  40. base::WeakPtrFactory<TrayIconCocoa> weak_factory_;
  41. DISALLOW_COPY_AND_ASSIGN(TrayIconCocoa);
  42. };
  43. } // namespace atom
  44. #endif // ATOM_BROWSER_UI_TRAY_ICON_COCOA_H_