tray_icon.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. // Displays a notification balloon with the specified contents.
  42. // Depending on the platform it might not appear by the icon tray.
  43. virtual void DisplayBalloon(ImageType icon,
  44. const base::string16& title,
  45. const base::string16& contents);
  46. // Popups the menu.
  47. virtual void PopUpContextMenu(const gfx::Point& pos,
  48. AtomMenuModel* menu_model);
  49. // Set the context menu for this icon.
  50. virtual void SetContextMenu(AtomMenuModel* menu_model) = 0;
  51. // Returns the bounds of tray icon.
  52. virtual gfx::Rect GetBounds();
  53. void AddObserver(TrayIconObserver* obs) { observers_.AddObserver(obs); }
  54. void RemoveObserver(TrayIconObserver* obs) { observers_.RemoveObserver(obs); }
  55. void NotifyClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
  56. void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
  57. void NotifyBalloonShow();
  58. void NotifyBalloonClicked();
  59. void NotifyBalloonClosed();
  60. void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
  61. int modifiers = 0);
  62. void NotifyDrop();
  63. void NotifyDropFiles(const std::vector<std::string>& files);
  64. void NotifyDropText(const std::string& text);
  65. void NotifyDragEntered();
  66. void NotifyDragExited();
  67. void NotifyDragEnded();
  68. protected:
  69. TrayIcon();
  70. private:
  71. base::ObserverList<TrayIconObserver> observers_;
  72. DISALLOW_COPY_AND_ASSIGN(TrayIcon);
  73. };
  74. } // namespace atom
  75. #endif // ATOM_BROWSER_UI_TRAY_ICON_H_