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

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

Issue 869793004: Bring up the Fast User Switcher on Shift+Click on the new Avatar Button (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Change to right click and port to Mac UI Created 5 years, 10 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/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/lifetime/application_lifetime.h" 10 #include "chrome/browser/lifetime/application_lifetime.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 const int kFixedMenuWidth = 250; 73 const int kFixedMenuWidth = 250;
74 const int kButtonHeight = 32; 74 const int kButtonHeight = 32;
75 const int kFixedGaiaViewHeight = 440; 75 const int kFixedGaiaViewHeight = 440;
76 const int kFixedGaiaViewWidth = 360; 76 const int kFixedGaiaViewWidth = 360;
77 const int kFixedAccountRemovalViewWidth = 280; 77 const int kFixedAccountRemovalViewWidth = 280;
78 const int kFixedSwitchUserViewWidth = 320; 78 const int kFixedSwitchUserViewWidth = 320;
79 const int kLargeImageSide = 88; 79 const int kLargeImageSide = 88;
80 80
81 const int kVerticalSpacing = 16; 81 const int kVerticalSpacing = 16;
82 82
83 bool IsProfileChooser(profiles::BubbleViewMode mode) {
84 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ||
85 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
Roger Tawa OOO till Jul 10th 2015/01/29 23:00:35 Two more spaces.
anthonyvd 2015/01/30 15:02:20 Done.
86 }
87
83 // Creates a GridLayout with a single column. This ensures that all the child 88 // Creates a GridLayout with a single column. This ensures that all the child
84 // views added get auto-expanded to fill the full width of the bubble. 89 // views added get auto-expanded to fill the full width of the bubble.
85 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { 90 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) {
86 views::GridLayout* layout = new views::GridLayout(view); 91 views::GridLayout* layout = new views::GridLayout(view);
87 view->SetLayoutManager(layout); 92 view->SetLayoutManager(layout);
88 93
89 views::ColumnSet* columns = layout->AddColumnSet(0); 94 views::ColumnSet* columns = layout->AddColumnSet(0);
90 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0, 95 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 0,
91 views::GridLayout::FIXED, width, width); 96 views::GridLayout::FIXED, width, width);
92 return layout; 97 return layout;
(...skipping 486 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 tutorial_close_button_ = NULL; 584 tutorial_close_button_ = NULL;
580 tutorial_sync_settings_link_ = NULL; 585 tutorial_sync_settings_link_ = NULL;
581 tutorial_see_whats_new_button_ = NULL; 586 tutorial_see_whats_new_button_ = NULL;
582 tutorial_not_you_link_ = NULL; 587 tutorial_not_you_link_ = NULL;
583 tutorial_learn_more_link_ = NULL; 588 tutorial_learn_more_link_ = NULL;
584 } 589 }
585 590
586 void ProfileChooserView::Init() { 591 void ProfileChooserView::Init() {
587 // If view mode is PROFILE_CHOOSER but there is an auth error, force 592 // If view mode is PROFILE_CHOOSER but there is an auth error, force
588 // ACCOUNT_MANAGEMENT mode. 593 // ACCOUNT_MANAGEMENT mode.
589 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && 594 if (IsProfileChooser(view_mode_) &&
590 HasAuthError(browser_->profile()) && 595 HasAuthError(browser_->profile()) &&
591 switches::IsEnableAccountConsistency() && 596 switches::IsEnableAccountConsistency() &&
592 avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()). 597 avatar_menu_->GetItemAt(avatar_menu_->GetActiveProfileIndex()).
593 signed_in) { 598 signed_in) {
594 view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT; 599 view_mode_ = profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT;
595 } 600 }
596 601
597 // The arrow keys can be used to tab between items. 602 // The arrow keys can be used to tab between items.
598 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE)); 603 AddAccelerator(ui::Accelerator(ui::VKEY_DOWN, ui::EF_NONE));
599 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE)); 604 AddAccelerator(ui::Accelerator(ui::VKEY_UP, ui::EF_NONE));
600 605
601 ShowView(view_mode_, avatar_menu_.get()); 606 ShowView(view_mode_, avatar_menu_.get());
602 } 607 }
603 608
604 void ProfileChooserView::OnAvatarMenuChanged( 609 void ProfileChooserView::OnAvatarMenuChanged(
605 AvatarMenu* avatar_menu) { 610 AvatarMenu* avatar_menu) {
606 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || 611 if (IsProfileChooser(view_mode_) ||
607 view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 612 view_mode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
608 // Refresh the view with the new menu. We can't just update the local copy 613 // Refresh the view with the new menu. We can't just update the local copy
609 // as this may have been triggered by a sign out action, in which case 614 // as this may have been triggered by a sign out action, in which case
610 // the view is being destroyed. 615 // the view is being destroyed.
611 ShowView(view_mode_, avatar_menu); 616 ShowView(view_mode_, avatar_menu);
612 } 617 }
613 } 618 }
614 619
615 void ProfileChooserView::OnRefreshTokenAvailable( 620 void ProfileChooserView::OnRefreshTokenAvailable(
616 const std::string& account_id) { 621 const std::string& account_id) {
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 return true; 890 return true;
886 891
887 profiles::UpdateProfileName(profile, new_profile_name); 892 profiles::UpdateProfileName(profile, new_profile_name);
888 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME); 893 PostActionPerformed(ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME);
889 current_profile_name_->ShowReadOnlyView(); 894 current_profile_name_->ShowReadOnlyView();
890 return true; 895 return true;
891 } 896 }
892 return false; 897 return false;
893 } 898 }
894 899
895 views::View* ProfileChooserView::CreateProfileChooserView( 900 void ProfileChooserView::PopulateCompleteProfileChooserView(
901 views::GridLayout* layout,
896 AvatarMenu* avatar_menu) { 902 AvatarMenu* avatar_menu) {
897 views::View* view = new views::View();
898 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
899 // Separate items into active and alternatives. 903 // Separate items into active and alternatives.
900 Indexes other_profiles; 904 Indexes other_profiles;
901 views::View* tutorial_view = NULL; 905 views::View* tutorial_view = NULL;
902 views::View* current_profile_view = NULL; 906 views::View* current_profile_view = NULL;
903 views::View* current_profile_accounts = NULL; 907 views::View* current_profile_accounts = NULL;
904 views::View* option_buttons_view = NULL; 908 views::View* option_buttons_view = NULL;
905 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { 909 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
906 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); 910 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
907 if (item.active) { 911 if (item.active) {
908 option_buttons_view = CreateOptionsView( 912 option_buttons_view = CreateOptionsView(
909 item.signed_in && profiles::IsLockAvailable(browser_->profile())); 913 item.signed_in && profiles::IsLockAvailable(browser_->profile()));
910 current_profile_view = CreateCurrentProfileView(item, false); 914 current_profile_view = CreateCurrentProfileView(item, false);
911 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 915 if (IsProfileChooser(view_mode_)) {
912 switch (tutorial_mode_) { 916 switch (tutorial_mode_) {
913 case profiles::TUTORIAL_MODE_NONE: 917 case profiles::TUTORIAL_MODE_NONE:
914 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: 918 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE:
915 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded( 919 tutorial_view = CreateWelcomeUpgradeTutorialViewIfNeeded(
916 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE, 920 tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE,
917 item); 921 item);
918 break; 922 break;
919 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: 923 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN:
920 tutorial_view = CreateSigninConfirmationView(); 924 tutorial_view = CreateSigninConfirmationView();
921 break; 925 break;
(...skipping 19 matching lines...) Expand all
941 945
942 if (!current_profile_view) { 946 if (!current_profile_view) {
943 // Guest windows don't have an active profile. 947 // Guest windows don't have an active profile.
944 current_profile_view = CreateGuestProfileView(); 948 current_profile_view = CreateGuestProfileView();
945 option_buttons_view = CreateOptionsView(false); 949 option_buttons_view = CreateOptionsView(false);
946 } 950 }
947 951
948 layout->StartRow(1, 0); 952 layout->StartRow(1, 0);
949 layout->AddView(current_profile_view); 953 layout->AddView(current_profile_view);
950 954
951 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 955 if (!IsProfileChooser(view_mode_)) {
952 DCHECK(current_profile_accounts); 956 DCHECK(current_profile_accounts);
953 layout->StartRow(0, 0); 957 layout->StartRow(0, 0);
954 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 958 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
955 layout->StartRow(1, 0); 959 layout->StartRow(1, 0);
956 layout->AddView(current_profile_accounts); 960 layout->AddView(current_profile_accounts);
957 } 961 }
958 962
959 if (browser_->profile()->IsSupervised()) { 963 if (browser_->profile()->IsSupervised()) {
960 layout->StartRow(0, 0); 964 layout->StartRow(0, 0);
961 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 965 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
962 layout->StartRow(1, 0); 966 layout->StartRow(1, 0);
963 layout->AddView(CreateSupervisedUserDisclaimerView()); 967 layout->AddView(CreateSupervisedUserDisclaimerView());
964 } 968 }
965 969
966 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 970 if (IsProfileChooser(view_mode_)) {
967 layout->StartRow(1, 0); 971 layout->StartRow(1, 0);
968 if (switches::IsFastUserSwitching()) 972 if (switches::IsFastUserSwitching() ||
973 view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) {
Roger Tawa OOO till Jul 10th 2015/01/29 23:00:35 Do we still need this view_mode_ check?
anthonyvd 2015/01/30 15:02:20 Done.
969 layout->AddView(CreateOtherProfilesView(other_profiles)); 974 layout->AddView(CreateOtherProfilesView(other_profiles));
975 }
970 } 976 }
971 977
972 layout->StartRow(0, 0); 978 layout->StartRow(0, 0);
973 layout->AddView(new views::Separator(views::Separator::HORIZONTAL)); 979 layout->AddView(new views::Separator(views::Separator::HORIZONTAL));
974 980
975 if (option_buttons_view) { 981 if (option_buttons_view) {
976 layout->StartRow(0, 0); 982 layout->StartRow(0, 0);
977 layout->AddView(option_buttons_view); 983 layout->AddView(option_buttons_view);
978 } 984 }
985 }
986
987 void ProfileChooserView::PopulateMinimalProfileChooserView(
988 views::GridLayout* layout,
989 AvatarMenu* avatar_menu) {
990 Indexes other_profiles;
991 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) {
992 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i);
993 if (!item.active) {
994 other_profiles.push_back(i);
995 }
996 }
997
998 layout->StartRow(1, 0);
999 layout->AddView(CreateOtherProfilesView(other_profiles));
1000 }
1001
1002 views::View* ProfileChooserView::CreateProfileChooserView(
1003 AvatarMenu* avatar_menu) {
1004 views::View* view = new views::View();
1005 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth);
1006
1007 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) {
1008 PopulateMinimalProfileChooserView(layout, avatar_menu);
1009 } else {
1010 PopulateCompleteProfileChooserView(layout, avatar_menu);
1011 }
979 1012
980 return view; 1013 return view;
981 } 1014 }
982 1015
983 void ProfileChooserView::DismissTutorial() { 1016 void ProfileChooserView::DismissTutorial() {
984 // Never shows the upgrade tutorial again if manually closed. 1017 // Never shows the upgrade tutorial again if manually closed.
985 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { 1018 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) {
986 browser_->profile()->GetPrefs()->SetInteger( 1019 browser_->profile()->GetPrefs()->SetInteger(
987 prefs::kProfileAvatarTutorialShown, 1020 prefs::kProfileAvatarTutorialShown,
988 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); 1021 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
1156 layout->AddView(current_profile_name_); 1189 layout->AddView(current_profile_name_);
1157 1190
1158 if (is_guest) 1191 if (is_guest)
1159 return view; 1192 return view;
1160 1193
1161 // The available links depend on the type of profile that is active. 1194 // The available links depend on the type of profile that is active.
1162 if (avatar_item.signed_in) { 1195 if (avatar_item.signed_in) {
1163 layout->StartRow(1, 0); 1196 layout->StartRow(1, 0);
1164 if (switches::IsEnableAccountConsistency()) { 1197 if (switches::IsEnableAccountConsistency()) {
1165 base::string16 link_title = l10n_util::GetStringUTF16( 1198 base::string16 link_title = l10n_util::GetStringUTF16(
1166 view_mode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? 1199 IsProfileChooser(view_mode_) ?
1167 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : 1200 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
1168 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 1201 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1169 manage_accounts_link_ = CreateLink(link_title, this); 1202 manage_accounts_link_ = CreateLink(link_title, this);
1170 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER); 1203 manage_accounts_link_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
1171 layout->AddView(manage_accounts_link_); 1204 layout->AddView(manage_accounts_link_);
1172 } else { 1205 } else {
1173 // Badge the email address if there's an authentication error. 1206 // Badge the email address if there's an authentication error.
1174 if (HasAuthError(browser_->profile())) { 1207 if (HasAuthError(browser_->profile())) {
1175 const gfx::ImageSkia warning_image = *rb->GetImageNamed( 1208 const gfx::ImageSkia warning_image = *rb->GetImageNamed(
1176 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia(); 1209 IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia();
(...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1701 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1669 IncognitoModePrefs::DISABLED; 1702 IncognitoModePrefs::DISABLED;
1670 return incognito_available && !browser_->profile()->IsGuestSession(); 1703 return incognito_available && !browser_->profile()->IsGuestSession();
1671 } 1704 }
1672 1705
1673 void ProfileChooserView::PostActionPerformed( 1706 void ProfileChooserView::PostActionPerformed(
1674 ProfileMetrics::ProfileDesktopMenu action_performed) { 1707 ProfileMetrics::ProfileDesktopMenu action_performed) {
1675 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); 1708 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_);
1676 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; 1709 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE;
1677 } 1710 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698