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/wm_root_window_controller.h" | 10 #include "ash/common/wm_root_window_controller.h" |
| 11 #include "ash/common/wm_shell.h" | 11 #include "ash/common/wm_shell.h" |
| 12 #include "ash/common/wm_window.h" | 12 #include "ash/common/wm_window.h" |
| 13 #include "ash/system/overview/overview_button_tray.h" | 13 #include "ash/system/overview/overview_button_tray.h" |
| 14 #include "ash/system/status_area_widget_delegate.h" | 14 #include "ash/system/status_area_widget_delegate.h" |
| 15 #include "ash/system/tray/system_tray.h" | 15 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/web_notification/web_notification_tray.h" | 16 #include "ash/system/web_notification/web_notification_tray.h" |
| 17 #include "ash/wm/window_properties.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/ime_menu/ime_menu_tray.h" | |
| 21 #include "ash/system/chromeos/session/logout_button_tray.h" | 22 #include "ash/system/chromeos/session/logout_button_tray.h" |
| 22 #include "ash/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 23 #include "ash/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_(NULL), |
| 31 system_tray_(NULL), | 32 system_tray_(NULL), |
| 32 web_notification_tray_(NULL), | 33 web_notification_tray_(NULL), |
| 33 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
| 34 logout_button_tray_(NULL), | 35 logout_button_tray_(NULL), |
| 35 virtual_keyboard_tray_(NULL), | 36 virtual_keyboard_tray_(NULL), |
| 37 ime_menu_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(); |
| 60 AddVirtualKeyboardTray(); | 62 AddVirtualKeyboardTray(); |
| 63 AddImeMenuTray(); | |
| 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); | 69 system_tray_->InitializeTrayItems(delegate); |
| 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(); |
| 74 ime_menu_tray_->Initialize(); | |
| 71 #endif | 75 #endif |
| 72 overview_button_tray_->Initialize(); | 76 overview_button_tray_->Initialize(); |
| 73 SetShelfAlignment(system_tray_->shelf_alignment()); | 77 SetShelfAlignment(system_tray_->shelf_alignment()); |
| 74 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 78 UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |
| 75 } | 79 } |
| 76 | 80 |
| 77 void StatusAreaWidget::Shutdown() { | 81 void StatusAreaWidget::Shutdown() { |
| 78 // 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 |
| 79 // 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 |
| 80 // 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). |
| 81 delete web_notification_tray_; | 85 delete web_notification_tray_; |
| 82 web_notification_tray_ = NULL; | 86 web_notification_tray_ = NULL; |
| 83 delete system_tray_; | 87 delete system_tray_; |
| 84 system_tray_ = NULL; | 88 system_tray_ = NULL; |
| 85 #if defined(OS_CHROMEOS) | 89 #if defined(OS_CHROMEOS) |
| 86 delete virtual_keyboard_tray_; | 90 delete virtual_keyboard_tray_; |
| 87 virtual_keyboard_tray_ = NULL; | 91 virtual_keyboard_tray_ = NULL; |
| 88 delete logout_button_tray_; | 92 delete logout_button_tray_; |
| 89 logout_button_tray_ = NULL; | 93 logout_button_tray_ = NULL; |
| 94 delete ime_menu_tray_; | |
| 95 ime_menu_tray_ = nullptr; | |
|
sadrul
2016/06/29 15:14:10
the destruction order should normally be the rever
Azure Wei
2016/06/30 00:36:30
Done.
| |
| 90 #endif | 96 #endif |
| 91 delete overview_button_tray_; | 97 delete overview_button_tray_; |
| 92 overview_button_tray_ = NULL; | 98 overview_button_tray_ = NULL; |
| 93 } | 99 } |
| 94 | 100 |
| 95 bool StatusAreaWidget::ShouldShowShelf() const { | 101 bool StatusAreaWidget::ShouldShowShelf() const { |
| 96 if ((system_tray_ && system_tray_->ShouldShowShelf()) || | 102 if ((system_tray_ && system_tray_->ShouldShowShelf()) || |
| 97 (web_notification_tray_ && | 103 (web_notification_tray_ && |
| 98 web_notification_tray_->ShouldBlockShelfAutoHide())) | 104 web_notification_tray_->ShouldBlockShelfAutoHide())) |
| 99 return true; | 105 return true; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 114 web_notification_tray_->IsMessageCenterBubbleVisible())); | 120 web_notification_tray_->IsMessageCenterBubbleVisible())); |
| 115 } | 121 } |
| 116 | 122 |
| 117 void StatusAreaWidget::SchedulePaint() { | 123 void StatusAreaWidget::SchedulePaint() { |
| 118 status_area_widget_delegate_->SchedulePaint(); | 124 status_area_widget_delegate_->SchedulePaint(); |
| 119 web_notification_tray_->SchedulePaint(); | 125 web_notification_tray_->SchedulePaint(); |
| 120 system_tray_->SchedulePaint(); | 126 system_tray_->SchedulePaint(); |
| 121 #if defined(OS_CHROMEOS) | 127 #if defined(OS_CHROMEOS) |
| 122 virtual_keyboard_tray_->SchedulePaint(); | 128 virtual_keyboard_tray_->SchedulePaint(); |
| 123 logout_button_tray_->SchedulePaint(); | 129 logout_button_tray_->SchedulePaint(); |
| 130 ime_menu_tray_->SchedulePaint(); | |
| 124 #endif | 131 #endif |
| 125 overview_button_tray_->SchedulePaint(); | 132 overview_button_tray_->SchedulePaint(); |
| 126 } | 133 } |
| 127 | 134 |
| 128 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { | 135 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { |
| 129 Widget::OnNativeWidgetActivationChanged(active); | 136 Widget::OnNativeWidgetActivationChanged(active); |
| 130 if (active) | 137 if (active) |
| 131 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); | 138 status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); |
| 132 } | 139 } |
| 133 | 140 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 154 #if defined(OS_CHROMEOS) | 161 #if defined(OS_CHROMEOS) |
| 155 void StatusAreaWidget::AddLogoutButtonTray() { | 162 void StatusAreaWidget::AddLogoutButtonTray() { |
| 156 logout_button_tray_ = new LogoutButtonTray(this); | 163 logout_button_tray_ = new LogoutButtonTray(this); |
| 157 status_area_widget_delegate_->AddTray(logout_button_tray_); | 164 status_area_widget_delegate_->AddTray(logout_button_tray_); |
| 158 } | 165 } |
| 159 | 166 |
| 160 void StatusAreaWidget::AddVirtualKeyboardTray() { | 167 void StatusAreaWidget::AddVirtualKeyboardTray() { |
| 161 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); | 168 virtual_keyboard_tray_ = new VirtualKeyboardTray(this); |
| 162 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 169 status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |
| 163 } | 170 } |
| 171 | |
| 172 void StatusAreaWidget::AddImeMenuTray() { | |
| 173 ime_menu_tray_ = new ImeMenuTray(this); | |
| 174 status_area_widget_delegate_->AddTray(ime_menu_tray_); | |
| 175 } | |
| 164 #endif | 176 #endif |
| 165 | 177 |
| 166 void StatusAreaWidget::AddOverviewButtonTray() { | 178 void StatusAreaWidget::AddOverviewButtonTray() { |
| 167 overview_button_tray_ = new OverviewButtonTray(this); | 179 overview_button_tray_ = new OverviewButtonTray(this); |
| 168 status_area_widget_delegate_->AddTray(overview_button_tray_); | 180 status_area_widget_delegate_->AddTray(overview_button_tray_); |
| 169 } | 181 } |
| 170 | 182 |
| 171 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 183 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |
| 172 status_area_widget_delegate_->set_alignment(alignment); | 184 status_area_widget_delegate_->set_alignment(alignment); |
| 173 if (system_tray_) | 185 if (system_tray_) |
| 174 system_tray_->SetShelfAlignment(alignment); | 186 system_tray_->SetShelfAlignment(alignment); |
| 175 if (web_notification_tray_) | 187 if (web_notification_tray_) |
| 176 web_notification_tray_->SetShelfAlignment(alignment); | 188 web_notification_tray_->SetShelfAlignment(alignment); |
| 177 #if defined(OS_CHROMEOS) | 189 #if defined(OS_CHROMEOS) |
| 178 if (logout_button_tray_) | 190 if (logout_button_tray_) |
| 179 logout_button_tray_->SetShelfAlignment(alignment); | 191 logout_button_tray_->SetShelfAlignment(alignment); |
| 180 if (virtual_keyboard_tray_) | 192 if (virtual_keyboard_tray_) |
| 181 virtual_keyboard_tray_->SetShelfAlignment(alignment); | 193 virtual_keyboard_tray_->SetShelfAlignment(alignment); |
| 194 if (ime_menu_tray_) | |
| 195 ime_menu_tray_->SetShelfAlignment(alignment); | |
| 182 #endif | 196 #endif |
| 183 if (overview_button_tray_) | 197 if (overview_button_tray_) |
| 184 overview_button_tray_->SetShelfAlignment(alignment); | 198 overview_button_tray_->SetShelfAlignment(alignment); |
| 185 status_area_widget_delegate_->UpdateLayout(); | 199 status_area_widget_delegate_->UpdateLayout(); |
| 186 } | 200 } |
| 187 | 201 |
| 188 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { | 202 void StatusAreaWidget::SetHideSystemNotifications(bool hide) { |
| 189 if (system_tray_) | 203 if (system_tray_) |
| 190 system_tray_->SetHideNotifications(hide); | 204 system_tray_->SetHideNotifications(hide); |
| 191 } | 205 } |
| 192 | 206 |
| 193 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 207 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |
| 194 if (login_status_ == login_status) | 208 if (login_status_ == login_status) |
| 195 return; | 209 return; |
| 196 login_status_ = login_status; | 210 login_status_ = login_status; |
| 197 if (system_tray_) | 211 if (system_tray_) |
| 198 system_tray_->UpdateAfterLoginStatusChange(login_status); | 212 system_tray_->UpdateAfterLoginStatusChange(login_status); |
| 199 if (web_notification_tray_) | 213 if (web_notification_tray_) |
| 200 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 214 web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |
| 201 #if defined(OS_CHROMEOS) | 215 #if defined(OS_CHROMEOS) |
| 202 if (logout_button_tray_) | 216 if (logout_button_tray_) |
| 203 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 217 logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 204 #endif | 218 #endif |
| 205 if (overview_button_tray_) | 219 if (overview_button_tray_) |
| 206 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); | 220 overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |
| 207 } | 221 } |
| 208 | 222 |
| 209 } // namespace ash | 223 } // namespace ash |
| OLD | NEW |