| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 #ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ |
| 7 | 7 |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/gtest_prod_util.h" |
| 9 #include "base/prefs/pref_member.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "chrome/browser/status_icons/status_icon_menu_model.h" | |
| 11 #include "chrome/browser/status_icons/status_icon_observer.h" | |
| 12 #include "chrome/browser/ui/views/message_center/message_center_widget_delegate.
h" | |
| 13 #include "content/public/browser/notification_observer.h" | |
| 14 #include "content/public/browser/notification_registrar.h" | |
| 15 #include "ui/base/models/simple_menu_model.h" | |
| 16 #include "ui/gfx/geometry/rect.h" | |
| 17 #include "ui/message_center/message_center_tray.h" | |
| 18 #include "ui/message_center/message_center_tray_delegate.h" | 10 #include "ui/message_center/message_center_tray_delegate.h" |
| 19 #include "ui/views/widget/widget_observer.h" | 11 #include "ui/views/widget/widget_observer.h" |
| 20 | 12 |
| 21 #if defined(OS_WIN) | |
| 22 #include "base/threading/thread.h" | |
| 23 #endif | |
| 24 | |
| 25 class PrefService; | |
| 26 class StatusIcon; | 13 class StatusIcon; |
| 27 | 14 |
| 28 namespace message_center { | 15 namespace message_center { |
| 16 class DesktopPopupAlignmentDelegate; |
| 29 class MessageCenter; | 17 class MessageCenter; |
| 18 class MessageCenterTray; |
| 30 class MessagePopupCollection; | 19 class MessagePopupCollection; |
| 31 } | |
| 32 | |
| 33 namespace views { | |
| 34 class Widget; | |
| 35 } | |
| 36 | |
| 37 namespace message_center { | |
| 38 | |
| 39 struct PositionInfo; | |
| 40 | |
| 41 class DesktopPopupAlignmentDelegate; | |
| 42 class MessageCenterWidgetDelegate; | |
| 43 | 20 |
| 44 // A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray | 21 // A MessageCenterTrayDelegate implementation that exposes the MessageCenterTray |
| 45 // via a system tray icon. The notification popups will be displayed in the | 22 // via a system tray icon. The notification popups will be displayed in the |
| 46 // corner of the screen and the message center will be displayed by the system | 23 // corner of the screen and the message center will be displayed by the system |
| 47 // tray icon on click. | 24 // tray icon on click. |
| 48 class WebNotificationTray : public message_center::MessageCenterTrayDelegate, | 25 class WebNotificationTray : public message_center::MessageCenterTrayDelegate { |
| 49 public StatusIconObserver, | |
| 50 public base::SupportsWeakPtr<WebNotificationTray>, | |
| 51 public StatusIconMenuModel::Delegate { | |
| 52 public: | 26 public: |
| 53 explicit WebNotificationTray(PrefService* local_state); | 27 WebNotificationTray(); |
| 54 ~WebNotificationTray() override; | 28 ~WebNotificationTray() override; |
| 55 | 29 |
| 56 message_center::MessageCenter* message_center(); | 30 message_center::MessageCenter* message_center(); |
| 57 | 31 |
| 58 // MessageCenterTrayDelegate implementation. | 32 // MessageCenterTrayDelegate implementation. |
| 59 bool ShowPopups() override; | 33 bool ShowPopups() override; |
| 60 void HidePopups() override; | 34 void HidePopups() override; |
| 61 bool ShowMessageCenter() override; | 35 bool ShowMessageCenter() override; |
| 62 void HideMessageCenter() override; | 36 void HideMessageCenter() override; |
| 63 void OnMessageCenterTrayChanged() override; | 37 void OnMessageCenterTrayChanged() override; |
| 64 bool ShowNotifierSettings() override; | 38 bool ShowNotifierSettings() override; |
| 65 bool IsContextMenuEnabled() const override; | 39 bool IsContextMenuEnabled() const override; |
| 66 | 40 |
| 67 // StatusIconObserver implementation. | |
| 68 void OnStatusIconClicked() override; | |
| 69 #if defined(OS_WIN) | |
| 70 void OnBalloonClicked() override; | |
| 71 | |
| 72 // This shows a platform-specific balloon informing the user of the existence | |
| 73 // of the message center in the status tray area. | |
| 74 void DisplayFirstRunBalloon() override; | |
| 75 | |
| 76 void EnforceStatusIconVisible(); | |
| 77 #endif | |
| 78 | |
| 79 // StatusIconMenuModel::Delegate implementation. | |
| 80 void ExecuteCommand(int command_id, int event_flags) override; | |
| 81 | |
| 82 // Changes the icon and hovertext based on number of unread notifications. | |
| 83 void UpdateStatusIcon(); | |
| 84 void SendHideMessageCenter(); | |
| 85 void MarkMessageCenterHidden(); | |
| 86 | |
| 87 // Gets the point where the status icon was clicked. | |
| 88 gfx::Point mouse_click_point() { return mouse_click_point_; } | |
| 89 MessageCenterTray* GetMessageCenterTray() override; | 41 MessageCenterTray* GetMessageCenterTray() override; |
| 90 | 42 |
| 91 private: | 43 private: |
| 92 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); | 44 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); |
| 93 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); | 45 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); |
| 94 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, | |
| 95 ManyMessageCenterNotifications); | |
| 96 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); | 46 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); |
| 97 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManuallyCloseMessageCenter); | 47 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManuallyCloseMessageCenter); |
| 98 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, StatusIconBehavior); | |
| 99 | 48 |
| 100 PositionInfo GetPositionInfo(); | 49 scoped_ptr<MessagePopupCollection> popup_collection_; |
| 50 scoped_ptr<DesktopPopupAlignmentDelegate> alignment_delegate_; |
| 101 | 51 |
| 102 void CreateStatusIcon(const gfx::ImageSkia& image, | |
| 103 const base::string16& tool_tip); | |
| 104 void DestroyStatusIcon(); | |
| 105 void AddQuietModeMenu(StatusIcon* status_icon); | |
| 106 MessageCenterWidgetDelegate* GetMessageCenterWidgetDelegateForTest(); | |
| 107 | |
| 108 #if defined(OS_WIN) | |
| 109 // This member variable keeps track of whether EnforceStatusIconVisible has | |
| 110 // been invoked on this machine, so the user still has control after we try | |
| 111 // promoting it the first time. | |
| 112 scoped_ptr<BooleanPrefMember> did_force_tray_visible_; | |
| 113 #endif | |
| 114 | |
| 115 MessageCenterWidgetDelegate* message_center_delegate_; | |
| 116 scoped_ptr<message_center::MessagePopupCollection> popup_collection_; | |
| 117 scoped_ptr<message_center::DesktopPopupAlignmentDelegate> alignment_delegate_; | |
| 118 | |
| 119 StatusIcon* status_icon_; | |
| 120 StatusIconMenuModel* status_icon_menu_; | |
| 121 scoped_ptr<MessageCenterTray> message_center_tray_; | 52 scoped_ptr<MessageCenterTray> message_center_tray_; |
| 122 gfx::Point mouse_click_point_; | |
| 123 | |
| 124 bool should_update_tray_content_; | |
| 125 bool last_quiet_mode_state_; | |
| 126 base::string16 title_; | |
| 127 | |
| 128 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); | 53 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); |
| 129 }; | 54 }; |
| 130 | 55 |
| 131 } // namespace message_center | 56 } // namespace message_center |
| 132 | 57 |
| 133 #endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ | 58 #endif // CHROME_BROWSER_UI_VIEWS_MESSAGE_CENTER_WEB_NOTIFICATION_TRAY_H_ |
| OLD | NEW |