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_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" | |
11 #include "ash/system/user/login_status.h" | 10 #include "ash/system/user/login_status.h" |
12 #include "base/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
13 #include "ui/message_center/message_center.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "ui/message_center/message_center_tray.h" | |
14 #include "ui/views/bubble/tray_bubble_view.h" | |
14 #include "ui/views/widget/widget_observer.h" | 15 #include "ui/views/widget/widget_observer.h" |
15 | 16 |
16 // Status area tray for showing browser and app notifications. This hosts | 17 // Status area tray for showing browser and app notifications. This hosts |
17 // a MessageCenter class which manages the notification list. This class | 18 // a MessageCenter class which manages the notification list. This class |
18 // contains the Ash specific tray implementation. | 19 // contains the Ash specific tray implementation. |
19 // | 20 // |
20 // Note: These are not related to system notifications (i.e NotificationView | 21 // Note: These are not related to system notifications (i.e NotificationView |
21 // generated by SystemTrayItem). Visibility of one notification type or other | 22 // generated by SystemTrayItem). Visibility of one notification type or other |
22 // is controlled by StatusAreaWidget. | 23 // is controlled by StatusAreaWidget. |
23 | 24 |
24 namespace aura { | |
25 class LocatedEvent; | |
26 } | |
27 | |
28 namespace gfx { | |
29 class ImageSkia; | |
30 } | |
31 | |
32 namespace views { | |
33 class ImageButton; | |
34 class TrayBubbleView; | |
35 class Widget; | |
36 } | |
37 | |
38 namespace message_center { | 25 namespace message_center { |
26 class MessageBubbleBase; | |
27 class MessageCenter; | |
39 class MessageCenterBubble; | 28 class MessageCenterBubble; |
40 class MessagePopupBubble; | 29 class MessagePopupBubble; |
41 class QuietModeBubble; | |
42 } | 30 } |
43 | 31 |
44 namespace ash { | 32 namespace ash { |
45 | 33 |
46 namespace internal { | 34 namespace internal { |
47 class StatusAreaWidget; | 35 class StatusAreaWidget; |
48 class WebNotificationBubbleWrapper; | 36 class WebNotificationBubbleWrapper; |
49 } | 37 } |
50 | 38 |
51 class ASH_EXPORT WebNotificationTray | 39 class ASH_EXPORT WebNotificationTray |
52 : public internal::TrayBackgroundView, | 40 : public internal::TrayBackgroundView, |
53 public views::TrayBubbleView::Delegate, | 41 public views::TrayBubbleView::Delegate, |
54 public message_center::MessageCenter::Observer, | 42 public ui::MessageCenterTrayDelegate, |
43 public ui::MessageCenterTrayObserver, | |
Jun Mukai
2013/01/22 18:55:34
A class being delegate and observer at the same ti
dewittj
2013/01/22 20:49:21
I thought it would be better to separate the roles
| |
55 public views::ButtonListener, | 44 public views::ButtonListener, |
56 public views::WidgetObserver { | 45 public views::WidgetObserver { |
57 public: | 46 public: |
58 explicit WebNotificationTray(internal::StatusAreaWidget* status_area_widget); | 47 explicit WebNotificationTray( |
48 internal::StatusAreaWidget* status_area_widget); | |
59 virtual ~WebNotificationTray(); | 49 virtual ~WebNotificationTray(); |
60 | 50 |
61 // Set whether or not the popup notifications should be hidden. | 51 // Set whether or not the popup notifications should be hidden. |
62 void SetHidePopupBubble(bool hide); | 52 void SetHidePopupBubble(bool hide); |
63 | 53 |
64 // Updates tray visibility login status of the system changes. | 54 // Updates tray visibility login status of the system changes. |
65 void UpdateAfterLoginStatusChange(user::LoginStatus login_status); | 55 void UpdateAfterLoginStatusChange(user::LoginStatus login_status); |
66 | 56 |
67 // Returns true if it should block the auto hide behavior of the launcher. | 57 // Returns true if it should block the auto hide behavior of the launcher. |
68 bool ShouldBlockLauncherAutoHide() const; | 58 bool ShouldBlockLauncherAutoHide() const; |
69 | 59 |
70 // Returns true if the message center bubble is visible. | 60 // Returns true if the message center bubble is visible. |
71 bool IsMessageCenterBubbleVisible() const; | 61 bool IsMessageCenterBubbleVisible() const; |
72 | 62 |
73 // Returns true if the mouse is inside the notification bubble. | 63 // Returns true if the mouse is inside the notification bubble. |
74 bool IsMouseInNotificationBubble() const; | 64 bool IsMouseInNotificationBubble() const; |
75 | 65 |
76 message_center::MessageCenter* message_center() { | 66 virtual message_center::MessageCenter* message_center(); |
77 return message_center_; | |
78 } | |
79 | 67 |
80 // Overridden from TrayBackgroundView. | 68 // Overridden from TrayBackgroundView. |
81 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; | 69 virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE; |
82 virtual void AnchorUpdated() OVERRIDE; | 70 virtual void AnchorUpdated() OVERRIDE; |
83 virtual string16 GetAccessibleNameForTray() OVERRIDE; | 71 virtual string16 GetAccessibleNameForTray() OVERRIDE; |
84 virtual void HideBubbleWithView( | 72 virtual void HideBubbleWithView( |
85 const views::TrayBubbleView* bubble_view) OVERRIDE; | 73 const views::TrayBubbleView* bubble_view) OVERRIDE; |
86 virtual bool ClickedOutsideBubble() OVERRIDE; | 74 virtual bool ClickedOutsideBubble() OVERRIDE; |
87 | 75 |
88 // Overridden from internal::ActionableView. | 76 // Overridden from internal::ActionableView. |
89 virtual bool PerformAction(const ui::Event& event) OVERRIDE; | 77 virtual bool PerformAction(const ui::Event& event) OVERRIDE; |
90 | 78 |
79 // Tells the tray to show the MessageCenter bubble. | |
80 void ShowMessageCenter(); | |
81 | |
91 // Overridden from views::TrayBubbleView::Delegate. | 82 // Overridden from views::TrayBubbleView::Delegate. |
92 virtual void BubbleViewDestroyed() OVERRIDE; | 83 virtual void BubbleViewDestroyed() OVERRIDE; |
93 virtual void OnMouseEnteredView() OVERRIDE; | 84 virtual void OnMouseEnteredView() OVERRIDE; |
94 virtual void OnMouseExitedView() OVERRIDE; | 85 virtual void OnMouseExitedView() OVERRIDE; |
95 virtual string16 GetAccessibleNameForBubble() OVERRIDE; | 86 virtual string16 GetAccessibleNameForBubble() OVERRIDE; |
96 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, | 87 virtual gfx::Rect GetAnchorRect(views::Widget* anchor_widget, |
97 AnchorType anchor_type, | 88 AnchorType anchor_type, |
98 AnchorAlignment anchor_alignment) OVERRIDE; | 89 AnchorAlignment anchor_alignment) OVERRIDE; |
99 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; | 90 virtual void HideBubble(const views::TrayBubbleView* bubble_view) OVERRIDE; |
100 | 91 |
101 // Overridden from message_center::MessageCenter::Observer. | 92 // Overridden from MessageCenterTrayObserver. |
102 virtual void OnMessageCenterChanged(bool new_notification) OVERRIDE; | 93 virtual void OnMessageCenterTrayChanged() OVERRIDE; |
103 | 94 |
104 // Overridden from ButtonListener. | 95 // Overridden from ButtonListener. |
105 virtual void ButtonPressed(views::Button* sender, | 96 virtual void ButtonPressed(views::Button* sender, |
106 const ui::Event& event) OVERRIDE; | 97 const ui::Event& event) OVERRIDE; |
107 | 98 |
108 // Overridden from WidgetObserver. | 99 // Overridden from WidgetObserver. |
109 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; | 100 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE; |
110 | 101 |
111 private: | 102 private: |
112 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); | 103 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications); |
113 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); | 104 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotificationPopupBubble); |
114 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, | 105 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, |
115 ManyMessageCenterNotifications); | 106 ManyMessageCenterNotifications); |
116 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); | 107 FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, ManyPopupNotifications); |
117 | 108 |
118 // Shows or hides the message center bubble. | 109 public: |
119 void ToggleMessageCenterBubble(); | 110 // TODO(dewittj): move these up above the private area after merging trunk. |
111 // MessageCenterTrayDelegate implementation. | |
112 virtual bool ShowMessageCenter( | |
113 message_center::MessageBubbleBase* bubble) OVERRIDE; | |
114 virtual void UpdateMessageCenter() OVERRIDE; | |
115 virtual void HideMessageCenter() OVERRIDE; | |
116 virtual bool ShowPopups ( | |
117 message_center::MessageBubbleBase* bubble) OVERRIDE; | |
118 virtual void UpdatePopups() OVERRIDE; | |
119 virtual void HidePopups() OVERRIDE; | |
120 | 120 |
121 // Shows or updates the message center bubble and hides the popup bubble. | 121 private: |
122 void ShowMessageCenterBubble(); | 122 // Queries login status and the status area widget to determine visibility of |
123 // the message center. | |
124 bool ShouldShowMessageCenter(); | |
123 | 125 |
124 // Hides the message center bubble if visible. | 126 // Returns true if it should show the quiet mode bubble. |
125 void HideMessageCenterBubble(); | |
126 | |
127 // Shows or updates the popup notification bubble if appropriate. | |
128 void ShowPopupBubble(); | |
129 | |
130 // Hides the notification bubble if visible. | |
131 void HidePopupBubble(); | |
132 | |
133 // Returns true if it should show the quiet mode bubble. | |
134 bool ShouldShowQuietModeBubble(const ui::Event& event); | 127 bool ShouldShowQuietModeBubble(const ui::Event& event); |
135 | 128 |
136 // Shows the quiet mode bubble. | 129 // Shows the quiet mode bubble. |
137 void ShowQuietModeBubble(); | 130 void ShowQuietModeBubble(); |
138 | 131 |
139 // Updates the tray icon and visibility. | |
140 void UpdateTray(); | |
141 | 132 |
142 internal::WebNotificationBubbleWrapper* message_center_bubble() const { | 133 internal::WebNotificationBubbleWrapper* message_center_bubble() const { |
143 return message_center_bubble_.get(); | 134 return message_center_bubble_.get(); |
144 } | 135 } |
145 | 136 |
146 internal::WebNotificationBubbleWrapper* popup_bubble() const { | 137 internal::WebNotificationBubbleWrapper* popup_bubble() const { |
147 return popup_bubble_.get(); | 138 return popup_bubble_.get(); |
148 } | 139 } |
149 | 140 |
150 message_center::QuietModeBubble* quiet_mode_bubble() const { | 141 message_center::QuietModeBubble* quiet_mode_bubble() const { |
151 return quiet_mode_bubble_.get(); | 142 return quiet_mode_bubble_.get(); |
152 } | 143 } |
153 | 144 |
154 // Testing accessors. | 145 // Testing accessors. |
146 bool IsPopupVisible() const; | |
155 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); | 147 message_center::MessageCenterBubble* GetMessageCenterBubbleForTest(); |
156 message_center::MessagePopupBubble* GetPopupBubbleForTest(); | 148 message_center::MessagePopupBubble* GetPopupBubbleForTest(); |
157 | 149 |
158 message_center::MessageCenter* message_center_; // Weak, owned by ash::Shell | 150 scoped_ptr<ui::MessageCenterTray> message_center_tray_; |
159 scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_; | 151 scoped_ptr<internal::WebNotificationBubbleWrapper> message_center_bubble_; |
160 scoped_ptr<internal::WebNotificationBubbleWrapper> popup_bubble_; | 152 scoped_ptr<internal::WebNotificationBubbleWrapper> popup_bubble_; |
161 scoped_ptr<message_center::QuietModeBubble> quiet_mode_bubble_; | 153 scoped_ptr<message_center::QuietModeBubble> quiet_mode_bubble_; |
162 views::ImageButton* button_; | 154 views::ImageButton* button_; |
155 | |
163 bool show_message_center_on_unlock_; | 156 bool show_message_center_on_unlock_; |
164 | 157 |
165 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); | 158 DISALLOW_COPY_AND_ASSIGN(WebNotificationTray); |
166 }; | 159 }; |
167 | 160 |
168 } // namespace ash | 161 } // namespace ash |
169 | 162 |
170 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ | 163 #endif // ASH_SYSTEM_WEB_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_ |
OLD | NEW |