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/common/system/user/tray_user.h" | 5 #include "ash/common/system/user/tray_user.h" |
| 6 | 6 |
| 7 #include "ash/common/session/session_state_delegate.h" | 7 #include "ash/common/session/session_controller.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/system/tray/system_tray.h" | 9 #include "ash/common/system/tray/system_tray.h" |
| 10 #include "ash/common/system/tray/system_tray_delegate.h" | 10 #include "ash/common/system/tray/system_tray_delegate.h" |
| 11 #include "ash/common/system/tray/system_tray_notifier.h" | 11 #include "ash/common/system/tray/system_tray_notifier.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_item_view.h" | 13 #include "ash/common/system/tray/tray_item_view.h" |
| 14 #include "ash/common/system/tray/tray_utils.h" | 14 #include "ash/common/system/tray/tray_utils.h" |
| 15 #include "ash/common/system/user/rounded_image_view.h" | 15 #include "ash/common/system/user/rounded_image_view.h" |
| 16 #include "ash/common/system/user/user_view.h" | 16 #include "ash/common/system/user/user_view.h" |
| 17 #include "ash/common/wm_shell.h" | 17 #include "ash/common/wm_shell.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 CHECK(layout_view_ == nullptr); | 73 CHECK(layout_view_ == nullptr); |
| 74 | 74 |
| 75 layout_view_ = new views::View; | 75 layout_view_ = new views::View; |
| 76 UpdateAfterLoginStatusChange(status); | 76 UpdateAfterLoginStatusChange(status); |
| 77 return layout_view_; | 77 return layout_view_; |
| 78 } | 78 } |
| 79 | 79 |
| 80 views::View* TrayUser::CreateDefaultView(LoginStatus status) { | 80 views::View* TrayUser::CreateDefaultView(LoginStatus status) { |
| 81 if (status == LoginStatus::NOT_LOGGED_IN) | 81 if (status == LoginStatus::NOT_LOGGED_IN) |
| 82 return nullptr; | 82 return nullptr; |
| 83 const SessionStateDelegate* session_state_delegate = | 83 const SessionController* const session_controller = |
| 84 WmShell::Get()->GetSessionStateDelegate(); | 84 WmShell::Get()->session_controller(); |
| 85 | 85 |
| 86 // If the screen is locked or a system modal dialog box is shown, show only | 86 // If the screen is locked or a system modal dialog box is shown, show only |
| 87 // the currently active user. | 87 // the currently active user. |
| 88 if (user_index_ && (session_state_delegate->IsUserSessionBlocked() || | 88 if (user_index_ && (session_controller->IsUserSessionBlocked() || |
| 89 WmShell::Get()->IsSystemModalWindowOpen())) | 89 WmShell::Get()->IsSystemModalWindowOpen())) |
| 90 return nullptr; | 90 return nullptr; |
| 91 | 91 |
| 92 CHECK(user_ == nullptr); | 92 CHECK(user_ == nullptr); |
| 93 | 93 |
| 94 int logged_in_users = session_state_delegate->NumberOfLoggedInUsers(); | 94 int logged_in_users = session_controller->NumberOfLoggedInUsers(); |
| 95 | 95 |
| 96 // Do not show more UserView's then there are logged in users. | 96 // Do not show more UserView's then there are logged in users. |
| 97 if (user_index_ >= logged_in_users) | 97 if (user_index_ >= logged_in_users) |
| 98 return nullptr; | 98 return nullptr; |
| 99 | 99 |
| 100 user_ = new tray::UserView(this, status, user_index_); | 100 user_ = new tray::UserView(this, status, user_index_); |
| 101 return user_; | 101 return user_; |
| 102 } | 102 } |
| 103 | 103 |
| 104 void TrayUser::DestroyTrayView() { | 104 void TrayUser::DestroyTrayView() { |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); | 216 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 | 219 |
| 220 void TrayUser::OnUserUpdate() { | 220 void TrayUser::OnUserUpdate() { |
| 221 UpdateAvatarImage( | 221 UpdateAvatarImage( |
| 222 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 222 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void TrayUser::OnUserAddedToSession() { | 225 void TrayUser::OnUserAddedToSession() { |
| 226 SessionStateDelegate* session_state_delegate = | 226 const SessionController* const session_controller = |
| 227 WmShell::Get()->GetSessionStateDelegate(); | 227 WmShell::Get()->session_controller(); |
| 228 // Only create views for user items which are logged in. | 228 // Only create views for user items which are logged in. |
| 229 if (user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) | 229 if (user_index_ >= session_controller->NumberOfLoggedInUsers()) |
| 230 return; | 230 return; |
| 231 | 231 |
| 232 // Enforce a layout change that newly added items become visible. | 232 // Enforce a layout change that newly added items become visible. |
| 233 UpdateLayoutOfItem(); | 233 UpdateLayoutOfItem(); |
| 234 | 234 |
| 235 // Update the user item. | 235 // Update the user item. |
| 236 UpdateAvatarImage( | 236 UpdateAvatarImage( |
| 237 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 237 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void TrayUser::UpdateAvatarImage(LoginStatus status) { | 240 void TrayUser::UpdateAvatarImage(LoginStatus status) { |
| 241 SessionStateDelegate* session_state_delegate = | 241 const SessionController* const session_controller = |
| 242 WmShell::Get()->GetSessionStateDelegate(); | 242 WmShell::Get()->session_controller(); |
| 243 if (!avatar_ || | 243 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers()) |
| 244 user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) | |
| 245 return; | 244 return; |
| 246 | 245 |
| 247 const user_manager::UserInfo* user_info = | 246 const mojom::UserSession* const user_session = |
| 248 session_state_delegate->GetUserInfo(user_index_); | 247 session_controller->GetUserSession(user_index_); |
| 249 CHECK(user_info); | 248 CHECK(user_session); |
| 250 avatar_->SetImage(user_info->GetImage(), | 249 avatar_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(user_session->avatar), |
|
James Cook
2017/03/17 17:14:35
Do we have high-dpi user images? If so, this might
xiyuan
2017/03/17 22:52:02
The bundled avatar images support hidpi. Filed htt
| |
| 251 gfx::Size(kTrayItemSize, kTrayItemSize)); | 250 gfx::Size(kTrayItemSize, kTrayItemSize)); |
| 252 | 251 |
| 253 // Unit tests might come here with no images for some users. | 252 // Unit tests might come here with no images for some users. |
| 254 if (avatar_->size().IsEmpty()) | 253 if (avatar_->size().IsEmpty()) |
| 255 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); | 254 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); |
| 256 } | 255 } |
| 257 | 256 |
| 258 void TrayUser::UpdateLayoutOfItem() { | 257 void TrayUser::UpdateLayoutOfItem() { |
| 259 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); | 258 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); |
| 260 } | 259 } |
| 261 | 260 |
| 262 } // namespace ash | 261 } // namespace ash |
| OLD | NEW |