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

Unified Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 2901043002: [Mac] Remove dead code in Profile Chooser Controller (Closed)
Patch Set: Created 3 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
diff --git a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
index 777e1f11c73011be2163a161ef55a7a6c3576292..7a6fa7c9a701859096cf96a4aba8824bd5314fb9 100644
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
@@ -93,7 +93,6 @@ namespace {
// Constants taken from the Windows/Views implementation at:
// chrome/browser/ui/views/profile_chooser_view.cc
-const int kLargeImageSide = 88;
const int kMdImageSide = 40;
const CGFloat kFixedMenuWidth = 240.0;
@@ -105,7 +104,6 @@ const CGFloat kHorizontalSpacing = 16.0;
const CGFloat kTitleFontSize = 15.0;
const CGFloat kTextFontSize = 12.0;
const CGFloat kProfileButtonHeight = 30;
-const int kBezelThickness = 3; // Width of the bezel on an NSButton.
const int kBlueButtonHeight = 30;
const CGFloat kFocusRingLineWidth = 2;
@@ -533,122 +531,6 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
}
@end
-// A custom image control that shows a "Change" button when moused over.
-@interface EditableProfilePhoto : HoverImageButton {
- @private
- AvatarMenu* avatarMenu_; // Weak; Owned by ProfileChooserController.
- base::scoped_nsobject<TransparentBackgroundImageView> changePhotoImage_;
- ProfileChooserController* controller_;
-}
-
-- (id)initWithFrame:(NSRect)frameRect
- avatarMenu:(AvatarMenu*)avatarMenu
- profileIcon:(const gfx::Image&)profileIcon
- editingAllowed:(BOOL)editingAllowed
- withController:(ProfileChooserController*)controller;
-
-// Called when the "Change" button is clicked.
-- (void)editPhoto:(id)sender;
-
-@end
-
-@implementation EditableProfilePhoto
-- (id)initWithFrame:(NSRect)frameRect
- avatarMenu:(AvatarMenu*)avatarMenu
- profileIcon:(const gfx::Image&)profileIcon
- editingAllowed:(BOOL)editingAllowed
- withController:(ProfileChooserController*)controller {
- if ((self = [super initWithFrame:frameRect])) {
- avatarMenu_ = avatarMenu;
- controller_ = controller;
-
- [self setBordered:NO];
-
- base::scoped_nsobject<CustomCircleImageCell> cell(
- [[CustomCircleImageCell alloc] init]);
- [self setCell:cell.get()];
-
- [self setDefaultImage:CreateProfileImage(profileIcon, kLargeImageSide,
- profiles::SHAPE_SQUARE)];
- [self setImagePosition:NSImageOnly];
-
- if (editingAllowed) {
- NSRect bounds = NSMakeRect(0, 0, kLargeImageSide, kLargeImageSide);
- [self setTarget:self];
- [self setAction:@selector(editPhoto:)];
- changePhotoImage_.reset([[TransparentBackgroundImageView alloc]
- initWithFrame:bounds]);
- [changePhotoImage_ setImage:ui::ResourceBundle::GetSharedInstance().
- GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()];
- [self addSubview:changePhotoImage_];
-
- // Hide the image until the button is hovered over.
- [changePhotoImage_ setHidden:YES];
- }
-
- // Set the image cell's accessibility strings to be the same as the
- // button's strings.
- [[self cell] accessibilitySetOverrideValue:l10n_util::GetNSString(
- editingAllowed ?
- IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME :
- IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME)
- forAttribute:NSAccessibilityTitleAttribute];
- [[self cell] accessibilitySetOverrideValue:
- editingAllowed ? NSAccessibilityButtonRole : NSAccessibilityImageRole
- forAttribute:NSAccessibilityRoleAttribute];
- [[self cell] accessibilitySetOverrideValue:
- NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil)
- forAttribute:NSAccessibilityRoleDescriptionAttribute];
-
- // The button and the cell should read the same thing.
- [self accessibilitySetOverrideValue:l10n_util::GetNSString(
- editingAllowed ?
- IDS_PROFILES_NEW_AVATAR_MENU_CHANGE_PHOTO_ACCESSIBLE_NAME :
- IDS_PROFILES_NEW_AVATAR_MENU_PHOTO_ACCESSIBLE_NAME)
- forAttribute:NSAccessibilityTitleAttribute];
- [self accessibilitySetOverrideValue:NSAccessibilityButtonRole
- forAttribute:NSAccessibilityRoleAttribute];
- [self accessibilitySetOverrideValue:
- NSAccessibilityRoleDescription(NSAccessibilityButtonRole, nil)
- forAttribute:NSAccessibilityRoleDescriptionAttribute];
- }
- return self;
-}
-
-- (void)editPhoto:(id)sender {
- avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex());
- [controller_
- postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE];
-}
-
-- (void)setHoverState:(HoverState)state {
- [super setHoverState:state];
- [changePhotoImage_ setHidden:([self hoverState] == kHoverStateNone)];
-}
-
-- (BOOL)canBecomeKeyView {
- return false;
-}
-
-- (BOOL)accessibilityIsIgnored {
- return NO;
-}
-
-- (NSArray*)accessibilityActionNames {
- NSArray* parentActions = [super accessibilityActionNames];
- return [parentActions arrayByAddingObject:NSAccessibilityPressAction];
-}
-
-- (void)accessibilityPerformAction:(NSString*)action {
- if ([action isEqualToString:NSAccessibilityPressAction]) {
- avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex());
- }
-
- [super accessibilityPerformAction:action];
-}
-
-@end
-
// A custom view with a filled circular background.
@interface BackgroundCircleView : NSView {
@private
@@ -673,158 +555,6 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
}
@end
-// A custom text control that turns into a textfield for editing when clicked.
-@interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> {
- @private
- base::scoped_nsobject<NSTextField> profileNameTextField_;
- Profile* profile_; // Weak.
- ProfileChooserController* controller_;
-}
-
-- (id)initWithFrame:(NSRect)frameRect
- profile:(Profile*)profile
- profileName:(NSString*)profileName
- editingAllowed:(BOOL)editingAllowed
- withController:(ProfileChooserController*)controller;
-
-// Called when the button is clicked.
-- (void)showEditableView:(id)sender;
-
-// Called when enter is pressed in the text field.
-- (void)saveProfileName;
-
-@end
-
-@implementation EditableProfileNameButton
-- (id)initWithFrame:(NSRect)frameRect
- profile:(Profile*)profile
- profileName:(NSString*)profileName
- editingAllowed:(BOOL)editingAllowed
- withController:(ProfileChooserController*)controller {
- if ((self = [super initWithFrame:frameRect])) {
- profile_ = profile;
- controller_ = controller;
-
- CGFloat availableWidth = frameRect.size.width;
- NSSize textSize = [profileName sizeWithAttributes:@{
- NSFontAttributeName : [self font]
- }];
-
- if (editingAllowed) {
- // Show an "edit" pencil icon when hovering over. In the default state,
- // we need to create an empty placeholder of the correct size, so that
- // the text doesn't jump around when the hovered icon appears.
- ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
- NSImage* hoverImage = rb->GetNativeImageNamed(
- IDR_ICON_PROFILES_EDIT_HOVER).AsNSImage();
-
- // In order to center the button title, we need to add a left padding of
- // the same width as the pencil icon.
- base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
- [[CustomPaddingImageButtonCell alloc]
- initWithLeftMarginSpacing:[hoverImage size].width
- imageTitleSpacing:0]);
- [self setCell:cell.get()];
-
- NSImage* placeholder = [[NSImage alloc] initWithSize:[hoverImage size]];
- [self setDefaultImage:placeholder];
- [self setHoverImage:hoverImage];
- [self setAlternateImage:
- rb->GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_PRESSED).AsNSImage()];
- [self setImagePosition:NSImageRight];
- [self setTarget:self];
- [self setAction:@selector(showEditableView:)];
-
- // We need to subtract the width of the bezel from the frame rect, so that
- // the textfield can take the exact same space as the button.
- frameRect.size.height -= 2 * kBezelThickness;
- frameRect.origin = NSMakePoint(0, kBezelThickness);
- profileNameTextField_.reset(
- [[NSTextField alloc] initWithFrame:frameRect]);
- [profileNameTextField_ setStringValue:profileName];
- [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]];
- [profileNameTextField_ setEditable:YES];
- [profileNameTextField_ setDrawsBackground:YES];
- [profileNameTextField_ setBezeled:YES];
- [profileNameTextField_ setAlignment:NSCenterTextAlignment];
- [[profileNameTextField_ cell] setWraps:NO];
- [[profileNameTextField_ cell] setLineBreakMode:
- NSLineBreakByTruncatingTail];
- [[profileNameTextField_ cell] setUsesSingleLineMode:YES];
- [self addSubview:profileNameTextField_];
- [profileNameTextField_ setDelegate:self];
-
- // Hide the textfield until the user clicks on the button.
- [profileNameTextField_ setHidden:YES];
-
- [[self cell] accessibilitySetOverrideValue:l10n_util::GetNSStringF(
- IDS_PROFILES_NEW_AVATAR_MENU_EDIT_NAME_ACCESSIBLE_NAME,
- base::SysNSStringToUTF16(profileName))
- forAttribute:NSAccessibilityTitleAttribute];
-
- // Recompute the available width for the name since the icon takes space.
- availableWidth -= [hoverImage size].width * 2;
- // The profileNameTextField_ might size the text differently.
- textSize = [profileName sizeWithAttributes:@{
- NSFontAttributeName : [profileNameTextField_ font]
- }];
- }
-
- if (textSize.width > availableWidth)
- [self setToolTip:profileName];
-
- [[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole
- forAttribute:NSAccessibilityRoleAttribute];
- [[self cell]
- accessibilitySetOverrideValue:NSAccessibilityRoleDescription(
- NSAccessibilityButtonRole, nil)
- forAttribute:NSAccessibilityRoleDescriptionAttribute];
-
- [self setBordered:NO];
- [self setFont:[NSFont labelFontOfSize:kTitleFontSize]];
- [self setAlignment:NSCenterTextAlignment];
- [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail];
- [self setTitle:profileName];
- }
- return self;
-}
-
-- (void)saveProfileName {
- base::string16 newProfileName =
- base::SysNSStringToUTF16([profileNameTextField_ stringValue]);
-
- // Empty profile names are not allowed, and do nothing.
- base::TrimWhitespace(newProfileName, base::TRIM_ALL, &newProfileName);
- if (!newProfileName.empty()) {
- profiles::UpdateProfileName(profile_, newProfileName);
- [controller_
- postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME];
- [profileNameTextField_ setHidden:YES];
- }
-}
-
-- (void)showEditableView:(id)sender {
- [profileNameTextField_ setHidden:NO];
- [[self window] makeFirstResponder:profileNameTextField_];
-}
-
-- (BOOL)canBecomeKeyView {
- return false;
-}
-
-- (BOOL)control:(NSControl*)control
- textView:(NSTextView*)textView
- doCommandBySelector:(SEL)commandSelector {
- if (commandSelector == @selector(insertTab:) ||
- commandSelector == @selector(insertNewline:)) {
- [self saveProfileName];
- return YES;
- }
- return NO;
-}
-
-@end
-
// A custom button that allows for setting a background color when hovered over.
@interface BackgroundColorHoverButton : HoverImageButton {
@private
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698