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 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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)]; |
| 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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 831 | 829 |
| 832 [self setBordered:NO]; | 830 [self setBordered:NO]; |
| 833 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 831 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
| 834 [self setButtonType:NSMomentaryChangeButton]; | 832 [self setButtonType:NSMomentaryChangeButton]; |
| 835 | 833 |
| 836 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( | 834 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( |
| 837 [[CustomPaddingImageButtonCell alloc] | 835 [[CustomPaddingImageButtonCell alloc] |
| 838 initWithLeftMarginSpacing:kHorizontalSpacing | 836 initWithLeftMarginSpacing:kHorizontalSpacing |
| 839 imageTitleSpacing:imageTitleSpacing]); | 837 imageTitleSpacing:imageTitleSpacing]); |
| 840 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; | 838 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 839 if (switches::IsMaterialDesignUserMenu()) | |
| 840 [cell setHighlightsBy:NSNoCellMask]; | |
| 841 [self setCell:cell.get()]; | 841 [self setCell:cell.get()]; |
| 842 } | 842 } |
| 843 return self; | 843 return self; |
| 844 } | 844 } |
| 845 | 845 |
| 846 - (void)setRightMarginSpacing:(int)rightMarginSpacing { | 846 - (void)setRightMarginSpacing:(int)rightMarginSpacing { |
| 847 [[self cell] setRightMarginSpacing:rightMarginSpacing]; | 847 [[self cell] setRightMarginSpacing:rightMarginSpacing]; |
| 848 } | 848 } |
| 849 | 849 |
| 850 - (void)drawRect:(NSRect)dirtyRect { | 850 - (void)drawRect:(NSRect)dirtyRect { |
| 851 if ([self isEnabled]) { | 851 if ([self isEnabled]) { |
| 852 bool isHighlighted = ([self hoverState] != kHoverStateNone); | 852 bool isHighlighted = ([self hoverState] != kHoverStateNone); |
| 853 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; | 853 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; |
| 854 [[self cell] setBackgroundColor:backgroundColor]; | 854 [[self cell] setBackgroundColor:backgroundColor]; |
| 855 } | 855 } |
| 856 [super drawRect:dirtyRect]; | 856 [super drawRect:dirtyRect]; |
| 857 } | 857 } |
| 858 | 858 |
| 859 -(void)keyDown:(NSEvent*)event { | 859 -(void)keyDown:(NSEvent*)event { |
| 860 // Since there is no default button in the bubble, it is safe to activate | 860 // Since there is no default button in the bubble, it is safe to activate |
| 861 // all buttons on Enter as well, and be consistent with the Windows | 861 // all buttons on Enter as well, and be consistent with the Windows |
| 862 // implementation. | 862 // implementation. |
| 863 if ([event keyCode] == kVK_Return) | 863 if ([event keyCode] == kVK_Return) |
| 864 [self performClick:self]; | 864 [self performClick:self]; |
| 865 else | 865 else |
| 866 [super keyDown:event]; | 866 [super keyDown:event]; |
| 867 } | 867 } |
| 868 | 868 |
| 869 - (BOOL)canBecomeKeyView { | 869 - (BOOL)canBecomeKeyView { |
| 870 return YES; | 870 return [self isEnabled] ? YES : NO; |
| 871 } | 871 } |
| 872 | 872 |
| 873 @end | 873 @end |
| 874 | 874 |
| 875 // A custom view with the given background color. | 875 // A custom view with the given background color. |
| 876 @interface BackgroundColorView : NSView { | 876 @interface BackgroundColorView : NSView { |
| 877 @private | 877 @private |
| 878 base::scoped_nsobject<NSColor> backgroundColor_; | 878 base::scoped_nsobject<NSColor> backgroundColor_; |
| 879 } | 879 } |
| 880 @end | 880 @end |
| (...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1905 if (!NSIsEmptyRect(profileLinksBound)) { | 1905 if (!NSIsEmptyRect(profileLinksBound)) { |
| 1906 NSView* linksContainer = | 1906 NSView* linksContainer = |
| 1907 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; | 1907 [self createCurrentProfileLinksForItem:item rect:profileLinksBound]; |
| 1908 [container addSubview:linksContainer]; | 1908 [container addSubview:linksContainer]; |
| 1909 yOffset = NSMaxY([linksContainer frame]); | 1909 yOffset = NSMaxY([linksContainer frame]); |
| 1910 } | 1910 } |
| 1911 | 1911 |
| 1912 // Profile card button that contains the profile icon, name, and username. | 1912 // Profile card button that contains the profile icon, name, and username. |
| 1913 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), | 1913 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), |
| 1914 kMdImageSide + kVerticalSpacing); | 1914 kMdImageSide + kVerticalSpacing); |
| 1915 NSButton* profileCard = [self hoverButtonWithRect:rect | 1915 NSButton* profileCard = |
| 1916 text:[[NSString alloc] init] | 1916 [self hoverButtonWithRect:rect |
| 1917 action:@selector(editProfile:)]; | 1917 text:[[NSString alloc] init] |
| 1918 image:CreateProfileImage(item.icon, kMdImageSide, | |
| 1919 profiles::SHAPE_CIRCLE) | |
| 1920 action:@selector(editProfile:)]; | |
| 1921 [[profileCard cell] setImageDimsWhenDisabled:NO]; | |
| 1918 [container addSubview:profileCard]; | 1922 [container addSubview:profileCard]; |
| 1919 if (isGuestSession_) | 1923 if (isGuestSession_) |
| 1920 [profileCard setEnabled:NO]; | 1924 [profileCard setEnabled:NO]; |
| 1921 | 1925 |
| 1922 // Profile icon, left-aligned. | 1926 // Profile badge for supervised account. |
| 1923 base::scoped_nsobject<NSImageView> iconView([[NSImageView alloc] | 1927 if (browser_->profile()->IsSupervised()) { |
| 1924 initWithFrame:NSMakeRect(xOffset, cardYOffset, kMdImageSide, | 1928 base::scoped_nsobject<NSImageView> supervisedIcon( |
| 1925 kMdImageSide)]); | 1929 [[NSImageView alloc] initWithFrame:NSZeroRect]); |
| 1926 [iconView setImage:CreateProfileImage(item.icon, kMdImageSide, | 1930 // TODO(janeliulwq): Replace the following two profile badge icons with |
| 1927 profiles::SHAPE_CIRCLE)]; | 1931 // smaller versions of them (24 x 24) to adapt to smaller profile icons. |
| 1928 [profileCard addSubview:iconView]; | 1932 int imageId = browser_->profile()->IsChild() |
| 1933 ? IDR_ICON_PROFILES_MENU_CHILD | |
| 1934 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED; | |
| 1935 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 1936 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()]; | |
| 1937 | |
| 1938 NSSize size = [[supervisedIcon image] size]; | |
| 1939 [supervisedIcon setFrameSize:size]; | |
| 1940 const int badgeSpacing = 4; | |
| 1941 [supervisedIcon setFrameOrigin:NSMakePoint(xOffset + kMdImageSide - | |
| 1942 size.width + badgeSpacing, | |
| 1943 cardYOffset + kMdImageSide - | |
| 1944 size.height + badgeSpacing)]; | |
| 1945 [profileCard addSubview:supervisedIcon]; | |
| 1946 } | |
| 1929 | 1947 |
| 1930 // Profile name, left-aligned to the right of profile icon. | 1948 // Profile name, left-aligned to the right of profile icon. |
| 1931 xOffset += kMdImageSide + kHorizontalSpacing; | 1949 xOffset += kMdImageSide + kHorizontalSpacing; |
| 1932 CGFloat fontSize = kTextFontSize + 1.0; | 1950 CGFloat fontSize = kTextFontSize + 1.0; |
| 1933 NSTextField* profileName = BuildLabel( | 1951 NSTextField* profileName = BuildLabel( |
| 1934 base::SysUTF16ToNSString( | 1952 base::SysUTF16ToNSString( |
| 1935 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())), | 1953 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())), |
| 1936 NSZeroPoint, nil); | 1954 NSZeroPoint, nil); |
| 1937 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 1955 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 1938 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; | 1956 [profileName setFont:[NSFont labelFontOfSize:fontSize]]; |
| 1957 [profileName sizeToFit]; | |
|
groby-ooo-7-16
2016/08/10 20:01:51
FWIW: You seem to use sizeToFit only to derive fon
Jane
2016/08/10 22:42:58
Yes, I'm only using sizeToFit to adapt to the new
groby-ooo-7-16
2016/08/11 05:33:19
It _should_ work fine, but since it doesn't, just
| |
| 1958 const int profileNameYOffset = | |
| 1959 cardYOffset + | |
| 1960 std::floor((kMdImageSide - [profileName frame].size.height) / 2); | |
| 1939 [profileName | 1961 [profileName |
| 1940 setFrame:NSMakeRect( | 1962 setFrame:NSMakeRect(xOffset, profileNameYOffset, availableTextWidth, |
| 1941 xOffset, | 1963 [profileName frame].size.height)]; |
|
groby-ooo-7-16
2016/08/10 20:01:51
Tiny nit: NSHeight([profileName frame]) here and p
Jane
2016/08/10 22:42:58
Done.
| |
| 1942 cardYOffset + | |
| 1943 (kMdImageSide - [profileName frame].size.height) / 2, | |
| 1944 availableTextWidth, [profileName frame].size.height)]; | |
| 1945 [profileCard addSubview:profileName]; | 1964 [profileCard addSubview:profileName]; |
| 1946 | 1965 |
| 1947 // Username, left-aligned to the right of profile icon and below the profile | 1966 // Username, left-aligned to the right of profile icon and below the profile |
| 1948 // name. | 1967 // name. |
| 1949 if (item.signed_in && !switches::IsEnableAccountConsistency()) { | 1968 if (item.signed_in && !switches::IsEnableAccountConsistency()) { |
| 1950 // Adjust the y-position of profile name to leave space for username. | 1969 // Adjust the y-position of profile name to leave space for username. |
| 1951 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; | 1970 cardYOffset += kMdImageSide / 2 - [profileName frame].size.height; |
| 1952 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; | 1971 [profileName setFrameOrigin:NSMakePoint(xOffset, cardYOffset)]; |
| 1953 | 1972 |
| 1954 NSTextField* username = BuildLabel( | 1973 NSTextField* username = BuildLabel( |
| 1955 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth), | 1974 ElideEmail(base::UTF16ToUTF8(item.username), availableTextWidth), |
| 1956 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); | 1975 NSZeroPoint, skia::SkColorToSRGBNSColor(SK_ColorGRAY)); |
| 1957 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; | 1976 [username setFrameOrigin:NSMakePoint(xOffset, NSMaxY([profileName frame]))]; |
| 1958 [profileCard addSubview:username]; | 1977 [profileCard addSubview:username]; |
| 1959 } | 1978 } |
| 1960 | 1979 |
| 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]); | 1980 yOffset = NSMaxY([profileCard frame]); |
| 1985 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 1981 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; |
| 1986 return container.autorelease(); | 1982 return container.autorelease(); |
| 1987 } | 1983 } |
| 1988 | 1984 |
| 1989 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 1985 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
| 1990 rect:(NSRect)rect { | 1986 rect:(NSRect)rect { |
| 1991 if (switches::IsMaterialDesignUserMenu()) { | 1987 if (switches::IsMaterialDesignUserMenu()) { |
| 1992 // The branch is empty for material design user menu in non-account- | 1988 // 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 | 1989 // consistency mode, because in that case, the username would appear in the |
| (...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2754 } | 2750 } |
| 2755 | 2751 |
| 2756 - (bool)shouldShowGoIncognito { | 2752 - (bool)shouldShowGoIncognito { |
| 2757 bool incognitoAvailable = | 2753 bool incognitoAvailable = |
| 2758 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2754 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2759 IncognitoModePrefs::DISABLED; | 2755 IncognitoModePrefs::DISABLED; |
| 2760 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2756 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2761 } | 2757 } |
| 2762 | 2758 |
| 2763 @end | 2759 @end |
| OLD | NEW |