tray_icon.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 title displayed aside of the status icon in the status bar. This
  32. // only works on macOS.
  33. virtual void SetTitle(const std::string& title);
  34. // Sets the status icon highlight mode. This only works on macOS.
  35. enum HighlightMode {
  36. ALWAYS, // Always highlight the tray icon
  37. NEVER, // Never highlight the tray icon
  38. SELECTION // Highlight the tray icon when clicked or the menu is opened
  39. };
  40. virtual void SetHighlightMode(HighlightMode mode);
  41. // Setter and getter for the flag which determines whether to ignore double
  42. // click events. These only work on macOS.
  43. #if defined(OS_MACOSX)
  44. virtual void SetIgnoreDoubleClickEvents(bool ignore) = 0;
  45. virtual bool GetIgnoreDoubleClickEvents() = 0;
  46. #endif
  47. // Displays a notification balloon with the specified contents.
  48. // Depending on the platform it might not appear by the icon tray.
  49. virtual void DisplayBalloon(ImageType icon,
  50. const base::string16& title,
  51. const base::string16& contents);
  52. // Popups the menu.
  53. virtual void PopUpContextMenu(const gfx::Point& pos,
  54. AtomMenuModel* menu_model);
  55. // Set the context menu for this icon.
  56. virtual void SetContextMenu(AtomMenuModel* menu_model) = 0;
  57. // Returns the bounds of tray icon.
  58. virtual gfx::Rect GetBounds();
  59. void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
  60. void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
  61. void NotifyClicked(const gfx::Rect& = gfx::Rect(),
  62. const gfx::Point& location = gfx::Point(),
  63. int modifiers = 0);
  64. void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
  65. void NotifyBalloonShow();
  66. void NotifyBalloonClicked();
  67. void NotifyBalloonClosed();
  68. void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
  69. int modifiers = 0);
  70. void NotifyDrop();
  71. void NotifyDropFiles(const std::vector<std::string>& files);
  72. void NotifyDropText(const std::string& text);
  73. void NotifyDragEntered();
  74. void NotifyDragExited();
  75. void NotifyDragEnded();
  76. void NotifyMouseEntered(const gfx::Point& location = gfx::Point(),
  77. int modifiers = 0);
  78. void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
  79. int modifiers = 0);
  80. void NotifyMouseMoved(const gfx::Point& location = gfx::Point(),
  81. int modifiers = 0);
  82. protected:
  83. TrayIcon();
  84. private:
  85. base::ObserverList<TrayIconObserver> observers_;
  86. DISALLOW_COPY_AND_ASSIGN(TrayIcon);
  87. };
  88. } // namespace atom
  89. #endif // ATOM_BROWSER_UI_TRAY_ICON_H_