| 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/common/system/status_area_widget.h" | 5 #include "ash/common/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/overview/overview_button_tray.h" | 9 #include "ash/common/system/overview/overview_button_tray.h" |
| 10 #include "ash/common/system/status_area_widget_delegate.h" | 10 #include "ash/common/system/status_area_widget_delegate.h" |
| 11 #include "ash/common/system/tray/system_tray.h" | 11 #include "ash/common/system/tray/system_tray.h" |
| 12 #include "ash/common/system/tray/system_tray_delegate.h" | 12 #include "ash/common/system/tray/system_tray_delegate.h" |
| 13 #include "ash/common/system/web_notification/web_notification_tray.h" | 13 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 14 #include "ash/common/wm_lookup.h" | 14 #include "ash/common/wm_lookup.h" |
| 15 #include "ash/common/wm_root_window_controller.h" | 15 #include "ash/common/wm_root_window_controller.h" |
| 16 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
| 17 #include "ash/common/wm_window.h" | 17 #include "ash/common/wm_window.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/common/system/chromeos/ime_menu/ime_menu_tray.h" | 21 #include "ash/common/system/chromeos/ime_menu/ime_menu_tray.h" |
| 22 #include "ash/common/system/chromeos/palette/palette_tray.h" |
| 22 #include "ash/common/system/chromeos/session/logout_button_tray.h" | 23 #include "ash/common/system/chromeos/session/logout_button_tray.h" |
| 23 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 24 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
| 24 #endif | 25 #endif |
| 25 | 26 |
| 26 namespace ash { | 27 namespace ash { |
| 27 | 28 |
| 28 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, | 29 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, |
| 29 WmShelf* wm_shelf) | 30 WmShelf* wm_shelf) |
| 30 : status_area_widget_delegate_(new StatusAreaWidgetDelegate), | 31 : status_area_widget_delegate_(new StatusAreaWidgetDelegate), |
| 31 overview_button_tray_(NULL), | 32 overview_button_tray_(nullptr), |
| 32 system_tray_(NULL), | 33 system_tray_(nullptr), |
| 33 web_notification_tray_(NULL), | 34 web_notification_tray_(nullptr), |
| 34 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 35 logout_button_tray_(NULL), | 36 logout_button_tray_(nullptr), |
| 36 virtual_keyboard_tray_(NULL), | 37 palette_tray_(nullptr), |
| 38 virtual_keyboard_tray_(nullptr), |
| 37 ime_menu_tray_(nullptr), | 39 ime_menu_tray_(nullptr), |
| 38 #endif | 40 #endif |
| 39 login_status_(LoginStatus::NOT_LOGGED_IN), | 41 login_status_(LoginStatus::NOT_LOGGED_IN), |
| 40 wm_shelf_(wm_shelf) { | 42 wm_shelf_(wm_shelf) { |
| 41 views::Widget::InitParams params( | 43 views::Widget::InitParams params( |
| 42 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 44 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 43 params.delegate = status_area_widget_delegate_; | 45 params.delegate = status_area_widget_delegate_; |
| 44 params.name = "StatusAreaWidget"; | 46 params.name = "StatusAreaWidget"; |
| 45 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 47 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 46 status_container->GetRootWindowController() | 48 status_container->GetRootWindowController() |
| 47 ->ConfigureWidgetInitParamsForContainer( | 49 ->ConfigureWidgetInitParamsForContainer( |
| 48 this, status_container->GetShellWindowId(), ¶ms); | 50 this, status_container->GetShellWindowId(), ¶ms); |
| 49 Init(params); | 51 Init(params); |
| 50 set_focus_on_creation(false); | 52 set_focus_on_creation(false); |
| 51 SetContentsView(status_area_widget_delegate_); | 53 SetContentsView(status_area_widget_delegate_); |
| 52 } | 54 } |
| 53 | 55 |
| 54 StatusAreaWidget::~StatusAreaWidget() {} | 56 StatusAreaWidget::~StatusAreaWidget() {} |
| 55 | 57 |
| 56 void StatusAreaWidget::CreateTrayViews() { | 58 void StatusAreaWidget::CreateTrayViews() { |
| 57 AddOverviewButtonTray(); | 59 AddOverviewButtonTray(); |
| 58 AddSystemTray(); | 60 AddSystemTray(); |
| 59 AddWebNotificationTray(); | 61 AddWebNotificationTray(); |
| 60 #if defined(OS_CHROMEOS) | 62 #if defined(OS_CHROMEOS) |
| 61 AddLogoutButtonTray(); | 63 AddLogoutButtonTray(); |
| 64 AddPaletteTray(); |
| 62 AddVirtualKeyboardTray(); | 65 AddVirtualKeyboardTray(); |
| 63 AddImeMenuTray(); | 66 AddImeMenuTray(); |
| 64 #endif | 67 #endif |
| 65 | 68 |
| 66 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 69 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 67 DCHECK(delegate); | 70 DCHECK(delegate); |
| 68 // Initialize after all trays have been created. | 71 // Initialize after all trays have been created. |
| 69 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); | 72 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); |
| 70 web_notification_tray_->Initialize(); | 73 web_notification_tray_->Initialize(); |
| 71 #if defined(OS_CHROMEOS) | 74 #if defined(OS_CHROMEOS) |
| 72 logout_button_tray_->Initialize(); | 75 logout_button_tray_->Initialize(); |
| 73 virtual_keyboard_tray_->Initialize(); | 76 virtual_keyboard_tray_->Initialize(); |
| 74 ime_menu_tray_->Initialize(); | 77 ime_menu_tray_->Initialize(); |
| 75 #endif | 78 #endif |
| 76 overview_button_tray_->Initialize(); | 79 overview_button_tray_->Initialize(); |
| 77 SetShelfAlignment(system_tray_->shelf_alignment()); | 80 SetShelfAlignment(system_tray_->shelf_alignment()); |
| 78 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 81 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
| 79 } | 82 } |
| 80 | 83 |
| 81 void StatusAreaWidget::Shutdown() { | 84 void StatusAreaWidget::Shutdown() { |
| 82 system_tray_->Shutdown(); | 85 system_tray_->Shutdown(); |
| 83 // Destroy the trays early, causing them to be removed from the view | 86 // Destroy the trays early, causing them to be removed from the view |
| 84 // hierarchy. Do not used scoped pointers since we don't want to destroy them | 87 // hierarchy. Do not used scoped pointers since we don't want to destroy them |
| 85 // in the destructor if Shutdown() is not called (e.g. in tests). | 88 // in the destructor if Shutdown() is not called (e.g. in tests). |
| 86 delete web_notification_tray_; | 89 delete web_notification_tray_; |
| 87 web_notification_tray_ = NULL; | 90 web_notification_tray_ = nullptr; |
| 88 // Must be destroyed after |web_notification_tray_|. | 91 // Must be destroyed after |web_notification_tray_|. |
| 89 delete system_tray_; | 92 delete system_tray_; |
| 90 system_tray_ = NULL; | 93 system_tray_ = nullptr; |
| 91 #if defined(OS_CHROMEOS) | 94 #if defined(OS_CHROMEOS) |
| 92 delete ime_menu_tray_; | 95 delete ime_menu_tray_; |
| 93 ime_menu_tray_ = nullptr; | 96 ime_menu_tray_ = nullptr; |
| 94 delete virtual_keyboard_tray_; | 97 delete virtual_keyboard_tray_; |
| 95 virtual_keyboard_tray_ = NULL; | 98 virtual_keyboard_tray_ = nullptr; |
| 96 delete logout_button_tray_; | 99 delete logout_button_tray_; |
| 97 logout_button_tray_ = NULL; | 100 logout_button_tray_ = nullptr; |
| 98 #endif | 101 #endif |
| 99 delete overview_button_tray_; | 102 delete overview_button_tray_; |
| 100 overview_button_tray_ = NULL; | 103 overview_button_tray_ = nullptr; |
| 101 } | 104 } |
| 102 | 105 |
| 103 bool StatusAreaWidget::ShouldShowShelf() const { | 106 bool StatusAreaWidget::ShouldShowShelf() const { |
| 104 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 107 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
| 105 (web_notification_tray_ && | 108 (web_notification_tray_ && |
| 106 web_notification_tray_->ShouldBlockShelfAutoHide())) | 109 web_notification_tray_->ShouldBlockShelfAutoHide())) |
| 107 return true; | 110 return true; |
| 108 | 111 |
| 109 if (!wm_shelf_->IsVisible()) | 112 if (!wm_shelf_->IsVisible()) |
| 110 return false; | 113 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 123 } | 126 } |
| 124 | 127 |
| 125 void StatusAreaWidget::SchedulePaint() { | 128 void StatusAreaWidget::SchedulePaint() { |
| 126 status_area_widget_delegate_->SchedulePaint(); | 129 status_area_widget_delegate_->SchedulePaint(); |
| 127 web_notification_tray_->SchedulePaint(); | 130 web_notification_tray_->SchedulePaint(); |
| 128 system_tray_->SchedulePaint(); | 131 system_tray_->SchedulePaint(); |
| 129 #if defined(OS_CHROMEOS) | 132 #if defined(OS_CHROMEOS) |
| 130 virtual_keyboard_tray_->SchedulePaint(); | 133 virtual_keyboard_tray_->SchedulePaint(); |
| 131 logout_button_tray_->SchedulePaint(); | 134 logout_button_tray_->SchedulePaint(); |
| 132 ime_menu_tray_->SchedulePaint(); | 135 ime_menu_tray_->SchedulePaint(); |
| 136 palette_tray_->SchedulePaint(); |
| 133 #endif | 137 #endif |
| 134 overview_button_tray_->SchedulePaint(); | 138 overview_button_tray_->SchedulePaint(); |
| 135 } | 139 } |
| 136 | 140 |
| 137 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { | 141 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { |
| 138 Widget::OnNativeWidgetActivationChanged(active); | 142 Widget::OnNativeWidgetActivationChanged(active); |
| 139 if (active) | 143 if (active) |
| 140 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); | 144 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); |
| 141 } | 145 } |
| 142 | 146 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 161 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_); | 165 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_); |
| 162 status_area_widget_delegate_->AddTray(web_notification_tray_); | 166 status_area_widget_delegate_->AddTray(web_notification_tray_); |
| 163 } | 167 } |
| 164 | 168 |
| 165 #if defined(OS_CHROMEOS) | 169 #if defined(OS_CHROMEOS) |
| 166 void StatusAreaWidget::AddLogoutButtonTray() { | 170 void StatusAreaWidget::AddLogoutButtonTray() { |
| 167 logout_button_tray_ = new LogoutButtonTray(wm_shelf_); | 171 logout_button_tray_ = new LogoutButtonTray(wm_shelf_); |
| 168 status_area_widget_delegate_->AddTray(logout_button_tray_); | 172 status_area_widget_delegate_->AddTray(logout_button_tray_); |
| 169 } | 173 } |
| 170 | 174 |
| 175 void StatusAreaWidget::AddPaletteTray() { |
| 176 palette_tray_ = new PaletteTray(wm_shelf_); |
| 177 status_area_widget_delegate_->AddTray(palette_tray_); |
| 178 } |
| 179 |
| 171 void StatusAreaWidget::AddVirtualKeyboardTray() { | 180 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 172 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); | 181 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); |
| 173 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 182 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 174 } | 183 } |
| 175 | 184 |
| 176 void StatusAreaWidget::AddImeMenuTray() { | 185 void StatusAreaWidget::AddImeMenuTray() { |
| 177 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); | 186 ime_menu_tray_ = new ImeMenuTray(wm_shelf_); |
| 178 status_area_widget_delegate_->AddTray(ime_menu_tray_); | 187 status_area_widget_delegate_->AddTray(ime_menu_tray_); |
| 179 } | 188 } |
| 180 #endif | 189 #endif |
| 181 | 190 |
| 182 void StatusAreaWidget::AddOverviewButtonTray() { | 191 void StatusAreaWidget::AddOverviewButtonTray() { |
| 183 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); | 192 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); |
| 184 status_area_widget_delegate_->AddTray(overview_button_tray_); | 193 status_area_widget_delegate_->AddTray(overview_button_tray_); |
| 185 } | 194 } |
| 186 | 195 |
| 187 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 196 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| 188 status_area_widget_delegate_->set_alignment(alignment); | 197 status_area_widget_delegate_->set_alignment(alignment); |
| 189 if (system_tray_) | 198 if (system_tray_) |
| 190 system_tray_->SetShelfAlignment(alignment); | 199 system_tray_->SetShelfAlignment(alignment); |
| 191 if (web_notification_tray_) | 200 if (web_notification_tray_) |
| 192 web_notification_tray_->SetShelfAlignment(alignment); | 201 web_notification_tray_->SetShelfAlignment(alignment); |
| 193 #if defined(OS_CHROMEOS) | 202 #if defined(OS_CHROMEOS) |
| 194 if (logout_button_tray_) | 203 if (logout_button_tray_) |
| 195 logout_button_tray_->SetShelfAlignment(alignment); | 204 logout_button_tray_->SetShelfAlignment(alignment); |
| 196 if (virtual_keyboard_tray_) | 205 if (virtual_keyboard_tray_) |
| 197 virtual_keyboard_tray_->SetShelfAlignment(alignment); | 206 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| 198 if (ime_menu_tray_) | 207 if (ime_menu_tray_) |
| 199 ime_menu_tray_->SetShelfAlignment(alignment); | 208 ime_menu_tray_->SetShelfAlignment(alignment); |
| 209 if (palette_tray_) |
| 210 palette_tray_->SetShelfAlignment(alignment); |
| 200 #endif | 211 #endif |
| 201 if (overview_button_tray_) | 212 if (overview_button_tray_) |
| 202 overview_button_tray_->SetShelfAlignment(alignment); | 213 overview_button_tray_->SetShelfAlignment(alignment); |
| 203 status_area_widget_delegate_->UpdateLayout(); | 214 status_area_widget_delegate_->UpdateLayout(); |
| 204 } | 215 } |
| 205 | 216 |
| 206 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 217 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| 207 if (login_status_ == login_status) | 218 if (login_status_ == login_status) |
| 208 return; | 219 return; |
| 209 login_status_ = login_status; | 220 login_status_ = login_status; |
| 210 if (system_tray_) | 221 if (system_tray_) |
| 211 system_tray_->UpdateAfterLoginStatusChange(login_status); | 222 system_tray_->UpdateAfterLoginStatusChange(login_status); |
| 212 if (web_notification_tray_) | 223 if (web_notification_tray_) |
| 213 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 224 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
| 214 #if defined(OS_CHROMEOS) | 225 #if defined(OS_CHROMEOS) |
| 215 if (logout_button_tray_) | 226 if (logout_button_tray_) |
| 216 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 227 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 217 #endif | 228 #endif |
| 218 if (overview_button_tray_) | 229 if (overview_button_tray_) |
| 219 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); | 230 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 220 } | 231 } |
| 221 | 232 |
| 222 } // namespace ash | 233 } // namespace ash |
| OLD | NEW |