| 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 |
| 11 #include "base/mac/bundle_locations.h" | 11 #include "base/mac/bundle_locations.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/metrics/user_metrics.h" | 13 #include "base/metrics/user_metrics.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/sys_string_conversions.h" | 15 #include "base/strings/sys_string_conversions.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
| 18 #include "chrome/app/vector_icons/vector_icons.h" |
| 18 #include "chrome/browser/browser_process.h" | 19 #include "chrome/browser/browser_process.h" |
| 19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
| 20 #include "chrome/browser/lifetime/application_lifetime.h" | 21 #include "chrome/browser/lifetime/application_lifetime.h" |
| 21 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 22 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 22 #include "chrome/browser/profiles/avatar_menu.h" | 23 #include "chrome/browser/profiles/avatar_menu.h" |
| 23 #include "chrome/browser/profiles/avatar_menu_observer.h" | 24 #include "chrome/browser/profiles/avatar_menu_observer.h" |
| 24 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 25 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| 25 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
| 26 #include "chrome/browser/profiles/profile_metrics.h" | 27 #include "chrome/browser/profiles/profile_metrics.h" |
| 27 #include "chrome/browser/profiles/profile_window.h" | 28 #include "chrome/browser/profiles/profile_window.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 #include "ui/base/cocoa/window_size_constants.h" | 79 #include "ui/base/cocoa/window_size_constants.h" |
| 79 #include "ui/base/l10n/l10n_util.h" | 80 #include "ui/base/l10n/l10n_util.h" |
| 80 #include "ui/base/l10n/l10n_util_mac.h" | 81 #include "ui/base/l10n/l10n_util_mac.h" |
| 81 #include "ui/base/resource/resource_bundle.h" | 82 #include "ui/base/resource/resource_bundle.h" |
| 82 #include "ui/events/keycodes/keyboard_codes.h" | 83 #include "ui/events/keycodes/keyboard_codes.h" |
| 83 #include "ui/gfx/color_palette.h" | 84 #include "ui/gfx/color_palette.h" |
| 84 #include "ui/gfx/image/image.h" | 85 #include "ui/gfx/image/image.h" |
| 85 #include "ui/gfx/image/image_skia_util_mac.h" | 86 #include "ui/gfx/image/image_skia_util_mac.h" |
| 86 #include "ui/gfx/paint_vector_icon.h" | 87 #include "ui/gfx/paint_vector_icon.h" |
| 87 #include "ui/gfx/text_elider.h" | 88 #include "ui/gfx/text_elider.h" |
| 88 #include "ui/gfx/vector_icons_public.h" | |
| 89 #include "ui/native_theme/common_theme.h" | 89 #include "ui/native_theme/common_theme.h" |
| 90 #include "ui/native_theme/native_theme.h" | 90 #include "ui/native_theme/native_theme.h" |
| 91 | 91 |
| 92 namespace { | 92 namespace { |
| 93 | 93 |
| 94 // Constants taken from the Windows/Views implementation at: | 94 // Constants taken from the Windows/Views implementation at: |
| 95 // chrome/browser/ui/views/profile_chooser_view.cc | 95 // chrome/browser/ui/views/profile_chooser_view.cc |
| 96 const int kLargeImageSide = 88; | 96 const int kLargeImageSide = 88; |
| 97 const int kSmallImageSide = 32; | 97 const int kSmallImageSide = 32; |
| 98 const int kMdImageSide = 40; | 98 const int kMdImageSide = 40; |
| (...skipping 1854 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1953 skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700)); | 1953 skia::SkColorToCalibratedNSColor(gfx::kGoogleRed700)); |
| 1954 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; | 1954 [titleLabel setFrameSize:NSMakeSize(availableWidth, 0)]; |
| 1955 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; | 1955 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleLabel]; |
| 1956 [container addSubview:titleLabel]; | 1956 [container addSubview:titleLabel]; |
| 1957 yOffset = NSMaxY([titleLabel frame]); | 1957 yOffset = NSMaxY([titleLabel frame]); |
| 1958 | 1958 |
| 1959 // Adds the sync problem icon. | 1959 // Adds the sync problem icon. |
| 1960 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc] | 1960 base::scoped_nsobject<NSImageView> syncProblemIcon([[NSImageView alloc] |
| 1961 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize, | 1961 initWithFrame:NSMakeRect(kHorizontalSpacing, yOffset - iconSize, iconSize, |
| 1962 iconSize)]); | 1962 iconSize)]); |
| 1963 [syncProblemIcon setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | 1963 [syncProblemIcon |
| 1964 gfx::VectorIconId::SYNC_PROBLEM, iconSize, | 1964 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 1965 gfx::kGoogleRed700))]; | 1965 kSyncProblemIcon, iconSize, gfx::kGoogleRed700))]; |
| 1966 [container addSubview:syncProblemIcon]; | 1966 [container addSubview:syncProblemIcon]; |
| 1967 | 1967 |
| 1968 [container | 1968 [container |
| 1969 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; | 1969 setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset + kVerticalSpacing)]; |
| 1970 return container.autorelease(); | 1970 return container.autorelease(); |
| 1971 } | 1971 } |
| 1972 | 1972 |
| 1973 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { | 1973 - (NSView*)createCurrentProfileView:(const AvatarMenu::Item&)item { |
| 1974 base::scoped_nsobject<NSView> container([[NSView alloc] | 1974 base::scoped_nsobject<NSView> container([[NSView alloc] |
| 1975 initWithFrame:NSZeroRect]); | 1975 initWithFrame:NSZeroRect]); |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2117 badgeSize, badgeSize); | 2117 badgeSize, badgeSize); |
| 2118 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([ | 2118 base::scoped_nsobject<BackgroundCircleView> badgeIconWithCircle([ |
| 2119 [BackgroundCircleView alloc] initWithFrame:badgeIconCircleFrame | 2119 [BackgroundCircleView alloc] initWithFrame:badgeIconCircleFrame |
| 2120 withFillColor:GetDialogBackgroundColor()]); | 2120 withFillColor:GetDialogBackgroundColor()]); |
| 2121 // Add the badge icon. | 2121 // Add the badge icon. |
| 2122 constexpr int borderWidth = 1; | 2122 constexpr int borderWidth = 1; |
| 2123 const int badgeIconSize = badgeSize - borderWidth * 2; | 2123 const int badgeIconSize = badgeSize - borderWidth * 2; |
| 2124 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc] | 2124 base::scoped_nsobject<NSImageView> badgeIconView([[NSImageView alloc] |
| 2125 initWithFrame:NSMakeRect(borderWidth, borderWidth, | 2125 initWithFrame:NSMakeRect(borderWidth, borderWidth, |
| 2126 badgeIconSize, badgeIconSize)]); | 2126 badgeIconSize, badgeIconSize)]); |
| 2127 gfx::VectorIconId badgeIcon = | 2127 const gfx::VectorIcon& badgeIcon = browser_->profile()->IsChild() |
| 2128 browser_->profile()->IsChild() | 2128 ? kAccountChildCircleIcon |
| 2129 ? gfx::VectorIconId::ACCOUNT_CHILD_CIRCLE | 2129 : kSupervisorAccountCircleIcon; |
| 2130 : gfx::VectorIconId::SUPERVISOR_ACCOUNT_CIRCLE; | |
| 2131 [badgeIconView | 2130 [badgeIconView |
| 2132 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2131 setImage:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2133 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))]; | 2132 badgeIcon, badgeIconSize, gfx::kChromeIconGrey))]; |
| 2134 [badgeIconWithCircle addSubview:badgeIconView]; | 2133 [badgeIconWithCircle addSubview:badgeIconView]; |
| 2135 | 2134 |
| 2136 [profileCard addSubview:badgeIconWithCircle]; | 2135 [profileCard addSubview:badgeIconWithCircle]; |
| 2137 } | 2136 } |
| 2138 | 2137 |
| 2139 // Profile name, left-aligned to the right of profile icon. | 2138 // Profile name, left-aligned to the right of profile icon. |
| 2140 xOffset += kMdImageSide + kHorizontalSpacing; | 2139 xOffset += kMdImageSide + kHorizontalSpacing; |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2500 | 2499 |
| 2501 // Create a lock profile button when supervised users exist; otherwise, create | 2500 // Create a lock profile button when supervised users exist; otherwise, create |
| 2502 // a button that closes all of the current profile's windows if more than one | 2501 // a button that closes all of the current profile's windows if more than one |
| 2503 // is open. | 2502 // is open. |
| 2504 if (showLock) { | 2503 if (showLock) { |
| 2505 NSButton* lockButton = | 2504 NSButton* lockButton = |
| 2506 [self hoverButtonWithRect:viewRect | 2505 [self hoverButtonWithRect:viewRect |
| 2507 text:l10n_util::GetNSString( | 2506 text:l10n_util::GetNSString( |
| 2508 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) | 2507 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) |
| 2509 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2508 image:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2510 gfx::VectorIconId::LOCK, | 2509 kLockIcon, material_icon_size, |
| 2511 material_icon_size, gfx::kChromeIconGrey)) | 2510 gfx::kChromeIconGrey)) |
| 2512 action:@selector(lockProfile:)]; | 2511 action:@selector(lockProfile:)]; |
| 2513 [container addSubview:lockButton]; | 2512 [container addSubview:lockButton]; |
| 2514 viewRect.origin.y = NSMaxY([lockButton frame]); | 2513 viewRect.origin.y = NSMaxY([lockButton frame]); |
| 2515 } else if (!isGuestSession_) { | 2514 } else if (!isGuestSession_) { |
| 2516 int num_browsers = 0; | 2515 int num_browsers = 0; |
| 2517 for (auto* browser : *BrowserList::GetInstance()) { | 2516 for (auto* browser : *BrowserList::GetInstance()) { |
| 2518 Profile* current_profile = browser_->profile()->GetOriginalProfile(); | 2517 Profile* current_profile = browser_->profile()->GetOriginalProfile(); |
| 2519 if (browser->profile()->GetOriginalProfile() == current_profile) | 2518 if (browser->profile()->GetOriginalProfile() == current_profile) |
| 2520 num_browsers++; | 2519 num_browsers++; |
| 2521 } | 2520 } |
| 2522 if (num_browsers > 1) { | 2521 if (num_browsers > 1) { |
| 2523 NSButton* closeAllWindowsButton = [self | 2522 NSButton* closeAllWindowsButton = |
| 2524 hoverButtonWithRect:viewRect | 2523 [self hoverButtonWithRect:viewRect |
| 2525 text:l10n_util::GetNSString( | 2524 text:l10n_util::GetNSString( |
| 2526 IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON) | 2525 IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON) |
| 2527 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2526 image:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2528 gfx::VectorIconId::CLOSE_ALL, | 2527 kCloseAllIcon, material_icon_size, |
| 2529 material_icon_size, gfx::kChromeIconGrey)) | 2528 gfx::kChromeIconGrey)) |
| 2530 action:@selector(closeAllWindows:)]; | 2529 action:@selector(closeAllWindows:)]; |
| 2531 [container addSubview:closeAllWindowsButton]; | 2530 [container addSubview:closeAllWindowsButton]; |
| 2532 viewRect.origin.y = NSMaxY([closeAllWindowsButton frame]); | 2531 viewRect.origin.y = NSMaxY([closeAllWindowsButton frame]); |
| 2533 } | 2532 } |
| 2534 } | 2533 } |
| 2535 | 2534 |
| 2536 // Create a manage users/exit guest button. | 2535 // Create a manage users/exit guest button. |
| 2537 NSString* text = | 2536 NSString* text = |
| 2538 isGuestSession_ | 2537 isGuestSession_ |
| 2539 ? l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) | 2538 ? l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) |
| 2540 : l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON); | 2539 : l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON); |
| 2541 NSImage* icon = NSImageFromImageSkia( | 2540 NSImage* icon = NSImageFromImageSkia( |
| 2542 gfx::CreateVectorIcon(isGuestSession_ ? gfx::VectorIconId::CLOSE_ALL | 2541 gfx::CreateVectorIcon(isGuestSession_ ? kCloseAllIcon : kSettingsIcon, |
| 2543 : gfx::VectorIconId::SETTINGS, | |
| 2544 material_icon_size, gfx::kChromeIconGrey)); | 2542 material_icon_size, gfx::kChromeIconGrey)); |
| 2545 SEL action = | 2543 SEL action = |
| 2546 isGuestSession_ ? @selector(exitGuest:) : @selector(showUserManager:); | 2544 isGuestSession_ ? @selector(exitGuest:) : @selector(showUserManager:); |
| 2547 NSButton* manageUsersButton = | 2545 NSButton* manageUsersButton = |
| 2548 [self hoverButtonWithRect:viewRect text:text image:icon action:action]; | 2546 [self hoverButtonWithRect:viewRect text:text image:icon action:action]; |
| 2549 viewRect.origin.y = NSMaxY([manageUsersButton frame]); | 2547 viewRect.origin.y = NSMaxY([manageUsersButton frame]); |
| 2550 [container addSubview:manageUsersButton]; | 2548 [container addSubview:manageUsersButton]; |
| 2551 | 2549 |
| 2552 // Create a guest profile button. | 2550 // Create a guest profile button. |
| 2553 if (!isGuestSession_) { | 2551 if (!isGuestSession_) { |
| 2554 PrefService* service = g_browser_process->local_state(); | 2552 PrefService* service = g_browser_process->local_state(); |
| 2555 DCHECK(service); | 2553 DCHECK(service); |
| 2556 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { | 2554 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { |
| 2557 NSButton* guestProfileButton = [self | 2555 NSButton* guestProfileButton = |
| 2558 hoverButtonWithRect:viewRect | 2556 [self hoverButtonWithRect:viewRect |
| 2559 text:l10n_util::GetNSString( | 2557 text:l10n_util::GetNSString( |
| 2560 IDS_PROFILES_GUEST_PROFILE_NAME) | 2558 IDS_PROFILES_GUEST_PROFILE_NAME) |
| 2561 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | 2559 image:NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 2562 gfx::VectorIconId::ACCOUNT_CIRCLE, | 2560 kAccountCircleIcon, material_icon_size, |
| 2563 material_icon_size, gfx::kChromeIconGrey)) | 2561 gfx::kChromeIconGrey)) |
| 2564 action:@selector(switchToGuest:)]; | 2562 action:@selector(switchToGuest:)]; |
| 2565 viewRect.origin.y = NSMaxY([guestProfileButton frame]); | 2563 viewRect.origin.y = NSMaxY([guestProfileButton frame]); |
| 2566 [container addSubview:guestProfileButton]; | 2564 [container addSubview:guestProfileButton]; |
| 2567 } | 2565 } |
| 2568 } | 2566 } |
| 2569 | 2567 |
| 2570 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; | 2568 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; |
| 2571 return container.autorelease(); | 2569 return container.autorelease(); |
| 2572 } | 2570 } |
| 2573 | 2571 |
| 2574 - (NSView*)createAccountsListWithRect:(NSRect)rect { | 2572 - (NSView*)createAccountsListWithRect:(NSRect)rect { |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2960 | 2958 |
| 2961 - (void)showWindow:(id)sender { | 2959 - (void)showWindow:(id)sender { |
| 2962 [super showWindow:sender]; | 2960 [super showWindow:sender]; |
| 2963 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; | 2961 NSEvent *event = [[NSApplication sharedApplication] currentEvent]; |
| 2964 if (firstProfileView_ && [event type] == NSKeyDown) { | 2962 if (firstProfileView_ && [event type] == NSKeyDown) { |
| 2965 [[self window] makeFirstResponder:firstProfileView_]; | 2963 [[self window] makeFirstResponder:firstProfileView_]; |
| 2966 } | 2964 } |
| 2967 } | 2965 } |
| 2968 | 2966 |
| 2969 @end | 2967 @end |
| OLD | NEW |