OLD | NEW |
---|---|
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 Loading... | |
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 image_view->SetImage(gfx::ImageSkia::CreateFrom1xBitmap( |
James Cook
2017/03/17 17:14:35
ditto re high dpi
xiyuan
2017/03/17 22:52:02
Acknowledged.
| |
68 controller->GetUserSession(user_index)->avatar), | |
68 gfx::Size(kTrayItemSize, kTrayItemSize)); | 69 gfx::Size(kTrayItemSize, kTrayItemSize)); |
69 } | 70 } |
70 | 71 |
71 image_view->SetBorder(views::CreateEmptyBorder(gfx::Insets( | 72 image_view->SetBorder(views::CreateEmptyBorder(gfx::Insets( |
72 (kTrayPopupItemMinStartWidth - image_view->GetPreferredSize().width()) / | 73 (kTrayPopupItemMinStartWidth - image_view->GetPreferredSize().width()) / |
73 2))); | 74 2))); |
74 return image_view; | 75 return image_view; |
75 } | 76 } |
76 | 77 |
77 // The user details shown in public account mode. This is essentially a label | 78 // 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 Loading... | |
111 const int inner_padding = | 112 const int inner_padding = |
112 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; | 113 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; |
113 const bool rtl = base::i18n::IsRTL(); | 114 const bool rtl = base::i18n::IsRTL(); |
114 SetBorder(views::CreateEmptyBorder( | 115 SetBorder(views::CreateEmptyBorder( |
115 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, | 116 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, |
116 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); | 117 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); |
117 | 118 |
118 // Retrieve the user's display name and wrap it with markers. | 119 // 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 | 120 // Note that since this is a public account it always has to be the primary |
120 // user. | 121 // user. |
121 base::string16 display_name = WmShell::Get() | 122 base::string16 display_name = base::UTF8ToUTF16( |
122 ->GetSessionStateDelegate() | 123 WmShell::Get()->session_controller()->GetUserSession(0)->display_name); |
123 ->GetUserInfo(0) | |
124 ->GetDisplayName(); | |
125 base::RemoveChars(display_name, kDisplayNameMark, &display_name); | 124 base::RemoveChars(display_name, kDisplayNameMark, &display_name); |
126 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; | 125 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; |
127 // Retrieve the domain managing the device and wrap it with markers. | 126 // Retrieve the domain managing the device and wrap it with markers. |
128 base::string16 domain = base::UTF8ToUTF16( | 127 base::string16 domain = base::UTF8ToUTF16( |
129 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain()); | 128 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain()); |
130 base::RemoveChars(domain, kDisplayNameMark, &domain); | 129 base::RemoveChars(domain, kDisplayNameMark, &domain); |
131 base::i18n::WrapStringWithLTRFormatting(&domain); | 130 base::i18n::WrapStringWithLTRFormatting(&domain); |
132 // Retrieve the label text, inserting the display name and domain. | 131 // Retrieve the label text, inserting the display name and domain. |
133 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, | 132 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, |
134 display_name, domain); | 133 display_name, domain); |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
388 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0); | 387 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0); |
389 AddChildView(avatar); | 388 AddChildView(avatar); |
390 int details_max_width = max_width - avatar->GetPreferredSize().width() - | 389 int details_max_width = max_width - avatar->GetPreferredSize().width() - |
391 kTrayPopupPaddingBetweenItems; | 390 kTrayPopupPaddingBetweenItems; |
392 AddChildView(new PublicAccountUserDetails(details_max_width)); | 391 AddChildView(new PublicAccountUserDetails(details_max_width)); |
393 } | 392 } |
394 | 393 |
395 void UserCardView::AddUserContent(views::BoxLayout* layout, | 394 void UserCardView::AddUserContent(views::BoxLayout* layout, |
396 LoginStatus login_status) { | 395 LoginStatus login_status) { |
397 AddChildView(CreateUserAvatarView(login_status, user_index_)); | 396 AddChildView(CreateUserAvatarView(login_status, user_index_)); |
398 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); | 397 SessionController* controller = WmShell::Get()->session_controller(); |
399 base::string16 user_name_string = | 398 base::string16 user_name_string = |
400 login_status == LoginStatus::GUEST | 399 login_status == LoginStatus::GUEST |
401 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) | 400 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) |
402 : delegate->GetUserInfo(user_index_)->GetDisplayName(); | 401 : base::UTF8ToUTF16( |
402 controller->GetUserSession(user_index_)->display_name); | |
403 user_name_ = new views::Label(user_name_string); | 403 user_name_ = new views::Label(user_name_string); |
404 user_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 404 user_name_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
405 TrayPopupItemStyle user_name_style( | 405 TrayPopupItemStyle user_name_style( |
406 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 406 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
407 user_name_style.SetupLabel(user_name_); | 407 user_name_style.SetupLabel(user_name_); |
408 | 408 |
409 TrayPopupItemStyle user_email_style(TrayPopupItemStyle::FontStyle::CAPTION); | 409 TrayPopupItemStyle user_email_style(TrayPopupItemStyle::FontStyle::CAPTION); |
410 // Only the active user's email label is lightened (for the inactive user, the | 410 // 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). | 411 // label starts as black and the entire row is 54% opacity). |
412 if (is_active_user()) | 412 if (is_active_user()) |
413 user_email_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); | 413 user_email_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); |
414 auto* user_email = new views::Label(); | 414 auto* user_email = new views::Label(); |
415 base::string16 user_email_string; | 415 base::string16 user_email_string; |
416 if (login_status != LoginStatus::GUEST) { | 416 if (login_status != LoginStatus::GUEST) { |
417 user_email_string = | 417 user_email_string = |
418 WmShell::Get()->system_tray_delegate()->IsUserSupervised() | 418 WmShell::Get()->system_tray_delegate()->IsUserSupervised() |
419 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) | 419 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) |
420 : base::UTF8ToUTF16( | 420 : base::UTF8ToUTF16( |
421 delegate->GetUserInfo(user_index_)->GetDisplayEmail()); | 421 controller->GetUserSession(user_index_)->display_email); |
422 } | 422 } |
423 user_email->SetText(user_email_string); | 423 user_email->SetText(user_email_string); |
424 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 424 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
425 user_email_style.SetupLabel(user_email); | 425 user_email_style.SetupLabel(user_email); |
426 user_email->SetVisible(!user_email_string.empty()); | 426 user_email->SetVisible(!user_email_string.empty()); |
427 user_email->set_collapse_when_hidden(true); | 427 user_email->set_collapse_when_hidden(true); |
428 | 428 |
429 views::View* stack_of_labels = new views::View; | 429 views::View* stack_of_labels = new views::View; |
430 AddChildView(stack_of_labels); | 430 AddChildView(stack_of_labels); |
431 layout->SetFlexForView(stack_of_labels, 1); | 431 layout->SetFlexForView(stack_of_labels, 1); |
(...skipping 29 matching lines...) Expand all Loading... | |
461 | 461 |
462 media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR); | 462 media_capture_icon_->set_id(VIEW_ID_USER_VIEW_MEDIA_INDICATOR); |
463 AddChildView(media_capture_icon_); | 463 AddChildView(media_capture_icon_); |
464 | 464 |
465 WmShell::Get()->media_controller()->RequestCaptureState(); | 465 WmShell::Get()->media_controller()->RequestCaptureState(); |
466 } | 466 } |
467 } | 467 } |
468 | 468 |
469 } // namespace tray | 469 } // namespace tray |
470 } // namespace ash | 470 } // namespace ash |
OLD | NEW |