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
3 // found in the LICENSE file.
5 #include "ash/system/status_area_widget.h"
7 #include "ash/root_window_controller.h"
8 #include "ash/shelf/shelf_layout_manager.h"
9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell.h"
11 #include "ash/shell_delegate.h"
12 #include "ash/shell_window_ids.h"
13 #include "ash/system/bluetooth/bluetooth_observer.h"
14 #include "ash/system/status_area_widget_delegate.h"
15 #include "ash/system/tray/system_tray.h"
16 #include "ash/system/tray/system_tray_delegate.h"
17 #include "ash/system/web_notification/web_notification_tray.h"
18 #include "ash/wm/window_properties.h"
19 #include "base/i18n/time_formatting.h"
20 #include "ui/aura/window.h"
21 #include "ui/gfx/screen.h"
27 StatusAreaWidget::StatusAreaWidget(aura::Window
* status_container
)
28 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate
),
30 web_notification_tray_(NULL
),
31 login_status_(user::LOGGED_IN_NONE
) {
32 views::Widget::InitParams
params(
33 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS
);
34 params
.delegate
= status_area_widget_delegate_
;
35 params
.parent
= status_container
;
36 params
.transparent
= true;
38 set_focus_on_creation(false);
39 SetContentsView(status_area_widget_delegate_
);
40 GetNativeView()->SetName("StatusAreaWidget");
41 GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey
, true);
44 StatusAreaWidget::~StatusAreaWidget() {
47 void StatusAreaWidget::CreateTrayViews() {
49 AddWebNotificationTray();
50 SystemTrayDelegate
* delegate
=
51 ash::Shell::GetInstance()->system_tray_delegate();
53 // Initialize after all trays have been created.
55 system_tray_
->InitializeTrayItems(delegate
);
56 if (web_notification_tray_
)
57 web_notification_tray_
->Initialize();
58 UpdateAfterLoginStatusChange(delegate
->GetUserLoginStatus());
61 void StatusAreaWidget::Shutdown() {
62 // Destroy the trays early, causing them to be removed from the view
63 // hierarchy. Do not used scoped pointers since we don't want to destroy them
64 // in the destructor if Shutdown() is not called (e.g. in tests).
65 delete web_notification_tray_
;
66 web_notification_tray_
= NULL
;
71 bool StatusAreaWidget::ShouldShowLauncher() const {
72 if ((system_tray_
&& system_tray_
->ShouldShowLauncher()) ||
73 (web_notification_tray_
&&
74 web_notification_tray_
->ShouldBlockLauncherAutoHide()))
77 if (!RootWindowController::ForLauncher(GetNativeView())->shelf()->IsVisible())
80 // If the launcher is currently visible, don't hide the launcher if the mouse
81 // is in any of the notification bubbles.
82 return (system_tray_
&& system_tray_
->IsMouseInNotificationBubble()) ||
83 (web_notification_tray_
&&
84 web_notification_tray_
->IsMouseInNotificationBubble());
87 bool StatusAreaWidget::IsMessageBubbleShown() const {
88 return ((system_tray_
&& system_tray_
->IsAnyBubbleVisible()) ||
89 (web_notification_tray_
&&
90 web_notification_tray_
->IsMessageCenterBubbleVisible()));
93 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active
) {
94 Widget::OnNativeWidgetActivationChanged(active
);
96 status_area_widget_delegate_
->SetPaneFocusAndFocusDefault();
99 void StatusAreaWidget::AddSystemTray() {
100 system_tray_
= new SystemTray(this);
101 status_area_widget_delegate_
->AddTray(system_tray_
);
104 void StatusAreaWidget::AddWebNotificationTray() {
105 web_notification_tray_
= new WebNotificationTray(this);
106 status_area_widget_delegate_
->AddTray(web_notification_tray_
);
109 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment
) {
110 status_area_widget_delegate_
->set_alignment(alignment
);
112 system_tray_
->SetShelfAlignment(alignment
);
113 if (web_notification_tray_
)
114 web_notification_tray_
->SetShelfAlignment(alignment
);
115 status_area_widget_delegate_
->UpdateLayout();
118 void StatusAreaWidget::SetHideWebNotifications(bool hide
) {
119 if (web_notification_tray_
)
120 web_notification_tray_
->SetHidePopupBubble(hide
);
123 void StatusAreaWidget::SetHideSystemNotifications(bool hide
) {
125 system_tray_
->SetHideNotifications(hide
);
128 bool StatusAreaWidget::ShouldShowWebNotifications() {
129 return !(system_tray_
&& system_tray_
->IsAnyBubbleVisible());
132 void StatusAreaWidget::UpdateAfterLoginStatusChange(
133 user::LoginStatus login_status
) {
134 if (login_status_
== login_status
)
136 login_status_
= login_status
;
138 system_tray_
->UpdateAfterLoginStatusChange(login_status
);
139 if (web_notification_tray_
)
140 web_notification_tray_
->UpdateAfterLoginStatusChange(login_status
);
143 } // namespace internal