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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
871 - (BOOL)canBecomeKeyView { | 871 - (BOOL)canBecomeKeyView { |
872 return NO; | 872 return NO; |
873 } | 873 } |
874 | 874 |
875 @end | 875 @end |
876 | 876 |
877 @interface ProfileChooserController () | 877 @interface ProfileChooserController () |
878 // Builds the profile chooser view. | 878 // Builds the profile chooser view. |
879 - (NSView*)buildProfileChooserView; | 879 - (NSView*)buildProfileChooserView; |
880 | 880 |
881 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; | |
882 | |
881 // Builds a tutorial card with a title label using |titleMessage|, a content | 883 // Builds a tutorial card with a title label using |titleMessage|, a content |
882 // label using |contentMessage|, a link using |linkMessage|, and a button using | 884 // label using |contentMessage|, a link using |linkMessage|, and a button using |
883 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | 885 // |buttonMessage|. If |stackButton| is YES, places the button above the link. |
884 // Otherwise places both on the same row with the link left aligned and button | 886 // Otherwise places both on the same row with the link left aligned and button |
885 // right aligned. On click, the link would execute |linkAction|, and the button | 887 // right aligned. On click, the link would execute |linkAction|, and the button |
886 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. | 888 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. |
887 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 889 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
888 titleMessage:(NSString*)titleMessage | 890 titleMessage:(NSString*)titleMessage |
889 contentMessage:(NSString*)contentMessage | 891 contentMessage:(NSString*)contentMessage |
890 linkMessage:(NSString*)linkMessage | 892 linkMessage:(NSString*)linkMessage |
891 buttonMessage:(NSString*)buttonMessage | 893 buttonMessage:(NSString*)buttonMessage |
892 stackButton:(BOOL)stackButton | 894 stackButton:(BOOL)stackButton |
893 hasCloseButton:(BOOL)hasCloseButton | 895 hasCloseButton:(BOOL)hasCloseButton |
894 linkAction:(SEL)linkAction | 896 linkAction:(SEL)linkAction |
895 buttonAction:(SEL)buttonAction; | 897 buttonAction:(SEL)buttonAction; |
896 | 898 |
899 // Returns YES if the Welcome/Upgrade tutorial bubble should be shown to the | |
900 // user, NO otherwise. | |
901 - (BOOL)shouldShowWelcomeUpgradeTutorial; | |
902 | |
903 // Returns YES if the tutorial informing the user about right-click user | |
904 // switching should be shown, NO otherwise. | |
905 - (BOOL)shouldShowRightClickTutorialView; | |
906 | |
897 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if | 907 // Builds a tutorial card to introduce an upgrade user to the new avatar menu if |
898 // needed. |tutorial_shown| indicates if the tutorial has already been shown in | 908 // needed. |tutorial_shown| indicates if the tutorial has already been shown in |
899 // the previous active view. |avatar_item| refers to the current profile. | 909 // the previous active view. |avatar_item| refers to the current profile. |
900 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded; | 910 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item; |
911 | |
912 // Builds a tutorial card to inform the user about right-click user switching if | |
913 // needed. | |
914 - (NSView*)buildRightClickTutorialView; | |
901 | 915 |
902 // Builds a tutorial card to have the user confirm the last Chrome signin, | 916 // Builds a tutorial card to have the user confirm the last Chrome signin, |
903 // Chrome sync will be delayed until the user either dismisses the tutorial, or | 917 // Chrome sync will be delayed until the user either dismisses the tutorial, or |
904 // configures sync through the "Settings" link. | 918 // configures sync through the "Settings" link. |
905 - (NSView*)buildSigninConfirmationView; | 919 - (NSView*)buildSigninConfirmationView; |
906 | 920 |
907 // Builds a tutorial card to show the last signin error. | 921 // Builds a tutorial card to show the last signin error. |
908 - (NSView*)buildSigninErrorView; | 922 - (NSView*)buildSigninErrorView; |
909 | 923 |
910 // Creates the main profile card for the profile |item| at the top of | 924 // Creates the main profile card for the profile |item| at the top of |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1122 } | 1136 } |
1123 | 1137 |
1124 - (IBAction)dismissTutorial:(id)sender { | 1138 - (IBAction)dismissTutorial:(id)sender { |
1125 // Never shows the upgrade tutorial again if manually closed. | 1139 // Never shows the upgrade tutorial again if manually closed. |
1126 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1140 if (tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { |
1127 browser_->profile()->GetPrefs()->SetInteger( | 1141 browser_->profile()->GetPrefs()->SetInteger( |
1128 prefs::kProfileAvatarTutorialShown, | 1142 prefs::kProfileAvatarTutorialShown, |
1129 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); | 1143 signin_ui_util::kUpgradeWelcomeTutorialShowMax + 1); |
1130 } | 1144 } |
1131 | 1145 |
1146 if(tutorialMode_ == profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING) { | |
1147 PrefService* localState = g_browser_process->local_state(); | |
1148 localState->SetBoolean( | |
1149 prefs::kProfileAvatarRightClickTutorialDismissed, true); | |
1150 } | |
1151 | |
1132 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | 1152 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
1133 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; | 1153 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER]; |
1134 } | 1154 } |
1135 | 1155 |
1136 - (void)windowWillClose:(NSNotification*)notification { | 1156 - (void)windowWillClose:(NSNotification*)notification { |
1137 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { | 1157 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) { |
1138 LoginUIServiceFactory::GetForProfile(browser_->profile())-> | 1158 LoginUIServiceFactory::GetForProfile(browser_->profile())-> |
1139 SyncConfirmationUIClosed(false); | 1159 SyncConfirmationUIClosed(false); |
1140 } | 1160 } |
1141 | 1161 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1263 [[NSView alloc] initWithFrame:NSZeroRect]); | 1283 [[NSView alloc] initWithFrame:NSZeroRect]); |
1264 | 1284 |
1265 NSView* tutorialView = nil; | 1285 NSView* tutorialView = nil; |
1266 NSView* currentProfileView = nil; | 1286 NSView* currentProfileView = nil; |
1267 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1287 base::scoped_nsobject<NSMutableArray> otherProfiles( |
1268 [[NSMutableArray alloc] init]); | 1288 [[NSMutableArray alloc] init]); |
1269 // Local and guest profiles cannot lock their profile. | 1289 // Local and guest profiles cannot lock their profile. |
1270 bool displayLock = false; | 1290 bool displayLock = false; |
1271 bool isFastProfileChooser = | 1291 bool isFastProfileChooser = |
1272 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; | 1292 viewMode_ == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER; |
1293 if (isFastProfileChooser) { | |
1294 // The user is using right-click switching, no need to tell them about it. | |
1295 PrefService* localState = g_browser_process->local_state(); | |
1296 localState->SetBoolean( | |
1297 prefs::kProfileAvatarRightClickTutorialDismissed, true); | |
1298 } | |
1273 | 1299 |
1274 // Loop over the profiles in reverse, so that they are sorted by their | 1300 // Loop over the profiles in reverse, so that they are sorted by their |
1275 // y-coordinate, and separate them into active and "other" profiles. | 1301 // y-coordinate, and separate them into active and "other" profiles. |
1276 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { | 1302 for (int i = avatarMenu_->GetNumberOfItems() - 1; i >= 0; --i) { |
1277 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); | 1303 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(i); |
1278 if (item.active) { | 1304 if (item.active) { |
1279 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { | 1305 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER) { |
1280 switch (tutorialMode_) { | 1306 tutorialView = [self buildTutorialViewIfNeededForItem:item]; |
1281 case profiles::TUTORIAL_MODE_NONE: | |
1282 case profiles::TUTORIAL_MODE_WELCOME_UPGRADE: | |
1283 tutorialView = | |
1284 [self buildWelcomeUpgradeTutorialViewIfNeeded]; | |
1285 break; | |
1286 case profiles::TUTORIAL_MODE_CONFIRM_SIGNIN: | |
1287 tutorialView = [self buildSigninConfirmationView]; | |
1288 break; | |
1289 case profiles::TUTORIAL_MODE_SHOW_ERROR: | |
1290 tutorialView = [self buildSigninErrorView]; | |
1291 } | |
1292 } | 1307 } |
1293 currentProfileView = [self createCurrentProfileView:item]; | 1308 currentProfileView = [self createCurrentProfileView:item]; |
1294 displayLock = item.signed_in && | 1309 displayLock = item.signed_in && |
1295 profiles::IsLockAvailable(browser_->profile()); | 1310 profiles::IsLockAvailable(browser_->profile()); |
1296 } else { | 1311 } else { |
1297 [otherProfiles addObject:[self createOtherProfileView:i]]; | 1312 [otherProfiles addObject:[self createOtherProfileView:i]]; |
1298 } | 1313 } |
1299 } | 1314 } |
1300 if (!currentProfileView) // Guest windows don't have an active profile. | 1315 if (!currentProfileView) // Guest windows don't have an active profile. |
1301 currentProfileView = [self createGuestProfileView]; | 1316 currentProfileView = [self createGuestProfileView]; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1418 titleMessage:titleMessage | 1433 titleMessage:titleMessage |
1419 contentMessage:contentMessage | 1434 contentMessage:contentMessage |
1420 linkMessage:linkMessage | 1435 linkMessage:linkMessage |
1421 buttonMessage:nil | 1436 buttonMessage:nil |
1422 stackButton:NO | 1437 stackButton:NO |
1423 hasCloseButton:YES | 1438 hasCloseButton:YES |
1424 linkAction:@selector(showLearnMorePage:) | 1439 linkAction:@selector(showLearnMorePage:) |
1425 buttonAction:nil]; | 1440 buttonAction:nil]; |
1426 } | 1441 } |
1427 | 1442 |
1428 - (NSView*)buildWelcomeUpgradeTutorialViewIfNeeded { | 1443 - (BOOL)shouldShowWelcomeUpgradeTutorial { |
1429 Profile* profile = browser_->profile(); | 1444 Profile* profile = browser_->profile(); |
1430 const AvatarMenu::Item& avatarItem = | |
1431 avatarMenu_->GetItemAt(avatarMenu_->GetActiveProfileIndex()); | |
1432 | 1445 |
1433 const int showCount = profile->GetPrefs()->GetInteger( | 1446 const int showCount = profile->GetPrefs()->GetInteger( |
1434 prefs::kProfileAvatarTutorialShown); | 1447 prefs::kProfileAvatarTutorialShown); |
1435 // Do not show the tutorial if user has dismissed it. | 1448 // Do not show the tutorial if user has dismissed it. |
1436 if (showCount > signin_ui_util::kUpgradeWelcomeTutorialShowMax) | 1449 if (showCount > signin_ui_util::kUpgradeWelcomeTutorialShowMax) |
1437 return nil; | 1450 return NO; |
1438 | 1451 |
1439 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | 1452 return tutorialMode_ == profiles::TUTORIAL_MODE_WELCOME_UPGRADE || |
groby-ooo-7-16
2015/05/07 01:59:01
That's returning a bool, not BOOL. Since you neve
anthonyvd
2015/05/12 16:09:11
Thanks! Done.
| |
1440 if (showCount == signin_ui_util::kUpgradeWelcomeTutorialShowMax) | 1453 showCount != signin_ui_util::kUpgradeWelcomeTutorialShowMax; |
1441 return nil; | 1454 } |
1442 profile->GetPrefs()->SetInteger( | |
1443 prefs::kProfileAvatarTutorialShown, showCount + 1); | |
1444 } | |
1445 | 1455 |
1456 - (BOOL)shouldShowRightClickTutorialView { | |
1457 PrefService* localState = g_browser_process->local_state(); | |
1458 const bool dismissed = localState->GetBoolean( | |
1459 prefs::kProfileAvatarRightClickTutorialDismissed); | |
1460 | |
1461 // Don't show the tutorial if it's already been dismissed or if right-clicking | |
1462 // wouldn't show any targets. | |
1463 return !dismissed && profiles::HasProfileSwitchTargets(browser_->profile()); | |
1464 } | |
1465 | |
1466 - (NSView*)buildWelcomeUpgradeTutorialView:(const AvatarMenu::Item&)item { | |
1446 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( | 1467 ProfileMetrics::LogProfileNewAvatarMenuUpgrade( |
1447 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); | 1468 ProfileMetrics::PROFILE_AVATAR_MENU_UPGRADE_VIEW); |
1448 | 1469 |
1449 NSString* titleMessage = l10n_util::GetNSString( | 1470 NSString* titleMessage = l10n_util::GetNSString( |
1450 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); | 1471 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_TITLE); |
1451 NSString* contentMessage = l10n_util::GetNSString( | 1472 NSString* contentMessage = l10n_util::GetNSString( |
1452 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); | 1473 IDS_PROFILES_WELCOME_UPGRADE_TUTORIAL_CONTENT_TEXT); |
1453 // For local profiles, the "Not you" link doesn't make sense. | 1474 // For local profiles, the "Not you" link doesn't make sense. |
1454 NSString* linkMessage = avatarItem.signed_in ? | 1475 NSString* linkMessage = item.signed_in ? |
1455 ElideMessage( | 1476 ElideMessage( |
1456 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, avatarItem.name), | 1477 l10n_util::GetStringFUTF16(IDS_PROFILES_NOT_YOU, item.name), |
1457 kFixedMenuWidth - 2 * kHorizontalSpacing) : | 1478 kFixedMenuWidth - 2 * kHorizontalSpacing) : |
1458 nil; | 1479 nil; |
1459 NSString* buttonMessage = l10n_util::GetNSString( | 1480 NSString* buttonMessage = l10n_util::GetNSString( |
1460 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); | 1481 IDS_PROFILES_TUTORIAL_WHATS_NEW_BUTTON); |
1461 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE | 1482 return [self tutorialViewWithMode:profiles::TUTORIAL_MODE_WELCOME_UPGRADE |
1462 titleMessage:titleMessage | 1483 titleMessage:titleMessage |
1463 contentMessage:contentMessage | 1484 contentMessage:contentMessage |
1464 linkMessage:linkMessage | 1485 linkMessage:linkMessage |
1465 buttonMessage:buttonMessage | 1486 buttonMessage:buttonMessage |
1466 stackButton:YES | 1487 stackButton:YES |
1467 hasCloseButton:YES | 1488 hasCloseButton:YES |
1468 linkAction:@selector(showSwitchUserView:) | 1489 linkAction:@selector(showSwitchUserView:) |
1469 buttonAction:@selector(seeWhatsNew:)]; | 1490 buttonAction:@selector(seeWhatsNew:)]; |
1470 } | 1491 } |
1471 | 1492 |
1493 - (NSView*)buildRightClickTutorialView { | |
1494 NSString* titleMessage = l10n_util::GetNSString( | |
1495 IDS_PROFILES_RIGHT_CLICK_TUTORIAL_TITLE); | |
1496 NSString* contentMessage = l10n_util::GetNSString( | |
1497 IDS_PROFILES_RIGHT_CLICK_TUTORIAL_CONTENT_TEXT); | |
1498 NSString* buttonMessage = l10n_util::GetNSString( | |
1499 IDS_PROFILES_TUTORIAL_OK_BUTTON); | |
1500 | |
1501 return | |
1502 [self tutorialViewWithMode:profiles::TUTORIAL_MODE_RIGHT_CLICK_SWITCHING | |
1503 titleMessage:titleMessage | |
1504 contentMessage:contentMessage | |
1505 linkMessage:nil | |
1506 buttonMessage:buttonMessage | |
1507 stackButton:NO | |
1508 hasCloseButton:NO | |
1509 linkAction:nil | |
1510 buttonAction:@selector(dismissTutorial:)]; | |
1511 } | |
1512 | |
1513 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item { | |
1514 if (tutorialMode_ == profiles::TUTORIAL_MODE_CONFIRM_SIGNIN) | |
1515 return [self buildSigninConfirmationView]; | |
1516 | |
1517 if (tutorialMode_ == profiles::TUTORIAL_MODE_SHOW_ERROR) | |
1518 return [self buildSigninErrorView]; | |
1519 | |
1520 if ([self shouldShowWelcomeUpgradeTutorial]) { | |
groby-ooo-7-16
2015/05/07 01:59:01
If I read this correctly, this code only updates t
anthonyvd
2015/05/12 16:09:11
I moved this code as-is from line 1439 of the prev
| |
1521 if (tutorialMode_ != profiles::TUTORIAL_MODE_WELCOME_UPGRADE) { | |
1522 Profile* profile = browser_->profile(); | |
1523 const int showCount = profile->GetPrefs()->GetInteger( | |
1524 prefs::kProfileAvatarTutorialShown); | |
1525 profile->GetPrefs()->SetInteger( | |
1526 prefs::kProfileAvatarTutorialShown, showCount + 1); | |
1527 } | |
1528 | |
1529 return [self buildWelcomeUpgradeTutorialView:item]; | |
1530 } | |
1531 | |
1532 if ([self shouldShowRightClickTutorialView]) | |
1533 return [self buildRightClickTutorialView]; | |
1534 | |
1535 return nil; | |
1536 } | |
1537 | |
1472 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 1538 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
1473 titleMessage:(NSString*)titleMessage | 1539 titleMessage:(NSString*)titleMessage |
1474 contentMessage:(NSString*)contentMessage | 1540 contentMessage:(NSString*)contentMessage |
1475 linkMessage:(NSString*)linkMessage | 1541 linkMessage:(NSString*)linkMessage |
1476 buttonMessage:(NSString*)buttonMessage | 1542 buttonMessage:(NSString*)buttonMessage |
1477 stackButton:(BOOL)stackButton | 1543 stackButton:(BOOL)stackButton |
1478 hasCloseButton:(BOOL)hasCloseButton | 1544 hasCloseButton:(BOOL)hasCloseButton |
1479 linkAction:(SEL)linkAction | 1545 linkAction:(SEL)linkAction |
1480 buttonAction:(SEL)buttonAction { | 1546 buttonAction:(SEL)buttonAction { |
1481 tutorialMode_ = mode; | 1547 tutorialMode_ = mode; |
(...skipping 833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2315 } | 2381 } |
2316 | 2382 |
2317 - (bool)shouldShowGoIncognito { | 2383 - (bool)shouldShowGoIncognito { |
2318 bool incognitoAvailable = | 2384 bool incognitoAvailable = |
2319 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2385 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2320 IncognitoModePrefs::DISABLED; | 2386 IncognitoModePrefs::DISABLED; |
2321 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2387 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2322 } | 2388 } |
2323 | 2389 |
2324 @end | 2390 @end |
OLD | NEW |