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_controller.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" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 75 |
76 layout_view_ = new views::View; | 76 layout_view_ = new views::View; |
77 UpdateAfterLoginStatusChange(status); | 77 UpdateAfterLoginStatusChange(status); |
78 return layout_view_; | 78 return layout_view_; |
79 } | 79 } |
80 | 80 |
81 views::View* TrayUser::CreateDefaultView(LoginStatus status) { | 81 views::View* TrayUser::CreateDefaultView(LoginStatus status) { |
82 if (status == LoginStatus::NOT_LOGGED_IN) | 82 if (status == LoginStatus::NOT_LOGGED_IN) |
83 return nullptr; | 83 return nullptr; |
84 const SessionController* const session_controller = | 84 const SessionController* const session_controller = |
85 WmShell::Get()->session_controller(); | 85 Shell::Get()->session_controller(); |
86 | 86 |
87 // If the screen is locked or a system modal dialog box is shown, show only | 87 // If the screen is locked or a system modal dialog box is shown, show only |
88 // the currently active user. | 88 // the currently active user. |
89 if (user_index_ && (session_controller->IsUserSessionBlocked() || | 89 if (user_index_ && (session_controller->IsUserSessionBlocked() || |
90 WmShell::Get()->IsSystemModalWindowOpen())) | 90 WmShell::Get()->IsSystemModalWindowOpen())) |
91 return nullptr; | 91 return nullptr; |
92 | 92 |
93 CHECK(user_ == nullptr); | 93 CHECK(user_ == nullptr); |
94 | 94 |
95 int logged_in_users = session_controller->NumberOfLoggedInUsers(); | 95 int logged_in_users = session_controller->NumberOfLoggedInUsers(); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); | 217 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 void TrayUser::OnUserUpdate() { | 221 void TrayUser::OnUserUpdate() { |
222 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 222 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
223 } | 223 } |
224 | 224 |
225 void TrayUser::OnUserAddedToSession() { | 225 void TrayUser::OnUserAddedToSession() { |
226 const SessionController* const session_controller = | 226 const SessionController* const session_controller = |
227 WmShell::Get()->session_controller(); | 227 Shell::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_controller->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(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); | 236 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
237 } | 237 } |
238 | 238 |
239 void TrayUser::UpdateAvatarImage(LoginStatus status) { | 239 void TrayUser::UpdateAvatarImage(LoginStatus status) { |
240 const SessionController* const session_controller = | 240 const SessionController* const session_controller = |
241 WmShell::Get()->session_controller(); | 241 Shell::Get()->session_controller(); |
242 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers()) | 242 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers()) |
243 return; | 243 return; |
244 | 244 |
245 const mojom::UserSession* const user_session = | 245 const mojom::UserSession* const user_session = |
246 session_controller->GetUserSession(user_index_); | 246 session_controller->GetUserSession(user_index_); |
247 CHECK(user_session); | 247 CHECK(user_session); |
248 // TODO(xiyuan); HiDpi avatar support. http://crbug.com/702689 | 248 // TODO(xiyuan); HiDpi avatar support. http://crbug.com/702689 |
249 avatar_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(user_session->avatar), | 249 avatar_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(user_session->avatar), |
250 gfx::Size(kTrayItemSize, kTrayItemSize)); | 250 gfx::Size(kTrayItemSize, kTrayItemSize)); |
251 | 251 |
252 // Unit tests might come here with no images for some users. | 252 // Unit tests might come here with no images for some users. |
253 if (avatar_->size().IsEmpty()) | 253 if (avatar_->size().IsEmpty()) |
254 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); | 254 avatar_->SetSize(gfx::Size(kTrayItemSize, kTrayItemSize)); |
255 } | 255 } |
256 | 256 |
257 void TrayUser::UpdateLayoutOfItem() { | 257 void TrayUser::UpdateLayoutOfItem() { |
258 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); | 258 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); |
259 } | 259 } |
260 | 260 |
261 } // namespace ash | 261 } // namespace ash |
OLD | NEW |