| 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/user/tray_user.h" | 5 #include "ash/system/user/tray_user.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 9 #include "ash/common/shelf/wm_shelf_util.h" | 9 #include "ash/common/shelf/wm_shelf_util.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/tray_constants.h" | 11 #include "ash/common/system/tray/tray_constants.h" |
| 12 #include "ash/common/wm_shell.h" |
| 12 #include "ash/shelf/shelf_layout_manager.h" | 13 #include "ash/shelf/shelf_layout_manager.h" |
| 13 #include "ash/shelf/shelf_util.h" | 14 #include "ash/shelf/shelf_util.h" |
| 14 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 15 #include "ash/system/tray/system_tray.h" | 16 #include "ash/system/tray/system_tray.h" |
| 16 #include "ash/system/tray/system_tray_notifier.h" | 17 #include "ash/system/tray/system_tray_notifier.h" |
| 17 #include "ash/system/tray/tray_item_view.h" | 18 #include "ash/system/tray/tray_item_view.h" |
| 18 #include "ash/system/tray/tray_utils.h" | 19 #include "ash/system/tray/tray_utils.h" |
| 19 #include "ash/system/user/rounded_image_view.h" | 20 #include "ash/system/user/rounded_image_view.h" |
| 20 #include "ash/system/user/user_view.h" | 21 #include "ash/system/user/user_view.h" |
| 21 #include "base/logging.h" | 22 #include "base/logging.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 } | 123 } |
| 123 | 124 |
| 124 void TrayUser::UpdateAfterLoginStatusChange(LoginStatus status) { | 125 void TrayUser::UpdateAfterLoginStatusChange(LoginStatus status) { |
| 125 // Only the active user is represented in the tray. | 126 // Only the active user is represented in the tray. |
| 126 if (!layout_view_) | 127 if (!layout_view_) |
| 127 return; | 128 return; |
| 128 if (user_index_ > 0) | 129 if (user_index_ > 0) |
| 129 return; | 130 return; |
| 130 bool need_label = false; | 131 bool need_label = false; |
| 131 bool need_avatar = false; | 132 bool need_avatar = false; |
| 132 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 133 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |
| 133 if (delegate->IsUserSupervised()) | 134 if (delegate->IsUserSupervised()) |
| 134 need_label = true; | 135 need_label = true; |
| 135 switch (status) { | 136 switch (status) { |
| 136 case LoginStatus::LOCKED: | 137 case LoginStatus::LOCKED: |
| 137 case LoginStatus::USER: | 138 case LoginStatus::USER: |
| 138 case LoginStatus::OWNER: | 139 case LoginStatus::OWNER: |
| 139 case LoginStatus::PUBLIC: | 140 case LoginStatus::PUBLIC: |
| 140 need_avatar = true; | 141 need_avatar = true; |
| 141 break; | 142 break; |
| 142 case LoginStatus::SUPERVISED: | 143 case LoginStatus::SUPERVISED: |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 kTrayLabelItemVerticalPaddingVerticalAlignment, | 227 kTrayLabelItemVerticalPaddingVerticalAlignment, |
| 227 kTrayLabelItemHorizontalPaddingBottomAlignment)); | 228 kTrayLabelItemHorizontalPaddingBottomAlignment)); |
| 228 } | 229 } |
| 229 layout_view_->SetLayoutManager( | 230 layout_view_->SetLayoutManager( |
| 230 new views::BoxLayout(views::BoxLayout::kVertical, | 231 new views::BoxLayout(views::BoxLayout::kVertical, |
| 231 0, 0, kUserLabelToIconPadding)); | 232 0, 0, kUserLabelToIconPadding)); |
| 232 } | 233 } |
| 233 } | 234 } |
| 234 | 235 |
| 235 void TrayUser::OnUserUpdate() { | 236 void TrayUser::OnUserUpdate() { |
| 236 UpdateAvatarImage(Shell::GetInstance()->system_tray_delegate()-> | 237 UpdateAvatarImage( |
| 237 GetUserLoginStatus()); | 238 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 238 } | 239 } |
| 239 | 240 |
| 240 void TrayUser::OnUserAddedToSession() { | 241 void TrayUser::OnUserAddedToSession() { |
| 241 SessionStateDelegate* session_state_delegate = | 242 SessionStateDelegate* session_state_delegate = |
| 242 Shell::GetInstance()->session_state_delegate(); | 243 Shell::GetInstance()->session_state_delegate(); |
| 243 // Only create views for user items which are logged in. | 244 // Only create views for user items which are logged in. |
| 244 if (user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) | 245 if (user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) |
| 245 return; | 246 return; |
| 246 | 247 |
| 247 // Enforce a layout change that newly added items become visible. | 248 // Enforce a layout change that newly added items become visible. |
| 248 UpdateLayoutOfItem(); | 249 UpdateLayoutOfItem(); |
| 249 | 250 |
| 250 // Update the user item. | 251 // Update the user item. |
| 251 UpdateAvatarImage( | 252 UpdateAvatarImage( |
| 252 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus()); | 253 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()); |
| 253 } | 254 } |
| 254 | 255 |
| 255 void TrayUser::UpdateAvatarImage(LoginStatus status) { | 256 void TrayUser::UpdateAvatarImage(LoginStatus status) { |
| 256 SessionStateDelegate* session_state_delegate = | 257 SessionStateDelegate* session_state_delegate = |
| 257 Shell::GetInstance()->session_state_delegate(); | 258 Shell::GetInstance()->session_state_delegate(); |
| 258 if (!avatar_ || | 259 if (!avatar_ || |
| 259 user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) | 260 user_index_ >= session_state_delegate->NumberOfLoggedInUsers()) |
| 260 return; | 261 return; |
| 261 | 262 |
| 262 const user_manager::UserInfo* user_info = | 263 const user_manager::UserInfo* user_info = |
| 263 session_state_delegate->GetUserInfo(user_index_); | 264 session_state_delegate->GetUserInfo(user_index_); |
| 264 CHECK(user_info); | 265 CHECK(user_info); |
| 265 avatar_->SetImage(user_info->GetImage(), | 266 avatar_->SetImage(user_info->GetImage(), |
| 266 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 267 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
| 267 | 268 |
| 268 // Unit tests might come here with no images for some users. | 269 // Unit tests might come here with no images for some users. |
| 269 if (avatar_->size().IsEmpty()) | 270 if (avatar_->size().IsEmpty()) |
| 270 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 271 avatar_->SetSize(gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
| 271 } | 272 } |
| 272 | 273 |
| 273 void TrayUser::UpdateLayoutOfItem() { | 274 void TrayUser::UpdateLayoutOfItem() { |
| 274 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); | 275 UpdateAfterShelfAlignmentChange(system_tray()->shelf_alignment()); |
| 275 } | 276 } |
| 276 | 277 |
| 277 } // namespace ash | 278 } // namespace ash |
| OLD | NEW |