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

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

Issue 10408039: status_icons: Factor out status icon observer into its own header file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/basictypes.h"
9 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
10 #include "base/observer_list.h" 11 #include "base/observer_list.h"
11 #include "base/string16.h" 12 #include "base/string16.h"
12 13
13 class SkBitmap; 14 class SkBitmap;
14 15
15 namespace ui { 16 namespace ui {
16 class MenuModel; 17 class MenuModel;
17 } 18 }
18 19
20 class StatusIconObserver;
21
19 class StatusIcon { 22 class StatusIcon {
20 public: 23 public:
21 StatusIcon(); 24 StatusIcon();
22 virtual ~StatusIcon(); 25 virtual ~StatusIcon();
23 26
24 // Sets the image associated with this status icon. 27 // Sets the image associated with this status icon.
25 virtual void SetImage(const SkBitmap& image) = 0; 28 virtual void SetImage(const SkBitmap& image) = 0;
26 29
27 // Sets the image associated with this status icon when pressed. 30 // Sets the image associated with this status icon when pressed.
28 virtual void SetPressedImage(const SkBitmap& image) = 0; 31 virtual void SetPressedImage(const SkBitmap& image) = 0;
29 32
30 // Sets the hover text for this status icon. 33 // Sets the hover text for this status icon.
31 virtual void SetToolTip(const string16& tool_tip) = 0; 34 virtual void SetToolTip(const string16& tool_tip) = 0;
32 35
33 // Displays a notification balloon with the specified contents. 36 // Displays a notification balloon with the specified contents.
34 // Depending on the platform it might not appear by the icon tray. 37 // Depending on the platform it might not appear by the icon tray.
35 virtual void DisplayBalloon(const SkBitmap& icon, 38 virtual void DisplayBalloon(const SkBitmap& icon,
36 const string16& title, 39 const string16& title,
37 const string16& contents) = 0; 40 const string16& contents) = 0;
38 41
39 // Set the context menu for this icon. The icon takes ownership of the passed 42 // Set the context menu for this icon. The icon takes ownership of the passed
40 // context menu. Passing NULL results in no menu at all. 43 // context menu. Passing NULL results in no menu at all.
41 void SetContextMenu(ui::MenuModel* menu); 44 void SetContextMenu(ui::MenuModel* menu);
42 45
43 class Observer {
44 public:
45 virtual ~Observer() {}
46
47 // Called when the user clicks on the system tray icon. Clicks that result
48 // in the context menu being displayed will not be passed to this observer
49 // (i.e. if there's a context menu set on this status icon, and the user
50 // right clicks on the icon to display the context menu, OnClicked will not
51 // be called).
52 // Note: Chrome OS displays the context menu on left button clicks.
53 // This will only be fired for this platform if no context menu is present.
54 virtual void OnClicked() = 0;
55 };
56
57 // Adds/Removes an observer for clicks on the status icon. If an observer is 46 // Adds/Removes an observer for clicks on the status icon. If an observer is
58 // registered, then left clicks on the status icon will result in the observer 47 // registered, then left clicks on the status icon will result in the observer
59 // being called, otherwise, both left and right clicks will display the 48 // being called, otherwise, both left and right clicks will display the
60 // context menu (if any). 49 // context menu (if any).
61 void AddObserver(Observer* observer); 50 void AddObserver(StatusIconObserver* observer);
62 void RemoveObserver(Observer* observer); 51 void RemoveObserver(StatusIconObserver* observer);
63 52
64 // Returns true if there are registered click observers. 53 // Returns true if there are registered click observers.
65 bool HasObservers(); 54 bool HasObservers() const;
66 55
67 // Dispatches a click event to the observers. 56 // Dispatches a click event to the observers.
68 void DispatchClickEvent(); 57 void DispatchClickEvent();
69 58
70 protected: 59 protected:
71 // Invoked after a call to SetContextMenu() to let the platform-specific 60 // Invoked after a call to SetContextMenu() to let the platform-specific
72 // subclass update the native context menu based on the new model. If NULL is 61 // subclass update the native context menu based on the new model. If NULL is
73 // passed, subclass should destroy the native context menu. 62 // passed, subclass should destroy the native context menu.
74 virtual void UpdatePlatformContextMenu(ui::MenuModel* model) = 0; 63 virtual void UpdatePlatformContextMenu(ui::MenuModel* model) = 0;
75 64
76 private: 65 private:
77 ObserverList<Observer> observers_; 66 ObserverList<StatusIconObserver> observers_;
67
78 // Context menu, if any. 68 // Context menu, if any.
79 scoped_ptr<ui::MenuModel> context_menu_contents_; 69 scoped_ptr<ui::MenuModel> context_menu_contents_;
70
80 DISALLOW_COPY_AND_ASSIGN(StatusIcon); 71 DISALLOW_COPY_AND_ASSIGN(StatusIcon);
81 }; 72 };
82 73
83 #endif // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_ 74 #endif // CHROME_BROWSER_STATUS_ICONS_STATUS_ICON_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/status_icons/status_icon.cc » ('j') | chrome/browser/status_icons/status_icon_observer.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698