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/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
12 #include "ash/common/shelf/wm_shelf_util.h" | 12 #include "ash/common/shelf/wm_shelf_util.h" |
13 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
14 #include "ash/common/system/tray/system_tray_delegate.h" | |
15 #include "ash/common/system/tray/tray_bubble_wrapper.h" | |
16 #include "ash/common/system/tray/tray_constants.h" | 14 #include "ash/common/system/tray/tray_constants.h" |
17 #include "ash/common/system/tray/tray_utils.h" | 15 #include "ash/common/system/tray/tray_utils.h" |
18 #include "ash/common/wm_lookup.h" | 16 #include "ash/common/wm_lookup.h" |
19 #include "ash/common/wm_root_window_controller.h" | 17 #include "ash/common/wm_root_window_controller.h" |
20 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
21 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
22 #include "ash/system/status_area_widget.h" | 20 #include "ash/system/status_area_widget.h" |
23 #include "ash/system/tray/system_tray.h" | 21 #include "ash/system/tray/system_tray.h" |
| 22 #include "ash/system/tray/tray_background_view.h" |
| 23 #include "ash/system/tray/tray_bubble_wrapper.h" |
24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
25 #include "base/auto_reset.h" | 25 #include "base/auto_reset.h" |
26 #include "base/i18n/number_formatting.h" | 26 #include "base/i18n/number_formatting.h" |
27 #include "base/i18n/rtl.h" | 27 #include "base/i18n/rtl.h" |
28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
29 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
30 #include "grit/ash_strings.h" | 30 #include "grit/ash_strings.h" |
31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
33 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 bool is_bubble_visible_; | 198 bool is_bubble_visible_; |
199 int unread_count_; | 199 int unread_count_; |
200 | 200 |
201 views::ImageView no_unread_icon_; | 201 views::ImageView no_unread_icon_; |
202 views::Label unread_label_; | 202 views::Label unread_label_; |
203 | 203 |
204 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | 204 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); |
205 }; | 205 }; |
206 | 206 |
207 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) | 207 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) |
208 : TrayBackgroundView(status_area_widget->wm_shelf()), | 208 : TrayBackgroundView(status_area_widget), |
209 status_area_widget_(status_area_widget), | |
210 button_(NULL), | 209 button_(NULL), |
211 show_message_center_on_unlock_(false), | 210 show_message_center_on_unlock_(false), |
212 should_update_tray_content_(false), | 211 should_update_tray_content_(false), |
213 should_block_shelf_auto_hide_(false) { | 212 should_block_shelf_auto_hide_(false) { |
214 DCHECK(status_area_widget_); | |
215 button_ = new WebNotificationButton(this); | 213 button_ = new WebNotificationButton(this); |
216 button_->set_triggerable_event_flags( | 214 button_->set_triggerable_event_flags( |
217 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 215 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
218 tray_container()->AddChildView(button_); | 216 tray_container()->AddChildView(button_); |
219 SetContentsBackground(); | 217 SetContentsBackground(); |
220 tray_container()->SetBorder(views::Border::NullBorder()); | 218 tray_container()->SetBorder(views::Border::NullBorder()); |
221 message_center_tray_.reset(new message_center::MessageCenterTray( | 219 message_center_tray_.reset(new message_center::MessageCenterTray( |
222 this, | 220 this, |
223 message_center::MessageCenter::Get())); | 221 message_center::MessageCenter::Get())); |
224 WmShelf* shelf = WmLookup::Get() | 222 WmShelf* shelf = WmLookup::Get() |
(...skipping 26 matching lines...) Expand all Loading... |
251 if (!ShouldShowMessageCenter()) | 249 if (!ShouldShowMessageCenter()) |
252 return false; | 250 return false; |
253 | 251 |
254 should_block_shelf_auto_hide_ = true; | 252 should_block_shelf_auto_hide_ = true; |
255 message_center::MessageCenterBubble* message_center_bubble = | 253 message_center::MessageCenterBubble* message_center_bubble = |
256 new message_center::MessageCenterBubble( | 254 new message_center::MessageCenterBubble( |
257 message_center(), | 255 message_center(), |
258 message_center_tray_.get(), | 256 message_center_tray_.get(), |
259 true); | 257 true); |
260 | 258 |
| 259 WmShelf* shelf = GetShelf(); |
261 int max_height; | 260 int max_height; |
262 if (IsHorizontalAlignment(shelf()->GetAlignment())) { | 261 if (IsHorizontalAlignment(shelf->GetAlignment())) { |
263 max_height = shelf()->GetIdealBounds().y(); | 262 max_height = shelf->GetIdealBounds().y(); |
264 } else { | 263 } else { |
265 // Assume the status area and bubble bottoms are aligned when vertical. | 264 // Assume the status area and bubble bottoms are aligned when vertical. |
266 WmWindow* status_area_window = | 265 WmWindow* status_area_window = |
267 WmLookup::Get()->GetWindowForWidget(status_area_widget_); | 266 WmLookup::Get()->GetWindowForWidget(status_area_widget()); |
268 gfx::Rect bounds_in_root = | 267 gfx::Rect bounds_in_root = |
269 status_area_window->GetRootWindow()->ConvertRectFromScreen( | 268 status_area_window->GetRootWindow()->ConvertRectFromScreen( |
270 status_area_window->GetBoundsInScreen()); | 269 status_area_window->GetBoundsInScreen()); |
271 max_height = bounds_in_root.bottom(); | 270 max_height = bounds_in_root.bottom(); |
272 } | 271 } |
273 message_center_bubble->SetMaxHeight( | 272 message_center_bubble->SetMaxHeight( |
274 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); | 273 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); |
275 if (show_settings) | 274 if (show_settings) |
276 message_center_bubble->SetSettingsVisible(); | 275 message_center_bubble->SetSettingsVisible(); |
277 message_center_bubble_.reset( | 276 message_center_bubble_.reset( |
278 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 277 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
279 | 278 |
280 status_area_widget_->SetHideSystemNotifications(true); | 279 status_area_widget()->SetHideSystemNotifications(true); |
281 shelf()->UpdateAutoHideState(); | 280 shelf->UpdateAutoHideState(); |
282 button_->SetBubbleVisible(true); | 281 button_->SetBubbleVisible(true); |
283 SetDrawBackgroundAsActive(true); | 282 SetDrawBackgroundAsActive(true); |
284 return true; | 283 return true; |
285 } | 284 } |
286 | 285 |
287 bool WebNotificationTray::ShowMessageCenter() { | 286 bool WebNotificationTray::ShowMessageCenter() { |
288 return ShowMessageCenterInternal(false /* show_settings */); | 287 return ShowMessageCenterInternal(false /* show_settings */); |
289 } | 288 } |
290 | 289 |
291 void WebNotificationTray::HideMessageCenter() { | 290 void WebNotificationTray::HideMessageCenter() { |
292 if (!message_center_bubble()) | 291 if (!message_center_bubble()) |
293 return; | 292 return; |
294 SetDrawBackgroundAsActive(false); | 293 SetDrawBackgroundAsActive(false); |
295 message_center_bubble_.reset(); | 294 message_center_bubble_.reset(); |
296 should_block_shelf_auto_hide_ = false; | 295 should_block_shelf_auto_hide_ = false; |
297 show_message_center_on_unlock_ = false; | 296 show_message_center_on_unlock_ = false; |
298 status_area_widget_->SetHideSystemNotifications(false); | 297 status_area_widget()->SetHideSystemNotifications(false); |
299 shelf()->UpdateAutoHideState(); | 298 GetShelf()->UpdateAutoHideState(); |
300 button_->SetBubbleVisible(false); | 299 button_->SetBubbleVisible(false); |
301 } | 300 } |
302 | 301 |
303 void WebNotificationTray::SetSystemTrayHeight(int height) { | 302 void WebNotificationTray::SetSystemTrayHeight(int height) { |
304 popup_alignment_delegate_->SetSystemTrayHeight(height); | 303 popup_alignment_delegate_->SetSystemTrayHeight(height); |
305 } | 304 } |
306 | 305 |
307 int WebNotificationTray::system_tray_height_for_test() const { | 306 int WebNotificationTray::system_tray_height_for_test() const { |
308 return popup_alignment_delegate_->system_tray_height_for_test(); | 307 return popup_alignment_delegate_->system_tray_height_for_test(); |
309 } | 308 } |
310 | 309 |
311 bool WebNotificationTray::ShowPopups() { | 310 bool WebNotificationTray::ShowPopups() { |
312 if (message_center_bubble()) | 311 if (message_center_bubble()) |
313 return false; | 312 return false; |
314 | 313 |
315 popup_collection_->DoUpdateIfPossible(); | 314 popup_collection_->DoUpdateIfPossible(); |
316 return true; | 315 return true; |
317 } | 316 } |
318 | 317 |
319 void WebNotificationTray::HidePopups() { | 318 void WebNotificationTray::HidePopups() { |
320 DCHECK(popup_collection_.get()); | 319 DCHECK(popup_collection_.get()); |
321 popup_collection_->MarkAllPopupsShown(); | 320 popup_collection_->MarkAllPopupsShown(); |
322 } | 321 } |
323 | 322 |
324 // Private methods. | 323 // Private methods. |
325 | 324 |
326 bool WebNotificationTray::ShouldShowMessageCenter() { | 325 bool WebNotificationTray::ShouldShowMessageCenter() { |
327 return !(status_area_widget_->system_tray() && | 326 return !(status_area_widget()->system_tray() && |
328 status_area_widget_->system_tray()->HasNotificationBubble()); | 327 status_area_widget()->system_tray()->HasNotificationBubble()); |
329 } | 328 } |
330 | 329 |
331 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { | 330 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { |
332 return should_block_shelf_auto_hide_; | 331 return should_block_shelf_auto_hide_; |
333 } | 332 } |
334 | 333 |
335 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 334 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
336 return (message_center_bubble() && | 335 return (message_center_bubble() && |
337 message_center_bubble()->bubble()->IsVisible()); | 336 message_center_bubble()->bubble()->IsVisible()); |
338 } | 337 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 return; | 512 return; |
514 | 513 |
515 message_center_tray_->HideMessageCenterBubble(); | 514 message_center_tray_->HideMessageCenterBubble(); |
516 } | 515 } |
517 | 516 |
518 message_center::MessageCenter* WebNotificationTray::message_center() const { | 517 message_center::MessageCenter* WebNotificationTray::message_center() const { |
519 return message_center_tray_->message_center(); | 518 return message_center_tray_->message_center(); |
520 } | 519 } |
521 | 520 |
522 bool WebNotificationTray::IsLoggedIn() const { | 521 bool WebNotificationTray::IsLoggedIn() const { |
523 WmShell* shell = WmShell::Get(); | 522 return status_area_widget()->login_status() != LoginStatus::NOT_LOGGED_IN && |
524 // TODO(jamescook): Should this also check LoginState::LOCKED? | 523 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); |
525 return shell->system_tray_delegate()->GetUserLoginStatus() != | |
526 LoginStatus::NOT_LOGGED_IN && | |
527 !shell->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | |
528 } | 524 } |
529 | 525 |
530 // Methods for testing | 526 // Methods for testing |
531 | 527 |
532 bool WebNotificationTray::IsPopupVisible() const { | 528 bool WebNotificationTray::IsPopupVisible() const { |
533 return message_center_tray_->popups_visible(); | 529 return message_center_tray_->popups_visible(); |
534 } | 530 } |
535 | 531 |
536 message_center::MessageCenterBubble* | 532 message_center::MessageCenterBubble* |
537 WebNotificationTray::GetMessageCenterBubbleForTest() { | 533 WebNotificationTray::GetMessageCenterBubbleForTest() { |
538 if (!message_center_bubble()) | 534 if (!message_center_bubble()) |
539 return NULL; | 535 return NULL; |
540 return static_cast<message_center::MessageCenterBubble*>( | 536 return static_cast<message_center::MessageCenterBubble*>( |
541 message_center_bubble()->bubble()); | 537 message_center_bubble()->bubble()); |
542 } | 538 } |
543 | 539 |
544 } // namespace ash | 540 } // namespace ash |
OLD | NEW |