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

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

Issue 474123002: [Mac, Win] Don't allow blank spaces in profile names in the new avatar bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: use TrimWhitespace ftw Created 6 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | 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 <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 [self setBordered:NO]; 616 [self setBordered:NO];
617 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; 617 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]];
618 [self setAlignment:NSCenterTextAlignment]; 618 [self setAlignment:NSCenterTextAlignment];
619 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; 619 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail];
620 [self setTitle:profileName]; 620 [self setTitle:profileName];
621 } 621 }
622 return self; 622 return self;
623 } 623 }
624 624
625 - (void)saveProfileName:(id)sender { 625 - (void)saveProfileName:(id)sender {
626 NSString* text = [profileNameTextField_ stringValue]; 626 NSString* originalText = [profileNameTextField_ stringValue];
627 base::string16 newProfileName = base::SysNSStringToUTF16(originalText);
628
627 // Empty profile names are not allowed, and are treated as a cancel. 629 // Empty profile names are not allowed, and are treated as a cancel.
628 if ([text length] > 0) { 630 base::TrimWhitespace(newProfileName, base::TRIM_ALL, &newProfileName);
629 profiles::UpdateProfileName(profile_, base::SysNSStringToUTF16(text)); 631 if (!newProfileName.empty()) {
632 profiles::UpdateProfileName(profile_, newProfileName);
630 [controller_ 633 [controller_
631 postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; 634 postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME];
632 [self setTitle:text]; 635 [self setTitle:originalText];
Alexei Svitkine (slow) 2014/08/15 17:40:46 If this really needs to be |originalText| instead
noms (inactive) 2014/08/15 18:14:28 Oh, now that I am doing the trimming you're right,
633 } 636 }
634 [profileNameTextField_ setHidden:YES]; 637 [profileNameTextField_ setHidden:YES];
635 } 638 }
636 639
637 - (void)showEditableView:(id)sender { 640 - (void)showEditableView:(id)sender {
641 // Update the textbox to the correct string, just in case we had previously
642 // entered a string that was rejected (eg. all spaces).
Alexei Svitkine (slow) 2014/08/15 17:40:47 If the previous string was rejected, then it would
noms (inactive) 2014/08/15 18:14:28 If the string is incorrect, we cancel editing, don
643 [profileNameTextField_ setStringValue:[self title]];
638 [profileNameTextField_ setHidden:NO]; 644 [profileNameTextField_ setHidden:NO];
639 [[self window] makeFirstResponder:profileNameTextField_]; 645 [[self window] makeFirstResponder:profileNameTextField_];
640 } 646 }
641 647
642 @end 648 @end
643 649
644 // A custom button that allows for setting a background color when hovered over. 650 // A custom button that allows for setting a background color when hovered over.
645 @interface BackgroundColorHoverButton : HoverImageButton { 651 @interface BackgroundColorHoverButton : HoverImageButton {
646 @private 652 @private
647 base::scoped_nsobject<NSColor> backgroundColor_; 653 base::scoped_nsobject<NSColor> backgroundColor_;
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1960 } 1966 }
1961 1967
1962 - (bool)shouldShowGoIncognito { 1968 - (bool)shouldShowGoIncognito {
1963 bool incognitoAvailable = 1969 bool incognitoAvailable =
1964 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != 1970 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) !=
1965 IncognitoModePrefs::DISABLED; 1971 IncognitoModePrefs::DISABLED;
1966 return incognitoAvailable && !browser_->profile()->IsGuestSession(); 1972 return incognitoAvailable && !browser_->profile()->IsGuestSession();
1967 } 1973 }
1968 1974
1969 @end 1975 @end
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/profiles/profile_chooser_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698