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

Side by Side Diff: chrome/browser/ui/views/profiles/profile_chooser_view.cc

Issue 2057203002: Bringing back fast user switching on desktop user menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DCHECK and comment Created 4 years, 6 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
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 "chrome/browser/ui/views/profiles/profile_chooser_view.h" 5 #include "chrome/browser/ui/views/profiles/profile_chooser_view.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/metrics/user_metrics.h" 8 #include "base/metrics/user_metrics.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 void ProfileChooserView::ShowBubble( 623 void ProfileChooserView::ShowBubble(
624 profiles::BubbleViewMode view_mode, 624 profiles::BubbleViewMode view_mode,
625 profiles::TutorialMode tutorial_mode, 625 profiles::TutorialMode tutorial_mode,
626 const signin::ManageAccountsParams& manage_accounts_params, 626 const signin::ManageAccountsParams& manage_accounts_params,
627 signin_metrics::AccessPoint access_point, 627 signin_metrics::AccessPoint access_point,
628 views::View* anchor_view, 628 views::View* anchor_view,
629 Browser* browser) { 629 Browser* browser) {
630 // Don't start creating the view if it would be an empty fast user switcher. 630 // Don't start creating the view if it would be an empty fast user switcher.
631 // It has to happen here to prevent the view system from creating an empty 631 // It has to happen here to prevent the view system from creating an empty
632 // container. 632 // container.
633 // Same for material design user menu since fast profile switcher will be
634 // migrated to the left-click menu.
633 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && 635 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER &&
634 !profiles::HasProfileSwitchTargets(browser->profile())) { 636 (!profiles::HasProfileSwitchTargets(browser->profile()) ||
637 switches::IsMaterialDesignUserMenu())) {
635 return; 638 return;
636 } 639 }
637 640
638 if (IsShowing()) { 641 if (IsShowing()) {
639 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { 642 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) {
640 profile_bubble_->tutorial_mode_ = tutorial_mode; 643 profile_bubble_->tutorial_mode_ = tutorial_mode;
641 profile_bubble_->ShowViewFromMode(view_mode); 644 profile_bubble_->ShowViewFromMode(view_mode);
642 } 645 }
643 return; 646 return;
644 } 647 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 694
692 void ProfileChooserView::ResetView() { 695 void ProfileChooserView::ResetView() {
693 open_other_profile_indexes_map_.clear(); 696 open_other_profile_indexes_map_.clear();
694 delete_account_button_map_.clear(); 697 delete_account_button_map_.clear();
695 reauth_account_button_map_.clear(); 698 reauth_account_button_map_.clear();
696 manage_accounts_link_ = NULL; 699 manage_accounts_link_ = NULL;
697 signin_current_profile_link_ = NULL; 700 signin_current_profile_link_ = NULL;
698 auth_error_email_button_ = NULL; 701 auth_error_email_button_ = NULL;
699 current_profile_photo_ = NULL; 702 current_profile_photo_ = NULL;
700 current_profile_name_ = NULL; 703 current_profile_name_ = NULL;
704 guest_profile_button_ = NULL;
701 users_button_ = NULL; 705 users_button_ = NULL;
702 go_incognito_button_ = NULL; 706 go_incognito_button_ = NULL;
703 lock_button_ = NULL; 707 lock_button_ = NULL;
704 add_account_link_ = NULL; 708 add_account_link_ = NULL;
705 gaia_signin_cancel_button_ = NULL; 709 gaia_signin_cancel_button_ = NULL;
706 remove_account_button_ = NULL; 710 remove_account_button_ = NULL;
707 account_removal_cancel_button_ = NULL; 711 account_removal_cancel_button_ = NULL;
708 add_person_button_ = NULL; 712 add_person_button_ = NULL;
709 disconnect_button_ = NULL; 713 disconnect_button_ = NULL;
710 switch_user_cancel_button_ = NULL; 714 switch_user_cancel_button_ = NULL;
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 899
896 bool ProfileChooserView::HandleContextMenu( 900 bool ProfileChooserView::HandleContextMenu(
897 const content::ContextMenuParams& params) { 901 const content::ContextMenuParams& params) {
898 // Suppresses the context menu because some features, such as inspecting 902 // Suppresses the context menu because some features, such as inspecting
899 // elements, are not appropriate in a bubble. 903 // elements, are not appropriate in a bubble.
900 return true; 904 return true;
901 } 905 }
902 906
903 void ProfileChooserView::ButtonPressed(views::Button* sender, 907 void ProfileChooserView::ButtonPressed(views::Button* sender,
904 const ui::Event& event) { 908 const ui::Event& event) {
905 if (sender == users_button_) { 909 if (sender == guest_profile_button_) {
910 PrefService* service = g_browser_process->local_state();
911 DCHECK(service);
912 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) {
913 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
914 } else {
915 // The UI should have prevented the user from allowing the selection of
916 // guest mode.
917 NOTREACHED();
918 }
919 } else if (sender == users_button_) {
906 // If this is a guest session, close all the guest browser windows. 920 // If this is a guest session, close all the guest browser windows.
907 if (browser_->profile()->IsGuestSession()) { 921 if (browser_->profile()->IsGuestSession()) {
908 profiles::CloseGuestProfileWindows(); 922 profiles::CloseGuestProfileWindows();
909 } else { 923 } else {
910 UserManager::Show(base::FilePath(), 924 UserManager::Show(base::FilePath(),
911 profiles::USER_MANAGER_NO_TUTORIAL, 925 profiles::USER_MANAGER_NO_TUTORIAL,
912 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 926 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
913 } 927 }
914 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER); 928 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER);
915 } else if (sender == go_incognito_button_) { 929 } else if (sender == go_incognito_button_) {
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1084 // Separate items into active and alternatives. 1098 // Separate items into active and alternatives.
1085 Indexes other_profiles; 1099 Indexes other_profiles;
1086 views::View* tutorial_view = NULL; 1100 views::View* tutorial_view = NULL;
1087 views::View* current_profile_view = NULL; 1101 views::View* current_profile_view = NULL;
1088 views::View* current_profile_accounts = NULL; 1102 views::View* current_profile_accounts = NULL;
1089 views::View* option_buttons_view = NULL; 1103 views::View* option_buttons_view = NULL;
1090 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 1104 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1091 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 1105 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1092 if (item.active) { 1106 if (item.active) {
1093 option_buttons_view = CreateOptionsView( 1107 option_buttons_view = CreateOptionsView(
1094 item.signed_in && profiles::IsLockAvailable(browser_->profile())); 1108 item.signed_in && profiles::IsLockAvailable(browser_->profile()),
1109 avatar_menu);
1095 current_profile_view = CreateCurrentProfileView(item, false); 1110 current_profile_view = CreateCurrentProfileView(item, false);
1096 if (IsProfileChooser(view_mode_)) { 1111 if (IsProfileChooser(view_mode_)) {
1097 tutorial_view = CreateTutorialViewIfNeeded(item); 1112 tutorial_view = CreateTutorialViewIfNeeded(item);
1098 } else { 1113 } else {
1099 current_profile_accounts = CreateCurrentProfileAccountsView(item); 1114 current_profile_accounts = CreateCurrentProfileAccountsView(item);
1100 } 1115 }
1101 } else { 1116 } else {
1102 other_profiles.push_back(i); 1117 other_profiles.push_back(i);
1103 } 1118 }
1104 } 1119 }
1105 1120
1106 if (tutorial_view) { 1121 if (tutorial_view) {
1107 // TODO(mlerman): update UMA stats for the new tutorial. 1122 // TODO(mlerman): update UMA stats for the new tutorial.
1108 layout->StartRow(1, 0); 1123 layout->StartRow(1, 0);
1109 layout->AddView(tutorial_view); 1124 layout->AddView(tutorial_view);
1110 } else { 1125 } else {
1111 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 1126 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
1112 } 1127 }
1113 1128
1114 if (!current_profile_view) { 1129 if (!current_profile_view) {
1115 // Guest windows don't have an active profile. 1130 // Guest windows don't have an active profile.
1116 current_profile_view = CreateGuestProfileView(); 1131 current_profile_view = CreateGuestProfileView();
1117 option_buttons_view = CreateOptionsView(false); 1132 option_buttons_view = CreateOptionsView(false, avatar_menu);
1118 } 1133 }
1119 1134
1120 layout->StartRow(1, 0); 1135 layout->StartRow(1, 0);
1121 layout->AddView(current_profile_view); 1136 layout->AddView(current_profile_view);
1122 1137
1123 if (!IsProfileChooser(view_mode_)) { 1138 if (!IsProfileChooser(view_mode_)) {
1124 DCHECK(current_profile_accounts); 1139 DCHECK(current_profile_accounts);
1125 layout->StartRow(0, 0); 1140 layout->StartRow(0, 0);
1126 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1141 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1127 layout->StartRow(1, 0); 1142 layout->StartRow(1, 0);
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 1506
1492 layout->StartRow(1, 0); 1507 layout->StartRow(1, 0);
1493 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1508 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1494 layout->StartRow(1, 0); 1509 layout->StartRow(1, 0);
1495 layout->AddView(button); 1510 layout->AddView(button);
1496 } 1511 }
1497 1512
1498 return view; 1513 return view;
1499 } 1514 }
1500 1515
1501 views::View* ProfileChooserView::CreateOptionsView(bool display_lock) { 1516 views::View* ProfileChooserView::CreateOptionsView(
1517 bool display_lock,
1518 AvatarMenu* avatar_menu) {
1502 views::View* view = new views::View(); 1519 views::View* view = new views::View();
1503 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1520 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1504 1521
1522 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16;
1523 if (switches::IsMaterialDesignUserMenu()) {
1524 // Add the user switching buttons
1525 const int kProfileIconSize = 18;
1526 layout->StartRowWithPadding(1, 0, 0,
1527 views::kRelatedControlVerticalSpacing);
1528 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1529 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1530 if (!item.active) {
1531 gfx::Image image = profiles::GetSizedAvatarIcon(
1532 item.icon, true, kProfileIconSize, kProfileIconSize,
1533 profiles::SHAPE_CIRCLE);
1534 views::LabelButton* button = new BackgroundColorHoverButton(
1535 this,
1536 profiles::GetProfileSwitcherTextForItem(item),
1537 *image.ToImageSkia());
1538 open_other_profile_indexes_map_[button] = i;
1539
1540 layout->StartRow(1, 0);
1541 layout->AddView(button);
1542 }
1543 }
1544
1545 // Add the "Guest" button for browsing as guest
1546 if (!browser_->profile()->IsGuestSession()) {
1547 PrefService* service = g_browser_process->local_state();
1548 DCHECK(service);
1549 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) {
1550 guest_profile_button_ = new BackgroundColorHoverButton(
1551 this,
1552 l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME),
1553 gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_CIRCLE,
1554 kIconSize, gfx::kChromeIconGrey));
1555 layout->StartRow(1, 0);
1556 layout->AddView(guest_profile_button_);
1557 }
1558 }
1559 }
1560
1505 base::string16 text = browser_->profile()->IsGuestSession() ? 1561 base::string16 text = browser_->profile()->IsGuestSession() ?
1506 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : 1562 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) :
1507 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); 1563 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON);
1564 gfx::VectorIconId settings_icon = gfx::VectorIconId::ACCOUNT_BOX;
1508 if (!browser_->profile()->IsGuestSession() 1565 if (!browser_->profile()->IsGuestSession()
1509 && switches::IsMaterialDesignUserMenu()) { 1566 && switches::IsMaterialDesignUserMenu()) {
1510 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); 1567 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON);
1568 settings_icon = gfx::VectorIconId::SETTINGS;
1511 } 1569 }
1512 const int kIconSize = 16;
1513
1514 gfx::VectorIconId settings_icon = switches::IsMaterialDesignUserMenu() ?
1515 gfx::VectorIconId::SETTINGS : gfx::VectorIconId::ACCOUNT_BOX;
1516 users_button_ = new BackgroundColorHoverButton( 1570 users_button_ = new BackgroundColorHoverButton(
1517 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize, 1571 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize,
1518 gfx::kChromeIconGrey)); 1572 gfx::kChromeIconGrey));
1519 1573
1520 layout->StartRow(1, 0); 1574 layout->StartRow(1, 0);
1521 layout->AddView(users_button_); 1575 layout->AddView(users_button_);
1522 1576
1523 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) { 1577 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) {
1524 layout->StartRow(1, 0); 1578 layout->StartRow(1, 0);
1525 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1579 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1526 1580
1527 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1581 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1528 go_incognito_button_ = new BackgroundColorHoverButton( 1582 go_incognito_button_ = new BackgroundColorHoverButton(
1529 this, 1583 this,
1530 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON), 1584 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON),
1531 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO)); 1585 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO));
1532 layout->StartRow(1, 0); 1586 layout->StartRow(1, 0);
1533 layout->AddView(go_incognito_button_); 1587 layout->AddView(go_incognito_button_);
1534 } 1588 }
1535 1589
1536 if (display_lock) { 1590 if (display_lock) {
1537 layout->StartRow(1, 0); 1591 if (!switches::IsMaterialDesignUserMenu()) {
1538 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1592 layout->StartRow(1, 0);
1593 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1594 }
1539 1595
1540 lock_button_ = new BackgroundColorHoverButton( 1596 lock_button_ = new BackgroundColorHoverButton(
1541 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), 1597 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON),
1542 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, 1598 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize,
1543 gfx::kChromeIconGrey)); 1599 gfx::kChromeIconGrey));
1544 layout->StartRow(1, 0); 1600 layout->StartRow(1, 0);
1545 layout->AddView(lock_button_); 1601 layout->AddView(lock_button_);
1546 } 1602 }
1603
1604 if (switches::IsMaterialDesignUserMenu()) {
1605 layout->StartRowWithPadding(1, 0, 0,
1606 views::kRelatedControlVerticalSpacing);
1607 }
1547 return view; 1608 return view;
1548 } 1609 }
1549 1610
1550 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { 1611 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
1551 views::View* view = new views::View(); 1612 views::View* view = new views::View();
1552 views::GridLayout* layout = CreateSingleColumnLayout( 1613 views::GridLayout* layout = CreateSingleColumnLayout(
1553 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 1614 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew);
1554 layout->SetInsets(views::kRelatedControlVerticalSpacing, 1615 layout->SetInsets(views::kRelatedControlVerticalSpacing,
1555 views::kButtonHEdgeMarginNew, 1616 views::kButtonHEdgeMarginNew,
1556 views::kRelatedControlVerticalSpacing, 1617 views::kRelatedControlVerticalSpacing,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1897 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1958 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1898 IncognitoModePrefs::DISABLED; 1959 IncognitoModePrefs::DISABLED;
1899 return incognito_available && !browser_->profile()->IsGuestSession(); 1960 return incognito_available && !browser_->profile()->IsGuestSession();
1900 } 1961 }
1901 1962
1902 void ProfileChooserView::PostActionPerformed( 1963 void ProfileChooserView::PostActionPerformed(
1903 ProfileMetrics::ProfileDesktopMenu action_performed) { 1964 ProfileMetrics::ProfileDesktopMenu action_performed) {
1904 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1965 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1905 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1966 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1906 } 1967 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698