| OLD | NEW |
| 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 "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
| 10 #include "ui/base/models/simple_menu_model.h" | 10 #include "ui/base/models/simple_menu_model.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 #include "ui/strings/grit/ui_strings.h" | 15 #include "ui/strings/grit/ui_strings.h" |
| 16 | 16 |
| 17 namespace message_center { | 17 namespace message_center { |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Menu constants | 21 // Menu constants |
| 22 const int kTogglePermissionCommand = 0; | 22 const int kTogglePermissionCommand = 0; |
| 23 |
| 24 #ifdef OS_CHROMEOS |
| 23 const int kShowSettingsCommand = 1; | 25 const int kShowSettingsCommand = 1; |
| 26 #endif |
| 24 | 27 |
| 25 // The model of the context menu for a notification card. | 28 // The model of the context menu for a notification card. |
| 26 class NotificationMenuModel : public ui::SimpleMenuModel, | 29 class NotificationMenuModel : public ui::SimpleMenuModel, |
| 27 public ui::SimpleMenuModel::Delegate { | 30 public ui::SimpleMenuModel::Delegate { |
| 28 public: | 31 public: |
| 29 NotificationMenuModel(MessageCenterTray* tray, | 32 NotificationMenuModel(MessageCenterTray* tray, |
| 30 const NotifierId& notifier_id, | 33 const NotifierId& notifier_id, |
| 31 const base::string16& display_source); | 34 const base::string16& display_source); |
| 32 ~NotificationMenuModel() override; | 35 ~NotificationMenuModel() override; |
| 33 | 36 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 DISALLOW_COPY_AND_ASSIGN(NotificationMenuModel); | 47 DISALLOW_COPY_AND_ASSIGN(NotificationMenuModel); |
| 45 }; | 48 }; |
| 46 | 49 |
| 47 NotificationMenuModel::NotificationMenuModel( | 50 NotificationMenuModel::NotificationMenuModel( |
| 48 MessageCenterTray* tray, | 51 MessageCenterTray* tray, |
| 49 const NotifierId& notifier_id, | 52 const NotifierId& notifier_id, |
| 50 const base::string16& display_source) | 53 const base::string16& display_source) |
| 51 : ui::SimpleMenuModel(this), | 54 : ui::SimpleMenuModel(this), |
| 52 tray_(tray), | 55 tray_(tray), |
| 53 notifier_id_(notifier_id) { | 56 notifier_id_(notifier_id) { |
| 54 // Add 'disable notifications' menu item. | |
| 55 if (!display_source.empty()) { | 57 if (!display_source.empty()) { |
| 56 AddItem(kTogglePermissionCommand, | 58 AddItem(kTogglePermissionCommand, |
| 57 l10n_util::GetStringFUTF16(IDS_MESSAGE_CENTER_NOTIFIER_DISABLE, | 59 l10n_util::GetStringFUTF16(IDS_MESSAGE_CENTER_NOTIFIER_DISABLE, |
| 58 display_source)); | 60 display_source)); |
| 59 } | 61 } |
| 62 |
| 63 #ifdef OS_CHROMEOS |
| 60 // Add settings menu item. | 64 // Add settings menu item. |
| 61 AddItem(kShowSettingsCommand, | 65 AddItem(kShowSettingsCommand, |
| 62 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS)); | 66 l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_SETTINGS)); |
| 67 #endif |
| 63 } | 68 } |
| 64 | 69 |
| 65 NotificationMenuModel::~NotificationMenuModel() { | 70 NotificationMenuModel::~NotificationMenuModel() { |
| 66 } | 71 } |
| 67 | 72 |
| 68 bool NotificationMenuModel::IsCommandIdChecked(int command_id) const { | 73 bool NotificationMenuModel::IsCommandIdChecked(int command_id) const { |
| 69 return false; | 74 return false; |
| 70 } | 75 } |
| 71 | 76 |
| 72 bool NotificationMenuModel::IsCommandIdEnabled(int command_id) const { | 77 bool NotificationMenuModel::IsCommandIdEnabled(int command_id) const { |
| 73 return tray_->delegate()->IsContextMenuEnabled(); | 78 return tray_->delegate()->IsContextMenuEnabled(); |
| 74 } | 79 } |
| 75 | 80 |
| 76 bool NotificationMenuModel::GetAcceleratorForCommandId( | 81 bool NotificationMenuModel::GetAcceleratorForCommandId( |
| 77 int command_id, | 82 int command_id, |
| 78 ui::Accelerator* accelerator) { | 83 ui::Accelerator* accelerator) { |
| 79 return false; | 84 return false; |
| 80 } | 85 } |
| 81 | 86 |
| 82 void NotificationMenuModel::ExecuteCommand(int command_id, int event_flags) { | 87 void NotificationMenuModel::ExecuteCommand(int command_id, int event_flags) { |
| 83 switch (command_id) { | 88 switch (command_id) { |
| 84 case kTogglePermissionCommand: | 89 case kTogglePermissionCommand: |
| 85 tray_->message_center()->DisableNotificationsByNotifier(notifier_id_); | 90 tray_->message_center()->DisableNotificationsByNotifier(notifier_id_); |
| 86 break; | 91 break; |
| 92 #ifdef OS_CHROMEOS |
| 87 case kShowSettingsCommand: | 93 case kShowSettingsCommand: |
| 88 tray_->ShowNotifierSettingsBubble(); | 94 tray_->ShowNotifierSettingsBubble(); |
| 89 break; | 95 break; |
| 96 #endif |
| 90 default: | 97 default: |
| 91 NOTREACHED(); | 98 NOTREACHED(); |
| 92 } | 99 } |
| 93 } | 100 } |
| 94 | 101 |
| 95 } // namespace | 102 } // namespace |
| 96 | 103 |
| 97 MessageCenterTray::MessageCenterTray( | 104 MessageCenterTray::MessageCenterTray( |
| 98 MessageCenterTrayDelegate* delegate, | 105 MessageCenterTrayDelegate* delegate, |
| 99 message_center::MessageCenter* message_center) | 106 message_center::MessageCenter* message_center) |
| 100 : message_center_(message_center), | 107 : message_center_(message_center), |
| 101 message_center_visible_(false), | 108 message_center_visible_(false), |
| 102 popups_visible_(false), | 109 popups_visible_(false), |
| 103 delegate_(delegate) { | 110 delegate_(delegate) { |
| 104 message_center_->AddObserver(this); | 111 message_center_->AddObserver(this); |
| 105 } | 112 } |
| 106 | 113 |
| 107 MessageCenterTray::~MessageCenterTray() { | 114 MessageCenterTray::~MessageCenterTray() { |
| 108 message_center_->RemoveObserver(this); | 115 message_center_->RemoveObserver(this); |
| 109 } | 116 } |
| 110 | 117 |
| 111 bool MessageCenterTray::ShowMessageCenterBubble() { | 118 bool MessageCenterTray::ShowMessageCenterBubble() { |
| 112 if (message_center_visible_) | 119 if (message_center_visible_) |
| 113 return true; | 120 return true; |
| 114 | 121 |
| 115 HidePopupBubbleInternal(); | 122 HidePopupBubbleInternal(); |
| 116 | 123 |
| 117 message_center_visible_ = delegate_->ShowMessageCenter(); | 124 message_center_visible_ = delegate_->ShowMessageCenter(); |
| 118 message_center_->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); | 125 if (message_center_visible_) { |
| 119 NotifyMessageCenterTrayChanged(); | 126 message_center_->SetVisibility(message_center::VISIBILITY_MESSAGE_CENTER); |
| 127 NotifyMessageCenterTrayChanged(); |
| 128 } |
| 120 return message_center_visible_; | 129 return message_center_visible_; |
| 121 } | 130 } |
| 122 | 131 |
| 123 bool MessageCenterTray::HideMessageCenterBubble() { | 132 bool MessageCenterTray::HideMessageCenterBubble() { |
| 124 if (!message_center_visible_) | 133 if (!message_center_visible_) |
| 125 return false; | 134 return false; |
| 126 delegate_->HideMessageCenter(); | 135 delegate_->HideMessageCenter(); |
| 127 MarkMessageCenterHidden(); | 136 MarkMessageCenterHidden(); |
| 128 return true; | 137 return true; |
| 129 } | 138 } |
| 130 | 139 |
| 131 void MessageCenterTray::MarkMessageCenterHidden() { | 140 void MessageCenterTray::MarkMessageCenterHidden() { |
| 132 if (!message_center_visible_) | 141 if (!message_center_visible_) |
| 133 return; | 142 return; |
| 134 message_center_visible_ = false; | 143 message_center_visible_ = false; |
| 135 message_center_->SetVisibility(message_center::VISIBILITY_TRANSIENT); | 144 message_center_->SetVisibility(message_center::VISIBILITY_TRANSIENT); |
| 136 | 145 |
| 137 // Some notifications (like system ones) should appear as popups again | 146 // Some notifications (like system ones) should appear as popups again |
| 138 // after the message center is closed. | 147 // after the message center is closed. |
| 139 if (message_center_->HasPopupNotifications()) { | 148 if (message_center_->HasPopupNotifications()) { |
| 140 ShowPopupBubble(); | 149 ShowPopupBubble(); |
| 141 return; | 150 return; |
| 142 } | 151 } |
| 143 | 152 |
| 144 NotifyMessageCenterTrayChanged(); | 153 NotifyMessageCenterTrayChanged(); |
| 145 } | 154 } |
| 146 | 155 |
| 147 void MessageCenterTray::ToggleMessageCenterBubble() { | |
| 148 if (message_center_visible_) | |
| 149 HideMessageCenterBubble(); | |
| 150 else | |
| 151 ShowMessageCenterBubble(); | |
| 152 } | |
| 153 | |
| 154 void MessageCenterTray::ShowPopupBubble() { | 156 void MessageCenterTray::ShowPopupBubble() { |
| 155 if (message_center_visible_) | 157 if (message_center_visible_) |
| 156 return; | 158 return; |
| 157 | 159 |
| 158 if (popups_visible_) { | 160 if (popups_visible_) { |
| 159 NotifyMessageCenterTrayChanged(); | 161 NotifyMessageCenterTrayChanged(); |
| 160 return; | 162 return; |
| 161 } | 163 } |
| 162 | 164 |
| 163 if (!message_center_->HasPopupNotifications()) | 165 if (!message_center_->HasPopupNotifications()) |
| (...skipping 27 matching lines...) Expand all Loading... |
| 191 | 193 |
| 192 message_center_visible_ = delegate_->ShowNotifierSettings(); | 194 message_center_visible_ = delegate_->ShowNotifierSettings(); |
| 193 message_center_->SetVisibility(message_center::VISIBILITY_SETTINGS); | 195 message_center_->SetVisibility(message_center::VISIBILITY_SETTINGS); |
| 194 | 196 |
| 195 NotifyMessageCenterTrayChanged(); | 197 NotifyMessageCenterTrayChanged(); |
| 196 } | 198 } |
| 197 | 199 |
| 198 scoped_ptr<ui::MenuModel> MessageCenterTray::CreateNotificationMenuModel( | 200 scoped_ptr<ui::MenuModel> MessageCenterTray::CreateNotificationMenuModel( |
| 199 const NotifierId& notifier_id, | 201 const NotifierId& notifier_id, |
| 200 const base::string16& display_source) { | 202 const base::string16& display_source) { |
| 203 #if !defined(OS_CHROMEOS) |
| 204 // Only web pages are configurable on non-chromeos platforms. |
| 205 if (notifier_id.type != NotifierId::WEB_PAGE) { |
| 206 return nullptr; |
| 207 } |
| 208 #endif |
| 209 |
| 201 return make_scoped_ptr( | 210 return make_scoped_ptr( |
| 202 new NotificationMenuModel(this, notifier_id, display_source)); | 211 new NotificationMenuModel(this, notifier_id, display_source)); |
| 203 } | 212 } |
| 204 | 213 |
| 205 void MessageCenterTray::OnNotificationAdded( | 214 void MessageCenterTray::OnNotificationAdded( |
| 206 const std::string& notification_id) { | 215 const std::string& notification_id) { |
| 207 OnMessageCenterChanged(); | 216 OnMessageCenterChanged(); |
| 208 } | 217 } |
| 209 | 218 |
| 210 void MessageCenterTray::OnNotificationRemoved( | 219 void MessageCenterTray::OnNotificationRemoved( |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 ShowPopupBubble(); | 264 ShowPopupBubble(); |
| 256 | 265 |
| 257 NotifyMessageCenterTrayChanged(); | 266 NotifyMessageCenterTrayChanged(); |
| 258 } | 267 } |
| 259 | 268 |
| 260 void MessageCenterTray::NotifyMessageCenterTrayChanged() { | 269 void MessageCenterTray::NotifyMessageCenterTrayChanged() { |
| 261 delegate_->OnMessageCenterTrayChanged(); | 270 delegate_->OnMessageCenterTrayChanged(); |
| 262 } | 271 } |
| 263 | 272 |
| 264 } // namespace message_center | 273 } // namespace message_center |
| OLD | NEW |