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

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