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 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 - (void)accessibilityPerformAction:(NSString*)action { | 648 - (void)accessibilityPerformAction:(NSString*)action { |
| 649 if ([action isEqualToString:NSAccessibilityPressAction]) { | 649 if ([action isEqualToString:NSAccessibilityPressAction]) { |
| 650 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); | 650 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); |
| 651 } | 651 } |
| 652 | 652 |
| 653 [super accessibilityPerformAction:action]; | 653 [super accessibilityPerformAction:action]; |
| 654 } | 654 } |
| 655 | 655 |
| 656 @end | 656 @end |
| 657 | 657 |
| 658 // A custom view with a filled circular background. | |
| 659 @interface BackgroundCircleView : NSView { | |
| 660 @private | |
| 661 base::scoped_nsobject<NSColor> fillColor_; | |
| 662 } | |
| 663 @end | |
| 664 | |
| 665 @implementation BackgroundCircleView | |
| 666 - (id)initWithFrame:(NSRect)frameRect withFillColor:(NSColor*)fillColor { | |
| 667 if ((self = [super initWithFrame:frameRect])) | |
| 668 fillColor_.reset([fillColor retain]); | |
| 669 return self; | |
| 670 } | |
| 671 | |
| 672 - (void)drawRect:(NSRect)dirtyRect { | |
| 673 [fillColor_ setFill]; | |
| 674 NSBezierPath* circlePath = [NSBezierPath bezierPath]; | |
| 675 [circlePath appendBezierPathWithOvalInRect:[self bounds]]; | |
| 676 [circlePath fill]; | |
| 677 | |
| 678 [super drawRect:dirtyRect]; | |
| 679 } | |
| 680 @end | |
| 681 | |
| 658 // A custom text control that turns into a textfield for editing when clicked. | 682 // A custom text control that turns into a textfield for editing when clicked. |
| 659 @interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> { | 683 @interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> { |
| 660 @private | 684 @private |
| 661 base::scoped_nsobject<NSTextField> profileNameTextField_; | 685 base::scoped_nsobject<NSTextField> profileNameTextField_; |
| 662 Profile* profile_; // Weak. | 686 Profile* profile_; // Weak. |
| 663 ProfileChooserController* controller_; | 687 ProfileChooserController* controller_; |
| 664 } | 688 } |
| 665 | 689 |
| 666 - (id)initWithFrame:(NSRect)frameRect | 690 - (id)initWithFrame:(NSRect)frameRect |
| 667 profile:(Profile*)profile | 691 profile:(Profile*)profile |
| (...skipping 1389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2057 image:CreateProfileImage(item.icon, kMdImageSide, | 2081 image:CreateProfileImage(item.icon, kMdImageSide, |
| 2058 profiles::SHAPE_CIRCLE) | 2082 profiles::SHAPE_CIRCLE) |
| 2059 action:@selector(editProfile:)]; | 2083 action:@selector(editProfile:)]; |
| 2060 [[profileCard cell] setImageDimsWhenDisabled:NO]; | 2084 [[profileCard cell] setImageDimsWhenDisabled:NO]; |
| 2061 [container addSubview:profileCard]; | 2085 [container addSubview:profileCard]; |
| 2062 if (isGuestSession_) | 2086 if (isGuestSession_) |
| 2063 [profileCard setEnabled:NO]; | 2087 [profileCard setEnabled:NO]; |
| 2064 | 2088 |
| 2065 // Profile badge for supervised account. | 2089 // Profile badge for supervised account. |
| 2066 if (browser_->profile()->IsSupervised()) { | 2090 if (browser_->profile()->IsSupervised()) { |
| 2067 base::scoped_nsobject<NSImageView> supervisedIcon( | 2091 // Draw a circle as the background of the badge icon. |
| 2068 [[NSImageView alloc] initWithFrame:NSZeroRect]); | 2092 const int badgeSize = 24; |
|
groby-ooo-7-16
2016/08/23 02:32:55
Tiny nit: Maybe want to use constexpr here. (It's
Jane
2016/08/23 13:33:04
Done.
| |
| 2069 // TODO(janeliulwq): Replace the following two profile badge icons with | 2093 const int badgeSpacing = 4; |
| 2070 // smaller versions of them (24 x 24) to adapt to smaller profile icons. | 2094 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([ |
| 2071 int imageId = browser_->profile()->IsChild() | 2095 [BackgroundCircleView alloc] |
| 2072 ? IDR_ICON_PROFILES_MENU_CHILD | 2096 initWithFrame:NSMakeRect( |
|
groby-ooo-7-16
2016/08/23 02:32:55
is that formatted with git cl format? I'd think th
Jane
2016/08/23 13:33:04
True, I see...
| |
| 2073 : IDR_ICON_PROFILES_MENU_LEGACY_SUPERVISED; | 2097 xOffset + kMdImageSide - badgeSize + badgeSpacing, |
|
groby-ooo-7-16
2016/08/23 02:32:55
Maybe factor out either the entire rect, or at lea
Jane
2016/08/23 13:33:04
Done. Factored out the rect above.
| |
| 2074 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 2098 cardYOffset + kMdImageSide - badgeSize + badgeSpacing, |
| 2075 [supervisedIcon setImage:rb.GetNativeImageNamed(imageId).ToNSImage()]; | 2099 badgeSize, badgeSize) |
| 2100 withFillColor:GetDialogBackgroundColor()]); | |
| 2101 // Draw the badge icon. | |
|
groby-ooo-7-16
2016/08/23 02:32:55
Super nitpicky nit: Add the badge icon - you're no
Jane
2016/08/23 13:33:04
Done.
| |
| 2102 const int borderWidth = 1; | |
| 2103 const int badgeIconSize = badgeSize - borderWidth * 2; | |
| 2104 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc] | |
| 2105 initWithFrame:NSMakeRect(borderWidth, borderWidth, | |
| 2106 badgeIconSize, badgeIconSize)]); | |
| 2107 gfx::VectorIconId badgeIcon = | |
| 2108 browser_->profile()->IsChild() | |
| 2109 ? gfx::VectorIconId::ACCOUNT_CHILD_CIRCLE | |
| 2110 : gfx::VectorIconId::SUPERVISOR_ACCOUNT_CIRCLE; | |
| 2111 [badgeIconView | |
| 2112 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 2113 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))]; | |
| 2114 [badgeIconWithCircle addSubview:badgeIconView]; | |
| 2076 | 2115 |
| 2077 NSSize size = [[supervisedIcon image] size]; | 2116 [profileCard addSubview:badgeIconWithCircle]; |
| 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 } | 2117 } |
| 2086 | 2118 |
| 2087 // Profile name, left-aligned to the right of profile icon. | 2119 // Profile name, left-aligned to the right of profile icon. |
| 2088 xOffset += kMdImageSide + kHorizontalSpacing; | 2120 xOffset += kMdImageSide + kHorizontalSpacing; |
| 2089 CGFloat fontSize = kTextFontSize + 1.0; | 2121 CGFloat fontSize = kTextFontSize + 1.0; |
| 2090 NSTextField* profileName = BuildLabel( | 2122 NSTextField* profileName = BuildLabel( |
| 2091 base::SysUTF16ToNSString( | 2123 base::SysUTF16ToNSString( |
| 2092 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())), | 2124 profiles::GetAvatarNameForProfile(browser_->profile()->GetPath())), |
| 2093 NSZeroPoint, nil); | 2125 NSZeroPoint, nil); |
| 2094 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 2126 [[profileName cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| (...skipping 795 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2890 } | 2922 } |
| 2891 | 2923 |
| 2892 - (bool)shouldShowGoIncognito { | 2924 - (bool)shouldShowGoIncognito { |
| 2893 bool incognitoAvailable = | 2925 bool incognitoAvailable = |
| 2894 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2926 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2895 IncognitoModePrefs::DISABLED; | 2927 IncognitoModePrefs::DISABLED; |
| 2896 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2928 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2897 } | 2929 } |
| 2898 | 2930 |
| 2899 @end | 2931 @end |
| OLD | NEW |