Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: chrome/browser/status_icons/status_icon.h

Issue 3189003: Added support for context menus to status icons. (Closed)
Patch Set: Final version. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_ 5 #ifndef CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
6 #define CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_ 6 #define CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/observer_list.h" 9 #include "base/observer_list.h"
10 #include "base/scoped_ptr.h"
10 #include "base/string16.h" 11 #include "base/string16.h"
11 12
12 class SkBitmap; 13 class SkBitmap;
13 14
15 namespace menus {
16 class MenuModel;
17 }
18
14 class StatusIcon { 19 class StatusIcon {
15 public: 20 public:
16 StatusIcon() {} 21 StatusIcon();
17 virtual ~StatusIcon() {} 22 virtual ~StatusIcon();
18 23
19 // Sets the image associated with this status icon. 24 // Sets the image associated with this status icon.
20 virtual void SetImage(const SkBitmap& image) = 0; 25 virtual void SetImage(const SkBitmap& image) = 0;
21 26
22 // Sets the image associated with this status icon when pressed. 27 // Sets the image associated with this status icon when pressed.
23 virtual void SetPressedImage(const SkBitmap& image) = 0; 28 virtual void SetPressedImage(const SkBitmap& image) = 0;
24 29
25 // Sets the hover text for this status icon. 30 // Sets the hover text for this status icon.
26 virtual void SetToolTip(const string16& tool_tip) = 0; 31 virtual void SetToolTip(const string16& tool_tip) = 0;
27 32
33 // Set the context menu for this icon. The icon takes ownership of the passed
34 // context menu. Passing NULL results in no menu at all.
35 void SetContextMenu(menus::MenuModel* menu);
36
28 class Observer { 37 class Observer {
29 public: 38 public:
30 virtual ~Observer() {} 39 virtual ~Observer() {}
31 40
32 // Called when the user clicks on the system tray icon. 41 // Called when the user clicks on the system tray icon. Clicks that result
42 // in the context menu being displayed will not be passed to this observer
43 // (i.e. if there's a context menu set on this status icon, and the user
44 // right clicks on the icon to display the context menu, OnClicked will not
45 // be called).
33 virtual void OnClicked() = 0; 46 virtual void OnClicked() = 0;
34 }; 47 };
35 48
36 // Adds/Removes an observer for status bar events. 49 // Adds/Removes an observer for clicks on the status icon. If an observer is
50 // registered, then left clicks on the status icon will result in the observer
51 // being called, otherwise, both left and right clicks will display the
52 // context menu (if any).
37 void AddObserver(Observer* observer); 53 void AddObserver(Observer* observer);
38 void RemoveObserver(Observer* observer); 54 void RemoveObserver(Observer* observer);
39 55
56 // Returns true if there are registered click observers.
57 bool HasObservers();
58
40 // Dispatches a click event to the observers. 59 // Dispatches a click event to the observers.
41 void DispatchClickEvent(); 60 void DispatchClickEvent();
42 61
62 protected:
63 // Invoked after a call to SetContextMenu() to let the platform-specific
64 // subclass update the native context menu based on the new model. If NULL is
65 // passed, subclass should destroy the native context menu.
66 virtual void ResetContextMenu(menus::MenuModel* model) = 0;
67
43 private: 68 private:
44 ObserverList<Observer> observers_; 69 ObserverList<Observer> observers_;
70 // Context menu, if any.
71 scoped_ptr<menus::MenuModel> context_menu_contents_;
45 DISALLOW_COPY_AND_ASSIGN(StatusIcon); 72 DISALLOW_COPY_AND_ASSIGN(StatusIcon);
46 }; 73 };
47 74
48 #endif // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_ 75 #endif // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
OLDNEW
« no previous file with comments | « chrome/browser/gtk/status_icons/status_icon_gtk.cc ('k') | chrome/browser/status_icons/status_icon.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698