Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(462)

Side by Side Diff: ash/system/web_notification/web_notification_tray.h

Issue 11189099: Re-factor Ash Message Center code part 4/4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ 5 #ifndef ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
6 #define ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ 6 #define ASH_SYSTEM_WEB_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/tray/tray_views.h" 10 #include "ash/system/tray/tray_views.h"
11 #include "ash/system/user/login_status.h" 11 #include "ash/system/user/login_status.h"
12 #include "ash/system/web_notification/web_notification_list.h" 12 #include "ash/system/web_notification/message_center.h"
13 #include "base/gtest_prod_util.h" 13 #include "base/gtest_prod_util.h"
14 14
15 // Status area tray for showing browser and app notifications. This hosts
16 // a MessageCenter class which manages the notification list. This class
17 // contains the Ash specific tray implementation.
18 //
19 // Note: These are not related to system notifications (i.e NotificationView
20 // generated by SystemTrayItem). Visibility of one notification type or other
21 // is controlled by StatusAreaWidget.
22
15 namespace aura { 23 namespace aura {
16 class LocatedEvent; 24 class LocatedEvent;
17 } 25 }
18 26
19 namespace gfx { 27 namespace gfx {
20 class ImageSkia; 28 class ImageSkia;
21 } 29 }
22 30
23 namespace views { 31 namespace views {
24 class ImageButton; 32 class ImageButton;
25 } 33 }
26 34
27 namespace message_center { 35 namespace message_center {
28 class MessageCenterBubble; 36 class MessageCenterBubble;
29 class PopupBubble; 37 class PopupBubble;
30 } 38 }
31 39
32 namespace ash { 40 namespace ash {
33 41
34 namespace internal { 42 namespace internal {
35 class StatusAreaWidget; 43 class StatusAreaWidget;
36 class WebNotificationBubbleWrapper; 44 class WebNotificationBubbleWrapper;
37 } 45 }
38 46
39 // Status area tray for showing browser and app notifications. The client
40 // (e.g. Chrome) calls [Add|Remove|Update]Notification to create and update
41 // notifications in the tray. It can also implement Delegate to receive
42 // callbacks when a notification is removed (closed), clicked on, or a menu
43 // item is triggered.
44 //
45 // Note: These are not related to system notifications (i.e NotificationView
46 // generated by SystemTrayItem). Visibility of one notification type or other
47 // is controlled by StatusAreaWidget.
48
49 class ASH_EXPORT WebNotificationTray 47 class ASH_EXPORT WebNotificationTray
50 : public internal::TrayBackgroundView, 48 : public internal::TrayBackgroundView,
51 public message_center::TrayBubbleView::Delegate, 49 public message_center::TrayBubbleView::Delegate,
52 public message_center::WebNotificationList::Delegate, 50 public message_center::MessageCenter::Host,
53 public views::ButtonListener { 51 public views::ButtonListener {
54 public: 52 public:
55 class ASH_EXPORT Delegate {
56 public:
57 virtual ~Delegate() {}
58
59 // Called when the notification associated with |notification_id| is
60 // removed (i.e. closed by the user).
61 virtual void NotificationRemoved(const std::string& notifcation_id) = 0;
62
63 // Request to disable the extension associated with |notification_id|.
64 virtual void DisableExtension(const std::string& notifcation_id) = 0;
65
66 // Request to disable notifications from the source of |notification_id|.
67 virtual void DisableNotificationsFromSource(
68 const std::string& notifcation_id) = 0;
69
70 // Request to show the notification settings (|notification_id| is used
71 // to identify the requesting browser context).
72 virtual void ShowSettings(const std::string& notifcation_id) = 0;
73
74 // Called when the notification body is clicked on.
75 virtual void OnClicked(const std::string& notifcation_id) = 0;
76 };
77
78 explicit WebNotificationTray(internal::StatusAreaWidget* status_area_widget); 53 explicit WebNotificationTray(internal::StatusAreaWidget* status_area_widget);
79 virtual ~WebNotificationTray(); 54 virtual ~WebNotificationTray();
80 55
81 // Called once to set the delegate.
82 void SetDelegate(Delegate* delegate);
83
84 // Add a new notification. |id| is a unique identifier, used to update or
85 // remove notifications. |title| and |meesage| describe the notification text.
86 // Use SetNotificationImage to set the icon image. If |extension_id| is
87 // provided then 'Disable extension' will appear in a dropdown menu and the
88 // id will be used to disable notifications from the extension. Otherwise if
89 // |display_source| is provided, a menu item showing the source and allowing
90 // notifications from that source to be disabled will be shown. All actual
91 // disabling is handled by the Delegate.
92 void AddNotification(const std::string& id,
93 const string16& title,
94 const string16& message,
95 const string16& display_source,
96 const std::string& extension_id);
97
98 // Update an existing notification with id = old_id and set its id to new_id.
99 void UpdateNotification(const std::string& old_id,
100 const std::string& new_id,
101 const string16& title,
102 const string16& message);
103
104 // Remove an existing notification.
105 void RemoveNotification(const std::string& id);
106
107 // Set the notification image.
108 void SetNotificationImage(const std::string& id,
109 const gfx::ImageSkia& image);
110
111 // Set whether or not the popup notifications should be hidden. 56 // Set whether or not the popup notifications should be hidden.
112 void SetHidePopupBubble(bool hide); 57 void SetHidePopupBubble(bool hide);
113 58
114 // Updates tray visibility login status of the system changes. 59 // Updates tray visibility login status of the system changes.
115 void UpdateAfterLoginStatusChange(user::LoginStatus login_status); 60 void UpdateAfterLoginStatusChange(user::LoginStatus login_status);
116 61
117 // Returns true if the message center bubble is visible. 62 // Returns true if the message center bubble is visible.
118 bool IsMessageCenterBubbleVisible() const; 63 bool IsMessageCenterBubbleVisible() const;
119 64
120 // Returns true if the mouse is inside the notification bubble. 65 // Returns true if the mouse is inside the notification bubble.
121 bool IsMouseInNotificationBubble() const; 66 bool IsMouseInNotificationBubble() const;
122 67
68 message_center::MessageCenter* message_center() {
69 return message_center_.get();
70 }
71
123 // Overridden from TrayBackgroundView. 72 // Overridden from TrayBackgroundView.
124 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; 73 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
125 virtual void AnchorUpdated() OVERRIDE; 74 virtual void AnchorUpdated() OVERRIDE;
126 virtual string16 GetAccessibleNameForTray() OVERRIDE; 75 virtual string16 GetAccessibleNameForTray() OVERRIDE;
127 virtual void HideBubbleWithView( 76 virtual void HideBubbleWithView(
128 const message_center::TrayBubbleView* bubble_view) OVERRIDE; 77 const message_center::TrayBubbleView* bubble_view) OVERRIDE;
129 virtual bool ClickedOutsideBubble() OVERRIDE; 78 virtual bool ClickedOutsideBubble() OVERRIDE;
130 79
131 // Overridden from internal::ActionableView. 80 // Overridden from internal::ActionableView.
132 virtual bool PerformAction(const ui::Event& event) OVERRIDE; 81 virtual bool PerformAction(const ui::Event& event) OVERRIDE;
133 82
134 // Overridden from message_center::TrayBubbleView::Delegate. 83 // Overridden from message_center::TrayBubbleView::Delegate.
135 virtual void BubbleViewDestroyed() OVERRIDE; 84 virtual void BubbleViewDestroyed() OVERRIDE;
136 virtual void OnMouseEnteredView() OVERRIDE; 85 virtual void OnMouseEnteredView() OVERRIDE;
137 virtual void OnMouseExitedView() OVERRIDE; 86 virtual void OnMouseExitedView() OVERRIDE;
138 virtual string16 GetAccessibleNameForBubble() OVERRIDE; 87 virtual string16 GetAccessibleNameForBubble() OVERRIDE;
139 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, 88 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget,
140 AnchorType anchor_type, 89 AnchorType anchor_type,
141 AnchorAlignment anchor_alignment) OVERRIDE; 90 AnchorAlignment anchor_alignment) OVERRIDE;
142 virtual void HideBubble( 91 virtual void HideBubble(
143 const message_center::TrayBubbleView* bubble_view) OVERRIDE; 92 const message_center::TrayBubbleView* bubble_view) OVERRIDE;
144 93
145 // Overridden from message_center::WebNotificationList::Delegate. 94 // Overridden from message_center::MessageCenter::Host.
146 virtual void SendRemoveNotification(const std::string& id) OVERRIDE; 95 virtual void MessageCenterChanged(bool new_notification) OVERRIDE;
147 virtual void SendRemoveAllNotifications() OVERRIDE;
148 virtual void DisableNotificationByExtension(const std::string& id) OVERRIDE;
149 virtual void DisableNotificationByUrl(const std::string& id) OVERRIDE;
150 virtual void ShowNotificationSettings(const std::string& id) OVERRIDE;
151 virtual void OnNotificationClicked(const std::string& id) OVERRIDE;
152 virtual message_center::WebNotificationList* GetNotificationList() OVERRIDE;
153 96
154 // Overridden from ButtonListener. 97 // Overridden from ButtonListener.
155 virtual void ButtonPressed(views::Button* sender, 98 virtual void ButtonPressed(views::Button* sender,
156 const ui::Event& event) OVERRIDE; 99 const ui::Event& event) OVERRIDE;
157 100
158 private: 101 private:
159 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); 102 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
160 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); 103 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble);
161 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, 104 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest,
162 ManyMessageCenterNotifications); 105 ManyMessageCenterNotifications);
(...skipping 10 matching lines...) Expand all
173 116
174 // Shows or updates the popup notification bubble if appropriate. 117 // Shows or updates the popup notification bubble if appropriate.
175 void ShowPopupBubble(); 118 void ShowPopupBubble();
176 119
177 // Hides the notification bubble if visible. 120 // Hides the notification bubble if visible.
178 void HidePopupBubble(); 121 void HidePopupBubble();
179 122
180 // Updates the tray icon and visibility. 123 // Updates the tray icon and visibility.
181 void UpdateTray(); 124 void UpdateTray();
182 125
183 // As above but also updates any visible bubble.
184 void UpdateTrayAndBubble();
185
186 message_center::WebNotificationList* notification_list() {
187 return notification_list_.get();
188 }
189
190 internal::WebNotificationBubbleWrapper* message_center_bubble() const { 126 internal::WebNotificationBubbleWrapper* message_center_bubble() const {
191 return message_center_bubble_.get(); 127 return message_center_bubble_.get();
192 } 128 }
193 129
194 internal::WebNotificationBubbleWrapper* popup_bubble() const { 130 internal::WebNotificationBubbleWrapper* popup_bubble() const {
195 return popup_bubble_.get(); 131 return popup_bubble_.get();
196 } 132 }
197 133
198 // Testing accessors. 134 // Testing accessors.
199 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); 135 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest();
200 message_center::PopupBubble* GetPopupBubbleForTest(); 136 message_center::PopupBubble* GetPopupBubbleForTest();
201 137
202 scoped_ptr<message_center::WebNotificationList> notification_list_; 138 scoped_ptr<message_center::MessageCenter> message_center_;
203 scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_; 139 scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_;
204 scoped_ptr<internal::WebNotificationBubbleWrapper> popup_bubble_; 140 scoped_ptr<internal::WebNotificationBubbleWrapper> popup_bubble_;
205 views::ImageButton* button_; 141 views::ImageButton* button_;
206 Delegate* delegate_;
207 bool show_message_center_on_unlock_; 142 bool show_message_center_on_unlock_;
208 143
209 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); 144 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
210 }; 145 };
211 146
212 } // namespace ash 147 } // namespace ash
213 148
214 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ 149 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
OLDNEW
« no previous file with comments | « ash/system/web_notification/web_notification_list.h ('k') | ash/system/web_notification/web_notification_tray.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698