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 "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/app/vector_icons/vector_icons.h" | 10 #include "chrome/app/vector_icons/vector_icons.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 108 |
109 // Spacing between the edge of the material design user menu and the | 109 // Spacing between the edge of the material design user menu and the |
110 // top/bottom or left/right of the menu items. | 110 // top/bottom or left/right of the menu items. |
111 const int kMenuEdgeMargin = 16; | 111 const int kMenuEdgeMargin = 16; |
112 | 112 |
113 const int kVerticalSpacing = 16; | 113 const int kVerticalSpacing = 16; |
114 | 114 |
115 const int kTitleViewNativeWidgetOffset = 8; | 115 const int kTitleViewNativeWidgetOffset = 8; |
116 | 116 |
117 bool IsProfileChooser(profiles::BubbleViewMode mode) { | 117 bool IsProfileChooser(profiles::BubbleViewMode mode) { |
118 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER || | 118 return mode == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER; |
119 mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | |
120 } | 119 } |
121 | 120 |
122 // DEPRECATED: New user menu components should use views::BoxLayout instead. | 121 // DEPRECATED: New user menu components should use views::BoxLayout instead. |
123 // Creates a GridLayout with a single column. This ensures that all the child | 122 // Creates a GridLayout with a single column. This ensures that all the child |
124 // views added get auto-expanded to fill the full width of the bubble. | 123 // views added get auto-expanded to fill the full width of the bubble. |
125 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { | 124 views::GridLayout* CreateSingleColumnLayout(views::View* view, int width) { |
126 views::GridLayout* layout = new views::GridLayout(view); | 125 views::GridLayout* layout = new views::GridLayout(view); |
127 view->SetLayoutManager(layout); | 126 view->SetLayoutManager(layout); |
128 | 127 |
129 views::ColumnSet* columns = layout->AddColumnSet(0); | 128 views::ColumnSet* columns = layout->AddColumnSet(0); |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 | 525 |
527 // static | 526 // static |
528 void ProfileChooserView::ShowBubble( | 527 void ProfileChooserView::ShowBubble( |
529 profiles::BubbleViewMode view_mode, | 528 profiles::BubbleViewMode view_mode, |
530 profiles::TutorialMode tutorial_mode, | 529 profiles::TutorialMode tutorial_mode, |
531 const signin::ManageAccountsParams& manage_accounts_params, | 530 const signin::ManageAccountsParams& manage_accounts_params, |
532 signin_metrics::AccessPoint access_point, | 531 signin_metrics::AccessPoint access_point, |
533 views::View* anchor_view, | 532 views::View* anchor_view, |
534 Browser* browser, | 533 Browser* browser, |
535 bool is_source_keyboard) { | 534 bool is_source_keyboard) { |
536 // Don't start creating the view if it would be an empty fast user switcher. | |
537 // It has to happen here to prevent the view system from creating an empty | |
538 // container. | |
539 // Same for material design user menu since fast profile switcher will be | |
540 // migrated to the left-click menu. | |
541 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) | |
542 return; | |
543 | |
544 if (IsShowing()) { | 535 if (IsShowing()) { |
545 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { | 536 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { |
546 profile_bubble_->tutorial_mode_ = tutorial_mode; | 537 profile_bubble_->tutorial_mode_ = tutorial_mode; |
547 profile_bubble_->ShowViewFromMode(view_mode); | 538 profile_bubble_->ShowViewFromMode(view_mode); |
548 } | 539 } |
549 return; | 540 return; |
550 } | 541 } |
551 | 542 |
552 profile_bubble_ = | 543 profile_bubble_ = |
553 new ProfileChooserView(anchor_view, browser, view_mode, tutorial_mode, | 544 new ProfileChooserView(anchor_view, browser, view_mode, tutorial_mode, |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 sub_view = CreateAccountRemovalView(); | 743 sub_view = CreateAccountRemovalView(); |
753 break; | 744 break; |
754 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: | 745 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: |
755 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); | 746 layout = CreateSingleColumnLayout(this, kFixedSwitchUserViewWidth); |
756 sub_view = CreateSwitchUserView(); | 747 sub_view = CreateSwitchUserView(); |
757 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 748 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
758 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); | 749 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_VIEW); |
759 break; | 750 break; |
760 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: | 751 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: |
761 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: | 752 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: |
762 case profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER: | |
763 layout = CreateSingleColumnLayout(this, kFixedMenuWidth); | 753 layout = CreateSingleColumnLayout(this, kFixedMenuWidth); |
764 sub_view = CreateProfileChooserView(avatar_menu); | 754 sub_view = CreateProfileChooserView(avatar_menu); |
765 break; | 755 break; |
766 } | 756 } |
767 // Clears tutorial mode for all non-profile-chooser views. | 757 // Clears tutorial mode for all non-profile-chooser views. |
768 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) | 758 if (view_mode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) |
769 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; | 759 tutorial_mode_ = profiles::TUTORIAL_MODE_NONE; |
770 | 760 |
771 layout->StartRow(1, 0); | 761 layout->StartRow(1, 0); |
772 layout->AddView(sub_view); | 762 layout->AddView(sub_view); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); | 986 signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); |
997 } | 987 } |
998 } | 988 } |
999 | 989 |
1000 void ProfileChooserView::StyledLabelLinkClicked(views::StyledLabel* label, | 990 void ProfileChooserView::StyledLabelLinkClicked(views::StyledLabel* label, |
1001 const gfx::Range& range, | 991 const gfx::Range& range, |
1002 int event_flags) { | 992 int event_flags) { |
1003 chrome::ShowSettings(browser_); | 993 chrome::ShowSettings(browser_); |
1004 } | 994 } |
1005 | 995 |
1006 void ProfileChooserView::PopulateCompleteProfileChooserView( | 996 views::View* ProfileChooserView::CreateProfileChooserView( |
1007 views::GridLayout* layout, | |
1008 AvatarMenu* avatar_menu) { | 997 AvatarMenu* avatar_menu) { |
| 998 views::View* view = new views::View(); |
| 999 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); |
1009 // Separate items into active and alternatives. | 1000 // Separate items into active and alternatives. |
1010 Indexes other_profiles; | 1001 Indexes other_profiles; |
1011 views::View* tutorial_view = NULL; | 1002 views::View* tutorial_view = NULL; |
1012 views::View* sync_error_view = NULL; | 1003 views::View* sync_error_view = NULL; |
1013 views::View* current_profile_view = NULL; | 1004 views::View* current_profile_view = NULL; |
1014 views::View* current_profile_accounts = NULL; | 1005 views::View* current_profile_accounts = NULL; |
1015 views::View* option_buttons_view = NULL; | 1006 views::View* option_buttons_view = NULL; |
1016 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 1007 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
1017 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 1008 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
1018 if (item.active) { | 1009 if (item.active) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1065 layout->AddView(CreateSupervisedUserDisclaimerView()); | 1056 layout->AddView(CreateSupervisedUserDisclaimerView()); |
1066 } | 1057 } |
1067 | 1058 |
1068 layout->StartRow(0, 0); | 1059 layout->StartRow(0, 0); |
1069 layout->AddView(new views::Separator()); | 1060 layout->AddView(new views::Separator()); |
1070 | 1061 |
1071 if (option_buttons_view) { | 1062 if (option_buttons_view) { |
1072 layout->StartRow(0, 0); | 1063 layout->StartRow(0, 0); |
1073 layout->AddView(option_buttons_view); | 1064 layout->AddView(option_buttons_view); |
1074 } | 1065 } |
1075 } | |
1076 | |
1077 void ProfileChooserView::PopulateMinimalProfileChooserView( | |
1078 views::GridLayout* layout, | |
1079 AvatarMenu* avatar_menu) { | |
1080 Indexes other_profiles; | |
1081 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | |
1082 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | |
1083 if (!item.active) { | |
1084 other_profiles.push_back(i); | |
1085 } | |
1086 } | |
1087 | |
1088 layout->StartRow(1, 0); | |
1089 layout->AddView(CreateOtherProfilesView(other_profiles)); | |
1090 } | |
1091 | |
1092 views::View* ProfileChooserView::CreateProfileChooserView( | |
1093 AvatarMenu* avatar_menu) { | |
1094 views::View* view = new views::View(); | |
1095 views::GridLayout* layout = CreateSingleColumnLayout(view, kFixedMenuWidth); | |
1096 | |
1097 if (view_mode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER) { | |
1098 PopulateMinimalProfileChooserView(layout, avatar_menu); | |
1099 // The user is using right-click switching, no need to tell them about it. | |
1100 PrefService* local_state = g_browser_process->local_state(); | |
1101 local_state->SetBoolean( | |
1102 prefs::kProfileAvatarRightClickTutorialDismissed, true); | |
1103 } else { | |
1104 PopulateCompleteProfileChooserView(layout, avatar_menu); | |
1105 } | |
1106 | |
1107 return view; | 1066 return view; |
1108 } | 1067 } |
1109 | 1068 |
1110 void ProfileChooserView::DismissTutorial() { | 1069 void ProfileChooserView::DismissTutorial() { |
1111 // Never shows the upgrade tutorial again if manually closed. | 1070 // Never shows the upgrade tutorial again if manually closed. |
1112 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1071 if (tutorial_mode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
1113 browser_->profile()->GetPrefs()->SetInteger( | 1072 browser_->profile()->GetPrefs()->SetInteger( |
1114 prefs::kProfileAvatarTutorialShown, | 1073 prefs::kProfileAvatarTutorialShown, |
1115 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | 1074 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
1116 } | 1075 } |
(...skipping 849 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1966 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 1925 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
1967 IncognitoModePrefs::DISABLED; | 1926 IncognitoModePrefs::DISABLED; |
1968 return incognito_available && !browser_->profile()->IsGuestSession(); | 1927 return incognito_available && !browser_->profile()->IsGuestSession(); |
1969 } | 1928 } |
1970 | 1929 |
1971 void ProfileChooserView::PostActionPerformed( | 1930 void ProfileChooserView::PostActionPerformed( |
1972 ProfileMetrics::ProfileDesktopMenu action_performed) { | 1931 ProfileMetrics::ProfileDesktopMenu action_performed) { |
1973 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 1932 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
1974 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 1933 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
1975 } | 1934 } |
OLD | NEW |