Chromium Code Reviews| 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/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 737 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; | 737 ProfileChooserView* ProfileChooserView::profile_bubble_ = nullptr; |
| 738 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; | 738 bool ProfileChooserView::close_on_deactivate_for_testing_ = true; |
| 739 | 739 |
| 740 // static | 740 // static |
| 741 void ProfileChooserView::ShowBubble( | 741 void ProfileChooserView::ShowBubble( |
| 742 profiles::BubbleViewMode view_mode, | 742 profiles::BubbleViewMode view_mode, |
| 743 profiles::TutorialMode tutorial_mode, | 743 profiles::TutorialMode tutorial_mode, |
| 744 const signin::ManageAccountsParams& manage_accounts_params, | 744 const signin::ManageAccountsParams& manage_accounts_params, |
| 745 signin_metrics::AccessPoint access_point, | 745 signin_metrics::AccessPoint access_point, |
| 746 views::View* anchor_view, | 746 views::View* anchor_view, |
| 747 Browser* browser) { | 747 Browser* browser, |
| 748 bool focus_first_profile_button) { | |
| 748 // Don't start creating the view if it would be an empty fast user switcher. | 749 // Don't start creating the view if it would be an empty fast user switcher. |
| 749 // It has to happen here to prevent the view system from creating an empty | 750 // It has to happen here to prevent the view system from creating an empty |
| 750 // container. | 751 // container. |
| 751 // Same for material design user menu since fast profile switcher will be | 752 // Same for material design user menu since fast profile switcher will be |
| 752 // migrated to the left-click menu. | 753 // migrated to the left-click menu. |
| 753 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && | 754 if (view_mode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && |
| 754 (!profiles::HasProfileSwitchTargets(browser->profile()) || | 755 (!profiles::HasProfileSwitchTargets(browser->profile()) || |
| 755 switches::IsMaterialDesignUserMenu())) { | 756 switches::IsMaterialDesignUserMenu())) { |
| 756 return; | 757 return; |
| 757 } | 758 } |
| 758 | 759 |
| 759 if (IsShowing()) { | 760 if (IsShowing()) { |
| 760 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { | 761 if (tutorial_mode != profiles::TUTORIAL_MODE_NONE) { |
| 761 profile_bubble_->tutorial_mode_ = tutorial_mode; | 762 profile_bubble_->tutorial_mode_ = tutorial_mode; |
| 762 profile_bubble_->ShowViewFromMode(view_mode); | 763 profile_bubble_->ShowViewFromMode(view_mode); |
| 763 } | 764 } |
| 764 return; | 765 return; |
| 765 } | 766 } |
| 766 | 767 |
| 767 profile_bubble_ = | 768 profile_bubble_ = |
| 768 new ProfileChooserView(anchor_view, browser, view_mode, tutorial_mode, | 769 new ProfileChooserView(anchor_view, browser, view_mode, tutorial_mode, |
| 769 manage_accounts_params.service_type, access_point); | 770 manage_accounts_params.service_type, access_point); |
| 770 views::Widget* widget = | 771 views::Widget* widget = |
| 771 views::BubbleDialogDelegateView::CreateBubble(profile_bubble_); | 772 views::BubbleDialogDelegateView::CreateBubble(profile_bubble_); |
| 772 profile_bubble_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 773 profile_bubble_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 773 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); | 774 profile_bubble_->SetArrowPaintType(views::BubbleBorder::PAINT_NONE); |
| 774 widget->Show(); | 775 widget->Show(); |
| 776 if (focus_first_profile_button) { | |
|
sky
2017/02/09 20:17:39
no {}
sky
2017/02/09 20:17:39
It seems unnecessary to store this view. Can't you
jlebel
2017/02/10 12:13:43
There are different buttons in this menu. The begi
| |
| 777 profile_bubble_->FocusFirstProfileButton(); | |
| 778 } | |
| 775 } | 779 } |
| 776 | 780 |
| 777 // static | 781 // static |
| 778 bool ProfileChooserView::IsShowing() { | 782 bool ProfileChooserView::IsShowing() { |
| 779 return profile_bubble_ != NULL; | 783 return profile_bubble_ != NULL; |
| 780 } | 784 } |
| 781 | 785 |
| 782 // static | 786 // static |
| 783 void ProfileChooserView::Hide() { | 787 void ProfileChooserView::Hide() { |
| 784 if (IsShowing()) | 788 if (IsShowing()) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 825 sync_error_upgrade_button_ = nullptr; | 829 sync_error_upgrade_button_ = nullptr; |
| 826 sync_error_signin_again_button_ = nullptr; | 830 sync_error_signin_again_button_ = nullptr; |
| 827 sync_error_signout_button_ = nullptr; | 831 sync_error_signout_button_ = nullptr; |
| 828 manage_accounts_link_ = nullptr; | 832 manage_accounts_link_ = nullptr; |
| 829 manage_accounts_button_ = nullptr; | 833 manage_accounts_button_ = nullptr; |
| 830 signin_current_profile_button_ = nullptr; | 834 signin_current_profile_button_ = nullptr; |
| 831 auth_error_email_button_ = nullptr; | 835 auth_error_email_button_ = nullptr; |
| 832 current_profile_photo_ = nullptr; | 836 current_profile_photo_ = nullptr; |
| 833 current_profile_name_ = nullptr; | 837 current_profile_name_ = nullptr; |
| 834 current_profile_card_ = nullptr; | 838 current_profile_card_ = nullptr; |
| 839 first_profile_button_ = nullptr; | |
| 835 guest_profile_button_ = nullptr; | 840 guest_profile_button_ = nullptr; |
| 836 users_button_ = nullptr; | 841 users_button_ = nullptr; |
| 837 go_incognito_button_ = nullptr; | 842 go_incognito_button_ = nullptr; |
| 838 lock_button_ = nullptr; | 843 lock_button_ = nullptr; |
| 839 close_all_windows_button_ = nullptr; | 844 close_all_windows_button_ = nullptr; |
| 840 add_account_link_ = nullptr; | 845 add_account_link_ = nullptr; |
| 841 gaia_signin_cancel_button_ = nullptr; | 846 gaia_signin_cancel_button_ = nullptr; |
| 842 remove_account_button_ = nullptr; | 847 remove_account_button_ = nullptr; |
| 843 account_removal_cancel_button_ = nullptr; | 848 account_removal_cancel_button_ = nullptr; |
| 844 add_person_button_ = nullptr; | 849 add_person_button_ = nullptr; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 // Hides the user menu if it is currently shown. The user menu automatically | 1001 // Hides the user menu if it is currently shown. The user menu automatically |
| 997 // closes when it loses focus; however, on Windows, the signin modals do not | 1002 // closes when it loses focus; however, on Windows, the signin modals do not |
| 998 // take away focus, thus we need to manually close the bubble. | 1003 // take away focus, thus we need to manually close the bubble. |
| 999 Hide(); | 1004 Hide(); |
| 1000 browser_->ShowModalSigninWindow(mode, access_point_); | 1005 browser_->ShowModalSigninWindow(mode, access_point_); |
| 1001 } else { | 1006 } else { |
| 1002 ShowView(mode, avatar_menu_.get()); | 1007 ShowView(mode, avatar_menu_.get()); |
| 1003 } | 1008 } |
| 1004 } | 1009 } |
| 1005 | 1010 |
| 1011 void ProfileChooserView::FocusFirstProfileButton() { | |
| 1012 if (first_profile_button_) { | |
|
sky
2017/02/09 20:17:39
no {}
jlebel
2017/02/10 12:13:43
Done.
| |
| 1013 first_profile_button_->RequestFocus(); | |
| 1014 } | |
| 1015 } | |
| 1016 | |
| 1006 void ProfileChooserView::WindowClosing() { | 1017 void ProfileChooserView::WindowClosing() { |
| 1007 DCHECK_EQ(profile_bubble_, this); | 1018 DCHECK_EQ(profile_bubble_, this); |
| 1008 profile_bubble_ = NULL; | 1019 profile_bubble_ = NULL; |
| 1009 | 1020 |
| 1010 if (tutorial_mode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { | 1021 if (tutorial_mode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { |
| 1011 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 1022 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
| 1012 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 1023 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
| 1013 } | 1024 } |
| 1014 } | 1025 } |
| 1015 | 1026 |
| 1016 bool ProfileChooserView::AcceleratorPressed( | 1027 bool ProfileChooserView::AcceleratorPressed( |
| 1017 const ui::Accelerator& accelerator) { | 1028 const ui::Accelerator& accelerator) { |
| 1018 if (accelerator.key_code() != ui::VKEY_DOWN && | 1029 if (accelerator.key_code() != ui::VKEY_DOWN && |
| 1019 accelerator.key_code() != ui::VKEY_UP) | 1030 accelerator.key_code() != ui::VKEY_UP) |
| 1020 return BubbleDialogDelegateView::AcceleratorPressed(accelerator); | 1031 return BubbleDialogDelegateView::AcceleratorPressed(accelerator); |
| 1021 | 1032 |
| 1022 // Move the focus up or down. | 1033 // Move the focus up or down. |
| 1023 GetFocusManager()->AdvanceFocus(accelerator.key_code() != ui::VKEY_DOWN); | 1034 GetFocusManager()->AdvanceFocus(accelerator.key_code() != ui::VKEY_DOWN); |
| 1024 return true; | 1035 return true; |
| 1025 } | 1036 } |
| 1026 | 1037 |
| 1027 views::View* ProfileChooserView::GetInitiallyFocusedView() { | 1038 views::View* ProfileChooserView::GetInitiallyFocusedView() { |
| 1028 return signin_current_profile_button_; | 1039 return signin_current_profile_button_; |
|
sky
2017/02/09 20:17:39
You should return the view here.
| |
| 1029 } | 1040 } |
| 1030 | 1041 |
| 1031 int ProfileChooserView::GetDialogButtons() const { | 1042 int ProfileChooserView::GetDialogButtons() const { |
| 1032 return ui::DIALOG_BUTTON_NONE; | 1043 return ui::DIALOG_BUTTON_NONE; |
| 1033 } | 1044 } |
| 1034 | 1045 |
| 1035 bool ProfileChooserView::HandleContextMenu( | 1046 bool ProfileChooserView::HandleContextMenu( |
| 1036 const content::ContextMenuParams& params) { | 1047 const content::ContextMenuParams& params) { |
| 1037 // Suppresses the context menu because some features, such as inspecting | 1048 // Suppresses the context menu because some features, such as inspecting |
| 1038 // elements, are not appropriate in a bubble. | 1049 // elements, are not appropriate in a bubble. |
| (...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1895 } | 1906 } |
| 1896 | 1907 |
| 1897 views::View* ProfileChooserView::CreateOptionsView(bool display_lock, | 1908 views::View* ProfileChooserView::CreateOptionsView(bool display_lock, |
| 1898 AvatarMenu* avatar_menu) { | 1909 AvatarMenu* avatar_menu) { |
| 1899 views::View* view = new views::View(); | 1910 views::View* view = new views::View(); |
| 1900 views::GridLayout* layout = | 1911 views::GridLayout* layout = |
| 1901 CreateSingleColumnLayout(view, GetFixedMenuWidth()); | 1912 CreateSingleColumnLayout(view, GetFixedMenuWidth()); |
| 1902 | 1913 |
| 1903 const bool is_guest = browser_->profile()->IsGuestSession(); | 1914 const bool is_guest = browser_->profile()->IsGuestSession(); |
| 1904 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16; | 1915 const int kIconSize = switches::IsMaterialDesignUserMenu() ? 20 : 16; |
| 1905 if (switches::IsMaterialDesignUserMenu()) { | 1916 if (switches::IsMaterialDesignUserMenu()) { |
|
sky
2017/02/09 20:17:39
What about the !md case?
| |
| 1906 // Add the user switching buttons | 1917 // Add the user switching buttons |
| 1907 const int kProfileIconSize = 18; | 1918 const int kProfileIconSize = 18; |
| 1908 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); | 1919 layout->StartRowWithPadding(1, 0, 0, views::kRelatedControlVerticalSpacing); |
| 1909 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { | 1920 for (size_t i = 0; i < avatar_menu->GetNumberOfItems(); ++i) { |
| 1910 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); | 1921 const AvatarMenu::Item& item = avatar_menu->GetItemAt(i); |
| 1911 if (!item.active) { | 1922 if (!item.active) { |
| 1912 gfx::Image image = profiles::GetSizedAvatarIcon( | 1923 gfx::Image image = profiles::GetSizedAvatarIcon( |
| 1913 item.icon, true, kProfileIconSize, kProfileIconSize, | 1924 item.icon, true, kProfileIconSize, kProfileIconSize, |
| 1914 profiles::SHAPE_CIRCLE); | 1925 profiles::SHAPE_CIRCLE); |
| 1915 views::LabelButton* button = new BackgroundColorHoverButton( | 1926 views::LabelButton* button = new BackgroundColorHoverButton( |
| 1916 this, profiles::GetProfileSwitcherTextForItem(item), | 1927 this, profiles::GetProfileSwitcherTextForItem(item), |
| 1917 *image.ToImageSkia()); | 1928 *image.ToImageSkia()); |
| 1918 button->SetImageLabelSpacing(kMaterialMenuEdgeMargin); | 1929 button->SetImageLabelSpacing(kMaterialMenuEdgeMargin); |
| 1919 open_other_profile_indexes_map_[button] = i; | 1930 open_other_profile_indexes_map_[button] = i; |
| 1920 | 1931 |
| 1932 if (!first_profile_button_) { | |
| 1933 first_profile_button_ = button; | |
| 1934 } | |
| 1921 layout->StartRow(1, 0); | 1935 layout->StartRow(1, 0); |
| 1922 layout->AddView(button); | 1936 layout->AddView(button); |
| 1923 } | 1937 } |
| 1924 } | 1938 } |
| 1925 | 1939 |
| 1926 // Add the "Guest" button for browsing as guest | 1940 // Add the "Guest" button for browsing as guest |
| 1927 if (!is_guest) { | 1941 if (!is_guest) { |
| 1928 PrefService* service = g_browser_process->local_state(); | 1942 PrefService* service = g_browser_process->local_state(); |
| 1929 DCHECK(service); | 1943 DCHECK(service); |
| 1930 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { | 1944 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { |
| (...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2365 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2379 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2366 IncognitoModePrefs::DISABLED; | 2380 IncognitoModePrefs::DISABLED; |
| 2367 return incognito_available && !browser_->profile()->IsGuestSession(); | 2381 return incognito_available && !browser_->profile()->IsGuestSession(); |
| 2368 } | 2382 } |
| 2369 | 2383 |
| 2370 void ProfileChooserView::PostActionPerformed( | 2384 void ProfileChooserView::PostActionPerformed( |
| 2371 ProfileMetrics::ProfileDesktopMenu action_performed) { | 2385 ProfileMetrics::ProfileDesktopMenu action_performed) { |
| 2372 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); | 2386 ProfileMetrics::LogProfileDesktopMenu(action_performed, gaia_service_type_); |
| 2373 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; | 2387 gaia_service_type_ = signin::GAIA_SERVICE_TYPE_NONE; |
| 2374 } | 2388 } |
| OLD | NEW |