Chromium Code Reviews| 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" | |
| 14 #include "ash/common/system/tray/tray_constants.h" | 13 #include "ash/common/system/tray/tray_constants.h" |
| 15 #include "ash/common/system/tray/tray_utils.h" | 14 #include "ash/common/system/tray/tray_utils.h" |
| 16 #include "ash/common/wm_lookup.h" | 15 #include "ash/common/wm_lookup.h" |
| 17 #include "ash/common/wm_root_window_controller.h" | 16 #include "ash/common/wm_root_window_controller.h" |
| 17 #include "ash/common/wm_shell.h" | |
| 18 #include "ash/common/wm_window.h" | 18 #include "ash/common/wm_window.h" |
| 19 #include "ash/shell.h" | |
| 20 #include "ash/system/status_area_widget.h" | 19 #include "ash/system/status_area_widget.h" |
| 21 #include "ash/system/tray/system_tray.h" | 20 #include "ash/system/tray/system_tray.h" |
| 22 #include "ash/system/tray/tray_background_view.h" | 21 #include "ash/system/tray/tray_background_view.h" |
| 23 #include "ash/system/tray/tray_bubble_wrapper.h" | 22 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 23 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 25 #include "base/auto_reset.h" | 24 #include "base/auto_reset.h" |
| 26 #include "base/i18n/number_formatting.h" | 25 #include "base/i18n/number_formatting.h" |
| 27 #include "base/i18n/rtl.h" | 26 #include "base/i18n/rtl.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 214 SetContentsBackground(); | 213 SetContentsBackground(); |
| 215 tray_container()->SetBorder(views::Border::NullBorder()); | 214 tray_container()->SetBorder(views::Border::NullBorder()); |
| 216 message_center_tray_.reset(new message_center::MessageCenterTray( | 215 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 217 this, | 216 this, |
| 218 message_center::MessageCenter::Get())); | 217 message_center::MessageCenter::Get())); |
| 219 WmShelf* shelf = WmLookup::Get() | 218 WmShelf* shelf = WmLookup::Get() |
| 220 ->GetWindowForWidget(status_area_widget) | 219 ->GetWindowForWidget(status_area_widget) |
| 221 ->GetRootWindowController() | 220 ->GetRootWindowController() |
| 222 ->GetShelf(); | 221 ->GetShelf(); |
| 223 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); | 222 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); |
| 224 // TODO(jamescook): Either MessagePopupCollection needs to become aware of | |
| 225 // mus or we need some sort of parent/container provider. | |
| 226 popup_collection_.reset(new message_center::MessagePopupCollection( | 223 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 227 ash::Shell::GetContainer( | |
| 228 status_area_widget->GetNativeView()->GetRootWindow(), | |
| 229 kShellWindowId_StatusContainer), | |
| 230 message_center(), | 224 message_center(), |
| 231 message_center_tray_.get(), | 225 message_center_tray_.get(), |
| 232 popup_alignment_delegate_.get())); | 226 popup_alignment_delegate_.get())); |
| 233 const display::Display& display = WmLookup::Get() | 227 const display::Display& display = WmLookup::Get() |
| 234 ->GetWindowForWidget(status_area_widget) | 228 ->GetWindowForWidget(status_area_widget) |
| 235 ->GetDisplayNearestWindow(); | 229 ->GetDisplayNearestWindow(); |
| 236 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), | 230 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), |
| 237 display); | 231 display); |
| 238 OnMessageCenterTrayChanged(); | 232 OnMessageCenterTrayChanged(); |
| 239 } | 233 } |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 bool WebNotificationTray::ShowNotifierSettings() { | 414 bool WebNotificationTray::ShowNotifierSettings() { |
| 421 if (message_center_bubble()) { | 415 if (message_center_bubble()) { |
| 422 static_cast<message_center::MessageCenterBubble*>( | 416 static_cast<message_center::MessageCenterBubble*>( |
| 423 message_center_bubble()->bubble())->SetSettingsVisible(); | 417 message_center_bubble()->bubble())->SetSettingsVisible(); |
| 424 return true; | 418 return true; |
| 425 } | 419 } |
| 426 return ShowMessageCenterInternal(true /* show_settings */); | 420 return ShowMessageCenterInternal(true /* show_settings */); |
| 427 } | 421 } |
| 428 | 422 |
| 429 bool WebNotificationTray::IsContextMenuEnabled() const { | 423 bool WebNotificationTray::IsContextMenuEnabled() const { |
| 430 LoginStatus login_status = status_area_widget()->login_status(); | 424 return IsLoggedIn(); |
| 431 bool userAddingRunning = ash::Shell::GetInstance() | |
| 432 ->session_state_delegate() | |
| 433 ->IsInSecondaryLoginScreen(); | |
| 434 | |
| 435 return login_status != LoginStatus::NOT_LOGGED_IN && !userAddingRunning; | |
| 436 } | 425 } |
| 437 | 426 |
| 438 message_center::MessageCenterTray* WebNotificationTray::GetMessageCenterTray() { | 427 message_center::MessageCenterTray* WebNotificationTray::GetMessageCenterTray() { |
| 439 return message_center_tray_.get(); | 428 return message_center_tray_.get(); |
| 440 } | 429 } |
| 441 | 430 |
| 442 bool WebNotificationTray::IsCommandIdChecked(int command_id) const { | 431 bool WebNotificationTray::IsCommandIdChecked(int command_id) const { |
| 443 if (command_id != kToggleQuietMode) | 432 if (command_id != kToggleQuietMode) |
| 444 return false; | 433 return false; |
| 445 return message_center()->IsQuietMode(); | 434 return message_center()->IsQuietMode(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 488 return; | 477 return; |
| 489 should_update_tray_content_ = false; | 478 should_update_tray_content_ = false; |
| 490 | 479 |
| 491 message_center::MessageCenter* message_center = | 480 message_center::MessageCenter* message_center = |
| 492 message_center_tray_->message_center(); | 481 message_center_tray_->message_center(); |
| 493 button_->SetUnreadCount(message_center->UnreadNotificationCount()); | 482 button_->SetUnreadCount(message_center->UnreadNotificationCount()); |
| 494 if (IsMessageCenterBubbleVisible()) | 483 if (IsMessageCenterBubbleVisible()) |
| 495 button_->SetState(views::CustomButton::STATE_PRESSED); | 484 button_->SetState(views::CustomButton::STATE_PRESSED); |
| 496 else | 485 else |
| 497 button_->SetState(views::CustomButton::STATE_NORMAL); | 486 button_->SetState(views::CustomButton::STATE_NORMAL); |
| 498 bool userAddingRunning = ash::Shell::GetInstance() | |
| 499 ->session_state_delegate() | |
| 500 ->IsInSecondaryLoginScreen(); | |
| 501 | 487 |
| 502 SetVisible( | 488 SetVisible(IsLoggedIn()); |
| 503 (status_area_widget()->login_status() != LoginStatus::NOT_LOGGED_IN) && | |
| 504 !userAddingRunning); | |
| 505 Layout(); | 489 Layout(); |
| 506 SchedulePaint(); | 490 SchedulePaint(); |
| 507 } | 491 } |
| 508 | 492 |
| 509 void WebNotificationTray::ClickedOutsideBubble() { | 493 void WebNotificationTray::ClickedOutsideBubble() { |
| 510 // Only hide the message center | 494 // Only hide the message center |
| 511 if (!message_center_bubble()) | 495 if (!message_center_bubble()) |
| 512 return; | 496 return; |
| 513 | 497 |
| 514 message_center_tray_->HideMessageCenterBubble(); | 498 message_center_tray_->HideMessageCenterBubble(); |
| 515 } | 499 } |
| 516 | 500 |
| 517 message_center::MessageCenter* WebNotificationTray::message_center() const { | 501 message_center::MessageCenter* WebNotificationTray::message_center() const { |
| 518 return message_center_tray_->message_center(); | 502 return message_center_tray_->message_center(); |
| 519 } | 503 } |
| 520 | 504 |
| 505 bool WebNotificationTray::IsLoggedIn() const { | |
| 506 return status_area_widget()->login_status() != LoginStatus::NOT_LOGGED_IN && | |
|
msw
2016/06/17 22:28:11
q: Is it odd that this doesn't check for LoginStat
James Cook
2016/06/17 23:46:33
A little, but maybe you want notifications at the
stevenjb
2016/06/20 17:41:35
Apparently elsewhere we hide the message center wh
James Cook
2016/06/20 18:05:10
Acknowledged.
| |
| 507 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | |
| 508 } | |
| 509 | |
| 521 // Methods for testing | 510 // Methods for testing |
| 522 | 511 |
| 523 bool WebNotificationTray::IsPopupVisible() const { | 512 bool WebNotificationTray::IsPopupVisible() const { |
| 524 return message_center_tray_->popups_visible(); | 513 return message_center_tray_->popups_visible(); |
| 525 } | 514 } |
| 526 | 515 |
| 527 message_center::MessageCenterBubble* | 516 message_center::MessageCenterBubble* |
| 528 WebNotificationTray::GetMessageCenterBubbleForTest() { | 517 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 529 if (!message_center_bubble()) | 518 if (!message_center_bubble()) |
| 530 return NULL; | 519 return NULL; |
| 531 return static_cast<message_center::MessageCenterBubble*>( | 520 return static_cast<message_center::MessageCenterBubble*>( |
| 532 message_center_bubble()->bubble()); | 521 message_center_bubble()->bubble()); |
| 533 } | 522 } |
| 534 | 523 |
| 535 } // namespace ash | 524 } // namespace ash |
| OLD | NEW |