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 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 // Builds the right-click profile switcher. | |
879 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles | |
880 atYOffset:(CGFloat)yOffset | |
881 inContainer:(NSView*)container; | |
882 | |
883 // Builds the regular profile chooser view. | |
884 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | |
885 tutorialView:(NSView*)tutorialView | |
886 atYOffset:(CGFloat)yOffset | |
887 inContainer:(NSView*)container | |
888 displayLock:(bool)displayLock; | |
889 | |
878 // Builds the profile chooser view. | 890 // Builds the profile chooser view. |
879 - (NSView*)buildProfileChooserView; | 891 - (NSView*)buildProfileChooserView; |
880 | 892 |
881 // Builds a tutorial card with a title label using |titleMessage|, a content | 893 // Builds a tutorial card with a title label using |titleMessage|, a content |
882 // label using |contentMessage|, a link using |linkMessage|, and a button using | 894 // label using |contentMessage|, a link using |linkMessage|, and a button using |
883 // |buttonMessage|. If |stackButton| is YES, places the button above the link. | 895 // |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 | 896 // 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 | 897 // right aligned. On click, the link would execute |linkAction|, and the button |
886 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. | 898 // would execute |buttonAction|. It sets |tutorialMode_| to the given |mode|. |
887 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode | 899 - (NSView*)tutorialViewWithMode:(profiles::TutorialMode)mode |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1251 [[[DummyWindowFocusButton alloc] initWithFrame:NSZeroRect] autorelease]; | 1263 [[[DummyWindowFocusButton alloc] initWithFrame:NSZeroRect] autorelease]; |
1252 [dummyFocusButton setNextKeyView:subView]; | 1264 [dummyFocusButton setNextKeyView:subView]; |
1253 [[self window] makeFirstResponder:dummyFocusButton]; | 1265 [[self window] makeFirstResponder:dummyFocusButton]; |
1254 | 1266 |
1255 [contentView addSubview:subView]; | 1267 [contentView addSubview:subView]; |
1256 [contentView addSubview:dummyFocusButton]; | 1268 [contentView addSubview:dummyFocusButton]; |
1257 SetWindowSize([self window], | 1269 SetWindowSize([self window], |
1258 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); | 1270 NSMakeSize(NSWidth([subView frame]), NSHeight([subView frame]))); |
1259 } | 1271 } |
1260 | 1272 |
1273 // Builds the fast user switcher view in |container| at |yOffset| and populates | |
1274 // it with the entries for every profile in |otherProfiles|. Returns the new | |
1275 // yOffset after adding the elements. | |
1276 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles | |
1277 atYOffset:(CGFloat)yOffset | |
1278 inContainer:(NSView*)container { | |
1279 // Other profiles switcher. The profiles have already been sorted | |
1280 // by their y-coordinate, so they can be added in the existing order. | |
1281 for (NSView *otherProfileView in otherProfiles) { | |
Alexei Svitkine (slow)
2015/05/15 14:45:32
Nit: Space should go after the *, not before it.
anthonyvd
2015/05/19 20:56:03
Done.
| |
1282 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1283 [container addSubview:otherProfileView]; | |
1284 yOffset = NSMaxY([otherProfileView frame]); | |
1285 | |
1286 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( | |
1287 0, yOffset, kFixedMenuWidth, 0)]; | |
1288 [container addSubview:separator]; | |
1289 yOffset = NSMaxY([separator frame]); | |
1290 } | |
1291 | |
1292 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | |
1293 } | |
1294 | |
1295 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | |
1296 tutorialView:(NSView*)tutorialView | |
1297 atYOffset:(CGFloat)yOffset | |
1298 inContainer:(NSView*)container | |
1299 displayLock:(bool)displayLock { | |
1300 // Option buttons. | |
1301 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); | |
1302 NSView* optionsView = [self createOptionsViewWithRect:rect | |
1303 displayLock:displayLock]; | |
1304 [container addSubview:optionsView]; | |
1305 rect.origin.y = NSMaxY([optionsView frame]); | |
1306 | |
1307 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | |
1308 [container addSubview:separator]; | |
1309 yOffset = NSMaxY([separator frame]); | |
1310 | |
1311 // For supervised users, add the disclaimer text. | |
1312 if (browser_->profile()->IsSupervised()) { | |
1313 yOffset += kSmallVerticalSpacing; | |
1314 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; | |
1315 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1316 [container addSubview:disclaimerContainer]; | |
1317 yOffset = NSMaxY([disclaimerContainer frame]); | |
1318 yOffset += kSmallVerticalSpacing; | |
1319 | |
1320 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( | |
1321 0, yOffset, kFixedMenuWidth, 0)]; | |
Alexei Svitkine (slow)
2015/05/15 14:45:32
Nit: Make a helper function for this, since you re
anthonyvd
2015/05/19 20:56:04
Done.
| |
1322 [container addSubview:separator]; | |
1323 yOffset = NSMaxY([separator frame]); | |
1324 } | |
1325 | |
1326 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | |
1327 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: | |
1328 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
1329 [container addSubview:currentProfileAccountsView]; | |
1330 yOffset = NSMaxY([currentProfileAccountsView frame]); | |
1331 | |
1332 NSBox* accountsSeparator = [self horizontalSeparatorWithFrame: | |
1333 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
1334 [container addSubview:accountsSeparator]; | |
1335 yOffset = NSMaxY([accountsSeparator frame]); | |
1336 } | |
1337 | |
1338 // Active profile card. | |
1339 if (currentProfileView) { | |
1340 yOffset += kVerticalSpacing; | |
1341 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1342 [container addSubview:currentProfileView]; | |
1343 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; | |
1344 } | |
1345 | |
1346 if (tutorialView) { | |
1347 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1348 [container addSubview:tutorialView]; | |
1349 yOffset = NSMaxY([tutorialView frame]); | |
1350 //TODO(mlerman): update UMA stats for the new tutorials. | |
1351 } else { | |
1352 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
1353 } | |
1354 | |
1355 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | |
1356 } | |
1357 | |
1261 - (NSView*)buildProfileChooserView { | 1358 - (NSView*)buildProfileChooserView { |
1262 base::scoped_nsobject<NSView> container( | 1359 base::scoped_nsobject<NSView> container( |
1263 [[NSView alloc] initWithFrame:NSZeroRect]); | 1360 [[NSView alloc] initWithFrame:NSZeroRect]); |
1264 | 1361 |
1265 NSView* tutorialView = nil; | 1362 NSView* tutorialView = nil; |
1266 NSView* currentProfileView = nil; | 1363 NSView* currentProfileView = nil; |
1267 base::scoped_nsobject<NSMutableArray> otherProfiles( | 1364 base::scoped_nsobject<NSMutableArray> otherProfiles( |
1268 [[NSMutableArray alloc] init]); | 1365 [[NSMutableArray alloc] init]); |
1269 // Local and guest profiles cannot lock their profile. | 1366 // Local and guest profiles cannot lock their profile. |
1270 bool displayLock = false; | 1367 bool displayLock = false; |
(...skipping 27 matching lines...) Expand all Loading... | |
1298 } | 1395 } |
1299 } | 1396 } |
1300 if (!currentProfileView) // Guest windows don't have an active profile. | 1397 if (!currentProfileView) // Guest windows don't have an active profile. |
1301 currentProfileView = [self createGuestProfileView]; | 1398 currentProfileView = [self createGuestProfileView]; |
1302 | 1399 |
1303 // |yOffset| is the next position at which to draw in |container| | 1400 // |yOffset| is the next position at which to draw in |container| |
1304 // coordinates. Add a pixel offset so that the bottom option buttons don't | 1401 // coordinates. Add a pixel offset so that the bottom option buttons don't |
1305 // overlap the bubble's rounded corners. | 1402 // overlap the bubble's rounded corners. |
1306 CGFloat yOffset = 1; | 1403 CGFloat yOffset = 1; |
1307 | 1404 |
1308 if (!isFastProfileChooser) { | 1405 if (isFastProfileChooser) { |
1309 // Option buttons. | 1406 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() |
1310 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); | 1407 atYOffset:yOffset |
1311 NSView* optionsView = [self createOptionsViewWithRect:rect | 1408 inContainer:container.get()]; |
1312 displayLock:displayLock]; | 1409 } else { |
1313 [container addSubview:optionsView]; | 1410 [self buildProfileChooserViewWithProfileView:currentProfileView |
1314 rect.origin.y = NSMaxY([optionsView frame]); | 1411 tutorialView:tutorialView |
1315 | 1412 atYOffset:yOffset |
1316 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | 1413 inContainer:container.get() |
1317 [container addSubview:separator]; | 1414 displayLock:displayLock]; |
1318 yOffset = NSMaxY([separator frame]); | |
1319 } | 1415 } |
1320 | 1416 |
1321 if ((viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && | |
1322 switches::IsFastUserSwitching()) || isFastProfileChooser) { | |
1323 // Other profiles switcher. The profiles have already been sorted | |
1324 // by their y-coordinate, so they can be added in the existing order. | |
1325 for (NSView *otherProfileView in otherProfiles.get()) { | |
1326 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1327 [container addSubview:otherProfileView]; | |
1328 yOffset = NSMaxY([otherProfileView frame]); | |
1329 | |
1330 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( | |
1331 0, yOffset, kFixedMenuWidth, 0)]; | |
1332 [container addSubview:separator]; | |
1333 yOffset = NSMaxY([separator frame]); | |
1334 } | |
1335 } | |
1336 | |
1337 // For supervised users, add the disclaimer text. | |
1338 if (browser_->profile()->IsSupervised()) { | |
1339 yOffset += kSmallVerticalSpacing; | |
1340 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; | |
1341 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1342 [container addSubview:disclaimerContainer]; | |
1343 yOffset = NSMaxY([disclaimerContainer frame]); | |
1344 yOffset += kSmallVerticalSpacing; | |
1345 | |
1346 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect( | |
1347 0, yOffset, kFixedMenuWidth, 0)]; | |
1348 [container addSubview:separator]; | |
1349 yOffset = NSMaxY([separator frame]); | |
1350 } | |
1351 | |
1352 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { | |
1353 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: | |
1354 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
1355 [container addSubview:currentProfileAccountsView]; | |
1356 yOffset = NSMaxY([currentProfileAccountsView frame]); | |
1357 | |
1358 NSBox* accountsSeparator = [self horizontalSeparatorWithFrame: | |
1359 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; | |
1360 [container addSubview:accountsSeparator]; | |
1361 yOffset = NSMaxY([accountsSeparator frame]); | |
1362 } | |
1363 | |
1364 // Active profile card. | |
1365 if (!isFastProfileChooser && currentProfileView) { | |
1366 yOffset += kVerticalSpacing; | |
1367 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1368 [container addSubview:currentProfileView]; | |
1369 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; | |
1370 } | |
1371 | |
1372 if (!isFastProfileChooser && tutorialView) { | |
1373 [tutorialView setFrameOrigin:NSMakePoint(0, yOffset)]; | |
1374 [container addSubview:tutorialView]; | |
1375 yOffset = NSMaxY([tutorialView frame]); | |
1376 //TODO(mlerman): update UMA stats for the new tutorials. | |
1377 } else { | |
1378 tutorialMode_ = profiles::TUTORIAL_MODE_NONE; | |
1379 } | |
1380 | |
1381 [container setFrameSize:NSMakeSize(kFixedMenuWidth, yOffset)]; | |
1382 return container.autorelease(); | 1417 return container.autorelease(); |
1383 } | 1418 } |
1384 | 1419 |
1385 - (NSView*)buildSigninConfirmationView { | 1420 - (NSView*)buildSigninConfirmationView { |
1386 ProfileMetrics::LogProfileNewAvatarMenuSignin( | 1421 ProfileMetrics::LogProfileNewAvatarMenuSignin( |
1387 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); | 1422 ProfileMetrics::PROFILE_AVATAR_MENU_SIGNIN_VIEW); |
1388 | 1423 |
1389 NSString* titleMessage = l10n_util::GetNSString( | 1424 NSString* titleMessage = l10n_util::GetNSString( |
1390 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); | 1425 IDS_PROFILES_CONFIRM_SIGNIN_TUTORIAL_TITLE); |
1391 NSString* contentMessage = l10n_util::GetNSString( | 1426 NSString* contentMessage = l10n_util::GetNSString( |
(...skipping 923 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2315 } | 2350 } |
2316 | 2351 |
2317 - (bool)shouldShowGoIncognito { | 2352 - (bool)shouldShowGoIncognito { |
2318 bool incognitoAvailable = | 2353 bool incognitoAvailable = |
2319 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2354 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
2320 IncognitoModePrefs::DISABLED; | 2355 IncognitoModePrefs::DISABLED; |
2321 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2356 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
2322 } | 2357 } |
2323 | 2358 |
2324 @end | 2359 @end |
OLD | NEW |