diff options
author | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-20 04:52:44 +0000 |
---|---|---|
committer | atwilson@chromium.org <atwilson@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-20 04:52:44 +0000 |
commit | 9979f5d4a25cab18fa10885c5c7b64ea9f8d8eeb (patch) | |
tree | 0204e3328959fb902f7fb613d0c99103a0e858c7 /chrome/browser/status_icons/status_icon.h | |
parent | c78b1e1619d7e700fce78f29533eba5ee78b0c70 (diff) | |
download | chromium_src-9979f5d4a25cab18fa10885c5c7b64ea9f8d8eeb.zip chromium_src-9979f5d4a25cab18fa10885c5c7b64ea9f8d8eeb.tar.gz chromium_src-9979f5d4a25cab18fa10885c5c7b64ea9f8d8eeb.tar.bz2 |
Added support for context menus to status icons.
BUG=37375
TEST=updated StatusIcon unit tests
Review URL: http://codereview.chromium.org/3189003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56812 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/status_icons/status_icon.h')
-rw-r--r-- | chrome/browser/status_icons/status_icon.h | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/chrome/browser/status_icons/status_icon.h b/chrome/browser/status_icons/status_icon.h index 8245e12..8f868b5 100644 --- a/chrome/browser/status_icons/status_icon.h +++ b/chrome/browser/status_icons/status_icon.h @@ -7,14 +7,19 @@ #pragma once #include "base/observer_list.h" +#include "base/scoped_ptr.h" #include "base/string16.h" class SkBitmap; +namespace menus { +class MenuModel; +} + class StatusIcon { public: - StatusIcon() {} - virtual ~StatusIcon() {} + StatusIcon(); + virtual ~StatusIcon(); // Sets the image associated with this status icon. virtual void SetImage(const SkBitmap& image) = 0; @@ -25,23 +30,45 @@ class StatusIcon { // Sets the hover text for this status icon. virtual void SetToolTip(const string16& tool_tip) = 0; + // Set the context menu for this icon. The icon takes ownership of the passed + // context menu. Passing NULL results in no menu at all. + void SetContextMenu(menus::MenuModel* menu); + class Observer { public: virtual ~Observer() {} - // Called when the user clicks on the system tray icon. + // Called when the user clicks on the system tray icon. Clicks that result + // in the context menu being displayed will not be passed to this observer + // (i.e. if there's a context menu set on this status icon, and the user + // right clicks on the icon to display the context menu, OnClicked will not + // be called). virtual void OnClicked() = 0; }; - // Adds/Removes an observer for status bar events. + // Adds/Removes an observer for clicks on the status icon. If an observer is + // registered, then left clicks on the status icon will result in the observer + // being called, otherwise, both left and right clicks will display the + // context menu (if any). void AddObserver(Observer* observer); void RemoveObserver(Observer* observer); + // Returns true if there are registered click observers. + bool HasObservers(); + // Dispatches a click event to the observers. void DispatchClickEvent(); + protected: + // Invoked after a call to SetContextMenu() to let the platform-specific + // subclass update the native context menu based on the new model. If NULL is + // passed, subclass should destroy the native context menu. + virtual void ResetContextMenu(menus::MenuModel* model) = 0; + private: ObserverList<Observer> observers_; + // Context menu, if any. + scoped_ptr<menus::MenuModel> context_menu_contents_; DISALLOW_COPY_AND_ASSIGN(StatusIcon); }; |