| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ash/common/system/user/button_from_view.h" | 22 #include "ash/common/system/user/button_from_view.h" |
| 23 #include "ash/common/system/user/login_status.h" | 23 #include "ash/common/system/user/login_status.h" |
| 24 #include "ash/common/system/user/rounded_image_view.h" | 24 #include "ash/common/system/user/rounded_image_view.h" |
| 25 #include "ash/common/system/user/user_card_view.h" | 25 #include "ash/common/system/user/user_card_view.h" |
| 26 #include "ash/common/wm_lookup.h" | 26 #include "ash/common/wm_lookup.h" |
| 27 #include "ash/common/wm_root_window_controller.h" | 27 #include "ash/common/wm_root_window_controller.h" |
| 28 #include "ash/common/wm_shell.h" | 28 #include "ash/common/wm_shell.h" |
| 29 #include "ash/common/wm_window.h" | 29 #include "ash/common/wm_window.h" |
| 30 #include "ash/public/cpp/shell_window_ids.h" | 30 #include "ash/public/cpp/shell_window_ids.h" |
| 31 #include "ash/resources/vector_icons/vector_icons.h" | 31 #include "ash/resources/vector_icons/vector_icons.h" |
| 32 #include "base/optional.h" | |
| 33 #include "components/signin/core/account_id/account_id.h" | 32 #include "components/signin/core/account_id/account_id.h" |
| 34 #include "components/user_manager/user_info.h" | 33 #include "components/user_manager/user_info.h" |
| 35 #include "grit/ash_resources.h" | 34 #include "grit/ash_resources.h" |
| 36 #include "grit/ash_strings.h" | 35 #include "grit/ash_strings.h" |
| 37 #include "ui/base/l10n/l10n_util.h" | 36 #include "ui/base/l10n/l10n_util.h" |
| 38 #include "ui/base/resource/resource_bundle.h" | 37 #include "ui/base/resource/resource_bundle.h" |
| 39 #include "ui/gfx/canvas.h" | 38 #include "ui/gfx/canvas.h" |
| 40 #include "ui/gfx/geometry/insets.h" | 39 #include "ui/gfx/geometry/insets.h" |
| 41 #include "ui/gfx/paint_vector_icon.h" | 40 #include "ui/gfx/paint_vector_icon.h" |
| 42 #include "ui/views/controls/button/label_button.h" | 41 #include "ui/views/controls/button/label_button.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); | 97 MultiProfileUMA::SWITCH_ACTIVE_USER_BY_TRAY); |
| 99 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); | 98 delegate->SwitchActiveUser(delegate->GetUserInfo(user_index)->GetAccountId()); |
| 100 } | 99 } |
| 101 | 100 |
| 102 bool IsMultiProfileSupportedAndUserActive() { | 101 bool IsMultiProfileSupportedAndUserActive() { |
| 103 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && | 102 return WmShell::Get()->delegate()->IsMultiProfilesEnabled() && |
| 104 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); | 103 !WmShell::Get()->GetSessionStateDelegate()->IsUserSessionBlocked(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). | 106 // Creates the view shown in the user switcher popup ("AddUserMenuOption"). |
| 108 views::View* CreateAddUserView( | 107 views::View* CreateAddUserView(AddUserSessionPolicy policy) { |
| 109 base::Optional<SessionStateDelegate::AddUserError> error) { | |
| 110 DCHECK(UseMd()); | 108 DCHECK(UseMd()); |
| 111 auto view = new views::View; | 109 auto view = new views::View; |
| 112 auto layout = new views::BoxLayout( | 110 auto layout = new views::BoxLayout( |
| 113 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2, | 111 views::BoxLayout::kHorizontal, (kMenuButtonSize - kMenuIconSize) / 2, |
| 114 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems); | 112 kMenuSeparatorVerticalPadding, kTrayPopupPaddingBetweenItems); |
| 115 layout->set_minimum_cross_axis_size( | 113 layout->set_minimum_cross_axis_size( |
| 116 error ? 56 : GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT)); | 114 policy == AddUserSessionPolicy::ALLOWED |
| 115 ? GetTrayConstant(TRAY_POPUP_ITEM_MIN_HEIGHT) |
| 116 : 56); |
| 117 view->SetLayoutManager(layout); | 117 view->SetLayoutManager(layout); |
| 118 view->set_background( | 118 view->set_background( |
| 119 views::Background::CreateSolidBackground(kBackgroundColor)); | 119 views::Background::CreateSolidBackground(kBackgroundColor)); |
| 120 | 120 |
| 121 if (!error) { | 121 int message_id = 0; |
| 122 auto icon = new views::ImageView(); | 122 switch (policy) { |
| 123 icon->SetImage( | 123 case AddUserSessionPolicy::ALLOWED: { |
| 124 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); | 124 message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; |
| 125 view->AddChildView(icon); | |
| 126 } | |
| 127 | 125 |
| 128 int message_id = IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT; | 126 auto icon = new views::ImageView(); |
| 129 if (error) { | 127 icon->SetImage( |
| 130 switch (*error) { | 128 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); |
| 131 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER: | 129 view->AddChildView(icon); |
| 132 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; | 130 break; |
| 133 break; | |
| 134 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED: | |
| 135 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; | |
| 136 break; | |
| 137 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS: | |
| 138 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; | |
| 139 break; | |
| 140 } | 131 } |
| 132 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER: |
| 133 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; |
| 134 break; |
| 135 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED: |
| 136 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; |
| 137 break; |
| 138 case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS: |
| 139 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; |
| 140 break; |
| 141 } | 141 } |
| 142 | 142 |
| 143 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id)); | 143 auto command_label = new views::Label(l10n_util::GetStringUTF16(message_id)); |
| 144 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 144 command_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 145 command_label->SetMultiLine(true); | 145 command_label->SetMultiLine(true); |
| 146 view->AddChildView(command_label); | 146 view->AddChildView(command_label); |
| 147 return view; | 147 return view; |
| 148 } | 148 } |
| 149 | 149 |
| 150 class UserViewMouseWatcherHost : public views::MouseWatcherHost { | 150 class UserViewMouseWatcherHost : public views::MouseWatcherHost { |
| (...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 WmLookup::Get() | 597 WmLookup::Get() |
| 598 ->GetWindowForWidget(GetWidget()) | 598 ->GetWindowForWidget(GetWidget()) |
| 599 ->GetRootWindowController() | 599 ->GetRootWindowController() |
| 600 ->ConfigureWidgetInitParamsForContainer( | 600 ->ConfigureWidgetInitParamsForContainer( |
| 601 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, | 601 add_menu_option_.get(), kShellWindowId_DragImageAndTooltipContainer, |
| 602 ¶ms); | 602 ¶ms); |
| 603 add_menu_option_->Init(params); | 603 add_menu_option_->Init(params); |
| 604 | 604 |
| 605 const SessionStateDelegate* delegate = | 605 const SessionStateDelegate* delegate = |
| 606 WmShell::Get()->GetSessionStateDelegate(); | 606 WmShell::Get()->GetSessionStateDelegate(); |
| 607 SessionStateDelegate::AddUserError add_user_error; | 607 const AddUserSessionPolicy add_user_policy = |
| 608 add_user_enabled_ = delegate->CanAddUserToMultiProfile(&add_user_error); | 608 delegate->GetAddUserSessionPolicy(); |
| 609 add_user_enabled_ = add_user_policy == AddUserSessionPolicy::ALLOWED; |
| 609 | 610 |
| 610 if (UseMd()) { | 611 if (UseMd()) { |
| 611 base::Optional<SessionStateDelegate::AddUserError> error; | |
| 612 if (!add_user_enabled_) | |
| 613 error = add_user_error; | |
| 614 ButtonFromView* button = new ButtonFromView( | 612 ButtonFromView* button = new ButtonFromView( |
| 615 CreateAddUserView(error), add_user_enabled_ ? this : nullptr, | 613 CreateAddUserView(add_user_policy), add_user_enabled_ ? this : nullptr, |
| 616 IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS | 614 IsActiveUser() ? TrayPopupInkDropStyle::INSET_BOUNDS |
| 617 : TrayPopupInkDropStyle::FILL_BOUNDS, | 615 : TrayPopupInkDropStyle::FILL_BOUNDS, |
| 618 false, gfx::Insets()); | 616 false, gfx::Insets()); |
| 619 button->SetAccessibleName( | 617 button->SetAccessibleName( |
| 620 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); | 618 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SIGN_IN_ANOTHER_ACCOUNT)); |
| 621 button->ForceBorderVisible(true); | 619 button->ForceBorderVisible(true); |
| 622 | 620 |
| 623 // Position the widget on top of the user card view (which is still in the | 621 // Position the widget on top of the user card view (which is still in the |
| 624 // system menu). The top half of the widget will be transparent to allow | 622 // system menu). The top half of the widget will be transparent to allow |
| 625 // the active user to show through. | 623 // the active user to show through. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 | 671 |
| 674 if (add_user_enabled_) { | 672 if (add_user_enabled_) { |
| 675 // We activate the entry automatically if invoked with focus. | 673 // We activate the entry automatically if invoked with focus. |
| 676 if (user_card_view_->HasFocus()) { | 674 if (user_card_view_->HasFocus()) { |
| 677 button->GetFocusManager()->SetFocusedView(button); | 675 button->GetFocusManager()->SetFocusedView(button); |
| 678 user_card_view_->GetFocusManager()->SetFocusedView(button); | 676 user_card_view_->GetFocusManager()->SetFocusedView(button); |
| 679 } | 677 } |
| 680 } else { | 678 } else { |
| 681 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 679 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 682 int message_id = 0; | 680 int message_id = 0; |
| 683 switch (add_user_error) { | 681 switch (add_user_policy) { |
| 684 case SessionStateDelegate::ADD_USER_ERROR_NOT_ALLOWED_PRIMARY_USER: | 682 case AddUserSessionPolicy::ERROR_NOT_ALLOWED_PRIMARY_USER: |
| 685 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; | 683 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_NOT_ALLOWED_PRIMARY_USER; |
| 686 break; | 684 break; |
| 687 case SessionStateDelegate::ADD_USER_ERROR_MAXIMUM_USERS_REACHED: | 685 case AddUserSessionPolicy::ERROR_MAXIMUM_USERS_REACHED: |
| 688 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; | 686 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_CANNOT_ADD_USER; |
| 689 break; | 687 break; |
| 690 case SessionStateDelegate::ADD_USER_ERROR_OUT_OF_USERS: | 688 case AddUserSessionPolicy::ERROR_NO_ELIGIBLE_USERS: |
| 691 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; | 689 message_id = IDS_ASH_STATUS_TRAY_MESSAGE_OUT_OF_USERS; |
| 692 break; | 690 break; |
| 693 default: | 691 default: |
| 694 NOTREACHED() << "Unknown adding user error " << add_user_error; | 692 NOTREACHED() << "Unknown adding user policy " |
| 693 << static_cast<int>(add_user_policy); |
| 695 } | 694 } |
| 696 | 695 |
| 697 popup_message_.reset(new PopupMessage( | 696 popup_message_.reset(new PopupMessage( |
| 698 bundle.GetLocalizedString( | 697 bundle.GetLocalizedString( |
| 699 IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), | 698 IDS_ASH_STATUS_TRAY_CAPTION_CANNOT_ADD_USER), |
| 700 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING, | 699 bundle.GetLocalizedString(message_id), PopupMessage::ICON_WARNING, |
| 701 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT, | 700 add_user_view->anchor(), views::BubbleBorder::TOP_LEFT, |
| 702 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), | 701 gfx::Size(parent()->bounds().width() - kPopupMessageOffset, 0), |
| 703 2 * kPopupMessageOffset)); | 702 2 * kPopupMessageOffset)); |
| 704 } | 703 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 724 focus_manager_ = nullptr; | 723 focus_manager_ = nullptr; |
| 725 if (user_card_view_->GetFocusManager()) | 724 if (user_card_view_->GetFocusManager()) |
| 726 user_card_view_->GetFocusManager()->ClearFocus(); | 725 user_card_view_->GetFocusManager()->ClearFocus(); |
| 727 popup_message_.reset(); | 726 popup_message_.reset(); |
| 728 mouse_watcher_.reset(); | 727 mouse_watcher_.reset(); |
| 729 add_menu_option_.reset(); | 728 add_menu_option_.reset(); |
| 730 } | 729 } |
| 731 | 730 |
| 732 } // namespace tray | 731 } // namespace tray |
| 733 } // namespace ash | 732 } // namespace ash |
| OLD | NEW |