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

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

Issue 2498293003: CrOS md user row adjustments (Closed)
Patch Set: more stuff Created 4 years, 1 month 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 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 <vector> 8 #include <vector>
9 9
10 #include "ash/common/login_status.h" 10 #include "ash/common/login_status.h"
11 #include "ash/common/material_design/material_design_controller.h" 11 #include "ash/common/material_design/material_design_controller.h"
12 #include "ash/common/session/session_state_delegate.h" 12 #include "ash/common/session/session_state_delegate.h"
13 #include "ash/common/system/tray/system_tray_controller.h" 13 #include "ash/common/system/tray/system_tray_controller.h"
14 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/system_tray_notifier.h" 15 #include "ash/common/system/tray/system_tray_notifier.h"
16 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
17 #include "ash/common/system/tray/tray_popup_item_style.h"
17 #include "ash/common/system/tray/tray_utils.h" 18 #include "ash/common/system/tray/tray_utils.h"
18 #include "ash/common/system/user/rounded_image_view.h" 19 #include "ash/common/system/user/rounded_image_view.h"
19 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
20 #include "ash/resources/vector_icons/vector_icons.h" 21 #include "ash/resources/vector_icons/vector_icons.h"
21 #include "base/i18n/rtl.h" 22 #include "base/i18n/rtl.h"
22 #include "base/memory/scoped_vector.h" 23 #include "base/memory/scoped_vector.h"
23 #include "base/strings/string16.h" 24 #include "base/strings/string16.h"
24 #include "base/strings/string_util.h" 25 #include "base/strings/string_util.h"
25 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
26 #include "components/user_manager/user_info.h" 27 #include "components/user_manager/user_info.h"
27 #include "grit/ash_resources.h" 28 #include "grit/ash_resources.h"
28 #include "grit/ash_strings.h" 29 #include "grit/ash_strings.h"
29 #include "ui/accessibility/ax_node_data.h" 30 #include "ui/accessibility/ax_node_data.h"
30 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 32 #include "ui/base/resource/resource_bundle.h"
33 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/geometry/insets.h" 34 #include "ui/gfx/geometry/insets.h"
33 #include "ui/gfx/geometry/rect.h" 35 #include "ui/gfx/geometry/rect.h"
34 #include "ui/gfx/geometry/size.h" 36 #include "ui/gfx/geometry/size.h"
35 #include "ui/gfx/paint_vector_icon.h" 37 #include "ui/gfx/paint_vector_icon.h"
36 #include "ui/gfx/range/range.h" 38 #include "ui/gfx/range/range.h"
37 #include "ui/gfx/render_text.h" 39 #include "ui/gfx/render_text.h"
38 #include "ui/gfx/text_elider.h" 40 #include "ui/gfx/text_elider.h"
39 #include "ui/gfx/text_utils.h" 41 #include "ui/gfx/text_utils.h"
40 #include "ui/views/border.h" 42 #include "ui/views/border.h"
41 #include "ui/views/controls/link.h" 43 #include "ui/views/controls/link.h"
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); 357 link_size.height() - learn_more_->GetInsets().top() - line_height, 0);
356 preferred_size_ = 358 preferred_size_ =
357 gfx::Size(min_width + insets.width(), 359 gfx::Size(min_width + insets.width(),
358 line_count * line_height + link_extra_height + insets.height()); 360 line_count * line_height + link_extra_height + insets.height());
359 } 361 }
360 362
361 } // namespace 363 } // namespace
362 364
363 UserCardView::UserCardView(LoginStatus login_status, 365 UserCardView::UserCardView(LoginStatus login_status,
364 int max_width, 366 int max_width,
365 int user_index) { 367 int user_index)
368 : user_index_(user_index) {
366 auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 369 auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0,
367 UseMd() ? kTrayPopupLabelHorizontalPadding 370 UseMd() ? kTrayPopupLabelHorizontalPadding
368 : kTrayPopupPaddingBetweenItems); 371 : kTrayPopupPaddingBetweenItems);
369 SetLayoutManager(layout); 372 SetLayoutManager(layout);
370 if (UseMd()) { 373 if (UseMd()) {
371 layout->set_minimum_cross_axis_size( 374 layout->set_minimum_cross_axis_size(
372 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); 375 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT));
373 layout->set_cross_axis_alignment( 376 layout->set_cross_axis_alignment(
374 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 377 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
378
379 if (user_index != 0) {
tdanderson 2016/11/16 23:08:08 Consider sharing UserView::IsActiveUser() logic, p
Evan Stade 2016/11/17 00:37:50 I don't like the idea of sharing such simple logic
tdanderson 2016/11/17 01:40:15 Thanks. One person's verbosity is perhaps another
380 SetPaintToLayer(true);
381 layer()->SetOpacity(0.5f);
382 }
375 } 383 }
376 384
377 if (login_status == LoginStatus::PUBLIC) { 385 if (login_status == LoginStatus::PUBLIC) {
378 AddPublicModeUserContent(max_width); 386 AddPublicModeUserContent(max_width);
379 } else { 387 } else {
380 AddUserContent(login_status, user_index); 388 AddUserContent(login_status);
381 } 389 }
382 } 390 }
383 391
384 UserCardView::~UserCardView() {} 392 UserCardView::~UserCardView() {}
385 393
386 void UserCardView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 394 void UserCardView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
387 node_data->role = ui::AX_ROLE_STATIC_TEXT; 395 node_data->role = ui::AX_ROLE_STATIC_TEXT;
388 std::vector<base::string16> labels; 396 std::vector<base::string16> labels;
389 for (int i = 0; i < child_count(); ++i) 397 for (int i = 0; i < child_count(); ++i)
390 GetAccessibleLabelFromDescendantViews(child_at(i), labels); 398 GetAccessibleLabelFromDescendantViews(child_at(i), labels);
391 node_data->SetName(base::JoinString(labels, base::ASCIIToUTF16(" "))); 399 node_data->SetName(base::JoinString(labels, base::ASCIIToUTF16(" ")));
392 } 400 }
393 401
394 void UserCardView::AddPublicModeUserContent(int max_width) { 402 void UserCardView::AddPublicModeUserContent(int max_width) {
395 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0); 403 views::View* avatar = CreateUserAvatarView(LoginStatus::PUBLIC, 0);
396 AddChildView(avatar); 404 AddChildView(avatar);
397 int details_max_width = max_width - avatar->GetPreferredSize().width() - 405 int details_max_width = max_width - avatar->GetPreferredSize().width() -
398 kTrayPopupPaddingBetweenItems; 406 kTrayPopupPaddingBetweenItems;
399 AddChildView(new PublicAccountUserDetails(details_max_width)); 407 AddChildView(new PublicAccountUserDetails(details_max_width));
400 } 408 }
401 409
402 void UserCardView::AddUserContent(LoginStatus login_status, int user_index) { 410 void UserCardView::AddUserContent(LoginStatus login_status) {
403 views::View* avatar = CreateUserAvatarView(login_status, user_index); 411 if (UseMd())
412 return AddUserContentMd(login_status);
413 views::View* avatar = CreateUserAvatarView(login_status, user_index_);
404 AddChildView(avatar); 414 AddChildView(avatar);
405 views::Label* user_name = NULL; 415 views::Label* user_name = NULL;
406 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); 416 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
407 if (!user_index) { 417 if (!user_index_) {
408 base::string16 user_name_string = 418 base::string16 user_name_string =
409 login_status == LoginStatus::GUEST 419 login_status == LoginStatus::GUEST
410 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL) 420 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
411 : delegate->GetUserInfo(user_index)->GetDisplayName(); 421 : delegate->GetUserInfo(user_index_)->GetDisplayName();
412 if (!user_name_string.empty()) { 422 if (!user_name_string.empty()) {
413 user_name = new views::Label(user_name_string); 423 user_name = new views::Label(user_name_string);
414 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT); 424 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
415 } 425 }
416 } 426 }
417 427
418 views::Label* user_email = NULL; 428 views::Label* user_email = NULL;
419 if (login_status != LoginStatus::GUEST) { 429 if (login_status != LoginStatus::GUEST) {
420 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate(); 430 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate();
421 base::string16 user_email_string = 431 base::string16 user_email_string =
422 tray_delegate->IsUserSupervised() 432 tray_delegate->IsUserSupervised()
423 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL) 433 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)
424 : base::UTF8ToUTF16( 434 : base::UTF8ToUTF16(
425 delegate->GetUserInfo(user_index)->GetDisplayEmail()); 435 delegate->GetUserInfo(user_index_)->GetDisplayEmail());
426 if (!user_email_string.empty()) { 436 if (!user_email_string.empty()) {
427 user_email = new views::Label(user_email_string); 437 user_email = new views::Label(user_email_string);
428 user_email->SetFontList( 438 user_email->SetFontList(
429 ui::ResourceBundle::GetSharedInstance().GetFontList( 439 ui::ResourceBundle::GetSharedInstance().GetFontList(
430 ui::ResourceBundle::SmallFont)); 440 ui::ResourceBundle::SmallFont));
431 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT); 441 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT);
432 } 442 }
433 } 443 }
434 444
435 // Adjust text properties dependent on if it is an active or inactive user. 445 // Adjust text properties dependent on if it is an active or inactive user.
436 if (user_index) { 446 if (user_index_) {
437 // Fade the text of non active users to 50%. 447 // Fade the text of non active users to 50%.
438 SkColor text_color = user_email->enabled_color(); 448 SkColor text_color = user_email->enabled_color();
439 text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2); 449 text_color = SkColorSetA(text_color, SkColorGetA(text_color) / 2);
440 if (user_email) 450 if (user_email)
441 user_email->SetDisabledColor(text_color); 451 user_email->SetDisabledColor(text_color);
442 if (user_name) 452 if (user_name)
443 user_name->SetDisabledColor(text_color); 453 user_name->SetDisabledColor(text_color);
444 } 454 }
445 455
446 if (user_email && user_name) { 456 if (user_email && user_name) {
447 views::View* details = new views::View; 457 views::View* details = new views::View;
448 details->SetLayoutManager(new views::BoxLayout( 458 details->SetLayoutManager(new views::BoxLayout(
449 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); 459 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
450 details->AddChildView(user_name); 460 details->AddChildView(user_name);
451 details->AddChildView(user_email); 461 details->AddChildView(user_email);
452 AddChildView(details); 462 AddChildView(details);
453 } else { 463 } else {
454 if (user_name) 464 if (user_name)
455 AddChildView(user_name); 465 AddChildView(user_name);
456 if (user_email) { 466 if (user_email) {
457 #if defined(OS_CHROMEOS) 467 #if defined(OS_CHROMEOS)
458 // Only non active user can have a media indicator. 468 // Only non active user can have a media indicator.
459 MediaIndicator* media_indicator = new MediaIndicator(user_index); 469 MediaIndicator* media_indicator = new MediaIndicator(user_index_);
460 views::View* email_indicator_view = new views::View; 470 views::View* email_indicator_view = new views::View;
461 email_indicator_view->SetLayoutManager(new views::BoxLayout( 471 email_indicator_view->SetLayoutManager(new views::BoxLayout(
462 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 472 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
463 email_indicator_view->AddChildView(user_email); 473 email_indicator_view->AddChildView(user_email);
464 email_indicator_view->AddChildView(media_indicator); 474 email_indicator_view->AddChildView(media_indicator);
465 475
466 views::View* details = new views::View; 476 views::View* details = new views::View;
467 details->SetLayoutManager(new views::BoxLayout( 477 details->SetLayoutManager(new views::BoxLayout(
468 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0)); 478 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
469 details->AddChildView(email_indicator_view); 479 details->AddChildView(email_indicator_view);
470 details->AddChildView(media_indicator->GetMessageView()); 480 details->AddChildView(media_indicator->GetMessageView());
471 AddChildView(details); 481 AddChildView(details);
472 #else 482 #else
473 AddChildView(user_email); 483 AddChildView(user_email);
474 #endif 484 #endif
475 } 485 }
476 } 486 }
477 } 487 }
478 488
489 void UserCardView::AddUserContentMd(LoginStatus login_status) {
tdanderson 2016/11/16 23:08:08 It seems the similarity between this and the non-M
Evan Stade 2016/11/17 00:37:50 It's way harder to sprinkle use_md around and not
tdanderson 2016/11/17 01:40:15 This all sounds very reasonable, and as I said, I
Evan Stade 2016/11/17 01:54:18 indeed, that is another consideration that I might
490 AddChildView(CreateUserAvatarView(login_status, user_index_));
491 views::Label* user_name = nullptr;
492 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate();
493 if (!user_index_) {
494 base::string16 user_name_string =
495 login_status == LoginStatus::GUEST
496 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_GUEST_LABEL)
497 : delegate->GetUserInfo(user_index_)->GetDisplayName();
498 if (!user_name_string.empty()) {
499 user_name = new views::Label(user_name_string);
500 user_name->SetHorizontalAlignment(gfx::ALIGN_LEFT);
501 TrayPopupItemStyle user_name_style(nullptr,
502 TrayPopupItemStyle::FontStyle::TITLE);
503 user_name_style.SetupLabel(user_name);
504 }
505 }
506
507 views::Label* user_email = NULL;
508 if (login_status != LoginStatus::GUEST) {
509 SystemTrayDelegate* tray_delegate = WmShell::Get()->system_tray_delegate();
510 base::string16 user_email_string =
511 tray_delegate->IsUserSupervised()
512 ? l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SUPERVISED_LABEL)
513 : base::UTF8ToUTF16(
514 delegate->GetUserInfo(user_index_)->GetDisplayEmail());
515 if (!user_email_string.empty()) {
516 user_email = new views::Label(user_email_string);
517 user_email->SetFontList(
518 ui::ResourceBundle::GetSharedInstance().GetFontList(
519 ui::ResourceBundle::SmallFont));
520 user_email->SetHorizontalAlignment(gfx::ALIGN_LEFT);
521 TrayPopupItemStyle user_email_style(
522 nullptr, TrayPopupItemStyle::FontStyle::CAPTION);
523 user_email_style.set_color_style(
524 TrayPopupItemStyle::ColorStyle::INACTIVE);
525 user_email_style.SetupLabel(user_email);
526 }
527 }
528
529 if (user_email && user_name) {
530 views::View* details = new views::View;
531 details->SetLayoutManager(
532 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
533 details->AddChildView(user_name);
534 details->AddChildView(user_email);
535 // The name and email have different font sizes. This border is designed
536 // to make both views take up equal space so the whitespace between them
537 // is centered on the vertical midpoint.
538 user_email->SetBorder(views::CreateEmptyBorder(
539 0, 0, user_name->GetPreferredSize().height() -
540 user_email->GetPreferredSize().height(),
541 0));
542 AddChildView(details);
543 } else if (user_name) {
544 AddChildView(user_name);
545 } else if (user_email) {
546 #if defined(OS_CHROMEOS)
547 // Only non active user can have a media indicator.
548 MediaIndicator* media_indicator = new MediaIndicator(user_index_);
549 views::View* email_indicator_view = new views::View;
550 email_indicator_view->SetLayoutManager(new views::BoxLayout(
551 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
552 email_indicator_view->AddChildView(user_email);
553 email_indicator_view->AddChildView(media_indicator);
554
555 views::View* details = new views::View;
556 details->SetLayoutManager(new views::BoxLayout(
557 views::BoxLayout::kVertical, 0, kUserDetailsVerticalPadding, 0));
558 details->AddChildView(email_indicator_view);
559 details->AddChildView(media_indicator->GetMessageView());
560 AddChildView(details);
561 #else
562 AddChildView(user_email);
563 #endif
564 }
565 }
479 566
480 } // namespace tray 567 } // namespace tray
481 } // namespace ash 568 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698