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/status_area_widget.h" | 5 #include "ash/system/status_area_widget.h" |
6 | 6 |
7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
9 #include "ash/shelf/shelf_widget.h" | 9 #include "ash/shelf/shelf_widget.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_delegate.h" | 11 #include "ash/shell_delegate.h" |
12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
13 #include "ash/system/bluetooth/bluetooth_observer.h" | 13 #include "ash/system/bluetooth/bluetooth_observer.h" |
14 #include "ash/system/logout_button/logout_button_tray.h" | 14 #include "ash/system/logout_button/logout_button_tray.h" |
15 #include "ash/system/status_area_widget_delegate.h" | 15 #include "ash/system/status_area_widget_delegate.h" |
16 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
17 #include "ash/system/tray/system_tray_delegate.h" | 17 #include "ash/system/tray/system_tray_delegate.h" |
18 #include "ash/system/web_notification/web_notification_tray.h" | 18 #include "ash/system/web_notification/web_notification_tray.h" |
19 #include "ash/wm/window_properties.h" | 19 #include "ash/wm/window_properties.h" |
20 #include "base/i18n/time_formatting.h" | 20 #include "base/i18n/time_formatting.h" |
21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
23 | 23 |
| 24 #if defined(OS_CHROMEOS) |
| 25 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
| 26 #endif |
| 27 |
24 namespace ash { | 28 namespace ash { |
25 | 29 |
26 namespace internal { | 30 namespace internal { |
27 | 31 |
28 const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; | 32 const char StatusAreaWidget::kNativeViewName[] = "StatusAreaWidget"; |
29 | 33 |
30 StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) | 34 StatusAreaWidget::StatusAreaWidget(aura::Window* status_container) |
31 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), | 35 : status_area_widget_delegate_(new internal::StatusAreaWidgetDelegate), |
32 system_tray_(NULL), | 36 system_tray_(NULL), |
33 web_notification_tray_(NULL), | 37 web_notification_tray_(NULL), |
34 logout_button_tray_(NULL), | 38 logout_button_tray_(NULL), |
| 39 #if defined(OS_CHROMEOS) |
| 40 virtual_keyboard_tray_(NULL), |
| 41 #endif |
35 login_status_(user::LOGGED_IN_NONE) { | 42 login_status_(user::LOGGED_IN_NONE) { |
36 views::Widget::InitParams params( | 43 views::Widget::InitParams params( |
37 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 44 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
38 params.delegate = status_area_widget_delegate_; | 45 params.delegate = status_area_widget_delegate_; |
39 params.parent = status_container; | 46 params.parent = status_container; |
40 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 47 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
41 Init(params); | 48 Init(params); |
42 set_focus_on_creation(false); | 49 set_focus_on_creation(false); |
43 SetContentsView(status_area_widget_delegate_); | 50 SetContentsView(status_area_widget_delegate_); |
44 GetNativeView()->SetName(kNativeViewName); | 51 GetNativeView()->SetName(kNativeViewName); |
45 } | 52 } |
46 | 53 |
47 StatusAreaWidget::~StatusAreaWidget() { | 54 StatusAreaWidget::~StatusAreaWidget() { |
48 } | 55 } |
49 | 56 |
50 void StatusAreaWidget::CreateTrayViews() { | 57 void StatusAreaWidget::CreateTrayViews() { |
51 AddSystemTray(); | 58 AddSystemTray(); |
52 AddWebNotificationTray(); | 59 AddWebNotificationTray(); |
53 AddLogoutButtonTray(); | 60 AddLogoutButtonTray(); |
| 61 #if defined(OS_CHROMEOS) |
| 62 AddVirtualKeyboardTray(); |
| 63 #endif |
54 SystemTrayDelegate* delegate = | 64 SystemTrayDelegate* delegate = |
55 ash::Shell::GetInstance()->system_tray_delegate(); | 65 ash::Shell::GetInstance()->system_tray_delegate(); |
56 DCHECK(delegate); | 66 DCHECK(delegate); |
57 // Initialize after all trays have been created. | 67 // Initialize after all trays have been created. |
58 if (system_tray_) | 68 if (system_tray_) |
59 system_tray_->InitializeTrayItems(delegate); | 69 system_tray_->InitializeTrayItems(delegate); |
60 if (web_notification_tray_) | 70 if (web_notification_tray_) |
61 web_notification_tray_->Initialize(); | 71 web_notification_tray_->Initialize(); |
62 if (logout_button_tray_) | 72 if (logout_button_tray_) |
63 logout_button_tray_->Initialize(); | 73 logout_button_tray_->Initialize(); |
| 74 #if defined(OS_CHROMEOS) |
| 75 if (virtual_keyboard_tray_) |
| 76 virtual_keyboard_tray_->Initialize(); |
| 77 #endif |
64 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 78 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
65 } | 79 } |
66 | 80 |
67 void StatusAreaWidget::Shutdown() { | 81 void StatusAreaWidget::Shutdown() { |
68 // Destroy the trays early, causing them to be removed from the view | 82 // Destroy the trays early, causing them to be removed from the view |
69 // hierarchy. Do not used scoped pointers since we don't want to destroy them | 83 // hierarchy. Do not used scoped pointers since we don't want to destroy them |
70 // in the destructor if Shutdown() is not called (e.g. in tests). | 84 // in the destructor if Shutdown() is not called (e.g. in tests). |
71 delete logout_button_tray_; | 85 delete logout_button_tray_; |
72 logout_button_tray_ = NULL; | 86 logout_button_tray_ = NULL; |
73 delete web_notification_tray_; | 87 delete web_notification_tray_; |
74 web_notification_tray_ = NULL; | 88 web_notification_tray_ = NULL; |
75 delete system_tray_; | 89 delete system_tray_; |
76 system_tray_ = NULL; | 90 system_tray_ = NULL; |
| 91 #if defined(OS_CHROMEOS) |
| 92 delete virtual_keyboard_tray_; |
| 93 virtual_keyboard_tray_ = NULL; |
| 94 #endif |
77 } | 95 } |
78 | 96 |
79 bool StatusAreaWidget::ShouldShowShelf() const { | 97 bool StatusAreaWidget::ShouldShowShelf() const { |
80 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 98 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
81 (web_notification_tray_ && | 99 (web_notification_tray_ && |
82 web_notification_tray_->ShouldBlockShelfAutoHide())) | 100 web_notification_tray_->ShouldBlockShelfAutoHide())) |
83 return true; | 101 return true; |
84 | 102 |
85 if (!RootWindowController::ForShelf(GetNativeView())->shelf()->IsVisible()) | 103 if (!RootWindowController::ForShelf(GetNativeView())->shelf()->IsVisible()) |
86 return false; | 104 return false; |
(...skipping 25 matching lines...) Expand all Loading... |
112 void StatusAreaWidget::AddWebNotificationTray() { | 130 void StatusAreaWidget::AddWebNotificationTray() { |
113 web_notification_tray_ = new WebNotificationTray(this); | 131 web_notification_tray_ = new WebNotificationTray(this); |
114 status_area_widget_delegate_->AddTray(web_notification_tray_); | 132 status_area_widget_delegate_->AddTray(web_notification_tray_); |
115 } | 133 } |
116 | 134 |
117 void StatusAreaWidget::AddLogoutButtonTray() { | 135 void StatusAreaWidget::AddLogoutButtonTray() { |
118 logout_button_tray_ = new LogoutButtonTray(this); | 136 logout_button_tray_ = new LogoutButtonTray(this); |
119 status_area_widget_delegate_->AddTray(logout_button_tray_); | 137 status_area_widget_delegate_->AddTray(logout_button_tray_); |
120 } | 138 } |
121 | 139 |
| 140 #if defined(OS_CHROMEOS) |
| 141 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 142 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); |
| 143 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 144 } |
| 145 #endif |
| 146 |
122 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 147 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
123 status_area_widget_delegate_->set_alignment(alignment); | 148 status_area_widget_delegate_->set_alignment(alignment); |
124 if (system_tray_) | 149 if (system_tray_) |
125 system_tray_->SetShelfAlignment(alignment); | 150 system_tray_->SetShelfAlignment(alignment); |
126 if (web_notification_tray_) | 151 if (web_notification_tray_) |
127 web_notification_tray_->SetShelfAlignment(alignment); | 152 web_notification_tray_->SetShelfAlignment(alignment); |
128 if (logout_button_tray_) | 153 if (logout_button_tray_) |
129 logout_button_tray_->SetShelfAlignment(alignment); | 154 logout_button_tray_->SetShelfAlignment(alignment); |
| 155 #if defined(OS_CHROMEOS) |
| 156 if (virtual_keyboard_tray_) |
| 157 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| 158 #endif |
130 status_area_widget_delegate_->UpdateLayout(); | 159 status_area_widget_delegate_->UpdateLayout(); |
131 } | 160 } |
132 | 161 |
133 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { | 162 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { |
134 if (system_tray_) | 163 if (system_tray_) |
135 system_tray_->SetHideNotifications(hide); | 164 system_tray_->SetHideNotifications(hide); |
136 } | 165 } |
137 | 166 |
138 void StatusAreaWidget::UpdateAfterLoginStatusChange( | 167 void StatusAreaWidget::UpdateAfterLoginStatusChange( |
139 user::LoginStatus login_status) { | 168 user::LoginStatus login_status) { |
140 if (login_status_ == login_status) | 169 if (login_status_ == login_status) |
141 return; | 170 return; |
142 login_status_ = login_status; | 171 login_status_ = login_status; |
143 if (system_tray_) | 172 if (system_tray_) |
144 system_tray_->UpdateAfterLoginStatusChange(login_status); | 173 system_tray_->UpdateAfterLoginStatusChange(login_status); |
145 if (web_notification_tray_) | 174 if (web_notification_tray_) |
146 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 175 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
147 if (logout_button_tray_) | 176 if (logout_button_tray_) |
148 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 177 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
149 } | 178 } |
150 | 179 |
151 } // namespace internal | 180 } // namespace internal |
152 } // namespace ash | 181 } // namespace ash |
OLD | NEW |