Chromium Code Reviews| 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/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 |
| 100 const CGFloat kVerticalSpacing = 16.0; | 99 const CGFloat kVerticalSpacing = 16.0; |
| 101 const CGFloat kSmallVerticalSpacing = 10.0; | 100 const CGFloat kSmallVerticalSpacing = 10.0; |
| 102 const CGFloat kRelatedControllVerticalSpacing = 8.0; | 101 const CGFloat kRelatedControllVerticalSpacing = 8.0; |
| 103 const CGFloat kHorizontalSpacing = 16.0; | 102 const CGFloat kHorizontalSpacing = 16.0; |
| 104 const CGFloat kTitleFontSize = 15.0; | 103 const CGFloat kTitleFontSize = 15.0; |
| 105 const CGFloat kTextFontSize = 12.0; | 104 const CGFloat kTextFontSize = 12.0; |
| 106 const CGFloat kProfileButtonHeight = 30; | 105 const CGFloat kProfileButtonHeight = 30; |
| 107 const int kBezelThickness = 3; // Width of the bezel on an NSButton. | 106 const int kBezelThickness = 3; // Width of the bezel on an NSButton. |
| 108 const int kImageTitleSpacing = 10; | |
| 109 const int kBlueButtonHeight = 30; | 107 const int kBlueButtonHeight = 30; |
| 110 const CGFloat kFocusRingLineWidth = 2; | 108 const CGFloat kFocusRingLineWidth = 2; |
| 111 | 109 |
| 112 // Fixed size for embedded sign in pages as defined in Gaia. | 110 // Fixed size for embedded sign in pages as defined in Gaia. |
| 113 const CGFloat kFixedGaiaViewWidth = 360; | 111 const CGFloat kFixedGaiaViewWidth = 360; |
| 114 | 112 |
| 115 // Fixed size for the account removal view. | 113 // Fixed size for the account removal view. |
| 116 const CGFloat kFixedAccountRemovalViewWidth = 280; | 114 const CGFloat kFixedAccountRemovalViewWidth = 280; |
| 117 | 115 |
| 118 // Fixed size for the switch user view. | 116 // Fixed size for the switch user view. |
| 119 const int kFixedSwitchUserViewWidth = 320; | 117 const int kFixedSwitchUserViewWidth = 320; |
| 120 | 118 |
| 121 // The tag number for the primary account. | 119 // The tag number for the primary account. |
| 122 const int kPrimaryProfileTag = -1; | 120 const int kPrimaryProfileTag = -1; |
| 123 | 121 |
| 124 CGFloat GetFixedMenuWidth() { | 122 CGFloat GetFixedMenuWidth() { |
|
msarda
2017/02/23 11:51:02
Nit: This should not be a constant named kFixedMen
jlebel
2017/02/23 18:18:49
Done.
| |
| 125 return switches::IsMaterialDesignUserMenu() ? 240.0 : 250.0; | 123 return 240.0; |
| 126 } | 124 } |
| 127 | 125 |
| 128 NSImage* CreateProfileImage(const gfx::Image& icon, | 126 NSImage* CreateProfileImage(const gfx::Image& icon, |
| 129 int imageSize, | 127 int imageSize, |
| 130 profiles::AvatarShape shape) { | 128 profiles::AvatarShape shape) { |
| 131 return (profiles::GetSizedAvatarIcon(icon, true /* image is a square */, | 129 return (profiles::GetSizedAvatarIcon(icon, true /* image is a square */, |
| 132 imageSize, imageSize, shape)) | 130 imageSize, imageSize, shape)) |
| 133 .ToNSImage(); | 131 .ToNSImage(); |
| 134 } | 132 } |
| 135 | 133 |
| (...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 854 | 852 |
| 855 [self setBordered:NO]; | 853 [self setBordered:NO]; |
| 856 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 854 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
| 857 [self setButtonType:NSMomentaryChangeButton]; | 855 [self setButtonType:NSMomentaryChangeButton]; |
| 858 | 856 |
| 859 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( | 857 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( |
| 860 [[CustomPaddingImageButtonCell alloc] | 858 [[CustomPaddingImageButtonCell alloc] |
| 861 initWithLeftMarginSpacing:kHorizontalSpacing | 859 initWithLeftMarginSpacing:kHorizontalSpacing |
| 862 imageTitleSpacing:imageTitleSpacing]); | 860 imageTitleSpacing:imageTitleSpacing]); |
| 863 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; | 861 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 864 if (switches::IsMaterialDesignUserMenu()) | 862 [cell setHighlightsBy:NSNoCellMask]; |
| 865 [cell setHighlightsBy:NSNoCellMask]; | |
| 866 [self setCell:cell.get()]; | 863 [self setCell:cell.get()]; |
| 867 } | 864 } |
| 868 return self; | 865 return self; |
| 869 } | 866 } |
| 870 | 867 |
| 871 - (void)setRightMarginSpacing:(int)rightMarginSpacing { | 868 - (void)setRightMarginSpacing:(int)rightMarginSpacing { |
| 872 [[self cell] setRightMarginSpacing:rightMarginSpacing]; | 869 [[self cell] setRightMarginSpacing:rightMarginSpacing]; |
| 873 } | 870 } |
| 874 | 871 |
| 875 - (void)drawRect:(NSRect)dirtyRect { | 872 - (void)drawRect:(NSRect)dirtyRect { |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 958 tutorialView:(NSView*)tutorialView | 955 tutorialView:(NSView*)tutorialView |
| 959 syncErrorView:(NSView*)syncErrorView | 956 syncErrorView:(NSView*)syncErrorView |
| 960 otherProfiles:(NSArray*)otherProfiles | 957 otherProfiles:(NSArray*)otherProfiles |
| 961 atYOffset:(CGFloat)yOffset | 958 atYOffset:(CGFloat)yOffset |
| 962 inContainer:(NSView*)container | 959 inContainer:(NSView*)container |
| 963 showLock:(bool)showLock; | 960 showLock:(bool)showLock; |
| 964 | 961 |
| 965 // Builds the profile chooser view. | 962 // Builds the profile chooser view. |
| 966 - (NSView*)buildProfileChooserView; | 963 - (NSView*)buildProfileChooserView; |
| 967 | 964 |
| 968 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; | |
| 969 | |
| 970 // Builds a tutorial card with a title label using |titleMessage|, a content | 965 // Builds a tutorial card with a title label using |titleMessage|, a content |
| 971 // label using |contentMessage|, a link using |linkMessage|, and a button using | 966 // label using |contentMessage|, a link using |linkMessage|, and a button using |
| 972 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | 967 // |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 | 968 // 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 | 969 // right aligned. On click, the link would execute |linkAction|, and the button |
| 975 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. | 970 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. |
| 976 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 971 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 977 titleMessage:(NSString*)titleMessage | 972 titleMessage:(NSString*)titleMessage |
| 978 contentMessage:(NSString*)contentMessage | 973 contentMessage:(NSString*)contentMessage |
| 979 linkMessage:(NSString*)linkMessage | 974 linkMessage:(NSString*)linkMessage |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 999 // Chrome sync will be delayed until the user either dismisses the tutorial, or | 994 // Chrome sync will be delayed until the user either dismisses the tutorial, or |
| 1000 // configures sync through the "Settings" link. | 995 // configures sync through the "Settings" link. |
| 1001 - (NSView*)buildSigninConfirmationView; | 996 - (NSView*)buildSigninConfirmationView; |
| 1002 | 997 |
| 1003 // Builds a tutorial card to show the last signin error. | 998 // Builds a tutorial card to show the last signin error. |
| 1004 - (NSView*)buildSigninErrorView; | 999 - (NSView*)buildSigninErrorView; |
| 1005 | 1000 |
| 1006 // Creates the main profile card for the profile |item| at the top of | 1001 // 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 | 1002 // the bubble, for non-material-design and material design user menu |
| 1008 // respectively. | 1003 // respectively. |
| 1009 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; | |
| 1010 - (NSView*)createMaterialDesignCurrentProfileView:(const AvatarMenu::Item&)item; | 1004 - (NSView*)createMaterialDesignCurrentProfileView:(const AvatarMenu::Item&)item; |
| 1011 | 1005 |
| 1012 // Creates the possible links for the main profile card with profile |item|. | 1006 // Creates the possible links for the main profile card with profile |item|. |
| 1013 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 1007 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
| 1014 rect:(NSRect)rect; | 1008 rect:(NSRect)rect; |
| 1015 | 1009 |
| 1016 // Creates the disclaimer text for supervised users, telling them that the | 1010 // Creates the disclaimer text for supervised users, telling them that the |
| 1017 // manager can view their history etc. | 1011 // manager can view their history etc. |
| 1018 - (NSView*)createSupervisedUserDisclaimerView; | 1012 - (NSView*)createSupervisedUserDisclaimerView; |
| 1019 | 1013 |
| 1020 // Creates a main profile card for the guest user. | 1014 // Creates a main profile card for the guest user. |
| 1021 - (NSView*)createGuestProfileView; | 1015 - (NSView*)createGuestProfileView; |
| 1022 | 1016 |
| 1023 // Creates an item for the profile |itemIndex| that is used in the fast profile | 1017 // Creates an item for the profile |itemIndex| that is used in the fast profile |
| 1024 // switcher view. | 1018 // switcher view. |
| 1025 - (NSButton*)createOtherProfileView:(int)itemIndex; | 1019 - (NSButton*)createOtherProfileView:(int)itemIndex; |
| 1026 | 1020 |
| 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 | 1021 // For material design user menu, creates the following option buttons: lock |
| 1032 // profile/close all windows, switch user/exit guest, and open guest profile. | 1022 // profile/close all windows, switch user/exit guest, and open guest profile. |
| 1033 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)frame | 1023 - (NSView*)createMaterialDesignOptionsViewWithFrame:(NSRect)frame |
| 1034 showLock:(BOOL)showLock; | 1024 showLock:(BOOL)showLock; |
| 1035 | 1025 |
| 1036 // Creates the account management view for the active profile. | 1026 // Creates the account management view for the active profile. |
| 1037 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; | 1027 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; |
| 1038 | 1028 |
| 1039 // Creates the list of accounts for the active profile. | 1029 // Creates the list of accounts for the active profile. |
| 1040 - (NSView*)createAccountsListWithRect:(NSRect)rect; | 1030 - (NSView*)createAccountsListWithRect:(NSRect)rect; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1443 // yOffset after adding the elements. | 1433 // yOffset after adding the elements. |
| 1444 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles | 1434 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles |
| 1445 atYOffset:(CGFloat)yOffset | 1435 atYOffset:(CGFloat)yOffset |
| 1446 inContainer:(NSView*)container { | 1436 inContainer:(NSView*)container { |
| 1447 // Other profiles switcher. The profiles have already been sorted | 1437 // Other profiles switcher. The profiles have already been sorted |
| 1448 // by their y-coordinate, so they can be added in the existing order. | 1438 // by their y-coordinate, so they can be added in the existing order. |
| 1449 for (NSView* otherProfileView in otherProfiles) { | 1439 for (NSView* otherProfileView in otherProfiles) { |
| 1450 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1440 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1451 [container addSubview:otherProfileView]; | 1441 [container addSubview:otherProfileView]; |
| 1452 yOffset = NSMaxY([otherProfileView frame]); | 1442 yOffset = NSMaxY([otherProfileView frame]); |
| 1453 | |
| 1454 if (!switches::IsMaterialDesignUserMenu()) | |
| 1455 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | |
| 1456 } | 1443 } |
| 1457 | 1444 |
| 1458 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 1445 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; |
| 1459 return yOffset; | 1446 return yOffset; |
| 1460 } | 1447 } |
| 1461 | 1448 |
| 1462 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 1449 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 1463 tutorialView:(NSView*)tutorialView | 1450 tutorialView:(NSView*)tutorialView |
| 1464 syncErrorView:(NSView*)syncErrorView | 1451 syncErrorView:(NSView*)syncErrorView |
| 1465 otherProfiles:(NSArray*)otherProfiles | 1452 otherProfiles:(NSArray*)otherProfiles |
| 1466 atYOffset:(CGFloat)yOffset | 1453 atYOffset:(CGFloat)yOffset |
| 1467 inContainer:(NSView*)container | 1454 inContainer:(NSView*)container |
| 1468 showLock:(bool)showLock { | 1455 showLock:(bool)showLock { |
| 1469 if (switches::IsMaterialDesignUserMenu()) | 1456 yOffset += kRelatedControllVerticalSpacing; |
| 1470 yOffset += kRelatedControllVerticalSpacing; | |
| 1471 | 1457 |
| 1472 // Option buttons. | 1458 // Option buttons. |
| 1473 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); | 1459 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); |
| 1474 NSView* optionsView = | 1460 NSView* optionsView = |
| 1475 switches::IsMaterialDesignUserMenu() | 1461 [self createMaterialDesignOptionsViewWithFrame:rect showLock:showLock]; |
| 1476 ? [self createMaterialDesignOptionsViewWithFrame:rect | |
| 1477 showLock:showLock] | |
| 1478 : [self createOptionsViewWithRect:rect showLock:showLock]; | |
| 1479 [container addSubview:optionsView]; | 1462 [container addSubview:optionsView]; |
| 1480 rect.origin.y = NSMaxY([optionsView frame]); | 1463 rect.origin.y = NSMaxY([optionsView frame]); |
| 1481 yOffset = rect.origin.y; | 1464 yOffset = rect.origin.y; |
| 1482 | 1465 |
| 1483 // For material design user menu, add the fast user switching buttons. | 1466 // Add the fast user switching buttons. |
| 1484 if (switches::IsMaterialDesignUserMenu()) { | 1467 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles |
| 1485 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles | 1468 atYOffset:yOffset |
| 1486 atYOffset:yOffset | 1469 inContainer:container]; |
| 1487 inContainer:container]; | 1470 yOffset += kRelatedControllVerticalSpacing; |
| 1488 yOffset += kRelatedControllVerticalSpacing; | 1471 rect.origin.y = yOffset; |
| 1489 rect.origin.y = yOffset; | |
| 1490 } | |
| 1491 | 1472 |
| 1492 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | 1473 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; |
| 1493 [container addSubview:separator]; | 1474 [container addSubview:separator]; |
| 1494 yOffset = NSMaxY([separator frame]); | 1475 yOffset = NSMaxY([separator frame]); |
| 1495 | 1476 |
| 1496 // For supervised users, add the disclaimer text. | 1477 // For supervised users, add the disclaimer text. |
| 1497 if (browser_->profile()->IsSupervised()) { | 1478 if (browser_->profile()->IsSupervised()) { |
| 1498 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing | 1479 yOffset += kVerticalSpacing; |
| 1499 : kSmallVerticalSpacing; | |
| 1500 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; | 1480 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; |
| 1501 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; | 1481 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1502 [container addSubview:disclaimerContainer]; | 1482 [container addSubview:disclaimerContainer]; |
| 1503 yOffset = NSMaxY([disclaimerContainer frame]); | 1483 yOffset = NSMaxY([disclaimerContainer frame]); |
| 1504 | |
| 1505 if (!switches::IsMaterialDesignUserMenu()) { | |
| 1506 yOffset += kSmallVerticalSpacing; | |
| 1507 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | |
| 1508 } | |
| 1509 } | 1484 } |
| 1510 | 1485 |
| 1511 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 1486 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 1512 const AvatarMenu::Item& item = | 1487 const AvatarMenu::Item& item = |
| 1513 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 1488 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
| 1514 if (item.signed_in) { | 1489 if (item.signed_in) { |
| 1515 NSView* currentProfileAccountsView = [self | 1490 NSView* currentProfileAccountsView = [self |
| 1516 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, | 1491 createCurrentProfileAccountsView:NSMakeRect(0, yOffset, |
| 1517 GetFixedMenuWidth(), 0)]; | 1492 GetFixedMenuWidth(), 0)]; |
| 1518 [container addSubview:currentProfileAccountsView]; | 1493 [container addSubview:currentProfileAccountsView]; |
| 1519 yOffset = NSMaxY([currentProfileAccountsView frame]); | 1494 yOffset = NSMaxY([currentProfileAccountsView frame]); |
| 1520 | 1495 |
| 1521 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | 1496 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; |
| 1522 } else { | 1497 } else { |
| 1523 // This is the case when the user selects the sign out option in the user | 1498 // This is the case when the user selects the sign out option in the user |
| 1524 // menu upon encountering unrecoverable errors. Afterwards, the profile | 1499 // menu upon encountering unrecoverable errors. Afterwards, the profile |
| 1525 // chooser view is shown instead of the account management view. | 1500 // chooser view is shown instead of the account management view. |
| 1526 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 1501 viewMode_ = profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
| 1527 } | 1502 } |
| 1528 } | 1503 } |
| 1529 | 1504 |
| 1530 // Active profile card. | 1505 // Active profile card. |
| 1531 if (currentProfileView) { | 1506 if (currentProfileView) { |
| 1532 const CGFloat verticalSpacing = switches::IsMaterialDesignUserMenu() | 1507 const CGFloat verticalSpacing = kRelatedControllVerticalSpacing; |
| 1533 ? kRelatedControllVerticalSpacing | |
| 1534 : kVerticalSpacing; | |
| 1535 yOffset += verticalSpacing; | 1508 yOffset += verticalSpacing; |
| 1536 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1509 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1537 [container addSubview:currentProfileView]; | 1510 [container addSubview:currentProfileView]; |
| 1538 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; | 1511 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; |
| 1539 } | 1512 } |
| 1540 | 1513 |
| 1541 if (syncErrorView) { | 1514 if (syncErrorView) { |
| 1542 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | 1515 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; |
| 1543 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1516 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1544 [container addSubview:syncErrorView]; | 1517 [container addSubview:syncErrorView]; |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 1575 PrefService* localState = g_browser_process->local_state(); | 1548 PrefService* localState = g_browser_process->local_state(); |
| 1576 localState->SetBoolean( | 1549 localState->SetBoolean( |
| 1577 prefs::kProfileAvatarRightClickTutorialDismissed, true); | 1550 prefs::kProfileAvatarRightClickTutorialDismissed, true); |
| 1578 } | 1551 } |
| 1579 | 1552 |
| 1580 // Loop over the profiles in reverse, so that they are sorted by their | 1553 // Loop over the profiles in reverse, so that they are sorted by their |
| 1581 // y-coordinate, and separate them into active and "other" profiles. | 1554 // y-coordinate, and separate them into active and "other" profiles. |
| 1582 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1555 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
| 1583 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); | 1556 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); |
| 1584 if (item.active) { | 1557 if (item.active) { |
| 1585 if (switches::IsMaterialDesignUserMenu()) { | 1558 syncErrorView = [self buildSyncErrorViewIfNeeded]; |
| 1586 syncErrorView = [self buildSyncErrorViewIfNeeded]; | 1559 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 && | 1560 showLock = item.signed_in && |
| 1595 profiles::IsLockAvailable(browser_->profile()); | 1561 profiles::IsLockAvailable(browser_->profile()); |
| 1596 } else { | 1562 } else { |
| 1597 [otherProfiles addObject:[self createOtherProfileView:i]]; | 1563 [otherProfiles addObject:[self createOtherProfileView:i]]; |
| 1598 } | 1564 } |
| 1599 } | 1565 } |
| 1600 firstProfileView_ = [otherProfiles lastObject]; | 1566 firstProfileView_ = [otherProfiles lastObject]; |
| 1601 if (!currentProfileView) // Guest windows don't have an active profile. | 1567 if (!currentProfileView) // Guest windows don't have an active profile. |
| 1602 currentProfileView = [self createGuestProfileView]; | 1568 currentProfileView = [self createGuestProfileView]; |
| 1603 | 1569 |
| 1604 // |yOffset| is the next position at which to draw in |container| | 1570 // |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 | 1571 // coordinates. Add a pixel offset so that the bottom option buttons don't |
| 1606 // overlap the bubble's rounded corners. | 1572 // overlap the bubble's rounded corners. |
| 1607 CGFloat yOffset = 1; | 1573 CGFloat yOffset = 1; |
| 1608 | 1574 |
| 1609 if (isFastProfileChooser) { | 1575 if (!isFastProfileChooser) { |
| 1610 if (!switches::IsMaterialDesignUserMenu()) { | |
| 1611 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() | |
| 1612 atYOffset:yOffset | |
| 1613 inContainer:container]; | |
| 1614 } | |
| 1615 } else { | |
| 1616 [self buildProfileChooserViewWithProfileView:currentProfileView | 1576 [self buildProfileChooserViewWithProfileView:currentProfileView |
| 1617 tutorialView:tutorialView | 1577 tutorialView:tutorialView |
| 1618 syncErrorView:syncErrorView | 1578 syncErrorView:syncErrorView |
| 1619 otherProfiles:otherProfiles.get() | 1579 otherProfiles:otherProfiles.get() |
| 1620 atYOffset:yOffset | 1580 atYOffset:yOffset |
| 1621 inContainer:container | 1581 inContainer:container |
| 1622 showLock:showLock]; | 1582 showLock:showLock]; |
| 1623 } | 1583 } |
| 1624 | 1584 |
| 1625 return container.autorelease(); | 1585 return container.autorelease(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1709 titleMessage:titleMessage | 1669 titleMessage:titleMessage |
| 1710 contentMessage:contentMessage | 1670 contentMessage:contentMessage |
| 1711 linkMessage:nil | 1671 linkMessage:nil |
| 1712 buttonMessage:buttonMessage | 1672 buttonMessage:buttonMessage |
| 1713 stackButton:NO | 1673 stackButton:NO |
| 1714 hasCloseButton:NO | 1674 hasCloseButton:NO |
| 1715 linkAction:nil | 1675 linkAction:nil |
| 1716 buttonAction:@selector(dismissTutorial:)]; | 1676 buttonAction:@selector(dismissTutorial:)]; |
| 1717 } | 1677 } |
| 1718 | 1678 |
| 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 | 1679 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
| 1746 titleMessage:(NSString*)titleMessage | 1680 titleMessage:(NSString*)titleMessage |
| 1747 contentMessage:(NSString*)contentMessage | 1681 contentMessage:(NSString*)contentMessage |
| 1748 linkMessage:(NSString*)linkMessage | 1682 linkMessage:(NSString*)linkMessage |
| 1749 buttonMessage:(NSString*)buttonMessage | 1683 buttonMessage:(NSString*)buttonMessage |
| 1750 stackButton:(BOOL)stackButton | 1684 stackButton:(BOOL)stackButton |
| 1751 hasCloseButton:(BOOL)hasCloseButton | 1685 hasCloseButton:(BOOL)hasCloseButton |
| 1752 linkAction:(SEL)linkAction | 1686 linkAction:(SEL)linkAction |
| 1753 buttonAction:(SEL)buttonAction { | 1687 buttonAction:(SEL)buttonAction { |
| 1754 tutorialMode_ = mode; | 1688 tutorialMode_ = mode; |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1963 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | 1897 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 1964 gfx::VectorIconId::SYNC_PROBLEM, iconSize, | 1898 gfx::VectorIconId::SYNC_PROBLEM, iconSize, |
| 1965 gfx::kGoogleRed700))]; | 1899 gfx::kGoogleRed700))]; |
| 1966 [container addSubview:syncProblemIcon]; | 1900 [container addSubview:syncProblemIcon]; |
| 1967 | 1901 |
| 1968 [container | 1902 [container |
| 1969 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; | 1903 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; |
| 1970 return container.autorelease(); | 1904 return container.autorelease(); |
| 1971 } | 1905 } |
| 1972 | 1906 |
| 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: | 1907 - (NSView*)createMaterialDesignCurrentProfileView: |
| 2050 (const AvatarMenu::Item&)item { | 1908 (const AvatarMenu::Item&)item { |
| 2051 base::scoped_nsobject<NSView> container( | 1909 base::scoped_nsobject<NSView> container( |
| 2052 [[NSView alloc] initWithFrame:NSZeroRect]); | 1910 [[NSView alloc] initWithFrame:NSZeroRect]); |
| 2053 | 1911 |
| 2054 CGFloat xOffset = kHorizontalSpacing; | 1912 CGFloat xOffset = kHorizontalSpacing; |
| 2055 CGFloat yOffset = 0.0; | 1913 CGFloat yOffset = 0.0; |
| 2056 CGFloat cardYOffset = kRelatedControllVerticalSpacing; | 1914 CGFloat cardYOffset = kRelatedControllVerticalSpacing; |
| 2057 CGFloat availableTextWidth = | 1915 CGFloat availableTextWidth = |
| 2058 GetFixedMenuWidth() - 3.0 * kHorizontalSpacing - kMdImageSide; | 1916 GetFixedMenuWidth() - 3.0 * kHorizontalSpacing - kMdImageSide; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2178 [profileCard addSubview:username]; | 2036 [profileCard addSubview:username]; |
| 2179 } | 2037 } |
| 2180 | 2038 |
| 2181 yOffset = NSMaxY([profileCard frame]); | 2039 yOffset = NSMaxY([profileCard frame]); |
| 2182 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 2040 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; |
| 2183 return container.autorelease(); | 2041 return container.autorelease(); |
| 2184 } | 2042 } |
| 2185 | 2043 |
| 2186 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 2044 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
| 2187 rect:(NSRect)rect { | 2045 rect:(NSRect)rect { |
| 2188 if (switches::IsMaterialDesignUserMenu()) { | 2046 // 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- | 2047 // 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 | 2048 // here. |
| 2191 // profile card instead of as a separate link here. | 2049 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( |
| 2192 SigninManagerBase* signinManager = SigninManagerFactory::GetForProfile( | 2050 browser_->profile()->GetOriginalProfile()); |
| 2193 browser_->profile()->GetOriginalProfile()); | 2051 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) || |
| 2194 DCHECK((item.signed_in && switches::IsEnableAccountConsistency()) || | 2052 (!item.signed_in && signinManager->IsSigninAllowed())); |
| 2195 (!item.signed_in && signinManager->IsSigninAllowed())); | |
| 2196 } | |
| 2197 | 2053 |
| 2198 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 2054 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
| 2199 | 2055 |
| 2200 // Don't double-apply the left margin to the sub-views. | 2056 // Don't double-apply the left margin to the sub-views. |
| 2201 rect.origin.x = 0; | 2057 rect.origin.x = 0; |
| 2202 | 2058 |
| 2203 // Adds right padding. | 2059 // Adds right padding. |
| 2204 const CGFloat kRightPadding = kHorizontalSpacing; | 2060 const CGFloat kRightPadding = kHorizontalSpacing; |
| 2205 rect.size.width -= kRightPadding; | 2061 rect.size.width -= kRightPadding; |
| 2206 | 2062 |
| 2207 // The available links depend on the type of profile that is active. | 2063 // The available links depend on the type of profile that is active. |
| 2208 if (item.signed_in) { | 2064 if (item.signed_in) { |
| 2209 NSButton* link = nil; | 2065 NSButton* link = nil; |
| 2210 if (switches::IsEnableAccountConsistency()) { | 2066 if (switches::IsEnableAccountConsistency()) { |
| 2211 NSString* linkTitle = l10n_util::GetNSString( | 2067 NSString* linkTitle = l10n_util::GetNSString( |
| 2212 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? | 2068 viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? |
| 2213 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : | 2069 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
| 2214 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | 2070 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); |
| 2215 SEL linkSelector = | 2071 SEL linkSelector = |
| 2216 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? | 2072 (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? |
| 2217 @selector(showAccountManagement:) : @selector(hideAccountManagement:); | 2073 @selector(showAccountManagement:) : @selector(hideAccountManagement:); |
| 2218 if (switches::IsMaterialDesignUserMenu()) { | 2074 rect.size.width += kRightPadding; // Spans the width of the entire menu. |
| 2219 rect.size.width += | 2075 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width, |
| 2220 kRightPadding; // Spans the width of the entire menu. | 2076 kBlueButtonHeight) |
| 2221 link = [self hoverButtonWithRect:NSMakeRect(0, 0, rect.size.width, | 2077 text:linkTitle |
| 2222 kBlueButtonHeight) | 2078 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 } | 2079 } |
| 2253 if (link) { | 2080 if (link) { |
| 2254 // -linkButtonWithTitle sizeToFit's the link. We can use the height, but | 2081 // -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 | 2082 // need to re-stretch the width so that the link can be centered correctly |
| 2256 // in the view. | 2083 // in the view. |
| 2257 rect.size.height = [link frame].size.height; | 2084 rect.size.height = [link frame].size.height; |
| 2258 if (!switches::IsMaterialDesignUserMenu()) | |
| 2259 [link setAlignment:NSCenterTextAlignment]; | |
| 2260 [link setFrame:rect]; | 2085 [link setFrame:rect]; |
| 2261 [container addSubview:link]; | 2086 [container addSubview:link]; |
| 2262 [container setFrameSize:rect.size]; | 2087 [container setFrameSize:rect.size]; |
| 2263 } | 2088 } |
| 2264 } else { | 2089 } else { |
| 2265 rect.size.height = kBlueButtonHeight; | 2090 rect.size.height = kBlueButtonHeight; |
| 2266 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect]; | 2091 NSButton* signinButton = [[BlueLabelButton alloc] initWithFrame:rect]; |
| 2267 | 2092 |
| 2268 // Manually elide the button text so that the contents fit inside the bubble | 2093 // 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 | 2094 // This is needed because the BlueLabelButton cell resets the style on |
| 2270 // every call to -cellSize, which prevents setting a custom lineBreakMode. | 2095 // every call to -cellSize, which prevents setting a custom lineBreakMode. |
| 2271 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( | 2096 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( |
| 2272 l10n_util::GetStringFUTF16( | 2097 l10n_util::GetStringFUTF16( |
| 2273 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 2098 IDS_SYNC_START_SYNC_BUTTON_LABEL, |
| 2274 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), | 2099 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), |
| 2275 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); | 2100 gfx::FontList(), rect.size.width, gfx::ELIDE_TAIL)); |
| 2276 | 2101 |
| 2277 [signinButton setTitle:elidedButtonText]; | 2102 [signinButton setTitle:elidedButtonText]; |
| 2278 if (switches::IsMaterialDesignUserMenu()) | 2103 [signinButton sizeToFit]; |
| 2279 [signinButton sizeToFit]; | |
| 2280 [signinButton setTarget:self]; | 2104 [signinButton setTarget:self]; |
| 2281 [signinButton setAction:@selector(showInlineSigninPage:)]; | 2105 [signinButton setAction:@selector(showInlineSigninPage:)]; |
| 2282 [container addSubview:signinButton]; | 2106 [container addSubview:signinButton]; |
| 2283 | 2107 |
| 2284 // Sign-in promo text. | 2108 // Sign-in promo text. |
| 2285 NSTextField* promo = BuildLabel( | 2109 NSTextField* promo = BuildLabel( |
| 2286 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), | 2110 l10n_util::GetNSString(IDS_PROFILES_SIGNIN_PROMO), |
| 2287 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), | 2111 NSMakePoint(0, NSMaxY([signinButton frame]) + kVerticalSpacing), |
| 2288 nil); | 2112 nil); |
| 2289 if (kRightPadding >= 8) | 2113 if (kRightPadding >= 8) |
| 2290 rect.size.width += 8; // Re-stretch a little bit to fit promo text. | 2114 rect.size.width += 8; // Re-stretch a little bit to fit promo text. |
| 2291 DCHECK(kRightPadding >= 8); | 2115 DCHECK(kRightPadding >= 8); |
| 2292 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; | 2116 [promo setFrameSize:NSMakeSize(rect.size.width, 0)]; |
| 2293 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; | 2117 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:promo]; |
| 2294 [container addSubview:promo]; | 2118 [container addSubview:promo]; |
| 2295 | 2119 |
| 2296 [container | 2120 [container setFrameSize:NSMakeSize(rect.size.width, |
| 2297 setFrameSize:NSMakeSize(rect.size.width, | 2121 NSMaxY([promo frame]) + |
| 2298 NSMaxY([promo frame]) + | 2122 kRelatedControllVerticalSpacing)]; |
| 2299 (switches::IsMaterialDesignUserMenu() | |
| 2300 ? kRelatedControllVerticalSpacing | |
| 2301 : 4))]; | |
| 2302 content::RecordAction( | 2123 content::RecordAction( |
| 2303 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); | 2124 base::UserMetricsAction("Signin_Impression_FromAvatarBubbleSignin")); |
| 2304 } | 2125 } |
| 2305 | 2126 |
| 2306 return container.autorelease(); | 2127 return container.autorelease(); |
| 2307 } | 2128 } |
| 2308 | 2129 |
| 2309 - (NSView*)createSupervisedUserDisclaimerView { | 2130 - (NSView*)createSupervisedUserDisclaimerView { |
| 2310 base::scoped_nsobject<NSView> container( | 2131 base::scoped_nsobject<NSView> container( |
| 2311 [[NSView alloc] initWithFrame:NSZeroRect]); | 2132 [[NSView alloc] initWithFrame:NSZeroRect]); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2329 gfx::Image guestIcon = | 2150 gfx::Image guestIcon = |
| 2330 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 2151 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
| 2331 profiles::GetPlaceholderAvatarIconResourceID()); | 2152 profiles::GetPlaceholderAvatarIconResourceID()); |
| 2332 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ | 2153 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ |
| 2333 base::FilePath(), /* profile_path, not used */ | 2154 base::FilePath(), /* profile_path, not used */ |
| 2334 guestIcon); | 2155 guestIcon); |
| 2335 guestItem.active = true; | 2156 guestItem.active = true; |
| 2336 guestItem.name = base::SysNSStringToUTF16( | 2157 guestItem.name = base::SysNSStringToUTF16( |
| 2337 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); | 2158 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); |
| 2338 | 2159 |
| 2339 return switches::IsMaterialDesignUserMenu() | 2160 return [self createMaterialDesignCurrentProfileView:guestItem]; |
| 2340 ? [self createMaterialDesignCurrentProfileView:guestItem] | |
| 2341 : [self createCurrentProfileView:guestItem]; | |
| 2342 } | 2161 } |
| 2343 | 2162 |
| 2344 - (NSButton*)createOtherProfileView:(int)itemIndex { | 2163 - (NSButton*)createOtherProfileView:(int)itemIndex { |
| 2345 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); | 2164 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); |
| 2346 | 2165 |
| 2347 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), | 2166 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), |
| 2348 kBlueButtonHeight + kSmallVerticalSpacing); | 2167 kBlueButtonHeight + kSmallVerticalSpacing); |
| 2349 const int imageTitleSpacing = switches::IsMaterialDesignUserMenu() | 2168 const int imageTitleSpacing = kHorizontalSpacing; |
| 2350 ? kHorizontalSpacing | |
| 2351 : kImageTitleSpacing; | |
| 2352 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( | 2169 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( |
| 2353 [[BackgroundColorHoverButton alloc] | 2170 [[BackgroundColorHoverButton alloc] |
| 2354 initWithFrame:rect | 2171 initWithFrame:rect |
| 2355 imageTitleSpacing:imageTitleSpacing | 2172 imageTitleSpacing:imageTitleSpacing |
| 2356 backgroundColor:GetDialogBackgroundColor()]); | 2173 backgroundColor:GetDialogBackgroundColor()]); |
| 2357 if (switches::IsMaterialDesignUserMenu()) | 2174 [profileButton setRightMarginSpacing:kHorizontalSpacing]; |
| 2358 [profileButton setRightMarginSpacing:kHorizontalSpacing]; | |
| 2359 | 2175 |
| 2360 NSString* title = base::SysUTF16ToNSString( | 2176 NSString* title = base::SysUTF16ToNSString( |
| 2361 profiles::GetProfileSwitcherTextForItem(item)); | 2177 profiles::GetProfileSwitcherTextForItem(item)); |
| 2362 [profileButton setTitle:title]; | 2178 [profileButton setTitle:title]; |
| 2363 | 2179 |
| 2364 CGFloat availableWidth; | 2180 CGFloat availableWidth; |
| 2365 if (switches::IsMaterialDesignUserMenu()) { | 2181 int iconImageSide = 18; |
|
msarda
2017/02/23 11:51:02
Optional nit: Let's make this a constant:
const in
jlebel
2017/02/23 18:18:49
Done.
| |
| 2366 int iconImageSide = 18; | 2182 [profileButton setDefaultImage:CreateProfileImage(item.icon, iconImageSide, |
| 2367 [profileButton setDefaultImage:CreateProfileImage(item.icon, iconImageSide, | 2183 profiles::SHAPE_CIRCLE)]; |
| 2368 profiles::SHAPE_CIRCLE)]; | 2184 availableWidth = rect.size.width - iconImageSide - imageTitleSpacing - |
| 2369 availableWidth = rect.size.width - iconImageSide - imageTitleSpacing - | 2185 2 * kHorizontalSpacing; |
| 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 | 2186 |
| 2382 [profileButton setImagePosition:NSImageLeft]; | 2187 [profileButton setImagePosition:NSImageLeft]; |
| 2383 [profileButton setAlignment:NSLeftTextAlignment]; | 2188 [profileButton setAlignment:NSLeftTextAlignment]; |
| 2384 [profileButton setBordered:NO]; | 2189 [profileButton setBordered:NO]; |
| 2385 [profileButton setTag:itemIndex]; | 2190 [profileButton setTag:itemIndex]; |
| 2386 [profileButton setTarget:self]; | 2191 [profileButton setTarget:self]; |
| 2387 [profileButton setAction:@selector(switchToProfile:)]; | 2192 [profileButton setAction:@selector(switchToProfile:)]; |
| 2388 | 2193 |
| 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(); | 2194 return profileButton.autorelease(); |
| 2398 } | 2195 } |
| 2399 | 2196 |
| 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 { | 2197 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { |
| 2454 const CGFloat kAccountButtonHeight = 34; | 2198 const CGFloat kAccountButtonHeight = 34; |
| 2455 | 2199 |
| 2456 const AvatarMenu::Item& item = | 2200 const AvatarMenu::Item& item = |
| 2457 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 2201 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
| 2458 DCHECK(item.signed_in); | 2202 DCHECK(item.signed_in); |
| 2459 | 2203 |
| 2460 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( | 2204 NSColor* backgroundColor = skia::SkColorToCalibratedNSColor( |
| 2461 profiles::kAvatarBubbleAccountsBackgroundColor); | 2205 profiles::kAvatarBubbleAccountsBackgroundColor); |
| 2462 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | 2206 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2844 action:(SEL)action { | 2588 action:(SEL)action { |
| 2845 // The vector icons in hover buttons have small embeded paddings and are | 2589 // 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 | 2590 // 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 | 2591 // profile icons; hence the -2.0 here to left align the hover button texts |
| 2848 // with those of profile buttons. | 2592 // with those of profile buttons. |
| 2849 const int md_image_title_spacing = kHorizontalSpacing - 2.0; | 2593 const int md_image_title_spacing = kHorizontalSpacing - 2.0; |
| 2850 | 2594 |
| 2851 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2595 base::scoped_nsobject<BackgroundColorHoverButton> button( |
| 2852 [[BackgroundColorHoverButton alloc] | 2596 [[BackgroundColorHoverButton alloc] |
| 2853 initWithFrame:rect | 2597 initWithFrame:rect |
| 2854 imageTitleSpacing:switches::IsMaterialDesignUserMenu() | 2598 imageTitleSpacing:md_image_title_spacing |
| 2855 ? md_image_title_spacing | |
| 2856 : kImageTitleSpacing | |
| 2857 backgroundColor:GetDialogBackgroundColor()]); | 2599 backgroundColor:GetDialogBackgroundColor()]); |
| 2858 | 2600 |
| 2859 [button setTitle:text]; | 2601 [button setTitle:text]; |
| 2860 [button setAlignment:NSLeftTextAlignment]; | 2602 [button setAlignment:NSLeftTextAlignment]; |
| 2861 [button setBordered:NO]; | 2603 [button setBordered:NO]; |
| 2862 [button setTarget:self]; | 2604 [button setTarget:self]; |
| 2863 [button setAction:action]; | 2605 [button setAction:action]; |
| 2864 | 2606 |
| 2865 return button.autorelease(); | 2607 return button.autorelease(); |
| 2866 } | 2608 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2960 | 2702 |
| 2961 - (void)showWindow:(id)sender { | 2703 - (void)showWindow:(id)sender { |
| 2962 [super showWindow:sender]; | 2704 [super showWindow:sender]; |
| 2963 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2705 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
| 2964 if (firstProfileView_ && [event type] == NSKeyDown) { | 2706 if (firstProfileView_ && [event type] == NSKeyDown) { |
| 2965 [[self window] makeFirstResponder:firstProfileView_]; | 2707 [[self window] makeFirstResponder:firstProfileView_]; |
| 2966 } | 2708 } |
| 2967 } | 2709 } |
| 2968 | 2710 |
| 2969 @end | 2711 @end |
| OLD | NEW |