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

Side by Side Diff: ui/message_center/message_center.h

Issue 12326091: Made notification center notifications collapsed and expandable. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Implemented review suggestions. Created 7 years, 9 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 5 #ifndef UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
6 #define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 6 #define UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "base/observer_list.h" 11 #include "base/observer_list.h"
12 #include "ui/gfx/native_widget_types.h" 12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/message_center/message_center_export.h" 13 #include "ui/message_center/message_center_export.h"
14 #include "ui/message_center/notification_change_delegate.h"
14 #include "ui/message_center/notification_list.h" 15 #include "ui/message_center/notification_list.h"
15 #include "ui/message_center/notification_types.h" 16 #include "ui/message_center/notification_types.h"
16 17
17 namespace base { 18 namespace base {
18 class DictionaryValue; 19 class DictionaryValue;
19 } 20 }
20 21
21 // Class for managing the NotificationList. The client (e.g. Chrome) calls 22 // Class for managing the NotificationList. The client (e.g. Chrome) calls
22 // [Add|Remove|Update]Notification to create and update notifications in the 23 // [Add|Remove|Update]Notification to create and update notifications in the
23 // list. It can also implement Delegate to receive callbacks when a 24 // list. It can also implement Delegate to receive callbacks when a
24 // notification is removed (closed), or clicked on. 25 // notification is removed (closed), or clicked on.
25 // If an Observer is provided, it will be informed when the notification list 26 // If an Observer is provided, it will be informed when the notification list
26 // changes, and is expected to handle creating, showing, and hiding of any 27 // changes, and is expected to handle creating, showing, and hiding of any
27 // bubbles. 28 // bubbles.
28 29
29 namespace message_center { 30 namespace message_center {
30 31
31 class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationList::Delegate { 32 class MESSAGE_CENTER_EXPORT MessageCenter : public NotificationChangeDelegate,
33 public NotificationList::Delegate {
32 public: 34 public:
33 // Class that hosts the message center. 35 // Class that hosts the message center.
34 class MESSAGE_CENTER_EXPORT Observer { 36 class MESSAGE_CENTER_EXPORT Observer {
35 public: 37 public:
36 // Called when the notification list has changed. |new_notification| will 38 // Called when the notification list has changed. |new_notification| will
37 // be true if a notification was added or updated. 39 // be true if a notification was added or updated.
38 virtual void OnMessageCenterChanged(bool new_notification) = 0; 40 virtual void OnMessageCenterChanged(bool new_notification) = 0;
39 protected: 41 protected:
40 virtual ~Observer() {} 42 virtual ~Observer() {}
41 }; 43 };
42 44
43 class MESSAGE_CENTER_EXPORT Delegate { 45 class MESSAGE_CENTER_EXPORT Delegate {
44 public: 46 public:
47 virtual ~Delegate();
48
45 // Called when the notification associated with |notification_id| is 49 // Called when the notification associated with |notification_id| is
46 // removed (i.e. closed by the user). 50 // removed (i.e. closed by the user).
47 virtual void NotificationRemoved(const std::string& notification_id, 51 virtual void NotificationRemoved(const std::string& notification_id,
48 bool by_user) = 0; 52 bool by_user) = 0;
49 53
50 // Request to disable the extension associated with |notification_id|. 54 // Request to disable the extension associated with |notification_id|.
51 virtual void DisableExtension(const std::string& notification_id) = 0; 55 virtual void DisableExtension(const std::string& notification_id) = 0;
52 56
53 // Request to disable notifications from the source of |notification_id|. 57 // Request to disable notifications from the source of |notification_id|.
54 virtual void DisableNotificationsFromSource( 58 virtual void DisableNotificationsFromSource(
(...skipping 10 matching lines...) Expand all
65 // Called when the notification body is clicked on. 69 // Called when the notification body is clicked on.
66 virtual void OnClicked(const std::string& notification_id) = 0; 70 virtual void OnClicked(const std::string& notification_id) = 0;
67 71
68 // Called when a button in a notification is clicked. |button_index| 72 // Called when a button in a notification is clicked. |button_index|
69 // indicates which button was clicked, zero-indexed (button one is 0, 73 // indicates which button was clicked, zero-indexed (button one is 0,
70 // button two is 1). 74 // button two is 1).
71 // 75 //
72 // TODO(miket): consider providing default implementations for the pure 76 // TODO(miket): consider providing default implementations for the pure
73 // virtuals above, to avoid changing so many files in disparate parts of 77 // virtuals above, to avoid changing so many files in disparate parts of
74 // the codebase each time we enhance this interface. 78 // the codebase each time we enhance this interface.
75 virtual void OnButtonClicked(const std::string& id, int button_index); 79 virtual void OnButtonClicked(const std::string& id, int button_index) = 0;
76
77 protected:
78 virtual ~Delegate() {}
79 }; 80 };
80 81
81 MessageCenter(); 82 MessageCenter();
82 virtual ~MessageCenter(); 83 virtual ~MessageCenter();
83 84
84 // Called to set the delegate. Generally called only once, except in tests. 85 // Called to set the delegate. Generally called only once, except in tests.
85 // Changing the delegate does not affect notifications in its 86 // Changing the delegate does not affect notifications in its
86 // NotificationList. 87 // NotificationList.
87 void SetDelegate(Delegate* delegate); 88 void SetDelegate(Delegate* delegate);
88 89
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 void SetNotificationImage(const std::string& notification_id, 133 void SetNotificationImage(const std::string& notification_id,
133 const gfx::ImageSkia& image); 134 const gfx::ImageSkia& image);
134 135
135 void SetNotificationButtonIcon(const std::string& notification_id, 136 void SetNotificationButtonIcon(const std::string& notification_id,
136 int button_index, 137 int button_index,
137 const gfx::ImageSkia& image); 138 const gfx::ImageSkia& image);
138 139
139 NotificationList* notification_list() { return notification_list_.get(); } 140 NotificationList* notification_list() { return notification_list_.get(); }
140 bool quiet_mode() const { return notification_list_->quiet_mode(); } 141 bool quiet_mode() const { return notification_list_->quiet_mode(); }
141 142
142 // Overridden from NotificationList::Delegate. 143 // Overridden from NotificationChangeDelegate:
143 virtual void SendRemoveNotification(const std::string& id, 144 virtual void RemoveNotification(const std::string& id, bool by_user) OVERRIDE;
144 bool by_user) OVERRIDE; 145 virtual void RemoveAllNotifications(bool by_user) OVERRIDE;
145 virtual void SendRemoveAllNotifications(bool by_user) OVERRIDE; 146 virtual void DisableNotificationsByExtension(const std::string& id) OVERRIDE;
146 virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE; 147 virtual void DisableNotificationsByUrl(const std::string& id) OVERRIDE;
147 virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE;
148 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE; 148 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE;
149 virtual void ShowNotificationSettingsDialog(gfx::NativeView context) OVERRIDE; 149 virtual void ShowNotificationSettingsDialog(gfx::NativeView context) OVERRIDE;
150 virtual void OnNotificationClicked(const std::string& id) OVERRIDE; 150 virtual void OnExpanded(const std::string& id) OVERRIDE;
151 virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE; 151 virtual void OnClicked(const std::string& id) OVERRIDE;
152 virtual void OnButtonClicked(const std::string& id, int button_index) 152 virtual void OnButtonClicked(const std::string& id, int button_index)
153 OVERRIDE; 153 OVERRIDE;
154 virtual NotificationList* GetNotificationList() OVERRIDE; 154
155 // Overridden from NotificationList::Delegate:
156 virtual void NotificationWasRemoved(const std::string& id,
157 bool by_user) OVERRIDE;
158 virtual void AllNotificationsWereRemoved(bool by_user) OVERRIDE;
dharcourt 2013/03/04 21:17:52 It turned out no one was using this so I pruned it
159 virtual void OnQuietModeChanged(bool quiet_mode) OVERRIDE;
155 160
156 private: 161 private:
157 // Calls OnMessageCenterChanged on each observer. 162 // Calls OnMessageCenterChanged on each observer.
158 void NotifyMessageCenterChanged(bool new_notification); 163 void NotifyMessageCenterChanged(bool new_notification);
159 164
160 scoped_ptr<NotificationList> notification_list_; 165 scoped_ptr<NotificationList> notification_list_;
161 ObserverList<Observer> observer_list_; 166 ObserverList<Observer> observer_list_;
162 Delegate* delegate_; 167 Delegate* delegate_;
163 168
164 DISALLOW_COPY_AND_ASSIGN(MessageCenter); 169 DISALLOW_COPY_AND_ASSIGN(MessageCenter);
165 }; 170 };
166 171
167 } // namespace message_center 172 } // namespace message_center
168 173
169 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_ 174 #endif // UI_MESSAGE_CENTER_MESSAGE_CENTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698