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

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

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 #include "ui/message_center/message_center.h" 5 #include "ui/message_center/message_center.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/singleton.h" 8 #include "base/memory/singleton.h"
9 #include "base/observer_list.h" 9 #include "base/observer_list.h"
10 #include "ui/message_center/notification.h" 10 #include "ui/message_center/notification.h"
11 #include "ui/message_center/notification_list.h" 11 #include "ui/message_center/notification_list.h"
12 12
13 namespace message_center { 13 namespace message_center {
14 14
15 MessageCenter::Delegate::~Delegate() {
16 }
dharcourt 2013/03/02 02:08:02 To avoid an "undefined reference to vtable..." lin
17
15 //------------------------------------------------------------------------------ 18 //------------------------------------------------------------------------------
16 MessageCenter::MessageCenter() 19 MessageCenter::MessageCenter()
17 : delegate_(NULL) { 20 : delegate_(NULL) {
18 notification_list_.reset(new NotificationList(this)); 21 notification_list_.reset(new NotificationList(this));
19 } 22 }
20 23
21 MessageCenter::~MessageCenter() { 24 MessageCenter::~MessageCenter() {
22 notification_list_.reset(); 25 notification_list_.reset();
23 } 26 }
24 27
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 99
97 void MessageCenter::SetNotificationButtonIcon( 100 void MessageCenter::SetNotificationButtonIcon(
98 const std::string& notification_id, int button_index, 101 const std::string& notification_id, int button_index,
99 const gfx::ImageSkia& image) { 102 const gfx::ImageSkia& image) {
100 if (notification_list_->SetNotificationButtonIcon(notification_id, 103 if (notification_list_->SetNotificationButtonIcon(notification_id,
101 button_index, image)) 104 button_index, image))
102 NotifyMessageCenterChanged(true); 105 NotifyMessageCenterChanged(true);
103 } 106 }
104 107
105 //------------------------------------------------------------------------------ 108 //------------------------------------------------------------------------------
106 // Overridden from NotificationList::Delegate. 109 // Overridden from NotificationChangeDelegate:
107 110
108 void MessageCenter::SendRemoveNotification(const std::string& id, 111 void MessageCenter::RemoveNotification(const std::string& id, bool by_user) {
109 bool by_user) {
110 if (delegate_) 112 if (delegate_)
111 delegate_->NotificationRemoved(id, by_user); 113 delegate_->NotificationRemoved(id, by_user);
112 } 114 }
113 115
114 void MessageCenter::SendRemoveAllNotifications(bool by_user) { 116 void MessageCenter::RemoveAllNotifications(bool by_user) {
115 if (delegate_) { 117 if (delegate_) {
116 const NotificationList::Notifications& notifications = 118 const NotificationList::Notifications& notifications =
117 notification_list_->GetNotifications(); 119 notification_list_->GetNotifications();
118 for (NotificationList::Notifications::const_iterator loopiter = 120 for (NotificationList::Notifications::const_iterator loopiter =
119 notifications.begin(); 121 notifications.begin();
120 loopiter != notifications.end(); ) { 122 loopiter != notifications.end(); ) {
121 NotificationList::Notifications::const_iterator curiter = loopiter++; 123 NotificationList::Notifications::const_iterator curiter = loopiter++;
122 std::string notification_id = (*curiter)->id(); 124 std::string notification_id = (*curiter)->id();
123 // May call RemoveNotification and erase curiter. 125 // May call RemoveNotification and erase curiter.
124 delegate_->NotificationRemoved(notification_id, by_user); 126 delegate_->NotificationRemoved(notification_id, by_user);
125 } 127 }
126 } 128 }
127 } 129 }
128 130
129 void MessageCenter::DisableNotificationByExtension( 131 void MessageCenter::DisableNotificationsByExtension(
130 const std::string& id) { 132 const std::string& id) {
131 if (delegate_) 133 if (delegate_)
132 delegate_->DisableExtension(id); 134 delegate_->DisableExtension(id);
133 // When we disable notifications, we remove any existing matching 135 // When we disable notifications, we remove any existing matching
134 // notifications to avoid adding complicated UI to re-enable the source. 136 // notifications to avoid adding complicated UI to re-enable the source.
135 notification_list_->SendRemoveNotificationsByExtension(id); 137 notification_list_->SendRemoveNotificationsByExtension(id);
136 } 138 }
137 139
138 void MessageCenter::DisableNotificationByUrl(const std::string& id) { 140 void MessageCenter::DisableNotificationsByUrl(const std::string& id) {
139 if (delegate_) 141 if (delegate_)
140 delegate_->DisableNotificationsFromSource(id); 142 delegate_->DisableNotificationsFromSource(id);
141 notification_list_->SendRemoveNotificationsBySource(id); 143 notification_list_->SendRemoveNotificationsBySource(id);
142 } 144 }
143 145
144 void MessageCenter::ShowNotificationSettings(const std::string& id) { 146 void MessageCenter::ShowNotificationSettings(const std::string& id) {
145 if (delegate_) 147 if (delegate_)
146 delegate_->ShowSettings(id); 148 delegate_->ShowSettings(id);
147 } 149 }
148 150
149 void MessageCenter::ShowNotificationSettingsDialog(gfx::NativeView context) { 151 void MessageCenter::ShowNotificationSettingsDialog(gfx::NativeView context) {
150 if (delegate_) 152 if (delegate_)
151 delegate_->ShowSettingsDialog(context); 153 delegate_->ShowSettingsDialog(context);
152 } 154 }
153 155
154 void MessageCenter::OnNotificationClicked(const std::string& id) { 156 void MessageCenter::OnExpanded(const std::string& id) {
157 notification_list_->MarkNotificationAsExpanded(id);
158 }
159
160 void MessageCenter::OnClicked(const std::string& id) {
155 if (delegate_) 161 if (delegate_)
156 delegate_->OnClicked(id); 162 delegate_->OnClicked(id);
157 if (HasPopupNotifications()) { 163 if (HasPopupNotifications()) {
158 notification_list_->MarkSinglePopupAsShown(id, true); 164 notification_list_->MarkSinglePopupAsShown(id, true);
159 NotifyMessageCenterChanged(false); 165 NotifyMessageCenterChanged(false);
160 } 166 }
161 } 167 }
162 168
163 void MessageCenter::OnQuietModeChanged(bool quiet_mode) {
164 NotifyMessageCenterChanged(true);
165 }
166
167 void MessageCenter::OnButtonClicked(const std::string& id, int button_index) { 169 void MessageCenter::OnButtonClicked(const std::string& id, int button_index) {
168 if (delegate_) 170 if (delegate_)
169 delegate_->OnButtonClicked(id, button_index); 171 delegate_->OnButtonClicked(id, button_index);
170 if (HasPopupNotifications()) { 172 if (HasPopupNotifications()) {
171 notification_list_->MarkSinglePopupAsShown(id, true); 173 notification_list_->MarkSinglePopupAsShown(id, true);
172 NotifyMessageCenterChanged(false); 174 NotifyMessageCenterChanged(false);
173 } 175 }
174 } 176 }
175 177
176 NotificationList* MessageCenter::GetNotificationList() { 178 //------------------------------------------------------------------------------
177 return notification_list_.get(); 179 // Overridden from NotificationList::Delegate:
180
181 void MessageCenter::NotificationWasRemoved(const std::string& id,
182 bool by_user) {
183 RemoveNotification(id, by_user);
178 } 184 }
179 185
180 void MessageCenter::Delegate::OnButtonClicked(const std::string& id, 186 void MessageCenter::AllNotificationsWereRemoved(bool by_user) {
181 int button_index) { 187 RemoveAllNotifications(by_user);
188 }
189
190 void MessageCenter::OnQuietModeChanged(bool quiet_mode) {
191 NotifyMessageCenterChanged(true);
182 } 192 }
183 193
184 //------------------------------------------------------------------------------ 194 //------------------------------------------------------------------------------
185 // Private. 195 // Private.
186 196
187 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) { 197 void MessageCenter::NotifyMessageCenterChanged(bool new_notification) {
188 FOR_EACH_OBSERVER(Observer, 198 FOR_EACH_OBSERVER(Observer,
189 observer_list_, 199 observer_list_,
190 OnMessageCenterChanged(new_notification)); 200 OnMessageCenterChanged(new_notification));
191 } 201 }
192 202
193 203
194 } // namespace message_center 204 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698