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 | 9 |
10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
(...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 return nil; | 868 return nil; |
869 } | 869 } |
870 | 870 |
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 // Adds an horizontal separator to |container| at |yOffset| and returns the |
| 879 // yOffset corresponding to after the separator. |
| 880 - (CGFloat)addSeparatorToContainer:(NSView*)container |
| 881 atYOffset:(CGFloat)yOffset; |
| 882 |
| 883 // Builds the right-click profile switcher. |
| 884 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles |
| 885 atYOffset:(CGFloat)yOffset |
| 886 inContainer:(NSView*)container; |
| 887 |
| 888 // Builds the regular profile chooser view. |
| 889 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 890 tutorialView:(NSView*)tutorialView |
| 891 atYOffset:(CGFloat)yOffset |
| 892 inContainer:(NSView*)container |
| 893 displayLock:(bool)displayLock; |
| 894 |
878 // Builds the profile chooser view. | 895 // Builds the profile chooser view. |
879 - (NSView*)buildProfileChooserView; | 896 - (NSView*)buildProfileChooserView; |
880 | 897 |
881 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; | 898 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; |
882 | 899 |
883 // Builds a tutorial card with a title label using |titleMessage|, a content | 900 // Builds a tutorial card with a title label using |titleMessage|, a content |
884 // label using |contentMessage|, a link using |linkMessage|, and a button using | 901 // label using |contentMessage|, a link using |linkMessage|, and a button using |
885 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | 902 // |buttonMessage|. If |stackButton| is YES, places the button above the link. |
886 // Otherwise places both on the same row with the link left aligned and button | 903 // Otherwise places both on the same row with the link left aligned and button |
887 // right aligned. On click, the link would execute |linkAction|, and the button | 904 // right aligned. On click, the link would execute |linkAction|, and the button |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1263 [[[DummyWindowFocusButton alloc] initWithFrame:NSZeroRect] autorelease]; | 1280 [[[DummyWindowFocusButton alloc] initWithFrame:NSZeroRect] autorelease]; |
1264 [dummyFocusButton setNextKeyView:subView]; | 1281 [dummyFocusButton setNextKeyView:subView]; |
1265 [[self window] makeFirstResponder:dummyFocusButton]; | 1282 [[self window] makeFirstResponder:dummyFocusButton]; |
1266 | 1283 |
1267 [contentView addSubview:subView]; | 1284 [contentView addSubview:subView]; |
1268 [contentView addSubview:dummyFocusButton]; | 1285 [contentView addSubview:dummyFocusButton]; |
1269 SetWindowSize([self window], | 1286 SetWindowSize([self window], |
1270 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); | 1287 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); |
1271 } | 1288 } |
1272 | 1289 |
| 1290 - (CGFloat)addSeparatorToContainer:(NSView*)container |
| 1291 atYOffset:(CGFloat)yOffset { |
| 1292 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( |
| 1293 0, yOffset, kFixedMenuWidth, 0)]; |
| 1294 [container addSubview:separator]; |
| 1295 return NSMaxY([separator frame]); |
| 1296 } |
| 1297 |
| 1298 // Builds the fast user switcher view in |container| at |yOffset| and populates |
| 1299 // it with the entries for every profile in |otherProfiles|. Returns the new |
| 1300 // yOffset after adding the elements. |
| 1301 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles |
| 1302 atYOffset:(CGFloat)yOffset |
| 1303 inContainer:(NSView*)container { |
| 1304 // Other profiles switcher. The profiles have already been sorted |
| 1305 // by their y-coordinate, so they can be added in the existing order. |
| 1306 for (NSView* otherProfileView in otherProfiles) { |
| 1307 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1308 [container addSubview:otherProfileView]; |
| 1309 yOffset = NSMaxY([otherProfileView frame]); |
| 1310 |
| 1311 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; |
| 1312 } |
| 1313 |
| 1314 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 1315 } |
| 1316 |
| 1317 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 1318 tutorialView:(NSView*)tutorialView |
| 1319 atYOffset:(CGFloat)yOffset |
| 1320 inContainer:(NSView*)container |
| 1321 displayLock:(bool)displayLock { |
| 1322 // Option buttons. |
| 1323 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); |
| 1324 NSView* optionsView = [self createOptionsViewWithRect:rect |
| 1325 displayLock:displayLock]; |
| 1326 [container addSubview:optionsView]; |
| 1327 rect.origin.y = NSMaxY([optionsView frame]); |
| 1328 |
| 1329 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; |
| 1330 [container addSubview:separator]; |
| 1331 yOffset = NSMaxY([separator frame]); |
| 1332 |
| 1333 // For supervised users, add the disclaimer text. |
| 1334 if (browser_->profile()->IsSupervised()) { |
| 1335 yOffset += kSmallVerticalSpacing; |
| 1336 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; |
| 1337 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1338 [container addSubview:disclaimerContainer]; |
| 1339 yOffset = NSMaxY([disclaimerContainer frame]); |
| 1340 yOffset += kSmallVerticalSpacing; |
| 1341 |
| 1342 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; |
| 1343 } |
| 1344 |
| 1345 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { |
| 1346 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: |
| 1347 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; |
| 1348 [container addSubview:currentProfileAccountsView]; |
| 1349 yOffset = NSMaxY([currentProfileAccountsView frame]); |
| 1350 |
| 1351 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; |
| 1352 } |
| 1353 |
| 1354 // Active profile card. |
| 1355 if (currentProfileView) { |
| 1356 yOffset += kVerticalSpacing; |
| 1357 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1358 [container addSubview:currentProfileView]; |
| 1359 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; |
| 1360 } |
| 1361 |
| 1362 if (tutorialView) { |
| 1363 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1364 [container addSubview:tutorialView]; |
| 1365 yOffset = NSMaxY([tutorialView frame]); |
| 1366 //TODO(mlerman): update UMA stats for the new tutorials. |
| 1367 } else { |
| 1368 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; |
| 1369 } |
| 1370 |
| 1371 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; |
| 1372 } |
| 1373 |
1273 - (NSView*)buildProfileChooserView { | 1374 - (NSView*)buildProfileChooserView { |
1274 base::scoped_nsobject<NSView> container( | 1375 base::scoped_nsobject<NSView> container( |
1275 [[NSView alloc] initWithFrame:NSZeroRect]); | 1376 [[NSView alloc] initWithFrame:NSZeroRect]); |
1276 | 1377 |
1277 NSView* tutorialView = nil; | 1378 NSView* tutorialView = nil; |
1278 NSView* currentProfileView = nil; | 1379 NSView* currentProfileView = nil; |
1279 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1380 base::scoped_nsobject<NSMutableArray> otherProfiles( |
1280 [[NSMutableArray alloc] init]); | 1381 [[NSMutableArray alloc] init]); |
1281 // Local and guest profiles cannot lock their profile. | 1382 // Local and guest profiles cannot lock their profile. |
1282 bool displayLock = false; | 1383 bool displayLock = false; |
(...skipping 22 matching lines...) Expand all Loading... |
1305 } | 1406 } |
1306 } | 1407 } |
1307 if (!currentProfileView) // Guest windows don't have an active profile. | 1408 if (!currentProfileView) // Guest windows don't have an active profile. |
1308 currentProfileView = [self createGuestProfileView]; | 1409 currentProfileView = [self createGuestProfileView]; |
1309 | 1410 |
1310 // |yOffset| is the next position at which to draw in |container| | 1411 // |yOffset| is the next position at which to draw in |container| |
1311 // coordinates. Add a pixel offset so that the bottom option buttons don't | 1412 // coordinates. Add a pixel offset so that the bottom option buttons don't |
1312 // overlap the bubble's rounded corners. | 1413 // overlap the bubble's rounded corners. |
1313 CGFloat yOffset = 1; | 1414 CGFloat yOffset = 1; |
1314 | 1415 |
1315 if (!isFastProfileChooser) { | 1416 if (isFastProfileChooser) { |
1316 // Option buttons. | 1417 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() |
1317 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); | 1418 atYOffset:yOffset |
1318 NSView* optionsView = [self createOptionsViewWithRect:rect | 1419 inContainer:container.get()]; |
1319 displayLock:displayLock]; | 1420 } else { |
1320 [container addSubview:optionsView]; | 1421 [self buildProfileChooserViewWithProfileView:currentProfileView |
1321 rect.origin.y = NSMaxY([optionsView frame]); | 1422 tutorialView:tutorialView |
1322 | 1423 atYOffset:yOffset |
1323 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | 1424 inContainer:container.get() |
1324 [container addSubview:separator]; | 1425 displayLock:displayLock]; |
1325 yOffset = NSMaxY([separator frame]); | |
1326 } | 1426 } |
1327 | 1427 |
1328 if ((viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | |
1329 switches::IsFastUserSwitching()) || isFastProfileChooser) { | |
1330 // Other profiles switcher. The profiles have already been sorted | |
1331 // by their y-coordinate, so they can be added in the existing order. | |
1332 for (NSView *otherProfileView in otherProfiles.get()) { | |
1333 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1334 [container addSubview:otherProfileView]; | |
1335 yOffset = NSMaxY([otherProfileView frame]); | |
1336 | |
1337 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( | |
1338 0, yOffset, kFixedMenuWidth, 0)]; | |
1339 [container addSubview:separator]; | |
1340 yOffset = NSMaxY([separator frame]); | |
1341 } | |
1342 } | |
1343 | |
1344 // For supervised users, add the disclaimer text. | |
1345 if (browser_->profile()->IsSupervised()) { | |
1346 yOffset += kSmallVerticalSpacing; | |
1347 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; | |
1348 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1349 [container addSubview:disclaimerContainer]; | |
1350 yOffset = NSMaxY([disclaimerContainer frame]); | |
1351 yOffset += kSmallVerticalSpacing; | |
1352 | |
1353 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( | |
1354 0, yOffset, kFixedMenuWidth, 0)]; | |
1355 [container addSubview:separator]; | |
1356 yOffset = NSMaxY([separator frame]); | |
1357 } | |
1358 | |
1359 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | |
1360 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: | |
1361 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
1362 [container addSubview:currentProfileAccountsView]; | |
1363 yOffset = NSMaxY([currentProfileAccountsView frame]); | |
1364 | |
1365 NSBox* accountsSeparator = [self horizontalSeparatorWithFrame: | |
1366 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
1367 [container addSubview:accountsSeparator]; | |
1368 yOffset = NSMaxY([accountsSeparator frame]); | |
1369 } | |
1370 | |
1371 // Active profile card. | |
1372 if (!isFastProfileChooser && currentProfileView) { | |
1373 yOffset += kVerticalSpacing; | |
1374 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1375 [container addSubview:currentProfileView]; | |
1376 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; | |
1377 } | |
1378 | |
1379 if (!isFastProfileChooser && tutorialView) { | |
1380 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1381 [container addSubview:tutorialView]; | |
1382 yOffset = NSMaxY([tutorialView frame]); | |
1383 //TODO(mlerman): update UMA stats for the new tutorials. | |
1384 } else { | |
1385 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
1386 } | |
1387 | |
1388 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | |
1389 return container.autorelease(); | 1428 return container.autorelease(); |
1390 } | 1429 } |
1391 | 1430 |
1392 - (NSView*)buildSigninConfirmationView { | 1431 - (NSView*)buildSigninConfirmationView { |
1393 ProfileMetrics::LogProfileNewAvatarMenuSignin( | 1432 ProfileMetrics::LogProfileNewAvatarMenuSignin( |
1394 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); | 1433 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); |
1395 | 1434 |
1396 NSString* titleMessage = l10n_util::GetNSString( | 1435 NSString* titleMessage = l10n_util::GetNSString( |
1397 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); | 1436 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); |
1398 NSString* contentMessage = l10n_util::GetNSString( | 1437 NSString* contentMessage = l10n_util::GetNSString( |
(...skipping 952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2351 } | 2390 } |
2352 | 2391 |
2353 - (bool)shouldShowGoIncognito { | 2392 - (bool)shouldShowGoIncognito { |
2354 bool incognitoAvailable = | 2393 bool incognitoAvailable = |
2355 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2394 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2356 IncognitoModePrefs::DISABLED; | 2395 IncognitoModePrefs::DISABLED; |
2357 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2396 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2358 } | 2397 } |
2359 | 2398 |
2360 @end | 2399 @end |
OLD | NEW |