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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
6 | 6 |
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
8 | 8 |
9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 #include "ui/base/l10n/l10n_util_mac.h" | 58 #include "ui/base/l10n/l10n_util_mac.h" |
59 #include "ui/base/resource/resource_bundle.h" | 59 #include "ui/base/resource/resource_bundle.h" |
60 #include "ui/gfx/image/image.h" | 60 #include "ui/gfx/image/image.h" |
61 #include "ui/gfx/text_elider.h" | 61 #include "ui/gfx/text_elider.h" |
62 #include "ui/native_theme/native_theme.h" | 62 #include "ui/native_theme/native_theme.h" |
63 | 63 |
64 namespace { | 64 namespace { |
65 | 65 |
66 // Constants taken from the Windows/Views implementation at: | 66 // Constants taken from the Windows/Views implementation at: |
67 // chrome/browser/ui/views/profile_chooser_view.cc | 67 // chrome/browser/ui/views/profile_chooser_view.cc |
68 const int kLargeImageSide = 64; | 68 const int kLargeImageSide = 88; |
69 const int kSmallImageSide = 32; | 69 const int kSmallImageSide = 32; |
70 const CGFloat kFixedMenuWidth = 250; | 70 const CGFloat kFixedMenuWidth = 250; |
71 | 71 |
72 const CGFloat kVerticalSpacing = 20.0; | 72 const CGFloat kVerticalSpacing = 16.0; |
73 const CGFloat kSmallVerticalSpacing = 10.0; | 73 const CGFloat kSmallVerticalSpacing = 10.0; |
74 const CGFloat kHorizontalSpacing = 20.0; | 74 const CGFloat kHorizontalSpacing = 16.0; |
75 const CGFloat kTitleFontSize = 15.0; | 75 const CGFloat kTitleFontSize = 15.0; |
76 const CGFloat kTextFontSize = 12.0; | 76 const CGFloat kTextFontSize = 12.0; |
77 const CGFloat kProfileButtonHeight = 30; | 77 const CGFloat kProfileButtonHeight = 30; |
78 const int kOverlayHeight = 20; // Height of the "Change" avatar photo overlay. | 78 const int kOverlayHeight = 20; // Height of the "Change" avatar photo overlay. |
79 const int kBezelThickness = 3; // Width of the bezel on an NSButton. | 79 const int kBezelThickness = 3; // Width of the bezel on an NSButton. |
80 const int kImageTitleSpacing = 10; | 80 const int kImageTitleSpacing = 10; |
81 const int kBlueButtonHeight = 30; | 81 const int kBlueButtonHeight = 30; |
82 | 82 |
83 // Fixed size for embedded sign in pages as defined in Gaia. | 83 // Fixed size for embedded sign in pages as defined in Gaia. |
84 const CGFloat kFixedGaiaViewWidth = 360; | 84 const CGFloat kFixedGaiaViewWidth = 360; |
85 const CGFloat kFixedGaiaViewHeight = 400; | 85 const CGFloat kFixedGaiaViewHeight = 400; |
86 | 86 |
87 // Fixed size for the account removal view. | 87 // Fixed size for the account removal view. |
88 const CGFloat kFixedAccountRemovalViewWidth = 280; | 88 const CGFloat kFixedAccountRemovalViewWidth = 280; |
89 | 89 |
90 // Maximum number of times to show the tutorial in the profile avatar bubble. | 90 // Maximum number of times to show the tutorial in the profile avatar bubble. |
91 const int kProfileAvatarTutorialShowMax = 5; | 91 const int kProfileAvatarTutorialShowMax = 5; |
92 | 92 |
93 // The tag number for the primary account. | 93 // The tag number for the primary account. |
94 const int kPrimaryProfileTag = -1; | 94 const int kPrimaryProfileTag = -1; |
95 | 95 |
96 gfx::Image CreateProfileImage(const gfx::Image& icon, int imageSize) { | 96 gfx::Image CreateProfileImage(const gfx::Image& icon, int imageSize) { |
97 return profiles::GetSizedAvatarIconWithBorder( | 97 return profiles::GetSizedAvatarIcon( |
98 icon, true /* image is a square */, | 98 icon, true /* image is a square */, |
99 imageSize + profiles::kAvatarIconPadding, | 99 imageSize + profiles::kAvatarIconPadding, |
100 imageSize + profiles::kAvatarIconPadding); | 100 imageSize + profiles::kAvatarIconPadding); |
101 } | 101 } |
102 | 102 |
103 // Updates the window size and position. | 103 // Updates the window size and position. |
104 void SetWindowSize(NSWindow* window, NSSize size) { | 104 void SetWindowSize(NSWindow* window, NSSize size) { |
105 NSRect frame = [window frame]; | 105 NSRect frame = [window frame]; |
106 frame.origin.x += frame.size.width - size.width; | 106 frame.origin.x += frame.size.width - size.width; |
107 frame.origin.y += frame.size.height - size.height; | 107 frame.origin.y += frame.size.height - size.height; |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
476 @implementation EditableProfileNameButton | 476 @implementation EditableProfileNameButton |
477 - (id)initWithFrame:(NSRect)frameRect | 477 - (id)initWithFrame:(NSRect)frameRect |
478 profile:(Profile*)profile | 478 profile:(Profile*)profile |
479 profileName:(NSString*)profileName | 479 profileName:(NSString*)profileName |
480 editingAllowed:(BOOL)editingAllowed { | 480 editingAllowed:(BOOL)editingAllowed { |
481 if ((self = [super initWithFrame:frameRect])) { | 481 if ((self = [super initWithFrame:frameRect])) { |
482 profile_ = profile; | 482 profile_ = profile; |
483 | 483 |
484 [self setBordered:NO]; | 484 [self setBordered:NO]; |
485 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 485 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
486 [self setAlignment:NSLeftTextAlignment]; | 486 [self setAlignment:NSCenterTextAlignment]; |
487 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 487 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
488 [self setTitle:profileName]; | 488 [self setTitle:profileName]; |
489 | 489 |
490 if (editingAllowed) { | 490 if (editingAllowed) { |
491 // Show an "edit" pencil icon when hovering over. | 491 // Show an "edit" pencil icon when hovering over. In the default state, |
492 // we need to create an empty placeholder of the correct size, so that | |
493 // the text doesn't jump around when the hovered icon appears. | |
492 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 494 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
493 [self setHoverImage: | 495 NSImage* hoverImage = rb->GetNativeImageNamed( |
494 rb->GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_HOVER).AsNSImage()]; | 496 IDR_ICON_PROFILES_EDIT_HOVER).AsNSImage(); |
497 NSImage* placeholder = [[NSImage alloc] initWithSize:[hoverImage size]]; | |
498 [self setDefaultImage:placeholder]; | |
499 [self setHoverImage:hoverImage]; | |
495 [self setAlternateImage: | 500 [self setAlternateImage: |
496 rb->GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_PRESSED).AsNSImage()]; | 501 rb->GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_PRESSED).AsNSImage()]; |
497 [self setImagePosition:NSImageRight]; | 502 [self setImagePosition:NSImageRight]; |
498 [self setTarget:self]; | 503 [self setTarget:self]; |
499 [self setAction:@selector(showEditableView:)]; | 504 [self setAction:@selector(showEditableView:)]; |
500 | 505 |
501 // We need to subtract the width of the bezel from the frame rect, so that | 506 // We need to subtract the width of the bezel from the frame rect, so that |
502 // the textfield can take the exact same space as the button. | 507 // the textfield can take the exact same space as the button. |
503 frameRect.size.height -= 2 * kBezelThickness; | 508 frameRect.size.height -= 2 * kBezelThickness; |
504 frameRect.origin = NSMakePoint(0, kBezelThickness); | 509 frameRect.origin = NSMakePoint(0, kBezelThickness); |
505 profileNameTextField_.reset( | 510 profileNameTextField_.reset( |
506 [[NSTextField alloc] initWithFrame:frameRect]); | 511 [[NSTextField alloc] initWithFrame:frameRect]); |
507 [profileNameTextField_ setStringValue:profileName]; | 512 [profileNameTextField_ setStringValue:profileName]; |
508 [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 513 [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
509 [profileNameTextField_ setEditable:YES]; | 514 [profileNameTextField_ setEditable:YES]; |
510 [profileNameTextField_ setDrawsBackground:YES]; | 515 [profileNameTextField_ setDrawsBackground:YES]; |
511 [profileNameTextField_ setBezeled:YES]; | 516 [profileNameTextField_ setBezeled:YES]; |
517 [profileNameTextField_ setAlignment:NSCenterTextAlignment]; | |
512 [[profileNameTextField_ cell] setWraps:NO]; | 518 [[profileNameTextField_ cell] setWraps:NO]; |
513 [[profileNameTextField_ cell] setLineBreakMode: | 519 [[profileNameTextField_ cell] setLineBreakMode: |
514 NSLineBreakByTruncatingTail]; | 520 NSLineBreakByTruncatingTail]; |
515 [profileNameTextField_ setDelegate:self]; | 521 [profileNameTextField_ setDelegate:self]; |
516 [self addSubview:profileNameTextField_]; | 522 [self addSubview:profileNameTextField_]; |
517 | 523 |
518 // Hide the textfield until the user clicks on the button. | 524 // Hide the textfield until the user clicks on the button. |
519 [profileNameTextField_ setHidden:YES]; | 525 [profileNameTextField_ setHidden:YES]; |
520 } | 526 } |
521 } | 527 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 | 591 |
586 - (NSSize)cellSize { | 592 - (NSSize)cellSize { |
587 NSSize buttonSize = [super cellSize]; | 593 NSSize buttonSize = [super cellSize]; |
588 buttonSize.width += leftMarginSpacing_ + imageTitleSpacing_; | 594 buttonSize.width += leftMarginSpacing_ + imageTitleSpacing_; |
589 return buttonSize; | 595 return buttonSize; |
590 } | 596 } |
591 | 597 |
592 @end | 598 @end |
593 | 599 |
594 // A custom button that allows for setting a background color when hovered over. | 600 // A custom button that allows for setting a background color when hovered over. |
595 @interface BackgroundColorHoverButton : HoverImageButton | 601 @interface BackgroundColorHoverButton : HoverImageButton { |
602 @private | |
603 base::scoped_nsobject<NSColor> backgroundColor_; | |
604 } | |
596 @end | 605 @end |
597 | 606 |
598 @implementation BackgroundColorHoverButton | 607 @implementation BackgroundColorHoverButton |
599 - (id)initWithFrame:(NSRect)frameRect { | 608 |
609 - (id)initWithFrame:(NSRect)frameRect | |
610 imageTitleSpacing:(int)imageTitleSpacing | |
611 backgroundColor:(const SkColor&)backgroundColor { | |
600 if ((self = [super initWithFrame:frameRect])) { | 612 if ((self = [super initWithFrame:frameRect])) { |
613 backgroundColor_.reset( | |
614 [gfx::SkColorToCalibratedNSColor(backgroundColor) retain]); | |
615 | |
601 [self setBordered:NO]; | 616 [self setBordered:NO]; |
602 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 617 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
603 [self setButtonType:NSMomentaryChangeButton]; | 618 [self setButtonType:NSMomentaryChangeButton]; |
604 | 619 |
605 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( | 620 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( |
606 [[CustomPaddingImageButtonCell alloc] | 621 [[CustomPaddingImageButtonCell alloc] |
607 initWithLeftMarginSpacing:kHorizontalSpacing | 622 initWithLeftMarginSpacing:kHorizontalSpacing |
608 imageTitleSpacing:kImageTitleSpacing]); | 623 imageTitleSpacing:imageTitleSpacing]); |
609 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; | 624 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; |
610 [self setCell:cell.get()]; | 625 [self setCell:cell.get()]; |
611 } | 626 } |
612 return self; | 627 return self; |
613 } | 628 } |
614 | 629 |
615 - (void)setHoverState:(HoverState)state { | 630 - (void)setHoverState:(HoverState)state { |
616 [super setHoverState:state]; | 631 [super setHoverState:state]; |
617 bool isHighlighted = ([self hoverState] != kHoverStateNone); | 632 bool isHighlighted = ([self hoverState] != kHoverStateNone); |
618 | 633 |
619 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( | 634 NSColor* backgroundColor = isHighlighted ? gfx::SkColorToCalibratedNSColor( |
620 ui::NativeTheme::instance()->GetSystemColor(isHighlighted? | 635 profiles::kAvatarBubbleButtonHighlightColor) : backgroundColor_; |
621 ui::NativeTheme::kColorId_MenuSeparatorColor : | |
622 ui::NativeTheme::kColorId_DialogBackground)); | |
Elliot Glaysher
2014/04/16 21:24:48
Like, you probably want to maintain this structure
noms (inactive)
2014/04/17 14:13:41
But If I make a specific ColorId, how is that diff
Elliot Glaysher
2014/04/17 17:29:25
There can be different NativeTheme subclasses comp
| |
623 | |
624 [[self cell] setBackgroundColor:backgroundColor]; | 636 [[self cell] setBackgroundColor:backgroundColor]; |
625 } | 637 } |
626 | 638 |
627 @end | 639 @end |
628 | 640 |
629 // A custom view with the given background color. | 641 // A custom view with the given background color. |
630 @interface BackgroundColorView : NSView { | 642 @interface BackgroundColorView : NSView { |
631 @private | 643 @private |
632 base::scoped_nsobject<NSColor> backgroundColor_; | 644 base::scoped_nsobject<NSColor> backgroundColor_; |
633 } | 645 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
666 // out the feature. Otherwise, it notifies the user that the feature has been | 678 // out the feature. Otherwise, it notifies the user that the feature has been |
667 // enabled if needed. | 679 // enabled if needed. |
668 - (NSView*)buildPreviewTutorialIfNeeded:(const AvatarMenu::Item&)item; | 680 - (NSView*)buildPreviewTutorialIfNeeded:(const AvatarMenu::Item&)item; |
669 | 681 |
670 // Creates the main profile card for the profile |item| at the top of | 682 // Creates the main profile card for the profile |item| at the top of |
671 // the bubble. | 683 // the bubble. |
672 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; | 684 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; |
673 | 685 |
674 // Creates the possible links for the main profile card with profile |item|. | 686 // Creates the possible links for the main profile card with profile |item|. |
675 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 687 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
676 withXOffset:(CGFloat)xOffset; | 688 rect:(NSRect)rect; |
677 | 689 |
678 // Creates a main profile card for the guest user. | 690 // Creates a main profile card for the guest user. |
679 - (NSView*)createGuestProfileView; | 691 - (NSView*)createGuestProfileView; |
680 | 692 |
681 // Creates an item for the profile |itemIndex| that is used in the fast profile | 693 // Creates an item for the profile |itemIndex| that is used in the fast profile |
682 // switcher in the middle of the bubble. | 694 // switcher in the middle of the bubble. |
683 - (NSButton*)createOtherProfileView:(int)itemIndex; | 695 - (NSButton*)createOtherProfileView:(int)itemIndex; |
684 | 696 |
685 // Creates the "Not you" and Lock option buttons. | 697 // Creates the "Not you" and Lock option buttons. |
686 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 698 - (NSView*)createOptionsViewWithRect:(NSRect)rect |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 } | 745 } |
734 | 746 |
735 - (IBAction)showUserManager:(id)sender { | 747 - (IBAction)showUserManager:(id)sender { |
736 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); | 748 profiles::ShowUserManagerMaybeWithTutorial(browser_->profile()); |
737 } | 749 } |
738 | 750 |
739 - (IBAction)showAccountManagement:(id)sender { | 751 - (IBAction)showAccountManagement:(id)sender { |
740 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 752 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
741 } | 753 } |
742 | 754 |
755 - (IBAction)hideAccountManagement:(id)sender { | |
756 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | |
757 } | |
758 | |
743 - (IBAction)lockProfile:(id)sender { | 759 - (IBAction)lockProfile:(id)sender { |
744 profiles::LockProfile(browser_->profile()); | 760 profiles::LockProfile(browser_->profile()); |
745 } | 761 } |
746 | 762 |
747 - (IBAction)showSigninPage:(id)sender { | 763 - (IBAction)showInlineSigninPage:(id)sender { |
748 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_GAIA_SIGNIN]; | 764 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_GAIA_SIGNIN]; |
749 } | 765 } |
750 | 766 |
767 - (IBAction)showTabbedSigninPage:(id)sender { | |
768 chrome::ShowBrowserSignin(browser_, signin::SOURCE_MENU); | |
769 } | |
770 | |
751 - (IBAction)addAccount:(id)sender { | 771 - (IBAction)addAccount:(id)sender { |
752 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT]; | 772 [self initMenuContentsWithView:BUBBLE_VIEW_MODE_GAIA_ADD_ACCOUNT]; |
753 } | 773 } |
754 | 774 |
755 - (IBAction)navigateBackFromSigninPage:(id)sender { | 775 - (IBAction)navigateBackFromSigninPage:(id)sender { |
756 std::string primaryAccount = SigninManagerFactory::GetForProfile( | 776 std::string primaryAccount = SigninManagerFactory::GetForProfile( |
757 browser_->profile())->GetAuthenticatedUsername(); | 777 browser_->profile())->GetAuthenticatedUsername(); |
758 [self initMenuContentsWithView:primaryAccount.empty() ? | 778 [self initMenuContentsWithView:primaryAccount.empty() ? |
759 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 779 BUBBLE_VIEW_MODE_PROFILE_CHOOSER : BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
760 } | 780 } |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
881 enableLock = item.signed_in; | 901 enableLock = item.signed_in; |
882 } else { | 902 } else { |
883 [otherProfiles addObject:[self createOtherProfileView:i]]; | 903 [otherProfiles addObject:[self createOtherProfileView:i]]; |
884 } | 904 } |
885 } | 905 } |
886 if (!currentProfileView) // Guest windows don't have an active profile. | 906 if (!currentProfileView) // Guest windows don't have an active profile. |
887 currentProfileView = [self createGuestProfileView]; | 907 currentProfileView = [self createGuestProfileView]; |
888 | 908 |
889 // |yOffset| is the next position at which to draw in |contentView| | 909 // |yOffset| is the next position at which to draw in |contentView| |
890 // coordinates. | 910 // coordinates. |
891 CGFloat yOffset = kSmallVerticalSpacing; | 911 CGFloat yOffset = 0; |
892 | 912 |
893 // Option buttons. | 913 // Option buttons. Only available with the new profile management flag. |
894 NSView* optionsView = [self createOptionsViewWithRect: | 914 if (switches::IsNewProfileManagement()) { |
895 NSMakeRect(0, yOffset, kFixedMenuWidth, 0) | 915 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); |
896 enableLock:enableLock]; | 916 NSView* optionsView = [self createOptionsViewWithRect:rect |
897 [contentView addSubview:optionsView]; | 917 enableLock:enableLock]; |
898 yOffset = NSMaxY([optionsView frame]) + kSmallVerticalSpacing; | 918 [contentView addSubview:optionsView]; |
919 rect.origin.y = NSMaxY([optionsView frame]); | |
899 | 920 |
900 NSBox* separator = [self separatorWithFrame: | 921 NSBox* separator = [self separatorWithFrame:rect]; |
901 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | 922 [contentView addSubview:separator]; |
902 [contentView addSubview:separator]; | 923 yOffset = NSMaxY([separator frame]); |
903 yOffset = NSMaxY([separator frame]) + kVerticalSpacing; | 924 } |
904 | 925 |
905 if (viewToDisplay == BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | 926 if (viewToDisplay == BUBBLE_VIEW_MODE_PROFILE_CHOOSER && |
906 switches::IsFastUserSwitching()) { | 927 switches::IsFastUserSwitching()) { |
907 // Other profiles switcher. The profiles have already been sorted | 928 // Other profiles switcher. The profiles have already been sorted |
908 // by their y-coordinate, so they can be added in the existing order. | 929 // by their y-coordinate, so they can be added in the existing order. |
909 for (NSView *otherProfileView in otherProfiles.get()) { | 930 for (NSView *otherProfileView in otherProfiles.get()) { |
910 [otherProfileView setFrameOrigin:NSMakePoint(kHorizontalSpacing, | 931 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
911 yOffset)]; | |
912 [contentView addSubview:otherProfileView]; | 932 [contentView addSubview:otherProfileView]; |
913 yOffset = NSMaxY([otherProfileView frame]) + kSmallVerticalSpacing; | 933 yOffset = NSMaxY([otherProfileView frame]); |
934 | |
935 NSBox* separator = | |
936 [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
937 [contentView addSubview:separator]; | |
938 yOffset = NSMaxY([separator frame]); | |
914 } | 939 } |
915 | |
916 // If we displayed other profiles, ensure the spacing between the last item | |
917 // and the active profile card is the same as the spacing between the active | |
918 // profile card and the bottom of the bubble. | |
919 if ([otherProfiles.get() count] > 0) | |
920 yOffset += kSmallVerticalSpacing; | |
921 } else if (viewToDisplay == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | 940 } else if (viewToDisplay == BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
922 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: | 941 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: |
923 NSMakeRect(kHorizontalSpacing, | 942 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
924 yOffset, | |
925 kFixedMenuWidth - 2 * kHorizontalSpacing, | |
926 0)]; | |
927 [contentView addSubview:currentProfileAccountsView]; | 943 [contentView addSubview:currentProfileAccountsView]; |
928 yOffset = NSMaxY([currentProfileAccountsView frame]) + kVerticalSpacing; | 944 yOffset = NSMaxY([currentProfileAccountsView frame]); |
929 | 945 |
930 NSBox* accountsSeparator = [self separatorWithFrame: | 946 NSBox* accountsSeparator = [self separatorWithFrame: |
931 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | 947 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
932 [contentView addSubview:accountsSeparator]; | 948 [contentView addSubview:accountsSeparator]; |
933 yOffset = NSMaxY([accountsSeparator frame]) + kVerticalSpacing; | 949 yOffset = NSMaxY([accountsSeparator frame]); |
934 } | 950 } |
935 | 951 |
936 // Active profile card. | 952 // Active profile card. |
937 if (currentProfileView) { | 953 if (currentProfileView) { |
938 [currentProfileView setFrameOrigin:NSMakePoint(kHorizontalSpacing, | 954 yOffset += kVerticalSpacing; |
939 yOffset)]; | 955 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
940 [contentView addSubview:currentProfileView]; | 956 [contentView addSubview:currentProfileView]; |
941 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; | 957 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; |
942 } | 958 } |
943 | 959 |
944 if (tutorialView) { | 960 if (tutorialView) { |
945 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; | 961 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; |
946 [contentView addSubview:tutorialView]; | 962 [contentView addSubview:tutorialView]; |
947 yOffset = NSMaxY([tutorialView frame]); | 963 yOffset = NSMaxY([tutorialView frame]); |
948 } else { | 964 } else { |
949 tutorialShowing_ = false; | 965 tutorialShowing_ = false; |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1083 | 1099 |
1084 [containerWithCaret setFrameSize: | 1100 [containerWithCaret setFrameSize: |
1085 NSMakeSize(kFixedMenuWidth, NSMaxY([container frame]))]; | 1101 NSMakeSize(kFixedMenuWidth, NSMaxY([container frame]))]; |
1086 return containerWithCaret.autorelease(); | 1102 return containerWithCaret.autorelease(); |
1087 } | 1103 } |
1088 | 1104 |
1089 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { | 1105 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { |
1090 base::scoped_nsobject<NSView> container([[NSView alloc] | 1106 base::scoped_nsobject<NSView> container([[NSView alloc] |
1091 initWithFrame:NSZeroRect]); | 1107 initWithFrame:NSZeroRect]); |
1092 | 1108 |
1093 // Profile icon. | 1109 CGFloat xOffset = kHorizontalSpacing; |
1094 base::scoped_nsobject<EditableProfilePhoto> iconView( | 1110 CGFloat yOffset = 0; |
1095 [[EditableProfilePhoto alloc] | 1111 CGFloat availableTextWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; |
1096 initWithFrame:NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide) | |
1097 avatarMenu:avatarMenu_.get() | |
1098 profileIcon:item.icon | |
1099 editingAllowed:!isGuestSession_]); | |
1100 | 1112 |
1101 [container addSubview:iconView]; | 1113 // Profile options. This can be a link to the accounts view, the profile's |
1102 | 1114 // username for signed in users, or a "Sign in" button for local profiles. |
1103 CGFloat xOffset = NSMaxX([iconView frame]) + kHorizontalSpacing; | 1115 if (!isGuestSession_) { |
1104 CGFloat yOffset = kVerticalSpacing; | |
1105 if (!isGuestSession_ && viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | |
1106 NSView* linksContainer = | 1116 NSView* linksContainer = |
1107 [self createCurrentProfileLinksForItem:item withXOffset:xOffset]; | 1117 [self createCurrentProfileLinksForItem:item |
1118 rect:NSMakeRect(xOffset, yOffset, | |
1119 availableTextWidth, | |
1120 0)]; | |
1108 [container addSubview:linksContainer]; | 1121 [container addSubview:linksContainer]; |
1109 yOffset = NSMaxY([linksContainer frame]); | 1122 yOffset = NSMaxY([linksContainer frame]); |
1110 } | 1123 } |
1111 | 1124 |
1112 // Profile name. | 1125 // Profile name, centered. |
1113 CGFloat availableTextWidth = | |
1114 kFixedMenuWidth - xOffset - 2 * kHorizontalSpacing; | |
1115 base::scoped_nsobject<EditableProfileNameButton> profileName( | 1126 base::scoped_nsobject<EditableProfileNameButton> profileName( |
1116 [[EditableProfileNameButton alloc] | 1127 [[EditableProfileNameButton alloc] |
1117 initWithFrame:NSMakeRect(xOffset, yOffset, | 1128 initWithFrame:NSMakeRect(xOffset, yOffset, |
1118 availableTextWidth, | 1129 availableTextWidth, |
1119 kProfileButtonHeight) | 1130 kProfileButtonHeight) |
1120 profile:browser_->profile() | 1131 profile:browser_->profile() |
1121 profileName:base::SysUTF16ToNSString( | 1132 profileName:base::SysUTF16ToNSString( |
1122 profiles::GetAvatarNameForProfile(browser_->profile())) | 1133 profiles::GetAvatarNameForProfile(browser_->profile())) |
1123 editingAllowed:!isGuestSession_]); | 1134 editingAllowed:!isGuestSession_]); |
1124 | 1135 |
1125 [container addSubview:profileName]; | 1136 [container addSubview:profileName]; |
1126 [container setFrameSize:NSMakeSize(kFixedMenuWidth, | 1137 yOffset = NSMaxY([profileName frame]); |
1127 NSHeight([iconView frame]))]; | 1138 |
1139 // Profile icon, centered. | |
1140 xOffset = (kFixedMenuWidth - kLargeImageSide) / 2; | |
1141 base::scoped_nsobject<EditableProfilePhoto> iconView( | |
1142 [[EditableProfilePhoto alloc] | |
1143 initWithFrame:NSMakeRect(xOffset, yOffset, | |
1144 kLargeImageSide, kLargeImageSide) | |
1145 avatarMenu:avatarMenu_.get() | |
1146 profileIcon:item.icon | |
1147 editingAllowed:!isGuestSession_]); | |
1148 | |
1149 [container addSubview:iconView]; | |
1150 yOffset = NSMaxY([iconView frame]); | |
1151 | |
1152 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | |
1128 return container.autorelease(); | 1153 return container.autorelease(); |
1129 } | 1154 } |
1130 | 1155 |
1131 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 1156 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
1132 withXOffset:(CGFloat)xOffset { | 1157 rect:(NSRect)rect { |
1133 base::scoped_nsobject<NSView> container([[NSView alloc] | 1158 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
1134 initWithFrame:NSZeroRect]); | |
1135 | 1159 |
1160 // Don't double-apply the left margin to the sub-views. | |
1161 rect.origin.x = 0; | |
1162 | |
1163 // The available links depend on the type of profile that is active. | |
1136 NSButton* link; | 1164 NSButton* link; |
1137 NSPoint frameOrigin = NSMakePoint(xOffset, kSmallVerticalSpacing); | |
1138 // The available links depend on the type of profile that is active. | |
1139 if (item.signed_in) { | 1165 if (item.signed_in) { |
1140 link = [self linkButtonWithTitle:l10n_util::GetNSString( | 1166 if (switches::IsNewProfileManagement()) { |
1141 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON) | 1167 NSString* linkTitle = l10n_util::GetNSString( |
1142 frameOrigin:frameOrigin | 1168 viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER ? |
1143 action:@selector(showAccountManagement:)]; | 1169 IDS_PROFILES_PROFILE_MANAGE_ACCOUNTS_BUTTON : |
1170 IDS_PROFILES_PROFILE_HIDE_MANAGE_ACCOUNTS_BUTTON); | |
1171 SEL linkSelector = (viewMode_ == BUBBLE_VIEW_MODE_PROFILE_CHOOSER) ? | |
1172 @selector(showAccountManagement:) : @selector(hideAccountManagement:); | |
1173 link = [self linkButtonWithTitle:linkTitle | |
1174 frameOrigin:rect.origin | |
1175 action:linkSelector]; | |
1176 } else { | |
1177 link = [self linkButtonWithTitle:base::SysUTF16ToNSString(item.sync_state) | |
1178 frameOrigin:rect.origin | |
1179 action:nil]; | |
1180 [[link cell] setTextColor:[NSColor blackColor]]; | |
1181 } | |
1182 // -linkButtonWithTitle sizeToFit's the link, so re-stretch it so that it | |
1183 // can be centered correctly in the view. | |
1184 rect.size.height = NSMaxY([link frame]); | |
1185 [link setFrame:rect]; | |
1186 [link setAlignment:NSCenterTextAlignment]; | |
1144 } else { | 1187 } else { |
1145 link = [self linkButtonWithTitle:l10n_util::GetNSStringFWithFixup( | 1188 rect.size.height = kBlueButtonHeight; |
1146 IDS_SYNC_START_SYNC_BUTTON_LABEL, | 1189 link = [[BlueLabelButton alloc] initWithFrame:rect]; |
1147 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)) | 1190 |
1148 frameOrigin:frameOrigin | 1191 // Manually elide the button text so that the contents fit inside the bubble |
1149 action:@selector(showSigninPage:)]; | 1192 // This is needed because the BlueLabelButton cell resets the style on |
1193 // every call to -cellSize, which prevents setting a custom lineBreakMode. | |
1194 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( | |
1195 l10n_util::GetStringFUTF16( | |
1196 IDS_SYNC_START_SYNC_BUTTON_LABEL, | |
1197 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)), | |
1198 ui::ResourceBundle::GetSharedInstance().GetFontList( | |
1199 ui::ResourceBundle::BaseFont), | |
1200 rect.size.width, | |
1201 gfx::ELIDE_AT_END)); | |
1202 | |
1203 [link setTitle:elidedButtonText]; | |
1204 [link setTarget:self]; | |
1205 [link setAction:switches::IsNewProfileManagement() ? | |
1206 @selector(showInlineSigninPage:) : @selector(showTabbedSigninPage:)]; | |
1150 } | 1207 } |
1151 | 1208 |
1152 [container addSubview:link]; | 1209 [container addSubview:link]; |
1153 [container setFrameSize:NSMakeSize( | 1210 [container setFrameSize:rect.size]; |
1154 NSMaxX([link frame]), NSMaxY([link frame]) + kSmallVerticalSpacing)]; | |
1155 return container.autorelease(); | 1211 return container.autorelease(); |
1156 } | 1212 } |
1157 | 1213 |
1158 - (NSView*)createGuestProfileView { | 1214 - (NSView*)createGuestProfileView { |
1159 gfx::Image guestIcon = | 1215 gfx::Image guestIcon = |
1160 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( | 1216 ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( |
1161 IDR_LOGIN_GUEST); | 1217 IDR_LOGIN_GUEST); |
1162 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ | 1218 AvatarMenu::Item guestItem(std::string::npos, /* menu_index, not used */ |
1163 std::string::npos, /* profile_index, not used */ | 1219 std::string::npos, /* profile_index, not used */ |
1164 guestIcon); | 1220 guestIcon); |
1165 guestItem.active = true; | 1221 guestItem.active = true; |
1166 guestItem.name = base::SysNSStringToUTF16( | 1222 guestItem.name = base::SysNSStringToUTF16( |
1167 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); | 1223 l10n_util::GetNSString(IDS_PROFILES_GUEST_PROFILE_NAME)); |
1168 | 1224 |
1169 return [self createCurrentProfileView:guestItem]; | 1225 return [self createCurrentProfileView:guestItem]; |
1170 } | 1226 } |
1171 | 1227 |
1172 - (NSButton*)createOtherProfileView:(int)itemIndex { | 1228 - (NSButton*)createOtherProfileView:(int)itemIndex { |
1173 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); | 1229 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); |
1174 base::scoped_nsobject<NSButton> profileButton([[NSButton alloc] | |
1175 initWithFrame:NSZeroRect]); | |
1176 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( | |
1177 [[CustomPaddingImageButtonCell alloc] | |
1178 initWithLeftMarginSpacing:0 | |
1179 imageTitleSpacing:kImageTitleSpacing]); | |
1180 [profileButton setCell:cell.get()]; | |
1181 | 1230 |
1182 [[profileButton cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 1231 NSRect rect = NSMakeRect(0, 0, kFixedMenuWidth, |
1232 kBlueButtonHeight + kSmallVerticalSpacing); | |
1233 SkColor backgroundColor = ui::NativeTheme::instance()->GetSystemColor( | |
1234 ui::NativeTheme::kColorId_DialogBackground); | |
1235 | |
1236 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( | |
1237 [[BackgroundColorHoverButton alloc] initWithFrame:rect | |
1238 imageTitleSpacing:kImageTitleSpacing | |
1239 backgroundColor:backgroundColor]); | |
1183 [profileButton setTitle:base::SysUTF16ToNSString(item.name)]; | 1240 [profileButton setTitle:base::SysUTF16ToNSString(item.name)]; |
1184 [profileButton setImage:CreateProfileImage( | 1241 [profileButton setDefaultImage:CreateProfileImage( |
1185 item.icon, kSmallImageSide).ToNSImage()]; | 1242 item.icon, kSmallImageSide).ToNSImage()]; |
1186 [profileButton setImagePosition:NSImageLeft]; | 1243 [profileButton setImagePosition:NSImageLeft]; |
1187 [profileButton setAlignment:NSLeftTextAlignment]; | 1244 [profileButton setAlignment:NSLeftTextAlignment]; |
1188 [profileButton setBordered:NO]; | 1245 [profileButton setBordered:NO]; |
1189 [profileButton setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | |
1190 [profileButton setTag:itemIndex]; | 1246 [profileButton setTag:itemIndex]; |
1191 [profileButton setTarget:self]; | 1247 [profileButton setTarget:self]; |
1192 [profileButton setAction:@selector(switchToProfile:)]; | 1248 [profileButton setAction:@selector(switchToProfile:)]; |
1193 | 1249 |
1194 // Since the bubble is fixed width, we need to calculate the width available | |
1195 // for the profile name, as longer names will have to be elided. | |
1196 CGFloat availableTextWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; | |
1197 [profileButton sizeToFit]; | |
1198 [profileButton setFrameSize:NSMakeSize(availableTextWidth, | |
1199 NSHeight([profileButton frame]))]; | |
1200 | |
1201 return profileButton.autorelease(); | 1250 return profileButton.autorelease(); |
1202 } | 1251 } |
1203 | 1252 |
1204 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 1253 - (NSView*)createOptionsViewWithRect:(NSRect)rect |
1205 enableLock:(BOOL)enableLock { | 1254 enableLock:(BOOL)enableLock { |
1206 int widthOfLockButton = enableLock? 2 * kHorizontalSpacing + 12 : 0; | 1255 int widthOfLockButton = enableLock? 2 * kHorizontalSpacing + 12 : 0; |
1207 NSRect viewRect = NSMakeRect(0, 0, | 1256 NSRect viewRect = NSMakeRect(0, 0, |
1208 rect.size.width - widthOfLockButton, | 1257 rect.size.width - widthOfLockButton, |
1209 kBlueButtonHeight); | 1258 kBlueButtonHeight + kVerticalSpacing); |
1210 NSButton* notYouButton = | 1259 NSButton* notYouButton = |
1211 [self hoverButtonWithRect:viewRect | 1260 [self hoverButtonWithRect:viewRect |
1212 text:l10n_util::GetNSStringF( | 1261 text:l10n_util::GetNSStringF( |
1213 IDS_PROFILES_NOT_YOU_BUTTON, | 1262 IDS_PROFILES_NOT_YOU_BUTTON, |
1214 profiles::GetAvatarNameForProfile(browser_->profile())) | 1263 profiles::GetAvatarNameForProfile(browser_->profile())) |
1215 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR | 1264 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR |
1216 alternateImageResourceId:IDR_ICON_PROFILES_MENU_AVATAR | 1265 alternateImageResourceId:IDR_ICON_PROFILES_MENU_AVATAR |
1217 action:@selector(showUserManager:)]; | 1266 action:@selector(showUserManager:)]; |
1218 | 1267 |
1219 rect.size.height = NSMaxY([notYouButton frame]); | 1268 rect.size.height = NSMaxY([notYouButton frame]); |
1220 base::scoped_nsobject<NSView> container([[NSView alloc] | 1269 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
1221 initWithFrame:rect]); | |
1222 [container addSubview:notYouButton]; | 1270 [container addSubview:notYouButton]; |
1223 | 1271 |
1224 if (enableLock) { | 1272 if (enableLock) { |
1225 viewRect.origin.x = NSMaxX([notYouButton frame]); | 1273 viewRect.origin.x = NSMaxX([notYouButton frame]); |
1226 viewRect.size.width = widthOfLockButton; | 1274 viewRect.size.width = widthOfLockButton; |
1227 NSButton* lockButton = | 1275 NSButton* lockButton = |
1228 [self hoverButtonWithRect:viewRect | 1276 [self hoverButtonWithRect:viewRect |
1229 text:@"" | 1277 text:@"" |
1230 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK | 1278 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK |
1231 alternateImageResourceId:IDR_ICON_PROFILES_MENU_LOCK | 1279 alternateImageResourceId:IDR_ICON_PROFILES_MENU_LOCK |
1232 action:@selector(lockProfile:)]; | 1280 action:@selector(lockProfile:)]; |
1233 [container addSubview:lockButton]; | 1281 [container addSubview:lockButton]; |
1234 } | 1282 } |
1235 | 1283 |
1236 return container.autorelease(); | 1284 return container.autorelease(); |
1237 } | 1285 } |
1238 | 1286 |
1239 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { | 1287 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect { |
1240 const CGFloat kAccountButtonHeight = 15; | 1288 const CGFloat kAccountButtonHeight = 34; |
1241 | 1289 |
1242 const AvatarMenu::Item& item = | 1290 const AvatarMenu::Item& item = |
1243 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | 1291 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); |
1244 DCHECK(item.signed_in); | 1292 DCHECK(item.signed_in); |
1245 | 1293 |
1246 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 1294 NSColor* backgroundColor = gfx::SkColorToCalibratedNSColor( |
1247 | 1295 profiles::kAvatarBubbleAccountsBackgroundColor); |
1248 NSRect viewRect = NSMakeRect(0, 0, rect.size.width, kBlueButtonHeight); | 1296 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] |
1249 base::scoped_nsobject<NSButton> addAccountsButton([[BlueLabelButton alloc] | 1297 initWithFrame:rect |
1250 initWithFrame:viewRect]); | 1298 withColor:backgroundColor]); |
1251 | 1299 |
1252 // Manually elide the button text so that the contents fit inside the bubble. | 1300 // Manually elide the button text so that the contents fit inside the bubble. |
1253 // This is needed because the BlueLabelButton cell resets the style on | 1301 // This is needed because the BlueLabelButton cell resets the style on |
1254 // every call to -cellSize, which prevents setting a custom lineBreakMode. | 1302 // every call to -cellSize, which prevents setting a custom lineBreakMode. |
1255 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( | 1303 NSString* elidedButtonText = base::SysUTF16ToNSString(gfx::ElideText( |
1256 l10n_util::GetStringFUTF16( | 1304 l10n_util::GetStringFUTF16( |
1257 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name), | 1305 IDS_PROFILES_PROFILE_ADD_ACCOUNT_BUTTON, item.name), |
1258 ui::ResourceBundle::GetSharedInstance().GetFontList( | 1306 ui::ResourceBundle::GetSharedInstance().GetFontList( |
1259 ui::ResourceBundle::BaseFont), | 1307 ui::ResourceBundle::BaseFont), |
1260 rect.size.width, | 1308 rect.size.width, |
1261 gfx::ELIDE_AT_END)); | 1309 gfx::ELIDE_AT_END)); |
1262 | 1310 |
1263 [addAccountsButton setTitle:elidedButtonText]; | 1311 NSButton* addAccountsButton = |
1264 [addAccountsButton setTarget:self]; | 1312 [self linkButtonWithTitle:elidedButtonText |
1265 [addAccountsButton setAction:@selector(addAccount:)]; | 1313 frameOrigin:NSMakePoint( |
1314 kHorizontalSpacing, kSmallVerticalSpacing) | |
1315 action:@selector(addAccount:)]; | |
1266 [container addSubview:addAccountsButton]; | 1316 [container addSubview:addAccountsButton]; |
1267 | 1317 |
1268 // Update the height of the email account buttons. This is needed so that the | 1318 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( |
1269 // all the buttons span the entire width of the bubble. | 1319 0, kAccountButtonHeight, rect.size.width, kAccountButtonHeight)]; |
1270 viewRect.origin.y = NSMaxY([addAccountsButton frame]) + kVerticalSpacing; | 1320 [container addSubview:accountEmails]; |
1271 viewRect.size.height = kAccountButtonHeight; | |
1272 | 1321 |
1273 NSView* accountEmails = [self createAccountsListWithRect:viewRect]; | 1322 [container setFrameSize:NSMakeSize(rect.size.width, |
1274 [container addSubview:accountEmails]; | 1323 NSMaxY([accountEmails frame]))]; |
1275 [container setFrameSize:NSMakeSize( | |
1276 NSWidth([container frame]), NSMaxY([accountEmails frame]))]; | |
1277 return container.autorelease(); | 1324 return container.autorelease(); |
1278 } | 1325 } |
1279 | 1326 |
1280 - (NSView*)createAccountsListWithRect:(NSRect)rect { | 1327 - (NSView*)createAccountsListWithRect:(NSRect)rect { |
1281 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 1328 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
1282 currentProfileAccounts_.clear(); | 1329 currentProfileAccounts_.clear(); |
1283 | 1330 |
1284 Profile* profile = browser_->profile(); | 1331 Profile* profile = browser_->profile(); |
1285 std::string primaryAccount = | 1332 std::string primaryAccount = |
1286 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); | 1333 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedUsername(); |
1287 DCHECK(!primaryAccount.empty()); | 1334 DCHECK(!primaryAccount.empty()); |
1288 std::vector<std::string>accounts = | 1335 std::vector<std::string>accounts = |
1289 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); | 1336 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); |
1290 | 1337 |
1291 rect.origin.y = 0; | 1338 rect.origin.y = 0; |
1292 for (size_t i = 0; i < accounts.size(); ++i) { | 1339 for (size_t i = 0; i < accounts.size(); ++i) { |
1293 // Save the original email address, as the button text could be elided. | 1340 // Save the original email address, as the button text could be elided. |
1294 currentProfileAccounts_[i] = accounts[i]; | 1341 currentProfileAccounts_[i] = accounts[i]; |
1295 NSButton* accountButton = [self accountButtonWithRect:rect | 1342 NSButton* accountButton = [self accountButtonWithRect:rect |
1296 title:accounts[i]]; | 1343 title:accounts[i]]; |
1297 [accountButton setTag:i]; | 1344 [accountButton setTag:i]; |
1298 [container addSubview:accountButton]; | 1345 [container addSubview:accountButton]; |
1299 rect.origin.y = NSMaxY([accountButton frame]) + kSmallVerticalSpacing; | 1346 rect.origin.y = NSMaxY([accountButton frame]); |
1300 } | 1347 } |
1301 | 1348 |
1302 // The primary account should always be listed first. | 1349 // The primary account should always be listed first. |
1303 NSButton* accountButton = [self accountButtonWithRect:rect | 1350 NSButton* accountButton = [self accountButtonWithRect:rect |
1304 title:primaryAccount]; | 1351 title:primaryAccount]; |
1305 [container addSubview:accountButton]; | 1352 [container addSubview:accountButton]; |
1306 [container setFrameSize:NSMakeSize(NSWidth([container frame]), | 1353 [container setFrameSize:NSMakeSize(NSWidth([container frame]), |
1307 NSMaxY([accountButton frame]))]; | 1354 NSMaxY([accountButton frame]))]; |
1308 [accountButton setTag:kPrimaryProfileTag]; | 1355 [accountButton setTag:kPrimaryProfileTag]; |
1309 return container.autorelease(); | 1356 return container.autorelease(); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1427 clickedOnLink:(id)link | 1474 clickedOnLink:(id)link |
1428 atIndex:(NSUInteger)charIndex { | 1475 atIndex:(NSUInteger)charIndex { |
1429 chrome::ShowSettings(browser_); | 1476 chrome::ShowSettings(browser_); |
1430 return YES; | 1477 return YES; |
1431 } | 1478 } |
1432 | 1479 |
1433 - (NSButton*)hoverButtonWithRect:(NSRect)rect | 1480 - (NSButton*)hoverButtonWithRect:(NSRect)rect |
1434 text:(NSString*)text | 1481 text:(NSString*)text |
1435 imageResourceId:(int)imageResourceId | 1482 imageResourceId:(int)imageResourceId |
1436 alternateImageResourceId:(int)alternateImageResourceId | 1483 alternateImageResourceId:(int)alternateImageResourceId |
1437 action:(SEL)action { | 1484 action:(SEL)action { |
1485 SkColor backgroundColor = ui::NativeTheme::instance()->GetSystemColor( | |
1486 ui::NativeTheme::kColorId_DialogBackground); | |
1438 base::scoped_nsobject<BackgroundColorHoverButton> button( | 1487 base::scoped_nsobject<BackgroundColorHoverButton> button( |
1439 [[BackgroundColorHoverButton alloc] initWithFrame:rect]); | 1488 [[BackgroundColorHoverButton alloc] initWithFrame:rect |
1489 imageTitleSpacing:kImageTitleSpacing | |
1490 backgroundColor:backgroundColor]); | |
1440 | 1491 |
1441 [button setTitle:text]; | 1492 [button setTitle:text]; |
1442 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | 1493 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); |
1443 NSImage* alternateImage = rb->GetNativeImageNamed( | 1494 NSImage* alternateImage = rb->GetNativeImageNamed( |
1444 alternateImageResourceId).ToNSImage(); | 1495 alternateImageResourceId).ToNSImage(); |
1445 [button setDefaultImage:rb->GetNativeImageNamed(imageResourceId).ToNSImage()]; | 1496 [button setDefaultImage:rb->GetNativeImageNamed(imageResourceId).ToNSImage()]; |
1446 [button setHoverImage:alternateImage]; | 1497 [button setHoverImage:alternateImage]; |
1447 [button setPressedImage:alternateImage]; | 1498 [button setPressedImage:alternateImage]; |
1448 [button setImagePosition:NSImageLeft]; | 1499 [button setImagePosition:NSImageLeft]; |
1449 [button setAlignment:NSLeftTextAlignment]; | 1500 [button setAlignment:NSLeftTextAlignment]; |
(...skipping 19 matching lines...) Expand all Loading... | |
1469 [link setTarget:self]; | 1520 [link setTarget:self]; |
1470 [link setAction:action]; | 1521 [link setAction:action]; |
1471 [link setFrameOrigin:frameOrigin]; | 1522 [link setFrameOrigin:frameOrigin]; |
1472 [link sizeToFit]; | 1523 [link sizeToFit]; |
1473 | 1524 |
1474 return link.autorelease(); | 1525 return link.autorelease(); |
1475 } | 1526 } |
1476 | 1527 |
1477 - (NSButton*)accountButtonWithRect:(NSRect)rect | 1528 - (NSButton*)accountButtonWithRect:(NSRect)rect |
1478 title:(const std::string&)title { | 1529 title:(const std::string&)title { |
1479 base::scoped_nsobject<NSButton> button([[NSButton alloc] initWithFrame:rect]); | 1530 SkColor backgroundColor = profiles::kAvatarBubbleAccountsBackgroundColor; |
1531 base::scoped_nsobject<BackgroundColorHoverButton> button( | |
1532 [[BackgroundColorHoverButton alloc] initWithFrame:rect | |
1533 imageTitleSpacing:0 | |
1534 backgroundColor:backgroundColor]); | |
1535 | |
1480 [button setTitle:ElideEmail(title, rect.size.width)]; | 1536 [button setTitle:ElideEmail(title, rect.size.width)]; |
1481 [button setAlignment:NSLeftTextAlignment]; | 1537 [button setAlignment:NSLeftTextAlignment]; |
1482 [button setBordered:NO]; | 1538 [button setBordered:NO]; |
1483 | |
1484 [button setImage:ui::ResourceBundle::GetSharedInstance(). | |
1485 GetNativeImageNamed(IDR_CLOSE_1).ToNSImage()]; | |
1486 [button setImagePosition:NSImageRight]; | |
1487 [button setTarget:self]; | 1539 [button setTarget:self]; |
1488 [button setAction:@selector(showAccountRemovalView:)]; | 1540 [button setAction:@selector(showAccountRemovalView:)]; |
1489 | 1541 |
1490 return button.autorelease(); | 1542 return button.autorelease(); |
1491 } | 1543 } |
1492 | 1544 |
1493 @end | 1545 @end |
OLD | NEW |