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 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
669 atYOffset:(CGFloat)yOffset; | 669 atYOffset:(CGFloat)yOffset; |
670 | 670 |
671 // Builds the fast user switcher view. This appears as part of the user menu. | 671 // Builds the fast user switcher view. This appears as part of the user menu. |
672 // Returns the yOffset corresponding to after the profile switcher buttons. | 672 // Returns the yOffset corresponding to after the profile switcher buttons. |
673 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles | 673 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSArray*)otherProfiles |
674 atYOffset:(CGFloat)yOffset | 674 atYOffset:(CGFloat)yOffset |
675 inContainer:(NSView*)container; | 675 inContainer:(NSView*)container; |
676 | 676 |
677 // Builds the regular profile chooser view. | 677 // Builds the regular profile chooser view. |
678 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 678 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
679 tutorialView:(NSView*)tutorialView | |
680 syncErrorView:(NSView*)syncErrorView | 679 syncErrorView:(NSView*)syncErrorView |
681 otherProfiles:(NSArray*)otherProfiles | 680 otherProfiles:(NSArray*)otherProfiles |
682 atYOffset:(CGFloat)yOffset | 681 atYOffset:(CGFloat)yOffset |
683 inContainer:(NSView*)container | 682 inContainer:(NSView*)container |
684 showLock:(bool)showLock; | 683 showLock:(bool)showLock; |
685 | 684 |
686 // Builds the profile chooser view. | 685 // Builds the profile chooser view. |
687 - (NSView*)buildProfileChooserView; | 686 - (NSView*)buildProfileChooserView; |
688 | 687 |
689 // Builds a tutorial card with a title label using |titleMessage|, a content | |
690 // label using |contentMessage|, a link using |linkMessage|, and a button using | |
691 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | |
692 // Otherwise places both on the same row with the link left aligned and button | |
693 // right aligned. On click, the link would execute |linkAction|, and the button | |
694 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. | |
695 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | |
696 titleMessage:(NSString*)titleMessage | |
697 contentMessage:(NSString*)contentMessage | |
698 linkMessage:(NSString*)linkMessage | |
699 buttonMessage:(NSString*)buttonMessage | |
700 stackButton:(BOOL)stackButton | |
701 hasCloseButton:(BOOL)hasCloseButton | |
702 linkAction:(SEL)linkAction | |
703 buttonAction:(SEL)buttonAction; | |
704 | |
705 // Builds a header for signin and sync error surfacing on the user menu. | 688 // Builds a header for signin and sync error surfacing on the user menu. |
706 - (NSView*)buildSyncErrorViewIfNeeded; | 689 - (NSView*)buildSyncErrorViewIfNeeded; |
707 | 690 |
708 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if | |
709 // needed. |tutorial_shown| indicates if the tutorial has already been shown in | |
710 // the previous active view. |avatar_item| refers to the current profile. | |
711 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item; | |
712 | |
713 // Builds a tutorial card to have the user confirm the last Chrome signin, | |
714 // Chrome sync will be delayed until the user either dismisses the tutorial, or | |
715 // configures sync through the "Settings" link. | |
716 - (NSView*)buildSigninConfirmationView; | |
717 | |
718 // Builds a tutorial card to show the last signin error. | |
719 - (NSView*)buildSigninErrorView; | |
720 | |
721 // Creates the main profile card for the profile |item| at the top of | 691 // Creates the main profile card for the profile |item| at the top of |
722 // the bubble. | 692 // the bubble. |
723 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; | 693 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item; |
724 | 694 |
725 // Creates the possible links for the main profile card with profile |item|. | 695 // Creates the possible links for the main profile card with profile |item|. |
726 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item | 696 - (NSView*)createCurrentProfileLinksForItem:(const AvatarMenu::Item&)item |
727 rect:(NSRect)rect; | 697 rect:(NSRect)rect; |
728 | 698 |
729 // Creates the disclaimer text for supervised users, telling them that the | 699 // Creates the disclaimer text for supervised users, telling them that the |
730 // manager can view their history etc. | 700 // manager can view their history etc. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 reauthRequired:(BOOL)reauthRequired; | 756 reauthRequired:(BOOL)reauthRequired; |
787 | 757 |
788 - (bool)shouldShowGoIncognito; | 758 - (bool)shouldShowGoIncognito; |
789 @end | 759 @end |
790 | 760 |
791 @implementation ProfileChooserController | 761 @implementation ProfileChooserController |
792 - (profiles::BubbleViewMode) viewMode { | 762 - (profiles::BubbleViewMode) viewMode { |
793 return viewMode_; | 763 return viewMode_; |
794 } | 764 } |
795 | 765 |
796 - (void)setTutorialMode:(profiles::TutorialMode)tutorialMode { | |
797 tutorialMode_ = tutorialMode; | |
798 } | |
799 | |
800 - (IBAction)editProfile:(id)sender { | 766 - (IBAction)editProfile:(id)sender { |
801 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); | 767 avatarMenu_->EditProfile(avatarMenu_->GetActiveProfileIndex()); |
802 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE]; | 768 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_IMAGE]; |
803 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; | 769 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; |
804 } | 770 } |
805 | 771 |
806 - (IBAction)switchToProfile:(id)sender { | 772 - (IBAction)switchToProfile:(id)sender { |
807 // Check the event flags to see if a new window should be created. | 773 // Check the event flags to see if a new window should be created. |
808 bool alwaysCreate = | 774 bool alwaysCreate = |
809 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]) == | 775 ui::WindowOpenDispositionFromNSEvent([NSApp currentEvent]) == |
810 WindowOpenDisposition::NEW_WINDOW; | 776 WindowOpenDisposition::NEW_WINDOW; |
811 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, | 777 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, |
812 ProfileMetrics::SWITCH_PROFILE_ICON); | 778 ProfileMetrics::SWITCH_PROFILE_ICON); |
813 } | 779 } |
814 | 780 |
815 - (IBAction)switchToGuest:(id)sender { | 781 - (IBAction)switchToGuest:(id)sender { |
816 PrefService* service = g_browser_process->local_state(); | 782 PrefService* service = g_browser_process->local_state(); |
817 DCHECK(service); | 783 DCHECK(service); |
818 DCHECK(service->GetBoolean(prefs::kBrowserGuestModeEnabled)); | 784 DCHECK(service->GetBoolean(prefs::kBrowserGuestModeEnabled)); |
819 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback()); | 785 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback()); |
820 } | 786 } |
821 | 787 |
822 - (IBAction)showUserManager:(id)sender { | 788 - (IBAction)showUserManager:(id)sender { |
823 UserManager::Show(base::FilePath(), | 789 UserManager::Show(base::FilePath(), |
824 profiles::USER_MANAGER_NO_TUTORIAL, | |
825 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 790 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
826 [self postActionPerformed: | 791 [self postActionPerformed: |
827 ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER]; | 792 ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER]; |
828 } | 793 } |
829 | 794 |
830 - (IBAction)exitGuest:(id)sender { | 795 - (IBAction)exitGuest:(id)sender { |
831 DCHECK(browser_->profile()->IsGuestSession()); | 796 DCHECK(browser_->profile()->IsGuestSession()); |
832 UserManager::Show(base::FilePath(), | 797 UserManager::Show(base::FilePath(), |
833 profiles::USER_MANAGER_NO_TUTORIAL, | |
834 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 798 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
835 profiles::CloseGuestProfileWindows(); | 799 profiles::CloseGuestProfileWindows(); |
836 } | 800 } |
837 | 801 |
838 - (IBAction)closeAllWindows:(id)sender { | 802 - (IBAction)closeAllWindows:(id)sender { |
839 profiles::CloseProfileWindows(browser_->profile()); | 803 profiles::CloseProfileWindows(browser_->profile()); |
840 } | 804 } |
841 | 805 |
842 - (IBAction)goIncognito:(id)sender { | 806 - (IBAction)goIncognito:(id)sender { |
843 DCHECK([self shouldShowGoIncognito]); | 807 DCHECK([self shouldShowGoIncognito]); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 - (IBAction)removeAccount:(id)sender { | 898 - (IBAction)removeAccount:(id)sender { |
935 DCHECK(!accountIdToRemove_.empty()); | 899 DCHECK(!accountIdToRemove_.empty()); |
936 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()) | 900 ProfileOAuth2TokenServiceFactory::GetForProfile(browser_->profile()) |
937 ->RevokeCredentials(accountIdToRemove_); | 901 ->RevokeCredentials(accountIdToRemove_); |
938 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT]; | 902 [self postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_REMOVE_ACCT]; |
939 accountIdToRemove_.clear(); | 903 accountIdToRemove_.clear(); |
940 | 904 |
941 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 905 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
942 } | 906 } |
943 | 907 |
944 - (IBAction)seeWhatsNew:(id)sender { | |
945 UserManager::Show(base::FilePath(), | |
946 profiles::USER_MANAGER_TUTORIAL_OVERVIEW, | |
947 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | |
948 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | |
949 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_WHATS_NEW); | |
950 } | |
951 | |
952 - (IBAction)showSwitchUserView:(id)sender { | 908 - (IBAction)showSwitchUserView:(id)sender { |
953 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_SWITCH_USER]; | 909 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_SWITCH_USER]; |
954 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | 910 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( |
955 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU); | 911 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_NOT_YOU); |
956 } | 912 } |
957 | 913 |
958 - (IBAction)showLearnMorePage:(id)sender { | 914 - (IBAction)showLearnMorePage:(id)sender { |
959 signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); | 915 signin_ui_util::ShowSigninErrorLearnMorePage(browser_->profile()); |
960 } | 916 } |
961 | 917 |
962 - (IBAction)configureSyncSettings:(id)sender { | 918 - (IBAction)configureSyncSettings:(id)sender { |
963 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
964 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 919 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
965 SyncConfirmationUIClosed(LoginUIService::CONFIGURE_SYNC_FIRST); | 920 SyncConfirmationUIClosed(LoginUIService::CONFIGURE_SYNC_FIRST); |
966 ProfileMetrics::LogProfileNewAvatarMenuSignin( | 921 ProfileMetrics::LogProfileNewAvatarMenuSignin( |
967 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS); | 922 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_SETTINGS); |
968 } | 923 } |
969 | 924 |
970 - (IBAction)syncSettingsConfirmed:(id)sender { | 925 - (IBAction)syncSettingsConfirmed:(id)sender { |
971 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
972 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 926 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
973 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | 927 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); |
974 ProfileMetrics::LogProfileNewAvatarMenuSignin( | 928 ProfileMetrics::LogProfileNewAvatarMenuSignin( |
975 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_OK); | 929 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_OK); |
976 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 930 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
977 } | 931 } |
978 | 932 |
979 - (IBAction)disconnectProfile:(id)sender { | 933 - (IBAction)disconnectProfile:(id)sender { |
980 chrome::ShowSettings(browser_); | 934 chrome::ShowSettings(browser_); |
981 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 935 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
982 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); | 936 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_DISCONNECT); |
983 } | 937 } |
984 | 938 |
985 - (IBAction)navigateBackFromSwitchUserView:(id)sender { | 939 - (IBAction)navigateBackFromSwitchUserView:(id)sender { |
986 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 940 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
987 ProfileMetrics::LogProfileNewAvatarMenuNotYou( | 941 ProfileMetrics::LogProfileNewAvatarMenuNotYou( |
988 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK); | 942 ProfileMetrics::PROFILE_AVATAR_MENU_NOT_YOU_BACK); |
989 } | 943 } |
990 | 944 |
991 - (IBAction)dismissTutorial:(id)sender { | |
992 // Never shows the upgrade tutorial again if manually closed. | |
993 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | |
994 browser_->profile()->GetPrefs()->SetInteger( | |
995 prefs::kProfileAvatarTutorialShown, | |
996 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | |
997 } | |
998 | |
999 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
1000 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | |
1001 } | |
1002 | |
1003 - (void)windowWillClose:(NSNotification*)notification { | 945 - (void)windowWillClose:(NSNotification*)notification { |
1004 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { | |
1005 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | |
1006 SyncConfirmationUIClosed(LoginUIService::SYNC_WITH_DEFAULT_SETTINGS); | |
1007 } | |
1008 | |
1009 [super windowWillClose:notification]; | 946 [super windowWillClose:notification]; |
1010 } | 947 } |
1011 | 948 |
1012 - (void)moveDown:(id)sender { | 949 - (void)moveDown:(id)sender { |
1013 [[self window] selectNextKeyView:self]; | 950 [[self window] selectNextKeyView:self]; |
1014 } | 951 } |
1015 | 952 |
1016 - (void)moveUp:(id)sender { | 953 - (void)moveUp:(id)sender { |
1017 [[self window] selectPreviousKeyView:self]; | 954 [[self window] selectPreviousKeyView:self]; |
1018 } | 955 } |
1019 | 956 |
1020 - (void)cleanUpEmbeddedViewContents { | 957 - (void)cleanUpEmbeddedViewContents { |
1021 webContents_.reset(); | 958 webContents_.reset(); |
1022 webContentsDelegate_.reset(); | 959 webContentsDelegate_.reset(); |
1023 } | 960 } |
1024 | 961 |
1025 - (id)initWithBrowser:(Browser*)browser | 962 - (id)initWithBrowser:(Browser*)browser |
1026 anchoredAt:(NSPoint)point | 963 anchoredAt:(NSPoint)point |
1027 viewMode:(profiles::BubbleViewMode)viewMode | 964 viewMode:(profiles::BubbleViewMode)viewMode |
1028 tutorialMode:(profiles::TutorialMode)tutorialMode | |
1029 serviceType:(signin::GAIAServiceType)serviceType | 965 serviceType:(signin::GAIAServiceType)serviceType |
1030 accessPoint:(signin_metrics::AccessPoint)accessPoint { | 966 accessPoint:(signin_metrics::AccessPoint)accessPoint { |
1031 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] | 967 base::scoped_nsobject<InfoBubbleWindow> window([[InfoBubbleWindow alloc] |
1032 initWithContentRect:ui::kWindowSizeDeterminedLater | 968 initWithContentRect:ui::kWindowSizeDeterminedLater |
1033 styleMask:NSBorderlessWindowMask | 969 styleMask:NSBorderlessWindowMask |
1034 backing:NSBackingStoreBuffered | 970 backing:NSBackingStoreBuffered |
1035 defer:NO]); | 971 defer:NO]); |
1036 | 972 |
1037 if ((self = [super initWithWindow:window | 973 if ((self = [super initWithWindow:window |
1038 parentWindow:browser->window()->GetNativeWindow() | 974 parentWindow:browser->window()->GetNativeWindow() |
1039 anchoredAt:point])) { | 975 anchoredAt:point])) { |
1040 browser_ = browser; | 976 browser_ = browser; |
1041 viewMode_ = viewMode; | 977 viewMode_ = viewMode; |
1042 tutorialMode_ = tutorialMode; | |
1043 observer_.reset(new ActiveProfileObserverBridge(self, browser_)); | 978 observer_.reset(new ActiveProfileObserverBridge(self, browser_)); |
1044 serviceType_ = serviceType; | 979 serviceType_ = serviceType; |
1045 accessPoint_ = accessPoint; | 980 accessPoint_ = accessPoint; |
1046 | 981 |
1047 avatarMenu_.reset(new AvatarMenu( | 982 avatarMenu_.reset(new AvatarMenu( |
1048 &g_browser_process->profile_manager()->GetProfileAttributesStorage(), | 983 &g_browser_process->profile_manager()->GetProfileAttributesStorage(), |
1049 observer_.get(), | 984 observer_.get(), |
1050 browser_)); | 985 browser_)); |
1051 avatarMenu_->RebuildMenu(); | 986 avatarMenu_->RebuildMenu(); |
1052 | 987 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1107 break; | 1042 break; |
1108 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: | 1043 case profiles::BUBBLE_VIEW_MODE_SWITCH_USER: |
1109 subView = [self buildSwitchUserView]; | 1044 subView = [self buildSwitchUserView]; |
1110 break; | 1045 break; |
1111 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: | 1046 case profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER: |
1112 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: | 1047 case profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT: |
1113 subView = [self buildProfileChooserView]; | 1048 subView = [self buildProfileChooserView]; |
1114 break; | 1049 break; |
1115 } | 1050 } |
1116 | 1051 |
1117 // Clears tutorial mode for all non-profile-chooser views. | |
1118 if (viewMode_ != profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) | |
1119 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
1120 | |
1121 // Add a dummy, empty element so that we don't initially display any | 1052 // Add a dummy, empty element so that we don't initially display any |
1122 // focus rings. | 1053 // focus rings. |
1123 NSButton* dummyFocusButton = | 1054 NSButton* dummyFocusButton = |
1124 [[[DummyWindowFocusButton alloc] initWithFrame:NSZeroRect] autorelease]; | 1055 [[[DummyWindowFocusButton alloc] initWithFrame:NSZeroRect] autorelease]; |
1125 [dummyFocusButton setNextKeyView:subView]; | 1056 [dummyFocusButton setNextKeyView:subView]; |
1126 [[self window] makeFirstResponder:dummyFocusButton]; | 1057 [[self window] makeFirstResponder:dummyFocusButton]; |
1127 | 1058 |
1128 [contentView addSubview:subView]; | 1059 [contentView addSubview:subView]; |
1129 [contentView addSubview:dummyFocusButton]; | 1060 [contentView addSubview:dummyFocusButton]; |
1130 SetWindowSize([self window], | 1061 SetWindowSize([self window], |
(...skipping 20 matching lines...) Expand all Loading... |
1151 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1082 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
1152 [container addSubview:otherProfileView]; | 1083 [container addSubview:otherProfileView]; |
1153 yOffset = NSMaxY([otherProfileView frame]); | 1084 yOffset = NSMaxY([otherProfileView frame]); |
1154 } | 1085 } |
1155 | 1086 |
1156 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | 1087 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
1157 return yOffset; | 1088 return yOffset; |
1158 } | 1089 } |
1159 | 1090 |
1160 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 1091 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
1161 tutorialView:(NSView*)tutorialView | |
1162 syncErrorView:(NSView*)syncErrorView | 1092 syncErrorView:(NSView*)syncErrorView |
1163 otherProfiles:(NSArray*)otherProfiles | 1093 otherProfiles:(NSArray*)otherProfiles |
1164 atYOffset:(CGFloat)yOffset | 1094 atYOffset:(CGFloat)yOffset |
1165 inContainer:(NSView*)container | 1095 inContainer:(NSView*)container |
1166 showLock:(bool)showLock { | 1096 showLock:(bool)showLock { |
1167 yOffset += kRelatedControllVerticalSpacing; | 1097 yOffset += kRelatedControllVerticalSpacing; |
1168 | 1098 |
1169 // Option buttons. | 1099 // Option buttons. |
1170 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); | 1100 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); |
1171 NSView* optionsView = | 1101 NSView* optionsView = |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1222 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; | 1152 yOffset = NSMaxY([currentProfileView frame]) + verticalSpacing; |
1223 } | 1153 } |
1224 | 1154 |
1225 if (syncErrorView) { | 1155 if (syncErrorView) { |
1226 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | 1156 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; |
1227 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1157 [syncErrorView setFrameOrigin:NSMakePoint(0, yOffset)]; |
1228 [container addSubview:syncErrorView]; | 1158 [container addSubview:syncErrorView]; |
1229 yOffset = NSMaxY([syncErrorView frame]); | 1159 yOffset = NSMaxY([syncErrorView frame]); |
1230 } | 1160 } |
1231 | 1161 |
1232 if (tutorialView) { | |
1233 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1234 [container addSubview:tutorialView]; | |
1235 yOffset = NSMaxY([tutorialView frame]); | |
1236 //TODO(mlerman): update UMA stats for the new tutorials. | |
1237 } else { | |
1238 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
1239 } | |
1240 | |
1241 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | 1162 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
1242 } | 1163 } |
1243 | 1164 |
1244 - (NSView*)buildProfileChooserView { | 1165 - (NSView*)buildProfileChooserView { |
1245 base::scoped_nsobject<NSView> container( | 1166 base::scoped_nsobject<NSView> container( |
1246 [[NSView alloc] initWithFrame:NSZeroRect]); | 1167 [[NSView alloc] initWithFrame:NSZeroRect]); |
1247 | 1168 |
1248 NSView* tutorialView = nil; | |
1249 NSView* syncErrorView = nil; | 1169 NSView* syncErrorView = nil; |
1250 NSView* currentProfileView = nil; | 1170 NSView* currentProfileView = nil; |
1251 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1171 base::scoped_nsobject<NSMutableArray> otherProfiles( |
1252 [[NSMutableArray alloc] init]); | 1172 [[NSMutableArray alloc] init]); |
1253 // Local and guest profiles cannot lock their profile. | 1173 // Local and guest profiles cannot lock their profile. |
1254 bool showLock = false; | 1174 bool showLock = false; |
1255 | 1175 |
1256 // Loop over the profiles in reverse, so that they are sorted by their | 1176 // Loop over the profiles in reverse, so that they are sorted by their |
1257 // y-coordinate, and separate them into active and "other" profiles. | 1177 // y-coordinate, and separate them into active and "other" profiles. |
1258 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1178 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
(...skipping 10 matching lines...) Expand all Loading... |
1269 firstProfileView_ = [otherProfiles lastObject]; | 1189 firstProfileView_ = [otherProfiles lastObject]; |
1270 if (!currentProfileView) // Guest windows don't have an active profile. | 1190 if (!currentProfileView) // Guest windows don't have an active profile. |
1271 currentProfileView = [self createGuestProfileView]; | 1191 currentProfileView = [self createGuestProfileView]; |
1272 | 1192 |
1273 // |yOffset| is the next position at which to draw in |container| | 1193 // |yOffset| is the next position at which to draw in |container| |
1274 // coordinates. Add a pixel offset so that the bottom option buttons don't | 1194 // coordinates. Add a pixel offset so that the bottom option buttons don't |
1275 // overlap the bubble's rounded corners. | 1195 // overlap the bubble's rounded corners. |
1276 CGFloat yOffset = 1; | 1196 CGFloat yOffset = 1; |
1277 | 1197 |
1278 [self buildProfileChooserViewWithProfileView:currentProfileView | 1198 [self buildProfileChooserViewWithProfileView:currentProfileView |
1279 tutorialView:tutorialView | |
1280 syncErrorView:syncErrorView | 1199 syncErrorView:syncErrorView |
1281 otherProfiles:otherProfiles.get() | 1200 otherProfiles:otherProfiles.get() |
1282 atYOffset:yOffset | 1201 atYOffset:yOffset |
1283 inContainer:container | 1202 inContainer:container |
1284 showLock:showLock]; | 1203 showLock:showLock]; |
1285 return container.autorelease(); | 1204 return container.autorelease(); |
1286 } | 1205 } |
1287 | 1206 |
1288 - (NSView*)buildSigninConfirmationView { | |
1289 ProfileMetrics::LogProfileNewAvatarMenuSignin( | |
1290 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); | |
1291 | |
1292 NSString* titleMessage = l10n_util::GetNSString( | |
1293 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); | |
1294 NSString* contentMessage = l10n_util::GetNSString( | |
1295 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_CONTENT_TEXT); | |
1296 NSString* linkMessage = l10n_util::GetNSString( | |
1297 IDS_PROFILES_SYNC_SETTINGS_LINK); | |
1298 NSString* buttonMessage = l10n_util::GetNSString( | |
1299 IDS_PROFILES_TUTORIAL_OK_BUTTON); | |
1300 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_CONFIRM_SIGNIN | |
1301 titleMessage:titleMessage | |
1302 contentMessage:contentMessage | |
1303 linkMessage:linkMessage | |
1304 buttonMessage:buttonMessage | |
1305 stackButton:NO | |
1306 hasCloseButton:NO | |
1307 linkAction:@selector(configureSyncSettings:) | |
1308 buttonAction:@selector(syncSettingsConfirmed:)]; | |
1309 } | |
1310 | |
1311 - (NSView*)buildSigninErrorView { | |
1312 NSString* titleMessage = l10n_util::GetNSString( | |
1313 IDS_PROFILES_ERROR_TUTORIAL_TITLE); | |
1314 LoginUIService* loginUiService = | |
1315 LoginUIServiceFactory::GetForProfile(browser_->profile()); | |
1316 NSString* contentMessage = | |
1317 base::SysUTF16ToNSString(loginUiService->GetLastLoginResult()); | |
1318 NSString* linkMessage = l10n_util::GetNSString( | |
1319 IDS_PROFILES_PROFILE_TUTORIAL_LEARN_MORE); | |
1320 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_CONFIRM_SIGNIN | |
1321 titleMessage:titleMessage | |
1322 contentMessage:contentMessage | |
1323 linkMessage:linkMessage | |
1324 buttonMessage:nil | |
1325 stackButton:NO | |
1326 hasCloseButton:YES | |
1327 linkAction:@selector(showLearnMorePage:) | |
1328 buttonAction:nil]; | |
1329 } | |
1330 | |
1331 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { | |
1332 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | |
1333 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); | |
1334 | |
1335 NSString* titleMessage = l10n_util::GetNSString( | |
1336 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); | |
1337 NSString* contentMessage = l10n_util::GetNSString( | |
1338 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); | |
1339 // For local profiles, the "Not you" link doesn't make sense. | |
1340 NSString* linkMessage = | |
1341 item.signed_in ? ElideMessage(l10n_util::GetStringFUTF16( | |
1342 IDS_PROFILES_NOT_YOU, item.name), | |
1343 kFixedMenuWidth - 2 * kHorizontalSpacing) | |
1344 : nil; | |
1345 NSString* buttonMessage = l10n_util::GetNSString( | |
1346 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); | |
1347 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE | |
1348 titleMessage:titleMessage | |
1349 contentMessage:contentMessage | |
1350 linkMessage:linkMessage | |
1351 buttonMessage:buttonMessage | |
1352 stackButton:YES | |
1353 hasCloseButton:YES | |
1354 linkAction:@selector(showSwitchUserView:) | |
1355 buttonAction:@selector(seeWhatsNew:)]; | |
1356 } | |
1357 | |
1358 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | |
1359 titleMessage:(NSString*)titleMessage | |
1360 contentMessage:(NSString*)contentMessage | |
1361 linkMessage:(NSString*)linkMessage | |
1362 buttonMessage:(NSString*)buttonMessage | |
1363 stackButton:(BOOL)stackButton | |
1364 hasCloseButton:(BOOL)hasCloseButton | |
1365 linkAction:(SEL)linkAction | |
1366 buttonAction:(SEL)buttonAction { | |
1367 tutorialMode_ = mode; | |
1368 | |
1369 NSColor* tutorialBackgroundColor = | |
1370 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialBackgroundColor); | |
1371 base::scoped_nsobject<NSView> container([[BackgroundColorView alloc] | |
1372 initWithFrame:NSMakeRect(0, 0, kFixedMenuWidth, 0) | |
1373 withColor:tutorialBackgroundColor]); | |
1374 CGFloat availableWidth = kFixedMenuWidth - 2 * kHorizontalSpacing; | |
1375 CGFloat yOffset = kVerticalSpacing; | |
1376 | |
1377 // Adds links and buttons at the bottom. | |
1378 base::scoped_nsobject<NSButton> tutorialOkButton; | |
1379 if (buttonMessage) { | |
1380 tutorialOkButton.reset([[HoverButton alloc] initWithFrame:NSZeroRect]); | |
1381 [tutorialOkButton setTitle:buttonMessage]; | |
1382 [tutorialOkButton setBezelStyle:NSRoundedBezelStyle]; | |
1383 [tutorialOkButton setTarget:self]; | |
1384 [tutorialOkButton setAction:buttonAction]; | |
1385 [tutorialOkButton setAlignment:NSCenterTextAlignment]; | |
1386 [tutorialOkButton sizeToFit]; | |
1387 } | |
1388 | |
1389 NSButton* learnMoreLink = nil; | |
1390 if (linkMessage) { | |
1391 learnMoreLink = [self linkButtonWithTitle:linkMessage | |
1392 frameOrigin:NSZeroPoint | |
1393 action:linkAction]; | |
1394 [[learnMoreLink cell] setTextColor:[NSColor whiteColor]]; | |
1395 } | |
1396 | |
1397 if (stackButton) { | |
1398 [learnMoreLink setFrameOrigin:NSMakePoint((kFixedMenuWidth - | |
1399 NSWidth([learnMoreLink frame])) / | |
1400 2, | |
1401 yOffset)]; | |
1402 [tutorialOkButton setFrameSize:NSMakeSize( | |
1403 availableWidth, NSHeight([tutorialOkButton frame]))]; | |
1404 [tutorialOkButton setFrameOrigin:NSMakePoint( | |
1405 kHorizontalSpacing, | |
1406 yOffset + (learnMoreLink ? NSHeight([learnMoreLink frame]) : 0))]; | |
1407 } else { | |
1408 if (buttonMessage) { | |
1409 NSSize buttonSize = [tutorialOkButton frame].size; | |
1410 const CGFloat kTopBottomTextPadding = 6; | |
1411 const CGFloat kLeftRightTextPadding = 15; | |
1412 buttonSize.width += 2 * kLeftRightTextPadding; | |
1413 buttonSize.height += 2 * kTopBottomTextPadding; | |
1414 [tutorialOkButton setFrameSize:buttonSize]; | |
1415 CGFloat buttonXOffset = kFixedMenuWidth - | |
1416 NSWidth([tutorialOkButton frame]) - | |
1417 kHorizontalSpacing; | |
1418 [tutorialOkButton setFrameOrigin:NSMakePoint(buttonXOffset, yOffset)]; | |
1419 } | |
1420 | |
1421 if (linkMessage) { | |
1422 CGFloat linkYOffset = yOffset; | |
1423 if (buttonMessage) { | |
1424 linkYOffset += (NSHeight([tutorialOkButton frame]) - | |
1425 NSHeight([learnMoreLink frame])) / 2; | |
1426 } | |
1427 [learnMoreLink setFrameOrigin:NSMakePoint( | |
1428 kHorizontalSpacing, linkYOffset)]; | |
1429 } | |
1430 } | |
1431 | |
1432 if (buttonMessage) { | |
1433 [container addSubview:tutorialOkButton]; | |
1434 yOffset = NSMaxY([tutorialOkButton frame]); | |
1435 } | |
1436 | |
1437 if (linkMessage) { | |
1438 [container addSubview:learnMoreLink]; | |
1439 yOffset = std::max(NSMaxY([learnMoreLink frame]), yOffset); | |
1440 } | |
1441 | |
1442 yOffset += kVerticalSpacing; | |
1443 | |
1444 // Adds body content. | |
1445 NSTextField* contentLabel = BuildLabel( | |
1446 contentMessage, | |
1447 NSMakePoint(kHorizontalSpacing, yOffset), | |
1448 skia::SkColorToSRGBNSColor(profiles::kAvatarTutorialContentTextColor)); | |
1449 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | |
1450 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; | |
1451 [container addSubview:contentLabel]; | |
1452 yOffset = NSMaxY([contentLabel frame]) + kSmallVerticalSpacing; | |
1453 | |
1454 // Adds title. | |
1455 NSTextField* titleLabel = | |
1456 BuildLabel(titleMessage, | |
1457 NSMakePoint(kHorizontalSpacing, yOffset), | |
1458 [NSColor whiteColor] /* text_color */); | |
1459 [titleLabel setFont:[NSFont labelFontOfSize:kTitleFontSize]]; | |
1460 | |
1461 if (hasCloseButton) { | |
1462 base::scoped_nsobject<HoverImageButton> closeButton( | |
1463 [[HoverImageButton alloc] initWithFrame:NSZeroRect]); | |
1464 [closeButton setBordered:NO]; | |
1465 | |
1466 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
1467 NSImage* closeImage = rb->GetNativeImageNamed(IDR_CLOSE_1).ToNSImage(); | |
1468 CGFloat closeImageWidth = [closeImage size].width; | |
1469 [closeButton setDefaultImage:closeImage]; | |
1470 [closeButton setHoverImage: | |
1471 rb->GetNativeImageNamed(IDR_CLOSE_1_H).ToNSImage()]; | |
1472 [closeButton setPressedImage: | |
1473 rb->GetNativeImageNamed(IDR_CLOSE_1_P).ToNSImage()]; | |
1474 [closeButton setTarget:self]; | |
1475 [closeButton setAction:@selector(dismissTutorial:)]; | |
1476 [closeButton setFrameSize:[closeImage size]]; | |
1477 [closeButton | |
1478 setFrameOrigin:NSMakePoint(kFixedMenuWidth - kHorizontalSpacing - | |
1479 closeImageWidth, | |
1480 yOffset)]; | |
1481 [container addSubview:closeButton]; | |
1482 | |
1483 [titleLabel setFrameSize:NSMakeSize( | |
1484 availableWidth - closeImageWidth - kHorizontalSpacing, 0)]; | |
1485 } else { | |
1486 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | |
1487 } | |
1488 | |
1489 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; | |
1490 [container addSubview:titleLabel]; | |
1491 yOffset = NSMaxY([titleLabel frame]) + kVerticalSpacing; | |
1492 | |
1493 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | |
1494 [container setFrameOrigin:NSZeroPoint]; | |
1495 return container.autorelease(); | |
1496 } | |
1497 | |
1498 - (NSView*)buildSyncErrorViewIfNeeded { | 1207 - (NSView*)buildSyncErrorViewIfNeeded { |
1499 int contentStringId, buttonStringId; | 1208 int contentStringId, buttonStringId; |
1500 SEL buttonAction; | 1209 SEL buttonAction; |
1501 sync_ui_util::AvatarSyncErrorType error = | 1210 sync_ui_util::AvatarSyncErrorType error = |
1502 sync_ui_util::GetMessagesForAvatarSyncError( | 1211 sync_ui_util::GetMessagesForAvatarSyncError( |
1503 browser_->profile(), &contentStringId, &buttonStringId); | 1212 browser_->profile(), &contentStringId, &buttonStringId); |
1504 switch (error) { | 1213 switch (error) { |
1505 case sync_ui_util::MANAGED_USER_UNRECOVERABLE_ERROR: | 1214 case sync_ui_util::MANAGED_USER_UNRECOVERABLE_ERROR: |
1506 buttonAction = @selector(showSignoutView:); | 1215 buttonAction = @selector(showSignoutView:); |
1507 break; | 1216 break; |
(...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2400 | 2109 |
2401 - (void)showWindow:(id)sender { | 2110 - (void)showWindow:(id)sender { |
2402 [super showWindow:sender]; | 2111 [super showWindow:sender]; |
2403 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2112 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
2404 if (firstProfileView_ && [event type] == NSKeyDown) { | 2113 if (firstProfileView_ && [event type] == NSKeyDown) { |
2405 [[self window] makeFirstResponder:firstProfileView_]; | 2114 [[self window] makeFirstResponder:firstProfileView_]; |
2406 } | 2115 } |
2407 } | 2116 } |
2408 | 2117 |
2409 @end | 2118 @end |
OLD | NEW |