OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | 5 #ifndef ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ |
6 #define ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | 6 #define ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ |
7 | 7 |
8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
9 #include "ash/system/tray/tray_background_view.h" | 9 #include "ash/system/tray/tray_background_view.h" |
10 #include "ash/system/user/login_status.h" | 10 #include "ash/system/user/login_status.h" |
11 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
12 #include "ui/aura/event_filter.h" | 12 #include "ui/aura/event_filter.h" |
13 | 13 |
14 namespace aura { | 14 namespace aura { |
15 class LocatedEvent; | 15 class LocatedEvent; |
16 } | 16 } |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 class ImageSkia; | 19 class ImageSkia; |
20 } | 20 } |
21 | 21 |
22 namespace views { | 22 namespace views { |
23 class Label; | 23 class Label; |
24 } | 24 } |
25 | 25 |
26 namespace ash { | 26 namespace ash { |
27 | 27 |
28 namespace internal { | 28 namespace internal { |
29 class StatusAreaWidget; | 29 class StatusAreaWidget; |
| 30 class WebNotificationButtonView; |
30 class WebNotificationList; | 31 class WebNotificationList; |
| 32 class WebNotificationMenuModel; |
| 33 class WebNotificationView; |
31 } | 34 } |
32 | 35 |
33 // Status area tray for showing browser and app notifications. The client | 36 // Status area tray for showing browser and app notifications. The client |
34 // (e.g. Chrome) calls [Add|Remove|Update]Notification to create and update | 37 // (e.g. Chrome) calls [Add|Remove|Update]Notification to create and update |
35 // notifications in the tray. It can also implement Delegate to receive | 38 // notifications in the tray. It can also implement Delegate to receive |
36 // callbacks when a notification is removed (closed), clicked on, or a menu | 39 // callbacks when a notification is removed (closed), clicked on, or a menu |
37 // item is triggered. | 40 // item is triggered. |
38 // | 41 // |
39 // Note: These are not related to system notifications (i.e NotificationView | 42 // Note: These are not related to system notifications (i.e NotificationView |
40 // generated by SystemTrayItem). Visibility of one notification type or other | 43 // generated by SystemTrayItem). Visibility of one notification type or other |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 // id will be used to disable notifications from the extension. Otherwise if | 81 // id will be used to disable notifications from the extension. Otherwise if |
79 // |display_source| is provided, a menu item showing the source and allowing | 82 // |display_source| is provided, a menu item showing the source and allowing |
80 // notifications from that source to be disabled will be shown. All actual | 83 // notifications from that source to be disabled will be shown. All actual |
81 // disabling is handled by the Delegate. | 84 // disabling is handled by the Delegate. |
82 void AddNotification(const std::string& id, | 85 void AddNotification(const std::string& id, |
83 const string16& title, | 86 const string16& title, |
84 const string16& message, | 87 const string16& message, |
85 const string16& display_source, | 88 const string16& display_source, |
86 const std::string& extension_id); | 89 const std::string& extension_id); |
87 | 90 |
88 // Update an existing notification. | 91 // Update an existing notification with id = old_id and set its id to new_id. |
89 void UpdateNotification(const std::string& id, | 92 void UpdateNotification(const std::string& old_id, |
| 93 const std::string& new_id, |
90 const string16& title, | 94 const string16& title, |
91 const string16& message); | 95 const string16& message); |
92 | 96 |
93 // Remove an existing notification and notify the delegate. | 97 // Remove an existing notification. |
94 void RemoveNotification(const std::string& id); | 98 void RemoveNotification(const std::string& id); |
95 | 99 |
96 // Remove all notifications and notify the delegate. | |
97 void RemoveAllNotifications(); | |
98 | |
99 // Set the notification image. | 100 // Set the notification image. |
100 void SetNotificationImage(const std::string& id, | 101 void SetNotificationImage(const std::string& id, |
101 const gfx::ImageSkia& image); | 102 const gfx::ImageSkia& image); |
102 | 103 |
103 // Disable all notifications matching notification |id|. | |
104 void DisableByExtension(const std::string& id); | |
105 void DisableByUrl(const std::string& id); | |
106 | |
107 // Show the message center bubble. Should only be called by StatusAreaWidget. | 104 // Show the message center bubble. Should only be called by StatusAreaWidget. |
108 void ShowMessageCenterBubble(); | 105 void ShowMessageCenterBubble(); |
109 | 106 |
110 // Hide the message center bubble. Should only be called by StatusAreaWidget. | 107 // Hide the message center bubble. Should only be called by StatusAreaWidget. |
111 void HideMessageCenterBubble(); | 108 void HideMessageCenterBubble(); |
112 | 109 |
113 // Hide the message center bubble if there are no notifications. | |
114 void HideMessageCenterBubbleIfEmpty(); | |
115 | |
116 // Show a single notification bubble for the most recent notification. | 110 // Show a single notification bubble for the most recent notification. |
117 void ShowNotificationBubble(); | 111 void ShowNotificationBubble(); |
118 | 112 |
119 // Hide the single notification bubble if visible. | 113 // Hide the single notification bubble if visible. |
120 void HideNotificationBubble(); | 114 void HideNotificationBubble(); |
121 | 115 |
122 // Updates tray visibility login status of the system changes. | 116 // Updates tray visibility login status of the system changes. |
123 void UpdateAfterLoginStatusChange(user::LoginStatus login_status); | 117 void UpdateAfterLoginStatusChange(user::LoginStatus login_status); |
124 | 118 |
| 119 // Overridden from TrayBackgroundView. |
| 120 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; |
| 121 |
| 122 // Overridden from internal::ActionableView. |
| 123 virtual bool PerformAction(const views::Event& event) OVERRIDE; |
| 124 |
| 125 protected: |
| 126 // Send a remove request to the delegate. |
| 127 void SendRemoveNotification(const std::string& id); |
| 128 |
| 129 // Send a remove request for all notifications to the delegate. |
| 130 void SendRemoveAllNotifications(); |
| 131 |
| 132 // Disable all notifications matching notification |id|. |
| 133 void DisableByExtension(const std::string& id); |
| 134 void DisableByUrl(const std::string& id); |
| 135 |
125 // Request the Delegate to the settings dialog. | 136 // Request the Delegate to the settings dialog. |
126 void ShowSettings(const std::string& id); | 137 void ShowSettings(const std::string& id); |
127 | 138 |
128 // Called when a notification is clicked on. Event is passed to the Delegate. | 139 // Called when a notification is clicked on. Event is passed to the Delegate. |
129 void OnClicked(const std::string& id); | 140 void OnClicked(const std::string& id); |
130 | 141 |
131 // Overridden from TrayBackgroundView. | |
132 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; | |
133 | |
134 // Overridden from internal::ActionableView. | |
135 virtual bool PerformAction(const views::Event& event) OVERRIDE; | |
136 | |
137 private: | 142 private: |
138 class Bubble; | 143 class Bubble; |
| 144 friend class internal::WebNotificationButtonView; |
| 145 friend class internal::WebNotificationMenuModel; |
| 146 friend class internal::WebNotificationView; |
139 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); | 147 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); |
| 148 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationBubble); |
140 | 149 |
141 int GetNotificationCount() const; | 150 int GetNotificationCount() const; |
142 void UpdateTray(); | 151 void UpdateTray(); |
143 void UpdateTrayAndBubble(); | 152 void UpdateTrayAndBubble(); |
144 void HideBubble(Bubble* bubble); | 153 void HideBubble(Bubble* bubble); |
| 154 bool HasNotificationForTest(const std::string& id) const; |
145 | 155 |
146 const internal::WebNotificationList* notification_list() const { | 156 const internal::WebNotificationList* notification_list() const { |
147 return notification_list_.get(); | 157 return notification_list_.get(); |
148 } | 158 } |
149 Bubble* message_center_bubble() const { return message_center_bubble_.get(); } | 159 Bubble* message_center_bubble() const { return message_center_bubble_.get(); } |
150 Bubble* notification_bubble() const { return notification_bubble_.get(); } | 160 Bubble* notification_bubble() const { return notification_bubble_.get(); } |
151 | 161 |
152 scoped_ptr<internal::WebNotificationList> notification_list_; | 162 scoped_ptr<internal::WebNotificationList> notification_list_; |
153 scoped_ptr<Bubble> message_center_bubble_; | 163 scoped_ptr<Bubble> message_center_bubble_; |
154 scoped_ptr<Bubble> notification_bubble_; | 164 scoped_ptr<Bubble> notification_bubble_; |
155 views::Label* count_label_; | 165 views::Label* count_label_; |
156 Delegate* delegate_; | 166 Delegate* delegate_; |
157 bool show_message_center_on_unlock_; | 167 bool show_message_center_on_unlock_; |
158 | 168 |
159 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); | 169 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); |
160 }; | 170 }; |
161 | 171 |
162 } // namespace ash | 172 } // namespace ash |
163 | 173 |
164 #endif // ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | 174 #endif // ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ |
OLD | NEW |