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

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: Minor cleanup 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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1081 // Separate items into active and alternatives. 1095 // Separate items into active and alternatives.
1082 Indexes other_profiles; 1096 Indexes other_profiles;
1083 views::View* tutorial_view = NULL; 1097 views::View* tutorial_view = NULL;
1084 views::View* current_profile_view = NULL; 1098 views::View* current_profile_view = NULL;
1085 views::View* current_profile_accounts = NULL; 1099 views::View* current_profile_accounts = NULL;
1086 views::View* option_buttons_view = NULL; 1100 views::View* option_buttons_view = NULL;
1087 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 1101 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1088 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 1102 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1089 if (item.active) { 1103 if (item.active) {
1090 option_buttons_view = CreateOptionsView( 1104 option_buttons_view = CreateOptionsView(
1091 item.signed_in && profiles::IsLockAvailable(browser_->profile())); 1105 item.signed_in && profiles::IsLockAvailable(browser_->profile()),
1106 avatar_menu);
1092 current_profile_view = CreateCurrentProfileView(item, false); 1107 current_profile_view = CreateCurrentProfileView(item, false);
1093 if (IsProfileChooser(view_mode_)) { 1108 if (IsProfileChooser(view_mode_)) {
1094 tutorial_view = CreateTutorialViewIfNeeded(item); 1109 tutorial_view = CreateTutorialViewIfNeeded(item);
1095 } else { 1110 } else {
1096 current_profile_accounts = CreateCurrentProfileAccountsView(item); 1111 current_profile_accounts = CreateCurrentProfileAccountsView(item);
1097 } 1112 }
1098 } else { 1113 } else {
1099 other_profiles.push_back(i); 1114 other_profiles.push_back(i);
1100 } 1115 }
1101 } 1116 }
1102 1117
1103 if (tutorial_view) { 1118 if (tutorial_view) {
1104 // TODO(mlerman): update UMA stats for the new tutorial. 1119 // TODO(mlerman): update UMA stats for the new tutorial.
1105 layout->StartRow(1, 0); 1120 layout->StartRow(1, 0);
1106 layout->AddView(tutorial_view); 1121 layout->AddView(tutorial_view);
1107 } else { 1122 } else {
1108 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; 1123 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE;
1109 } 1124 }
1110 1125
1111 if (!current_profile_view) { 1126 if (!current_profile_view) {
1112 // Guest windows don't have an active profile. 1127 // Guest windows don't have an active profile.
1113 current_profile_view = CreateGuestProfileView(); 1128 current_profile_view = CreateGuestProfileView();
1114 option_buttons_view = CreateOptionsView(false); 1129 option_buttons_view = CreateOptionsView(false, avatar_menu);
1115 } 1130 }
1116 1131
1117 layout->StartRow(1, 0); 1132 layout->StartRow(1, 0);
1118 layout->AddView(current_profile_view); 1133 layout->AddView(current_profile_view);
1119 1134
1120 if (!IsProfileChooser(view_mode_)) { 1135 if (!IsProfileChooser(view_mode_)) {
1121 DCHECK(current_profile_accounts); 1136 DCHECK(current_profile_accounts);
1122 layout->StartRow(0, 0); 1137 layout->StartRow(0, 0);
1123 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1138 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1124 layout->StartRow(1, 0); 1139 layout->StartRow(1, 0);
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1488 1503
1489 layout->StartRow(1, 0); 1504 layout->StartRow(1, 0);
1490 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1505 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1491 layout->StartRow(1, 0); 1506 layout->StartRow(1, 0);
1492 layout->AddView(button); 1507 layout->AddView(button);
1493 } 1508 }
1494 1509
1495 return view; 1510 return view;
1496 } 1511 }
1497 1512
1498 views::View* ProfileChooserView::CreateOptionsView(bool display_lock) { 1513 views::View* ProfileChooserView::CreateOptionsView(
1514 bool display_lock,
1515 AvatarMenu* avatar_menu) {
1499 views::View* view = new views::View(); 1516 views::View* view = new views::View();
1500 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); 1517 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1501 1518
1519 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16;
1520 if (switches::IsMaterialDesignUserMenu()) {
1521 // Add the user switching buttons
1522 const int kProfileIconSize = 18;
1523 layout->StartRowWithPadding(1, 0, 0,
1524 views::kRelatedControlVerticalSpacing);
1525 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
1526 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
1527 if (!item.active) {
1528 gfx::Image item_icon;
1529 AvatarMenu::GetImageForMenuButton(item.profile_path, &item_icon);
1530 gfx::Image image = profiles::GetSizedAvatarIcon(
1531 item_icon, true, kProfileIconSize, kProfileIconSize, true);
Roger Tawa OOO till Jul 10th 2016/06/13 15:20:44 Instead of using true|false for last arg (the new
Jane 2016/06/13 17:53:42 Done.
1532 views::LabelButton* button = new BackgroundColorHoverButton(
1533 this,
1534 profiles::GetProfileSwitcherTextForItem(item),
1535 *image.ToImageSkia());
1536 open_other_profile_indexes_map_[button] = i;
1537
1538 layout->StartRow(1, 0);
1539 layout->AddView(button);
1540 }
1541 }
1542
1543 // Add the "Guest" button for browsing as guest
1544 if (!browser_->profile()->IsGuestSession()) {
1545 guest_profile_button_ = new BackgroundColorHoverButton(
1546 this,
1547 l10n_util::GetStringUTF16(IDS_GUEST_PROFILE_NAME),
1548 gfx::CreateVectorIcon(gfx::VectorIconId::ACCOUNT_CIRCLE,
1549 kIconSize, gfx::kChromeIconGrey));
1550 layout->StartRow(1, 0);
1551 layout->AddView(guest_profile_button_);
1552 }
1553 }
1554
1502 base::string16 text = browser_->profile()->IsGuestSession() ? 1555 base::string16 text = browser_->profile()->IsGuestSession() ?
1503 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) : 1556 l10n_util::GetStringUTF16(IDS_PROFILES_EXIT_GUEST) :
1504 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON); 1557 l10n_util::GetStringUTF16(IDS_PROFILES_SWITCH_USERS_BUTTON);
1558 gfx::VectorIconId settings_icon = gfx::VectorIconId::ACCOUNT_BOX;
1505 if (!browser_->profile()->IsGuestSession() 1559 if (!browser_->profile()->IsGuestSession()
1506 && switches::IsMaterialDesignUserMenu()) { 1560 && switches::IsMaterialDesignUserMenu()) {
1507 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON); 1561 text = l10n_util::GetStringUTF16(IDS_PROFILES_MANAGE_USERS_BUTTON);
1562 settings_icon = gfx::VectorIconId::SETTINGS;
1508 } 1563 }
1509 const int kIconSize = 16;
1510
1511 gfx::VectorIconId settings_icon = switches::IsMaterialDesignUserMenu() ?
1512 gfx::VectorIconId::SETTINGS : gfx::VectorIconId::ACCOUNT_BOX;
1513 users_button_ = new BackgroundColorHoverButton( 1564 users_button_ = new BackgroundColorHoverButton(
1514 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize, 1565 this, text, gfx::CreateVectorIcon(settings_icon, kIconSize,
1515 gfx::kChromeIconGrey)); 1566 gfx::kChromeIconGrey));
1516 1567
1517 layout->StartRow(1, 0); 1568 layout->StartRow(1, 0);
1518 layout->AddView(users_button_); 1569 layout->AddView(users_button_);
1519 1570
1520 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) { 1571 if (!switches::IsMaterialDesignUserMenu() && ShouldShowGoIncognito()) {
1521 layout->StartRow(1, 0); 1572 layout->StartRow(1, 0);
1522 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1573 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1523 1574
1524 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1575 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1525 go_incognito_button_ = new BackgroundColorHoverButton( 1576 go_incognito_button_ = new BackgroundColorHoverButton(
1526 this, 1577 this,
1527 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON), 1578 l10n_util::GetStringUTF16(IDS_PROFILES_GO_INCOGNITO_BUTTON),
1528 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO)); 1579 *rb->GetImageSkiaNamed(IDR_ICON_PROFILES_MENU_INCOGNITO));
1529 layout->StartRow(1, 0); 1580 layout->StartRow(1, 0);
1530 layout->AddView(go_incognito_button_); 1581 layout->AddView(go_incognito_button_);
1531 } 1582 }
1532 1583
1533 if (display_lock) { 1584 if (display_lock) {
1534 layout->StartRow(1, 0); 1585 if (!switches::IsMaterialDesignUserMenu()) {
1535 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 1586 layout->StartRow(1, 0);
1587 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
1588 }
1536 1589
1537 lock_button_ = new BackgroundColorHoverButton( 1590 lock_button_ = new BackgroundColorHoverButton(
1538 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON), 1591 this, l10n_util::GetStringUTF16(IDS_PROFILES_PROFILE_SIGNOUT_BUTTON),
1539 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize, 1592 gfx::CreateVectorIcon(gfx::VectorIconId::LOCK, kIconSize,
1540 gfx::kChromeIconGrey)); 1593 gfx::kChromeIconGrey));
1541 layout->StartRow(1, 0); 1594 layout->StartRow(1, 0);
1542 layout->AddView(lock_button_); 1595 layout->AddView(lock_button_);
1543 } 1596 }
1597
1598 if (switches::IsMaterialDesignUserMenu())
1599 layout->StartRowWithPadding(1, 0, 0,
1600 views::kRelatedControlVerticalSpacing);
Roger Tawa OOO till Jul 10th 2016/06/13 15:20:44 Add { and } when the block of the if statement spa
Jane 2016/06/13 17:53:42 Done.
1544 return view; 1601 return view;
1545 } 1602 }
1546 1603
1547 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() { 1604 views::View* ProfileChooserView::CreateSupervisedUserDisclaimerView() {
1548 views::View* view = new views::View(); 1605 views::View* view = new views::View();
1549 views::GridLayout* layout = CreateSingleColumnLayout( 1606 views::GridLayout* layout = CreateSingleColumnLayout(
1550 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew); 1607 view, kFixedMenuWidth - 2 * views::kButtonHEdgeMarginNew);
1551 layout->SetInsets(views::kRelatedControlVerticalSpacing, 1608 layout->SetInsets(views::kRelatedControlVerticalSpacing,
1552 views::kButtonHEdgeMarginNew, 1609 views::kButtonHEdgeMarginNew,
1553 views::kRelatedControlVerticalSpacing, 1610 views::kRelatedControlVerticalSpacing,
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1894 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1951 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1895 IncognitoModePrefs::DISABLED; 1952 IncognitoModePrefs::DISABLED;
1896 return incognito_available && !browser_->profile()->IsGuestSession(); 1953 return incognito_available && !browser_->profile()->IsGuestSession();
1897 } 1954 }
1898 1955
1899 void ProfileChooserView::PostActionPerformed( 1956 void ProfileChooserView::PostActionPerformed(
1900 ProfileMetrics::ProfileDesktopMenu action_performed) { 1957 ProfileMetrics::ProfileDesktopMenu action_performed) {
1901 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1958 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1902 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1959 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1903 } 1960 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698