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

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: Number tweaking 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_base_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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 if ((self = [super initWithFrame:frameRect])) { 564 if ((self = [super initWithFrame:frameRect])) {
565 avatarMenu_ = avatarMenu; 565 avatarMenu_ = avatarMenu;
566 controller_ = controller; 566 controller_ = controller;
567 567
568 [self setBordered:NO]; 568 [self setBordered:NO];
569 569
570 base::scoped_nsobject<CustomCircleImageCell> cell( 570 base::scoped_nsobject<CustomCircleImageCell> cell(
571 [[CustomCircleImageCell alloc] init]); 571 [[CustomCircleImageCell alloc] init]);
572 [self setCell:cell.get()]; 572 [self setCell:cell.get()];
573 573
574 const int imageSide = 574 [self setDefaultImage:CreateProfileImage(profileIcon, kLargeImageSide,
575 switches::IsMaterialDesignUserMenu() ? kMdImageSide : kLargeImageSide; 575 profiles::SHAPE_SQUARE)];
groby-ooo-7-16 2016/08/03 17:23:09 I'm confused - the "after" images still show a rou
Jane 2016/08/08 19:22:24 Yes it's still a round avatar, and no we are keepi
576 [self setDefaultImage:CreateProfileImage(profileIcon, imageSide,
577 profiles::SHAPE_CIRCLE)];
578 [self setImagePosition:NSImageOnly]; 576 [self setImagePosition:NSImageOnly];
579 577
580 if (editingAllowed) { 578 if (editingAllowed) {
581 NSRect bounds = NSMakeRect(0, 0, imageSide, imageSide); 579 NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide);
582 [self setTarget:self]; 580 [self setTarget:self];
583 [self setAction:@selector(editPhoto:)]; 581 [self setAction:@selector(editPhoto:)];
584 changePhotoImage_.reset([[TransparentBackgroundImageView alloc] 582 changePhotoImage_.reset([[TransparentBackgroundImageView alloc]
585 initWithFrame:bounds]); 583 initWithFrame:bounds]);
586 [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance(). 584 [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance().
587 GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()]; 585 GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()];
588 [self addSubview:changePhotoImage_]; 586 [self addSubview:changePhotoImage_];
589 587
590 // Hide the image until the button is hovered over. 588 // Hide the image until the button is hovered over.
591 [changePhotoImage_ setHidden:YES]; 589 [changePhotoImage_ setHidden:YES];
(...skipping 1313 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 if (!NSIsEmptyRect(profileLinksBound)) { 1903 if (!NSIsEmptyRect(profileLinksBound)) {
1906 NSView* linksContainer = 1904 NSView* linksContainer =
1907 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; 1905 [self createCurrentProfileLinksForItem:item rect:profileLinksBound];
1908 [container addSubview:linksContainer]; 1906 [container addSubview:linksContainer];
1909 yOffset = NSMaxY([linksContainer frame]); 1907 yOffset = NSMaxY([linksContainer frame]);
1910 } 1908 }
1911 1909
1912 // Profile card button that contains the profile icon, name, and username. 1910 // Profile card button that contains the profile icon, name, and username.
1913 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 1911 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(),
1914 kMdImageSide + kVerticalSpacing); 1912 kMdImageSide + kVerticalSpacing);
1915 NSButton* profileCard = [self hoverButtonWithRect:rect 1913 NSButton* profileCard =
1916 text:[[NSString alloc] init] 1914 [self hoverButtonWithRect:rect
1917 action:@selector(editProfile:)]; 1915 text:[[NSString alloc] init]
1916 image:CreateProfileImage(item.icon, kMdImageSide,
1917 profiles::SHAPE_CIRCLE)
1918 action:@selector(editProfile:)];
1919 [[profileCard cell] setImageDimsWhenDisabled:NO];
groby-ooo-7-16 2016/08/03 17:23:09 How will the user tell it's disabled?
Jane 2016/08/08 19:22:24 Double checked with UI folks about this design: "T
groby-ooo-7-16 2016/08/10 20:01:51 Mumblegrumble UI should always indicate if there i
Jane 2016/08/10 22:42:57 I will bring this up for UI review (coming soon)!
1918 [container addSubview:profileCard]; 1920 [container addSubview:profileCard];
1919 if (isGuestSession_) 1921 if (isGuestSession_)
1920 [profileCard setEnabled:NO]; 1922 [profileCard setEnabled:NO];
1921 1923
1922 // Profile icon, left-aligned. 1924 // Profile badge for supervised account.
1923 base::scoped_nsobject<NSImageView> iconView([[NSImageView alloc] 1925 if (browser_->profile()->IsSupervised()) {
1924 initWithFrame:NSMakeRect(xOffset, cardYOffset, kMdImageSide, 1926 base::scoped_nsobject<NSImageView> supervisedIcon(
1925 kMdImageSide)]); 1927 [[NSImageView alloc] initWithFrame:NSZeroRect]);
1926 [iconView setImage:CreateProfileImage(item.icon, kMdImageSide, 1928 // TODO(janeliulwq): Replace the following two profile badge icons with
1927 profiles::SHAPE_CIRCLE)]; 1929 // smaller versions of them (24 x 24) to adapt to smaller profile icons.
groby-ooo-7-16 2016/08/03 17:23:09 Note (not this CL): You probably want SVG images h
Jane 2016/08/08 19:22:24 Yes, I will be using SVG images! :) I'm just still
1928 [profileCard addSubview:iconView]; 1930 int imageId = browser_->profile()->IsChild()
1931 ? IDR_ICON_PROFILES_MENU_CHILD
1932 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
1933 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1934 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()];
1935
1936 NSSize size = [[supervisedIcon image] size];
1937 [supervisedIcon setFrameSize:size];
1938 const int badgeSpacing = 4;
1939 [supervisedIcon setFrameOrigin:NSMakePoint(xOffset + kMdImageSide -
1940 size.width + badgeSpacing,
1941 cardYOffset + kMdImageSide -
1942 size.height + badgeSpacing)];
1943 [profileCard addSubview:supervisedIcon];
1944 }
1929 1945
1930 // Profile name, left-aligned to the right of profile icon. 1946 // Profile name, left-aligned to the right of profile icon.
1931 xOffset += kMdImageSide + kHorizontalSpacing; 1947 xOffset += kMdImageSide + kHorizontalSpacing;
1932 CGFloat fontSize = kTextFontSize + 1.0; 1948 CGFloat fontSize = kTextFontSize + 1.0;
1933 NSTextField* profileName = BuildLabel( 1949 NSTextField* profileName = BuildLabel(
1934 base::SysUTF16ToNSString( 1950 base::SysUTF16ToNSString(
1935 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())), 1951 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())),
1936 NSZeroPoint, nil); 1952 NSZeroPoint, nil);
1937 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; 1953 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail];
1938 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; 1954 [profileName setFont:[NSFont labelFontOfSize:fontSize]];
1955 [profileName sizeToFit];
1956 // Adding 1px in height to avoid cutting off certain letters on the bottom.
groby-ooo-7-16 2016/08/03 17:23:09 That's weird - any chance the letters are cut off
Jane 2016/08/08 19:22:24 Woah, yes that's exactly why! Changed it to std::f
groby-ooo-7-16 2016/08/10 20:01:51 My pleasure. You have now passed the std::ceil rit
1939 [profileName 1957 [profileName
1940 setFrame:NSMakeRect( 1958 setFrame:NSMakeRect(
1941 xOffset, 1959 xOffset,
1942 cardYOffset + 1960 cardYOffset +
1943 (kMdImageSide - [profileName frame].size.height) / 2, 1961 (kMdImageSide - [profileName frame].size.height - 1) / 2,
1944 availableTextWidth, [profileName frame].size.height)]; 1962 availableTextWidth, [profileName frame].size.height + 1)];
1945 [profileCard addSubview:profileName]; 1963 [profileCard addSubview:profileName];
1946 1964
1947 // Username, left-aligned to the right of profile icon and below the profile 1965 // Username, left-aligned to the right of profile icon and below the profile
1948 // name. 1966 // name.
1949 if (item.signed_in && !switches::IsEnableAccountConsistency()) { 1967 if (item.signed_in && !switches::IsEnableAccountConsistency()) {
1950 // Adjust the y-position of profile name to leave space for username. 1968 // Adjust the y-position of profile name to leave space for username.
1951 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; 1969 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height;
1952 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; 1970 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)];
1953 1971
1954 NSTextField* username = BuildLabel( 1972 NSTextField* username = BuildLabel(
1955 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth), 1973 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth),
1956 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); 1974 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY));
1957 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; 1975 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))];
1958 [profileCard addSubview:username]; 1976 [profileCard addSubview:username];
1959 } 1977 }
1960 1978
1961 // Profile badge for supervised account.
1962 if (browser_->profile()->IsSupervised()) {
1963 base::scoped_nsobject<NSImageView> supervisedIcon(
1964 [[NSImageView alloc] initWithFrame:NSZeroRect]);
1965 // TODO(janeliulwq): Replace the following two profile badge icons with
1966 // smaller versions of them (24 x 24) to adapt to smaller profile icons.
1967 int imageId = browser_->profile()->IsChild()
1968 ? IDR_ICON_PROFILES_MENU_CHILD
1969 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED;
1970 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1971 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()];
1972
1973 NSSize size = [[supervisedIcon image] size];
1974 [supervisedIcon setFrameSize:size];
1975 NSRect profileIconFrame = [iconView frame];
1976 const int badgeSpacing = 4;
1977 [supervisedIcon setFrameOrigin:NSMakePoint(NSMaxX(profileIconFrame) -
1978 size.width + badgeSpacing,
1979 NSMaxY(profileIconFrame) -
1980 size.height + badgeSpacing)];
1981 [profileCard addSubview:supervisedIcon];
1982 }
1983
1984 yOffset = NSMaxY([profileCard frame]); 1979 yOffset = NSMaxY([profileCard frame]);
1985 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; 1980 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)];
1986 return container.autorelease(); 1981 return container.autorelease();
1987 } 1982 }
1988 1983
1989 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item 1984 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item
1990 rect:(NSRect)rect { 1985 rect:(NSRect)rect {
1991 if (switches::IsMaterialDesignUserMenu()) { 1986 if (switches::IsMaterialDesignUserMenu()) {
1992 // The branch is empty for material design user menu in non-account- 1987 // The branch is empty for material design user menu in non-account-
1993 // consistency mode, because in that case, the username would appear in the 1988 // consistency mode, because in that case, the username would appear in the
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after
2754 } 2749 }
2755 2750
2756 - (bool)shouldShowGoIncognito { 2751 - (bool)shouldShowGoIncognito {
2757 bool incognitoAvailable = 2752 bool incognitoAvailable =
2758 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 2753 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
2759 IncognitoModePrefs::DISABLED; 2754 IncognitoModePrefs::DISABLED;
2760 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 2755 return incognitoAvailable && !browser_->profile()->IsGuestSession();
2761 } 2756 }
2762 2757
2763 @end 2758 @end
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/profiles/avatar_base_controller.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698