| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #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 Loading... |
| 87 #include "ui/gfx/paint_vector_icon.h" | 87 #include "ui/gfx/paint_vector_icon.h" |
| 88 #include "ui/gfx/text_elider.h" | 88 #include "ui/gfx/text_elider.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 Loading... |
| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 } | 933 } |
| 939 | 934 |
| 940 @end | 935 @end |
| 941 | 936 |
| 942 @interface ProfileChooserController () | 937 @interface ProfileChooserController () |
| 943 // Adds an horizontal separator to |container| at |yOffset| and returns the | 938 // Adds an horizontal separator to |container| at |yOffset| and returns the |
| 944 // yOffset corresponding to after the separator. | 939 // yOffset corresponding to after the separator. |
| 945 - (CGFloat)addSeparatorToContainer:(NSView*)container | 940 - (CGFloat)addSeparatorToContainer:(NSView*)container |
| 946 atYOffset:(CGFloat)yOffset; | 941 atYOffset:(CGFloat)yOffset; |
| 947 | 942 |
| 948 // Builds the fast user switcher view. In the current user menu, this is | 943 // Builds the fast user switcher view. This appears as part of the user menu. |
| 949 // triggered by right-clicking the avatar button; in the material design user | 944 // Returns the yOffset corresponding to after the profile switcher buttons. |
| 950 // menu, this appears as part of the user menu. Returns the yOffset | |
| 951 // corresponding to after the profile switcher buttons. | |
| 952 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles | 945 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles |
| 953 atYOffset:(CGFloat)yOffset | 946 atYOffset:(CGFloat)yOffset |
| 954 inContainer:(NSView*)container; | 947 inContainer:(NSView*)container; |
| 955 | 948 |
| 956 // Builds the regular profile chooser view. | 949 // Builds the regular profile chooser view. |
| 957 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 950 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 958 tutorialView:(NSView*)tutorialView | 951 tutorialView:(NSView*)tutorialView |
| 959 syncErrorView:(NSView*)syncErrorView | 952 syncErrorView:(NSView*)syncErrorView |
| 960 otherProfiles:(NSArray*)otherProfiles | 953 otherProfiles:(NSArray*)otherProfiles |
| 961 atYOffset:(CGFloat)yOffset | 954 atYOffset:(CGFloat)yOffset |
| 962 inContainer:(NSView*)container | 955 inContainer:(NSView*)container |
| 963 showLock:(bool)showLock; | 956 showLock:(bool)showLock; |
| 964 | 957 |
| 965 // Builds the profile chooser view. | 958 // Builds the profile chooser view. |
| 966 - (NSView*)buildProfileChooserView; | 959 - (NSView*)buildProfileChooserView; |
| 967 | 960 |
| 968 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; | |
| 969 | |
| 970 // Builds a tutorial card with a title label using |titleMessage|, a content | 961 // Builds a tutorial card with a title label using |titleMessage|, a content |
| 971 // label using |contentMessage|, a link using |linkMessage|, and a button using | 962 // label using |contentMessage|, a link using |linkMessage|, and a button using |
| 972 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | 963 // |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 | 964 // 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 | 965 // right aligned. On click, the link would execute |linkAction|, and the button |
| 975 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. | 966 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. |
| 976 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 967 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 977 titleMessage:(NSString*)titleMessage | 968 titleMessage:(NSString*)titleMessage |
| 978 contentMessage:(NSString*)contentMessage | 969 contentMessage:(NSString*)contentMessage |
| 979 linkMessage:(NSString*)linkMessage | 970 linkMessage:(NSString*)linkMessage |
| (...skipping 17 matching lines...) Expand all Loading... |
| 997 | 988 |
| 998 // Builds a tutorial card to have the user confirm the last Chrome signin, | 989 // Builds a tutorial card to have the user confirm the last Chrome signin, |
| 999 // Chrome sync will be delayed until the user either dismisses the tutorial, or | 990 // Chrome sync will be delayed until the user either dismisses the tutorial, or |
| 1000 // configures sync through the "Settings" link. | 991 // configures sync through the "Settings" link. |
| 1001 - (NSView*)buildSigninConfirmationView; | 992 - (NSView*)buildSigninConfirmationView; |
| 1002 | 993 |
| 1003 // Builds a tutorial card to show the last signin error. | 994 // Builds a tutorial card to show the last signin error. |
| 1004 - (NSView*)buildSigninErrorView; | 995 - (NSView*)buildSigninErrorView; |
| 1005 | 996 |
| 1006 // Creates the main profile card for the profile |item| at the top of | 997 // 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 | 998 // the bubble. |
| 1008 // respectively. | |
| 1009 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; | 999 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; |
| 1010 - (NSView*)createMaterialDesignCurrentProfileView:(const AvatarMenu::Item&)item; | |
| 1011 | 1000 |
| 1012 // Creates the possible links for the main profile card with profile |item|. | 1001 // Creates the possible links for the main profile card with profile |item|. |
| 1013 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 1002 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
| 1014 rect:(NSRect)rect; | 1003 rect:(NSRect)rect; |
| 1015 | 1004 |
| 1016 // Creates the disclaimer text for supervised users, telling them that the | 1005 // Creates the disclaimer text for supervised users, telling them that the |
| 1017 // manager can view their history etc. | 1006 // manager can view their history etc. |
| 1018 - (NSView*)createSupervisedUserDisclaimerView; | 1007 - (NSView*)createSupervisedUserDisclaimerView; |
| 1019 | 1008 |
| 1020 // Creates a main profile card for the guest user. | 1009 // Creates a main profile card for the guest user. |
| 1021 - (NSView*)createGuestProfileView; | 1010 - (NSView*)createGuestProfileView; |
| 1022 | 1011 |
| 1023 // Creates an item for the profile |itemIndex| that is used in the fast profile | 1012 // Creates an item for the profile |itemIndex| that is used in the fast profile |
| 1024 // switcher view. | 1013 // switcher view. |
| 1025 - (NSButton*)createOtherProfileView:(int)itemIndex; | 1014 - (NSButton*)createOtherProfileView:(int)itemIndex; |
| 1026 | 1015 |
| 1027 // Creates the following option buttons: lock profile, go incognito, and switch | 1016 // Creates the following option buttons: lock profile/close all windows, switch |
| 1028 // user/exit guest. | 1017 // user/exit guest, and open guest profile. |
| 1029 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 1018 - (NSView*)createOptionsViewWithFrame:(NSRect)frame showLock:(BOOL)showLock; |
| 1030 showLock:(BOOL)showLock; | |
| 1031 // For material design user menu, creates the following option buttons: lock | |
| 1032 // profile/close all windows, switch user/exit guest, and open guest profile. | |
| 1033 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)frame | |
| 1034 showLock:(BOOL)showLock; | |
| 1035 | 1019 |
| 1036 // Creates the account management view for the active profile. | 1020 // Creates the account management view for the active profile. |
| 1037 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; | 1021 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; |
| 1038 | 1022 |
| 1039 // Creates the list of accounts for the active profile. | 1023 // Creates the list of accounts for the active profile. |
| 1040 - (NSView*)createAccountsListWithRect:(NSRect)rect; | 1024 - (NSView*)createAccountsListWithRect:(NSRect)rect; |
| 1041 | 1025 |
| 1042 // Creates the Gaia sign-in/add account view. | 1026 // Creates the Gaia sign-in/add account view. |
| 1043 - (NSView*)buildGaiaEmbeddedView; | 1027 - (NSView*)buildGaiaEmbeddedView; |
| 1044 | 1028 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1424 [[self window] makeFirstResponder:dummyFocusButton]; | 1408 [[self window] makeFirstResponder:dummyFocusButton]; |
| 1425 | 1409 |
| 1426 [contentView addSubview:subView]; | 1410 [contentView addSubview:subView]; |
| 1427 [contentView addSubview:dummyFocusButton]; | 1411 [contentView addSubview:dummyFocusButton]; |
| 1428 SetWindowSize([self window], | 1412 SetWindowSize([self window], |
| 1429 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); | 1413 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); |
| 1430 } | 1414 } |
| 1431 | 1415 |
| 1432 - (CGFloat)addSeparatorToContainer:(NSView*)container | 1416 - (CGFloat)addSeparatorToContainer:(NSView*)container |
| 1433 atYOffset:(CGFloat)yOffset { | 1417 atYOffset:(CGFloat)yOffset { |
| 1434 NSBox* separator = | 1418 NSBox* separator = [self |
| 1435 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, | 1419 horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
| 1436 GetFixedMenuWidth(), 0)]; | |
| 1437 [container addSubview:separator]; | 1420 [container addSubview:separator]; |
| 1438 return NSMaxY([separator frame]); | 1421 return NSMaxY([separator frame]); |
| 1439 } | 1422 } |
| 1440 | 1423 |
| 1441 // Builds the fast user switcher view in |container| at |yOffset| and populates | 1424 // 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 | 1425 // it with the entries for every profile in |otherProfiles|. Returns the new |
| 1443 // yOffset after adding the elements. | 1426 // yOffset after adding the elements. |
| 1444 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles | 1427 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles |
| 1445 atYOffset:(CGFloat)yOffset | 1428 atYOffset:(CGFloat)yOffset |
| 1446 inContainer:(NSView*)container { | 1429 inContainer:(NSView*)container { |
| 1447 // Other profiles switcher. The profiles have already been sorted | 1430 // Other profiles switcher. The profiles have already been sorted |
| 1448 // by their y-coordinate, so they can be added in the existing order. | 1431 // by their y-coordinate, so they can be added in the existing order. |
| 1449 for (NSView* otherProfileView in otherProfiles) { | 1432 for (NSView* otherProfileView in otherProfiles) { |
| 1450 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1433 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1451 [container addSubview:otherProfileView]; | 1434 [container addSubview:otherProfileView]; |
| 1452 yOffset = NSMaxY([otherProfileView frame]); | 1435 yOffset = NSMaxY([otherProfileView frame]); |
| 1453 | |
| 1454 if (!switches::IsMaterialDesignUserMenu()) | |
| 1455 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | |
| 1456 } | 1436 } |
| 1457 | 1437 |
| 1458 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 1438 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 1459 return yOffset; | 1439 return yOffset; |
| 1460 } | 1440 } |
| 1461 | 1441 |
| 1462 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 1442 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 1463 tutorialView:(NSView*)tutorialView | 1443 tutorialView:(NSView*)tutorialView |
| 1464 syncErrorView:(NSView*)syncErrorView | 1444 syncErrorView:(NSView*)syncErrorView |
| 1465 otherProfiles:(NSArray*)otherProfiles | 1445 otherProfiles:(NSArray*)otherProfiles |
| 1466 atYOffset:(CGFloat)yOffset | 1446 atYOffset:(CGFloat)yOffset |
| 1467 inContainer:(NSView*)container | 1447 inContainer:(NSView*)container |
| 1468 showLock:(bool)showLock { | 1448 showLock:(bool)showLock { |
| 1469 if (switches::IsMaterialDesignUserMenu()) | 1449 yOffset += kRelatedControllVerticalSpacing; |
| 1470 yOffset += kRelatedControllVerticalSpacing; | |
| 1471 | 1450 |
| 1472 // Option buttons. | 1451 // Option buttons. |
| 1473 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); | 1452 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); |
| 1474 NSView* optionsView = | 1453 NSView* optionsView = |
| 1475 switches::IsMaterialDesignUserMenu() | 1454 [self createOptionsViewWithFrame:rect showLock:showLock]; |
| 1476 ? [self createMaterialDesignOptionsViewWithFrame:rect | |
| 1477 showLock:showLock] | |
| 1478 : [self createOptionsViewWithRect:rect showLock:showLock]; | |
| 1479 [container addSubview:optionsView]; | 1455 [container addSubview:optionsView]; |
| 1480 rect.origin.y = NSMaxY([optionsView frame]); | 1456 rect.origin.y = NSMaxY([optionsView frame]); |
| 1481 yOffset = rect.origin.y; | 1457 yOffset = rect.origin.y; |
| 1482 | 1458 |
| 1483 // For material design user menu, add the fast user switching buttons. | 1459 // Add the fast user switching buttons. |
| 1484 if (switches::IsMaterialDesignUserMenu()) { | 1460 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles |
| 1485 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles | 1461 atYOffset:yOffset |
| 1486 atYOffset:yOffset | 1462 inContainer:container]; |
| 1487 inContainer:container]; | 1463 yOffset += kRelatedControllVerticalSpacing; |
| 1488 yOffset += kRelatedControllVerticalSpacing; | 1464 rect.origin.y = yOffset; |
| 1489 rect.origin.y = yOffset; | |
| 1490 } | |
| 1491 | 1465 |
| 1492 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | 1466 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; |
| 1493 [container addSubview:separator]; | 1467 [container addSubview:separator]; |
| 1494 yOffset = NSMaxY([separator frame]); | 1468 yOffset = NSMaxY([separator frame]); |
| 1495 | 1469 |
| 1496 // For supervised users, add the disclaimer text. | 1470 // For supervised users, add the disclaimer text. |
| 1497 if (browser_->profile()->IsSupervised()) { | 1471 if (browser_->profile()->IsSupervised()) { |
| 1498 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing | 1472 yOffset += kVerticalSpacing; |
| 1499 : kSmallVerticalSpacing; | |
| 1500 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; | 1473 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; |
| 1501 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; | 1474 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1502 [container addSubview:disclaimerContainer]; | 1475 [container addSubview:disclaimerContainer]; |
| 1503 yOffset = NSMaxY([disclaimerContainer frame]); | 1476 yOffset = NSMaxY([disclaimerContainer frame]); |
| 1504 | |
| 1505 if (!switches::IsMaterialDesignUserMenu()) { | |
| 1506 yOffset += kSmallVerticalSpacing; | |
| 1507 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | |
| 1508 } | |
| 1509 } | 1477 } |
| 1510 | 1478 |
| 1511 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 1479 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 1512 const AvatarMenu::Item& item = | 1480 const AvatarMenu::Item& item = |
| 1513 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 1481 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
| 1514 if (item.signed_in) { | 1482 if (item.signed_in) { |
| 1515 NSView* currentProfileAccountsView = [self | 1483 NSView* currentProfileAccountsView = [self |
| 1516 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, | 1484 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, |
| 1517 GetFixedMenuWidth(), 0)]; | 1485 kFixedMenuWidth, 0)]; |
| 1518 [container addSubview:currentProfileAccountsView]; | 1486 [container addSubview:currentProfileAccountsView]; |
| 1519 yOffset = NSMaxY([currentProfileAccountsView frame]); | 1487 yOffset = NSMaxY([currentProfileAccountsView frame]); |
| 1520 | 1488 |
| 1521 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | 1489 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; |
| 1522 } else { | 1490 } else { |
| 1523 // This is the case when the user selects the sign out option in the user | 1491 // This is the case when the user selects the sign out option in the user |
| 1524 // menu upon encountering unrecoverable errors. Afterwards, the profile | 1492 // menu upon encountering unrecoverable errors. Afterwards, the profile |
| 1525 // chooser view is shown instead of the account management view. | 1493 // chooser view is shown instead of the account management view. |
| 1526 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 1494 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 1527 } | 1495 } |
| 1528 } | 1496 } |
| 1529 | 1497 |
| 1530 // Active profile card. | 1498 // Active profile card. |
| 1531 if (currentProfileView) { | 1499 if (currentProfileView) { |
| 1532 const CGFloat verticalSpacing = switches::IsMaterialDesignUserMenu() | 1500 const CGFloat verticalSpacing = kRelatedControllVerticalSpacing; |
| 1533 ? kRelatedControllVerticalSpacing | |
| 1534 : kVerticalSpacing; | |
| 1535 yOffset += verticalSpacing; | 1501 yOffset += verticalSpacing; |
| 1536 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1502 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1537 [container addSubview:currentProfileView]; | 1503 [container addSubview:currentProfileView]; |
| 1538 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; | 1504 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; |
| 1539 } | 1505 } |
| 1540 | 1506 |
| 1541 if (syncErrorView) { | 1507 if (syncErrorView) { |
| 1542 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | 1508 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; |
| 1543 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1509 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1544 [container addSubview:syncErrorView]; | 1510 [container addSubview:syncErrorView]; |
| 1545 yOffset = NSMaxY([syncErrorView frame]); | 1511 yOffset = NSMaxY([syncErrorView frame]); |
| 1546 } | 1512 } |
| 1547 | 1513 |
| 1548 if (tutorialView) { | 1514 if (tutorialView) { |
| 1549 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1515 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1550 [container addSubview:tutorialView]; | 1516 [container addSubview:tutorialView]; |
| 1551 yOffset = NSMaxY([tutorialView frame]); | 1517 yOffset = NSMaxY([tutorialView frame]); |
| 1552 //TODO(mlerman): update UMA stats for the new tutorials. | 1518 //TODO(mlerman): update UMA stats for the new tutorials. |
| 1553 } else { | 1519 } else { |
| 1554 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | 1520 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
| 1555 } | 1521 } |
| 1556 | 1522 |
| 1557 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 1523 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 1558 } | 1524 } |
| 1559 | 1525 |
| 1560 - (NSView*)buildProfileChooserView { | 1526 - (NSView*)buildProfileChooserView { |
| 1561 base::scoped_nsobject<NSView> container( | 1527 base::scoped_nsobject<NSView> container( |
| 1562 [[NSView alloc] initWithFrame:NSZeroRect]); | 1528 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 1563 | 1529 |
| 1564 NSView* tutorialView = nil; | 1530 NSView* tutorialView = nil; |
| 1565 NSView* syncErrorView = nil; | 1531 NSView* syncErrorView = nil; |
| 1566 NSView* currentProfileView = nil; | 1532 NSView* currentProfileView = nil; |
| 1567 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1533 base::scoped_nsobject<NSMutableArray> otherProfiles( |
| 1568 [[NSMutableArray alloc] init]); | 1534 [[NSMutableArray alloc] init]); |
| 1569 // Local and guest profiles cannot lock their profile. | 1535 // Local and guest profiles cannot lock their profile. |
| 1570 bool showLock = false; | 1536 bool showLock = false; |
| 1571 bool isFastProfileChooser = | 1537 bool isFastProfileChooser = |
| 1572 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 1538 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 1573 if (isFastProfileChooser) { | 1539 if (isFastProfileChooser) { |
| 1574 // The user is using right-click switching, no need to tell them about it. | 1540 // The user is using right-click switching, no need to tell them about it. |
| 1575 PrefService* localState = g_browser_process->local_state(); | 1541 PrefService* localState = g_browser_process->local_state(); |
| 1576 localState->SetBoolean( | 1542 localState->SetBoolean( |
| 1577 prefs::kProfileAvatarRightClickTutorialDismissed, true); | 1543 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1578 } | 1544 } |
| 1579 | 1545 |
| 1580 // Loop over the profiles in reverse, so that they are sorted by their | 1546 // Loop over the profiles in reverse, so that they are sorted by their |
| 1581 // y-coordinate, and separate them into active and "other" profiles. | 1547 // y-coordinate, and separate them into active and "other" profiles. |
| 1582 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1548 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
| 1583 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); | 1549 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); |
| 1584 if (item.active) { | 1550 if (item.active) { |
| 1585 if (switches::IsMaterialDesignUserMenu()) { | 1551 syncErrorView = [self buildSyncErrorViewIfNeeded]; |
| 1586 syncErrorView = [self buildSyncErrorViewIfNeeded]; | 1552 currentProfileView = [self createCurrentProfileView: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 && | 1553 showLock = item.signed_in && |
| 1595 profiles::IsLockAvailable(browser_->profile()); | 1554 profiles::IsLockAvailable(browser_->profile()); |
| 1596 } else { | 1555 } else { |
| 1597 [otherProfiles addObject:[self createOtherProfileView:i]]; | 1556 [otherProfiles addObject:[self createOtherProfileView:i]]; |
| 1598 } | 1557 } |
| 1599 } | 1558 } |
| 1600 firstProfileView_ = [otherProfiles lastObject]; | 1559 firstProfileView_ = [otherProfiles lastObject]; |
| 1601 if (!currentProfileView) // Guest windows don't have an active profile. | 1560 if (!currentProfileView) // Guest windows don't have an active profile. |
| 1602 currentProfileView = [self createGuestProfileView]; | 1561 currentProfileView = [self createGuestProfileView]; |
| 1603 | 1562 |
| 1604 // |yOffset| is the next position at which to draw in |container| | 1563 // |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 | 1564 // coordinates. Add a pixel offset so that the bottom option buttons don't |
| 1606 // overlap the bubble's rounded corners. | 1565 // overlap the bubble's rounded corners. |
| 1607 CGFloat yOffset = 1; | 1566 CGFloat yOffset = 1; |
| 1608 | 1567 |
| 1609 if (isFastProfileChooser) { | 1568 if (!isFastProfileChooser) |
| 1610 if (!switches::IsMaterialDesignUserMenu()) { | |
| 1611 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() | |
| 1612 atYOffset:yOffset | |
| 1613 inContainer:container]; | |
| 1614 } | |
| 1615 } else { | |
| 1616 [self buildProfileChooserViewWithProfileView:currentProfileView | 1569 [self buildProfileChooserViewWithProfileView:currentProfileView |
| 1617 tutorialView:tutorialView | 1570 tutorialView:tutorialView |
| 1618 syncErrorView:syncErrorView | 1571 syncErrorView:syncErrorView |
| 1619 otherProfiles:otherProfiles.get() | 1572 otherProfiles:otherProfiles.get() |
| 1620 atYOffset:yOffset | 1573 atYOffset:yOffset |
| 1621 inContainer:container | 1574 inContainer:container |
| 1622 showLock:showLock]; | 1575 showLock:showLock]; |
| 1623 } | |
| 1624 | 1576 |
| 1625 return container.autorelease(); | 1577 return container.autorelease(); |
| 1626 } | 1578 } |
| 1627 | 1579 |
| 1628 - (NSView*)buildSigninConfirmationView { | 1580 - (NSView*)buildSigninConfirmationView { |
| 1629 ProfileMetrics::LogProfileNewAvatarMenuSignin( | 1581 ProfileMetrics::LogProfileNewAvatarMenuSignin( |
| 1630 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); | 1582 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); |
| 1631 | 1583 |
| 1632 NSString* titleMessage = l10n_util::GetNSString( | 1584 NSString* titleMessage = l10n_util::GetNSString( |
| 1633 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); | 1585 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { | 1623 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { |
| 1672 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | 1624 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( |
| 1673 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); | 1625 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); |
| 1674 | 1626 |
| 1675 NSString* titleMessage = l10n_util::GetNSString( | 1627 NSString* titleMessage = l10n_util::GetNSString( |
| 1676 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); | 1628 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); |
| 1677 NSString* contentMessage = l10n_util::GetNSString( | 1629 NSString* contentMessage = l10n_util::GetNSString( |
| 1678 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); | 1630 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); |
| 1679 // For local profiles, the "Not you" link doesn't make sense. | 1631 // For local profiles, the "Not you" link doesn't make sense. |
| 1680 NSString* linkMessage = | 1632 NSString* linkMessage = |
| 1681 item.signed_in | 1633 item.signed_in ? ElideMessage(l10n_util::GetStringFUTF16( |
| 1682 ? ElideMessage( | 1634 IDS_PROFILES_NOT_YOU, item.name), |
| 1683 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name), | 1635 kFixedMenuWidth - 2 * kHorizontalSpacing) |
| 1684 GetFixedMenuWidth() - 2 * kHorizontalSpacing) | 1636 : nil; |
| 1685 : nil; | |
| 1686 NSString* buttonMessage = l10n_util::GetNSString( | 1637 NSString* buttonMessage = l10n_util::GetNSString( |
| 1687 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); | 1638 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); |
| 1688 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE | 1639 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE |
| 1689 titleMessage:titleMessage | 1640 titleMessage:titleMessage |
| 1690 contentMessage:contentMessage | 1641 contentMessage:contentMessage |
| 1691 linkMessage:linkMessage | 1642 linkMessage:linkMessage |
| 1692 buttonMessage:buttonMessage | 1643 buttonMessage:buttonMessage |
| 1693 stackButton:YES | 1644 stackButton:YES |
| 1694 hasCloseButton:YES | 1645 hasCloseButton:YES |
| 1695 linkAction:@selector(showSwitchUserView:) | 1646 linkAction:@selector(showSwitchUserView:) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1709 titleMessage:titleMessage | 1660 titleMessage:titleMessage |
| 1710 contentMessage:contentMessage | 1661 contentMessage:contentMessage |
| 1711 linkMessage:nil | 1662 linkMessage:nil |
| 1712 buttonMessage:buttonMessage | 1663 buttonMessage:buttonMessage |
| 1713 stackButton:NO | 1664 stackButton:NO |
| 1714 hasCloseButton:NO | 1665 hasCloseButton:NO |
| 1715 linkAction:nil | 1666 linkAction:nil |
| 1716 buttonAction:@selector(dismissTutorial:)]; | 1667 buttonAction:@selector(dismissTutorial:)]; |
| 1717 } | 1668 } |
| 1718 | 1669 |
| 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 | 1670 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 1746 titleMessage:(NSString*)titleMessage | 1671 titleMessage:(NSString*)titleMessage |
| 1747 contentMessage:(NSString*)contentMessage | 1672 contentMessage:(NSString*)contentMessage |
| 1748 linkMessage:(NSString*)linkMessage | 1673 linkMessage:(NSString*)linkMessage |
| 1749 buttonMessage:(NSString*)buttonMessage | 1674 buttonMessage:(NSString*)buttonMessage |
| 1750 stackButton:(BOOL)stackButton | 1675 stackButton:(BOOL)stackButton |
| 1751 hasCloseButton:(BOOL)hasCloseButton | 1676 hasCloseButton:(BOOL)hasCloseButton |
| 1752 linkAction:(SEL)linkAction | 1677 linkAction:(SEL)linkAction |
| 1753 buttonAction:(SEL)buttonAction { | 1678 buttonAction:(SEL)buttonAction { |
| 1754 tutorialMode_ = mode; | 1679 tutorialMode_ = mode; |
| 1755 | 1680 |
| 1756 NSColor* tutorialBackgroundColor = | 1681 NSColor* tutorialBackgroundColor = |
| 1757 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); | 1682 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); |
| 1758 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | 1683 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
| 1759 initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0) | 1684 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) |
| 1760 withColor:tutorialBackgroundColor]); | 1685 withColor:tutorialBackgroundColor]); |
| 1761 CGFloat availableWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; | 1686 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; |
| 1762 CGFloat yOffset = kVerticalSpacing; | 1687 CGFloat yOffset = kVerticalSpacing; |
| 1763 | 1688 |
| 1764 // Adds links and buttons at the bottom. | 1689 // Adds links and buttons at the bottom. |
| 1765 base::scoped_nsobject<NSButton> tutorialOkButton; | 1690 base::scoped_nsobject<NSButton> tutorialOkButton; |
| 1766 if (buttonMessage) { | 1691 if (buttonMessage) { |
| 1767 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); | 1692 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); |
| 1768 [tutorialOkButton setTitle:buttonMessage]; | 1693 [tutorialOkButton setTitle:buttonMessage]; |
| 1769 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; | 1694 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; |
| 1770 [tutorialOkButton setTarget:self]; | 1695 [tutorialOkButton setTarget:self]; |
| 1771 [tutorialOkButton setAction:buttonAction]; | 1696 [tutorialOkButton setAction:buttonAction]; |
| 1772 [tutorialOkButton setAlignment:NSCenterTextAlignment]; | 1697 [tutorialOkButton setAlignment:NSCenterTextAlignment]; |
| 1773 [tutorialOkButton sizeToFit]; | 1698 [tutorialOkButton sizeToFit]; |
| 1774 } | 1699 } |
| 1775 | 1700 |
| 1776 NSButton* learnMoreLink = nil; | 1701 NSButton* learnMoreLink = nil; |
| 1777 if (linkMessage) { | 1702 if (linkMessage) { |
| 1778 learnMoreLink = [self linkButtonWithTitle:linkMessage | 1703 learnMoreLink = [self linkButtonWithTitle:linkMessage |
| 1779 frameOrigin:NSZeroPoint | 1704 frameOrigin:NSZeroPoint |
| 1780 action:linkAction]; | 1705 action:linkAction]; |
| 1781 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; | 1706 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; |
| 1782 } | 1707 } |
| 1783 | 1708 |
| 1784 if (stackButton) { | 1709 if (stackButton) { |
| 1785 [learnMoreLink | 1710 [learnMoreLink setFrameOrigin:NSMakePoint((kFixedMenuWidth - |
| 1786 setFrameOrigin:NSMakePoint((GetFixedMenuWidth() - | 1711 NSWidth([learnMoreLink frame])) / |
| 1787 NSWidth([learnMoreLink frame])) / 2, | 1712 2, |
| 1788 yOffset)]; | 1713 yOffset)]; |
| 1789 [tutorialOkButton setFrameSize:NSMakeSize( | 1714 [tutorialOkButton setFrameSize:NSMakeSize( |
| 1790 availableWidth, NSHeight([tutorialOkButton frame]))]; | 1715 availableWidth, NSHeight([tutorialOkButton frame]))]; |
| 1791 [tutorialOkButton setFrameOrigin:NSMakePoint( | 1716 [tutorialOkButton setFrameOrigin:NSMakePoint( |
| 1792 kHorizontalSpacing, | 1717 kHorizontalSpacing, |
| 1793 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; | 1718 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; |
| 1794 } else { | 1719 } else { |
| 1795 if (buttonMessage) { | 1720 if (buttonMessage) { |
| 1796 NSSize buttonSize = [tutorialOkButton frame].size; | 1721 NSSize buttonSize = [tutorialOkButton frame].size; |
| 1797 const CGFloat kTopBottomTextPadding = 6; | 1722 const CGFloat kTopBottomTextPadding = 6; |
| 1798 const CGFloat kLeftRightTextPadding = 15; | 1723 const CGFloat kLeftRightTextPadding = 15; |
| 1799 buttonSize.width += 2 * kLeftRightTextPadding; | 1724 buttonSize.width += 2 * kLeftRightTextPadding; |
| 1800 buttonSize.height += 2 * kTopBottomTextPadding; | 1725 buttonSize.height += 2 * kTopBottomTextPadding; |
| 1801 [tutorialOkButton setFrameSize:buttonSize]; | 1726 [tutorialOkButton setFrameSize:buttonSize]; |
| 1802 CGFloat buttonXOffset = GetFixedMenuWidth() - | 1727 CGFloat buttonXOffset = kFixedMenuWidth - |
| 1803 NSWidth([tutorialOkButton frame]) - | 1728 NSWidth([tutorialOkButton frame]) - |
| 1804 kHorizontalSpacing; | 1729 kHorizontalSpacing; |
| 1805 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; | 1730 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; |
| 1806 } | 1731 } |
| 1807 | 1732 |
| 1808 if (linkMessage) { | 1733 if (linkMessage) { |
| 1809 CGFloat linkYOffset = yOffset; | 1734 CGFloat linkYOffset = yOffset; |
| 1810 if (buttonMessage) { | 1735 if (buttonMessage) { |
| 1811 linkYOffset += (NSHeight([tutorialOkButton frame]) - | 1736 linkYOffset += (NSHeight([tutorialOkButton frame]) - |
| 1812 NSHeight([learnMoreLink frame])) / 2; | 1737 NSHeight([learnMoreLink frame])) / 2; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1855 CGFloat closeImageWidth = [closeImage size].width; | 1780 CGFloat closeImageWidth = [closeImage size].width; |
| 1856 [closeButton setDefaultImage:closeImage]; | 1781 [closeButton setDefaultImage:closeImage]; |
| 1857 [closeButton setHoverImage: | 1782 [closeButton setHoverImage: |
| 1858 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()]; | 1783 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()]; |
| 1859 [closeButton setPressedImage: | 1784 [closeButton setPressedImage: |
| 1860 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()]; | 1785 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()]; |
| 1861 [closeButton setTarget:self]; | 1786 [closeButton setTarget:self]; |
| 1862 [closeButton setAction:@selector(dismissTutorial:)]; | 1787 [closeButton setAction:@selector(dismissTutorial:)]; |
| 1863 [closeButton setFrameSize:[closeImage size]]; | 1788 [closeButton setFrameSize:[closeImage size]]; |
| 1864 [closeButton | 1789 [closeButton |
| 1865 setFrameOrigin:NSMakePoint(GetFixedMenuWidth() - kHorizontalSpacing - | 1790 setFrameOrigin:NSMakePoint(kFixedMenuWidth - kHorizontalSpacing - |
| 1866 closeImageWidth, | 1791 closeImageWidth, |
| 1867 yOffset)]; | 1792 yOffset)]; |
| 1868 [container addSubview:closeButton]; | 1793 [container addSubview:closeButton]; |
| 1869 | 1794 |
| 1870 [titleLabel setFrameSize:NSMakeSize( | 1795 [titleLabel setFrameSize:NSMakeSize( |
| 1871 availableWidth - closeImageWidth - kHorizontalSpacing, 0)]; | 1796 availableWidth - closeImageWidth - kHorizontalSpacing, 0)]; |
| 1872 } else { | 1797 } else { |
| 1873 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1798 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
| 1874 } | 1799 } |
| 1875 | 1800 |
| 1876 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; | 1801 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; |
| 1877 [container addSubview:titleLabel]; | 1802 [container addSubview:titleLabel]; |
| 1878 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; | 1803 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; |
| 1879 | 1804 |
| 1880 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 1805 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 1881 [container setFrameOrigin:NSZeroPoint]; | 1806 [container setFrameOrigin:NSZeroPoint]; |
| 1882 return container.autorelease(); | 1807 return container.autorelease(); |
| 1883 } | 1808 } |
| 1884 | 1809 |
| 1885 - (NSView*)buildSyncErrorViewIfNeeded { | 1810 - (NSView*)buildSyncErrorViewIfNeeded { |
| 1886 int contentStringId, buttonStringId; | 1811 int contentStringId, buttonStringId; |
| 1887 SEL buttonAction; | 1812 SEL buttonAction; |
| 1888 sync_ui_util::AvatarSyncErrorType error = | 1813 sync_ui_util::AvatarSyncErrorType error = |
| 1889 sync_ui_util::GetMessagesForAvatarSyncError( | 1814 sync_ui_util::GetMessagesForAvatarSyncError( |
| 1890 browser_->profile(), &contentStringId, &buttonStringId); | 1815 browser_->profile(), &contentStringId, &buttonStringId); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1907 case sync_ui_util::PASSPHRASE_ERROR: | 1832 case sync_ui_util::PASSPHRASE_ERROR: |
| 1908 buttonAction = @selector(showSyncPassphraseSetupView:); | 1833 buttonAction = @selector(showSyncPassphraseSetupView:); |
| 1909 break; | 1834 break; |
| 1910 case sync_ui_util::NO_SYNC_ERROR: | 1835 case sync_ui_util::NO_SYNC_ERROR: |
| 1911 return nil; | 1836 return nil; |
| 1912 default: | 1837 default: |
| 1913 NOTREACHED(); | 1838 NOTREACHED(); |
| 1914 } | 1839 } |
| 1915 | 1840 |
| 1916 base::scoped_nsobject<NSView> container( | 1841 base::scoped_nsobject<NSView> container( |
| 1917 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, GetFixedMenuWidth(), 0)]); | 1842 [[NSView alloc] initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0)]); |
| 1918 CGFloat iconSize = 20.0; | 1843 CGFloat iconSize = 20.0; |
| 1919 CGFloat xOffset = kHorizontalSpacing + iconSize + 12.0; | 1844 CGFloat xOffset = kHorizontalSpacing + iconSize + 12.0; |
| 1920 CGFloat availableWidth = GetFixedMenuWidth() - xOffset - kHorizontalSpacing; | 1845 CGFloat availableWidth = kFixedMenuWidth - xOffset - kHorizontalSpacing; |
| 1921 CGFloat yOffset = 16.0; | 1846 CGFloat yOffset = 16.0; |
| 1922 | 1847 |
| 1923 // Adds an action button for resolving the error at the bottom. | 1848 // Adds an action button for resolving the error at the bottom. |
| 1924 if (buttonStringId) { | 1849 if (buttonStringId) { |
| 1925 // If the button string is specified, then the button action needs to be | 1850 // If the button string is specified, then the button action needs to be |
| 1926 // already initialized for the button to be constructed. | 1851 // already initialized for the button to be constructed. |
| 1927 DCHECK(buttonAction); | 1852 DCHECK(buttonAction); |
| 1928 base::scoped_nsobject<NSButton> resolveErrorButton( | 1853 base::scoped_nsobject<NSButton> resolveErrorButton( |
| 1929 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); | 1854 [[BlueLabelButton alloc] initWithFrame:NSZeroRect]); |
| 1930 [resolveErrorButton setTitle:l10n_util::GetNSString(buttonStringId)]; | 1855 [resolveErrorButton setTitle:l10n_util::GetNSString(buttonStringId)]; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1959 // Adds the sync problem icon. | 1884 // Adds the sync problem icon. |
| 1960 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc] | 1885 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc] |
| 1961 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize, | 1886 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize, |
| 1962 iconSize)]); | 1887 iconSize)]); |
| 1963 [syncProblemIcon | 1888 [syncProblemIcon |
| 1964 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | 1889 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 1965 kSyncProblemIcon, iconSize, gfx::kGoogleRed700))]; | 1890 kSyncProblemIcon, iconSize, gfx::kGoogleRed700))]; |
| 1966 [container addSubview:syncProblemIcon]; | 1891 [container addSubview:syncProblemIcon]; |
| 1967 | 1892 |
| 1968 [container | 1893 [container |
| 1969 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; | 1894 setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset + kVerticalSpacing)]; |
| 1970 return container.autorelease(); | 1895 return container.autorelease(); |
| 1971 } | 1896 } |
| 1972 | 1897 |
| 1973 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { | 1898 - (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: | |
| 2050 (const AvatarMenu::Item&)item { | |
| 2051 base::scoped_nsobject<NSView> container( | 1899 base::scoped_nsobject<NSView> container( |
| 2052 [[NSView alloc] initWithFrame:NSZeroRect]); | 1900 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 2053 | 1901 |
| 2054 CGFloat xOffset = kHorizontalSpacing; | 1902 CGFloat xOffset = kHorizontalSpacing; |
| 2055 CGFloat yOffset = 0.0; | 1903 CGFloat yOffset = 0.0; |
| 2056 CGFloat cardYOffset = kRelatedControllVerticalSpacing; | 1904 CGFloat cardYOffset = kRelatedControllVerticalSpacing; |
| 2057 CGFloat availableTextWidth = | 1905 CGFloat availableTextWidth = |
| 2058 GetFixedMenuWidth() - 3.0 * kHorizontalSpacing - kMdImageSide; | 1906 kFixedMenuWidth - 3.0 * kHorizontalSpacing - kMdImageSide; |
| 2059 CGFloat maxAvailableTextWidth = GetFixedMenuWidth() - kHorizontalSpacing; | 1907 CGFloat maxAvailableTextWidth = kFixedMenuWidth - kHorizontalSpacing; |
| 2060 | 1908 |
| 2061 // Profile options. This can be a link to the accounts view, or a "Sign in" | 1909 // Profile options. This can be a link to the accounts view, or a "Sign in" |
| 2062 // button for local profiles. | 1910 // button for local profiles. |
| 2063 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( | 1911 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( |
| 2064 browser_->profile()->GetOriginalProfile()); | 1912 browser_->profile()->GetOriginalProfile()); |
| 2065 NSRect profileLinksBound = NSZeroRect; | 1913 NSRect profileLinksBound = NSZeroRect; |
| 2066 if (item.signed_in && switches::IsEnableAccountConsistency()) { | 1914 if (item.signed_in && switches::IsEnableAccountConsistency()) { |
| 2067 profileLinksBound = NSMakeRect(0, 0, GetFixedMenuWidth(), kVerticalSpacing); | 1915 profileLinksBound = NSMakeRect(0, 0, kFixedMenuWidth, kVerticalSpacing); |
| 2068 } else if (!item.signed_in && signinManager->IsSigninAllowed()) { | 1916 } else if (!item.signed_in && signinManager->IsSigninAllowed()) { |
| 2069 profileLinksBound = NSMakeRect(xOffset, kRelatedControllVerticalSpacing, | 1917 profileLinksBound = NSMakeRect(xOffset, kRelatedControllVerticalSpacing, |
| 2070 maxAvailableTextWidth, kVerticalSpacing); | 1918 maxAvailableTextWidth, kVerticalSpacing); |
| 2071 } | 1919 } |
| 2072 if (!NSIsEmptyRect(profileLinksBound)) { | 1920 if (!NSIsEmptyRect(profileLinksBound)) { |
| 2073 NSView* linksContainer = | 1921 NSView* linksContainer = |
| 2074 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; | 1922 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; |
| 2075 [container addSubview:linksContainer]; | 1923 [container addSubview:linksContainer]; |
| 2076 yOffset = NSMaxY([linksContainer frame]); | 1924 yOffset = NSMaxY([linksContainer frame]); |
| 2077 } | 1925 } |
| 2078 | 1926 |
| 2079 // Profile card button that contains the profile icon, name, and username. | 1927 // Profile card button that contains the profile icon, name, and username. |
| 2080 const base::string16 profileNameString = | 1928 const base::string16 profileNameString = |
| 2081 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); | 1929 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath()); |
| 2082 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), | 1930 NSRect rect = |
| 2083 kMdImageSide + kVerticalSpacing); | 1931 NSMakeRect(0, yOffset, kFixedMenuWidth, kMdImageSide + kVerticalSpacing); |
| 2084 NSButton* profileCard = | 1932 NSButton* profileCard = |
| 2085 [self hoverButtonWithRect:rect | 1933 [self hoverButtonWithRect:rect |
| 2086 text:[[NSString alloc] init] | 1934 text:[[NSString alloc] init] |
| 2087 image:CreateProfileImage(item.icon, kMdImageSide, | 1935 image:CreateProfileImage(item.icon, kMdImageSide, |
| 2088 profiles::SHAPE_CIRCLE) | 1936 profiles::SHAPE_CIRCLE) |
| 2089 action:@selector(editProfile:)]; | 1937 action:@selector(editProfile:)]; |
| 2090 [[profileCard cell] setImageDimsWhenDisabled:NO]; | 1938 [[profileCard cell] setImageDimsWhenDisabled:NO]; |
| 2091 if (item.signed_in) { | 1939 if (item.signed_in) { |
| 2092 [[profileCard cell] | 1940 [[profileCard cell] |
| 2093 accessibilitySetOverrideValue: | 1941 accessibilitySetOverrideValue: |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2171 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; | 2019 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; |
| 2172 NSString* usernameNSString = base::SysUTF16ToNSString(item.username); | 2020 NSString* usernameNSString = base::SysUTF16ToNSString(item.username); |
| 2173 if (![elidedEmail isEqualToString:usernameNSString]) { | 2021 if (![elidedEmail isEqualToString:usernameNSString]) { |
| 2174 // Add the tooltip only if the user name is truncated. | 2022 // Add the tooltip only if the user name is truncated. |
| 2175 username.toolTip = usernameNSString; | 2023 username.toolTip = usernameNSString; |
| 2176 } | 2024 } |
| 2177 [profileCard addSubview:username]; | 2025 [profileCard addSubview:username]; |
| 2178 } | 2026 } |
| 2179 | 2027 |
| 2180 yOffset = NSMaxY([profileCard frame]); | 2028 yOffset = NSMaxY([profileCard frame]); |
| 2181 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 2029 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 2182 return container.autorelease(); | 2030 return container.autorelease(); |
| 2183 } | 2031 } |
| 2184 | 2032 |
| 2185 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 2033 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
| 2186 rect:(NSRect)rect { | 2034 rect:(NSRect)rect { |
| 2187 if (switches::IsMaterialDesignUserMenu()) { | 2035 // The branch is empty in non-account-consistency mode, because in that case, |
| 2188 // The branch is empty for material design user menu in non-account- | 2036 // the username would appear in the profile card instead of as a separate link |
| 2189 // consistency mode, because in that case, the username would appear in the | 2037 // here. |
| 2190 // profile card instead of as a separate link here. | 2038 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( |
| 2191 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( | 2039 browser_->profile()->GetOriginalProfile()); |
| 2192 browser_->profile()->GetOriginalProfile()); | 2040 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) || |
| 2193 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) || | 2041 (!item.signed_in && signinManager->IsSigninAllowed())); |
| 2194 (!item.signed_in && signinManager->IsSigninAllowed())); | |
| 2195 } | |
| 2196 | 2042 |
| 2197 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 2043 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
| 2198 | 2044 |
| 2199 // Don't double-apply the left margin to the sub-views. | 2045 // Don't double-apply the left margin to the sub-views. |
| 2200 rect.origin.x = 0; | 2046 rect.origin.x = 0; |
| 2201 | 2047 |
| 2202 // Adds right padding. | 2048 // Adds right padding. |
| 2203 const CGFloat kRightPadding = kHorizontalSpacing; | 2049 const CGFloat kRightPadding = kHorizontalSpacing; |
| 2204 rect.size.width -= kRightPadding; | 2050 rect.size.width -= kRightPadding; |
| 2205 | 2051 |
| 2206 // The available links depend on the type of profile that is active. | 2052 // The available links depend on the type of profile that is active. |
| 2207 if (item.signed_in) { | 2053 if (item.signed_in) { |
| 2208 NSButton* link = nil; | 2054 NSButton* link = nil; |
| 2209 if (switches::IsEnableAccountConsistency()) { | 2055 if (switches::IsEnableAccountConsistency()) { |
| 2210 NSString* linkTitle = l10n_util::GetNSString( | 2056 NSString* linkTitle = l10n_util::GetNSString( |
| 2211 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? | 2057 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? |
| 2212 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : | 2058 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| 2213 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 2059 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 2214 SEL linkSelector = | 2060 SEL linkSelector = |
| 2215 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? | 2061 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? |
| 2216 @selector(showAccountManagement:) : @selector(hideAccountManagement:); | 2062 @selector(showAccountManagement:) : @selector(hideAccountManagement:); |
| 2217 if (switches::IsMaterialDesignUserMenu()) { | 2063 rect.size.width += kRightPadding; // Spans the width of the entire menu. |
| 2218 rect.size.width += | 2064 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width, |
| 2219 kRightPadding; // Spans the width of the entire menu. | 2065 kBlueButtonHeight) |
| 2220 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width, | 2066 text:linkTitle |
| 2221 kBlueButtonHeight) | 2067 action:linkSelector]; |
| 2222 text:linkTitle | |
| 2223 action:linkSelector]; | |
| 2224 } else { | |
| 2225 link = [self linkButtonWithTitle:linkTitle | |
| 2226 frameOrigin:rect.origin | |
| 2227 action:linkSelector]; | |
| 2228 } | |
| 2229 } else if (!switches::IsMaterialDesignUserMenu()) { | |
| 2230 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.username) | |
| 2231 frameOrigin:rect.origin | |
| 2232 action:nil]; | |
| 2233 if (HasAuthError(browser_->profile())) { | |
| 2234 [link setImage:ui::ResourceBundle::GetSharedInstance(). | |
| 2235 GetNativeImageNamed(IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR). | |
| 2236 ToNSImage()]; | |
| 2237 [link setImagePosition:NSImageRight]; | |
| 2238 [link setTarget:self]; | |
| 2239 [link setAction:@selector(showAccountReauthenticationView:)]; | |
| 2240 [link setTag:kPrimaryProfileTag]; | |
| 2241 [[link cell] | |
| 2242 accessibilitySetOverrideValue:l10n_util::GetNSStringF( | |
| 2243 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME, | |
| 2244 item.username) | |
| 2245 forAttribute:NSAccessibilityTitleAttribute]; | |
| 2246 } else { | |
| 2247 // Signed in profiles with no authentication errors do not have a | |
| 2248 // clickable email link. | |
| 2249 [link setEnabled:NO]; | |
| 2250 } | |
| 2251 } | 2068 } |
| 2252 if (link) { | 2069 if (link) { |
| 2253 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but | 2070 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but |
| 2254 // need to re-stretch the width so that the link can be centered correctly | 2071 // need to re-stretch the width so that the link can be centered correctly |
| 2255 // in the view. | 2072 // in the view. |
| 2256 rect.size.height = [link frame].size.height; | 2073 rect.size.height = [link frame].size.height; |
| 2257 if (!switches::IsMaterialDesignUserMenu()) | |
| 2258 [link setAlignment:NSCenterTextAlignment]; | |
| 2259 [link setFrame:rect]; | 2074 [link setFrame:rect]; |
| 2260 [container addSubview:link]; | 2075 [container addSubview:link]; |
| 2261 [container setFrameSize:rect.size]; | 2076 [container setFrameSize:rect.size]; |
| 2262 } | 2077 } |
| 2263 } else { | 2078 } else { |
| 2264 rect.size.height = kBlueButtonHeight; | 2079 rect.size.height = kBlueButtonHeight; |
| 2265 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect]; | 2080 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect]; |
| 2266 | 2081 |
| 2267 // Manually elide the button text so that the contents fit inside the bubble | 2082 // Manually elide the button text so that the contents fit inside the bubble |
| 2268 // This is needed because the BlueLabelButton cell resets the style on | 2083 // This is needed because the BlueLabelButton cell resets the style on |
| 2269 // every call to -cellSize, which prevents setting a custom lineBreakMode. | 2084 // every call to -cellSize, which prevents setting a custom lineBreakMode. |
| 2270 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( | 2085 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( |
| 2271 l10n_util::GetStringFUTF16( | 2086 l10n_util::GetStringFUTF16( |
| 2272 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 2087 IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 2273 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), | 2088 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), |
| 2274 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); | 2089 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); |
| 2275 | 2090 |
| 2276 [signinButton setTitle:elidedButtonText]; | 2091 [signinButton setTitle:elidedButtonText]; |
| 2277 if (switches::IsMaterialDesignUserMenu()) | 2092 [signinButton sizeToFit]; |
| 2278 [signinButton sizeToFit]; | |
| 2279 [signinButton setTarget:self]; | 2093 [signinButton setTarget:self]; |
| 2280 [signinButton setAction:@selector(showInlineSigninPage:)]; | 2094 [signinButton setAction:@selector(showInlineSigninPage:)]; |
| 2281 [container addSubview:signinButton]; | 2095 [container addSubview:signinButton]; |
| 2282 | 2096 |
| 2283 // Sign-in promo text. | 2097 // Sign-in promo text. |
| 2284 NSTextField* promo = BuildLabel( | 2098 NSTextField* promo = BuildLabel( |
| 2285 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), | 2099 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), |
| 2286 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), | 2100 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), |
| 2287 nil); | 2101 nil); |
| 2288 if (kRightPadding >= 8) | 2102 if (kRightPadding >= 8) |
| 2289 rect.size.width += 8; // Re-stretch a little bit to fit promo text. | 2103 rect.size.width += 8; // Re-stretch a little bit to fit promo text. |
| 2290 DCHECK(kRightPadding >= 8); | 2104 DCHECK(kRightPadding >= 8); |
| 2291 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; | 2105 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; |
| 2292 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; | 2106 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; |
| 2293 [container addSubview:promo]; | 2107 [container addSubview:promo]; |
| 2294 | 2108 |
| 2295 [container | 2109 [container setFrameSize:NSMakeSize(rect.size.width, |
| 2296 setFrameSize:NSMakeSize(rect.size.width, | 2110 NSMaxY([promo frame]) + |
| 2297 NSMaxY([promo frame]) + | 2111 kRelatedControllVerticalSpacing)]; |
| 2298 (switches::IsMaterialDesignUserMenu() | |
| 2299 ? kRelatedControllVerticalSpacing | |
| 2300 : 4))]; | |
| 2301 content::RecordAction( | 2112 content::RecordAction( |
| 2302 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 2113 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| 2303 } | 2114 } |
| 2304 | 2115 |
| 2305 return container.autorelease(); | 2116 return container.autorelease(); |
| 2306 } | 2117 } |
| 2307 | 2118 |
| 2308 - (NSView*)createSupervisedUserDisclaimerView { | 2119 - (NSView*)createSupervisedUserDisclaimerView { |
| 2309 base::scoped_nsobject<NSView> container( | 2120 base::scoped_nsobject<NSView> container( |
| 2310 [[NSView alloc] initWithFrame:NSZeroRect]); | 2121 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 2311 | 2122 |
| 2312 int yOffset = 0; | 2123 int yOffset = 0; |
| 2313 int availableTextWidth = GetFixedMenuWidth() - 2 * kHorizontalSpacing; | 2124 int availableTextWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; |
| 2314 | 2125 |
| 2315 NSTextField* disclaimer = BuildLabel( | 2126 NSTextField* disclaimer = BuildLabel( |
| 2316 base::SysUTF16ToNSString(avatarMenu_->GetSupervisedUserInformation()), | 2127 base::SysUTF16ToNSString(avatarMenu_->GetSupervisedUserInformation()), |
| 2317 NSMakePoint(kHorizontalSpacing, yOffset), nil); | 2128 NSMakePoint(kHorizontalSpacing, yOffset), nil); |
| 2318 [disclaimer setFrameSize:NSMakeSize(availableTextWidth, 0)]; | 2129 [disclaimer setFrameSize:NSMakeSize(availableTextWidth, 0)]; |
| 2319 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:disclaimer]; | 2130 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:disclaimer]; |
| 2320 yOffset = NSMaxY([disclaimer frame]); | 2131 yOffset = NSMaxY([disclaimer frame]); |
| 2321 | 2132 |
| 2322 [container addSubview:disclaimer]; | 2133 [container addSubview:disclaimer]; |
| 2323 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 2134 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 2324 return container.autorelease(); | 2135 return container.autorelease(); |
| 2325 } | 2136 } |
| 2326 | 2137 |
| 2327 - (NSView*)createGuestProfileView { | 2138 - (NSView*)createGuestProfileView { |
| 2328 gfx::Image guestIcon = | 2139 gfx::Image guestIcon = |
| 2329 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 2140 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 2330 profiles::GetPlaceholderAvatarIconResourceID()); | 2141 profiles::GetPlaceholderAvatarIconResourceID()); |
| 2331 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ | 2142 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ |
| 2332 base::FilePath(), /* profile_path, not used */ | 2143 base::FilePath(), /* profile_path, not used */ |
| 2333 guestIcon); | 2144 guestIcon); |
| 2334 guestItem.active = true; | 2145 guestItem.active = true; |
| 2335 guestItem.name = base::SysNSStringToUTF16( | 2146 guestItem.name = base::SysNSStringToUTF16( |
| 2336 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); | 2147 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); |
| 2337 | 2148 |
| 2338 return switches::IsMaterialDesignUserMenu() | 2149 return [self createCurrentProfileView:guestItem]; |
| 2339 ? [self createMaterialDesignCurrentProfileView:guestItem] | |
| 2340 : [self createCurrentProfileView:guestItem]; | |
| 2341 } | 2150 } |
| 2342 | 2151 |
| 2343 - (NSButton*)createOtherProfileView:(int)itemIndex { | 2152 - (NSButton*)createOtherProfileView:(int)itemIndex { |
| 2344 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); | 2153 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); |
| 2345 | 2154 |
| 2346 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), | 2155 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth, |
| 2347 kBlueButtonHeight + kSmallVerticalSpacing); | 2156 kBlueButtonHeight + kSmallVerticalSpacing); |
| 2348 const int imageTitleSpacing = switches::IsMaterialDesignUserMenu() | 2157 const int imageTitleSpacing = kHorizontalSpacing; |
| 2349 ? kHorizontalSpacing | |
| 2350 : kImageTitleSpacing; | |
| 2351 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( | 2158 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( |
| 2352 [[BackgroundColorHoverButton alloc] | 2159 [[BackgroundColorHoverButton alloc] |
| 2353 initWithFrame:rect | 2160 initWithFrame:rect |
| 2354 imageTitleSpacing:imageTitleSpacing | 2161 imageTitleSpacing:imageTitleSpacing |
| 2355 backgroundColor:GetDialogBackgroundColor()]); | 2162 backgroundColor:GetDialogBackgroundColor()]); |
| 2356 if (switches::IsMaterialDesignUserMenu()) | 2163 [profileButton setRightMarginSpacing:kHorizontalSpacing]; |
| 2357 [profileButton setRightMarginSpacing:kHorizontalSpacing]; | |
| 2358 | 2164 |
| 2359 NSString* title = base::SysUTF16ToNSString( | 2165 NSString* title = base::SysUTF16ToNSString( |
| 2360 profiles::GetProfileSwitcherTextForItem(item)); | 2166 profiles::GetProfileSwitcherTextForItem(item)); |
| 2361 [profileButton setTitle:title]; | 2167 [profileButton setTitle:title]; |
| 2362 | 2168 |
| 2363 CGFloat availableWidth; | 2169 CGFloat availableWidth; |
| 2364 if (switches::IsMaterialDesignUserMenu()) { | 2170 [profileButton setDefaultImage:CreateProfileImage(item.icon, kIconImageSide, |
| 2365 int iconImageSide = 18; | 2171 profiles::SHAPE_CIRCLE)]; |
| 2366 [profileButton setDefaultImage:CreateProfileImage(item.icon, iconImageSide, | 2172 availableWidth = rect.size.width - kIconImageSide - imageTitleSpacing - |
| 2367 profiles::SHAPE_CIRCLE)]; | 2173 2 * kHorizontalSpacing; |
| 2368 availableWidth = rect.size.width - iconImageSide - imageTitleSpacing - | |
| 2369 2 * kHorizontalSpacing; | |
| 2370 } else { | |
| 2371 // Use the low-res, small default avatars in the fast user switcher, like | |
| 2372 // we do in the menu bar. | |
| 2373 gfx::Image itemIcon; | |
| 2374 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon); | |
| 2375 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide, | |
| 2376 profiles::SHAPE_SQUARE)]; | |
| 2377 availableWidth = rect.size.width - kSmallImageSide - imageTitleSpacing - | |
| 2378 kHorizontalSpacing; | |
| 2379 } | |
| 2380 | 2174 |
| 2381 [profileButton setImagePosition:NSImageLeft]; | 2175 [profileButton setImagePosition:NSImageLeft]; |
| 2382 [profileButton setAlignment:NSLeftTextAlignment]; | 2176 [profileButton setAlignment:NSLeftTextAlignment]; |
| 2383 [profileButton setBordered:NO]; | 2177 [profileButton setBordered:NO]; |
| 2384 [profileButton setTag:itemIndex]; | 2178 [profileButton setTag:itemIndex]; |
| 2385 [profileButton setTarget:self]; | 2179 [profileButton setTarget:self]; |
| 2386 [profileButton setAction:@selector(switchToProfile:)]; | 2180 [profileButton setAction:@selector(switchToProfile:)]; |
| 2387 | 2181 |
| 2388 NSSize textSize = [[profileButton title] sizeWithAttributes:@{ | |
| 2389 NSFontAttributeName : [profileButton font] | |
| 2390 }]; | |
| 2391 | |
| 2392 if (!switches::IsMaterialDesignUserMenu() && | |
| 2393 std::ceil(textSize.width) > availableWidth) | |
| 2394 [profileButton setToolTip:[profileButton title]]; | |
| 2395 | |
| 2396 return profileButton.autorelease(); | 2182 return profileButton.autorelease(); |
| 2397 } | 2183 } |
| 2398 | 2184 |
| 2399 - (NSView*)createOptionsViewWithRect:(NSRect)rect | |
| 2400 showLock:(BOOL)showLock { | |
| 2401 NSRect viewRect = NSMakeRect(0, 0, | |
| 2402 rect.size.width, | |
| 2403 kBlueButtonHeight + kSmallVerticalSpacing); | |
| 2404 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | |
| 2405 | |
| 2406 if (showLock) { | |
| 2407 NSButton* lockButton = | |
| 2408 [self hoverButtonWithRect:viewRect | |
| 2409 text:l10n_util::GetNSString( | |
| 2410 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) | |
| 2411 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK | |
| 2412 action:@selector(lockProfile:)]; | |
| 2413 [container addSubview:lockButton]; | |
| 2414 viewRect.origin.y = NSMaxY([lockButton frame]); | |
| 2415 | |
| 2416 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | |
| 2417 [container addSubview:separator]; | |
| 2418 viewRect.origin.y = NSMaxY([separator frame]); | |
| 2419 } | |
| 2420 | |
| 2421 if ([self shouldShowGoIncognito]) { | |
| 2422 NSButton* goIncognitoButton = | |
| 2423 [self hoverButtonWithRect:viewRect | |
| 2424 text:l10n_util::GetNSString( | |
| 2425 IDS_PROFILES_GO_INCOGNITO_BUTTON) | |
| 2426 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO | |
| 2427 action:@selector(goIncognito:)]; | |
| 2428 viewRect.origin.y = NSMaxY([goIncognitoButton frame]); | |
| 2429 [container addSubview:goIncognitoButton]; | |
| 2430 | |
| 2431 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | |
| 2432 [container addSubview:separator]; | |
| 2433 viewRect.origin.y = NSMaxY([separator frame]); | |
| 2434 } | |
| 2435 | |
| 2436 NSString* text = isGuestSession_ ? | |
| 2437 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) : | |
| 2438 l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON); | |
| 2439 NSButton* switchUsersButton = | |
| 2440 [self hoverButtonWithRect:viewRect | |
| 2441 text:text | |
| 2442 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR | |
| 2443 action:isGuestSession_? @selector(exitGuest:) : | |
| 2444 @selector(showUserManager:)]; | |
| 2445 viewRect.origin.y = NSMaxY([switchUsersButton frame]); | |
| 2446 [container addSubview:switchUsersButton]; | |
| 2447 | |
| 2448 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; | |
| 2449 return container.autorelease(); | |
| 2450 } | |
| 2451 | |
| 2452 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { | 2185 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { |
| 2453 const CGFloat kAccountButtonHeight = 34; | 2186 const CGFloat kAccountButtonHeight = 34; |
| 2454 | 2187 |
| 2455 const AvatarMenu::Item& item = | 2188 const AvatarMenu::Item& item = |
| 2456 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 2189 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
| 2457 DCHECK(item.signed_in); | 2190 DCHECK(item.signed_in); |
| 2458 | 2191 |
| 2459 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( | 2192 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( |
| 2460 profiles::kAvatarBubbleAccountsBackgroundColor); | 2193 profiles::kAvatarBubbleAccountsBackgroundColor); |
| 2461 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | 2194 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2483 | 2216 |
| 2484 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( | 2217 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( |
| 2485 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; | 2218 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; |
| 2486 [container addSubview:accountEmails]; | 2219 [container addSubview:accountEmails]; |
| 2487 | 2220 |
| 2488 [container setFrameSize:NSMakeSize(rect.size.width, | 2221 [container setFrameSize:NSMakeSize(rect.size.width, |
| 2489 NSMaxY([accountEmails frame]))]; | 2222 NSMaxY([accountEmails frame]))]; |
| 2490 return container.autorelease(); | 2223 return container.autorelease(); |
| 2491 } | 2224 } |
| 2492 | 2225 |
| 2493 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)rect | 2226 - (NSView*)createOptionsViewWithFrame:(NSRect)rect showLock:(BOOL)showLock { |
| 2494 showLock:(BOOL)showLock { | |
| 2495 NSRect viewRect = NSMakeRect(0, 0, rect.size.width, | 2227 NSRect viewRect = NSMakeRect(0, 0, rect.size.width, |
| 2496 kBlueButtonHeight + kSmallVerticalSpacing); | 2228 kBlueButtonHeight + kSmallVerticalSpacing); |
| 2497 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 2229 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
| 2498 const int material_icon_size = 20; | 2230 const int icon_size = 20; |
| 2499 | 2231 |
| 2500 // Create a lock profile button when supervised users exist; otherwise, create | 2232 // Create a lock profile button when supervised users exist; otherwise, create |
| 2501 // a button that closes all of the current profile's windows if more than one | 2233 // a button that closes all of the current profile's windows if more than one |
| 2502 // is open. | 2234 // is open. |
| 2503 if (showLock) { | 2235 if (showLock) { |
| 2504 NSButton* lockButton = | 2236 NSButton* lockButton = [self |
| 2505 [self hoverButtonWithRect:viewRect | 2237 hoverButtonWithRect:viewRect |
| 2506 text:l10n_util::GetNSString( | 2238 text:l10n_util::GetNSString( |
| 2507 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) | 2239 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) |
| 2508 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2240 image:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2509 kLockIcon, material_icon_size, | 2241 kLockIcon, icon_size, gfx::kChromeIconGrey)) |
| 2510 gfx::kChromeIconGrey)) | 2242 action:@selector(lockProfile:)]; |
| 2511 action:@selector(lockProfile:)]; | |
| 2512 [container addSubview:lockButton]; | 2243 [container addSubview:lockButton]; |
| 2513 viewRect.origin.y = NSMaxY([lockButton frame]); | 2244 viewRect.origin.y = NSMaxY([lockButton frame]); |
| 2514 } else if (!isGuestSession_) { | 2245 } else if (!isGuestSession_) { |
| 2515 int num_browsers = 0; | 2246 int num_browsers = 0; |
| 2516 for (auto* browser : *BrowserList::GetInstance()) { | 2247 for (auto* browser : *BrowserList::GetInstance()) { |
| 2517 Profile* current_profile = browser_->profile()->GetOriginalProfile(); | 2248 Profile* current_profile = browser_->profile()->GetOriginalProfile(); |
| 2518 if (browser->profile()->GetOriginalProfile() == current_profile) | 2249 if (browser->profile()->GetOriginalProfile() == current_profile) |
| 2519 num_browsers++; | 2250 num_browsers++; |
| 2520 } | 2251 } |
| 2521 if (num_browsers > 1) { | 2252 if (num_browsers > 1) { |
| 2522 NSButton* closeAllWindowsButton = | 2253 NSButton* closeAllWindowsButton = |
| 2523 [self hoverButtonWithRect:viewRect | 2254 [self hoverButtonWithRect:viewRect |
| 2524 text:l10n_util::GetNSString( | 2255 text:l10n_util::GetNSString( |
| 2525 IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON) | 2256 IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON) |
| 2526 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2257 image:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2527 kCloseAllIcon, material_icon_size, | 2258 kCloseAllIcon, icon_size, |
| 2528 gfx::kChromeIconGrey)) | 2259 gfx::kChromeIconGrey)) |
| 2529 action:@selector(closeAllWindows:)]; | 2260 action:@selector(closeAllWindows:)]; |
| 2530 [container addSubview:closeAllWindowsButton]; | 2261 [container addSubview:closeAllWindowsButton]; |
| 2531 viewRect.origin.y = NSMaxY([closeAllWindowsButton frame]); | 2262 viewRect.origin.y = NSMaxY([closeAllWindowsButton frame]); |
| 2532 } | 2263 } |
| 2533 } | 2264 } |
| 2534 | 2265 |
| 2535 // Create a manage users/exit guest button. | 2266 // Create a manage users/exit guest button. |
| 2536 NSString* text = | 2267 NSString* text = |
| 2537 isGuestSession_ | 2268 isGuestSession_ |
| 2538 ? l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) | 2269 ? l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) |
| 2539 : l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON); | 2270 : l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON); |
| 2540 NSImage* icon = NSImageFromImageSkia( | 2271 NSImage* icon = NSImageFromImageSkia( |
| 2541 gfx::CreateVectorIcon(isGuestSession_ ? kCloseAllIcon : kSettingsIcon, | 2272 gfx::CreateVectorIcon(isGuestSession_ ? kCloseAllIcon : kSettingsIcon, |
| 2542 material_icon_size, gfx::kChromeIconGrey)); | 2273 icon_size, gfx::kChromeIconGrey)); |
| 2543 SEL action = | 2274 SEL action = |
| 2544 isGuestSession_ ? @selector(exitGuest:) : @selector(showUserManager:); | 2275 isGuestSession_ ? @selector(exitGuest:) : @selector(showUserManager:); |
| 2545 NSButton* manageUsersButton = | 2276 NSButton* manageUsersButton = |
| 2546 [self hoverButtonWithRect:viewRect text:text image:icon action:action]; | 2277 [self hoverButtonWithRect:viewRect text:text image:icon action:action]; |
| 2547 viewRect.origin.y = NSMaxY([manageUsersButton frame]); | 2278 viewRect.origin.y = NSMaxY([manageUsersButton frame]); |
| 2548 [container addSubview:manageUsersButton]; | 2279 [container addSubview:manageUsersButton]; |
| 2549 | 2280 |
| 2550 // Create a guest profile button. | 2281 // Create a guest profile button. |
| 2551 if (!isGuestSession_) { | 2282 if (!isGuestSession_) { |
| 2552 PrefService* service = g_browser_process->local_state(); | 2283 PrefService* service = g_browser_process->local_state(); |
| 2553 DCHECK(service); | 2284 DCHECK(service); |
| 2554 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { | 2285 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { |
| 2555 NSButton* guestProfileButton = | 2286 NSButton* guestProfileButton = |
| 2556 [self hoverButtonWithRect:viewRect | 2287 [self hoverButtonWithRect:viewRect |
| 2557 text:l10n_util::GetNSString( | 2288 text:l10n_util::GetNSString( |
| 2558 IDS_PROFILES_GUEST_PROFILE_NAME) | 2289 IDS_PROFILES_GUEST_PROFILE_NAME) |
| 2559 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2290 image:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2560 kAccountCircleIcon, material_icon_size, | 2291 kAccountCircleIcon, icon_size, |
| 2561 gfx::kChromeIconGrey)) | 2292 gfx::kChromeIconGrey)) |
| 2562 action:@selector(switchToGuest:)]; | 2293 action:@selector(switchToGuest:)]; |
| 2563 viewRect.origin.y = NSMaxY([guestProfileButton frame]); | 2294 viewRect.origin.y = NSMaxY([guestProfileButton frame]); |
| 2564 [container addSubview:guestProfileButton]; | 2295 [container addSubview:guestProfileButton]; |
| 2565 } | 2296 } |
| 2566 } | 2297 } |
| 2567 | 2298 |
| 2568 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; | 2299 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; |
| 2569 return container.autorelease(); | 2300 return container.autorelease(); |
| 2570 } | 2301 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2837 return button; | 2568 return button; |
| 2838 } | 2569 } |
| 2839 | 2570 |
| 2840 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect | 2571 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect |
| 2841 text:(NSString*)text | 2572 text:(NSString*)text |
| 2842 action:(SEL)action { | 2573 action:(SEL)action { |
| 2843 // The vector icons in hover buttons have small embeded paddings and are | 2574 // The vector icons in hover buttons have small embeded paddings and are |
| 2844 // therefore given an extra 2px in size to have a consistent look as the | 2575 // therefore given an extra 2px in size to have a consistent look as the |
| 2845 // profile icons; hence the -2.0 here to left align the hover button texts | 2576 // profile icons; hence the -2.0 here to left align the hover button texts |
| 2846 // with those of profile buttons. | 2577 // with those of profile buttons. |
| 2847 const int md_image_title_spacing = kHorizontalSpacing - 2.0; | 2578 const int image_title_spacing = kHorizontalSpacing - 2.0; |
| 2848 | 2579 |
| 2849 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2580 base::scoped_nsobject<BackgroundColorHoverButton> button( |
| 2850 [[BackgroundColorHoverButton alloc] | 2581 [[BackgroundColorHoverButton alloc] |
| 2851 initWithFrame:rect | 2582 initWithFrame:rect |
| 2852 imageTitleSpacing:switches::IsMaterialDesignUserMenu() | 2583 imageTitleSpacing:image_title_spacing |
| 2853 ? md_image_title_spacing | |
| 2854 : kImageTitleSpacing | |
| 2855 backgroundColor:GetDialogBackgroundColor()]); | 2584 backgroundColor:GetDialogBackgroundColor()]); |
| 2856 | 2585 |
| 2857 [button setTitle:text]; | 2586 [button setTitle:text]; |
| 2858 [button setAlignment:NSLeftTextAlignment]; | 2587 [button setAlignment:NSLeftTextAlignment]; |
| 2859 [button setBordered:NO]; | 2588 [button setBordered:NO]; |
| 2860 [button setTarget:self]; | 2589 [button setTarget:self]; |
| 2861 [button setAction:action]; | 2590 [button setAction:action]; |
| 2862 | 2591 |
| 2863 return button.autorelease(); | 2592 return button.autorelease(); |
| 2864 } | 2593 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2958 | 2687 |
| 2959 - (void)showWindow:(id)sender { | 2688 - (void)showWindow:(id)sender { |
| 2960 [super showWindow:sender]; | 2689 [super showWindow:sender]; |
| 2961 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2690 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
| 2962 if (firstProfileView_ && [event type] == NSKeyDown) { | 2691 if (firstProfileView_ && [event type] == NSKeyDown) { |
| 2963 [[self window] makeFirstResponder:firstProfileView_]; | 2692 [[self window] makeFirstResponder:firstProfileView_]; |
| 2964 } | 2693 } |
| 2965 } | 2694 } |
| 2966 | 2695 |
| 2967 @end | 2696 @end |
| OLD | NEW |