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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 2171473002: Bringing back fast user switching on Mac material design user menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final nits Created 4 years, 5 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
6 6
7 #import <Carbon/Carbon.h> // kVK_Return. 7 #import <Carbon/Carbon.h> // kVK_Return.
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/profiles/profile_window.h" 27 #include "chrome/browser/profiles/profile_window.h"
28 #include "chrome/browser/profiles/profiles_state.h" 28 #include "chrome/browser/profiles/profiles_state.h"
29 #include "chrome/browser/signin/chrome_signin_helper.h" 29 #include "chrome/browser/signin/chrome_signin_helper.h"
30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
31 #include "chrome/browser/signin/signin_error_controller_factory.h" 31 #include "chrome/browser/signin/signin_error_controller_factory.h"
32 #include "chrome/browser/signin/signin_manager_factory.h" 32 #include "chrome/browser/signin/signin_manager_factory.h"
33 #include "chrome/browser/signin/signin_promo.h" 33 #include "chrome/browser/signin/signin_promo.h"
34 #include "chrome/browser/signin/signin_ui_util.h" 34 #include "chrome/browser/signin/signin_ui_util.h"
35 #include "chrome/browser/ui/browser.h" 35 #include "chrome/browser/ui/browser.h"
36 #include "chrome/browser/ui/browser_commands.h" 36 #include "chrome/browser/ui/browser_commands.h"
37 #include "chrome/browser/ui/browser_list.h"
37 #include "chrome/browser/ui/browser_window.h" 38 #include "chrome/browser/ui/browser_window.h"
38 #include "chrome/browser/ui/chrome_pages.h" 39 #include "chrome/browser/ui/chrome_pages.h"
39 #include "chrome/browser/ui/chrome_style.h" 40 #include "chrome/browser/ui/chrome_style.h"
40 #import "chrome/browser/ui/cocoa/browser_window_utils.h" 41 #import "chrome/browser/ui/cocoa/browser_window_utils.h"
41 #import "chrome/browser/ui/cocoa/info_bubble_view.h" 42 #import "chrome/browser/ui/cocoa/info_bubble_view.h"
42 #import "chrome/browser/ui/cocoa/info_bubble_window.h" 43 #import "chrome/browser/ui/cocoa/info_bubble_window.h"
43 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " 44 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h "
44 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" 45 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h"
45 #include "chrome/browser/ui/singleton_tabs.h" 46 #include "chrome/browser/ui/singleton_tabs.h"
46 #include "chrome/browser/ui/user_manager.h" 47 #include "chrome/browser/ui/user_manager.h"
(...skipping 20 matching lines...) Expand all
67 #import "ui/base/cocoa/cocoa_base_utils.h" 68 #import "ui/base/cocoa/cocoa_base_utils.h"
68 #import "ui/base/cocoa/controls/blue_label_button.h" 69 #import "ui/base/cocoa/controls/blue_label_button.h"
69 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" 70 #import "ui/base/cocoa/controls/hyperlink_button_cell.h"
70 #import "ui/base/cocoa/controls/hyperlink_text_view.h" 71 #import "ui/base/cocoa/controls/hyperlink_text_view.h"
71 #import "ui/base/cocoa/hover_image_button.h" 72 #import "ui/base/cocoa/hover_image_button.h"
72 #include "ui/base/cocoa/window_size_constants.h" 73 #include "ui/base/cocoa/window_size_constants.h"
73 #include "ui/base/l10n/l10n_util.h" 74 #include "ui/base/l10n/l10n_util.h"
74 #include "ui/base/l10n/l10n_util_mac.h" 75 #include "ui/base/l10n/l10n_util_mac.h"
75 #include "ui/base/resource/resource_bundle.h" 76 #include "ui/base/resource/resource_bundle.h"
76 #include "ui/events/keycodes/keyboard_codes.h" 77 #include "ui/events/keycodes/keyboard_codes.h"
78 #include "ui/gfx/color_palette.h"
77 #include "ui/gfx/image/image.h" 79 #include "ui/gfx/image/image.h"
80 #include "ui/gfx/image/image_skia_util_mac.h"
81 #include "ui/gfx/paint_vector_icon.h"
78 #include "ui/gfx/text_elider.h" 82 #include "ui/gfx/text_elider.h"
83 #include "ui/gfx/vector_icons_public.h"
79 #include "ui/native_theme/common_theme.h" 84 #include "ui/native_theme/common_theme.h"
80 #include "ui/native_theme/native_theme.h" 85 #include "ui/native_theme/native_theme.h"
81 #include "ui/native_theme/native_theme_mac.h" 86 #include "ui/native_theme/native_theme_mac.h"
82 87
83 namespace { 88 namespace {
84 89
85 // Constants taken from the Windows/Views implementation at: 90 // Constants taken from the Windows/Views implementation at:
86 // chrome/browser/ui/views/profile_chooser_view.cc 91 // chrome/browser/ui/views/profile_chooser_view.cc
87 const int kLargeImageSide = 88; 92 const int kLargeImageSide = 88;
88 const int kSmallImageSide = 32; 93 const int kSmallImageSide = 32;
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 }; 425 };
421 426
422 // Custom button cell that adds a left padding before the button image, and 427 // Custom button cell that adds a left padding before the button image, and
423 // a custom spacing between the button image and title. 428 // a custom spacing between the button image and title.
424 @interface CustomPaddingImageButtonCell : NSButtonCell { 429 @interface CustomPaddingImageButtonCell : NSButtonCell {
425 @private 430 @private
426 // Padding added to the left margin of the button. 431 // Padding added to the left margin of the button.
427 int leftMarginSpacing_; 432 int leftMarginSpacing_;
428 // Spacing between the cell image and title. 433 // Spacing between the cell image and title.
429 int imageTitleSpacing_; 434 int imageTitleSpacing_;
435 // Padding added to the right margin of the button.
436 int rightMarginSpacing_;
430 } 437 }
431 438
432 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing 439 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing
433 imageTitleSpacing:(int)imageTitleSpacing; 440 imageTitleSpacing:(int)imageTitleSpacing;
441
442 - (void)setRightMarginSpacing:(int)rightMarginSpacing;
434 @end 443 @end
435 444
436 @implementation CustomPaddingImageButtonCell 445 @implementation CustomPaddingImageButtonCell
437 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing 446 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing
438 imageTitleSpacing:(int)imageTitleSpacing { 447 imageTitleSpacing:(int)imageTitleSpacing {
439 if ((self = [super init])) { 448 if ((self = [super init])) {
440 leftMarginSpacing_ = leftMarginSpacing; 449 leftMarginSpacing_ = leftMarginSpacing;
441 imageTitleSpacing_ = imageTitleSpacing; 450 imageTitleSpacing_ = imageTitleSpacing;
442 } 451 }
443 return self; 452 return self;
444 } 453 }
445 454
455 - (void)setRightMarginSpacing:(int)rightMarginSpacing {
456 rightMarginSpacing_ = rightMarginSpacing;
457 }
458
446 - (NSRect)drawTitle:(NSAttributedString*)title 459 - (NSRect)drawTitle:(NSAttributedString*)title
447 withFrame:(NSRect)frame 460 withFrame:(NSRect)frame
448 inView:(NSView*)controlView { 461 inView:(NSView*)controlView {
449 NSRect marginRect; 462 NSRect marginRect;
450 NSDivideRect(frame, &marginRect, &frame, leftMarginSpacing_, NSMinXEdge); 463 NSDivideRect(frame, &marginRect, &frame, leftMarginSpacing_, NSMinXEdge);
451 464
452 // The title frame origin isn't aware of the left margin spacing added 465 // The title frame origin isn't aware of the left margin spacing added
453 // in -drawImage, so it must be added when drawing the title as well. 466 // in -drawImage, so it must be added when drawing the title as well.
454 if ([self imagePosition] == NSImageLeft) 467 if ([self imagePosition] == NSImageLeft)
455 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, NSMinXEdge); 468 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, NSMinXEdge);
456 469
470 NSDivideRect(frame, &marginRect, &frame, rightMarginSpacing_, NSMaxXEdge);
471
457 return [super drawTitle:title withFrame:frame inView:controlView]; 472 return [super drawTitle:title withFrame:frame inView:controlView];
458 } 473 }
459 474
460 - (void)drawImage:(NSImage*)image 475 - (void)drawImage:(NSImage*)image
461 withFrame:(NSRect)frame 476 withFrame:(NSRect)frame
462 inView:(NSView*)controlView { 477 inView:(NSView*)controlView {
463 if ([self imagePosition] == NSImageLeft) 478 if ([self imagePosition] == NSImageLeft)
464 frame.origin.x = leftMarginSpacing_; 479 frame.origin.x = leftMarginSpacing_;
465 [super drawImage:image withFrame:frame inView:controlView]; 480 [super drawImage:image withFrame:frame inView:controlView];
466 } 481 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
790 } 805 }
791 806
792 @end 807 @end
793 808
794 // A custom button that allows for setting a background color when hovered over. 809 // A custom button that allows for setting a background color when hovered over.
795 @interface BackgroundColorHoverButton : HoverImageButton { 810 @interface BackgroundColorHoverButton : HoverImageButton {
796 @private 811 @private
797 base::scoped_nsobject<NSColor> backgroundColor_; 812 base::scoped_nsobject<NSColor> backgroundColor_;
798 base::scoped_nsobject<NSColor> hoverColor_; 813 base::scoped_nsobject<NSColor> hoverColor_;
799 } 814 }
815
816 - (void)setRightMarginSpacing:(int)rightMarginSpacing;
800 @end 817 @end
801 818
802 @implementation BackgroundColorHoverButton 819 @implementation BackgroundColorHoverButton
803 820
804 - (id)initWithFrame:(NSRect)frameRect 821 - (id)initWithFrame:(NSRect)frameRect
805 imageTitleSpacing:(int)imageTitleSpacing 822 imageTitleSpacing:(int)imageTitleSpacing
806 backgroundColor:(NSColor*)backgroundColor { 823 backgroundColor:(NSColor*)backgroundColor {
807 if ((self = [super initWithFrame:frameRect])) { 824 if ((self = [super initWithFrame:frameRect])) {
808 backgroundColor_.reset([backgroundColor retain]); 825 backgroundColor_.reset([backgroundColor retain]);
809 // Use a color from Aura, since this button is not trying to look like a 826 // Use a color from Aura, since this button is not trying to look like a
810 // native control. 827 // native control.
811 SkColor hoverColor = ui::GetAuraColor( 828 SkColor hoverColor = ui::GetAuraColor(
812 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor, nullptr); 829 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor, nullptr);
813 hoverColor_.reset([skia::SkColorToSRGBNSColor(hoverColor) retain]); 830 hoverColor_.reset([skia::SkColorToSRGBNSColor(hoverColor) retain]);
814 831
815 [self setBordered:NO]; 832 [self setBordered:NO];
816 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; 833 [self setFont:[NSFont labelFontOfSize:kTextFontSize]];
817 [self setButtonType:NSMomentaryChangeButton]; 834 [self setButtonType:NSMomentaryChangeButton];
818 835
819 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( 836 base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
820 [[CustomPaddingImageButtonCell alloc] 837 [[CustomPaddingImageButtonCell alloc]
821 initWithLeftMarginSpacing:kHorizontalSpacing 838 initWithLeftMarginSpacing:kHorizontalSpacing
822 imageTitleSpacing:imageTitleSpacing]); 839 imageTitleSpacing:imageTitleSpacing]);
823 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; 840 [cell setLineBreakMode:NSLineBreakByTruncatingTail];
824 [self setCell:cell.get()]; 841 [self setCell:cell.get()];
825 } 842 }
826 return self; 843 return self;
827 } 844 }
828 845
846 - (void)setRightMarginSpacing:(int)rightMarginSpacing {
847 [[self cell] setRightMarginSpacing:rightMarginSpacing];
848 }
849
829 - (void)drawRect:(NSRect)dirtyRect { 850 - (void)drawRect:(NSRect)dirtyRect {
830 if ([self isEnabled]) { 851 if ([self isEnabled]) {
831 bool isHighlighted = ([self hoverState] != kHoverStateNone); 852 bool isHighlighted = ([self hoverState] != kHoverStateNone);
832 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; 853 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_;
833 [[self cell] setBackgroundColor:backgroundColor]; 854 [[self cell] setBackgroundColor:backgroundColor];
834 } 855 }
835 [super drawRect:dirtyRect]; 856 [super drawRect:dirtyRect];
836 } 857 }
837 858
838 -(void)keyDown:(NSEvent*)event { 859 -(void)keyDown:(NSEvent*)event {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 } 913 }
893 914
894 @end 915 @end
895 916
896 @interface ProfileChooserController () 917 @interface ProfileChooserController ()
897 // Adds an horizontal separator to |container| at |yOffset| and returns the 918 // Adds an horizontal separator to |container| at |yOffset| and returns the
898 // yOffset corresponding to after the separator. 919 // yOffset corresponding to after the separator.
899 - (CGFloat)addSeparatorToContainer:(NSView*)container 920 - (CGFloat)addSeparatorToContainer:(NSView*)container
900 atYOffset:(CGFloat)yOffset; 921 atYOffset:(CGFloat)yOffset;
901 922
902 // Builds the right-click profile switcher. 923 // Builds the fast user switcher view. In the current user menu, this is
903 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles 924 // triggered by right-clicking the avatar button; in the material design user
904 atYOffset:(CGFloat)yOffset 925 // menu, this appears as part of the user menu. Returns the yOffset
905 inContainer:(NSView*)container; 926 // corresponding to after the profile switcher buttons.
927 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles
928 atYOffset:(CGFloat)yOffset
929 inContainer:(NSView*)container;
906 930
907 // Builds the regular profile chooser view. 931 // Builds the regular profile chooser view.
908 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView 932 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView
909 tutorialView:(NSView*)tutorialView 933 tutorialView:(NSView*)tutorialView
934 otherProfiles:(NSArray*)otherProfiles
910 atYOffset:(CGFloat)yOffset 935 atYOffset:(CGFloat)yOffset
911 inContainer:(NSView*)container 936 inContainer:(NSView*)container
912 displayLock:(bool)displayLock; 937 showLock:(bool)showLock;
913 938
914 // Builds the profile chooser view. 939 // Builds the profile chooser view.
915 - (NSView*)buildProfileChooserView; 940 - (NSView*)buildProfileChooserView;
916 941
917 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; 942 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item;
918 943
919 // Builds a tutorial card with a title label using |titleMessage|, a content 944 // Builds a tutorial card with a title label using |titleMessage|, a content
920 // label using |contentMessage|, a link using |linkMessage|, and a button using 945 // label using |contentMessage|, a link using |linkMessage|, and a button using
921 // |buttonMessage|. If |stackButton| is YES, places the button above the link. 946 // |buttonMessage|. If |stackButton| is YES, places the button above the link.
922 // Otherwise places both on the same row with the link left aligned and button 947 // Otherwise places both on the same row with the link left aligned and button
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 rect:(NSRect)rect; 985 rect:(NSRect)rect;
961 986
962 // Creates the disclaimer text for supervised users, telling them that the 987 // Creates the disclaimer text for supervised users, telling them that the
963 // manager can view their history etc. 988 // manager can view their history etc.
964 - (NSView*)createSupervisedUserDisclaimerView; 989 - (NSView*)createSupervisedUserDisclaimerView;
965 990
966 // Creates a main profile card for the guest user. 991 // Creates a main profile card for the guest user.
967 - (NSView*)createGuestProfileView; 992 - (NSView*)createGuestProfileView;
968 993
969 // Creates an item for the profile |itemIndex| that is used in the fast profile 994 // Creates an item for the profile |itemIndex| that is used in the fast profile
970 // switcher in the middle of the bubble. 995 // switcher view.
971 - (NSButton*)createOtherProfileView:(int)itemIndex; 996 - (NSButton*)createOtherProfileView:(int)itemIndex;
972 997
973 // Creates the "Not you" and Lock option buttons. 998 // Creates the following option buttons: lock profile, go incognito, and switch
999 // user/exit guest.
974 - (NSView*)createOptionsViewWithRect:(NSRect)rect 1000 - (NSView*)createOptionsViewWithRect:(NSRect)rect
975 displayLock:(BOOL)displayLock; 1001 showLock:(BOOL)showLock;
1002 // For material design user menu, creates the following option buttons: lock
1003 // profile/close all windows, switch user/exit guest, and open guest profile.
1004 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)frame
1005 showLock:(BOOL)showLock;
976 1006
977 // Creates the account management view for the active profile. 1007 // Creates the account management view for the active profile.
978 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; 1008 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect;
979 1009
980 // Creates the list of accounts for the active profile. 1010 // Creates the list of accounts for the active profile.
981 - (NSView*)createAccountsListWithRect:(NSRect)rect; 1011 - (NSView*)createAccountsListWithRect:(NSRect)rect;
982 1012
983 // Creates the Gaia sign-in/add account view. 1013 // Creates the Gaia sign-in/add account view.
984 - (NSView*)buildGaiaEmbeddedView; 1014 - (NSView*)buildGaiaEmbeddedView;
985 1015
986 // Creates the account removal view. 1016 // Creates the account removal view.
987 - (NSView*)buildAccountRemovalView; 1017 - (NSView*)buildAccountRemovalView;
988 1018
989 // Create a view that shows various options for an upgrade user who is not 1019 // Create a view that shows various options for an upgrade user who is not
990 // the same person as the currently signed in user. 1020 // the same person as the currently signed in user.
991 - (NSView*)buildSwitchUserView; 1021 - (NSView*)buildSwitchUserView;
992 1022
993 // Creates a button with |text| and |action|, optionally with an icon given by 1023 // Creates a button with |text| and |action|, optionally with an icon given by
994 // |imageResourceId|. 1024 // |imageResourceId| or |image|.
995 - (NSButton*)hoverButtonWithRect:(NSRect)rect 1025 - (NSButton*)hoverButtonWithRect:(NSRect)rect
996 text:(NSString*)text 1026 text:(NSString*)text
997 imageResourceId:(int)imageResourceId 1027 imageResourceId:(int)imageResourceId
998 action:(SEL)action; 1028 action:(SEL)action;
1029 - (NSButton*)hoverButtonWithRect:(NSRect)rect
1030 text:(NSString*)text
1031 image:(NSImage*)image
1032 action:(SEL)action;
999 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect 1033 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect
1000 text:(NSString*)text 1034 text:(NSString*)text
1001 action:(SEL)action; 1035 action:(SEL)action;
1002 1036
1003 // Creates a generic link button with |title| and an |action| positioned at 1037 // Creates a generic link button with |title| and an |action| positioned at
1004 // |frameOrigin|. 1038 // |frameOrigin|.
1005 - (NSButton*)linkButtonWithTitle:(NSString*)title 1039 - (NSButton*)linkButtonWithTitle:(NSString*)title
1006 frameOrigin:(NSPoint)frameOrigin 1040 frameOrigin:(NSPoint)frameOrigin
1007 action:(SEL)action; 1041 action:(SEL)action;
1008 1042
(...skipping 24 matching lines...) Expand all
1033 } 1067 }
1034 1068
1035 - (IBAction)switchToProfile:(id)sender { 1069 - (IBAction)switchToProfile:(id)sender {
1036 // Check the event flags to see if a new window should be created. 1070 // Check the event flags to see if a new window should be created.
1037 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( 1071 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent(
1038 [NSApp currentEvent]) == NEW_WINDOW; 1072 [NSApp currentEvent]) == NEW_WINDOW;
1039 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, 1073 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate,
1040 ProfileMetrics::SWITCH_PROFILE_ICON); 1074 ProfileMetrics::SWITCH_PROFILE_ICON);
1041 } 1075 }
1042 1076
1077 - (IBAction)switchToGuest:(id)sender {
1078 PrefService* service = g_browser_process->local_state();
1079 DCHECK(service);
1080 DCHECK(service->GetBoolean(prefs::kBrowserGuestModeEnabled));
1081 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback());
1082 }
1083
1043 - (IBAction)showUserManager:(id)sender { 1084 - (IBAction)showUserManager:(id)sender {
1044 UserManager::Show(base::FilePath(), 1085 UserManager::Show(base::FilePath(),
1045 profiles::USER_MANAGER_NO_TUTORIAL, 1086 profiles::USER_MANAGER_NO_TUTORIAL,
1046 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 1087 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
1047 [self postActionPerformed: 1088 [self postActionPerformed:
1048 ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER]; 1089 ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER];
1049 } 1090 }
1050 1091
1051 - (IBAction)exitGuest:(id)sender { 1092 - (IBAction)exitGuest:(id)sender {
1052 DCHECK(browser_->profile()->IsGuestSession()); 1093 DCHECK(browser_->profile()->IsGuestSession());
1053 UserManager::Show(base::FilePath(), 1094 UserManager::Show(base::FilePath(),
1054 profiles::USER_MANAGER_NO_TUTORIAL, 1095 profiles::USER_MANAGER_NO_TUTORIAL,
1055 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); 1096 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION);
1056 profiles::CloseGuestProfileWindows(); 1097 profiles::CloseGuestProfileWindows();
1057 } 1098 }
1058 1099
1100 - (IBAction)closeAllWindows:(id)sender {
1101 profiles::CloseProfileWindows(browser_->profile());
1102 }
1103
1059 - (IBAction)goIncognito:(id)sender { 1104 - (IBAction)goIncognito:(id)sender {
1060 DCHECK([self shouldShowGoIncognito]); 1105 DCHECK([self shouldShowGoIncognito]);
1061 chrome::NewIncognitoWindow(browser_); 1106 chrome::NewIncognitoWindow(browser_);
1062 [self postActionPerformed: 1107 [self postActionPerformed:
1063 ProfileMetrics::PROFILE_DESKTOP_MENU_GO_INCOGNITO]; 1108 ProfileMetrics::PROFILE_DESKTOP_MENU_GO_INCOGNITO];
1064 } 1109 }
1065 1110
1066 - (IBAction)showAccountManagement:(id)sender { 1111 - (IBAction)showAccountManagement:(id)sender {
1067 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; 1112 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT];
1068 } 1113 }
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 NSBox* separator = 1377 NSBox* separator =
1333 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, 1378 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset,
1334 GetFixedMenuWidth(), 0)]; 1379 GetFixedMenuWidth(), 0)];
1335 [container addSubview:separator]; 1380 [container addSubview:separator];
1336 return NSMaxY([separator frame]); 1381 return NSMaxY([separator frame]);
1337 } 1382 }
1338 1383
1339 // Builds the fast user switcher view in |container| at |yOffset| and populates 1384 // Builds the fast user switcher view in |container| at |yOffset| and populates
1340 // it with the entries for every profile in |otherProfiles|. Returns the new 1385 // it with the entries for every profile in |otherProfiles|. Returns the new
1341 // yOffset after adding the elements. 1386 // yOffset after adding the elements.
1342 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles 1387 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles
1343 atYOffset:(CGFloat)yOffset 1388 atYOffset:(CGFloat)yOffset
1344 inContainer:(NSView*)container { 1389 inContainer:(NSView*)container {
1345 // Other profiles switcher. The profiles have already been sorted 1390 // Other profiles switcher. The profiles have already been sorted
1346 // by their y-coordinate, so they can be added in the existing order. 1391 // by their y-coordinate, so they can be added in the existing order.
1347 for (NSView* otherProfileView in otherProfiles) { 1392 for (NSView* otherProfileView in otherProfiles) {
1348 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1393 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1349 [container addSubview:otherProfileView]; 1394 [container addSubview:otherProfileView];
1350 yOffset = NSMaxY([otherProfileView frame]); 1395 yOffset = NSMaxY([otherProfileView frame]);
1351 1396
1352 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; 1397 if (!switches::IsMaterialDesignUserMenu())
1398 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1353 } 1399 }
1354 1400
1355 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1401 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1402 return yOffset;
1356 } 1403 }
1357 1404
1358 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView 1405 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView
1359 tutorialView:(NSView*)tutorialView 1406 tutorialView:(NSView*)tutorialView
1407 otherProfiles:(NSArray*)otherProfiles
1360 atYOffset:(CGFloat)yOffset 1408 atYOffset:(CGFloat)yOffset
1361 inContainer:(NSView*)container 1409 inContainer:(NSView*)container
1362 displayLock:(bool)displayLock { 1410 showLock:(bool)showLock {
1411 if (switches::IsMaterialDesignUserMenu())
1412 yOffset += kRelatedControllVerticalSpacing;
1413
1363 // Option buttons. 1414 // Option buttons.
1364 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); 1415 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0);
1365 NSView* optionsView = [self createOptionsViewWithRect:rect 1416 NSView* optionsView =
1366 displayLock:displayLock]; 1417 switches::IsMaterialDesignUserMenu()
1418 ? [self createMaterialDesignOptionsViewWithFrame:rect
1419 showLock:showLock]
1420 : [self createOptionsViewWithRect:rect showLock:showLock];
1367 [container addSubview:optionsView]; 1421 [container addSubview:optionsView];
1368 rect.origin.y = NSMaxY([optionsView frame]); 1422 rect.origin.y = NSMaxY([optionsView frame]);
1423 yOffset = rect.origin.y;
1424
1425 // For material design user menu, add the fast user switching buttons.
1426 if (switches::IsMaterialDesignUserMenu()) {
1427 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles
1428 atYOffset:yOffset
1429 inContainer:container];
1430 yOffset += kRelatedControllVerticalSpacing;
1431 rect.origin.y = yOffset;
1432 }
1369 1433
1370 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; 1434 NSBox* separator = [self horizontalSeparatorWithFrame:rect];
1371 [container addSubview:separator]; 1435 [container addSubview:separator];
1372 yOffset = NSMaxY([separator frame]); 1436 yOffset = NSMaxY([separator frame]);
1373 1437
1374 // For supervised users, add the disclaimer text. 1438 // For supervised users, add the disclaimer text.
1375 if (browser_->profile()->IsSupervised()) { 1439 if (browser_->profile()->IsSupervised()) {
1376 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing 1440 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing
1377 : kSmallVerticalSpacing; 1441 : kSmallVerticalSpacing;
1378 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; 1442 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView];
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1421 1485
1422 - (NSView*)buildProfileChooserView { 1486 - (NSView*)buildProfileChooserView {
1423 base::scoped_nsobject<NSView> container( 1487 base::scoped_nsobject<NSView> container(
1424 [[NSView alloc] initWithFrame:NSZeroRect]); 1488 [[NSView alloc] initWithFrame:NSZeroRect]);
1425 1489
1426 NSView* tutorialView = nil; 1490 NSView* tutorialView = nil;
1427 NSView* currentProfileView = nil; 1491 NSView* currentProfileView = nil;
1428 base::scoped_nsobject<NSMutableArray> otherProfiles( 1492 base::scoped_nsobject<NSMutableArray> otherProfiles(
1429 [[NSMutableArray alloc] init]); 1493 [[NSMutableArray alloc] init]);
1430 // Local and guest profiles cannot lock their profile. 1494 // Local and guest profiles cannot lock their profile.
1431 bool displayLock = false; 1495 bool showLock = false;
1432 bool isFastProfileChooser = 1496 bool isFastProfileChooser =
1433 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 1497 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
1434 if (isFastProfileChooser) { 1498 if (isFastProfileChooser) {
1435 // The user is using right-click switching, no need to tell them about it. 1499 // The user is using right-click switching, no need to tell them about it.
1436 PrefService* localState = g_browser_process->local_state(); 1500 PrefService* localState = g_browser_process->local_state();
1437 localState->SetBoolean( 1501 localState->SetBoolean(
1438 prefs::kProfileAvatarRightClickTutorialDismissed, true); 1502 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1439 } 1503 }
1440 1504
1441 // Loop over the profiles in reverse, so that they are sorted by their 1505 // Loop over the profiles in reverse, so that they are sorted by their
1442 // y-coordinate, and separate them into active and "other" profiles. 1506 // y-coordinate, and separate them into active and "other" profiles.
1443 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { 1507 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) {
1444 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); 1508 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i);
1445 if (item.active) { 1509 if (item.active) {
1446 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 1510 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
1447 tutorialView = [self buildTutorialViewIfNeededForItem:item]; 1511 tutorialView = [self buildTutorialViewIfNeededForItem:item];
1448 } 1512 }
1449 currentProfileView = 1513 currentProfileView =
1450 switches::IsMaterialDesignUserMenu() 1514 switches::IsMaterialDesignUserMenu()
1451 ? [self createMaterialDesignCurrentProfileView:item] 1515 ? [self createMaterialDesignCurrentProfileView:item]
1452 : [self createCurrentProfileView:item]; 1516 : [self createCurrentProfileView:item];
1453 displayLock = item.signed_in && 1517 showLock = item.signed_in &&
1454 profiles::IsLockAvailable(browser_->profile()); 1518 profiles::IsLockAvailable(browser_->profile());
1455 } else { 1519 } else {
1456 [otherProfiles addObject:[self createOtherProfileView:i]]; 1520 [otherProfiles addObject:[self createOtherProfileView:i]];
1457 } 1521 }
1458 } 1522 }
1459 if (!currentProfileView) // Guest windows don't have an active profile. 1523 if (!currentProfileView) // Guest windows don't have an active profile.
1460 currentProfileView = [self createGuestProfileView]; 1524 currentProfileView = [self createGuestProfileView];
1461 1525
1462 // |yOffset| is the next position at which to draw in |container| 1526 // |yOffset| is the next position at which to draw in |container|
1463 // coordinates. Add a pixel offset so that the bottom option buttons don't 1527 // coordinates. Add a pixel offset so that the bottom option buttons don't
1464 // overlap the bubble's rounded corners. 1528 // overlap the bubble's rounded corners.
1465 CGFloat yOffset = 1; 1529 CGFloat yOffset = 1;
1466 1530
1467 if (isFastProfileChooser) { 1531 if (isFastProfileChooser) {
1468 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() 1532 if (!switches::IsMaterialDesignUserMenu()) {
1469 atYOffset:yOffset 1533 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get()
1470 inContainer:container.get()]; 1534 atYOffset:yOffset
1535 inContainer:container];
1536 }
1471 } else { 1537 } else {
1472 [self buildProfileChooserViewWithProfileView:currentProfileView 1538 [self buildProfileChooserViewWithProfileView:currentProfileView
1473 tutorialView:tutorialView 1539 tutorialView:tutorialView
1540 otherProfiles:otherProfiles.get()
1474 atYOffset:yOffset 1541 atYOffset:yOffset
1475 inContainer:container.get() 1542 inContainer:container
1476 displayLock:displayLock]; 1543 showLock:showLock];
1477 } 1544 }
1478 1545
1479 return container.autorelease(); 1546 return container.autorelease();
1480 } 1547 }
1481 1548
1482 - (NSView*)buildSigninConfirmationView { 1549 - (NSView*)buildSigninConfirmationView {
1483 ProfileMetrics::LogProfileNewAvatarMenuSignin( 1550 ProfileMetrics::LogProfileNewAvatarMenuSignin(
1484 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); 1551 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW);
1485 1552
1486 NSString* titleMessage = l10n_util::GetNSString( 1553 NSString* titleMessage = l10n_util::GetNSString(
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after
2075 return switches::IsMaterialDesignUserMenu() 2142 return switches::IsMaterialDesignUserMenu()
2076 ? [self createMaterialDesignCurrentProfileView:guestItem] 2143 ? [self createMaterialDesignCurrentProfileView:guestItem]
2077 : [self createCurrentProfileView:guestItem]; 2144 : [self createCurrentProfileView:guestItem];
2078 } 2145 }
2079 2146
2080 - (NSButton*)createOtherProfileView:(int)itemIndex { 2147 - (NSButton*)createOtherProfileView:(int)itemIndex {
2081 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); 2148 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex);
2082 2149
2083 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), 2150 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(),
2084 kBlueButtonHeight + kSmallVerticalSpacing); 2151 kBlueButtonHeight + kSmallVerticalSpacing);
2152 const int imageTitleSpacing = switches::IsMaterialDesignUserMenu()
2153 ? kHorizontalSpacing
2154 : kImageTitleSpacing;
2085 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( 2155 base::scoped_nsobject<BackgroundColorHoverButton> profileButton(
2086 [[BackgroundColorHoverButton alloc] 2156 [[BackgroundColorHoverButton alloc]
2087 initWithFrame:rect 2157 initWithFrame:rect
2088 imageTitleSpacing:kImageTitleSpacing 2158 imageTitleSpacing:imageTitleSpacing
2089 backgroundColor:GetDialogBackgroundColor()]); 2159 backgroundColor:GetDialogBackgroundColor()]);
2160 if (switches::IsMaterialDesignUserMenu())
2161 [profileButton setRightMarginSpacing:kHorizontalSpacing];
2090 2162
2091 NSString* title = base::SysUTF16ToNSString( 2163 NSString* title = base::SysUTF16ToNSString(
2092 profiles::GetProfileSwitcherTextForItem(item)); 2164 profiles::GetProfileSwitcherTextForItem(item));
2093 [profileButton setTitle:title]; 2165 [profileButton setTitle:title];
2094 2166
2095 // Use the low-res, small default avatars in the fast user switcher, like 2167 CGFloat availableWidth;
2096 // we do in the menu bar. 2168 if (switches::IsMaterialDesignUserMenu()) {
2097 gfx::Image itemIcon; 2169 int iconImageSide = 18;
2098 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon); 2170 [profileButton setDefaultImage:CreateProfileImage(item.icon, iconImageSide,
2171 profiles::SHAPE_CIRCLE)];
2172 availableWidth = rect.size.width - iconImageSide - imageTitleSpacing -
2173 2 * kHorizontalSpacing;
2174 } else {
2175 // Use the low-res, small default avatars in the fast user switcher, like
2176 // we do in the menu bar.
2177 gfx::Image itemIcon;
2178 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon);
2179 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide,
2180 profiles::SHAPE_SQUARE)];
2181 availableWidth = rect.size.width - kSmallImageSide - imageTitleSpacing -
2182 kHorizontalSpacing;
2183 }
2099 2184
2100 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide,
2101 profiles::SHAPE_SQUARE)];
2102 [profileButton setImagePosition:NSImageLeft]; 2185 [profileButton setImagePosition:NSImageLeft];
2103 [profileButton setAlignment:NSLeftTextAlignment]; 2186 [profileButton setAlignment:NSLeftTextAlignment];
2104 [profileButton setBordered:NO]; 2187 [profileButton setBordered:NO];
2105 [profileButton setTag:itemIndex]; 2188 [profileButton setTag:itemIndex];
2106 [profileButton setTarget:self]; 2189 [profileButton setTarget:self];
2107 [profileButton setAction:@selector(switchToProfile:)]; 2190 [profileButton setAction:@selector(switchToProfile:)];
2108 2191
2109 NSSize textSize = [[profileButton title] sizeWithAttributes:@{ 2192 NSSize textSize = [[profileButton title] sizeWithAttributes:@{
2110 NSFontAttributeName : [profileButton font] 2193 NSFontAttributeName : [profileButton font]
2111 }]; 2194 }];
2112 2195
2113 CGFloat availableWidth = rect.size.width - kSmallImageSide -
2114 kImageTitleSpacing - kHorizontalSpacing;
2115
2116 if (std::ceil(textSize.width) > availableWidth) 2196 if (std::ceil(textSize.width) > availableWidth)
2117 [profileButton setToolTip:[profileButton title]]; 2197 [profileButton setToolTip:[profileButton title]];
2118 2198
2119 return profileButton.autorelease(); 2199 return profileButton.autorelease();
2120 } 2200 }
2121 2201
2122 - (NSView*)createOptionsViewWithRect:(NSRect)rect 2202 - (NSView*)createOptionsViewWithRect:(NSRect)rect
2123 displayLock:(BOOL)displayLock { 2203 showLock:(BOOL)showLock {
2124 NSRect viewRect = NSMakeRect(0, 0, 2204 NSRect viewRect = NSMakeRect(0, 0,
2125 rect.size.width, 2205 rect.size.width,
2126 kBlueButtonHeight + kSmallVerticalSpacing); 2206 kBlueButtonHeight + kSmallVerticalSpacing);
2127 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 2207 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
2128 2208
2129 if (displayLock) { 2209 if (showLock) {
2130 NSButton* lockButton = 2210 NSButton* lockButton =
2131 [self hoverButtonWithRect:viewRect 2211 [self hoverButtonWithRect:viewRect
2132 text:l10n_util::GetNSString( 2212 text:l10n_util::GetNSString(
2133 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) 2213 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON)
2134 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK 2214 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK
2135 action:@selector(lockProfile:)]; 2215 action:@selector(lockProfile:)];
2136 [container addSubview:lockButton]; 2216 [container addSubview:lockButton];
2137 viewRect.origin.y = NSMaxY([lockButton frame]); 2217 viewRect.origin.y = NSMaxY([lockButton frame]);
2138 2218
2139 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; 2219 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect];
2140 [container addSubview:separator]; 2220 [container addSubview:separator];
2141 viewRect.origin.y = NSMaxY([separator frame]); 2221 viewRect.origin.y = NSMaxY([separator frame]);
2142 } 2222 }
2143 2223
2144 if (!switches::IsMaterialDesignUserMenu() && [self shouldShowGoIncognito]) { 2224 if ([self shouldShowGoIncognito]) {
2145 NSButton* goIncognitoButton = 2225 NSButton* goIncognitoButton =
2146 [self hoverButtonWithRect:viewRect 2226 [self hoverButtonWithRect:viewRect
2147 text:l10n_util::GetNSString( 2227 text:l10n_util::GetNSString(
2148 IDS_PROFILES_GO_INCOGNITO_BUTTON) 2228 IDS_PROFILES_GO_INCOGNITO_BUTTON)
2149 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO 2229 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO
2150 action:@selector(goIncognito:)]; 2230 action:@selector(goIncognito:)];
2151 viewRect.origin.y = NSMaxY([goIncognitoButton frame]); 2231 viewRect.origin.y = NSMaxY([goIncognitoButton frame]);
2152 [container addSubview:goIncognitoButton]; 2232 [container addSubview:goIncognitoButton];
2153 2233
2154 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; 2234 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect];
2155 [container addSubview:separator]; 2235 [container addSubview:separator];
2156 viewRect.origin.y = NSMaxY([separator frame]); 2236 viewRect.origin.y = NSMaxY([separator frame]);
2157 } 2237 }
2158 2238
2159 NSString* text = isGuestSession_ ? 2239 NSString* text = isGuestSession_ ?
2160 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) : 2240 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) :
2161 l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON); 2241 l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON);
2162 if (!isGuestSession_ && switches::IsMaterialDesignUserMenu()) {
2163 text = l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON);
2164 }
2165 NSButton* switchUsersButton = 2242 NSButton* switchUsersButton =
2166 [self hoverButtonWithRect:viewRect 2243 [self hoverButtonWithRect:viewRect
2167 text:text 2244 text:text
2168 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR 2245 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR
2169 action:isGuestSession_? @selector(exitGuest:) : 2246 action:isGuestSession_? @selector(exitGuest:) :
2170 @selector(showUserManager:)]; 2247 @selector(showUserManager:)];
2171 viewRect.origin.y = NSMaxY([switchUsersButton frame]); 2248 viewRect.origin.y = NSMaxY([switchUsersButton frame]);
2172 [container addSubview:switchUsersButton]; 2249 [container addSubview:switchUsersButton];
2173 2250
2174 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; 2251 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)];
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
2209 2286
2210 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( 2287 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect(
2211 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; 2288 0, rect.origin.y, rect.size.width, kAccountButtonHeight)];
2212 [container addSubview:accountEmails]; 2289 [container addSubview:accountEmails];
2213 2290
2214 [container setFrameSize:NSMakeSize(rect.size.width, 2291 [container setFrameSize:NSMakeSize(rect.size.width,
2215 NSMaxY([accountEmails frame]))]; 2292 NSMaxY([accountEmails frame]))];
2216 return container.autorelease(); 2293 return container.autorelease();
2217 } 2294 }
2218 2295
2296 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)rect
2297 showLock:(BOOL)showLock {
2298 NSRect viewRect = NSMakeRect(0, 0, rect.size.width,
2299 kBlueButtonHeight + kSmallVerticalSpacing);
2300 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
2301 const int material_icon_size = 20;
2302
2303 // Create a lock profile button when supervised users exist; otherwise, create
2304 // a button that closes all of the current profile's windows if more than one
2305 // is open.
2306 if (showLock) {
2307 NSButton* lockButton =
2308 [self hoverButtonWithRect:viewRect
2309 text:l10n_util::GetNSString(
2310 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON)
2311 image:NSImageFromImageSkia(gfx::CreateVectorIcon(
2312 gfx::VectorIconId::LOCK,
2313 material_icon_size, gfx::kChromeIconGrey))
2314 action:@selector(lockProfile:)];
2315 [container addSubview:lockButton];
2316 viewRect.origin.y = NSMaxY([lockButton frame]);
2317 } else if (!isGuestSession_) {
2318 int num_browsers = 0;
2319 for (auto* browser : *BrowserList::GetInstance()) {
2320 Profile* current_profile = browser_->profile()->GetOriginalProfile();
2321 if (browser->profile()->GetOriginalProfile() == current_profile)
2322 num_browsers++;
2323 }
2324 if (num_browsers > 1) {
2325 NSButton* closeAllWindowsButton = [self
2326 hoverButtonWithRect:viewRect
2327 text:l10n_util::GetNSString(
2328 IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON)
2329 image:NSImageFromImageSkia(gfx::CreateVectorIcon(
2330 gfx::VectorIconId::CLOSE_ALL,
2331 material_icon_size, gfx::kChromeIconGrey))
2332 action:@selector(closeAllWindows:)];
2333 [container addSubview:closeAllWindowsButton];
2334 viewRect.origin.y = NSMaxY([closeAllWindowsButton frame]);
2335 }
2336 }
2337
2338 // Create a manage users/exit guest button.
2339 NSString* text =
2340 isGuestSession_
2341 ? l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST)
2342 : l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON);
2343 NSImage* icon = NSImageFromImageSkia(
2344 gfx::CreateVectorIcon(isGuestSession_ ? gfx::VectorIconId::CLOSE_ALL
2345 : gfx::VectorIconId::SETTINGS,
2346 material_icon_size, gfx::kChromeIconGrey));
2347 SEL action =
2348 isGuestSession_ ? @selector(exitGuest:) : @selector(showUserManager:);
2349 NSButton* manageUsersButton =
2350 [self hoverButtonWithRect:viewRect text:text image:icon action:action];
2351 viewRect.origin.y = NSMaxY([manageUsersButton frame]);
2352 [container addSubview:manageUsersButton];
2353
2354 // Create a guest profile button.
2355 if (!isGuestSession_) {
2356 PrefService* service = g_browser_process->local_state();
2357 DCHECK(service);
2358 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) {
2359 NSButton* guestProfileButton = [self
2360 hoverButtonWithRect:viewRect
2361 text:l10n_util::GetNSString(
2362 IDS_PROFILES_GUEST_PROFILE_NAME)
2363 image:NSImageFromImageSkia(gfx::CreateVectorIcon(
2364 gfx::VectorIconId::ACCOUNT_CIRCLE,
2365 material_icon_size, gfx::kChromeIconGrey))
2366 action:@selector(switchToGuest:)];
2367 viewRect.origin.y = NSMaxY([guestProfileButton frame]);
2368 [container addSubview:guestProfileButton];
2369 }
2370 }
2371
2372 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)];
2373 return container.autorelease();
2374 }
2375
2219 - (NSView*)createAccountsListWithRect:(NSRect)rect { 2376 - (NSView*)createAccountsListWithRect:(NSRect)rect {
2220 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 2377 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
2221 currentProfileAccounts_.clear(); 2378 currentProfileAccounts_.clear();
2222 2379
2223 Profile* profile = browser_->profile(); 2380 Profile* profile = browser_->profile();
2224 std::string primaryAccount = 2381 std::string primaryAccount =
2225 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); 2382 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId();
2226 DCHECK(!primaryAccount.empty()); 2383 DCHECK(!primaryAccount.empty());
2227 std::vector<std::string>accounts = 2384 std::vector<std::string>accounts =
2228 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); 2385 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
2458 clickedOnLink:(id)link 2615 clickedOnLink:(id)link
2459 atIndex:(NSUInteger)charIndex { 2616 atIndex:(NSUInteger)charIndex {
2460 chrome::ShowSettings(browser_); 2617 chrome::ShowSettings(browser_);
2461 return YES; 2618 return YES;
2462 } 2619 }
2463 2620
2464 - (NSButton*)hoverButtonWithRect:(NSRect)rect 2621 - (NSButton*)hoverButtonWithRect:(NSRect)rect
2465 text:(NSString*)text 2622 text:(NSString*)text
2466 imageResourceId:(int)imageResourceId 2623 imageResourceId:(int)imageResourceId
2467 action:(SEL)action { 2624 action:(SEL)action {
2625 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
2626 NSImage* image = rb.GetNativeImageNamed(imageResourceId).ToNSImage();
2627 return [self hoverButtonWithRect:rect text:text image:image action:action];
2628 }
2629
2630 - (NSButton*)hoverButtonWithRect:(NSRect)rect
2631 text:(NSString*)text
2632 image:(NSImage*)image
2633 action:(SEL)action {
2468 BackgroundColorHoverButton* button = 2634 BackgroundColorHoverButton* button =
2469 [self hoverButtonWithRect:rect text:text action:action]; 2635 [self hoverButtonWithRect:rect text:text action:action];
2470 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
2471 NSImage* image = rb->GetNativeImageNamed(imageResourceId).ToNSImage();
2472 [button setDefaultImage:image]; 2636 [button setDefaultImage:image];
2473 [button setHoverImage:image]; 2637 [button setHoverImage:image];
2474 [button setPressedImage:image]; 2638 [button setPressedImage:image];
2475 [button setImagePosition:NSImageLeft]; 2639 [button setImagePosition:NSImageLeft];
2476 2640
2477 return button; 2641 return button;
2478 } 2642 }
2479 2643
2480 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect 2644 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect
2481 text:(NSString*)text 2645 text:(NSString*)text
2482 action:(SEL)action { 2646 action:(SEL)action {
2647 // The vector icons in hover buttons have small embeded paddings and are
2648 // therefore given an extra 2px in size to have a consistent look as the
2649 // profile icons; hence the -2.0 here to left align the hover button texts
2650 // with those of profile buttons.
2651 const int md_image_title_spacing = kHorizontalSpacing - 2.0;
2652
2483 base::scoped_nsobject<BackgroundColorHoverButton> button( 2653 base::scoped_nsobject<BackgroundColorHoverButton> button(
2484 [[BackgroundColorHoverButton alloc] 2654 [[BackgroundColorHoverButton alloc]
2485 initWithFrame:rect 2655 initWithFrame:rect
2486 imageTitleSpacing:kImageTitleSpacing 2656 imageTitleSpacing:switches::IsMaterialDesignUserMenu()
2657 ? md_image_title_spacing
2658 : kImageTitleSpacing
2487 backgroundColor:GetDialogBackgroundColor()]); 2659 backgroundColor:GetDialogBackgroundColor()]);
2488 2660
2489 [button setTitle:text]; 2661 [button setTitle:text];
2490 [button setAlignment:NSLeftTextAlignment]; 2662 [button setAlignment:NSLeftTextAlignment];
2491 [button setBordered:NO]; 2663 [button setBordered:NO];
2492 [button setTarget:self]; 2664 [button setTarget:self];
2493 [button setAction:action]; 2665 [button setAction:action];
2494 2666
2495 return button.autorelease(); 2667 return button.autorelease();
2496 } 2668 }
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
2582 } 2754 }
2583 2755
2584 - (bool)shouldShowGoIncognito { 2756 - (bool)shouldShowGoIncognito {
2585 bool incognitoAvailable = 2757 bool incognitoAvailable =
2586 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2758 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2587 IncognitoModePrefs::DISABLED; 2759 IncognitoModePrefs::DISABLED;
2588 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2760 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2589 } 2761 }
2590 2762
2591 @end 2763 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698