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

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

Issue 2136943003: Reflowed the profile card in mac desktop user menu into a button (for material design user menu). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Final comments 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 #include "ui/native_theme/common_theme.h" 79 #include "ui/native_theme/common_theme.h"
80 #include "ui/native_theme/native_theme.h" 80 #include "ui/native_theme/native_theme.h"
81 #include "ui/native_theme/native_theme_mac.h" 81 #include "ui/native_theme/native_theme_mac.h"
82 82
83 namespace { 83 namespace {
84 84
85 // Constants taken from the Windows/Views implementation at: 85 // Constants taken from the Windows/Views implementation at:
86 // chrome/browser/ui/views/profile_chooser_view.cc 86 // chrome/browser/ui/views/profile_chooser_view.cc
87 const int kLargeImageSide = 88; 87 const int kLargeImageSide = 88;
88 const int kSmallImageSide = 32; 88 const int kSmallImageSide = 32;
89 const CGFloat kFixedMenuWidth = 250; 89 const int kMdImageSide = 40;
90 90
91 const CGFloat kVerticalSpacing = 16.0; 91 const CGFloat kVerticalSpacing = 16.0;
92 const CGFloat kSmallVerticalSpacing = 10.0; 92 const CGFloat kSmallVerticalSpacing = 10.0;
93 const CGFloat kRelatedControllVerticalSpacing = 8.0;
93 const CGFloat kHorizontalSpacing = 16.0; 94 const CGFloat kHorizontalSpacing = 16.0;
94 const CGFloat kTitleFontSize = 15.0; 95 const CGFloat kTitleFontSize = 15.0;
95 const CGFloat kTextFontSize = 12.0; 96 const CGFloat kTextFontSize = 12.0;
96 const CGFloat kProfileButtonHeight = 30; 97 const CGFloat kProfileButtonHeight = 30;
97 const int kBezelThickness = 3; // Width of the bezel on an NSButton. 98 const int kBezelThickness = 3; // Width of the bezel on an NSButton.
98 const int kImageTitleSpacing = 10; 99 const int kImageTitleSpacing = 10;
99 const int kBlueButtonHeight = 30; 100 const int kBlueButtonHeight = 30;
100 const CGFloat kFocusRingLineWidth = 2; 101 const CGFloat kFocusRingLineWidth = 2;
101 102
102 // Fixed size for embedded sign in pages as defined in Gaia. 103 // Fixed size for embedded sign in pages as defined in Gaia.
103 const CGFloat kFixedGaiaViewWidth = 360; 104 const CGFloat kFixedGaiaViewWidth = 360;
104 105
105 // Fixed size for the account removal view. 106 // Fixed size for the account removal view.
106 const CGFloat kFixedAccountRemovalViewWidth = 280; 107 const CGFloat kFixedAccountRemovalViewWidth = 280;
107 108
108 // Fixed size for the switch user view. 109 // Fixed size for the switch user view.
109 const int kFixedSwitchUserViewWidth = 320; 110 const int kFixedSwitchUserViewWidth = 320;
110 111
111 // The tag number for the primary account. 112 // The tag number for the primary account.
112 const int kPrimaryProfileTag = -1; 113 const int kPrimaryProfileTag = -1;
113 114
114 gfx::Image CreateProfileImage(const gfx::Image& icon, int imageSize) { 115 CGFloat GetFixedMenuWidth() {
115 return profiles::GetSizedAvatarIcon( 116 return switches::IsMaterialDesignUserMenu() ? 240.0 : 250.0;
116 icon, true /* image is a square */, imageSize, imageSize); 117 }
118
119 NSImage* CreateProfileImage(const gfx::Image& icon,
120 int imageSize,
121 profiles::AvatarShape shape) {
122 return (profiles::GetSizedAvatarIcon(icon, true /* image is a square */,
123 imageSize, imageSize, shape))
124 .ToNSImage();
117 } 125 }
118 126
119 // Updates the window size and position. 127 // Updates the window size and position.
120 void SetWindowSize(NSWindow* window, NSSize size) { 128 void SetWindowSize(NSWindow* window, NSSize size) {
121 NSRect frame = [window frame]; 129 NSRect frame = [window frame];
122 frame.origin.x += frame.size.width - size.width; 130 frame.origin.x += frame.size.width - size.width;
123 frame.origin.y += frame.size.height - size.height; 131 frame.origin.y += frame.size.height - size.height;
124 frame.size = size; 132 frame.size = size;
125 [window setFrame:frame display:YES]; 133 [window setFrame:frame display:YES];
126 } 134 }
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 if ((self = [super initWithFrame:frameRect])) { 549 if ((self = [super initWithFrame:frameRect])) {
542 avatarMenu_ = avatarMenu; 550 avatarMenu_ = avatarMenu;
543 controller_ = controller; 551 controller_ = controller;
544 552
545 [self setBordered:NO]; 553 [self setBordered:NO];
546 554
547 base::scoped_nsobject<CustomCircleImageCell> cell( 555 base::scoped_nsobject<CustomCircleImageCell> cell(
548 [[CustomCircleImageCell alloc] init]); 556 [[CustomCircleImageCell alloc] init]);
549 [self setCell:cell.get()]; 557 [self setCell:cell.get()];
550 558
551 [self setDefaultImage:CreateProfileImage( 559 const int imageSide =
552 profileIcon, kLargeImageSide).ToNSImage()]; 560 switches::IsMaterialDesignUserMenu() ? kMdImageSide : kLargeImageSide;
561 [self setDefaultImage:CreateProfileImage(profileIcon, imageSide,
562 profiles::SHAPE_CIRCLE)];
553 [self setImagePosition:NSImageOnly]; 563 [self setImagePosition:NSImageOnly];
554 564
555 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide);
556 if (editingAllowed) { 565 if (editingAllowed) {
566 NSRect bounds = NSMakeRect(0, 0, imageSide, imageSide);
557 [self setTarget:self]; 567 [self setTarget:self];
558 [self setAction:@selector(editPhoto:)]; 568 [self setAction:@selector(editPhoto:)];
559 changePhotoImage_.reset([[TransparentBackgroundImageView alloc] 569 changePhotoImage_.reset([[TransparentBackgroundImageView alloc]
560 initWithFrame:bounds]); 570 initWithFrame:bounds]);
561 [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance(). 571 [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance().
562 GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()]; 572 GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()];
563 [self addSubview:changePhotoImage_]; 573 [self addSubview:changePhotoImage_];
564 574
565 // Hide the image until the button is hovered over. 575 // Hide the image until the button is hovered over.
566 [changePhotoImage_ setHidden:YES]; 576 [changePhotoImage_ setHidden:YES];
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( 819 base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
810 [[CustomPaddingImageButtonCell alloc] 820 [[CustomPaddingImageButtonCell alloc]
811 initWithLeftMarginSpacing:kHorizontalSpacing 821 initWithLeftMarginSpacing:kHorizontalSpacing
812 imageTitleSpacing:imageTitleSpacing]); 822 imageTitleSpacing:imageTitleSpacing]);
813 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; 823 [cell setLineBreakMode:NSLineBreakByTruncatingTail];
814 [self setCell:cell.get()]; 824 [self setCell:cell.get()];
815 } 825 }
816 return self; 826 return self;
817 } 827 }
818 828
819 - (void)setHoverState:(HoverState)state { 829 - (void)drawRect:(NSRect)dirtyRect {
820 [super setHoverState:state]; 830 if ([self isEnabled]) {
821 bool isHighlighted = ([self hoverState] != kHoverStateNone); 831 bool isHighlighted = ([self hoverState] != kHoverStateNone);
822 832 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_;
823 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; 833 [[self cell] setBackgroundColor:backgroundColor];
824 [[self cell] setBackgroundColor:backgroundColor]; 834 }
835 [super drawRect:dirtyRect];
825 } 836 }
826 837
827 -(void)keyDown:(NSEvent*)event { 838 -(void)keyDown:(NSEvent*)event {
828 // Since there is no default button in the bubble, it is safe to activate 839 // Since there is no default button in the bubble, it is safe to activate
829 // all buttons on Enter as well, and be consistent with the Windows 840 // all buttons on Enter as well, and be consistent with the Windows
830 // implementation. 841 // implementation.
831 if ([event keyCode] == kVK_Return) 842 if ([event keyCode] == kVK_Return)
832 [self performClick:self]; 843 [self performClick:self];
833 else 844 else
834 [super keyDown:event]; 845 [super keyDown:event];
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
932 943
933 // Builds a tutorial card to have the user confirm the last Chrome signin, 944 // Builds a tutorial card to have the user confirm the last Chrome signin,
934 // Chrome sync will be delayed until the user either dismisses the tutorial, or 945 // Chrome sync will be delayed until the user either dismisses the tutorial, or
935 // configures sync through the "Settings" link. 946 // configures sync through the "Settings" link.
936 - (NSView*)buildSigninConfirmationView; 947 - (NSView*)buildSigninConfirmationView;
937 948
938 // Builds a tutorial card to show the last signin error. 949 // Builds a tutorial card to show the last signin error.
939 - (NSView*)buildSigninErrorView; 950 - (NSView*)buildSigninErrorView;
940 951
941 // Creates the main profile card for the profile |item| at the top of 952 // Creates the main profile card for the profile |item| at the top of
942 // the bubble. 953 // the bubble, for non-material-design and material design user menu
954 // respectively.
943 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; 955 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item;
956 - (NSView*)createMaterialDesignCurrentProfileView:(const AvatarMenu::Item&)item;
944 957
945 // Creates the possible links for the main profile card with profile |item|. 958 // Creates the possible links for the main profile card with profile |item|.
946 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 959 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
947 rect:(NSRect)rect; 960 rect:(NSRect)rect;
948 961
949 // Creates the disclaimer text for supervised users, telling them that the 962 // Creates the disclaimer text for supervised users, telling them that the
950 // manager can view their history etc. 963 // manager can view their history etc.
951 - (NSView*)createSupervisedUserDisclaimerView; 964 - (NSView*)createSupervisedUserDisclaimerView;
952 965
953 // Creates a main profile card for the guest user. 966 // Creates a main profile card for the guest user.
(...skipping 16 matching lines...) Expand all
970 // Creates the Gaia sign-in/add account view. 983 // Creates the Gaia sign-in/add account view.
971 - (NSView*)buildGaiaEmbeddedView; 984 - (NSView*)buildGaiaEmbeddedView;
972 985
973 // Creates the account removal view. 986 // Creates the account removal view.
974 - (NSView*)buildAccountRemovalView; 987 - (NSView*)buildAccountRemovalView;
975 988
976 // Create a view that shows various options for an upgrade user who is not 989 // Create a view that shows various options for an upgrade user who is not
977 // the same person as the currently signed in user. 990 // the same person as the currently signed in user.
978 - (NSView*)buildSwitchUserView; 991 - (NSView*)buildSwitchUserView;
979 992
980 // Creates a button with |text|, an icon given by |imageResourceId| and with 993 // Creates a button with |text| and |action|, optionally with an icon given by
981 // |action|. 994 // |imageResourceId|.
982 - (NSButton*)hoverButtonWithRect:(NSRect)rect 995 - (NSButton*)hoverButtonWithRect:(NSRect)rect
983 text:(NSString*)text 996 text:(NSString*)text
984 imageResourceId:(int)imageResourceId 997 imageResourceId:(int)imageResourceId
985 action:(SEL)action; 998 action:(SEL)action;
999 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect
1000 text:(NSString*)text
1001 action:(SEL)action;
986 1002
987 // Creates a generic link button with |title| and an |action| positioned at 1003 // Creates a generic link button with |title| and an |action| positioned at
988 // |frameOrigin|. 1004 // |frameOrigin|.
989 - (NSButton*)linkButtonWithTitle:(NSString*)title 1005 - (NSButton*)linkButtonWithTitle:(NSString*)title
990 frameOrigin:(NSPoint)frameOrigin 1006 frameOrigin:(NSPoint)frameOrigin
991 action:(SEL)action; 1007 action:(SEL)action;
992 1008
993 // Creates an email account button with |title| and a remove icon. If 1009 // Creates an email account button with |title| and a remove icon. If
994 // |reauthRequired| is true, the button also displays a warning icon. |tag| 1010 // |reauthRequired| is true, the button also displays a warning icon. |tag|
995 // indicates which account the button refers to. 1011 // indicates which account the button refers to.
996 - (NSButton*)accountButtonWithRect:(NSRect)rect 1012 - (NSButton*)accountButtonWithRect:(NSRect)rect
997 accountId:(const std::string&)accountId 1013 accountId:(const std::string&)accountId
998 tag:(int)tag 1014 tag:(int)tag
999 reauthRequired:(BOOL)reauthRequired; 1015 reauthRequired:(BOOL)reauthRequired;
1000 1016
1001 - (bool)shouldShowGoIncognito; 1017 - (bool)shouldShowGoIncognito;
1002 @end 1018 @end
1003 1019
1004 @implementation ProfileChooserController 1020 @implementation ProfileChooserController
1005 - (profiles::BubbleViewMode) viewMode { 1021 - (profiles::BubbleViewMode) viewMode {
1006 return viewMode_; 1022 return viewMode_;
1007 } 1023 }
1008 1024
1009 - (void)setTutorialMode:(profiles::TutorialMode)tutorialMode { 1025 - (void)setTutorialMode:(profiles::TutorialMode)tutorialMode {
1010 tutorialMode_ = tutorialMode; 1026 tutorialMode_ = tutorialMode;
1011 } 1027 }
1012 1028
1029 - (IBAction)editProfile:(id)sender {
1030 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex());
1031 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE];
1032 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME];
1033 }
1034
1013 - (IBAction)switchToProfile:(id)sender { 1035 - (IBAction)switchToProfile:(id)sender {
1014 // Check the event flags to see if a new window should be created. 1036 // Check the event flags to see if a new window should be created.
1015 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( 1037 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent(
1016 [NSApp currentEvent]) == NEW_WINDOW; 1038 [NSApp currentEvent]) == NEW_WINDOW;
1017 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, 1039 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate,
1018 ProfileMetrics::SWITCH_PROFILE_ICON); 1040 ProfileMetrics::SWITCH_PROFILE_ICON);
1019 } 1041 }
1020 1042
1021 - (IBAction)showUserManager:(id)sender { 1043 - (IBAction)showUserManager:(id)sender {
1022 UserManager::Show(base::FilePath(), 1044 UserManager::Show(base::FilePath(),
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 [[self window] makeFirstResponder:dummyFocusButton]; 1322 [[self window] makeFirstResponder:dummyFocusButton];
1301 1323
1302 [contentView addSubview:subView]; 1324 [contentView addSubview:subView];
1303 [contentView addSubview:dummyFocusButton]; 1325 [contentView addSubview:dummyFocusButton];
1304 SetWindowSize([self window], 1326 SetWindowSize([self window],
1305 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); 1327 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame])));
1306 } 1328 }
1307 1329
1308 - (CGFloat)addSeparatorToContainer:(NSView*)container 1330 - (CGFloat)addSeparatorToContainer:(NSView*)container
1309 atYOffset:(CGFloat)yOffset { 1331 atYOffset:(CGFloat)yOffset {
1310 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( 1332 NSBox* separator =
1311 0, yOffset, kFixedMenuWidth, 0)]; 1333 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset,
1334 GetFixedMenuWidth(), 0)];
1312 [container addSubview:separator]; 1335 [container addSubview:separator];
1313 return NSMaxY([separator frame]); 1336 return NSMaxY([separator frame]);
1314 } 1337 }
1315 1338
1316 // Builds the fast user switcher view in |container| at |yOffset| and populates 1339 // Builds the fast user switcher view in |container| at |yOffset| and populates
1317 // it with the entries for every profile in |otherProfiles|. Returns the new 1340 // it with the entries for every profile in |otherProfiles|. Returns the new
1318 // yOffset after adding the elements. 1341 // yOffset after adding the elements.
1319 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles 1342 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles
1320 atYOffset:(CGFloat)yOffset 1343 atYOffset:(CGFloat)yOffset
1321 inContainer:(NSView*)container { 1344 inContainer:(NSView*)container {
1322 // Other profiles switcher. The profiles have already been sorted 1345 // Other profiles switcher. The profiles have already been sorted
1323 // by their y-coordinate, so they can be added in the existing order. 1346 // by their y-coordinate, so they can be added in the existing order.
1324 for (NSView* otherProfileView in otherProfiles) { 1347 for (NSView* otherProfileView in otherProfiles) {
1325 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1348 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1326 [container addSubview:otherProfileView]; 1349 [container addSubview:otherProfileView];
1327 yOffset = NSMaxY([otherProfileView frame]); 1350 yOffset = NSMaxY([otherProfileView frame]);
1328 1351
1329 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; 1352 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset];
1330 } 1353 }
1331 1354
1332 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 1355 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1333 } 1356 }
1334 1357
1335 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView 1358 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView
1336 tutorialView:(NSView*)tutorialView 1359 tutorialView:(NSView*)tutorialView
1337 atYOffset:(CGFloat)yOffset 1360 atYOffset:(CGFloat)yOffset
1338 inContainer:(NSView*)container 1361 inContainer:(NSView*)container
1339 displayLock:(bool)displayLock { 1362 displayLock:(bool)displayLock {
1340 // Option buttons. 1363 // Option buttons.
1341 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); 1364 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0);
1342 NSView* optionsView = [self createOptionsViewWithRect:rect 1365 NSView* optionsView = [self createOptionsViewWithRect:rect
1343 displayLock:displayLock]; 1366 displayLock:displayLock];
1344 [container addSubview:optionsView]; 1367 [container addSubview:optionsView];
1345 rect.origin.y = NSMaxY([optionsView frame]); 1368 rect.origin.y = NSMaxY([optionsView frame]);
1346 1369
1347 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; 1370 NSBox* separator = [self horizontalSeparatorWithFrame:rect];
1348 [container addSubview:separator]; 1371 [container addSubview:separator];
1349 yOffset = NSMaxY([separator frame]); 1372 yOffset = NSMaxY([separator frame]);
1350 1373
1351 // For supervised users, add the disclaimer text. 1374 // For supervised users, add the disclaimer text.
1352 if (browser_->profile()->IsSupervised()) { 1375 if (browser_->profile()->IsSupervised()) {
1353 yOffset += kSmallVerticalSpacing; 1376 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing
1377 : kSmallVerticalSpacing;
1354 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; 1378 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView];
1355 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; 1379 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)];
1356 [container addSubview:disclaimerContainer]; 1380 [container addSubview:disclaimerContainer];
1357 yOffset = NSMaxY([disclaimerContainer frame]); 1381 yOffset = NSMaxY([disclaimerContainer frame]);
1358 yOffset += kSmallVerticalSpacing;
1359 1382
1360 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; 1383 if (!switches::IsMaterialDesignUserMenu()) {
1384 yOffset += kSmallVerticalSpacing;
1385 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1386 }
1361 } 1387 }
1362 1388
1363 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 1389 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
1364 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: 1390 NSView* currentProfileAccountsView = [self
1365 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 1391 createCurrentProfileAccountsView:NSMakeRect(0, yOffset,
1392 GetFixedMenuWidth(), 0)];
1366 [container addSubview:currentProfileAccountsView]; 1393 [container addSubview:currentProfileAccountsView];
1367 yOffset = NSMaxY([currentProfileAccountsView frame]); 1394 yOffset = NSMaxY([currentProfileAccountsView frame]);
1368 1395
1369 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; 1396 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset];
1370 } 1397 }
1371 1398
1372 // Active profile card. 1399 // Active profile card.
1373 if (currentProfileView) { 1400 if (currentProfileView) {
1374 yOffset += kVerticalSpacing; 1401 const CGFloat verticalSpacing = switches::IsMaterialDesignUserMenu()
1402 ? kRelatedControllVerticalSpacing
1403 : kVerticalSpacing;
1404 yOffset += verticalSpacing;
1375 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1405 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1376 [container addSubview:currentProfileView]; 1406 [container addSubview:currentProfileView];
1377 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; 1407 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing;
1378 } 1408 }
1379 1409
1380 if (tutorialView) { 1410 if (tutorialView) {
1381 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; 1411 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)];
1382 [container addSubview:tutorialView]; 1412 [container addSubview:tutorialView];
1383 yOffset = NSMaxY([tutorialView frame]); 1413 yOffset = NSMaxY([tutorialView frame]);
1384 //TODO(mlerman): update UMA stats for the new tutorials. 1414 //TODO(mlerman): update UMA stats for the new tutorials.
1385 } else { 1415 } else {
1386 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; 1416 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
1387 } 1417 }
1388 1418
1389 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 1419 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1390 } 1420 }
1391 1421
1392 - (NSView*)buildProfileChooserView { 1422 - (NSView*)buildProfileChooserView {
1393 base::scoped_nsobject<NSView> container( 1423 base::scoped_nsobject<NSView> container(
1394 [[NSView alloc] initWithFrame:NSZeroRect]); 1424 [[NSView alloc] initWithFrame:NSZeroRect]);
1395 1425
1396 NSView* tutorialView = nil; 1426 NSView* tutorialView = nil;
1397 NSView* currentProfileView = nil; 1427 NSView* currentProfileView = nil;
1398 base::scoped_nsobject<NSMutableArray> otherProfiles( 1428 base::scoped_nsobject<NSMutableArray> otherProfiles(
1399 [[NSMutableArray alloc] init]); 1429 [[NSMutableArray alloc] init]);
1400 // Local and guest profiles cannot lock their profile. 1430 // Local and guest profiles cannot lock their profile.
1401 bool displayLock = false; 1431 bool displayLock = false;
1402 bool isFastProfileChooser = 1432 bool isFastProfileChooser =
1403 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 1433 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
1404 if (isFastProfileChooser) { 1434 if (isFastProfileChooser) {
1405 // The user is using right-click switching, no need to tell them about it. 1435 // The user is using right-click switching, no need to tell them about it.
1406 PrefService* localState = g_browser_process->local_state(); 1436 PrefService* localState = g_browser_process->local_state();
1407 localState->SetBoolean( 1437 localState->SetBoolean(
1408 prefs::kProfileAvatarRightClickTutorialDismissed, true); 1438 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1409 } 1439 }
1410 1440
1411 // Loop over the profiles in reverse, so that they are sorted by their 1441 // Loop over the profiles in reverse, so that they are sorted by their
1412 // y-coordinate, and separate them into active and "other" profiles. 1442 // y-coordinate, and separate them into active and "other" profiles.
1413 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { 1443 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) {
1414 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); 1444 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i);
1415 if (item.active) { 1445 if (item.active) {
1416 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { 1446 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
1417 tutorialView = [self buildTutorialViewIfNeededForItem:item]; 1447 tutorialView = [self buildTutorialViewIfNeededForItem:item];
1418 } 1448 }
1419 currentProfileView = [self createCurrentProfileView:item]; 1449 currentProfileView =
1450 switches::IsMaterialDesignUserMenu()
1451 ? [self createMaterialDesignCurrentProfileView:item]
1452 : [self createCurrentProfileView:item];
1420 displayLock = item.signed_in && 1453 displayLock = item.signed_in &&
1421 profiles::IsLockAvailable(browser_->profile()); 1454 profiles::IsLockAvailable(browser_->profile());
1422 } else { 1455 } else {
1423 [otherProfiles addObject:[self createOtherProfileView:i]]; 1456 [otherProfiles addObject:[self createOtherProfileView:i]];
1424 } 1457 }
1425 } 1458 }
1426 if (!currentProfileView) // Guest windows don't have an active profile. 1459 if (!currentProfileView) // Guest windows don't have an active profile.
1427 currentProfileView = [self createGuestProfileView]; 1460 currentProfileView = [self createGuestProfileView];
1428 1461
1429 // |yOffset| is the next position at which to draw in |container| 1462 // |yOffset| is the next position at which to draw in |container|
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1491 1524
1492 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { 1525 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item {
1493 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 1526 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
1494 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); 1527 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW);
1495 1528
1496 NSString* titleMessage = l10n_util::GetNSString( 1529 NSString* titleMessage = l10n_util::GetNSString(
1497 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); 1530 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE);
1498 NSString* contentMessage = l10n_util::GetNSString( 1531 NSString* contentMessage = l10n_util::GetNSString(
1499 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); 1532 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT);
1500 // For local profiles, the "Not you" link doesn't make sense. 1533 // For local profiles, the "Not you" link doesn't make sense.
1501 NSString* linkMessage = item.signed_in ? 1534 NSString* linkMessage =
1502 ElideMessage( 1535 item.signed_in
1503 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name), 1536 ? ElideMessage(
1504 kFixedMenuWidth - 2 * kHorizontalSpacing) : 1537 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name),
1505 nil; 1538 GetFixedMenuWidth() - 2 * kHorizontalSpacing)
1539 : nil;
1506 NSString* buttonMessage = l10n_util::GetNSString( 1540 NSString* buttonMessage = l10n_util::GetNSString(
1507 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); 1541 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON);
1508 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE 1542 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE
1509 titleMessage:titleMessage 1543 titleMessage:titleMessage
1510 contentMessage:contentMessage 1544 contentMessage:contentMessage
1511 linkMessage:linkMessage 1545 linkMessage:linkMessage
1512 buttonMessage:buttonMessage 1546 buttonMessage:buttonMessage
1513 stackButton:YES 1547 stackButton:YES
1514 hasCloseButton:YES 1548 hasCloseButton:YES
1515 linkAction:@selector(showSwitchUserView:) 1549 linkAction:@selector(showSwitchUserView:)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1569 buttonMessage:(NSString*)buttonMessage 1603 buttonMessage:(NSString*)buttonMessage
1570 stackButton:(BOOL)stackButton 1604 stackButton:(BOOL)stackButton
1571 hasCloseButton:(BOOL)hasCloseButton 1605 hasCloseButton:(BOOL)hasCloseButton
1572 linkAction:(SEL)linkAction 1606 linkAction:(SEL)linkAction
1573 buttonAction:(SEL)buttonAction { 1607 buttonAction:(SEL)buttonAction {
1574 tutorialMode_ = mode; 1608 tutorialMode_ = mode;
1575 1609
1576 NSColor* tutorialBackgroundColor = 1610 NSColor* tutorialBackgroundColor =
1577 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); 1611 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor);
1578 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] 1612 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc]
1579 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) 1613 initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0)
1580 withColor:tutorialBackgroundColor]); 1614 withColor:tutorialBackgroundColor]);
1581 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; 1615 CGFloat availableWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing;
1582 CGFloat yOffset = kVerticalSpacing; 1616 CGFloat yOffset = kVerticalSpacing;
1583 1617
1584 // Adds links and buttons at the bottom. 1618 // Adds links and buttons at the bottom.
1585 base::scoped_nsobject<NSButton> tutorialOkButton; 1619 base::scoped_nsobject<NSButton> tutorialOkButton;
1586 if (buttonMessage) { 1620 if (buttonMessage) {
1587 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); 1621 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]);
1588 [tutorialOkButton setTitle:buttonMessage]; 1622 [tutorialOkButton setTitle:buttonMessage];
1589 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; 1623 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle];
1590 [tutorialOkButton setTarget:self]; 1624 [tutorialOkButton setTarget:self];
1591 [tutorialOkButton setAction:buttonAction]; 1625 [tutorialOkButton setAction:buttonAction];
1592 [tutorialOkButton setAlignment:NSCenterTextAlignment]; 1626 [tutorialOkButton setAlignment:NSCenterTextAlignment];
1593 [tutorialOkButton sizeToFit]; 1627 [tutorialOkButton sizeToFit];
1594 } 1628 }
1595 1629
1596 NSButton* learnMoreLink = nil; 1630 NSButton* learnMoreLink = nil;
1597 if (linkMessage) { 1631 if (linkMessage) {
1598 learnMoreLink = [self linkButtonWithTitle:linkMessage 1632 learnMoreLink = [self linkButtonWithTitle:linkMessage
1599 frameOrigin:NSZeroPoint 1633 frameOrigin:NSZeroPoint
1600 action:linkAction]; 1634 action:linkAction];
1601 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; 1635 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]];
1602 } 1636 }
1603 1637
1604 if (stackButton) { 1638 if (stackButton) {
1605 if (linkMessage) { 1639 [learnMoreLink
1606 [learnMoreLink setFrameOrigin:NSMakePoint( 1640 setFrameOrigin:NSMakePoint((GetFixedMenuWidth() -
1607 (kFixedMenuWidth - NSWidth([learnMoreLink frame])) / 2, yOffset)]; 1641 NSWidth([learnMoreLink frame])) / 2,
1608 } 1642 yOffset)];
1609 [tutorialOkButton setFrameSize:NSMakeSize( 1643 [tutorialOkButton setFrameSize:NSMakeSize(
1610 availableWidth, NSHeight([tutorialOkButton frame]))]; 1644 availableWidth, NSHeight([tutorialOkButton frame]))];
1611 [tutorialOkButton setFrameOrigin:NSMakePoint( 1645 [tutorialOkButton setFrameOrigin:NSMakePoint(
1612 kHorizontalSpacing, 1646 kHorizontalSpacing,
1613 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; 1647 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))];
1614 } else { 1648 } else {
1615 if (buttonMessage) { 1649 if (buttonMessage) {
1616 NSSize buttonSize = [tutorialOkButton frame].size; 1650 NSSize buttonSize = [tutorialOkButton frame].size;
1617 const CGFloat kTopBottomTextPadding = 6; 1651 const CGFloat kTopBottomTextPadding = 6;
1618 const CGFloat kLeftRightTextPadding = 15; 1652 const CGFloat kLeftRightTextPadding = 15;
1619 buttonSize.width += 2 * kLeftRightTextPadding; 1653 buttonSize.width += 2 * kLeftRightTextPadding;
1620 buttonSize.height += 2 * kTopBottomTextPadding; 1654 buttonSize.height += 2 * kTopBottomTextPadding;
1621 [tutorialOkButton setFrameSize:buttonSize]; 1655 [tutorialOkButton setFrameSize:buttonSize];
1622 CGFloat buttonXOffset = kFixedMenuWidth - 1656 CGFloat buttonXOffset = GetFixedMenuWidth() -
1623 NSWidth([tutorialOkButton frame]) - kHorizontalSpacing; 1657 NSWidth([tutorialOkButton frame]) -
1658 kHorizontalSpacing;
1624 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; 1659 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)];
1625 } 1660 }
1626 1661
1627 if (linkMessage) { 1662 if (linkMessage) {
1628 CGFloat linkYOffset = yOffset; 1663 CGFloat linkYOffset = yOffset;
1629 if (buttonMessage) { 1664 if (buttonMessage) {
1630 linkYOffset += (NSHeight([tutorialOkButton frame]) - 1665 linkYOffset += (NSHeight([tutorialOkButton frame]) -
1631 NSHeight([learnMoreLink frame])) / 2; 1666 NSHeight([learnMoreLink frame])) / 2;
1632 } 1667 }
1633 [learnMoreLink setFrameOrigin:NSMakePoint( 1668 [learnMoreLink setFrameOrigin:NSMakePoint(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1673 NSImage* closeImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); 1708 NSImage* closeImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage();
1674 CGFloat closeImageWidth = [closeImage size].width; 1709 CGFloat closeImageWidth = [closeImage size].width;
1675 [closeButton setDefaultImage:closeImage]; 1710 [closeButton setDefaultImage:closeImage];
1676 [closeButton setHoverImage: 1711 [closeButton setHoverImage:
1677 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()]; 1712 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()];
1678 [closeButton setPressedImage: 1713 [closeButton setPressedImage:
1679 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()]; 1714 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()];
1680 [closeButton setTarget:self]; 1715 [closeButton setTarget:self];
1681 [closeButton setAction:@selector(dismissTutorial:)]; 1716 [closeButton setAction:@selector(dismissTutorial:)];
1682 [closeButton setFrameSize:[closeImage size]]; 1717 [closeButton setFrameSize:[closeImage size]];
1683 [closeButton setFrameOrigin:NSMakePoint( 1718 [closeButton
1684 kFixedMenuWidth - kHorizontalSpacing - closeImageWidth, yOffset)]; 1719 setFrameOrigin:NSMakePoint(GetFixedMenuWidth() - kHorizontalSpacing -
1720 closeImageWidth,
1721 yOffset)];
1685 [container addSubview:closeButton]; 1722 [container addSubview:closeButton];
1686 1723
1687 [titleLabel setFrameSize:NSMakeSize( 1724 [titleLabel setFrameSize:NSMakeSize(
1688 availableWidth - closeImageWidth - kHorizontalSpacing, 0)]; 1725 availableWidth - closeImageWidth - kHorizontalSpacing, 0)];
1689 } else { 1726 } else {
1690 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; 1727 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1691 } 1728 }
1692 1729
1693 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; 1730 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel];
1694 [container addSubview:titleLabel]; 1731 [container addSubview:titleLabel];
1695 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; 1732 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing;
1696 1733
1697 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 1734 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1698 [container setFrameOrigin:NSZeroPoint]; 1735 [container setFrameOrigin:NSZeroPoint];
1699 return container.autorelease(); 1736 return container.autorelease();
1700 } 1737 }
1701 1738
1702 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { 1739 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item {
1703 base::scoped_nsobject<NSView> container([[NSView alloc] 1740 base::scoped_nsobject<NSView> container([[NSView alloc]
1704 initWithFrame:NSZeroRect]); 1741 initWithFrame:NSZeroRect]);
1705 1742
1706 CGFloat xOffset = kHorizontalSpacing; 1743 CGFloat xOffset = kHorizontalSpacing;
1707 CGFloat yOffset = 0; 1744 CGFloat yOffset = 0;
1708 CGFloat availableTextWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; 1745 CGFloat availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing;
1709 CGFloat maxAvailableTextWidth = kFixedMenuWidth - kHorizontalSpacing; 1746 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing;
1710 1747
1711 // Profile options. This can be a link to the accounts view, the profile's 1748 // Profile options. This can be a link to the accounts view, the profile's
1712 // username for signed in users, or a "Sign in" button for local profiles. 1749 // username for signed in users, or a "Sign in" button for local profiles.
1713 SigninManagerBase* signinManager = 1750 SigninManagerBase* signinManager =
1714 SigninManagerFactory::GetForProfile( 1751 SigninManagerFactory::GetForProfile(
1715 browser_->profile()->GetOriginalProfile()); 1752 browser_->profile()->GetOriginalProfile());
1716 if (!isGuestSession_ && signinManager->IsSigninAllowed()) { 1753 if (!isGuestSession_ && signinManager->IsSigninAllowed()) {
1717 NSView* linksContainer = [self 1754 NSView* linksContainer = [self
1718 createCurrentProfileLinksForItem:item 1755 createCurrentProfileLinksForItem:item
1719 rect:NSMakeRect(xOffset, yOffset, 1756 rect:NSMakeRect(xOffset, yOffset,
(...skipping 15 matching lines...) Expand all
1735 profileName:base::SysUTF16ToNSString( 1772 profileName:base::SysUTF16ToNSString(
1736 profiles::GetAvatarNameForProfile( 1773 profiles::GetAvatarNameForProfile(
1737 browser_->profile()->GetPath())) 1774 browser_->profile()->GetPath()))
1738 editingAllowed:editingAllowed 1775 editingAllowed:editingAllowed
1739 withController:self]); 1776 withController:self]);
1740 1777
1741 [container addSubview:profileName]; 1778 [container addSubview:profileName];
1742 yOffset = NSMaxY([profileName frame]) + 4; // Adds a small vertical padding. 1779 yOffset = NSMaxY([profileName frame]) + 4; // Adds a small vertical padding.
1743 1780
1744 // Profile icon, centered. 1781 // Profile icon, centered.
1745 xOffset = (kFixedMenuWidth - kLargeImageSide) / 2; 1782 xOffset = (GetFixedMenuWidth() - kLargeImageSide) / 2;
1746 base::scoped_nsobject<EditableProfilePhoto> iconView( 1783 base::scoped_nsobject<EditableProfilePhoto> iconView(
1747 [[EditableProfilePhoto alloc] 1784 [[EditableProfilePhoto alloc]
1748 initWithFrame:NSMakeRect(xOffset, yOffset, 1785 initWithFrame:NSMakeRect(xOffset, yOffset,
1749 kLargeImageSide, kLargeImageSide) 1786 kLargeImageSide, kLargeImageSide)
1750 avatarMenu:avatarMenu_.get() 1787 avatarMenu:avatarMenu_.get()
1751 profileIcon:item.icon 1788 profileIcon:item.icon
1752 editingAllowed:!isGuestSession_ 1789 editingAllowed:!isGuestSession_
1753 withController:self]); 1790 withController:self]);
1754 1791
1755 [container addSubview:iconView]; 1792 [container addSubview:iconView];
1756 yOffset = NSMaxY([iconView frame]); 1793 yOffset = NSMaxY([iconView frame]);
1757 1794
1758 if (browser_->profile()->IsSupervised()) { 1795 if (browser_->profile()->IsSupervised()) {
1759 base::scoped_nsobject<NSImageView> supervisedIcon( 1796 base::scoped_nsobject<NSImageView> supervisedIcon(
1760 [[NSImageView alloc] initWithFrame:NSZeroRect]); 1797 [[NSImageView alloc] initWithFrame:NSZeroRect]);
1761 int imageId = browser_->profile()->IsChild() 1798 int imageId = browser_->profile()->IsChild()
1762 ? IDR_ICON_PROFILES_MENU_CHILD 1799 ? IDR_ICON_PROFILES_MENU_CHILD
1763 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED; 1800 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
1764 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 1801 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
1765 [supervisedIcon setImage:rb->GetNativeImageNamed(imageId).ToNSImage()]; 1802 [supervisedIcon setImage:rb->GetNativeImageNamed(imageId).ToNSImage()];
1766 NSSize size = [[supervisedIcon image] size]; 1803 NSSize size = [[supervisedIcon image] size];
1767 [supervisedIcon setFrameSize:size]; 1804 [supervisedIcon setFrameSize:size];
1768 NSRect parentFrame = [iconView frame]; 1805 NSRect parentFrame = [iconView frame];
1769 [supervisedIcon setFrameOrigin:NSMakePoint(NSMaxX(parentFrame) - size.width, 1806 [supervisedIcon setFrameOrigin:NSMakePoint(NSMaxX(parentFrame) - size.width,
1770 NSMinY(parentFrame))]; 1807 NSMinY(parentFrame))];
1771 [container addSubview:supervisedIcon]; 1808 [container addSubview:supervisedIcon];
1772 } 1809 }
1773 1810
1774 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 1811 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1812 return container.autorelease();
1813 }
1814
1815 - (NSView*)createMaterialDesignCurrentProfileView:
1816 (const AvatarMenu::Item&)item {
1817 base::scoped_nsobject<NSView> container(
1818 [[NSView alloc] initWithFrame:NSZeroRect]);
1819
1820 CGFloat xOffset = kHorizontalSpacing;
1821 CGFloat yOffset = 0.0;
1822 CGFloat cardYOffset = kRelatedControllVerticalSpacing;
1823 CGFloat availableTextWidth =
1824 GetFixedMenuWidth() - 3.0 * kHorizontalSpacing - kMdImageSide;
1825 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing;
1826
1827 // Profile options. This can be a link to the accounts view, or a "Sign in"
1828 // button for local profiles.
1829 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile(
1830 browser_->profile()->GetOriginalProfile());
1831 NSRect profileLinksBound = NSZeroRect;
1832 if (item.signed_in && switches::IsEnableAccountConsistency()) {
1833 profileLinksBound = NSMakeRect(0, 0, GetFixedMenuWidth(), kVerticalSpacing);
1834 } else if (!item.signed_in && signinManager->IsSigninAllowed()) {
1835 profileLinksBound = NSMakeRect(xOffset, kRelatedControllVerticalSpacing,
1836 maxAvailableTextWidth, kVerticalSpacing);
1837 }
1838 if (!NSIsEmptyRect(profileLinksBound)) {
1839 NSView* linksContainer =
1840 [self createCurrentProfileLinksForItem:item rect:profileLinksBound];
1841 [container addSubview:linksContainer];
1842 yOffset = NSMaxY([linksContainer frame]);
1843 }
1844
1845 // Profile card button that contains the profile icon, name, and username.
1846 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(),
1847 kMdImageSide + kVerticalSpacing);
1848 NSButton* profileCard = [self hoverButtonWithRect:rect
1849 text:[[NSString alloc] init]
1850 action:@selector(editProfile:)];
1851 [container addSubview:profileCard];
1852 if (isGuestSession_)
1853 [profileCard setEnabled:NO];
1854
1855 // Profile icon, left-aligned.
1856 base::scoped_nsobject<NSImageView> iconView([[NSImageView alloc]
1857 initWithFrame:NSMakeRect(xOffset, cardYOffset, kMdImageSide,
1858 kMdImageSide)]);
1859 [iconView setImage:CreateProfileImage(item.icon, kMdImageSide,
1860 profiles::SHAPE_CIRCLE)];
1861 [profileCard addSubview:iconView];
1862
1863 // Profile name, left-aligned to the right of profile icon.
1864 xOffset += kMdImageSide + kHorizontalSpacing;
1865 CGFloat fontSize = kTextFontSize + 1.0;
1866 NSTextField* profileName = BuildLabel(
1867 base::SysUTF16ToNSString(
1868 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())),
1869 NSZeroPoint, nil);
1870 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail];
1871 [profileName setFont:[NSFont labelFontOfSize:fontSize]];
1872 [profileName
1873 setFrame:NSMakeRect(
1874 xOffset,
1875 cardYOffset +
1876 (kMdImageSide - [profileName frame].size.height) / 2,
1877 availableTextWidth, [profileName frame].size.height)];
1878 [profileCard addSubview:profileName];
1879
1880 // Username, left-aligned to the right of profile icon and below the profile
1881 // name.
1882 if (item.signed_in && !switches::IsEnableAccountConsistency()) {
1883 // Adjust the y-position of profile name to leave space for username.
1884 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height;
1885 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)];
1886
1887 NSTextField* username = BuildLabel(
1888 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth),
1889 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY));
1890 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))];
1891 [profileCard addSubview:username];
1892 }
1893
1894 // Profile badge for supervised account.
1895 if (browser_->profile()->IsSupervised()) {
1896 base::scoped_nsobject<NSImageView> supervisedIcon(
1897 [[NSImageView alloc] initWithFrame:NSZeroRect]);
1898 // TODO(janeliulwq): Replace the following two profile badge icons with
1899 // smaller versions of them (24 x 24) to adapt to smaller profile icons.
1900 int imageId = browser_->profile()->IsChild()
1901 ? IDR_ICON_PROFILES_MENU_CHILD
1902 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
1903 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1904 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()];
1905
1906 NSSize size = [[supervisedIcon image] size];
1907 [supervisedIcon setFrameSize:size];
1908 NSRect profileIconFrame = [iconView frame];
1909 const int badgeSpacing = 4;
1910 [supervisedIcon setFrameOrigin:NSMakePoint(NSMaxX(profileIconFrame) -
1911 size.width + badgeSpacing,
1912 NSMaxY(profileIconFrame) -
1913 size.height + badgeSpacing)];
1914 [profileCard addSubview:supervisedIcon];
1915 }
1916
1917 yOffset = NSMaxY([profileCard frame]);
1918 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1775 return container.autorelease(); 1919 return container.autorelease();
1776 } 1920 }
1777 1921
1778 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 1922 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
1779 rect:(NSRect)rect { 1923 rect:(NSRect)rect {
1924 if (switches::IsMaterialDesignUserMenu()) {
1925 // The branch is empty for material design user menu in non-account-
1926 // consistency mode, because in that case, the username would appear in the
1927 // profile card instead of as a separate link here.
1928 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile(
1929 browser_->profile()->GetOriginalProfile());
1930 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) ||
1931 (!item.signed_in && signinManager->IsSigninAllowed()));
1932 }
1933
1780 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 1934 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
1781 1935
1782 // Don't double-apply the left margin to the sub-views. 1936 // Don't double-apply the left margin to the sub-views.
1783 rect.origin.x = 0; 1937 rect.origin.x = 0;
1784 1938
1785 // Adds right padding. 1939 // Adds right padding.
1786 const CGFloat kRightPadding = kHorizontalSpacing; 1940 const CGFloat kRightPadding = kHorizontalSpacing;
1787 rect.size.width -= kRightPadding; 1941 rect.size.width -= kRightPadding;
1788 1942
1789 // The available links depend on the type of profile that is active. 1943 // The available links depend on the type of profile that is active.
1790 if (item.signed_in) { 1944 if (item.signed_in) {
1791 // Signed in profiles with no authentication errors do not have a clickable
1792 // email link.
1793 NSButton* link = nil; 1945 NSButton* link = nil;
1794 if (switches::IsEnableAccountConsistency()) { 1946 if (switches::IsEnableAccountConsistency()) {
1795 NSString* linkTitle = l10n_util::GetNSString( 1947 NSString* linkTitle = l10n_util::GetNSString(
1796 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? 1948 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ?
1797 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : 1949 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
1798 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 1950 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
1799 SEL linkSelector = 1951 SEL linkSelector =
1800 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? 1952 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ?
1801 @selector(showAccountManagement:) : @selector(hideAccountManagement:); 1953 @selector(showAccountManagement:) : @selector(hideAccountManagement:);
1802 link = [self linkButtonWithTitle:linkTitle 1954 if (switches::IsMaterialDesignUserMenu()) {
1803 frameOrigin:rect.origin 1955 rect.size.width +=
1804 action:linkSelector]; 1956 kRightPadding; // Spans the width of the entire menu.
1805 } else { 1957 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width,
1958 kBlueButtonHeight)
1959 text:linkTitle
1960 action:linkSelector];
1961 } else {
1962 link = [self linkButtonWithTitle:linkTitle
1963 frameOrigin:rect.origin
1964 action:linkSelector];
1965 }
1966 } else if (!switches::IsMaterialDesignUserMenu()) {
1806 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.username) 1967 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.username)
1807 frameOrigin:rect.origin 1968 frameOrigin:rect.origin
1808 action:nil]; 1969 action:nil];
1809 if (HasAuthError(browser_->profile())) { 1970 if (HasAuthError(browser_->profile())) {
1810 [link setImage:ui::ResourceBundle::GetSharedInstance(). 1971 [link setImage:ui::ResourceBundle::GetSharedInstance().
1811 GetNativeImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR). 1972 GetNativeImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).
1812 ToNSImage()]; 1973 ToNSImage()];
1813 [link setImagePosition:NSImageRight]; 1974 [link setImagePosition:NSImageRight];
1814 [link setTarget:self]; 1975 [link setTarget:self];
1815 [link setAction:@selector(showAccountReauthenticationView:)]; 1976 [link setAction:@selector(showAccountReauthenticationView:)];
1816 [link setTag:kPrimaryProfileTag]; 1977 [link setTag:kPrimaryProfileTag];
1817 [[link cell] 1978 [[link cell]
1818 accessibilitySetOverrideValue:l10n_util::GetNSStringF( 1979 accessibilitySetOverrideValue:l10n_util::GetNSStringF(
1819 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME, 1980 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME,
1820 item.username) 1981 item.username)
1821 forAttribute:NSAccessibilityTitleAttribute]; 1982 forAttribute:NSAccessibilityTitleAttribute];
1822 } else { 1983 } else {
1984 // Signed in profiles with no authentication errors do not have a
1985 // clickable email link.
1823 [link setEnabled:NO]; 1986 [link setEnabled:NO];
1824 } 1987 }
1825 } 1988 }
1826 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but 1989 if (link) {
1827 // need to re-stretch the width so that the link can be centered correctly 1990 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but
1828 // in the view. 1991 // need to re-stretch the width so that the link can be centered correctly
1829 rect.size.height = [link frame].size.height; 1992 // in the view.
1830 [link setAlignment:NSCenterTextAlignment]; 1993 rect.size.height = [link frame].size.height;
1831 [link setFrame:rect]; 1994 if (!switches::IsMaterialDesignUserMenu())
1832 [container addSubview:link]; 1995 [link setAlignment:NSCenterTextAlignment];
1833 [container setFrameSize:rect.size]; 1996 [link setFrame:rect];
1997 [container addSubview:link];
1998 [container setFrameSize:rect.size];
1999 }
1834 } else { 2000 } else {
1835 rect.size.height = kBlueButtonHeight; 2001 rect.size.height = kBlueButtonHeight;
1836 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect]; 2002 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect];
1837 2003
1838 // Manually elide the button text so that the contents fit inside the bubble 2004 // Manually elide the button text so that the contents fit inside the bubble
1839 // This is needed because the BlueLabelButton cell resets the style on 2005 // This is needed because the BlueLabelButton cell resets the style on
1840 // every call to -cellSize, which prevents setting a custom lineBreakMode. 2006 // every call to -cellSize, which prevents setting a custom lineBreakMode.
1841 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( 2007 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText(
1842 l10n_util::GetStringFUTF16( 2008 l10n_util::GetStringFUTF16(
1843 IDS_SYNC_START_SYNC_BUTTON_LABEL, 2009 IDS_SYNC_START_SYNC_BUTTON_LABEL,
1844 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), 2010 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)),
1845 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); 2011 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL));
1846 2012
1847 [signinButton setTitle:elidedButtonText]; 2013 [signinButton setTitle:elidedButtonText];
2014 if (switches::IsMaterialDesignUserMenu())
2015 [signinButton sizeToFit];
1848 [signinButton setTarget:self]; 2016 [signinButton setTarget:self];
1849 [signinButton setAction:@selector(showInlineSigninPage:)]; 2017 [signinButton setAction:@selector(showInlineSigninPage:)];
1850 [container addSubview:signinButton]; 2018 [container addSubview:signinButton];
1851 2019
1852 // Sign-in promo text. 2020 // Sign-in promo text.
1853 NSTextField* promo = BuildLabel( 2021 NSTextField* promo = BuildLabel(
1854 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), 2022 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO),
1855 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), 2023 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing),
1856 nil); 2024 nil);
1857 if (kRightPadding >= 8) 2025 if (kRightPadding >= 8)
1858 rect.size.width += 8; // Re-stretch a little bit to fit promo text. 2026 rect.size.width += 8; // Re-stretch a little bit to fit promo text.
1859 DCHECK(kRightPadding >= 8); 2027 DCHECK(kRightPadding >= 8);
1860 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; 2028 [promo setFrameSize:NSMakeSize(rect.size.width, 0)];
1861 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; 2029 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo];
1862 [container addSubview:promo]; 2030 [container addSubview:promo];
1863 2031
1864 [container setFrameSize:NSMakeSize( 2032 [container
1865 rect.size.width, 2033 setFrameSize:NSMakeSize(rect.size.width,
1866 NSMaxY([promo frame]) + 4)]; // Adds a small vertical padding. 2034 NSMaxY([promo frame]) +
2035 (switches::IsMaterialDesignUserMenu()
2036 ? kRelatedControllVerticalSpacing
2037 : 4))];
1867 content::RecordAction( 2038 content::RecordAction(
1868 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); 2039 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
1869 } 2040 }
1870 2041
1871 return container.autorelease(); 2042 return container.autorelease();
1872 } 2043 }
1873 2044
1874 - (NSView*)createSupervisedUserDisclaimerView { 2045 - (NSView*)createSupervisedUserDisclaimerView {
1875 base::scoped_nsobject<NSView> container( 2046 base::scoped_nsobject<NSView> container(
1876 [[NSView alloc] initWithFrame:NSZeroRect]); 2047 [[NSView alloc] initWithFrame:NSZeroRect]);
1877 2048
1878 int yOffset = 0; 2049 int yOffset = 0;
1879 int availableTextWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; 2050 int availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing;
1880 2051
1881 NSTextField* disclaimer = BuildLabel( 2052 NSTextField* disclaimer = BuildLabel(
1882 base::SysUTF16ToNSString(avatarMenu_->GetSupervisedUserInformation()), 2053 base::SysUTF16ToNSString(avatarMenu_->GetSupervisedUserInformation()),
1883 NSMakePoint(kHorizontalSpacing, yOffset), nil); 2054 NSMakePoint(kHorizontalSpacing, yOffset), nil);
1884 [disclaimer setFrameSize:NSMakeSize(availableTextWidth, 0)]; 2055 [disclaimer setFrameSize:NSMakeSize(availableTextWidth, 0)];
1885 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:disclaimer]; 2056 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:disclaimer];
1886 yOffset = NSMaxY([disclaimer frame]); 2057 yOffset = NSMaxY([disclaimer frame]);
1887 2058
1888 [container addSubview:disclaimer]; 2059 [container addSubview:disclaimer];
1889 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; 2060 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1890 return container.autorelease(); 2061 return container.autorelease();
1891 } 2062 }
1892 2063
1893 - (NSView*)createGuestProfileView { 2064 - (NSView*)createGuestProfileView {
1894 gfx::Image guestIcon = 2065 gfx::Image guestIcon =
1895 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 2066 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
1896 profiles::GetPlaceholderAvatarIconResourceID()); 2067 profiles::GetPlaceholderAvatarIconResourceID());
1897 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ 2068 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */
1898 base::FilePath(), /* profile_path, not used */ 2069 base::FilePath(), /* profile_path, not used */
1899 guestIcon); 2070 guestIcon);
1900 guestItem.active = true; 2071 guestItem.active = true;
1901 guestItem.name = base::SysNSStringToUTF16( 2072 guestItem.name = base::SysNSStringToUTF16(
1902 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); 2073 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME));
1903 2074
1904 return [self createCurrentProfileView:guestItem]; 2075 return switches::IsMaterialDesignUserMenu()
2076 ? [self createMaterialDesignCurrentProfileView:guestItem]
2077 : [self createCurrentProfileView:guestItem];
1905 } 2078 }
1906 2079
1907 - (NSButton*)createOtherProfileView:(int)itemIndex { 2080 - (NSButton*)createOtherProfileView:(int)itemIndex {
1908 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); 2081 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex);
1909 2082
1910 NSRect rect = NSMakeRect( 2083 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(),
1911 0, 0, kFixedMenuWidth, kBlueButtonHeight + kSmallVerticalSpacing); 2084 kBlueButtonHeight + kSmallVerticalSpacing);
1912 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( 2085 base::scoped_nsobject<BackgroundColorHoverButton> profileButton(
1913 [[BackgroundColorHoverButton alloc] 2086 [[BackgroundColorHoverButton alloc]
1914 initWithFrame:rect 2087 initWithFrame:rect
1915 imageTitleSpacing:kImageTitleSpacing 2088 imageTitleSpacing:kImageTitleSpacing
1916 backgroundColor:GetDialogBackgroundColor()]); 2089 backgroundColor:GetDialogBackgroundColor()]);
1917 2090
1918 NSString* title = base::SysUTF16ToNSString( 2091 NSString* title = base::SysUTF16ToNSString(
1919 profiles::GetProfileSwitcherTextForItem(item)); 2092 profiles::GetProfileSwitcherTextForItem(item));
1920 [profileButton setTitle:title]; 2093 [profileButton setTitle:title];
1921 2094
1922 // Use the low-res, small default avatars in the fast user switcher, like 2095 // Use the low-res, small default avatars in the fast user switcher, like
1923 // we do in the menu bar. 2096 // we do in the menu bar.
1924 gfx::Image itemIcon; 2097 gfx::Image itemIcon;
1925 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon); 2098 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon);
1926 2099
1927 [profileButton setDefaultImage:CreateProfileImage( 2100 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide,
1928 itemIcon, kSmallImageSide).ToNSImage()]; 2101 profiles::SHAPE_SQUARE)];
1929 [profileButton setImagePosition:NSImageLeft]; 2102 [profileButton setImagePosition:NSImageLeft];
1930 [profileButton setAlignment:NSLeftTextAlignment]; 2103 [profileButton setAlignment:NSLeftTextAlignment];
1931 [profileButton setBordered:NO]; 2104 [profileButton setBordered:NO];
1932 [profileButton setTag:itemIndex]; 2105 [profileButton setTag:itemIndex];
1933 [profileButton setTarget:self]; 2106 [profileButton setTarget:self];
1934 [profileButton setAction:@selector(switchToProfile:)]; 2107 [profileButton setAction:@selector(switchToProfile:)];
1935 2108
1936 NSSize textSize = [[profileButton title] sizeWithAttributes:@{ 2109 NSSize textSize = [[profileButton title] sizeWithAttributes:@{
1937 NSFontAttributeName : [profileButton font] 2110 NSFontAttributeName : [profileButton font]
1938 }]; 2111 }];
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
2285 clickedOnLink:(id)link 2458 clickedOnLink:(id)link
2286 atIndex:(NSUInteger)charIndex { 2459 atIndex:(NSUInteger)charIndex {
2287 chrome::ShowSettings(browser_); 2460 chrome::ShowSettings(browser_);
2288 return YES; 2461 return YES;
2289 } 2462 }
2290 2463
2291 - (NSButton*)hoverButtonWithRect:(NSRect)rect 2464 - (NSButton*)hoverButtonWithRect:(NSRect)rect
2292 text:(NSString*)text 2465 text:(NSString*)text
2293 imageResourceId:(int)imageResourceId 2466 imageResourceId:(int)imageResourceId
2294 action:(SEL)action { 2467 action:(SEL)action {
2295 base::scoped_nsobject<BackgroundColorHoverButton> button( 2468 BackgroundColorHoverButton* button =
2296 [[BackgroundColorHoverButton alloc] 2469 [self hoverButtonWithRect:rect text:text action:action];
2297 initWithFrame:rect
2298 imageTitleSpacing:kImageTitleSpacing
2299 backgroundColor:GetDialogBackgroundColor()]);
2300
2301 [button setTitle:text];
2302 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 2470 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
2303 NSImage* image = rb->GetNativeImageNamed(imageResourceId).ToNSImage(); 2471 NSImage* image = rb->GetNativeImageNamed(imageResourceId).ToNSImage();
2304 [button setDefaultImage:image]; 2472 [button setDefaultImage:image];
2305 [button setHoverImage:image]; 2473 [button setHoverImage:image];
2306 [button setPressedImage:image]; 2474 [button setPressedImage:image];
2307 [button setImagePosition:NSImageLeft]; 2475 [button setImagePosition:NSImageLeft];
2476
2477 return button;
2478 }
2479
2480 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect
2481 text:(NSString*)text
2482 action:(SEL)action {
2483 base::scoped_nsobject<BackgroundColorHoverButton> button(
2484 [[BackgroundColorHoverButton alloc]
2485 initWithFrame:rect
2486 imageTitleSpacing:kImageTitleSpacing
2487 backgroundColor:GetDialogBackgroundColor()]);
2488
2489 [button setTitle:text];
2308 [button setAlignment:NSLeftTextAlignment]; 2490 [button setAlignment:NSLeftTextAlignment];
2309 [button setBordered:NO]; 2491 [button setBordered:NO];
2310 [button setTarget:self]; 2492 [button setTarget:self];
2311 [button setAction:action]; 2493 [button setAction:action];
2312 2494
2313 return button.autorelease(); 2495 return button.autorelease();
2314 } 2496 }
2315 2497
2316 - (NSButton*)linkButtonWithTitle:(NSString*)title 2498 - (NSButton*)linkButtonWithTitle:(NSString*)title
2317 frameOrigin:(NSPoint)frameOrigin 2499 frameOrigin:(NSPoint)frameOrigin
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
2400 } 2582 }
2401 2583
2402 - (bool)shouldShowGoIncognito { 2584 - (bool)shouldShowGoIncognito {
2403 bool incognitoAvailable = 2585 bool incognitoAvailable =
2404 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2586 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2405 IncognitoModePrefs::DISABLED; 2587 IncognitoModePrefs::DISABLED;
2406 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2588 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2407 } 2589 }
2408 2590
2409 @end 2591 @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