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

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

Issue 114323002: Fixes the context menu for a notification. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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_tray.h" 5 #include "ui/message_center/message_center_tray.h"
6 6
7 #include "base/observer_list.h" 7 #include "base/observer_list.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "grit/ui_strings.h" 9 #include "grit/ui_strings.h"
10 #include "ui/base/l10n/l10n_util.h" 10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/message_center/message_center.h" 11 #include "ui/message_center/message_center.h"
12 #include "ui/message_center/message_center_tray_delegate.h" 12 #include "ui/message_center/message_center_tray_delegate.h"
13 #include "ui/message_center/message_center_types.h" 13 #include "ui/message_center/message_center_types.h"
14 #include "ui/message_center/notification_blocker.h" 14 #include "ui/message_center/notification_blocker.h"
15 15
16 namespace message_center { 16 namespace message_center {
17 17
18 namespace {
19
20 // Menu constants
21 const int kTogglePermissionCommand = 0;
22 const int kShowSettingsCommand = 1;
23
24 }
25
18 MessageCenterTray::MessageCenterTray( 26 MessageCenterTray::MessageCenterTray(
19 MessageCenterTrayDelegate* delegate, 27 MessageCenterTrayDelegate* delegate,
20 message_center::MessageCenter* message_center) 28 message_center::MessageCenter* message_center)
21 : message_center_(message_center), 29 : message_center_(message_center),
22 message_center_visible_(false), 30 message_center_visible_(false),
23 popups_visible_(false), 31 popups_visible_(false),
24 delegate_(delegate) { 32 delegate_(delegate),
33 context_menu_notification_(NULL) {
25 message_center_->AddObserver(this); 34 message_center_->AddObserver(this);
26 } 35 }
27 36
28 MessageCenterTray::~MessageCenterTray() { 37 MessageCenterTray::~MessageCenterTray() {
29 message_center_->RemoveObserver(this); 38 message_center_->RemoveObserver(this);
30 } 39 }
31 40
32 bool MessageCenterTray::ShowMessageCenterBubble() { 41 bool MessageCenterTray::ShowMessageCenterBubble() {
33 if (message_center_visible_) 42 if (message_center_visible_)
34 return true; 43 return true;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 void MessageCenterTray::ShowNotifierSettingsBubble() { 118 void MessageCenterTray::ShowNotifierSettingsBubble() {
110 if (popups_visible_) 119 if (popups_visible_)
111 HidePopupBubbleInternal(); 120 HidePopupBubbleInternal();
112 121
113 message_center_visible_ = delegate_->ShowNotifierSettings(); 122 message_center_visible_ = delegate_->ShowNotifierSettings();
114 message_center_->SetVisibility(message_center::VISIBILITY_SETTINGS); 123 message_center_->SetVisibility(message_center::VISIBILITY_SETTINGS);
115 124
116 NotifyMessageCenterTrayChanged(); 125 NotifyMessageCenterTrayChanged();
117 } 126 }
118 127
128 scoped_ptr<ui::MenuModel> MessageCenterTray::CreateMenuModelForNotification(
129 const std::string& id) {
130 scoped_ptr<ui::SimpleMenuModel> model(new ui::SimpleMenuModel(this));
131
132 // Find the notification for |id| to get the display source.
133 context_menu_notification_ = NULL;
134 const NotificationList::Notifications& notifications =
135 message_center_->GetVisibleNotifications();
136 for (NotificationList::Notifications::const_iterator iter =
137 notifications.begin(); iter != notifications.end(); ++iter) {
138 if ((*iter)->id() == id) {
139 context_menu_notification_ = *iter;
140 break;
141 }
142 }
stevenjb 2013/12/12 21:19:46 This seems like it ought to be in MessageCenter, e
Jun Mukai 2013/12/14 01:13:14 This actually depends on the tray, for executing S
143 if (!context_menu_notification_)
144 return model.PassAs<ui::MenuModel>();
145
146 // Add 'disable notifications' menu item.
147 if (!context_menu_notification_->display_source().empty()) {
148 model->AddItem(kTogglePermissionCommand,
149 l10n_util::GetStringFUTF16(
150 IDS_MESSAGE_CENTER_NOTIFIER_DISABLE,
151 context_menu_notification_->display_source()));
152 }
153 // Add settings menu item.
154 model->AddItem(kShowSettingsCommand,
155 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS));
156
157 return model.PassAs<ui::MenuModel>();
158 }
159
119 void MessageCenterTray::OnNotificationAdded( 160 void MessageCenterTray::OnNotificationAdded(
120 const std::string& notification_id) { 161 const std::string& notification_id) {
121 OnMessageCenterChanged(); 162 OnMessageCenterChanged();
122 } 163 }
123 164
124 void MessageCenterTray::OnNotificationRemoved( 165 void MessageCenterTray::OnNotificationRemoved(
125 const std::string& notification_id, 166 const std::string& notification_id,
126 bool by_user) { 167 bool by_user) {
127 OnMessageCenterChanged(); 168 OnMessageCenterChanged();
128 } 169 }
(...skipping 22 matching lines...) Expand all
151 } 192 }
152 193
153 void MessageCenterTray::OnQuietModeChanged(bool in_quiet_mode) { 194 void MessageCenterTray::OnQuietModeChanged(bool in_quiet_mode) {
154 NotifyMessageCenterTrayChanged(); 195 NotifyMessageCenterTrayChanged();
155 } 196 }
156 197
157 void MessageCenterTray::OnBlockingStateChanged(NotificationBlocker* blocker) { 198 void MessageCenterTray::OnBlockingStateChanged(NotificationBlocker* blocker) {
158 OnMessageCenterChanged(); 199 OnMessageCenterChanged();
159 } 200 }
160 201
202 bool MessageCenterTray::IsCommandIdChecked(int command_id) const {
203 return false;
204 }
205
206 bool MessageCenterTray::IsCommandIdEnabled(int command_id) const {
207 return delegate_->IsContextMenuEnabled();
208 }
209
210 bool MessageCenterTray::GetAcceleratorForCommandId(
211 int command_id,
212 ui::Accelerator* accelerator) {
213 return false;
214 }
215
216 void MessageCenterTray::ExecuteCommand(int command_id, int event_flags) {
217 switch (command_id) {
218 case kTogglePermissionCommand:
219 message_center_->DisableNotificationsByNotifier(
220 context_menu_notification_->notifier_id());
221 break;
222 case kShowSettingsCommand:
223 ShowNotifierSettingsBubble();
224 break;
225 default:
226 NOTREACHED();
227 }
228 }
229
230 void MessageCenterTray::MenuClosed(ui::SimpleMenuModel* source) {
231 context_menu_notification_ = NULL;
232 }
233
161 void MessageCenterTray::OnMessageCenterChanged() { 234 void MessageCenterTray::OnMessageCenterChanged() {
162 if (message_center_visible_ && message_center_->NotificationCount() == 0) 235 if (message_center_visible_ && message_center_->NotificationCount() == 0)
163 HideMessageCenterBubble(); 236 HideMessageCenterBubble();
164 237
165 if (popups_visible_ && !message_center_->HasPopupNotifications()) 238 if (popups_visible_ && !message_center_->HasPopupNotifications())
166 HidePopupBubbleInternal(); 239 HidePopupBubbleInternal();
167 else if (!popups_visible_ && message_center_->HasPopupNotifications()) 240 else if (!popups_visible_ && message_center_->HasPopupNotifications())
168 ShowPopupBubble(); 241 ShowPopupBubble();
169 242
170 NotifyMessageCenterTrayChanged(); 243 NotifyMessageCenterTrayChanged();
171 } 244 }
172 245
173 void MessageCenterTray::NotifyMessageCenterTrayChanged() { 246 void MessageCenterTray::NotifyMessageCenterTrayChanged() {
174 delegate_->OnMessageCenterTrayChanged(); 247 delegate_->OnMessageCenterTrayChanged();
175 } 248 }
176 249
177 } // namespace message_center 250 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698