tray_icon.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_H_
  5. #define ATOM_BROWSER_UI_TRAY_ICON_H_
  6. #include <string>
  7. #include <vector>
  8. #include "atom/browser/ui/atom_menu_model.h"
  9. #include "atom/browser/ui/tray_icon_observer.h"
  10. #include "base/observer_list.h"
  11. #include "ui/gfx/geometry/rect.h"
  12. namespace atom {
  13. class TrayIcon {
  14. public:
  15. static TrayIcon* Create();
  16. #if defined(OS_WIN)
  17. using ImageType = HICON;
  18. #else
  19. using ImageType = const gfx::Image&;
  20. #endif
  21. virtual ~TrayIcon();
  22. // Sets the image associated with this status icon.
  23. virtual void SetImage(ImageType image) = 0;
  24. // Sets the image associated with this status icon when pressed.
  25. virtual void SetPressedImage(ImageType image);
  26. // Sets the hover text for this status icon. This is also used as the label
  27. // for the menu item which is created as a replacement for the status icon
  28. // click action on platforms that do not support custom click actions for the
  29. // status icon (e.g. Ubuntu Unity).
  30. virtual void SetToolTip(const std::string& tool_tip) = 0;
  31. // Sets the status icon highlight mode. This only works on macOS.
  32. enum HighlightMode {
  33. ALWAYS, // Always highlight the tray icon
  34. NEVER, // Never highlight the tray icon
  35. SELECTION // Highlight the tray icon when clicked or the menu is opened
  36. };
  37. virtual void SetHighlightMode(HighlightMode mode);
  38. #if defined(OS_MACOSX)
  39. // Set/Get flag determining whether to ignore double click events.
  40. virtual void SetIgnoreDoubleClickEvents(bool ignore) = 0;
  41. virtual bool GetIgnoreDoubleClickEvents() = 0;
  42. // Set/Get title displayed next to status icon in the status bar.
  43. virtual void SetTitle(const std::string& title) = 0;
  44. virtual std::string GetTitle() = 0;
  45. #endif
  46. // Displays a notification balloon with the specified contents.
  47. // Depending on the platform it might not appear by the icon tray.
  48. virtual void DisplayBalloon(ImageType icon,
  49. const base::string16& title,
  50. const base::string16& contents);
  51. // Popups the menu.
  52. virtual void PopUpContextMenu(const gfx::Point& pos,
  53. AtomMenuModel* menu_model);
  54. // Set the context menu for this icon.
  55. virtual void SetContextMenu(AtomMenuModel* menu_model) = 0;
  56. // Returns the bounds of tray icon.
  57. virtual gfx::Rect GetBounds();
  58. void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
  59. void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
  60. void NotifyClicked(const gfx::Rect& = gfx::Rect(),
  61. const gfx::Point& location = gfx::Point(),
  62. int modifiers = 0);
  63. void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
  64. void NotifyBalloonShow();
  65. void NotifyBalloonClicked();
  66. void NotifyBalloonClosed();
  67. void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
  68. int modifiers = 0);
  69. void NotifyDrop();
  70. void NotifyDropFiles(const std::vector<std::string>& files);
  71. void NotifyDropText(const std::string& text);
  72. void NotifyDragEntered();
  73. void NotifyDragExited();
  74. void NotifyDragEnded();
  75. void NotifyMouseEntered(const gfx::Point& location = gfx::Point(),
  76. int modifiers = 0);
  77. void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
  78. int modifiers = 0);
  79. void NotifyMouseMoved(const gfx::Point& location = gfx::Point(),
  80. int modifiers = 0);
  81. protected:
  82. TrayIcon();
  83. private:
  84. base::ObserverList<TrayIconObserver> observers_;
  85. DISALLOW_COPY_AND_ASSIGN(TrayIcon);
  86. };
  87. } // namespace atom
  88. #endif // ATOM_BROWSER_UI_TRAY_ICON_H_