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 #include "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/status_area_widget.h" | 8 #include "ash/system/status_area_widget.h" |
9 #include "ash/system/tray/tray_bubble_view.h" | |
10 #include "ash/system/tray/tray_bubble_wrapper.h" | 9 #include "ash/system/tray/tray_bubble_wrapper.h" |
11 #include "ash/system/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
12 #include "ash/system/tray/tray_views.h" | 11 #include "ash/system/tray/tray_views.h" |
13 #include "ash/system/web_notification/message_center_bubble.h" | 12 #include "ui/message_center/message_center_bubble.h" |
14 #include "ash/system/web_notification/popup_bubble.h" | 13 #include "ui/message_center/message_popup_bubble.h" |
15 #include "ash/system/web_notification/web_notification.h" | |
16 #include "ash/system/web_notification/web_notification_bubble.h" | |
17 #include "ash/wm/shelf_layout_manager.h" | 14 #include "ash/wm/shelf_layout_manager.h" |
18 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
19 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
20 #include "grit/ash_resources.h" | 17 #include "grit/ash_resources.h" |
21 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
22 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
| 22 #include "ui/views/bubble/tray_bubble_view.h" |
25 #include "ui/views/widget/widget_observer.h" | 23 #include "ui/views/widget/widget_observer.h" |
26 | 24 |
27 namespace { | 25 namespace { |
28 | 26 |
29 // Tray constants | 27 // Tray constants |
30 const int kTrayContainerVerticalPaddingBottomAlignment = 3; | 28 const int kTrayContainerVerticalPaddingBottomAlignment = 3; |
31 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 29 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; |
32 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 30 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; |
33 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; | 31 const int kTrayContainerHorizontalPaddingVerticalAlignment = 0; |
34 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; | 32 const int kPaddingFromLeftEdgeOfSystemTrayBottomAlignment = 8; |
35 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; | 33 const int kPaddingFromTopEdgeOfSystemTrayVerticalAlignment = 10; |
36 | 34 |
37 } // namespace | 35 } // namespace |
38 | 36 |
39 using message_center::MessageCenterBubble; | |
40 using message_center::PopupBubble; | |
41 using message_center::TrayBubbleView; | |
42 using message_center::WebNotification; | |
43 using message_center::WebNotificationBubble; | |
44 | |
45 namespace ash { | 37 namespace ash { |
46 | 38 |
47 namespace internal { | 39 namespace internal { |
48 | 40 |
49 // Class to initialize and manage the WebNotificationBubble and | 41 // Class to initialize and manage the WebNotificationBubble and |
50 // TrayBubbleWrapper instances for a bubble. | 42 // TrayBubbleWrapper instances for a bubble. |
51 | 43 |
52 class WebNotificationBubbleWrapper { | 44 class WebNotificationBubbleWrapper { |
53 public: | 45 public: |
54 // Takes ownership of |bubble| and creates |bubble_wrapper_|. | 46 // Takes ownership of |bubble| and creates |bubble_wrapper_|. |
55 WebNotificationBubbleWrapper(WebNotificationTray* tray, | 47 WebNotificationBubbleWrapper(WebNotificationTray* tray, |
56 WebNotificationBubble* bubble) { | 48 message_center::MessageBubbleBase* bubble) { |
57 bubble_.reset(bubble); | 49 bubble_.reset(bubble); |
58 TrayBubbleView::AnchorAlignment anchor_alignment = | 50 views::TrayBubbleView::AnchorAlignment anchor_alignment = |
59 tray->GetAnchorAlignment(); | 51 tray->GetAnchorAlignment(); |
60 TrayBubbleView::InitParams init_params = | 52 views::TrayBubbleView::InitParams init_params = |
61 bubble->GetInitParams(anchor_alignment); | 53 bubble->GetInitParams(anchor_alignment); |
62 views::View* anchor = tray->tray_container(); | 54 views::View* anchor = tray->tray_container(); |
63 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 55 if (anchor_alignment == views::TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
64 gfx::Point bounds(anchor->width() / 2, 0); | 56 gfx::Point bounds(anchor->width() / 2, 0); |
65 views::View::ConvertPointToWidget(anchor, &bounds); | 57 views::View::ConvertPointToWidget(anchor, &bounds); |
66 init_params.arrow_offset = bounds.x(); | 58 init_params.arrow_offset = bounds.x(); |
67 } | 59 } |
68 TrayBubbleView* bubble_view = TrayBubbleView::Create( | 60 views::TrayBubbleView* bubble_view = views::TrayBubbleView::Create( |
69 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); | 61 tray->GetBubbleWindowContainer(), anchor, tray, &init_params); |
70 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); | 62 bubble_wrapper_.reset(new TrayBubbleWrapper(tray, bubble_view)); |
71 bubble->InitializeContents(bubble_view); | 63 bubble->InitializeContents(bubble_view); |
72 } | 64 } |
73 | 65 |
74 WebNotificationBubble* bubble() const { return bubble_.get(); } | 66 message_center::MessageBubbleBase* bubble() const { return bubble_.get(); } |
75 | 67 |
76 // Convenience accessors. | 68 // Convenience accessors. |
77 TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } | 69 views::TrayBubbleView* bubble_view() const { return bubble_->bubble_view(); } |
78 | 70 |
79 private: | 71 private: |
80 scoped_ptr<WebNotificationBubble> bubble_; | 72 scoped_ptr<message_center::MessageBubbleBase> bubble_; |
81 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; | 73 scoped_ptr<internal::TrayBubbleWrapper> bubble_wrapper_; |
82 }; | 74 }; |
83 | 75 |
84 } // namespace internal | 76 } // namespace internal |
85 | 77 |
86 WebNotificationTray::WebNotificationTray( | 78 WebNotificationTray::WebNotificationTray( |
87 internal::StatusAreaWidget* status_area_widget) | 79 internal::StatusAreaWidget* status_area_widget) |
88 : internal::TrayBackgroundView(status_area_widget), | 80 : internal::TrayBackgroundView(status_area_widget), |
89 button_(NULL), | 81 button_(NULL), |
90 show_message_center_on_unlock_(false) { | 82 show_message_center_on_unlock_(false) { |
(...skipping 15 matching lines...) Expand all Loading... |
106 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) | 98 if (status_area_widget()->login_status() == user::LOGGED_IN_LOCKED) |
107 return; | 99 return; |
108 if (message_center_bubble()) { | 100 if (message_center_bubble()) { |
109 UpdateTray(); | 101 UpdateTray(); |
110 return; | 102 return; |
111 } | 103 } |
112 // Indicate that the message center is visible. Clears the unread count. | 104 // Indicate that the message center is visible. Clears the unread count. |
113 message_center_->SetMessageCenterVisible(true); | 105 message_center_->SetMessageCenterVisible(true); |
114 UpdateTray(); | 106 UpdateTray(); |
115 HidePopupBubble(); | 107 HidePopupBubble(); |
116 MessageCenterBubble* bubble = new MessageCenterBubble(message_center_.get()); | 108 message_center::MessageCenterBubble* bubble = |
| 109 new message_center::MessageCenterBubble(message_center_.get()); |
117 message_center_bubble_.reset( | 110 message_center_bubble_.reset( |
118 new internal::WebNotificationBubbleWrapper(this, bubble)); | 111 new internal::WebNotificationBubbleWrapper(this, bubble)); |
119 | 112 |
120 status_area_widget()->SetHideSystemNotifications(true); | 113 status_area_widget()->SetHideSystemNotifications(true); |
121 GetShelfLayoutManager()->UpdateAutoHideState(); | 114 GetShelfLayoutManager()->UpdateAutoHideState(); |
122 } | 115 } |
123 | 116 |
124 void WebNotificationTray::HideMessageCenterBubble() { | 117 void WebNotificationTray::HideMessageCenterBubble() { |
125 if (!message_center_bubble()) | 118 if (!message_center_bubble()) |
126 return; | 119 return; |
(...skipping 18 matching lines...) Expand all Loading... |
145 if (message_center_bubble()) | 138 if (message_center_bubble()) |
146 return; | 139 return; |
147 if (!status_area_widget()->ShouldShowWebNotifications()) | 140 if (!status_area_widget()->ShouldShowWebNotifications()) |
148 return; | 141 return; |
149 UpdateTray(); | 142 UpdateTray(); |
150 if (popup_bubble()) { | 143 if (popup_bubble()) { |
151 popup_bubble()->bubble()->ScheduleUpdate(); | 144 popup_bubble()->bubble()->ScheduleUpdate(); |
152 } else if (message_center_->HasPopupNotifications()) { | 145 } else if (message_center_->HasPopupNotifications()) { |
153 popup_bubble_.reset( | 146 popup_bubble_.reset( |
154 new internal::WebNotificationBubbleWrapper( | 147 new internal::WebNotificationBubbleWrapper( |
155 this, new PopupBubble(message_center_.get()))); | 148 this, new message_center::MessagePopupBubble( |
| 149 message_center_.get()))); |
156 } | 150 } |
157 } | 151 } |
158 | 152 |
159 void WebNotificationTray::HidePopupBubble() { | 153 void WebNotificationTray::HidePopupBubble() { |
160 popup_bubble_.reset(); | 154 popup_bubble_.reset(); |
161 } | 155 } |
162 | 156 |
163 void WebNotificationTray::UpdateAfterLoginStatusChange( | 157 void WebNotificationTray::UpdateAfterLoginStatusChange( |
164 user::LoginStatus login_status) { | 158 user::LoginStatus login_status) { |
165 if (login_status == user::LOGGED_IN_LOCKED) { | 159 if (login_status == user::LOGGED_IN_LOCKED) { |
(...skipping 29 matching lines...) Expand all Loading... |
195 // Destroy any existing bubble so that it will be rebuilt correctly. | 189 // Destroy any existing bubble so that it will be rebuilt correctly. |
196 HideMessageCenterBubble(); | 190 HideMessageCenterBubble(); |
197 HidePopupBubble(); | 191 HidePopupBubble(); |
198 } | 192 } |
199 | 193 |
200 void WebNotificationTray::AnchorUpdated() { | 194 void WebNotificationTray::AnchorUpdated() { |
201 if (popup_bubble_.get()) { | 195 if (popup_bubble_.get()) { |
202 popup_bubble_->bubble_view()->UpdateBubble(); | 196 popup_bubble_->bubble_view()->UpdateBubble(); |
203 // Ensure that the notification buble is above the launcher/status area. | 197 // Ensure that the notification buble is above the launcher/status area. |
204 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 198 popup_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 199 UpdateBubbleViewArrow(popup_bubble_->bubble_view()); |
205 } | 200 } |
206 if (message_center_bubble_.get()) | 201 if (message_center_bubble_.get()) { |
207 message_center_bubble_->bubble_view()->UpdateBubble(); | 202 message_center_bubble_->bubble_view()->UpdateBubble(); |
| 203 UpdateBubbleViewArrow(message_center_bubble_->bubble_view()); |
| 204 } |
208 } | 205 } |
209 | 206 |
210 string16 WebNotificationTray::GetAccessibleNameForTray() { | 207 string16 WebNotificationTray::GetAccessibleNameForTray() { |
211 return l10n_util::GetStringUTF16( | 208 return l10n_util::GetStringUTF16( |
212 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); | 209 IDS_ASH_WEB_NOTIFICATION_TRAY_ACCESSIBLE_NAME); |
213 } | 210 } |
214 | 211 |
215 void WebNotificationTray::HideBubbleWithView( | 212 void WebNotificationTray::HideBubbleWithView( |
216 const TrayBubbleView* bubble_view) { | 213 const views::TrayBubbleView* bubble_view) { |
217 if (message_center_bubble() && | 214 if (message_center_bubble() && |
218 bubble_view == message_center_bubble()->bubble_view()) { | 215 bubble_view == message_center_bubble()->bubble_view()) { |
219 HideMessageCenterBubble(); | 216 HideMessageCenterBubble(); |
220 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { | 217 } else if (popup_bubble() && bubble_view == popup_bubble()->bubble_view()) { |
221 HidePopupBubble(); | 218 HidePopupBubble(); |
222 } | 219 } |
223 } | 220 } |
224 | 221 |
225 bool WebNotificationTray::PerformAction(const ui::Event& event) { | 222 bool WebNotificationTray::PerformAction(const ui::Event& event) { |
226 ToggleMessageCenterBubble(); | 223 ToggleMessageCenterBubble(); |
(...skipping 20 matching lines...) Expand all Loading... |
247 string16 WebNotificationTray::GetAccessibleNameForBubble() { | 244 string16 WebNotificationTray::GetAccessibleNameForBubble() { |
248 return GetAccessibleNameForTray(); | 245 return GetAccessibleNameForTray(); |
249 } | 246 } |
250 | 247 |
251 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, | 248 gfx::Rect WebNotificationTray::GetAnchorRect(views::Widget* anchor_widget, |
252 AnchorType anchor_type, | 249 AnchorType anchor_type, |
253 AnchorAlignment anchor_alignment) { | 250 AnchorAlignment anchor_alignment) { |
254 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); | 251 return GetBubbleAnchorRect(anchor_widget, anchor_type, anchor_alignment); |
255 } | 252 } |
256 | 253 |
257 void WebNotificationTray::HideBubble(const TrayBubbleView* bubble_view) { | 254 void WebNotificationTray::HideBubble(const views::TrayBubbleView* bubble_view) { |
258 HideBubbleWithView(bubble_view); | 255 HideBubbleWithView(bubble_view); |
259 } | 256 } |
260 | 257 |
261 void WebNotificationTray::MessageCenterChanged(bool new_notification) { | 258 void WebNotificationTray::MessageCenterChanged(bool new_notification) { |
262 if (message_center_bubble()) { | 259 if (message_center_bubble()) { |
263 if (message_center_->NotificationCount() == 0) | 260 if (message_center_->NotificationCount() == 0) |
264 HideMessageCenterBubble(); | 261 HideMessageCenterBubble(); |
265 else | 262 else |
266 message_center_bubble()->bubble()->ScheduleUpdate(); | 263 message_center_bubble()->bubble()->ScheduleUpdate(); |
267 } | 264 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 bool WebNotificationTray::ClickedOutsideBubble() { | 322 bool WebNotificationTray::ClickedOutsideBubble() { |
326 // Only hide the message center. | 323 // Only hide the message center. |
327 if (!message_center_bubble()) | 324 if (!message_center_bubble()) |
328 return false; | 325 return false; |
329 HideMessageCenterBubble(); | 326 HideMessageCenterBubble(); |
330 return true; | 327 return true; |
331 } | 328 } |
332 | 329 |
333 // Methods for testing | 330 // Methods for testing |
334 | 331 |
335 MessageCenterBubble* WebNotificationTray::GetMessageCenterBubbleForTest() { | 332 message_center::MessageCenterBubble* |
| 333 WebNotificationTray::GetMessageCenterBubbleForTest() { |
336 if (!message_center_bubble_.get()) | 334 if (!message_center_bubble_.get()) |
337 return NULL; | 335 return NULL; |
338 return static_cast<MessageCenterBubble*>(message_center_bubble_->bubble()); | 336 return static_cast<message_center::MessageCenterBubble*>( |
| 337 message_center_bubble_->bubble()); |
339 } | 338 } |
340 | 339 |
341 PopupBubble* WebNotificationTray::GetPopupBubbleForTest() { | 340 message_center::MessagePopupBubble* |
| 341 WebNotificationTray::GetPopupBubbleForTest() { |
342 if (!popup_bubble_.get()) | 342 if (!popup_bubble_.get()) |
343 return NULL; | 343 return NULL; |
344 return static_cast<PopupBubble*>(popup_bubble_->bubble()); | 344 return static_cast<message_center::MessagePopupBubble*>( |
| 345 popup_bubble_->bubble()); |
345 } | 346 } |
346 | 347 |
347 } // namespace ash | 348 } // namespace ash |
OLD | NEW |