Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: ash/common/system/user/tray_user.cc

Issue 2761063002: Move more from WmShell to Shell (Closed)
Patch Set: merge Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
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"
18 #include "ash/shell.h"
18 #include "ash/strings/grit/ash_strings.h" 19 #include "ash/strings/grit/ash_strings.h"
19 #include "base/logging.h" 20 #include "base/logging.h"
20 #include "base/strings/string16.h" 21 #include "base/strings/string16.h"
21 #include "components/signin/core/account_id/account_id.h" 22 #include "components/signin/core/account_id/account_id.h"
22 #include "components/user_manager/user_info.h" 23 #include "components/user_manager/user_info.h"
23 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
24 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
25 #include "ui/views/border.h" 26 #include "ui/views/border.h"
26 #include "ui/views/controls/label.h" 27 #include "ui/views/controls/label.h"
27 #include "ui/views/layout/box_layout.h" 28 #include "ui/views/layout/box_layout.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 } 113 }
113 114
114 void TrayUser::UpdateAfterLoginStatusChange(LoginStatus status) { 115 void TrayUser::UpdateAfterLoginStatusChange(LoginStatus status) {
115 // Only the active user is represented in the tray. 116 // Only the active user is represented in the tray.
116 if (!layout_view_) 117 if (!layout_view_)
117 return; 118 return;
118 if (user_index_ > 0) 119 if (user_index_ > 0)
119 return; 120 return;
120 bool need_label = false; 121 bool need_label = false;
121 bool need_avatar = false; 122 bool need_avatar = false;
122 SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); 123 SystemTrayDelegate* delegate = Shell::Get()->system_tray_delegate();
123 if (delegate->IsUserSupervised()) 124 if (delegate->IsUserSupervised())
124 need_label = true; 125 need_label = true;
125 switch (status) { 126 switch (status) {
126 case LoginStatus::LOCKED: 127 case LoginStatus::LOCKED:
127 case LoginStatus::USER: 128 case LoginStatus::USER:
128 case LoginStatus::OWNER: 129 case LoginStatus::OWNER:
129 case LoginStatus::PUBLIC: 130 case LoginStatus::PUBLIC:
130 need_avatar = true; 131 need_avatar = true;
131 break; 132 break;
132 case LoginStatus::SUPERVISED: 133 case LoginStatus::SUPERVISED:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 kTrayLabelItemHorizontalPaddingBottomAlignment, 212 kTrayLabelItemHorizontalPaddingBottomAlignment,
212 kTrayLabelItemVerticalPaddingVerticalAlignment, 213 kTrayLabelItemVerticalPaddingVerticalAlignment,
213 kTrayLabelItemHorizontalPaddingBottomAlignment)); 214 kTrayLabelItemHorizontalPaddingBottomAlignment));
214 } 215 }
215 layout_view_->SetLayoutManager(new views::BoxLayout( 216 layout_view_->SetLayoutManager(new views::BoxLayout(
216 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding)); 217 views::BoxLayout::kVertical, 0, 0, kUserLabelToIconPadding));
217 } 218 }
218 } 219 }
219 220
220 void TrayUser::OnUserUpdate() { 221 void TrayUser::OnUserUpdate() {
221 UpdateAvatarImage( 222 UpdateAvatarImage(Shell::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 const SessionController* const session_controller = 226 const SessionController* const session_controller =
227 WmShell::Get()->session_controller(); 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_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( 236 UpdateAvatarImage(Shell::Get()->system_tray_delegate()->GetUserLoginStatus());
237 WmShell::Get()->system_tray_delegate()->GetUserLoginStatus());
238 } 237 }
239 238
240 void TrayUser::UpdateAvatarImage(LoginStatus status) { 239 void TrayUser::UpdateAvatarImage(LoginStatus status) {
241 const SessionController* const session_controller = 240 const SessionController* const session_controller =
242 WmShell::Get()->session_controller(); 241 WmShell::Get()->session_controller();
243 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers()) 242 if (!avatar_ || user_index_ >= session_controller->NumberOfLoggedInUsers())
244 return; 243 return;
245 244
246 const mojom::UserSession* const user_session = 245 const mojom::UserSession* const user_session =
247 session_controller->GetUserSession(user_index_); 246 session_controller->GetUserSession(user_index_);
248 CHECK(user_session); 247 CHECK(user_session);
249 // TODO(xiyuan); HiDpi avatar support. http://crbug.com/702689 248 // TODO(xiyuan); HiDpi avatar support. http://crbug.com/702689
250 avatar_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(user_session->avatar), 249 avatar_->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(user_session->avatar),
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
OLDNEW
« no previous file with comments | « ash/common/system/update/tray_update_unittest.cc ('k') | ash/common/system/user/user_card_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698