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

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

Issue 960863002: Match profile name textfield behaviour to Windows (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rephrase comment Created 5 years, 10 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 2c8a22324cf495473a723774790156fe4271c5b1..41021aefaf51321cdc6abe0b58a664c53c9968e1 100644
--- a/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
+++ b/chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm
@@ -618,7 +618,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
@end
// A custom text control that turns into a textfield for editing when clicked.
-@interface EditableProfileNameButton : HoverImageButton {
+@interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> {
@private
base::scoped_nsobject<NSTextField> profileNameTextField_;
Profile* profile_; // Weak.
@@ -635,7 +635,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
- (void)showEditableView:(id)sender;
// Called when enter is pressed in the text field.
-- (void)saveProfileName:(id)sender;
+- (void)saveProfileName;
@end
@@ -691,8 +691,7 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
NSLineBreakByTruncatingTail];
[[profileNameTextField_ cell] setUsesSingleLineMode:YES];
[self addSubview:profileNameTextField_];
- [profileNameTextField_ setTarget:self];
- [profileNameTextField_ setAction:@selector(saveProfileName:)];
+ [profileNameTextField_ setDelegate:self];
// Hide the textfield until the user clicks on the button.
[profileNameTextField_ setHidden:YES];
@@ -719,21 +718,23 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
return self;
}
-- (void)saveProfileName:(id)sender {
+- (void)saveProfileName {
base::string16 newProfileName =
base::SysNSStringToUTF16([profileNameTextField_ stringValue]);
- // Empty profile names are not allowed, and are treated as a cancel.
+ // 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];
- } else {
- // Since the text is empty and not allowed, revert it from the textbox.
- [profileNameTextField_ setStringValue:[self title]];
+ [profileNameTextField_ setHidden:YES];
+ // This needs to be called async as the firstResponder is reset
+ // at the same time that controlTextDidEndEditing happens.
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[self window] makeFirstResponder:nil];
+ });
}
- [profileNameTextField_ setHidden:YES];
}
- (void)showEditableView:(id)sender {
@@ -745,6 +746,10 @@ class ActiveProfileObserverBridge : public AvatarMenuObserver,
return false;
}
+- (void)controlTextDidEndEditing:(NSNotification*)notification {
+ [self saveProfileName];
+}
+
@end
// A custom button that allows for setting a background color when hovered over.
« 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