| 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..fff1fd25b220a9e6fbedc22b0e2030bd9166fb81 100644
|
| --- a/ui/message_center/message_center_tray.cc
|
| +++ b/ui/message_center/message_center_tray.cc
|
| @@ -8,6 +8,7 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "grit/ui_strings.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| +#include "ui/base/models/simple_menu_model.h"
|
| #include "ui/message_center/message_center.h"
|
| #include "ui/message_center/message_center_tray_delegate.h"
|
| #include "ui/message_center/message_center_types.h"
|
| @@ -15,6 +16,85 @@
|
|
|
| namespace message_center {
|
|
|
| +namespace {
|
| +
|
| +// Menu constants
|
| +const int kTogglePermissionCommand = 0;
|
| +const int kShowSettingsCommand = 1;
|
| +
|
| +// The model of the context menu for a notification card.
|
| +class NotificationMenuModel : public ui::SimpleMenuModel,
|
| + public ui::SimpleMenuModel::Delegate {
|
| + public:
|
| + NotificationMenuModel(MessageCenterTray* tray,
|
| + const NotifierId& notifier_id,
|
| + const base::string16& display_source);
|
| + virtual ~NotificationMenuModel();
|
| +
|
| + // Overridden from ui::SimpleMenuModel::Delegate:
|
| + virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
|
| + virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
|
| + virtual bool GetAcceleratorForCommandId(
|
| + int command_id,
|
| + ui::Accelerator* accelerator) OVERRIDE;
|
| + virtual void ExecuteCommand(int command_id, int event_flags) OVERRIDE;
|
| +
|
| + private:
|
| + MessageCenterTray* tray_;
|
| + NotifierId notifier_id_;
|
| + DISALLOW_COPY_AND_ASSIGN(NotificationMenuModel);
|
| +};
|
| +
|
| +NotificationMenuModel::NotificationMenuModel(
|
| + MessageCenterTray* tray,
|
| + const NotifierId& notifier_id,
|
| + const base::string16& display_source)
|
| + : ui::SimpleMenuModel(this),
|
| + tray_(tray),
|
| + notifier_id_(notifier_id) {
|
| + // Add 'disable notifications' menu item.
|
| + if (!display_source.empty()) {
|
| + AddItem(kTogglePermissionCommand,
|
| + l10n_util::GetStringFUTF16(IDS_MESSAGE_CENTER_NOTIFIER_DISABLE,
|
| + display_source));
|
| + }
|
| + // Add settings menu item.
|
| + AddItem(kShowSettingsCommand,
|
| + l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS));
|
| +}
|
| +
|
| +NotificationMenuModel::~NotificationMenuModel() {
|
| +}
|
| +
|
| +bool NotificationMenuModel::IsCommandIdChecked(int command_id) const {
|
| + return false;
|
| +}
|
| +
|
| +bool NotificationMenuModel::IsCommandIdEnabled(int command_id) const {
|
| + return tray_->delegate()->IsContextMenuEnabled();
|
| +}
|
| +
|
| +bool NotificationMenuModel::GetAcceleratorForCommandId(
|
| + int command_id,
|
| + ui::Accelerator* accelerator) {
|
| + return false;
|
| +}
|
| +
|
| +void NotificationMenuModel::ExecuteCommand(int command_id, int event_flags) {
|
| + switch (command_id) {
|
| + case kTogglePermissionCommand:
|
| + tray_->message_center()->DisableNotificationsByNotifier(notifier_id_);
|
| + break;
|
| + case kShowSettingsCommand:
|
| + tray_->ShowNotifierSettingsBubble();
|
| + break;
|
| + default:
|
| + NOTREACHED();
|
| + }
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| MessageCenterTray::MessageCenterTray(
|
| MessageCenterTrayDelegate* delegate,
|
| message_center::MessageCenter* message_center)
|
| @@ -116,6 +196,13 @@ void MessageCenterTray::ShowNotifierSettingsBubble() {
|
| NotifyMessageCenterTrayChanged();
|
| }
|
|
|
| +scoped_ptr<ui::MenuModel> MessageCenterTray::CreateNotificationMenuModel(
|
| + const NotifierId& notifier_id,
|
| + const base::string16& display_source) {
|
| + return scoped_ptr<ui::MenuModel>(new NotificationMenuModel(
|
| + this, notifier_id, display_source));
|
| +}
|
| +
|
| void MessageCenterTray::OnNotificationAdded(
|
| const std::string& notification_id) {
|
| OnMessageCenterChanged();
|
|
|