tray_icon.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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(),
  56. const gfx::Point& location = gfx::Point(),
  57. int modifiers = 0);
  58. void NotifyDoubleClicked(const gfx::Rect& = gfx::Rect(), int modifiers = 0);
  59. void NotifyBalloonShow();
  60. void NotifyBalloonClicked();
  61. void NotifyBalloonClosed();
  62. void NotifyRightClicked(const gfx::Rect& bounds = gfx::Rect(),
  63. int modifiers = 0);
  64. void NotifyDrop();
  65. void NotifyDropFiles(const std::vector<std::string>& files);
  66. void NotifyDropText(const std::string& text);
  67. void NotifyDragEntered();
  68. void NotifyDragExited();
  69. void NotifyDragEnded();
  70. void NotifyMouseEntered(const gfx::Point& location = gfx::Point(),
  71. int modifiers = 0);
  72. void NotifyMouseExited(const gfx::Point& location = gfx::Point(),
  73. int modifiers = 0);
  74. void NotifyMouseMoved(const gfx::Point& location = gfx::Point(),
  75. int modifiers = 0);
  76. protected:
  77. TrayIcon();
  78. private:
  79. base::ObserverList<TrayIconObserver> observers_;
  80. DISALLOW_COPY_AND_ASSIGN(TrayIcon);
  81. };
  82. } // namespace atom
  83. #endif // ATOM_BROWSER_UI_TRAY_ICON_H_