Chromium Code Reviews| Index: ui/message_center/message_center_tray.cc |
| diff --git a/ui/message_center/message_center_tray.cc b/ui/message_center/message_center_tray.cc |
| index 58e5868a1e8b5edc329fabec409472ec80486f08..86fdbd6c712f21032b1943daa9827e4f284edbde 100644 |
| --- a/ui/message_center/message_center_tray.cc |
| +++ b/ui/message_center/message_center_tray.cc |
| @@ -15,13 +15,22 @@ |
| namespace message_center { |
| +namespace { |
| + |
| +// Menu constants |
| +const int kTogglePermissionCommand = 0; |
| +const int kShowSettingsCommand = 1; |
| + |
| +} |
| + |
| MessageCenterTray::MessageCenterTray( |
| MessageCenterTrayDelegate* delegate, |
| message_center::MessageCenter* message_center) |
| : message_center_(message_center), |
| message_center_visible_(false), |
| popups_visible_(false), |
| - delegate_(delegate) { |
| + delegate_(delegate), |
| + context_menu_notification_(NULL) { |
| message_center_->AddObserver(this); |
| } |
| @@ -116,6 +125,38 @@ void MessageCenterTray::ShowNotifierSettingsBubble() { |
| NotifyMessageCenterTrayChanged(); |
| } |
| +scoped_ptr<ui::MenuModel> MessageCenterTray::CreateMenuModelForNotification( |
| + const std::string& id) { |
| + scoped_ptr<ui::SimpleMenuModel> model(new ui::SimpleMenuModel(this)); |
| + |
| + // Find the notification for |id| to get the display source. |
| + context_menu_notification_ = NULL; |
| + const NotificationList::Notifications& notifications = |
| + message_center_->GetVisibleNotifications(); |
| + for (NotificationList::Notifications::const_iterator iter = |
| + notifications.begin(); iter != notifications.end(); ++iter) { |
| + if ((*iter)->id() == id) { |
| + context_menu_notification_ = *iter; |
| + break; |
| + } |
| + } |
|
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
|
| + if (!context_menu_notification_) |
| + return model.PassAs<ui::MenuModel>(); |
| + |
| + // Add 'disable notifications' menu item. |
| + if (!context_menu_notification_->display_source().empty()) { |
| + model->AddItem(kTogglePermissionCommand, |
| + l10n_util::GetStringFUTF16( |
| + IDS_MESSAGE_CENTER_NOTIFIER_DISABLE, |
| + context_menu_notification_->display_source())); |
| + } |
| + // Add settings menu item. |
| + model->AddItem(kShowSettingsCommand, |
| + l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS)); |
| + |
| + return model.PassAs<ui::MenuModel>(); |
| +} |
| + |
| void MessageCenterTray::OnNotificationAdded( |
| const std::string& notification_id) { |
| OnMessageCenterChanged(); |
| @@ -158,6 +199,38 @@ void MessageCenterTray::OnBlockingStateChanged(NotificationBlocker* blocker) { |
| OnMessageCenterChanged(); |
| } |
| +bool MessageCenterTray::IsCommandIdChecked(int command_id) const { |
| + return false; |
| +} |
| + |
| +bool MessageCenterTray::IsCommandIdEnabled(int command_id) const { |
| + return delegate_->IsContextMenuEnabled(); |
| +} |
| + |
| +bool MessageCenterTray::GetAcceleratorForCommandId( |
| + int command_id, |
| + ui::Accelerator* accelerator) { |
| + return false; |
| +} |
| + |
| +void MessageCenterTray::ExecuteCommand(int command_id, int event_flags) { |
| + switch (command_id) { |
| + case kTogglePermissionCommand: |
| + message_center_->DisableNotificationsByNotifier( |
| + context_menu_notification_->notifier_id()); |
| + break; |
| + case kShowSettingsCommand: |
| + ShowNotifierSettingsBubble(); |
| + break; |
| + default: |
| + NOTREACHED(); |
| + } |
| +} |
| + |
| +void MessageCenterTray::MenuClosed(ui::SimpleMenuModel* source) { |
| + context_menu_notification_ = NULL; |
| +} |
| + |
| void MessageCenterTray::OnMessageCenterChanged() { |
| if (message_center_visible_ && message_center_->NotificationCount() == 0) |
| HideMessageCenterBubble(); |