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

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

Issue 2734933004: ash: Use SessionController instead of SessionStateDelegate (Closed)
Patch Set: rebase to get WorkspaceLayoutManagerSoloTest change 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
« no previous file with comments | « ash/common/system/user/tray_user_unittest.cc ('k') | ash/common/system/user/user_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/user_card_view.h" 5 #include "ash/common/system/user/user_card_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/ash_view_ids.h" 11 #include "ash/common/ash_view_ids.h"
12 #include "ash/common/login_status.h" 12 #include "ash/common/login_status.h"
13 #include "ash/common/media_controller.h" 13 #include "ash/common/media_controller.h"
14 #include "ash/common/session/session_state_delegate.h" 14 #include "ash/common/session/session_controller.h"
15 #include "ash/common/system/tray/system_tray_controller.h" 15 #include "ash/common/system/tray/system_tray_controller.h"
16 #include "ash/common/system/tray/system_tray_delegate.h" 16 #include "ash/common/system/tray/system_tray_delegate.h"
17 #include "ash/common/system/tray/tray_constants.h" 17 #include "ash/common/system/tray/tray_constants.h"
18 #include "ash/common/system/tray/tray_popup_item_style.h" 18 #include "ash/common/system/tray/tray_popup_item_style.h"
19 #include "ash/common/system/user/rounded_image_view.h" 19 #include "ash/common/system/user/rounded_image_view.h"
20 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
21 #include "ash/resources/vector_icons/vector_icons.h" 21 #include "ash/resources/vector_icons/vector_icons.h"
22 #include "ash/strings/grit/ash_strings.h" 22 #include "ash/strings/grit/ash_strings.h"
23 #include "base/i18n/rtl.h" 23 #include "base/i18n/rtl.h"
24 #include "base/memory/ptr_util.h" 24 #include "base/memory/ptr_util.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // and end of the user's display name in the public account user card's text. 56 // and end of the user's display name in the public account user card's text.
57 const base::char16 kDisplayNameMark[] = {0x2060, 0}; 57 const base::char16 kDisplayNameMark[] = {0x2060, 0};
58 58
59 views::View* CreateUserAvatarView(LoginStatus login_status, int user_index) { 59 views::View* CreateUserAvatarView(LoginStatus login_status, int user_index) {
60 RoundedImageView* image_view = new RoundedImageView(kTrayItemSize / 2); 60 RoundedImageView* image_view = new RoundedImageView(kTrayItemSize / 2);
61 if (login_status == LoginStatus::GUEST) { 61 if (login_status == LoginStatus::GUEST) {
62 gfx::ImageSkia icon = 62 gfx::ImageSkia icon =
63 gfx::CreateVectorIcon(kSystemMenuGuestIcon, kMenuIconColor); 63 gfx::CreateVectorIcon(kSystemMenuGuestIcon, kMenuIconColor);
64 image_view->SetImage(icon, icon.size()); 64 image_view->SetImage(icon, icon.size());
65 } else { 65 } else {
66 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); 66 SessionController* controller = WmShell::Get()->session_controller();
67 image_view->SetImage(delegate->GetUserInfo(user_index)->GetImage(), 67 // TODO(xiyuan); HiDpi avatar support. http://crbug.com/702689
68 image_view->SetImage(gfx::ImageSkia::CreateFrom1xBitmap(
69 controller->GetUserSession(user_index)->avatar),
68 gfx::Size(kTrayItemSize, kTrayItemSize)); 70 gfx::Size(kTrayItemSize, kTrayItemSize));
69 } 71 }
70 72
71 image_view->SetBorder(views::CreateEmptyBorder(gfx::Insets( 73 image_view->SetBorder(views::CreateEmptyBorder(gfx::Insets(
72 (kTrayPopupItemMinStartWidth - image_view->GetPreferredSize().width()) / 74 (kTrayPopupItemMinStartWidth - image_view->GetPreferredSize().width()) /
73 2))); 75 2)));
74 return image_view; 76 return image_view;
75 } 77 }
76 78
77 // The user details shown in public account mode. This is essentially a label 79 // The user details shown in public account mode. This is essentially a label
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 const int inner_padding = 113 const int inner_padding =
112 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; 114 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems;
113 const bool rtl = base::i18n::IsRTL(); 115 const bool rtl = base::i18n::IsRTL();
114 SetBorder(views::CreateEmptyBorder( 116 SetBorder(views::CreateEmptyBorder(
115 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, 117 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding,
116 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); 118 kUserDetailsVerticalPadding, rtl ? inner_padding : 0));
117 119
118 // Retrieve the user's display name and wrap it with markers. 120 // Retrieve the user's display name and wrap it with markers.
119 // Note that since this is a public account it always has to be the primary 121 // Note that since this is a public account it always has to be the primary
120 // user. 122 // user.
121 base::string16 display_name = WmShell::Get() 123 base::string16 display_name = base::UTF8ToUTF16(
122 ->GetSessionStateDelegate() 124 WmShell::Get()->session_controller()->GetUserSession(0)->display_name);
123 ->GetUserInfo(0)
124 ->GetDisplayName();
125 base::RemoveChars(display_name, kDisplayNameMark, &display_name); 125 base::RemoveChars(display_name, kDisplayNameMark, &display_name);
126 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; 126 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0];
127 // Retrieve the domain managing the device and wrap it with markers. 127 // Retrieve the domain managing the device and wrap it with markers.
128 base::string16 domain = base::UTF8ToUTF16( 128 base::string16 domain = base::UTF8ToUTF16(
129 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain()); 129 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain());
130 base::RemoveChars(domain, kDisplayNameMark, &domain); 130 base::RemoveChars(domain, kDisplayNameMark, &domain);
131 base::i18n::WrapStringWithLTRFormatting(&domain); 131 base::i18n::WrapStringWithLTRFormatting(&domain);
132 // Retrieve the label text, inserting the display name and domain. 132 // Retrieve the label text, inserting the display name and domain.
133 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, 133 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL,
134 display_name, domain); 134 display_name, domain);
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0); 388 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0);
389 AddChildView(avatar); 389 AddChildView(avatar);
390 int details_max_width = max_width - avatar->GetPreferredSize().width() - 390 int details_max_width = max_width - avatar->GetPreferredSize().width() -
391 kTrayPopupPaddingBetweenItems; 391 kTrayPopupPaddingBetweenItems;
392 AddChildView(new PublicAccountUserDetails(details_max_width)); 392 AddChildView(new PublicAccountUserDetails(details_max_width));
393 } 393 }
394 394
395 void UserCardView::AddUserContent(views::BoxLayout* layout, 395 void UserCardView::AddUserContent(views::BoxLayout* layout,
396 LoginStatus login_status) { 396 LoginStatus login_status) {
397 AddChildView(CreateUserAvatarView(login_status, user_index_)); 397 AddChildView(CreateUserAvatarView(login_status, user_index_));
398 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); 398 SessionController* controller = WmShell::Get()->session_controller();
399 base::string16 user_name_string = 399 base::string16 user_name_string =
400 login_status == LoginStatus::GUEST 400 login_status == LoginStatus::GUEST
401 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) 401 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
402 : delegate->GetUserInfo(user_index_)->GetDisplayName(); 402 : base::UTF8ToUTF16(
403 controller->GetUserSession(user_index_)->display_name);
403 user_name_ = new views::Label(user_name_string); 404 user_name_ = new views::Label(user_name_string);
404 user_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 405 user_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
405 TrayPopupItemStyle user_name_style( 406 TrayPopupItemStyle user_name_style(
406 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); 407 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL);
407 user_name_style.SetupLabel(user_name_); 408 user_name_style.SetupLabel(user_name_);
408 409
409 TrayPopupItemStyle user_email_style(TrayPopupItemStyle::FontStyle::CAPTION); 410 TrayPopupItemStyle user_email_style(TrayPopupItemStyle::FontStyle::CAPTION);
410 // Only the active user's email label is lightened (for the inactive user, the 411 // Only the active user's email label is lightened (for the inactive user, the
411 // label starts as black and the entire row is 54% opacity). 412 // label starts as black and the entire row is 54% opacity).
412 if (is_active_user()) 413 if (is_active_user())
413 user_email_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); 414 user_email_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE);
414 auto* user_email = new views::Label(); 415 auto* user_email = new views::Label();
415 base::string16 user_email_string; 416 base::string16 user_email_string;
416 if (login_status != LoginStatus::GUEST) { 417 if (login_status != LoginStatus::GUEST) {
417 user_email_string = 418 user_email_string =
418 WmShell::Get()->system_tray_delegate()->IsUserSupervised() 419 WmShell::Get()->system_tray_delegate()->IsUserSupervised()
419 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) 420 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)
420 : base::UTF8ToUTF16( 421 : base::UTF8ToUTF16(
421 delegate->GetUserInfo(user_index_)->GetDisplayEmail()); 422 controller->GetUserSession(user_index_)->display_email);
422 } 423 }
423 user_email->SetText(user_email_string); 424 user_email->SetText(user_email_string);
424 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT); 425 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT);
425 user_email_style.SetupLabel(user_email); 426 user_email_style.SetupLabel(user_email);
426 user_email->SetVisible(!user_email_string.empty()); 427 user_email->SetVisible(!user_email_string.empty());
427 user_email->set_collapse_when_hidden(true); 428 user_email->set_collapse_when_hidden(true);
428 429
429 views::View* stack_of_labels = new views::View; 430 views::View* stack_of_labels = new views::View;
430 AddChildView(stack_of_labels); 431 AddChildView(stack_of_labels);
431 layout->SetFlexForView(stack_of_labels, 1); 432 layout->SetFlexForView(stack_of_labels, 1);
(...skipping 29 matching lines...) Expand all
461 462
462 media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR); 463 media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR);
463 AddChildView(media_capture_icon_); 464 AddChildView(media_capture_icon_);
464 465
465 WmShell::Get()->media_controller()->RequestCaptureState(); 466 WmShell::Get()->media_controller()->RequestCaptureState();
466 } 467 }
467 } 468 }
468 469
469 } // namespace tray 470 } // namespace tray
470 } // namespace ash 471 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/user/tray_user_unittest.cc ('k') | ash/common/system/user/user_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698