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/status_area_widget.h" | 5 #include "ash/system/status_area_widget.h" |
| 6 | 6 |
| 7 #include "ash/common/shelf/wm_shelf.h" | 7 #include "ash/common/shelf/wm_shelf.h" |
| 8 #include "ash/common/shell_window_ids.h" | 8 #include "ash/common/shell_window_ids.h" |
| 9 #include "ash/common/system/tray/system_tray_delegate.h" | 9 #include "ash/common/system/tray/system_tray_delegate.h" |
| 10 #include "ash/common/system/web_notification/web_notification_tray.h" | |
| 11 #include "ash/common/wm_lookup.h" | |
| 10 #include "ash/common/wm_root_window_controller.h" | 12 #include "ash/common/wm_root_window_controller.h" |
| 11 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 13 #include "ash/system/overview/overview_button_tray.h" | 15 #include "ash/system/overview/overview_button_tray.h" |
| 14 #include "ash/system/status_area_widget_delegate.h" | 16 #include "ash/system/status_area_widget_delegate.h" |
| 15 #include "ash/system/tray/system_tray.h" | 17 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/web_notification/web_notification_tray.h" | |
| 17 #include "ash/wm/window_properties.h" | |
| 18 #include "base/i18n/time_formatting.h" | 18 #include "base/i18n/time_formatting.h" |
| 19 | 19 |
| 20 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
| 21 #include "ash/system/chromeos/session/logout_button_tray.h" | 21 #include "ash/system/chromeos/session/logout_button_tray.h" |
| 22 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 22 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
| 23 #endif | 23 #endif |
| 24 | 24 |
| 25 namespace ash { | 25 namespace ash { |
| 26 | 26 |
| 27 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, | 27 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 56 AddSystemTray(); | 56 AddSystemTray(); |
| 57 AddWebNotificationTray(); | 57 AddWebNotificationTray(); |
| 58 #if defined(OS_CHROMEOS) | 58 #if defined(OS_CHROMEOS) |
| 59 AddLogoutButtonTray(); | 59 AddLogoutButtonTray(); |
| 60 AddVirtualKeyboardTray(); | 60 AddVirtualKeyboardTray(); |
| 61 #endif | 61 #endif |
| 62 | 62 |
| 63 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 63 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 64 DCHECK(delegate); | 64 DCHECK(delegate); |
| 65 // Initialize after all trays have been created. | 65 // Initialize after all trays have been created. |
| 66 system_tray_->InitializeTrayItems(delegate); | 66 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); |
| 67 web_notification_tray_->Initialize(); | 67 web_notification_tray_->Initialize(); |
| 68 #if defined(OS_CHROMEOS) | 68 #if defined(OS_CHROMEOS) |
| 69 logout_button_tray_->Initialize(); | 69 logout_button_tray_->Initialize(); |
| 70 virtual_keyboard_tray_->Initialize(); | 70 virtual_keyboard_tray_->Initialize(); |
| 71 #endif | 71 #endif |
| 72 overview_button_tray_->Initialize(); | 72 overview_button_tray_->Initialize(); |
| 73 SetShelfAlignment(system_tray_->shelf_alignment()); | 73 SetShelfAlignment(system_tray_->shelf_alignment()); |
| 74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
| 75 } | 75 } |
| 76 | 76 |
| 77 void StatusAreaWidget::Shutdown() { | 77 void StatusAreaWidget::Shutdown() { |
| 78 system_tray_->Shutdown(); | |
| 78 // Destroy the trays early, causing them to be removed from the view | 79 // Destroy the trays early, causing them to be removed from the view |
| 79 // hierarchy. Do not used scoped pointers since we don't want to destroy them | 80 // hierarchy. Do not used scoped pointers since we don't want to destroy them |
| 80 // in the destructor if Shutdown() is not called (e.g. in tests). | 81 // in the destructor if Shutdown() is not called (e.g. in tests). |
| 81 delete web_notification_tray_; | 82 delete web_notification_tray_; |
| 82 web_notification_tray_ = NULL; | 83 web_notification_tray_ = NULL; |
| 84 // Must be destroyed after |web_notification_tray_|. | |
|
msw
2016/06/27 23:57:36
It's a bit odd to call this out and also need to s
James Cook
2016/06/28 00:47:25
Discussed offline. Both SystemTray and WebNotifica
| |
| 83 delete system_tray_; | 85 delete system_tray_; |
| 84 system_tray_ = NULL; | 86 system_tray_ = NULL; |
| 85 #if defined(OS_CHROMEOS) | 87 #if defined(OS_CHROMEOS) |
| 86 delete virtual_keyboard_tray_; | 88 delete virtual_keyboard_tray_; |
| 87 virtual_keyboard_tray_ = NULL; | 89 virtual_keyboard_tray_ = NULL; |
| 88 delete logout_button_tray_; | 90 delete logout_button_tray_; |
| 89 logout_button_tray_ = NULL; | 91 logout_button_tray_ = NULL; |
| 90 #endif | 92 #endif |
| 91 delete overview_button_tray_; | 93 delete overview_button_tray_; |
| 92 overview_button_tray_ = NULL; | 94 overview_button_tray_ = NULL; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 Widget::OnMouseEvent(event); | 137 Widget::OnMouseEvent(event); |
| 136 wm_shelf_->UpdateAutoHideForMouseEvent(event); | 138 wm_shelf_->UpdateAutoHideForMouseEvent(event); |
| 137 } | 139 } |
| 138 | 140 |
| 139 void StatusAreaWidget::OnGestureEvent(ui::GestureEvent* event) { | 141 void StatusAreaWidget::OnGestureEvent(ui::GestureEvent* event) { |
| 140 Widget::OnGestureEvent(event); | 142 Widget::OnGestureEvent(event); |
| 141 wm_shelf_->UpdateAutoHideForGestureEvent(event); | 143 wm_shelf_->UpdateAutoHideForGestureEvent(event); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void StatusAreaWidget::AddSystemTray() { | 146 void StatusAreaWidget::AddSystemTray() { |
| 145 system_tray_ = new SystemTray(this); | 147 system_tray_ = new SystemTray(wm_shelf_); |
| 146 status_area_widget_delegate_->AddTray(system_tray_); | 148 status_area_widget_delegate_->AddTray(system_tray_); |
| 147 } | 149 } |
| 148 | 150 |
| 149 void StatusAreaWidget::AddWebNotificationTray() { | 151 void StatusAreaWidget::AddWebNotificationTray() { |
| 150 web_notification_tray_ = new WebNotificationTray(this); | 152 DCHECK(system_tray_); |
| 153 web_notification_tray_ = new WebNotificationTray( | |
| 154 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_); | |
| 151 status_area_widget_delegate_->AddTray(web_notification_tray_); | 155 status_area_widget_delegate_->AddTray(web_notification_tray_); |
| 152 } | 156 } |
| 153 | 157 |
| 154 #if defined(OS_CHROMEOS) | 158 #if defined(OS_CHROMEOS) |
| 155 void StatusAreaWidget::AddLogoutButtonTray() { | 159 void StatusAreaWidget::AddLogoutButtonTray() { |
| 156 logout_button_tray_ = new LogoutButtonTray(this); | 160 logout_button_tray_ = new LogoutButtonTray(wm_shelf_); |
| 157 status_area_widget_delegate_->AddTray(logout_button_tray_); | 161 status_area_widget_delegate_->AddTray(logout_button_tray_); |
| 158 } | 162 } |
| 159 | 163 |
| 160 void StatusAreaWidget::AddVirtualKeyboardTray() { | 164 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 161 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); | 165 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); |
| 162 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 166 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 163 } | 167 } |
| 164 #endif | 168 #endif |
| 165 | 169 |
| 166 void StatusAreaWidget::AddOverviewButtonTray() { | 170 void StatusAreaWidget::AddOverviewButtonTray() { |
| 167 overview_button_tray_ = new OverviewButtonTray(this); | 171 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); |
| 168 status_area_widget_delegate_->AddTray(overview_button_tray_); | 172 status_area_widget_delegate_->AddTray(overview_button_tray_); |
| 169 } | 173 } |
| 170 | 174 |
| 171 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 175 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| 172 status_area_widget_delegate_->set_alignment(alignment); | 176 status_area_widget_delegate_->set_alignment(alignment); |
| 173 if (system_tray_) | 177 if (system_tray_) |
| 174 system_tray_->SetShelfAlignment(alignment); | 178 system_tray_->SetShelfAlignment(alignment); |
| 175 if (web_notification_tray_) | 179 if (web_notification_tray_) |
| 176 web_notification_tray_->SetShelfAlignment(alignment); | 180 web_notification_tray_->SetShelfAlignment(alignment); |
| 177 #if defined(OS_CHROMEOS) | 181 #if defined(OS_CHROMEOS) |
| 178 if (logout_button_tray_) | 182 if (logout_button_tray_) |
| 179 logout_button_tray_->SetShelfAlignment(alignment); | 183 logout_button_tray_->SetShelfAlignment(alignment); |
| 180 if (virtual_keyboard_tray_) | 184 if (virtual_keyboard_tray_) |
| 181 virtual_keyboard_tray_->SetShelfAlignment(alignment); | 185 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| 182 #endif | 186 #endif |
| 183 if (overview_button_tray_) | 187 if (overview_button_tray_) |
| 184 overview_button_tray_->SetShelfAlignment(alignment); | 188 overview_button_tray_->SetShelfAlignment(alignment); |
| 185 status_area_widget_delegate_->UpdateLayout(); | 189 status_area_widget_delegate_->UpdateLayout(); |
| 186 } | 190 } |
| 187 | 191 |
| 188 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { | |
| 189 if (system_tray_) | |
| 190 system_tray_->SetHideNotifications(hide); | |
| 191 } | |
| 192 | |
| 193 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 192 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| 194 if (login_status_ == login_status) | 193 if (login_status_ == login_status) |
| 195 return; | 194 return; |
| 196 login_status_ = login_status; | 195 login_status_ = login_status; |
| 197 if (system_tray_) | 196 if (system_tray_) |
| 198 system_tray_->UpdateAfterLoginStatusChange(login_status); | 197 system_tray_->UpdateAfterLoginStatusChange(login_status); |
| 199 if (web_notification_tray_) | 198 if (web_notification_tray_) |
| 200 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 199 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
| 201 #if defined(OS_CHROMEOS) | 200 #if defined(OS_CHROMEOS) |
| 202 if (logout_button_tray_) | 201 if (logout_button_tray_) |
| 203 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 202 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 204 #endif | 203 #endif |
| 205 if (overview_button_tray_) | 204 if (overview_button_tray_) |
| 206 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); | 205 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 207 } | 206 } |
| 208 | 207 |
| 209 } // namespace ash | 208 } // namespace ash |
| OLD | NEW |