| 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/palette/palette_tray.h" |
| 21 #include "ash/common/system/chromeos/session/logout_button_tray.h" | 22 #include "ash/common/system/chromeos/session/logout_button_tray.h" |
| 22 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 23 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |
| 23 #endif | 24 #endif |
| 24 | 25 |
| 25 namespace ash { | 26 namespace ash { |
| 26 | 27 |
| 27 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, | 28 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, |
| 28 WmShelf* wm_shelf) | 29 WmShelf* wm_shelf) |
| 29 : status_area_widget_delegate_(new StatusAreaWidgetDelegate), | 30 : status_area_widget_delegate_(new StatusAreaWidgetDelegate), |
| 30 overview_button_tray_(NULL), | 31 overview_button_tray_(nullptr), |
| 31 system_tray_(NULL), | 32 system_tray_(nullptr), |
| 32 web_notification_tray_(NULL), | 33 web_notification_tray_(nullptr), |
| 33 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 34 logout_button_tray_(NULL), | 35 logout_button_tray_(nullptr), |
| 35 virtual_keyboard_tray_(NULL), | 36 palette_tray_(nullptr), |
| 37 virtual_keyboard_tray_(nullptr), |
| 36 #endif | 38 #endif |
| 37 login_status_(LoginStatus::NOT_LOGGED_IN), | 39 login_status_(LoginStatus::NOT_LOGGED_IN), |
| 38 wm_shelf_(wm_shelf) { | 40 wm_shelf_(wm_shelf) { |
| 39 views::Widget::InitParams params( | 41 views::Widget::InitParams params( |
| 40 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 42 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 41 params.delegate = status_area_widget_delegate_; | 43 params.delegate = status_area_widget_delegate_; |
| 42 params.name = "StatusAreaWidget"; | 44 params.name = "StatusAreaWidget"; |
| 43 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 45 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 44 status_container->GetRootWindowController() | 46 status_container->GetRootWindowController() |
| 45 ->ConfigureWidgetInitParamsForContainer( | 47 ->ConfigureWidgetInitParamsForContainer( |
| 46 this, status_container->GetShellWindowId(), ¶ms); | 48 this, status_container->GetShellWindowId(), ¶ms); |
| 47 Init(params); | 49 Init(params); |
| 48 set_focus_on_creation(false); | 50 set_focus_on_creation(false); |
| 49 SetContentsView(status_area_widget_delegate_); | 51 SetContentsView(status_area_widget_delegate_); |
| 50 } | 52 } |
| 51 | 53 |
| 52 StatusAreaWidget::~StatusAreaWidget() {} | 54 StatusAreaWidget::~StatusAreaWidget() {} |
| 53 | 55 |
| 54 void StatusAreaWidget::CreateTrayViews() { | 56 void StatusAreaWidget::CreateTrayViews() { |
| 55 AddOverviewButtonTray(); | 57 AddOverviewButtonTray(); |
| 56 AddSystemTray(); | 58 AddSystemTray(); |
| 57 AddWebNotificationTray(); | 59 AddWebNotificationTray(); |
| 58 #if defined(OS_CHROMEOS) | 60 #if defined(OS_CHROMEOS) |
| 59 AddLogoutButtonTray(); | 61 AddLogoutButtonTray(); |
| 62 AddPaletteTray(); |
| 60 AddVirtualKeyboardTray(); | 63 AddVirtualKeyboardTray(); |
| 61 #endif | 64 #endif |
| 62 | 65 |
| 63 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 66 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 64 DCHECK(delegate); | 67 DCHECK(delegate); |
| 65 // Initialize after all trays have been created. | 68 // Initialize after all trays have been created. |
| 66 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); | 69 system_tray_->InitializeTrayItems(delegate, web_notification_tray_); |
| 67 web_notification_tray_->Initialize(); | 70 web_notification_tray_->Initialize(); |
| 68 #if defined(OS_CHROMEOS) | 71 #if defined(OS_CHROMEOS) |
| 69 logout_button_tray_->Initialize(); | 72 logout_button_tray_->Initialize(); |
| 70 virtual_keyboard_tray_->Initialize(); | 73 virtual_keyboard_tray_->Initialize(); |
| 71 #endif | 74 #endif |
| 72 overview_button_tray_->Initialize(); | 75 overview_button_tray_->Initialize(); |
| 73 SetShelfAlignment(system_tray_->shelf_alignment()); | 76 SetShelfAlignment(system_tray_->shelf_alignment()); |
| 74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 77 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
| 75 } | 78 } |
| 76 | 79 |
| 77 void StatusAreaWidget::Shutdown() { | 80 void StatusAreaWidget::Shutdown() { |
| 78 system_tray_->Shutdown(); | 81 system_tray_->Shutdown(); |
| 79 // 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 |
| 80 // 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 |
| 81 // 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). |
| 82 delete web_notification_tray_; | 85 delete web_notification_tray_; |
| 83 web_notification_tray_ = NULL; | 86 web_notification_tray_ = nullptr; |
| 84 // Must be destroyed after |web_notification_tray_|. | 87 // Must be destroyed after |web_notification_tray_|. |
| 85 delete system_tray_; | 88 delete system_tray_; |
| 86 system_tray_ = NULL; | 89 system_tray_ = nullptr; |
| 87 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
| 88 delete virtual_keyboard_tray_; | 91 delete virtual_keyboard_tray_; |
| 89 virtual_keyboard_tray_ = NULL; | 92 virtual_keyboard_tray_ = nullptr; |
| 90 delete logout_button_tray_; | 93 delete logout_button_tray_; |
| 91 logout_button_tray_ = NULL; | 94 logout_button_tray_ = nullptr; |
| 92 #endif | 95 #endif |
| 93 delete overview_button_tray_; | 96 delete overview_button_tray_; |
| 94 overview_button_tray_ = NULL; | 97 overview_button_tray_ = nullptr; |
| 95 } | 98 } |
| 96 | 99 |
| 97 bool StatusAreaWidget::ShouldShowShelf() const { | 100 bool StatusAreaWidget::ShouldShowShelf() const { |
| 98 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 101 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
| 99 (web_notification_tray_ && | 102 (web_notification_tray_ && |
| 100 web_notification_tray_->ShouldBlockShelfAutoHide())) | 103 web_notification_tray_->ShouldBlockShelfAutoHide())) |
| 101 return true; | 104 return true; |
| 102 | 105 |
| 103 if (!wm_shelf_->IsVisible()) | 106 if (!wm_shelf_->IsVisible()) |
| 104 return false; | 107 return false; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 116 web_notification_tray_->IsMessageCenterBubbleVisible())); | 119 web_notification_tray_->IsMessageCenterBubbleVisible())); |
| 117 } | 120 } |
| 118 | 121 |
| 119 void StatusAreaWidget::SchedulePaint() { | 122 void StatusAreaWidget::SchedulePaint() { |
| 120 status_area_widget_delegate_->SchedulePaint(); | 123 status_area_widget_delegate_->SchedulePaint(); |
| 121 web_notification_tray_->SchedulePaint(); | 124 web_notification_tray_->SchedulePaint(); |
| 122 system_tray_->SchedulePaint(); | 125 system_tray_->SchedulePaint(); |
| 123 #if defined(OS_CHROMEOS) | 126 #if defined(OS_CHROMEOS) |
| 124 virtual_keyboard_tray_->SchedulePaint(); | 127 virtual_keyboard_tray_->SchedulePaint(); |
| 125 logout_button_tray_->SchedulePaint(); | 128 logout_button_tray_->SchedulePaint(); |
| 129 palette_tray_->SchedulePaint(); |
| 126 #endif | 130 #endif |
| 127 overview_button_tray_->SchedulePaint(); | 131 overview_button_tray_->SchedulePaint(); |
| 128 } | 132 } |
| 129 | 133 |
| 130 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { | 134 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { |
| 131 Widget::OnNativeWidgetActivationChanged(active); | 135 Widget::OnNativeWidgetActivationChanged(active); |
| 132 if (active) | 136 if (active) |
| 133 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); | 137 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); |
| 134 } | 138 } |
| 135 | 139 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 154 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_); | 158 wm_shelf_, WmLookup::Get()->GetWindowForWidget(this), system_tray_); |
| 155 status_area_widget_delegate_->AddTray(web_notification_tray_); | 159 status_area_widget_delegate_->AddTray(web_notification_tray_); |
| 156 } | 160 } |
| 157 | 161 |
| 158 #if defined(OS_CHROMEOS) | 162 #if defined(OS_CHROMEOS) |
| 159 void StatusAreaWidget::AddLogoutButtonTray() { | 163 void StatusAreaWidget::AddLogoutButtonTray() { |
| 160 logout_button_tray_ = new LogoutButtonTray(wm_shelf_); | 164 logout_button_tray_ = new LogoutButtonTray(wm_shelf_); |
| 161 status_area_widget_delegate_->AddTray(logout_button_tray_); | 165 status_area_widget_delegate_->AddTray(logout_button_tray_); |
| 162 } | 166 } |
| 163 | 167 |
| 168 void StatusAreaWidget::AddPaletteTray() { |
| 169 palette_tray_ = new PaletteTray(wm_shelf_); |
| 170 status_area_widget_delegate_->AddTray(palette_tray_); |
| 171 } |
| 172 |
| 164 void StatusAreaWidget::AddVirtualKeyboardTray() { | 173 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 165 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); | 174 virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); |
| 166 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 175 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 167 } | 176 } |
| 168 #endif | 177 #endif |
| 169 | 178 |
| 170 void StatusAreaWidget::AddOverviewButtonTray() { | 179 void StatusAreaWidget::AddOverviewButtonTray() { |
| 171 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); | 180 overview_button_tray_ = new OverviewButtonTray(wm_shelf_); |
| 172 status_area_widget_delegate_->AddTray(overview_button_tray_); | 181 status_area_widget_delegate_->AddTray(overview_button_tray_); |
| 173 } | 182 } |
| 174 | 183 |
| 175 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 184 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| 176 status_area_widget_delegate_->set_alignment(alignment); | 185 status_area_widget_delegate_->set_alignment(alignment); |
| 177 if (system_tray_) | 186 if (system_tray_) |
| 178 system_tray_->SetShelfAlignment(alignment); | 187 system_tray_->SetShelfAlignment(alignment); |
| 179 if (web_notification_tray_) | 188 if (web_notification_tray_) |
| 180 web_notification_tray_->SetShelfAlignment(alignment); | 189 web_notification_tray_->SetShelfAlignment(alignment); |
| 181 #if defined(OS_CHROMEOS) | 190 #if defined(OS_CHROMEOS) |
| 182 if (logout_button_tray_) | 191 if (logout_button_tray_) |
| 183 logout_button_tray_->SetShelfAlignment(alignment); | 192 logout_button_tray_->SetShelfAlignment(alignment); |
| 184 if (virtual_keyboard_tray_) | 193 if (virtual_keyboard_tray_) |
| 185 virtual_keyboard_tray_->SetShelfAlignment(alignment); | 194 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| 195 if (palette_tray_) |
| 196 palette_tray_->SetShelfAlignment(alignment); |
| 186 #endif | 197 #endif |
| 187 if (overview_button_tray_) | 198 if (overview_button_tray_) |
| 188 overview_button_tray_->SetShelfAlignment(alignment); | 199 overview_button_tray_->SetShelfAlignment(alignment); |
| 189 status_area_widget_delegate_->UpdateLayout(); | 200 status_area_widget_delegate_->UpdateLayout(); |
| 190 } | 201 } |
| 191 | 202 |
| 192 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 203 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| 193 if (login_status_ == login_status) | 204 if (login_status_ == login_status) |
| 194 return; | 205 return; |
| 195 login_status_ = login_status; | 206 login_status_ = login_status; |
| 196 if (system_tray_) | 207 if (system_tray_) |
| 197 system_tray_->UpdateAfterLoginStatusChange(login_status); | 208 system_tray_->UpdateAfterLoginStatusChange(login_status); |
| 198 if (web_notification_tray_) | 209 if (web_notification_tray_) |
| 199 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 210 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
| 200 #if defined(OS_CHROMEOS) | 211 #if defined(OS_CHROMEOS) |
| 201 if (logout_button_tray_) | 212 if (logout_button_tray_) |
| 202 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 213 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 203 #endif | 214 #endif |
| 204 if (overview_button_tray_) | 215 if (overview_button_tray_) |
| 205 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); | 216 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 206 } | 217 } |
| 207 | 218 |
| 208 } // namespace ash | 219 } // namespace ash |
| OLD | NEW |