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

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

Issue 2197253002: [Mac][MD User Menu] UI Tweaks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: NSHeight + rebased Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
6 6
7 #import <Carbon/Carbon.h> // kVK_Return. 7 #import <Carbon/Carbon.h> // kVK_Return.
8 #import <Cocoa/Cocoa.h> 8 #import <Cocoa/Cocoa.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 if ((self = [super initWithFrame:frameRect])) { 567 if ((self = [super initWithFrame:frameRect])) {
568 avatarMenu_ = avatarMenu; 568 avatarMenu_ = avatarMenu;
569 controller_ = controller; 569 controller_ = controller;
570 570
571 [self setBordered:NO]; 571 [self setBordered:NO];
572 572
573 base::scoped_nsobject<CustomCircleImageCell> cell( 573 base::scoped_nsobject<CustomCircleImageCell> cell(
574 [[CustomCircleImageCell alloc] init]); 574 [[CustomCircleImageCell alloc] init]);
575 [self setCell:cell.get()]; 575 [self setCell:cell.get()];
576 576
577 const int imageSide = 577 [self setDefaultImage:CreateProfileImage(profileIcon, kLargeImageSide,
578 switches::IsMaterialDesignUserMenu() ? kMdImageSide : kLargeImageSide; 578 profiles::SHAPE_SQUARE)];
579 [self setDefaultImage:CreateProfileImage(profileIcon, imageSide,
580 profiles::SHAPE_CIRCLE)];
581 [self setImagePosition:NSImageOnly]; 579 [self setImagePosition:NSImageOnly];
582 580
583 if (editingAllowed) { 581 if (editingAllowed) {
584 NSRect bounds = NSMakeRect(0, 0, imageSide, imageSide); 582 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide);
585 [self setTarget:self]; 583 [self setTarget:self];
586 [self setAction:@selector(editPhoto:)]; 584 [self setAction:@selector(editPhoto:)];
587 changePhotoImage_.reset([[TransparentBackgroundImageView alloc] 585 changePhotoImage_.reset([[TransparentBackgroundImageView alloc]
588 initWithFrame:bounds]); 586 initWithFrame:bounds]);
589 [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance(). 587 [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance().
590 GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()]; 588 GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()];
591 [self addSubview:changePhotoImage_]; 589 [self addSubview:changePhotoImage_];
592 590
593 // Hide the image until the button is hovered over. 591 // Hide the image until the button is hovered over.
594 [changePhotoImage_ setHidden:YES]; 592 [changePhotoImage_ setHidden:YES];
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
834 832
835 [self setBordered:NO]; 833 [self setBordered:NO];
836 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; 834 [self setFont:[NSFont labelFontOfSize:kTextFontSize]];
837 [self setButtonType:NSMomentaryChangeButton]; 835 [self setButtonType:NSMomentaryChangeButton];
838 836
839 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( 837 base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
840 [[CustomPaddingImageButtonCell alloc] 838 [[CustomPaddingImageButtonCell alloc]
841 initWithLeftMarginSpacing:kHorizontalSpacing 839 initWithLeftMarginSpacing:kHorizontalSpacing
842 imageTitleSpacing:imageTitleSpacing]); 840 imageTitleSpacing:imageTitleSpacing]);
843 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; 841 [cell setLineBreakMode:NSLineBreakByTruncatingTail];
842 if (switches::IsMaterialDesignUserMenu())
843 [cell setHighlightsBy:NSNoCellMask];
844 [self setCell:cell.get()]; 844 [self setCell:cell.get()];
845 } 845 }
846 return self; 846 return self;
847 } 847 }
848 848
849 - (void)setRightMarginSpacing:(int)rightMarginSpacing { 849 - (void)setRightMarginSpacing:(int)rightMarginSpacing {
850 [[self cell] setRightMarginSpacing:rightMarginSpacing]; 850 [[self cell] setRightMarginSpacing:rightMarginSpacing];
851 } 851 }
852 852
853 - (void)drawRect:(NSRect)dirtyRect { 853 - (void)drawRect:(NSRect)dirtyRect {
854 if ([self isEnabled]) { 854 if ([self isEnabled]) {
855 bool isHighlighted = ([self hoverState] != kHoverStateNone); 855 bool isHighlighted = ([self hoverState] != kHoverStateNone);
856 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; 856 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_;
857 [[self cell] setBackgroundColor:backgroundColor]; 857 [[self cell] setBackgroundColor:backgroundColor];
858 } 858 }
859 [super drawRect:dirtyRect]; 859 [super drawRect:dirtyRect];
860 } 860 }
861 861
862 -(void)keyDown:(NSEvent*)event { 862 -(void)keyDown:(NSEvent*)event {
863 // Since there is no default button in the bubble, it is safe to activate 863 // Since there is no default button in the bubble, it is safe to activate
864 // all buttons on Enter as well, and be consistent with the Windows 864 // all buttons on Enter as well, and be consistent with the Windows
865 // implementation. 865 // implementation.
866 if ([event keyCode] == kVK_Return) 866 if ([event keyCode] == kVK_Return)
867 [self performClick:self]; 867 [self performClick:self];
868 else 868 else
869 [super keyDown:event]; 869 [super keyDown:event];
870 } 870 }
871 871
872 - (BOOL)canBecomeKeyView { 872 - (BOOL)canBecomeKeyView {
873 return YES; 873 return [self isEnabled] ? YES : NO;
874 } 874 }
875 875
876 @end 876 @end
877 877
878 // A custom view with the given background color. 878 // A custom view with the given background color.
879 @interface BackgroundColorView : NSView { 879 @interface BackgroundColorView : NSView {
880 @private 880 @private
881 base::scoped_nsobject<NSColor> backgroundColor_; 881 base::scoped_nsobject<NSColor> backgroundColor_;
882 } 882 }
883 @end 883 @end
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after
2044 if (!NSIsEmptyRect(profileLinksBound)) { 2044 if (!NSIsEmptyRect(profileLinksBound)) {
2045 NSView* linksContainer = 2045 NSView* linksContainer =
2046 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; 2046 [self createCurrentProfileLinksForItem:item rect:profileLinksBound];
2047 [container addSubview:linksContainer]; 2047 [container addSubview:linksContainer];
2048 yOffset = NSMaxY([linksContainer frame]); 2048 yOffset = NSMaxY([linksContainer frame]);
2049 } 2049 }
2050 2050
2051 // Profile card button that contains the profile icon, name, and username. 2051 // Profile card button that contains the profile icon, name, and username.
2052 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 2052 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(),
2053 kMdImageSide + kVerticalSpacing); 2053 kMdImageSide + kVerticalSpacing);
2054 NSButton* profileCard = [self hoverButtonWithRect:rect 2054 NSButton* profileCard =
2055 text:[[NSString alloc] init] 2055 [self hoverButtonWithRect:rect
2056 action:@selector(editProfile:)]; 2056 text:[[NSString alloc] init]
2057 image:CreateProfileImage(item.icon, kMdImageSide,
2058 profiles::SHAPE_CIRCLE)
2059 action:@selector(editProfile:)];
2060 [[profileCard cell] setImageDimsWhenDisabled:NO];
2057 [container addSubview:profileCard]; 2061 [container addSubview:profileCard];
2058 if (isGuestSession_) 2062 if (isGuestSession_)
2059 [profileCard setEnabled:NO]; 2063 [profileCard setEnabled:NO];
2060 2064
2061 // Profile icon, left-aligned. 2065 // Profile badge for supervised account.
2062 base::scoped_nsobject<NSImageView> iconView([[NSImageView alloc] 2066 if (browser_->profile()->IsSupervised()) {
2063 initWithFrame:NSMakeRect(xOffset, cardYOffset, kMdImageSide, 2067 base::scoped_nsobject<NSImageView> supervisedIcon(
2064 kMdImageSide)]); 2068 [[NSImageView alloc] initWithFrame:NSZeroRect]);
2065 [iconView setImage:CreateProfileImage(item.icon, kMdImageSide, 2069 // TODO(janeliulwq): Replace the following two profile badge icons with
2066 profiles::SHAPE_CIRCLE)]; 2070 // smaller versions of them (24 x 24) to adapt to smaller profile icons.
2067 [profileCard addSubview:iconView]; 2071 int imageId = browser_->profile()->IsChild()
2072 ? IDR_ICON_PROFILES_MENU_CHILD
2073 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
2074 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
2075 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()];
2076
2077 NSSize size = [[supervisedIcon image] size];
2078 [supervisedIcon setFrameSize:size];
2079 const int badgeSpacing = 4;
2080 [supervisedIcon setFrameOrigin:NSMakePoint(xOffset + kMdImageSide -
2081 size.width + badgeSpacing,
2082 cardYOffset + kMdImageSide -
2083 size.height + badgeSpacing)];
2084 [profileCard addSubview:supervisedIcon];
2085 }
2068 2086
2069 // Profile name, left-aligned to the right of profile icon. 2087 // Profile name, left-aligned to the right of profile icon.
2070 xOffset += kMdImageSide + kHorizontalSpacing; 2088 xOffset += kMdImageSide + kHorizontalSpacing;
2071 CGFloat fontSize = kTextFontSize + 1.0; 2089 CGFloat fontSize = kTextFontSize + 1.0;
2072 NSTextField* profileName = BuildLabel( 2090 NSTextField* profileName = BuildLabel(
2073 base::SysUTF16ToNSString( 2091 base::SysUTF16ToNSString(
2074 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())), 2092 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())),
2075 NSZeroPoint, nil); 2093 NSZeroPoint, nil);
2076 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; 2094 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail];
2077 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; 2095 [profileName setFont:[NSFont labelFontOfSize:fontSize]];
2096 [profileName sizeToFit];
2097 const int profileNameYOffset =
2098 cardYOffset +
2099 std::floor((kMdImageSide - NSHeight([profileName frame])) / 2);
2078 [profileName 2100 [profileName
2079 setFrame:NSMakeRect( 2101 setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth,
2080 xOffset, 2102 NSHeight([profileName frame]))];
2081 cardYOffset +
2082 (kMdImageSide - [profileName frame].size.height) / 2,
2083 availableTextWidth, [profileName frame].size.height)];
2084 [profileCard addSubview:profileName]; 2103 [profileCard addSubview:profileName];
2085 2104
2086 // Username, left-aligned to the right of profile icon and below the profile 2105 // Username, left-aligned to the right of profile icon and below the profile
2087 // name. 2106 // name.
2088 if (item.signed_in && !switches::IsEnableAccountConsistency()) { 2107 if (item.signed_in && !switches::IsEnableAccountConsistency()) {
2089 // Adjust the y-position of profile name to leave space for username. 2108 // Adjust the y-position of profile name to leave space for username.
2090 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; 2109 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height;
2091 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; 2110 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)];
2092 2111
2093 NSTextField* username = BuildLabel( 2112 NSTextField* username = BuildLabel(
2094 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth), 2113 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth),
2095 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); 2114 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY));
2096 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; 2115 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))];
2097 [profileCard addSubview:username]; 2116 [profileCard addSubview:username];
2098 } 2117 }
2099 2118
2100 // Profile badge for supervised account.
2101 if (browser_->profile()->IsSupervised()) {
2102 base::scoped_nsobject<NSImageView> supervisedIcon(
2103 [[NSImageView alloc] initWithFrame:NSZeroRect]);
2104 // TODO(janeliulwq): Replace the following two profile badge icons with
2105 // smaller versions of them (24 x 24) to adapt to smaller profile icons.
2106 int imageId = browser_->profile()->IsChild()
2107 ? IDR_ICON_PROFILES_MENU_CHILD
2108 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
2109 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
2110 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()];
2111
2112 NSSize size = [[supervisedIcon image] size];
2113 [supervisedIcon setFrameSize:size];
2114 NSRect profileIconFrame = [iconView frame];
2115 const int badgeSpacing = 4;
2116 [supervisedIcon setFrameOrigin:NSMakePoint(NSMaxX(profileIconFrame) -
2117 size.width + badgeSpacing,
2118 NSMaxY(profileIconFrame) -
2119 size.height + badgeSpacing)];
2120 [profileCard addSubview:supervisedIcon];
2121 }
2122
2123 yOffset = NSMaxY([profileCard frame]); 2119 yOffset = NSMaxY([profileCard frame]);
2124 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 2120 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
2125 return container.autorelease(); 2121 return container.autorelease();
2126 } 2122 }
2127 2123
2128 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 2124 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
2129 rect:(NSRect)rect { 2125 rect:(NSRect)rect {
2130 if (switches::IsMaterialDesignUserMenu()) { 2126 if (switches::IsMaterialDesignUserMenu()) {
2131 // The branch is empty for material design user menu in non-account- 2127 // The branch is empty for material design user menu in non-account-
2132 // consistency mode, because in that case, the username would appear in the 2128 // consistency mode, because in that case, the username would appear in the
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2893 } 2889 }
2894 2890
2895 - (bool)shouldShowGoIncognito { 2891 - (bool)shouldShowGoIncognito {
2896 bool incognitoAvailable = 2892 bool incognitoAvailable =
2897 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2893 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2898 IncognitoModePrefs::DISABLED; 2894 IncognitoModePrefs::DISABLED;
2899 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2895 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2900 } 2896 }
2901 2897
2902 @end 2898 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698