| 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_view.h" | 5 #include "ash/common/system/user/user_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/common/material_design/material_design_controller.h" | 10 #include "ash/common/material_design/material_design_controller.h" |
| 11 #include "ash/common/multi_profile_uma.h" | 11 #include "ash/common/multi_profile_uma.h" |
| 12 #include "ash/common/popup_message.h" | 12 #include "ash/common/popup_message.h" |
| 13 #include "ash/common/session/session_state_delegate.h" | 13 #include "ash/common/session/session_state_delegate.h" |
| 14 #include "ash/common/shell_delegate.h" | 14 #include "ash/common/shell_delegate.h" |
| 15 #include "ash/common/system/tray/system_tray.h" | 15 #include "ash/common/system/tray/system_tray.h" |
| 16 #include "ash/common/system/tray/system_tray_controller.h" | 16 #include "ash/common/system/tray/system_tray_controller.h" |
| 17 #include "ash/common/system/tray/system_tray_delegate.h" | 17 #include "ash/common/system/tray/system_tray_delegate.h" |
| 18 #include "ash/common/system/tray/tray_constants.h" | 18 #include "ash/common/system/tray/tray_constants.h" |
| 19 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 19 #include "ash/common/system/tray/tray_popup_label_button.h" | 20 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 20 #include "ash/common/system/tray/tray_popup_label_button_border.h" | 21 #include "ash/common/system/tray/tray_popup_label_button_border.h" |
| 21 #include "ash/common/system/tray/tray_popup_utils.h" | 22 #include "ash/common/system/tray/tray_popup_utils.h" |
| 22 #include "ash/common/system/user/button_from_view.h" | 23 #include "ash/common/system/user/button_from_view.h" |
| 23 #include "ash/common/system/user/login_status.h" | 24 #include "ash/common/system/user/login_status.h" |
| 24 #include "ash/common/system/user/rounded_image_view.h" | 25 #include "ash/common/system/user/rounded_image_view.h" |
| 25 #include "ash/common/system/user/user_card_view.h" | 26 #include "ash/common/system/user/user_card_view.h" |
| 26 #include "ash/common/wm_lookup.h" | 27 #include "ash/common/wm_lookup.h" |
| 27 #include "ash/common/wm_root_window_controller.h" | 28 #include "ash/common/wm_root_window_controller.h" |
| 28 #include "ash/common/wm_shell.h" | 29 #include "ash/common/wm_shell.h" |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); | 98 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); |
| 98 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); | 99 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); |
| 99 } | 100 } |
| 100 | 101 |
| 101 bool IsMultiProfileSupportedAndUserActive() { | 102 bool IsMultiProfileSupportedAndUserActive() { |
| 102 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && | 103 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && |
| 103 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); | 104 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); |
| 104 } | 105 } |
| 105 | 106 |
| 106 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). | 107 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). |
| 107 views::View* CreateAddUserView(AddUserSessionPolicy policy) { | 108 views::View* CreateAddUserView(AddUserSessionPolicy policy, |
| 109 views::ButtonListener* listener) { |
| 108 DCHECK(UseMd()); | 110 DCHECK(UseMd()); |
| 109 auto view = new views::View; | 111 auto view = new views::View; |
| 110 auto layout = new views::BoxLayout( | 112 const int icon_padding = (kMenuButtonSize - kMenuIconSize) / 2; |
| 111 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2, | 113 auto layout = |
| 112 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems); | 114 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
| 115 kTrayPopupLabelHorizontalPadding + icon_padding); |
| 113 layout->set_minimum_cross_axis_size( | 116 layout->set_minimum_cross_axis_size( |
| 114 policy == AddUserSessionPolicy::ALLOWED | 117 GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); |
| 115 ? GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT) | |
| 116 : 56); | |
| 117 view->SetLayoutManager(layout); | 118 view->SetLayoutManager(layout); |
| 118 view->set_background( | 119 view->set_background( |
| 119 views::Background::CreateSolidBackground(kBackgroundColor)); | 120 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 120 | 121 |
| 121 int message_id = 0; | 122 int message_id = 0; |
| 122 switch (policy) { | 123 switch (policy) { |
| 123 case AddUserSessionPolicy::ALLOWED: { | 124 case AddUserSessionPolicy::ALLOWED: { |
| 124 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; | 125 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; |
| 125 | 126 |
| 126 auto icon = new views::ImageView(); | 127 auto icon = new views::ImageView(); |
| 127 icon->SetImage( | 128 icon->SetImage( |
| 128 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); | 129 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); |
| 129 view->AddChildView(icon); | 130 view->AddChildView(icon); |
| 130 break; | 131 break; |
| 131 } | 132 } |
| 132 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER: | 133 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER: |
| 133 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; | 134 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; |
| 134 break; | 135 break; |
| 135 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED: | 136 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED: |
| 136 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; | 137 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; |
| 137 break; | 138 break; |
| 138 case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS: | 139 case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS: |
| 139 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; | 140 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; |
| 140 break; | 141 break; |
| 141 } | 142 } |
| 142 | 143 |
| 143 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id)); | 144 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id)); |
| 144 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 145 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 145 command_label->SetMultiLine(true); | 146 command_label->SetMultiLine(true); |
| 147 |
| 148 TrayPopupItemStyle label_style( |
| 149 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); |
| 150 int vertical_padding = kMenuSeparatorVerticalPadding; |
| 151 if (policy != AddUserSessionPolicy::ALLOWED) { |
| 152 label_style.set_font_style(TrayPopupItemStyle::FontStyle::CAPTION); |
| 153 label_style.set_color_style(TrayPopupItemStyle::ColorStyle::INACTIVE); |
| 154 vertical_padding += kMenuSeparatorVerticalPadding; |
| 155 } |
| 156 label_style.SetupLabel(command_label); |
| 146 view->AddChildView(command_label); | 157 view->AddChildView(command_label); |
| 158 view->SetBorder(views::CreateEmptyBorder(vertical_padding, icon_padding, |
| 159 vertical_padding, |
| 160 kTrayPopupLabelHorizontalPadding)); |
| 161 if (policy == AddUserSessionPolicy::ALLOWED) { |
| 162 auto button = |
| 163 new ButtonFromView(view, listener, TrayPopupInkDropStyle::INSET_BOUNDS, |
| 164 false, gfx::Insets()); |
| 165 button->SetAccessibleName( |
| 166 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); |
| 167 return button; |
| 168 } |
| 169 |
| 147 return view; | 170 return view; |
| 148 } | 171 } |
| 149 | 172 |
| 150 class UserViewMouseWatcherHost : public views::MouseWatcherHost { | 173 class UserViewMouseWatcherHost : public views::MouseWatcherHost { |
| 151 public: | 174 public: |
| 152 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) | 175 explicit UserViewMouseWatcherHost(const gfx::Rect& screen_area) |
| 153 : screen_area_(screen_area) {} | 176 : screen_area_(screen_area) {} |
| 154 ~UserViewMouseWatcherHost() override {} | 177 ~UserViewMouseWatcherHost() override {} |
| 155 | 178 |
| 156 // Implementation of MouseWatcherHost. | 179 // Implementation of MouseWatcherHost. |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 } | 489 } |
| 467 | 490 |
| 468 void UserView::AddLogoutButton(LoginStatus login) { | 491 void UserView::AddLogoutButton(LoginStatus login) { |
| 469 const base::string16 title = | 492 const base::string16 title = |
| 470 user::GetLocalizedSignOutStringForStatus(login, true); | 493 user::GetLocalizedSignOutStringForStatus(login, true); |
| 471 auto* logout_button = | 494 auto* logout_button = |
| 472 TrayPopupUtils::CreateTrayPopupBorderlessButton(this, title); | 495 TrayPopupUtils::CreateTrayPopupBorderlessButton(this, title); |
| 473 logout_button->SetAccessibleName(title); | 496 logout_button->SetAccessibleName(title); |
| 474 logout_button_ = logout_button; | 497 logout_button_ = logout_button; |
| 475 if (UseMd()) { | 498 if (UseMd()) { |
| 476 views::View* separator = TrayPopupUtils::CreateVerticalSeparator(); | 499 AddChildView(TrayPopupUtils::CreateVerticalSeparator()); |
| 477 separator->SetBorder(views::CreateEmptyBorder( | |
| 478 gfx::Insets(0, 0, 0, kTrayPopupLabelHorizontalPadding))); | |
| 479 AddChildView(separator); | |
| 480 } else if (login == LoginStatus::PUBLIC) { | 500 } else if (login == LoginStatus::PUBLIC) { |
| 481 // In public account mode, the logout button border has a custom color. | 501 // In public account mode, the logout button border has a custom color. |
| 482 std::unique_ptr<TrayPopupLabelButtonBorder> border( | 502 std::unique_ptr<TrayPopupLabelButtonBorder> border( |
| 483 new TrayPopupLabelButtonBorder()); | 503 new TrayPopupLabelButtonBorder()); |
| 484 border->SetPainter(false, views::Button::STATE_NORMAL, | 504 border->SetPainter(false, views::Button::STATE_NORMAL, |
| 485 views::Painter::CreateImageGridPainter( | 505 views::Painter::CreateImageGridPainter( |
| 486 kPublicAccountLogoutButtonBorderImagesNormal)); | 506 kPublicAccountLogoutButtonBorderImagesNormal)); |
| 487 border->SetPainter(false, views::Button::STATE_HOVERED, | 507 border->SetPainter(false, views::Button::STATE_HOVERED, |
| 488 views::Painter::CreateImageGridPainter( | 508 views::Painter::CreateImageGridPainter( |
| 489 kPublicAccountLogoutButtonBorderImagesHovered)); | 509 kPublicAccountLogoutButtonBorderImagesHovered)); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 ¶ms); | 622 ¶ms); |
| 603 add_menu_option_->Init(params); | 623 add_menu_option_->Init(params); |
| 604 | 624 |
| 605 const SessionStateDelegate* delegate = | 625 const SessionStateDelegate* delegate = |
| 606 WmShell::Get()->GetSessionStateDelegate(); | 626 WmShell::Get()->GetSessionStateDelegate(); |
| 607 const AddUserSessionPolicy add_user_policy = | 627 const AddUserSessionPolicy add_user_policy = |
| 608 delegate->GetAddUserSessionPolicy(); | 628 delegate->GetAddUserSessionPolicy(); |
| 609 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; | 629 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; |
| 610 | 630 |
| 611 if (UseMd()) { | 631 if (UseMd()) { |
| 612 ButtonFromView* button = new ButtonFromView( | |
| 613 CreateAddUserView(add_user_policy), add_user_enabled_ ? this : nullptr, | |
| 614 IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS | |
| 615 : TrayPopupInkDropStyle::FILL_BOUNDS, | |
| 616 false, gfx::Insets()); | |
| 617 button->SetAccessibleName( | |
| 618 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); | |
| 619 button->ForceBorderVisible(true); | |
| 620 | |
| 621 // Position the widget on top of the user card view (which is still in the | 632 // Position the widget on top of the user card view (which is still in the |
| 622 // system menu). The top half of the widget will be transparent to allow | 633 // system menu). The top half of the widget will be transparent to allow |
| 623 // the active user to show through. | 634 // the active user to show through. |
| 624 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); | 635 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); |
| 625 bounds.set_width(bounds.width() + kSeparatorWidth); | 636 bounds.set_width(bounds.width() + kSeparatorWidth); |
| 626 int row_height = bounds.height(); | 637 int row_height = bounds.height(); |
| 627 | 638 |
| 628 views::View* container = new AddUserWidgetContents( | 639 views::View* container = new AddUserWidgetContents( |
| 629 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); | 640 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); |
| 630 container->SetBorder(views::CreatePaddedBorder( | 641 container->SetBorder(views::CreatePaddedBorder( |
| 631 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, | 642 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, |
| 632 kBackgroundColor), | 643 kBackgroundColor), |
| 633 gfx::Insets(row_height, 0, 0, 0))); | 644 gfx::Insets(row_height, 0, 0, 0))); |
| 645 views::View* add_user_padding = new views::View(); |
| 646 add_user_padding->SetBorder(views::CreateSolidSidedBorder( |
| 647 kMenuSeparatorVerticalPadding, 0, 0, 0, kBackgroundColor)); |
| 648 views::View* add_user_view = CreateAddUserView(add_user_policy, this); |
| 649 add_user_padding->AddChildView(add_user_view); |
| 650 add_user_padding->SetLayoutManager(new views::FillLayout()); |
| 651 container->AddChildView(add_user_padding); |
| 634 container->SetLayoutManager(new views::FillLayout()); | 652 container->SetLayoutManager(new views::FillLayout()); |
| 635 container->AddChildView(button); | |
| 636 add_menu_option_->SetContentsView(container); | 653 add_menu_option_->SetContentsView(container); |
| 637 | 654 |
| 638 bounds.set_height(container->GetPreferredSize().height()); | 655 bounds.set_height(container->GetPreferredSize().height()); |
| 639 add_menu_option_->SetBounds(bounds); | 656 add_menu_option_->SetBounds(bounds); |
| 640 | 657 |
| 641 // Show the content. | 658 // Show the content. |
| 642 add_menu_option_->SetAlwaysOnTop(true); | 659 add_menu_option_->SetAlwaysOnTop(true); |
| 643 add_menu_option_->Show(); | 660 add_menu_option_->Show(); |
| 644 | 661 |
| 645 // We activate the entry automatically if invoked with focus. | 662 // We activate the entry automatically if invoked with focus. |
| 646 if (add_user_enabled_ && user_card_view_->HasFocus()) { | 663 if (add_user_enabled_ && user_card_view_->HasFocus()) { |
| 647 button->GetFocusManager()->SetFocusedView(button); | 664 add_user_view->GetFocusManager()->SetFocusedView(add_user_view); |
| 648 user_card_view_->GetFocusManager()->SetFocusedView(button); | 665 user_card_view_->GetFocusManager()->SetFocusedView(add_user_view); |
| 649 } | 666 } |
| 650 } else { | 667 } else { |
| 651 AddUserView* add_user_view = | 668 AddUserView* add_user_view = |
| 652 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); | 669 new AddUserView(static_cast<ButtonFromView*>(user_card_view_)); |
| 653 ButtonFromView* button = new ButtonFromView( | 670 ButtonFromView* button = new ButtonFromView( |
| 654 add_user_view, add_user_enabled_ ? this : nullptr, | 671 add_user_view, add_user_enabled_ ? this : nullptr, |
| 655 // Ignored in non-md. | 672 // Ignored in non-md. |
| 656 TrayPopupInkDropStyle::INSET_BOUNDS, add_user_enabled_, gfx::Insets(1)); | 673 TrayPopupInkDropStyle::INSET_BOUNDS, add_user_enabled_, gfx::Insets(1)); |
| 657 button->SetAccessibleName( | 674 button->SetAccessibleName( |
| 658 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); | 675 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 focus_manager_ = nullptr; | 740 focus_manager_ = nullptr; |
| 724 if (user_card_view_->GetFocusManager()) | 741 if (user_card_view_->GetFocusManager()) |
| 725 user_card_view_->GetFocusManager()->ClearFocus(); | 742 user_card_view_->GetFocusManager()->ClearFocus(); |
| 726 popup_message_.reset(); | 743 popup_message_.reset(); |
| 727 mouse_watcher_.reset(); | 744 mouse_watcher_.reset(); |
| 728 add_menu_option_.reset(); | 745 add_menu_option_.reset(); |
| 729 } | 746 } |
| 730 | 747 |
| 731 } // namespace tray | 748 } // namespace tray |
| 732 } // namespace ash | 749 } // namespace ash |
| OLD | NEW |