| 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 <Cocoa/Cocoa.h> | 5 #import <Cocoa/Cocoa.h> |
| 6 #import <Carbon/Carbon.h> // kVK_Return. | 6 #import <Carbon/Carbon.h> // kVK_Return. |
| 7 | 7 |
| 8 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" | 8 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" |
| 9 | 9 |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| (...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 if ([action isEqualToString:NSAccessibilityPressAction]) { | 611 if ([action isEqualToString:NSAccessibilityPressAction]) { |
| 612 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); | 612 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); |
| 613 } | 613 } |
| 614 | 614 |
| 615 [super accessibilityPerformAction:action]; | 615 [super accessibilityPerformAction:action]; |
| 616 } | 616 } |
| 617 | 617 |
| 618 @end | 618 @end |
| 619 | 619 |
| 620 // A custom text control that turns into a textfield for editing when clicked. | 620 // A custom text control that turns into a textfield for editing when clicked. |
| 621 @interface EditableProfileNameButton : HoverImageButton { | 621 @interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> { |
| 622 @private | 622 @private |
| 623 base::scoped_nsobject<NSTextField> profileNameTextField_; | 623 base::scoped_nsobject<NSTextField> profileNameTextField_; |
| 624 Profile* profile_; // Weak. | 624 Profile* profile_; // Weak. |
| 625 ProfileChooserController* controller_; | 625 ProfileChooserController* controller_; |
| 626 } | 626 } |
| 627 | 627 |
| 628 - (id)initWithFrame:(NSRect)frameRect | 628 - (id)initWithFrame:(NSRect)frameRect |
| 629 profile:(Profile*)profile | 629 profile:(Profile*)profile |
| 630 profileName:(NSString*)profileName | 630 profileName:(NSString*)profileName |
| 631 editingAllowed:(BOOL)editingAllowed | 631 editingAllowed:(BOOL)editingAllowed |
| 632 withController:(ProfileChooserController*)controller; | 632 withController:(ProfileChooserController*)controller; |
| 633 | 633 |
| 634 // Called when the button is clicked. | 634 // Called when the button is clicked. |
| 635 - (void)showEditableView:(id)sender; | 635 - (void)showEditableView:(id)sender; |
| 636 | 636 |
| 637 // Called when enter is pressed in the text field. | 637 // Called when enter is pressed in the text field. |
| 638 - (void)saveProfileName:(id)sender; | 638 - (void)saveProfileName; |
| 639 | 639 |
| 640 @end | 640 @end |
| 641 | 641 |
| 642 @implementation EditableProfileNameButton | 642 @implementation EditableProfileNameButton |
| 643 - (id)initWithFrame:(NSRect)frameRect | 643 - (id)initWithFrame:(NSRect)frameRect |
| 644 profile:(Profile*)profile | 644 profile:(Profile*)profile |
| 645 profileName:(NSString*)profileName | 645 profileName:(NSString*)profileName |
| 646 editingAllowed:(BOOL)editingAllowed | 646 editingAllowed:(BOOL)editingAllowed |
| 647 withController:(ProfileChooserController*)controller { | 647 withController:(ProfileChooserController*)controller { |
| 648 if ((self = [super initWithFrame:frameRect])) { | 648 if ((self = [super initWithFrame:frameRect])) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 684 [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
| 685 [profileNameTextField_ setEditable:YES]; | 685 [profileNameTextField_ setEditable:YES]; |
| 686 [profileNameTextField_ setDrawsBackground:YES]; | 686 [profileNameTextField_ setDrawsBackground:YES]; |
| 687 [profileNameTextField_ setBezeled:YES]; | 687 [profileNameTextField_ setBezeled:YES]; |
| 688 [profileNameTextField_ setAlignment:NSCenterTextAlignment]; | 688 [profileNameTextField_ setAlignment:NSCenterTextAlignment]; |
| 689 [[profileNameTextField_ cell] setWraps:NO]; | 689 [[profileNameTextField_ cell] setWraps:NO]; |
| 690 [[profileNameTextField_ cell] setLineBreakMode: | 690 [[profileNameTextField_ cell] setLineBreakMode: |
| 691 NSLineBreakByTruncatingTail]; | 691 NSLineBreakByTruncatingTail]; |
| 692 [[profileNameTextField_ cell] setUsesSingleLineMode:YES]; | 692 [[profileNameTextField_ cell] setUsesSingleLineMode:YES]; |
| 693 [self addSubview:profileNameTextField_]; | 693 [self addSubview:profileNameTextField_]; |
| 694 [profileNameTextField_ setTarget:self]; | 694 [profileNameTextField_ setDelegate:self]; |
| 695 [profileNameTextField_ setAction:@selector(saveProfileName:)]; | |
| 696 | 695 |
| 697 // Hide the textfield until the user clicks on the button. | 696 // Hide the textfield until the user clicks on the button. |
| 698 [profileNameTextField_ setHidden:YES]; | 697 [profileNameTextField_ setHidden:YES]; |
| 699 | 698 |
| 700 [[self cell] accessibilitySetOverrideValue:l10n_util::GetNSStringF( | 699 [[self cell] accessibilitySetOverrideValue:l10n_util::GetNSStringF( |
| 701 IDS_PROFILES_NEW_AVATAR_MENU_EDIT_NAME_ACCESSIBLE_NAME, | 700 IDS_PROFILES_NEW_AVATAR_MENU_EDIT_NAME_ACCESSIBLE_NAME, |
| 702 base::SysNSStringToUTF16(profileName)) | 701 base::SysNSStringToUTF16(profileName)) |
| 703 forAttribute:NSAccessibilityTitleAttribute]; | 702 forAttribute:NSAccessibilityTitleAttribute]; |
| 704 } | 703 } |
| 705 | 704 |
| 706 [[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole | 705 [[self cell] accessibilitySetOverrideValue:NSAccessibilityButtonRole |
| 707 forAttribute:NSAccessibilityRoleAttribute]; | 706 forAttribute:NSAccessibilityRoleAttribute]; |
| 708 [[self cell] | 707 [[self cell] |
| 709 accessibilitySetOverrideValue:NSAccessibilityRoleDescription( | 708 accessibilitySetOverrideValue:NSAccessibilityRoleDescription( |
| 710 NSAccessibilityButtonRole, nil) | 709 NSAccessibilityButtonRole, nil) |
| 711 forAttribute:NSAccessibilityRoleDescriptionAttribute]; | 710 forAttribute:NSAccessibilityRoleDescriptionAttribute]; |
| 712 | 711 |
| 713 [self setBordered:NO]; | 712 [self setBordered:NO]; |
| 714 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | 713 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]]; |
| 715 [self setAlignment:NSCenterTextAlignment]; | 714 [self setAlignment:NSCenterTextAlignment]; |
| 716 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; | 715 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 717 [self setTitle:profileName]; | 716 [self setTitle:profileName]; |
| 718 } | 717 } |
| 719 return self; | 718 return self; |
| 720 } | 719 } |
| 721 | 720 |
| 722 - (void)saveProfileName:(id)sender { | 721 - (void)saveProfileName { |
| 723 base::string16 newProfileName = | 722 base::string16 newProfileName = |
| 724 base::SysNSStringToUTF16([profileNameTextField_ stringValue]); | 723 base::SysNSStringToUTF16([profileNameTextField_ stringValue]); |
| 725 | 724 |
| 726 // Empty profile names are not allowed, and are treated as a cancel. | 725 // Empty profile names are not allowed, and do nothing. |
| 727 base::TrimWhitespace(newProfileName, base::TRIM_ALL, &newProfileName); | 726 base::TrimWhitespace(newProfileName, base::TRIM_ALL, &newProfileName); |
| 728 if (!newProfileName.empty()) { | 727 if (!newProfileName.empty()) { |
| 729 profiles::UpdateProfileName(profile_, newProfileName); | 728 profiles::UpdateProfileName(profile_, newProfileName); |
| 730 [controller_ | 729 [controller_ |
| 731 postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; | 730 postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; |
| 732 } else { | 731 [profileNameTextField_ setHidden:YES]; |
| 733 // Since the text is empty and not allowed, revert it from the textbox. | 732 // This needs to be called async as the firstResponder is reset |
| 734 [profileNameTextField_ setStringValue:[self title]]; | 733 // at the same time that controlTextDidEndEditing happens. |
| 734 dispatch_async(dispatch_get_main_queue(), ^{ |
| 735 [[self window] makeFirstResponder:nil]; |
| 736 }); |
| 735 } | 737 } |
| 736 [profileNameTextField_ setHidden:YES]; | |
| 737 } | 738 } |
| 738 | 739 |
| 739 - (void)showEditableView:(id)sender { | 740 - (void)showEditableView:(id)sender { |
| 740 [profileNameTextField_ setHidden:NO]; | 741 [profileNameTextField_ setHidden:NO]; |
| 741 [[self window] makeFirstResponder:profileNameTextField_]; | 742 [[self window] makeFirstResponder:profileNameTextField_]; |
| 742 } | 743 } |
| 743 | 744 |
| 744 - (BOOL)canBecomeKeyView { | 745 - (BOOL)canBecomeKeyView { |
| 745 return false; | 746 return false; |
| 746 } | 747 } |
| 747 | 748 |
| 749 - (void)controlTextDidEndEditing:(NSNotification*)notification { |
| 750 [self saveProfileName]; |
| 751 } |
| 752 |
| 748 @end | 753 @end |
| 749 | 754 |
| 750 // A custom button that allows for setting a background color when hovered over. | 755 // A custom button that allows for setting a background color when hovered over. |
| 751 @interface BackgroundColorHoverButton : HoverImageButton { | 756 @interface BackgroundColorHoverButton : HoverImageButton { |
| 752 @private | 757 @private |
| 753 base::scoped_nsobject<NSColor> backgroundColor_; | 758 base::scoped_nsobject<NSColor> backgroundColor_; |
| 754 base::scoped_nsobject<NSColor> hoverColor_; | 759 base::scoped_nsobject<NSColor> hoverColor_; |
| 755 } | 760 } |
| 756 @end | 761 @end |
| 757 | 762 |
| (...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2284 } | 2289 } |
| 2285 | 2290 |
| 2286 - (bool)shouldShowGoIncognito { | 2291 - (bool)shouldShowGoIncognito { |
| 2287 bool incognitoAvailable = | 2292 bool incognitoAvailable = |
| 2288 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2293 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2289 IncognitoModePrefs::DISABLED; | 2294 IncognitoModePrefs::DISABLED; |
| 2290 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2295 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2291 } | 2296 } |
| 2292 | 2297 |
| 2293 @end | 2298 @end |
| OLD | NEW |