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

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

Issue 2708073002: Removing pre-material design menu setting. (Closed)
Patch Set: Replacing functions by variables Created 3 years, 9 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
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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 #include "ui/gfx/text_elider.h" 87 #include "ui/gfx/text_elider.h"
88 #include "ui/gfx/vector_icons_public.h" 88 #include "ui/gfx/vector_icons_public.h"
89 #include "ui/native_theme/common_theme.h" 89 #include "ui/native_theme/common_theme.h"
90 #include "ui/native_theme/native_theme.h" 90 #include "ui/native_theme/native_theme.h"
91 91
92 namespace { 92 namespace {
93 93
94 // Constants taken from the Windows/Views implementation at: 94 // Constants taken from the Windows/Views implementation at:
95 // chrome/browser/ui/views/profile_chooser_view.cc 95 // chrome/browser/ui/views/profile_chooser_view.cc
96 const int kLargeImageSide = 88; 96 const int kLargeImageSide = 88;
97 const int kSmallImageSide = 32;
98 const int kMdImageSide = 40; 97 const int kMdImageSide = 40;
99 98
99 const CGFloat kFixedMenuWidth = 240.0;
100 const int kIconImageSide = 18;
100 const CGFloat kVerticalSpacing = 16.0; 101 const CGFloat kVerticalSpacing = 16.0;
101 const CGFloat kSmallVerticalSpacing = 10.0; 102 const CGFloat kSmallVerticalSpacing = 10.0;
102 const CGFloat kRelatedControllVerticalSpacing = 8.0; 103 const CGFloat kRelatedControllVerticalSpacing = 8.0;
103 const CGFloat kHorizontalSpacing = 16.0; 104 const CGFloat kHorizontalSpacing = 16.0;
104 const CGFloat kTitleFontSize = 15.0; 105 const CGFloat kTitleFontSize = 15.0;
105 const CGFloat kTextFontSize = 12.0; 106 const CGFloat kTextFontSize = 12.0;
106 const CGFloat kProfileButtonHeight = 30; 107 const CGFloat kProfileButtonHeight = 30;
107 const int kBezelThickness = 3; // Width of the bezel on an NSButton. 108 const int kBezelThickness = 3; // Width of the bezel on an NSButton.
108 const int kImageTitleSpacing = 10;
109 const int kBlueButtonHeight = 30; 109 const int kBlueButtonHeight = 30;
110 const CGFloat kFocusRingLineWidth = 2; 110 const CGFloat kFocusRingLineWidth = 2;
111 111
112 // Fixed size for embedded sign in pages as defined in Gaia. 112 // Fixed size for embedded sign in pages as defined in Gaia.
113 const CGFloat kFixedGaiaViewWidth = 360; 113 const CGFloat kFixedGaiaViewWidth = 360;
114 114
115 // Fixed size for the account removal view. 115 // Fixed size for the account removal view.
116 const CGFloat kFixedAccountRemovalViewWidth = 280; 116 const CGFloat kFixedAccountRemovalViewWidth = 280;
117 117
118 // Fixed size for the switch user view. 118 // Fixed size for the switch user view.
119 const int kFixedSwitchUserViewWidth = 320; 119 const int kFixedSwitchUserViewWidth = 320;
120 120
121 // The tag number for the primary account. 121 // The tag number for the primary account.
122 const int kPrimaryProfileTag = -1; 122 const int kPrimaryProfileTag = -1;
123 123
124 CGFloat GetFixedMenuWidth() {
125 return switches::IsMaterialDesignUserMenu() ? 240.0 : 250.0;
126 }
127
128 NSImage* CreateProfileImage(const gfx::Image& icon, 124 NSImage* CreateProfileImage(const gfx::Image& icon,
129 int imageSize, 125 int imageSize,
130 profiles::AvatarShape shape) { 126 profiles::AvatarShape shape) {
131 return (profiles::GetSizedAvatarIcon(icon, true /* image is a square */, 127 return (profiles::GetSizedAvatarIcon(icon, true /* image is a square */,
132 imageSize, imageSize, shape)) 128 imageSize, imageSize, shape))
133 .ToNSImage(); 129 .ToNSImage();
134 } 130 }
135 131
136 // Updates the window size and position. 132 // Updates the window size and position.
137 void SetWindowSize(NSWindow* window, NSSize size) { 133 void SetWindowSize(NSWindow* window, NSSize size) {
(...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after
854 850
855 [self setBordered:NO]; 851 [self setBordered:NO];
856 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; 852 [self setFont:[NSFont labelFontOfSize:kTextFontSize]];
857 [self setButtonType:NSMomentaryChangeButton]; 853 [self setButtonType:NSMomentaryChangeButton];
858 854
859 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( 855 base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
860 [[CustomPaddingImageButtonCell alloc] 856 [[CustomPaddingImageButtonCell alloc]
861 initWithLeftMarginSpacing:kHorizontalSpacing 857 initWithLeftMarginSpacing:kHorizontalSpacing
862 imageTitleSpacing:imageTitleSpacing]); 858 imageTitleSpacing:imageTitleSpacing]);
863 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; 859 [cell setLineBreakMode:NSLineBreakByTruncatingTail];
864 if (switches::IsMaterialDesignUserMenu()) 860 [cell setHighlightsBy:NSNoCellMask];
865 [cell setHighlightsBy:NSNoCellMask];
866 [self setCell:cell.get()]; 861 [self setCell:cell.get()];
867 } 862 }
868 return self; 863 return self;
869 } 864 }
870 865
871 - (void)setRightMarginSpacing:(int)rightMarginSpacing { 866 - (void)setRightMarginSpacing:(int)rightMarginSpacing {
872 [[self cell] setRightMarginSpacing:rightMarginSpacing]; 867 [[self cell] setRightMarginSpacing:rightMarginSpacing];
873 } 868 }
874 869
875 - (void)drawRect:(NSRect)dirtyRect { 870 - (void)drawRect:(NSRect)dirtyRect {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
958 tutorialView:(NSView*)tutorialView 953 tutorialView:(NSView*)tutorialView
959 syncErrorView:(NSView*)syncErrorView 954 syncErrorView:(NSView*)syncErrorView
960 otherProfiles:(NSArray*)otherProfiles 955 otherProfiles:(NSArray*)otherProfiles
961 atYOffset:(CGFloat)yOffset 956 atYOffset:(CGFloat)yOffset
962 inContainer:(NSView*)container 957 inContainer:(NSView*)container
963 showLock:(bool)showLock; 958 showLock:(bool)showLock;
964 959
965 // Builds the profile chooser view. 960 // Builds the profile chooser view.
966 - (NSView*)buildProfileChooserView; 961 - (NSView*)buildProfileChooserView;
967 962
968 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item;
969
970 // Builds a tutorial card with a title label using |titleMessage|, a content 963 // Builds a tutorial card with a title label using |titleMessage|, a content
971 // label using |contentMessage|, a link using |linkMessage|, and a button using 964 // label using |contentMessage|, a link using |linkMessage|, and a button using
972 // |buttonMessage|. If |stackButton| is YES, places the button above the link. 965 // |buttonMessage|. If |stackButton| is YES, places the button above the link.
973 // Otherwise places both on the same row with the link left aligned and button 966 // Otherwise places both on the same row with the link left aligned and button
974 // right aligned. On click, the link would execute |linkAction|, and the button 967 // right aligned. On click, the link would execute |linkAction|, and the button
975 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. 968 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|.
976 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode 969 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode
977 titleMessage:(NSString*)titleMessage 970 titleMessage:(NSString*)titleMessage
978 contentMessage:(NSString*)contentMessage 971 contentMessage:(NSString*)contentMessage
979 linkMessage:(NSString*)linkMessage 972 linkMessage:(NSString*)linkMessage
(...skipping 19 matching lines...) Expand all
999 // Chrome sync will be delayed until the user either dismisses the tutorial, or 992 // Chrome sync will be delayed until the user either dismisses the tutorial, or
1000 // configures sync through the "Settings" link. 993 // configures sync through the "Settings" link.
1001 - (NSView*)buildSigninConfirmationView; 994 - (NSView*)buildSigninConfirmationView;
1002 995
1003 // Builds a tutorial card to show the last signin error. 996 // Builds a tutorial card to show the last signin error.
1004 - (NSView*)buildSigninErrorView; 997 - (NSView*)buildSigninErrorView;
1005 998
1006 // Creates the main profile card for the profile |item| at the top of 999 // Creates the main profile card for the profile |item| at the top of
1007 // the bubble, for non-material-design and material design user menu 1000 // the bubble, for non-material-design and material design user menu
1008 // respectively. 1001 // respectively.
1009 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item;
1010 - (NSView*)createMaterialDesignCurrentProfileView:(const AvatarMenu::Item&)item; 1002 - (NSView*)createMaterialDesignCurrentProfileView:(const AvatarMenu::Item&)item;
1011 1003
1012 // Creates the possible links for the main profile card with profile |item|. 1004 // Creates the possible links for the main profile card with profile |item|.
1013 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 1005 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
1014 rect:(NSRect)rect; 1006 rect:(NSRect)rect;
1015 1007
1016 // Creates the disclaimer text for supervised users, telling them that the 1008 // Creates the disclaimer text for supervised users, telling them that the
1017 // manager can view their history etc. 1009 // manager can view their history etc.
1018 - (NSView*)createSupervisedUserDisclaimerView; 1010 - (NSView*)createSupervisedUserDisclaimerView;
1019 1011
1020 // Creates a main profile card for the guest user. 1012 // Creates a main profile card for the guest user.
1021 - (NSView*)createGuestProfileView; 1013 - (NSView*)createGuestProfileView;
1022 1014
1023 // Creates an item for the profile |itemIndex| that is used in the fast profile 1015 // Creates an item for the profile |itemIndex| that is used in the fast profile
1024 // switcher view. 1016 // switcher view.
1025 - (NSButton*)createOtherProfileView:(int)itemIndex; 1017 - (NSButton*)createOtherProfileView:(int)itemIndex;
1026 1018
1027 // Creates the following option buttons: lock profile, go incognito, and switch
1028 // user/exit guest.
1029 - (NSView*)createOptionsViewWithRect:(NSRect)rect
1030 showLock:(BOOL)showLock;
1031 // For material design user menu, creates the following option buttons: lock 1019 // For material design user menu, creates the following option buttons: lock
1032 // profile/close all windows, switch user/exit guest, and open guest profile. 1020 // profile/close all windows, switch user/exit guest, and open guest profile.
1033 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)frame 1021 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)frame
1034 showLock:(BOOL)showLock; 1022 showLock:(BOOL)showLock;
1035 1023
1036 // Creates the account management view for the active profile. 1024 // Creates the account management view for the active profile.
1037 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; 1025 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect;
1038 1026
1039 // Creates the list of accounts for the active profile. 1027 // Creates the list of accounts for the active profile.
1040 - (NSView*)createAccountsListWithRect:(NSRect)rect; 1028 - (NSView*)createAccountsListWithRect:(NSRect)rect;
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 [[self window] makeFirstResponder:dummyFocusButton]; 1412 [[self window] makeFirstResponder:dummyFocusButton];
1425 1413
1426 [contentView addSubview:subView]; 1414 [contentView addSubview:subView];
1427 [contentView addSubview:dummyFocusButton]; 1415 [contentView addSubview:dummyFocusButton];
1428 SetWindowSize([self window], 1416 SetWindowSize([self window],
1429 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); 1417 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame])));
1430 } 1418 }
1431 1419
1432 - (CGFloat)addSeparatorToContainer:(NSView*)container 1420 - (CGFloat)addSeparatorToContainer:(NSView*)container
1433 atYOffset:(CGFloat)yOffset { 1421 atYOffset:(CGFloat)yOffset {
1434 NSBox* separator = 1422 NSBox* separator = [self
1435 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, 1423 horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)];
1436 GetFixedMenuWidth(), 0)];
1437 [container addSubview:separator]; 1424 [container addSubview:separator];
1438 return NSMaxY([separator frame]); 1425 return NSMaxY([separator frame]);
1439 } 1426 }
1440 1427
1441 // Builds the fast user switcher view in |container| at |yOffset| and populates 1428 // Builds the fast user switcher view in |container| at |yOffset| and populates
1442 // it with the entries for every profile in |otherProfiles|. Returns the new 1429 // it with the entries for every profile in |otherProfiles|. Returns the new
1443 // yOffset after adding the elements. 1430 // yOffset after adding the elements.
1444 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles 1431 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles
1445 atYOffset:(CGFloat)yOffset 1432 atYOffset:(CGFloat)yOffset
1446 inContainer:(NSView*)container { 1433 inContainer:(NSView*)container {
1447 // Other profiles switcher. The profiles have already been sorted 1434 // Other profiles switcher. The profiles have already been sorted
1448 // by their y-coordinate, so they can be added in the existing order. 1435 // by their y-coordinate, so they can be added in the existing order.
1449 for (NSView* otherProfileView in otherProfiles) { 1436 for (NSView* otherProfileView in otherProfiles) {
1450 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1437 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1451 [container addSubview:otherProfileView]; 1438 [container addSubview:otherProfileView];
1452 yOffset = NSMaxY([otherProfileView frame]); 1439 yOffset = NSMaxY([otherProfileView frame]);
1453
1454 if (!switches::IsMaterialDesignUserMenu())
1455 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1456 } 1440 }
1457 1441
1458 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1442 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
1459 return yOffset; 1443 return yOffset;
1460 } 1444 }
1461 1445
1462 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView 1446 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView
1463 tutorialView:(NSView*)tutorialView 1447 tutorialView:(NSView*)tutorialView
1464 syncErrorView:(NSView*)syncErrorView 1448 syncErrorView:(NSView*)syncErrorView
1465 otherProfiles:(NSArray*)otherProfiles 1449 otherProfiles:(NSArray*)otherProfiles
1466 atYOffset:(CGFloat)yOffset 1450 atYOffset:(CGFloat)yOffset
1467 inContainer:(NSView*)container 1451 inContainer:(NSView*)container
1468 showLock:(bool)showLock { 1452 showLock:(bool)showLock {
1469 if (switches::IsMaterialDesignUserMenu()) 1453 yOffset += kRelatedControllVerticalSpacing;
1470 yOffset += kRelatedControllVerticalSpacing;
1471 1454
1472 // Option buttons. 1455 // Option buttons.
1473 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); 1456 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0);
1474 NSView* optionsView = 1457 NSView* optionsView =
1475 switches::IsMaterialDesignUserMenu() 1458 [self createMaterialDesignOptionsViewWithFrame:rect showLock:showLock];
1476 ? [self createMaterialDesignOptionsViewWithFrame:rect
1477 showLock:showLock]
1478 : [self createOptionsViewWithRect:rect showLock:showLock];
1479 [container addSubview:optionsView]; 1459 [container addSubview:optionsView];
1480 rect.origin.y = NSMaxY([optionsView frame]); 1460 rect.origin.y = NSMaxY([optionsView frame]);
1481 yOffset = rect.origin.y; 1461 yOffset = rect.origin.y;
1482 1462
1483 // For material design user menu, add the fast user switching buttons. 1463 // Add the fast user switching buttons.
1484 if (switches::IsMaterialDesignUserMenu()) { 1464 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles
1485 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles 1465 atYOffset:yOffset
1486 atYOffset:yOffset 1466 inContainer:container];
1487 inContainer:container]; 1467 yOffset += kRelatedControllVerticalSpacing;
1488 yOffset += kRelatedControllVerticalSpacing; 1468 rect.origin.y = yOffset;
1489 rect.origin.y = yOffset;
1490 }
1491 1469
1492 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; 1470 NSBox* separator = [self horizontalSeparatorWithFrame:rect];
1493 [container addSubview:separator]; 1471 [container addSubview:separator];
1494 yOffset = NSMaxY([separator frame]); 1472 yOffset = NSMaxY([separator frame]);
1495 1473
1496 // For supervised users, add the disclaimer text. 1474 // For supervised users, add the disclaimer text.
1497 if (browser_->profile()->IsSupervised()) { 1475 if (browser_->profile()->IsSupervised()) {
1498 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing 1476 yOffset += kVerticalSpacing;
1499 : kSmallVerticalSpacing;
1500 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; 1477 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView];
1501 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; 1478 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)];
1502 [container addSubview:disclaimerContainer]; 1479 [container addSubview:disclaimerContainer];
1503 yOffset = NSMaxY([disclaimerContainer frame]); 1480 yOffset = NSMaxY([disclaimerContainer frame]);
1504
1505 if (!switches::IsMaterialDesignUserMenu()) {
1506 yOffset += kSmallVerticalSpacing;
1507 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1508 }
1509 } 1481 }
1510 1482
1511 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 1483 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
1512 const AvatarMenu::Item& item = 1484 const AvatarMenu::Item& item =
1513 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); 1485 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex());
1514 if (item.signed_in) { 1486 if (item.signed_in) {
1515 NSView* currentProfileAccountsView = [self 1487 NSView* currentProfileAccountsView = [self
1516 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, 1488 createCurrentProfileAccountsView:NSMakeRect(0, yOffset,
1517 GetFixedMenuWidth(), 0)]; 1489 kFixedMenuWidth, 0)];
1518 [container addSubview:currentProfileAccountsView]; 1490 [container addSubview:currentProfileAccountsView];
1519 yOffset = NSMaxY([currentProfileAccountsView frame]); 1491 yOffset = NSMaxY([currentProfileAccountsView frame]);
1520 1492
1521 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; 1493 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1522 } else { 1494 } else {
1523 // This is the case when the user selects the sign out option in the user 1495 // This is the case when the user selects the sign out option in the user
1524 // menu upon encountering unrecoverable errors. Afterwards, the profile 1496 // menu upon encountering unrecoverable errors. Afterwards, the profile
1525 // chooser view is shown instead of the account management view. 1497 // chooser view is shown instead of the account management view.
1526 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 1498 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
1527 } 1499 }
1528 } 1500 }
1529 1501
1530 // Active profile card. 1502 // Active profile card.
1531 if (currentProfileView) { 1503 if (currentProfileView) {
1532 const CGFloat verticalSpacing = switches::IsMaterialDesignUserMenu() 1504 const CGFloat verticalSpacing = kRelatedControllVerticalSpacing;
1533 ? kRelatedControllVerticalSpacing
1534 : kVerticalSpacing;
1535 yOffset += verticalSpacing; 1505 yOffset += verticalSpacing;
1536 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1506 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1537 [container addSubview:currentProfileView]; 1507 [container addSubview:currentProfileView];
1538 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; 1508 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing;
1539 } 1509 }
1540 1510
1541 if (syncErrorView) { 1511 if (syncErrorView) {
1542 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; 1512 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset];
1543 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; 1513 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)];
1544 [container addSubview:syncErrorView]; 1514 [container addSubview:syncErrorView];
1545 yOffset = NSMaxY([syncErrorView frame]); 1515 yOffset = NSMaxY([syncErrorView frame]);
1546 } 1516 }
1547 1517
1548 if (tutorialView) { 1518 if (tutorialView) {
1549 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; 1519 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)];
1550 [container addSubview:tutorialView]; 1520 [container addSubview:tutorialView];
1551 yOffset = NSMaxY([tutorialView frame]); 1521 yOffset = NSMaxY([tutorialView frame]);
1552 //TODO(mlerman): update UMA stats for the new tutorials. 1522 //TODO(mlerman): update UMA stats for the new tutorials.
1553 } else { 1523 } else {
1554 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; 1524 tutorialMode_ = profiles::TUTORIAL_MODE_NONE;
1555 } 1525 }
1556 1526
1557 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1527 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
1558 } 1528 }
1559 1529
1560 - (NSView*)buildProfileChooserView { 1530 - (NSView*)buildProfileChooserView {
1561 base::scoped_nsobject<NSView> container( 1531 base::scoped_nsobject<NSView> container(
1562 [[NSView alloc] initWithFrame:NSZeroRect]); 1532 [[NSView alloc] initWithFrame:NSZeroRect]);
1563 1533
1564 NSView* tutorialView = nil; 1534 NSView* tutorialView = nil;
1565 NSView* syncErrorView = nil; 1535 NSView* syncErrorView = nil;
1566 NSView* currentProfileView = nil; 1536 NSView* currentProfileView = nil;
1567 base::scoped_nsobject<NSMutableArray> otherProfiles( 1537 base::scoped_nsobject<NSMutableArray> otherProfiles(
1568 [[NSMutableArray alloc] init]); 1538 [[NSMutableArray alloc] init]);
1569 // Local and guest profiles cannot lock their profile. 1539 // Local and guest profiles cannot lock their profile.
1570 bool showLock = false; 1540 bool showLock = false;
1571 bool isFastProfileChooser = 1541 bool isFastProfileChooser =
1572 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; 1542 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER;
1573 if (isFastProfileChooser) { 1543 if (isFastProfileChooser) {
1574 // The user is using right-click switching, no need to tell them about it. 1544 // The user is using right-click switching, no need to tell them about it.
1575 PrefService* localState = g_browser_process->local_state(); 1545 PrefService* localState = g_browser_process->local_state();
1576 localState->SetBoolean( 1546 localState->SetBoolean(
1577 prefs::kProfileAvatarRightClickTutorialDismissed, true); 1547 prefs::kProfileAvatarRightClickTutorialDismissed, true);
1578 } 1548 }
1579 1549
1580 // Loop over the profiles in reverse, so that they are sorted by their 1550 // Loop over the profiles in reverse, so that they are sorted by their
1581 // y-coordinate, and separate them into active and "other" profiles. 1551 // y-coordinate, and separate them into active and "other" profiles.
1582 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { 1552 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) {
1583 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); 1553 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i);
1584 if (item.active) { 1554 if (item.active) {
1585 if (switches::IsMaterialDesignUserMenu()) { 1555 syncErrorView = [self buildSyncErrorViewIfNeeded];
1586 syncErrorView = [self buildSyncErrorViewIfNeeded]; 1556 currentProfileView = [self createMaterialDesignCurrentProfileView:item];
1587 } else if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) {
1588 tutorialView = [self buildTutorialViewIfNeededForItem:item];
1589 }
1590 currentProfileView =
1591 switches::IsMaterialDesignUserMenu()
1592 ? [self createMaterialDesignCurrentProfileView:item]
1593 : [self createCurrentProfileView:item];
1594 showLock = item.signed_in && 1557 showLock = item.signed_in &&
1595 profiles::IsLockAvailable(browser_->profile()); 1558 profiles::IsLockAvailable(browser_->profile());
1596 } else { 1559 } else {
1597 [otherProfiles addObject:[self createOtherProfileView:i]]; 1560 [otherProfiles addObject:[self createOtherProfileView:i]];
1598 } 1561 }
1599 } 1562 }
1600 firstProfileView_ = [otherProfiles lastObject]; 1563 firstProfileView_ = [otherProfiles lastObject];
1601 if (!currentProfileView) // Guest windows don't have an active profile. 1564 if (!currentProfileView) // Guest windows don't have an active profile.
1602 currentProfileView = [self createGuestProfileView]; 1565 currentProfileView = [self createGuestProfileView];
1603 1566
1604 // |yOffset| is the next position at which to draw in |container| 1567 // |yOffset| is the next position at which to draw in |container|
1605 // coordinates. Add a pixel offset so that the bottom option buttons don't 1568 // coordinates. Add a pixel offset so that the bottom option buttons don't
1606 // overlap the bubble's rounded corners. 1569 // overlap the bubble's rounded corners.
1607 CGFloat yOffset = 1; 1570 CGFloat yOffset = 1;
1608 1571
1609 if (isFastProfileChooser) { 1572 if (!isFastProfileChooser) {
1610 if (!switches::IsMaterialDesignUserMenu()) {
1611 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get()
1612 atYOffset:yOffset
1613 inContainer:container];
1614 }
1615 } else {
1616 [self buildProfileChooserViewWithProfileView:currentProfileView 1573 [self buildProfileChooserViewWithProfileView:currentProfileView
1617 tutorialView:tutorialView 1574 tutorialView:tutorialView
1618 syncErrorView:syncErrorView 1575 syncErrorView:syncErrorView
1619 otherProfiles:otherProfiles.get() 1576 otherProfiles:otherProfiles.get()
1620 atYOffset:yOffset 1577 atYOffset:yOffset
1621 inContainer:container 1578 inContainer:container
1622 showLock:showLock]; 1579 showLock:showLock];
1623 } 1580 }
1624 1581
1625 return container.autorelease(); 1582 return container.autorelease();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { 1628 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item {
1672 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( 1629 ProfileMetrics::LogProfileNewAvatarMenuUpgrade(
1673 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); 1630 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW);
1674 1631
1675 NSString* titleMessage = l10n_util::GetNSString( 1632 NSString* titleMessage = l10n_util::GetNSString(
1676 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); 1633 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE);
1677 NSString* contentMessage = l10n_util::GetNSString( 1634 NSString* contentMessage = l10n_util::GetNSString(
1678 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); 1635 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT);
1679 // For local profiles, the "Not you" link doesn't make sense. 1636 // For local profiles, the "Not you" link doesn't make sense.
1680 NSString* linkMessage = 1637 NSString* linkMessage =
1681 item.signed_in 1638 item.signed_in ? ElideMessage(l10n_util::GetStringFUTF16(
1682 ? ElideMessage( 1639 IDS_PROFILES_NOT_YOU, item.name),
1683 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name), 1640 kFixedMenuWidth - 2 * kHorizontalSpacing)
1684 GetFixedMenuWidth() - 2 * kHorizontalSpacing) 1641 : nil;
1685 : nil;
1686 NSString* buttonMessage = l10n_util::GetNSString( 1642 NSString* buttonMessage = l10n_util::GetNSString(
1687 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); 1643 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON);
1688 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE 1644 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE
1689 titleMessage:titleMessage 1645 titleMessage:titleMessage
1690 contentMessage:contentMessage 1646 contentMessage:contentMessage
1691 linkMessage:linkMessage 1647 linkMessage:linkMessage
1692 buttonMessage:buttonMessage 1648 buttonMessage:buttonMessage
1693 stackButton:YES 1649 stackButton:YES
1694 hasCloseButton:YES 1650 hasCloseButton:YES
1695 linkAction:@selector(showSwitchUserView:) 1651 linkAction:@selector(showSwitchUserView:)
(...skipping 13 matching lines...) Expand all
1709 titleMessage:titleMessage 1665 titleMessage:titleMessage
1710 contentMessage:contentMessage 1666 contentMessage:contentMessage
1711 linkMessage:nil 1667 linkMessage:nil
1712 buttonMessage:buttonMessage 1668 buttonMessage:buttonMessage
1713 stackButton:NO 1669 stackButton:NO
1714 hasCloseButton:NO 1670 hasCloseButton:NO
1715 linkAction:nil 1671 linkAction:nil
1716 buttonAction:@selector(dismissTutorial:)]; 1672 buttonAction:@selector(dismissTutorial:)];
1717 } 1673 }
1718 1674
1719 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item {
1720 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN)
1721 return [self buildSigninConfirmationView];
1722
1723 if (tutorialMode_ == profiles::TUTORIAL_MODE_SHOW_ERROR)
1724 return [self buildSigninErrorView];
1725
1726 if (profiles::ShouldShowWelcomeUpgradeTutorial(
1727 browser_->profile(), tutorialMode_)) {
1728 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) {
1729 Profile* profile = browser_->profile();
1730 const int showCount = profile->GetPrefs()->GetInteger(
1731 prefs::kProfileAvatarTutorialShown);
1732 profile->GetPrefs()->SetInteger(
1733 prefs::kProfileAvatarTutorialShown, showCount + 1);
1734 }
1735
1736 return [self buildWelcomeUpgradeTutorialView:item];
1737 }
1738
1739 if (profiles::ShouldShowRightClickTutorial(browser_->profile()))
1740 return [self buildRightClickTutorialView];
1741
1742 return nil;
1743 }
1744
1745 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode 1675 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode
1746 titleMessage:(NSString*)titleMessage 1676 titleMessage:(NSString*)titleMessage
1747 contentMessage:(NSString*)contentMessage 1677 contentMessage:(NSString*)contentMessage
1748 linkMessage:(NSString*)linkMessage 1678 linkMessage:(NSString*)linkMessage
1749 buttonMessage:(NSString*)buttonMessage 1679 buttonMessage:(NSString*)buttonMessage
1750 stackButton:(BOOL)stackButton 1680 stackButton:(BOOL)stackButton
1751 hasCloseButton:(BOOL)hasCloseButton 1681 hasCloseButton:(BOOL)hasCloseButton
1752 linkAction:(SEL)linkAction 1682 linkAction:(SEL)linkAction
1753 buttonAction:(SEL)buttonAction { 1683 buttonAction:(SEL)buttonAction {
1754 tutorialMode_ = mode; 1684 tutorialMode_ = mode;
1755 1685
1756 NSColor* tutorialBackgroundColor = 1686 NSColor* tutorialBackgroundColor =
1757 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); 1687 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor);
1758 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] 1688 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc]
1759 initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0) 1689 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0)
1760 withColor:tutorialBackgroundColor]); 1690 withColor:tutorialBackgroundColor]);
1761 CGFloat availableWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; 1691 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing;
1762 CGFloat yOffset = kVerticalSpacing; 1692 CGFloat yOffset = kVerticalSpacing;
1763 1693
1764 // Adds links and buttons at the bottom. 1694 // Adds links and buttons at the bottom.
1765 base::scoped_nsobject<NSButton> tutorialOkButton; 1695 base::scoped_nsobject<NSButton> tutorialOkButton;
1766 if (buttonMessage) { 1696 if (buttonMessage) {
1767 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); 1697 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]);
1768 [tutorialOkButton setTitle:buttonMessage]; 1698 [tutorialOkButton setTitle:buttonMessage];
1769 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; 1699 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle];
1770 [tutorialOkButton setTarget:self]; 1700 [tutorialOkButton setTarget:self];
1771 [tutorialOkButton setAction:buttonAction]; 1701 [tutorialOkButton setAction:buttonAction];
1772 [tutorialOkButton setAlignment:NSCenterTextAlignment]; 1702 [tutorialOkButton setAlignment:NSCenterTextAlignment];
1773 [tutorialOkButton sizeToFit]; 1703 [tutorialOkButton sizeToFit];
1774 } 1704 }
1775 1705
1776 NSButton* learnMoreLink = nil; 1706 NSButton* learnMoreLink = nil;
1777 if (linkMessage) { 1707 if (linkMessage) {
1778 learnMoreLink = [self linkButtonWithTitle:linkMessage 1708 learnMoreLink = [self linkButtonWithTitle:linkMessage
1779 frameOrigin:NSZeroPoint 1709 frameOrigin:NSZeroPoint
1780 action:linkAction]; 1710 action:linkAction];
1781 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; 1711 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]];
1782 } 1712 }
1783 1713
1784 if (stackButton) { 1714 if (stackButton) {
1785 [learnMoreLink 1715 [learnMoreLink setFrameOrigin:NSMakePoint((kFixedMenuWidth -
1786 setFrameOrigin:NSMakePoint((GetFixedMenuWidth() - 1716 NSWidth([learnMoreLink frame])) /
1787 NSWidth([learnMoreLink frame])) / 2, 1717 2,
1788 yOffset)]; 1718 yOffset)];
1789 [tutorialOkButton setFrameSize:NSMakeSize( 1719 [tutorialOkButton setFrameSize:NSMakeSize(
1790 availableWidth, NSHeight([tutorialOkButton frame]))]; 1720 availableWidth, NSHeight([tutorialOkButton frame]))];
1791 [tutorialOkButton setFrameOrigin:NSMakePoint( 1721 [tutorialOkButton setFrameOrigin:NSMakePoint(
1792 kHorizontalSpacing, 1722 kHorizontalSpacing,
1793 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; 1723 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))];
1794 } else { 1724 } else {
1795 if (buttonMessage) { 1725 if (buttonMessage) {
1796 NSSize buttonSize = [tutorialOkButton frame].size; 1726 NSSize buttonSize = [tutorialOkButton frame].size;
1797 const CGFloat kTopBottomTextPadding = 6; 1727 const CGFloat kTopBottomTextPadding = 6;
1798 const CGFloat kLeftRightTextPadding = 15; 1728 const CGFloat kLeftRightTextPadding = 15;
1799 buttonSize.width += 2 * kLeftRightTextPadding; 1729 buttonSize.width += 2 * kLeftRightTextPadding;
1800 buttonSize.height += 2 * kTopBottomTextPadding; 1730 buttonSize.height += 2 * kTopBottomTextPadding;
1801 [tutorialOkButton setFrameSize:buttonSize]; 1731 [tutorialOkButton setFrameSize:buttonSize];
1802 CGFloat buttonXOffset = GetFixedMenuWidth() - 1732 CGFloat buttonXOffset = kFixedMenuWidth -
1803 NSWidth([tutorialOkButton frame]) - 1733 NSWidth([tutorialOkButton frame]) -
1804 kHorizontalSpacing; 1734 kHorizontalSpacing;
1805 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; 1735 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)];
1806 } 1736 }
1807 1737
1808 if (linkMessage) { 1738 if (linkMessage) {
1809 CGFloat linkYOffset = yOffset; 1739 CGFloat linkYOffset = yOffset;
1810 if (buttonMessage) { 1740 if (buttonMessage) {
1811 linkYOffset += (NSHeight([tutorialOkButton frame]) - 1741 linkYOffset += (NSHeight([tutorialOkButton frame]) -
1812 NSHeight([learnMoreLink frame])) / 2; 1742 NSHeight([learnMoreLink frame])) / 2;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1855 CGFloat closeImageWidth = [closeImage size].width; 1785 CGFloat closeImageWidth = [closeImage size].width;
1856 [closeButton setDefaultImage:closeImage]; 1786 [closeButton setDefaultImage:closeImage];
1857 [closeButton setHoverImage: 1787 [closeButton setHoverImage:
1858 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()]; 1788 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()];
1859 [closeButton setPressedImage: 1789 [closeButton setPressedImage:
1860 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()]; 1790 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()];
1861 [closeButton setTarget:self]; 1791 [closeButton setTarget:self];
1862 [closeButton setAction:@selector(dismissTutorial:)]; 1792 [closeButton setAction:@selector(dismissTutorial:)];
1863 [closeButton setFrameSize:[closeImage size]]; 1793 [closeButton setFrameSize:[closeImage size]];
1864 [closeButton 1794 [closeButton
1865 setFrameOrigin:NSMakePoint(GetFixedMenuWidth() - kHorizontalSpacing - 1795 setFrameOrigin:NSMakePoint(kFixedMenuWidth - kHorizontalSpacing -
1866 closeImageWidth, 1796 closeImageWidth,
1867 yOffset)]; 1797 yOffset)];
1868 [container addSubview:closeButton]; 1798 [container addSubview:closeButton];
1869 1799
1870 [titleLabel setFrameSize:NSMakeSize( 1800 [titleLabel setFrameSize:NSMakeSize(
1871 availableWidth - closeImageWidth - kHorizontalSpacing, 0)]; 1801 availableWidth - closeImageWidth - kHorizontalSpacing, 0)];
1872 } else { 1802 } else {
1873 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; 1803 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1874 } 1804 }
1875 1805
1876 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; 1806 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel];
1877 [container addSubview:titleLabel]; 1807 [container addSubview:titleLabel];
1878 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; 1808 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing;
1879 1809
1880 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1810 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
1881 [container setFrameOrigin:NSZeroPoint]; 1811 [container setFrameOrigin:NSZeroPoint];
1882 return container.autorelease(); 1812 return container.autorelease();
1883 } 1813 }
1884 1814
1885 - (NSView*)buildSyncErrorViewIfNeeded { 1815 - (NSView*)buildSyncErrorViewIfNeeded {
1886 int contentStringId, buttonStringId; 1816 int contentStringId, buttonStringId;
1887 SEL buttonAction; 1817 SEL buttonAction;
1888 sync_ui_util::AvatarSyncErrorType error = 1818 sync_ui_util::AvatarSyncErrorType error =
1889 sync_ui_util::GetMessagesForAvatarSyncError( 1819 sync_ui_util::GetMessagesForAvatarSyncError(
1890 browser_->profile(), &contentStringId, &buttonStringId); 1820 browser_->profile(), &contentStringId, &buttonStringId);
(...skipping 16 matching lines...) Expand all
1907 case sync_ui_util::PASSPHRASE_ERROR: 1837 case sync_ui_util::PASSPHRASE_ERROR:
1908 buttonAction = @selector(showSyncPassphraseSetupView:); 1838 buttonAction = @selector(showSyncPassphraseSetupView:);
1909 break; 1839 break;
1910 case sync_ui_util::NO_SYNC_ERROR: 1840 case sync_ui_util::NO_SYNC_ERROR:
1911 return nil; 1841 return nil;
1912 default: 1842 default:
1913 NOTREACHED(); 1843 NOTREACHED();
1914 } 1844 }
1915 1845
1916 base::scoped_nsobject<NSView> container( 1846 base::scoped_nsobject<NSView> container(
1917 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0)]); 1847 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0)]);
1918 CGFloat iconSize = 20.0; 1848 CGFloat iconSize = 20.0;
1919 CGFloat xOffset = kHorizontalSpacing + iconSize + 12.0; 1849 CGFloat xOffset = kHorizontalSpacing + iconSize + 12.0;
1920 CGFloat availableWidth = GetFixedMenuWidth() - xOffset - kHorizontalSpacing; 1850 CGFloat availableWidth = kFixedMenuWidth - xOffset - kHorizontalSpacing;
1921 CGFloat yOffset = 16.0; 1851 CGFloat yOffset = 16.0;
1922 1852
1923 // Adds an action button for resolving the error at the bottom. 1853 // Adds an action button for resolving the error at the bottom.
1924 if (buttonStringId) { 1854 if (buttonStringId) {
1925 // If the button string is specified, then the button action needs to be 1855 // If the button string is specified, then the button action needs to be
1926 // already initialized for the button to be constructed. 1856 // already initialized for the button to be constructed.
1927 DCHECK(buttonAction); 1857 DCHECK(buttonAction);
1928 base::scoped_nsobject<NSButton> resolveErrorButton( 1858 base::scoped_nsobject<NSButton> resolveErrorButton(
1929 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); 1859 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]);
1930 [resolveErrorButton setTitle:l10n_util::GetNSString(buttonStringId)]; 1860 [resolveErrorButton setTitle:l10n_util::GetNSString(buttonStringId)];
(...skipping 28 matching lines...) Expand all
1959 // Adds the sync problem icon. 1889 // Adds the sync problem icon.
1960 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc] 1890 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc]
1961 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize, 1891 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize,
1962 iconSize)]); 1892 iconSize)]);
1963 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( 1893 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon(
1964 gfx::VectorIconId::SYNC_PROBLEM, iconSize, 1894 gfx::VectorIconId::SYNC_PROBLEM, iconSize,
1965 gfx::kGoogleRed700))]; 1895 gfx::kGoogleRed700))];
1966 [container addSubview:syncProblemIcon]; 1896 [container addSubview:syncProblemIcon];
1967 1897
1968 [container 1898 [container
1969 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; 1899 setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset + kVerticalSpacing)];
1970 return container.autorelease(); 1900 return container.autorelease();
1971 } 1901 }
1972 1902
1973 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item {
1974 base::scoped_nsobject<NSView> container([[NSView alloc]
1975 initWithFrame:NSZeroRect]);
1976
1977 CGFloat xOffset = kHorizontalSpacing;
1978 CGFloat yOffset = 0;
1979 CGFloat availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing;
1980 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing;
1981
1982 // Profile options. This can be a link to the accounts view, the profile's
1983 // username for signed in users, or a "Sign in" button for local profiles.
1984 SigninManagerBase* signinManager =
1985 SigninManagerFactory::GetForProfile(
1986 browser_->profile()->GetOriginalProfile());
1987 if (!isGuestSession_ && signinManager->IsSigninAllowed()) {
1988 NSView* linksContainer = [self
1989 createCurrentProfileLinksForItem:item
1990 rect:NSMakeRect(xOffset, yOffset,
1991 maxAvailableTextWidth, 0)];
1992 [container addSubview:linksContainer];
1993 yOffset = NSMaxY([linksContainer frame]);
1994 }
1995
1996 // Profile name, centered.
1997 bool editingAllowed = !isGuestSession_ &&
1998 !browser_->profile()->IsLegacySupervised();
1999 base::scoped_nsobject<EditableProfileNameButton> profileName(
2000 [[EditableProfileNameButton alloc]
2001 initWithFrame:NSMakeRect(xOffset,
2002 yOffset,
2003 availableTextWidth,
2004 kProfileButtonHeight)
2005 profile:browser_->profile()
2006 profileName:base::SysUTF16ToNSString(
2007 profiles::GetAvatarNameForProfile(
2008 browser_->profile()->GetPath()))
2009 editingAllowed:editingAllowed
2010 withController:self]);
2011
2012 [container addSubview:profileName];
2013 yOffset = NSMaxY([profileName frame]) + 4; // Adds a small vertical padding.
2014
2015 // Profile icon, centered.
2016 xOffset = (GetFixedMenuWidth() - kLargeImageSide) / 2;
2017 base::scoped_nsobject<EditableProfilePhoto> iconView(
2018 [[EditableProfilePhoto alloc]
2019 initWithFrame:NSMakeRect(xOffset, yOffset,
2020 kLargeImageSide, kLargeImageSide)
2021 avatarMenu:avatarMenu_.get()
2022 profileIcon:item.icon
2023 editingAllowed:!isGuestSession_
2024 withController:self]);
2025
2026 [container addSubview:iconView];
2027 yOffset = NSMaxY([iconView frame]);
2028
2029 if (browser_->profile()->IsSupervised()) {
2030 base::scoped_nsobject<NSImageView> supervisedIcon(
2031 [[NSImageView alloc] initWithFrame:NSZeroRect]);
2032 int imageId = browser_->profile()->IsChild()
2033 ? IDR_ICON_PROFILES_MENU_CHILD
2034 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
2035 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
2036 [supervisedIcon setImage:rb->GetNativeImageNamed(imageId).ToNSImage()];
2037 NSSize size = [[supervisedIcon image] size];
2038 [supervisedIcon setFrameSize:size];
2039 NSRect parentFrame = [iconView frame];
2040 [supervisedIcon setFrameOrigin:NSMakePoint(NSMaxX(parentFrame) - size.width,
2041 NSMinY(parentFrame))];
2042 [container addSubview:supervisedIcon];
2043 }
2044
2045 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
2046 return container.autorelease();
2047 }
2048
2049 - (NSView*)createMaterialDesignCurrentProfileView: 1903 - (NSView*)createMaterialDesignCurrentProfileView:
2050 (const AvatarMenu::Item&)item { 1904 (const AvatarMenu::Item&)item {
2051 base::scoped_nsobject<NSView> container( 1905 base::scoped_nsobject<NSView> container(
2052 [[NSView alloc] initWithFrame:NSZeroRect]); 1906 [[NSView alloc] initWithFrame:NSZeroRect]);
2053 1907
2054 CGFloat xOffset = kHorizontalSpacing; 1908 CGFloat xOffset = kHorizontalSpacing;
2055 CGFloat yOffset = 0.0; 1909 CGFloat yOffset = 0.0;
2056 CGFloat cardYOffset = kRelatedControllVerticalSpacing; 1910 CGFloat cardYOffset = kRelatedControllVerticalSpacing;
2057 CGFloat availableTextWidth = 1911 CGFloat availableTextWidth =
2058 GetFixedMenuWidth() - 3.0 * kHorizontalSpacing - kMdImageSide; 1912 kFixedMenuWidth - 3.0 * kHorizontalSpacing - kMdImageSide;
2059 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing; 1913 CGFloat maxAvailableTextWidth = kFixedMenuWidth - kHorizontalSpacing;
2060 1914
2061 // Profile options. This can be a link to the accounts view, or a "Sign in" 1915 // Profile options. This can be a link to the accounts view, or a "Sign in"
2062 // button for local profiles. 1916 // button for local profiles.
2063 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( 1917 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile(
2064 browser_->profile()->GetOriginalProfile()); 1918 browser_->profile()->GetOriginalProfile());
2065 NSRect profileLinksBound = NSZeroRect; 1919 NSRect profileLinksBound = NSZeroRect;
2066 if (item.signed_in && switches::IsEnableAccountConsistency()) { 1920 if (item.signed_in && switches::IsEnableAccountConsistency()) {
2067 profileLinksBound = NSMakeRect(0, 0, GetFixedMenuWidth(), kVerticalSpacing); 1921 profileLinksBound = NSMakeRect(0, 0, kFixedMenuWidth, kVerticalSpacing);
2068 } else if (!item.signed_in && signinManager->IsSigninAllowed()) { 1922 } else if (!item.signed_in && signinManager->IsSigninAllowed()) {
2069 profileLinksBound = NSMakeRect(xOffset, kRelatedControllVerticalSpacing, 1923 profileLinksBound = NSMakeRect(xOffset, kRelatedControllVerticalSpacing,
2070 maxAvailableTextWidth, kVerticalSpacing); 1924 maxAvailableTextWidth, kVerticalSpacing);
2071 } 1925 }
2072 if (!NSIsEmptyRect(profileLinksBound)) { 1926 if (!NSIsEmptyRect(profileLinksBound)) {
2073 NSView* linksContainer = 1927 NSView* linksContainer =
2074 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; 1928 [self createCurrentProfileLinksForItem:item rect:profileLinksBound];
2075 [container addSubview:linksContainer]; 1929 [container addSubview:linksContainer];
2076 yOffset = NSMaxY([linksContainer frame]); 1930 yOffset = NSMaxY([linksContainer frame]);
2077 } 1931 }
2078 1932
2079 // Profile card button that contains the profile icon, name, and username. 1933 // Profile card button that contains the profile icon, name, and username.
2080 const base::string16 profileNameString = 1934 const base::string16 profileNameString =
2081 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); 1935 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath());
2082 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 1936 NSRect rect =
2083 kMdImageSide + kVerticalSpacing); 1937 NSMakeRect(0, yOffset, kFixedMenuWidth, kMdImageSide + kVerticalSpacing);
2084 NSButton* profileCard = 1938 NSButton* profileCard =
2085 [self hoverButtonWithRect:rect 1939 [self hoverButtonWithRect:rect
2086 text:[[NSString alloc] init] 1940 text:[[NSString alloc] init]
2087 image:CreateProfileImage(item.icon, kMdImageSide, 1941 image:CreateProfileImage(item.icon, kMdImageSide,
2088 profiles::SHAPE_CIRCLE) 1942 profiles::SHAPE_CIRCLE)
2089 action:@selector(editProfile:)]; 1943 action:@selector(editProfile:)];
2090 [[profileCard cell] setImageDimsWhenDisabled:NO]; 1944 [[profileCard cell] setImageDimsWhenDisabled:NO];
2091 if (item.signed_in) { 1945 if (item.signed_in) {
2092 [[profileCard cell] 1946 [[profileCard cell]
2093 accessibilitySetOverrideValue: 1947 accessibilitySetOverrideValue:
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
2172 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; 2026 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))];
2173 NSString* usernameNSString = base::SysUTF16ToNSString(item.username); 2027 NSString* usernameNSString = base::SysUTF16ToNSString(item.username);
2174 if (![elidedEmail isEqualToString:usernameNSString]) { 2028 if (![elidedEmail isEqualToString:usernameNSString]) {
2175 // Add the tooltip only if the user name is truncated. 2029 // Add the tooltip only if the user name is truncated.
2176 username.toolTip = usernameNSString; 2030 username.toolTip = usernameNSString;
2177 } 2031 }
2178 [profileCard addSubview:username]; 2032 [profileCard addSubview:username];
2179 } 2033 }
2180 2034
2181 yOffset = NSMaxY([profileCard frame]); 2035 yOffset = NSMaxY([profileCard frame]);
2182 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 2036 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
2183 return container.autorelease(); 2037 return container.autorelease();
2184 } 2038 }
2185 2039
2186 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 2040 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
2187 rect:(NSRect)rect { 2041 rect:(NSRect)rect {
2188 if (switches::IsMaterialDesignUserMenu()) { 2042 // The branch is empty in non-account-consistency mode, because in that case,
2189 // The branch is empty for material design user menu in non-account- 2043 // the username would appear in the profile card instead of as a separate link
2190 // consistency mode, because in that case, the username would appear in the 2044 // here.
2191 // profile card instead of as a separate link here. 2045 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile(
2192 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( 2046 browser_->profile()->GetOriginalProfile());
2193 browser_->profile()->GetOriginalProfile()); 2047 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) ||
2194 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) || 2048 (!item.signed_in && signinManager->IsSigninAllowed()));
2195 (!item.signed_in && signinManager->IsSigninAllowed()));
2196 }
2197 2049
2198 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 2050 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
2199 2051
2200 // Don't double-apply the left margin to the sub-views. 2052 // Don't double-apply the left margin to the sub-views.
2201 rect.origin.x = 0; 2053 rect.origin.x = 0;
2202 2054
2203 // Adds right padding. 2055 // Adds right padding.
2204 const CGFloat kRightPadding = kHorizontalSpacing; 2056 const CGFloat kRightPadding = kHorizontalSpacing;
2205 rect.size.width -= kRightPadding; 2057 rect.size.width -= kRightPadding;
2206 2058
2207 // The available links depend on the type of profile that is active. 2059 // The available links depend on the type of profile that is active.
2208 if (item.signed_in) { 2060 if (item.signed_in) {
2209 NSButton* link = nil; 2061 NSButton* link = nil;
2210 if (switches::IsEnableAccountConsistency()) { 2062 if (switches::IsEnableAccountConsistency()) {
2211 NSString* linkTitle = l10n_util::GetNSString( 2063 NSString* linkTitle = l10n_util::GetNSString(
2212 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? 2064 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ?
2213 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : 2065 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON :
2214 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); 2066 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON);
2215 SEL linkSelector = 2067 SEL linkSelector =
2216 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? 2068 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ?
2217 @selector(showAccountManagement:) : @selector(hideAccountManagement:); 2069 @selector(showAccountManagement:) : @selector(hideAccountManagement:);
2218 if (switches::IsMaterialDesignUserMenu()) { 2070 rect.size.width += kRightPadding; // Spans the width of the entire menu.
2219 rect.size.width += 2071 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width,
2220 kRightPadding; // Spans the width of the entire menu. 2072 kBlueButtonHeight)
2221 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width, 2073 text:linkTitle
2222 kBlueButtonHeight) 2074 action:linkSelector];
2223 text:linkTitle
2224 action:linkSelector];
2225 } else {
2226 link = [self linkButtonWithTitle:linkTitle
2227 frameOrigin:rect.origin
2228 action:linkSelector];
2229 }
2230 } else if (!switches::IsMaterialDesignUserMenu()) {
2231 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.username)
2232 frameOrigin:rect.origin
2233 action:nil];
2234 if (HasAuthError(browser_->profile())) {
2235 [link setImage:ui::ResourceBundle::GetSharedInstance().
2236 GetNativeImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).
2237 ToNSImage()];
2238 [link setImagePosition:NSImageRight];
2239 [link setTarget:self];
2240 [link setAction:@selector(showAccountReauthenticationView:)];
2241 [link setTag:kPrimaryProfileTag];
2242 [[link cell]
2243 accessibilitySetOverrideValue:l10n_util::GetNSStringF(
2244 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME,
2245 item.username)
2246 forAttribute:NSAccessibilityTitleAttribute];
2247 } else {
2248 // Signed in profiles with no authentication errors do not have a
2249 // clickable email link.
2250 [link setEnabled:NO];
2251 }
2252 } 2075 }
2253 if (link) { 2076 if (link) {
2254 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but 2077 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but
2255 // need to re-stretch the width so that the link can be centered correctly 2078 // need to re-stretch the width so that the link can be centered correctly
2256 // in the view. 2079 // in the view.
2257 rect.size.height = [link frame].size.height; 2080 rect.size.height = [link frame].size.height;
2258 if (!switches::IsMaterialDesignUserMenu())
2259 [link setAlignment:NSCenterTextAlignment];
2260 [link setFrame:rect]; 2081 [link setFrame:rect];
2261 [container addSubview:link]; 2082 [container addSubview:link];
2262 [container setFrameSize:rect.size]; 2083 [container setFrameSize:rect.size];
2263 } 2084 }
2264 } else { 2085 } else {
2265 rect.size.height = kBlueButtonHeight; 2086 rect.size.height = kBlueButtonHeight;
2266 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect]; 2087 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect];
2267 2088
2268 // Manually elide the button text so that the contents fit inside the bubble 2089 // Manually elide the button text so that the contents fit inside the bubble
2269 // This is needed because the BlueLabelButton cell resets the style on 2090 // This is needed because the BlueLabelButton cell resets the style on
2270 // every call to -cellSize, which prevents setting a custom lineBreakMode. 2091 // every call to -cellSize, which prevents setting a custom lineBreakMode.
2271 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( 2092 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText(
2272 l10n_util::GetStringFUTF16( 2093 l10n_util::GetStringFUTF16(
2273 IDS_SYNC_START_SYNC_BUTTON_LABEL, 2094 IDS_SYNC_START_SYNC_BUTTON_LABEL,
2274 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), 2095 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)),
2275 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); 2096 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL));
2276 2097
2277 [signinButton setTitle:elidedButtonText]; 2098 [signinButton setTitle:elidedButtonText];
2278 if (switches::IsMaterialDesignUserMenu()) 2099 [signinButton sizeToFit];
2279 [signinButton sizeToFit];
2280 [signinButton setTarget:self]; 2100 [signinButton setTarget:self];
2281 [signinButton setAction:@selector(showInlineSigninPage:)]; 2101 [signinButton setAction:@selector(showInlineSigninPage:)];
2282 [container addSubview:signinButton]; 2102 [container addSubview:signinButton];
2283 2103
2284 // Sign-in promo text. 2104 // Sign-in promo text.
2285 NSTextField* promo = BuildLabel( 2105 NSTextField* promo = BuildLabel(
2286 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), 2106 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO),
2287 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), 2107 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing),
2288 nil); 2108 nil);
2289 if (kRightPadding >= 8) 2109 if (kRightPadding >= 8)
2290 rect.size.width += 8; // Re-stretch a little bit to fit promo text. 2110 rect.size.width += 8; // Re-stretch a little bit to fit promo text.
2291 DCHECK(kRightPadding >= 8); 2111 DCHECK(kRightPadding >= 8);
2292 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; 2112 [promo setFrameSize:NSMakeSize(rect.size.width, 0)];
2293 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; 2113 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo];
2294 [container addSubview:promo]; 2114 [container addSubview:promo];
2295 2115
2296 [container 2116 [container setFrameSize:NSMakeSize(rect.size.width,
2297 setFrameSize:NSMakeSize(rect.size.width, 2117 NSMaxY([promo frame]) +
2298 NSMaxY([promo frame]) + 2118 kRelatedControllVerticalSpacing)];
2299 (switches::IsMaterialDesignUserMenu()
2300 ? kRelatedControllVerticalSpacing
2301 : 4))];
2302 content::RecordAction( 2119 content::RecordAction(
2303 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); 2120 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin"));
2304 } 2121 }
2305 2122
2306 return container.autorelease(); 2123 return container.autorelease();
2307 } 2124 }
2308 2125
2309 - (NSView*)createSupervisedUserDisclaimerView { 2126 - (NSView*)createSupervisedUserDisclaimerView {
2310 base::scoped_nsobject<NSView> container( 2127 base::scoped_nsobject<NSView> container(
2311 [[NSView alloc] initWithFrame:NSZeroRect]); 2128 [[NSView alloc] initWithFrame:NSZeroRect]);
2312 2129
2313 int yOffset = 0; 2130 int yOffset = 0;
2314 int availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; 2131 int availableTextWidth = kFixedMenuWidth - 2 * kHorizontalSpacing;
2315 2132
2316 NSTextField* disclaimer = BuildLabel( 2133 NSTextField* disclaimer = BuildLabel(
2317 base::SysUTF16ToNSString(avatarMenu_->GetSupervisedUserInformation()), 2134 base::SysUTF16ToNSString(avatarMenu_->GetSupervisedUserInformation()),
2318 NSMakePoint(kHorizontalSpacing, yOffset), nil); 2135 NSMakePoint(kHorizontalSpacing, yOffset), nil);
2319 [disclaimer setFrameSize:NSMakeSize(availableTextWidth, 0)]; 2136 [disclaimer setFrameSize:NSMakeSize(availableTextWidth, 0)];
2320 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:disclaimer]; 2137 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:disclaimer];
2321 yOffset = NSMaxY([disclaimer frame]); 2138 yOffset = NSMaxY([disclaimer frame]);
2322 2139
2323 [container addSubview:disclaimer]; 2140 [container addSubview:disclaimer];
2324 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 2141 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)];
2325 return container.autorelease(); 2142 return container.autorelease();
2326 } 2143 }
2327 2144
2328 - (NSView*)createGuestProfileView { 2145 - (NSView*)createGuestProfileView {
2329 gfx::Image guestIcon = 2146 gfx::Image guestIcon =
2330 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 2147 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
2331 profiles::GetPlaceholderAvatarIconResourceID()); 2148 profiles::GetPlaceholderAvatarIconResourceID());
2332 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ 2149 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */
2333 base::FilePath(), /* profile_path, not used */ 2150 base::FilePath(), /* profile_path, not used */
2334 guestIcon); 2151 guestIcon);
2335 guestItem.active = true; 2152 guestItem.active = true;
2336 guestItem.name = base::SysNSStringToUTF16( 2153 guestItem.name = base::SysNSStringToUTF16(
2337 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); 2154 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME));
2338 2155
2339 return switches::IsMaterialDesignUserMenu() 2156 return [self createMaterialDesignCurrentProfileView:guestItem];
2340 ? [self createMaterialDesignCurrentProfileView:guestItem]
2341 : [self createCurrentProfileView:guestItem];
2342 } 2157 }
2343 2158
2344 - (NSButton*)createOtherProfileView:(int)itemIndex { 2159 - (NSButton*)createOtherProfileView:(int)itemIndex {
2345 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); 2160 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex);
2346 2161
2347 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), 2162 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth,
2348 kBlueButtonHeight + kSmallVerticalSpacing); 2163 kBlueButtonHeight + kSmallVerticalSpacing);
2349 const int imageTitleSpacing = switches::IsMaterialDesignUserMenu() 2164 const int imageTitleSpacing = kHorizontalSpacing;
2350 ? kHorizontalSpacing
2351 : kImageTitleSpacing;
2352 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( 2165 base::scoped_nsobject<BackgroundColorHoverButton> profileButton(
2353 [[BackgroundColorHoverButton alloc] 2166 [[BackgroundColorHoverButton alloc]
2354 initWithFrame:rect 2167 initWithFrame:rect
2355 imageTitleSpacing:imageTitleSpacing 2168 imageTitleSpacing:imageTitleSpacing
2356 backgroundColor:GetDialogBackgroundColor()]); 2169 backgroundColor:GetDialogBackgroundColor()]);
2357 if (switches::IsMaterialDesignUserMenu()) 2170 [profileButton setRightMarginSpacing:kHorizontalSpacing];
2358 [profileButton setRightMarginSpacing:kHorizontalSpacing];
2359 2171
2360 NSString* title = base::SysUTF16ToNSString( 2172 NSString* title = base::SysUTF16ToNSString(
2361 profiles::GetProfileSwitcherTextForItem(item)); 2173 profiles::GetProfileSwitcherTextForItem(item));
2362 [profileButton setTitle:title]; 2174 [profileButton setTitle:title];
2363 2175
2364 CGFloat availableWidth; 2176 CGFloat availableWidth;
2365 if (switches::IsMaterialDesignUserMenu()) { 2177 [profileButton setDefaultImage:CreateProfileImage(item.icon, kIconImageSide,
2366 int iconImageSide = 18; 2178 profiles::SHAPE_CIRCLE)];
2367 [profileButton setDefaultImage:CreateProfileImage(item.icon, iconImageSide, 2179 availableWidth = rect.size.width - kIconImageSide - imageTitleSpacing -
2368 profiles::SHAPE_CIRCLE)]; 2180 2 * kHorizontalSpacing;
2369 availableWidth = rect.size.width - iconImageSide - imageTitleSpacing -
2370 2 * kHorizontalSpacing;
2371 } else {
2372 // Use the low-res, small default avatars in the fast user switcher, like
2373 // we do in the menu bar.
2374 gfx::Image itemIcon;
2375 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon);
2376 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide,
2377 profiles::SHAPE_SQUARE)];
2378 availableWidth = rect.size.width - kSmallImageSide - imageTitleSpacing -
2379 kHorizontalSpacing;
2380 }
2381 2181
2382 [profileButton setImagePosition:NSImageLeft]; 2182 [profileButton setImagePosition:NSImageLeft];
2383 [profileButton setAlignment:NSLeftTextAlignment]; 2183 [profileButton setAlignment:NSLeftTextAlignment];
2384 [profileButton setBordered:NO]; 2184 [profileButton setBordered:NO];
2385 [profileButton setTag:itemIndex]; 2185 [profileButton setTag:itemIndex];
2386 [profileButton setTarget:self]; 2186 [profileButton setTarget:self];
2387 [profileButton setAction:@selector(switchToProfile:)]; 2187 [profileButton setAction:@selector(switchToProfile:)];
2388 2188
2389 NSSize textSize = [[profileButton title] sizeWithAttributes:@{
2390 NSFontAttributeName : [profileButton font]
2391 }];
2392
2393 if (!switches::IsMaterialDesignUserMenu() &&
2394 std::ceil(textSize.width) > availableWidth)
2395 [profileButton setToolTip:[profileButton title]];
2396
2397 return profileButton.autorelease(); 2189 return profileButton.autorelease();
2398 } 2190 }
2399 2191
2400 - (NSView*)createOptionsViewWithRect:(NSRect)rect
2401 showLock:(BOOL)showLock {
2402 NSRect viewRect = NSMakeRect(0, 0,
2403 rect.size.width,
2404 kBlueButtonHeight + kSmallVerticalSpacing);
2405 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
2406
2407 if (showLock) {
2408 NSButton* lockButton =
2409 [self hoverButtonWithRect:viewRect
2410 text:l10n_util::GetNSString(
2411 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON)
2412 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK
2413 action:@selector(lockProfile:)];
2414 [container addSubview:lockButton];
2415 viewRect.origin.y = NSMaxY([lockButton frame]);
2416
2417 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect];
2418 [container addSubview:separator];
2419 viewRect.origin.y = NSMaxY([separator frame]);
2420 }
2421
2422 if ([self shouldShowGoIncognito]) {
2423 NSButton* goIncognitoButton =
2424 [self hoverButtonWithRect:viewRect
2425 text:l10n_util::GetNSString(
2426 IDS_PROFILES_GO_INCOGNITO_BUTTON)
2427 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO
2428 action:@selector(goIncognito:)];
2429 viewRect.origin.y = NSMaxY([goIncognitoButton frame]);
2430 [container addSubview:goIncognitoButton];
2431
2432 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect];
2433 [container addSubview:separator];
2434 viewRect.origin.y = NSMaxY([separator frame]);
2435 }
2436
2437 NSString* text = isGuestSession_ ?
2438 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) :
2439 l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON);
2440 NSButton* switchUsersButton =
2441 [self hoverButtonWithRect:viewRect
2442 text:text
2443 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR
2444 action:isGuestSession_? @selector(exitGuest:) :
2445 @selector(showUserManager:)];
2446 viewRect.origin.y = NSMaxY([switchUsersButton frame]);
2447 [container addSubview:switchUsersButton];
2448
2449 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)];
2450 return container.autorelease();
2451 }
2452
2453 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { 2192 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect {
2454 const CGFloat kAccountButtonHeight = 34; 2193 const CGFloat kAccountButtonHeight = 34;
2455 2194
2456 const AvatarMenu::Item& item = 2195 const AvatarMenu::Item& item =
2457 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); 2196 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex());
2458 DCHECK(item.signed_in); 2197 DCHECK(item.signed_in);
2459 2198
2460 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( 2199 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor(
2461 profiles::kAvatarBubbleAccountsBackgroundColor); 2200 profiles::kAvatarBubbleAccountsBackgroundColor);
2462 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] 2201 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc]
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
2844 action:(SEL)action { 2583 action:(SEL)action {
2845 // The vector icons in hover buttons have small embeded paddings and are 2584 // The vector icons in hover buttons have small embeded paddings and are
2846 // therefore given an extra 2px in size to have a consistent look as the 2585 // therefore given an extra 2px in size to have a consistent look as the
2847 // profile icons; hence the -2.0 here to left align the hover button texts 2586 // profile icons; hence the -2.0 here to left align the hover button texts
2848 // with those of profile buttons. 2587 // with those of profile buttons.
2849 const int md_image_title_spacing = kHorizontalSpacing - 2.0; 2588 const int md_image_title_spacing = kHorizontalSpacing - 2.0;
2850 2589
2851 base::scoped_nsobject<BackgroundColorHoverButton> button( 2590 base::scoped_nsobject<BackgroundColorHoverButton> button(
2852 [[BackgroundColorHoverButton alloc] 2591 [[BackgroundColorHoverButton alloc]
2853 initWithFrame:rect 2592 initWithFrame:rect
2854 imageTitleSpacing:switches::IsMaterialDesignUserMenu() 2593 imageTitleSpacing:md_image_title_spacing
2855 ? md_image_title_spacing
2856 : kImageTitleSpacing
2857 backgroundColor:GetDialogBackgroundColor()]); 2594 backgroundColor:GetDialogBackgroundColor()]);
2858 2595
2859 [button setTitle:text]; 2596 [button setTitle:text];
2860 [button setAlignment:NSLeftTextAlignment]; 2597 [button setAlignment:NSLeftTextAlignment];
2861 [button setBordered:NO]; 2598 [button setBordered:NO];
2862 [button setTarget:self]; 2599 [button setTarget:self];
2863 [button setAction:action]; 2600 [button setAction:action];
2864 2601
2865 return button.autorelease(); 2602 return button.autorelease();
2866 } 2603 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
2960 2697
2961 - (void)showWindow:(id)sender { 2698 - (void)showWindow:(id)sender {
2962 [super showWindow:sender]; 2699 [super showWindow:sender];
2963 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; 2700 NSEvent *event = [[NSApplication sharedApplication] currentEvent];
2964 if (firstProfileView_ && [event type] == NSKeyDown) { 2701 if (firstProfileView_ && [event type] == NSKeyDown) {
2965 [[self window] makeFirstResponder:firstProfileView_]; 2702 [[self window] makeFirstResponder:firstProfileView_];
2966 } 2703 }
2967 } 2704 }
2968 2705
2969 @end 2706 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698