Chromium Code Reviews| 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 16 matching lines...) Expand all Loading... | |
| 27 #include "chrome/browser/profiles/profile_window.h" | 27 #include "chrome/browser/profiles/profile_window.h" |
| 28 #include "chrome/browser/profiles/profiles_state.h" | 28 #include "chrome/browser/profiles/profiles_state.h" |
| 29 #include "chrome/browser/signin/chrome_signin_helper.h" | 29 #include "chrome/browser/signin/chrome_signin_helper.h" |
| 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 30 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 31 #include "chrome/browser/signin/signin_error_controller_factory.h" | 31 #include "chrome/browser/signin/signin_error_controller_factory.h" |
| 32 #include "chrome/browser/signin/signin_manager_factory.h" | 32 #include "chrome/browser/signin/signin_manager_factory.h" |
| 33 #include "chrome/browser/signin/signin_promo.h" | 33 #include "chrome/browser/signin/signin_promo.h" |
| 34 #include "chrome/browser/signin/signin_ui_util.h" | 34 #include "chrome/browser/signin/signin_ui_util.h" |
| 35 #include "chrome/browser/ui/browser.h" | 35 #include "chrome/browser/ui/browser.h" |
| 36 #include "chrome/browser/ui/browser_commands.h" | 36 #include "chrome/browser/ui/browser_commands.h" |
| 37 #include "chrome/browser/ui/browser_list.h" | |
| 37 #include "chrome/browser/ui/browser_window.h" | 38 #include "chrome/browser/ui/browser_window.h" |
| 38 #include "chrome/browser/ui/chrome_pages.h" | 39 #include "chrome/browser/ui/chrome_pages.h" |
| 39 #include "chrome/browser/ui/chrome_style.h" | 40 #include "chrome/browser/ui/chrome_style.h" |
| 40 #import "chrome/browser/ui/cocoa/browser_window_utils.h" | 41 #import "chrome/browser/ui/cocoa/browser_window_utils.h" |
| 41 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 42 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 42 #import "chrome/browser/ui/cocoa/info_bubble_window.h" | 43 #import "chrome/browser/ui/cocoa/info_bubble_window.h" |
| 43 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " | 44 #include "chrome/browser/ui/cocoa/profiles/signin_view_controller_delegate_mac.h " |
| 44 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" | 45 #import "chrome/browser/ui/cocoa/profiles/user_manager_mac.h" |
| 45 #include "chrome/browser/ui/singleton_tabs.h" | 46 #include "chrome/browser/ui/singleton_tabs.h" |
| 46 #include "chrome/browser/ui/user_manager.h" | 47 #include "chrome/browser/ui/user_manager.h" |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 67 #import "ui/base/cocoa/cocoa_base_utils.h" | 68 #import "ui/base/cocoa/cocoa_base_utils.h" |
| 68 #import "ui/base/cocoa/controls/blue_label_button.h" | 69 #import "ui/base/cocoa/controls/blue_label_button.h" |
| 69 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 70 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 70 #import "ui/base/cocoa/controls/hyperlink_text_view.h" | 71 #import "ui/base/cocoa/controls/hyperlink_text_view.h" |
| 71 #import "ui/base/cocoa/hover_image_button.h" | 72 #import "ui/base/cocoa/hover_image_button.h" |
| 72 #include "ui/base/cocoa/window_size_constants.h" | 73 #include "ui/base/cocoa/window_size_constants.h" |
| 73 #include "ui/base/l10n/l10n_util.h" | 74 #include "ui/base/l10n/l10n_util.h" |
| 74 #include "ui/base/l10n/l10n_util_mac.h" | 75 #include "ui/base/l10n/l10n_util_mac.h" |
| 75 #include "ui/base/resource/resource_bundle.h" | 76 #include "ui/base/resource/resource_bundle.h" |
| 76 #include "ui/events/keycodes/keyboard_codes.h" | 77 #include "ui/events/keycodes/keyboard_codes.h" |
| 78 #include "ui/gfx/color_palette.h" | |
| 77 #include "ui/gfx/image/image.h" | 79 #include "ui/gfx/image/image.h" |
| 80 #include "ui/gfx/image/image_skia_util_mac.h" | |
| 81 #include "ui/gfx/paint_vector_icon.h" | |
| 78 #include "ui/gfx/text_elider.h" | 82 #include "ui/gfx/text_elider.h" |
| 83 #include "ui/gfx/vector_icons_public.h" | |
| 79 #include "ui/native_theme/common_theme.h" | 84 #include "ui/native_theme/common_theme.h" |
| 80 #include "ui/native_theme/native_theme.h" | 85 #include "ui/native_theme/native_theme.h" |
| 81 #include "ui/native_theme/native_theme_mac.h" | 86 #include "ui/native_theme/native_theme_mac.h" |
| 82 | 87 |
| 83 namespace { | 88 namespace { |
| 84 | 89 |
| 85 // Constants taken from the Windows/Views implementation at: | 90 // Constants taken from the Windows/Views implementation at: |
| 86 // chrome/browser/ui/views/profile_chooser_view.cc | 91 // chrome/browser/ui/views/profile_chooser_view.cc |
| 87 const int kLargeImageSide = 88; | 92 const int kLargeImageSide = 88; |
| 88 const int kSmallImageSide = 32; | 93 const int kSmallImageSide = 32; |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 420 }; | 425 }; |
| 421 | 426 |
| 422 // Custom button cell that adds a left padding before the button image, and | 427 // Custom button cell that adds a left padding before the button image, and |
| 423 // a custom spacing between the button image and title. | 428 // a custom spacing between the button image and title. |
| 424 @interface CustomPaddingImageButtonCell : NSButtonCell { | 429 @interface CustomPaddingImageButtonCell : NSButtonCell { |
| 425 @private | 430 @private |
| 426 // Padding added to the left margin of the button. | 431 // Padding added to the left margin of the button. |
| 427 int leftMarginSpacing_; | 432 int leftMarginSpacing_; |
| 428 // Spacing between the cell image and title. | 433 // Spacing between the cell image and title. |
| 429 int imageTitleSpacing_; | 434 int imageTitleSpacing_; |
| 435 // Padding added to the right margin of the button. | |
| 436 int rightMarginSpacing_; | |
| 430 } | 437 } |
| 431 | 438 |
| 432 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing | 439 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing |
| 433 imageTitleSpacing:(int)imageTitleSpacing; | 440 imageTitleSpacing:(int)imageTitleSpacing; |
| 441 | |
| 442 - (void)addRightMarginSpacing:(int)rightMarginSpacing; | |
| 434 @end | 443 @end |
| 435 | 444 |
| 436 @implementation CustomPaddingImageButtonCell | 445 @implementation CustomPaddingImageButtonCell |
| 437 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing | 446 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing |
| 438 imageTitleSpacing:(int)imageTitleSpacing { | 447 imageTitleSpacing:(int)imageTitleSpacing { |
| 439 if ((self = [super init])) { | 448 if ((self = [super init])) { |
| 440 leftMarginSpacing_ = leftMarginSpacing; | 449 leftMarginSpacing_ = leftMarginSpacing; |
| 441 imageTitleSpacing_ = imageTitleSpacing; | 450 imageTitleSpacing_ = imageTitleSpacing; |
| 442 } | 451 } |
| 443 return self; | 452 return self; |
| 444 } | 453 } |
| 445 | 454 |
| 455 - (void)addRightMarginSpacing:(int)rightMarginSpacing { | |
|
groby-ooo-7-16
2016/07/20 20:54:22
nit: setRightMargingSpacing seems more appropriate
Jane
2016/07/20 22:03:46
Done.
| |
| 456 rightMarginSpacing_ = rightMarginSpacing; | |
| 457 } | |
| 458 | |
| 446 - (NSRect)drawTitle:(NSAttributedString*)title | 459 - (NSRect)drawTitle:(NSAttributedString*)title |
| 447 withFrame:(NSRect)frame | 460 withFrame:(NSRect)frame |
| 448 inView:(NSView*)controlView { | 461 inView:(NSView*)controlView { |
| 449 NSRect marginRect; | 462 NSRect marginRect; |
| 450 NSDivideRect(frame, &marginRect, &frame, leftMarginSpacing_, NSMinXEdge); | 463 NSDivideRect(frame, &marginRect, &frame, leftMarginSpacing_, NSMinXEdge); |
| 451 | 464 |
| 452 // The title frame origin isn't aware of the left margin spacing added | 465 // The title frame origin isn't aware of the left margin spacing added |
| 453 // in -drawImage, so it must be added when drawing the title as well. | 466 // in -drawImage, so it must be added when drawing the title as well. |
| 454 if ([self imagePosition] == NSImageLeft) | 467 if ([self imagePosition] == NSImageLeft) |
| 455 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, NSMinXEdge); | 468 NSDivideRect(frame, &marginRect, &frame, imageTitleSpacing_, NSMinXEdge); |
| 456 | 469 |
| 470 if (rightMarginSpacing_ > 0) | |
| 471 NSDivideRect(frame, &marginRect, &frame, rightMarginSpacing_, NSMaxXEdge); | |
|
groby-ooo-7-16
2016/07/20 20:54:22
You can probably skip the ">0" test.
Jane
2016/07/20 22:03:46
Done.
| |
| 472 | |
| 457 return [super drawTitle:title withFrame:frame inView:controlView]; | 473 return [super drawTitle:title withFrame:frame inView:controlView]; |
| 458 } | 474 } |
| 459 | 475 |
| 460 - (void)drawImage:(NSImage*)image | 476 - (void)drawImage:(NSImage*)image |
| 461 withFrame:(NSRect)frame | 477 withFrame:(NSRect)frame |
| 462 inView:(NSView*)controlView { | 478 inView:(NSView*)controlView { |
| 463 if ([self imagePosition] == NSImageLeft) | 479 if ([self imagePosition] == NSImageLeft) |
| 464 frame.origin.x = leftMarginSpacing_; | 480 frame.origin.x = leftMarginSpacing_; |
| 465 [super drawImage:image withFrame:frame inView:controlView]; | 481 [super drawImage:image withFrame:frame inView:controlView]; |
| 466 } | 482 } |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 790 } | 806 } |
| 791 | 807 |
| 792 @end | 808 @end |
| 793 | 809 |
| 794 // A custom button that allows for setting a background color when hovered over. | 810 // A custom button that allows for setting a background color when hovered over. |
| 795 @interface BackgroundColorHoverButton : HoverImageButton { | 811 @interface BackgroundColorHoverButton : HoverImageButton { |
| 796 @private | 812 @private |
| 797 base::scoped_nsobject<NSColor> backgroundColor_; | 813 base::scoped_nsobject<NSColor> backgroundColor_; |
| 798 base::scoped_nsobject<NSColor> hoverColor_; | 814 base::scoped_nsobject<NSColor> hoverColor_; |
| 799 } | 815 } |
| 816 | |
| 817 - (void)addRightMarginSpacing:(int)rightMarginSpacing; | |
| 800 @end | 818 @end |
| 801 | 819 |
| 802 @implementation BackgroundColorHoverButton | 820 @implementation BackgroundColorHoverButton |
| 803 | 821 |
| 804 - (id)initWithFrame:(NSRect)frameRect | 822 - (id)initWithFrame:(NSRect)frameRect |
| 805 imageTitleSpacing:(int)imageTitleSpacing | 823 imageTitleSpacing:(int)imageTitleSpacing |
| 806 backgroundColor:(NSColor*)backgroundColor { | 824 backgroundColor:(NSColor*)backgroundColor { |
| 807 if ((self = [super initWithFrame:frameRect])) { | 825 if ((self = [super initWithFrame:frameRect])) { |
| 808 backgroundColor_.reset([backgroundColor retain]); | 826 backgroundColor_.reset([backgroundColor retain]); |
| 809 // Use a color from Aura, since this button is not trying to look like a | 827 // Use a color from Aura, since this button is not trying to look like a |
| 810 // native control. | 828 // native control. |
| 811 SkColor hoverColor = ui::GetAuraColor( | 829 SkColor hoverColor = ui::GetAuraColor( |
| 812 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor, nullptr); | 830 ui::NativeTheme::kColorId_ButtonHoverBackgroundColor, nullptr); |
| 813 hoverColor_.reset([skia::SkColorToSRGBNSColor(hoverColor) retain]); | 831 hoverColor_.reset([skia::SkColorToSRGBNSColor(hoverColor) retain]); |
| 814 | 832 |
| 815 [self setBordered:NO]; | 833 [self setBordered:NO]; |
| 816 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; | 834 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; |
| 817 [self setButtonType:NSMomentaryChangeButton]; | 835 [self setButtonType:NSMomentaryChangeButton]; |
| 818 | 836 |
| 819 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( | 837 base::scoped_nsobject<CustomPaddingImageButtonCell> cell( |
| 820 [[CustomPaddingImageButtonCell alloc] | 838 [[CustomPaddingImageButtonCell alloc] |
| 821 initWithLeftMarginSpacing:kHorizontalSpacing | 839 initWithLeftMarginSpacing:kHorizontalSpacing |
| 822 imageTitleSpacing:imageTitleSpacing]); | 840 imageTitleSpacing:imageTitleSpacing]); |
| 823 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; | 841 [cell setLineBreakMode:NSLineBreakByTruncatingTail]; |
| 824 [self setCell:cell.get()]; | 842 [self setCell:cell.get()]; |
| 825 } | 843 } |
| 826 return self; | 844 return self; |
| 827 } | 845 } |
| 828 | 846 |
| 847 - (void)addRightMarginSpacing:(int)rightMarginSpacing { | |
| 848 [[self cell] addRightMarginSpacing:rightMarginSpacing]; | |
| 849 } | |
| 850 | |
| 829 - (void)drawRect:(NSRect)dirtyRect { | 851 - (void)drawRect:(NSRect)dirtyRect { |
| 830 if ([self isEnabled]) { | 852 if ([self isEnabled]) { |
| 831 bool isHighlighted = ([self hoverState] != kHoverStateNone); | 853 bool isHighlighted = ([self hoverState] != kHoverStateNone); |
| 832 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; | 854 NSColor* backgroundColor = isHighlighted ? hoverColor_ : backgroundColor_; |
| 833 [[self cell] setBackgroundColor:backgroundColor]; | 855 [[self cell] setBackgroundColor:backgroundColor]; |
| 834 } | 856 } |
| 835 [super drawRect:dirtyRect]; | 857 [super drawRect:dirtyRect]; |
| 836 } | 858 } |
| 837 | 859 |
| 838 -(void)keyDown:(NSEvent*)event { | 860 -(void)keyDown:(NSEvent*)event { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 892 } | 914 } |
| 893 | 915 |
| 894 @end | 916 @end |
| 895 | 917 |
| 896 @interface ProfileChooserController () | 918 @interface ProfileChooserController () |
| 897 // Adds an horizontal separator to |container| at |yOffset| and returns the | 919 // Adds an horizontal separator to |container| at |yOffset| and returns the |
| 898 // yOffset corresponding to after the separator. | 920 // yOffset corresponding to after the separator. |
| 899 - (CGFloat)addSeparatorToContainer:(NSView*)container | 921 - (CGFloat)addSeparatorToContainer:(NSView*)container |
| 900 atYOffset:(CGFloat)yOffset; | 922 atYOffset:(CGFloat)yOffset; |
| 901 | 923 |
| 902 // Builds the right-click profile switcher. | 924 // Builds the fast user switcher view. In the current user menu, this is |
| 903 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles | 925 // triggered by right-clicking the avatar button; in the material design user |
| 904 atYOffset:(CGFloat)yOffset | 926 // menu, this appears as part of the user menu. Returns the yOffset |
| 905 inContainer:(NSView*)container; | 927 // corresponding to after the profile switcher buttons. |
| 928 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles | |
| 929 atYOffset:(CGFloat)yOffset | |
| 930 inContainer:(NSView*)container; | |
| 906 | 931 |
| 907 // Builds the regular profile chooser view. | 932 // Builds the regular profile chooser view. |
| 908 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 933 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 909 tutorialView:(NSView*)tutorialView | 934 tutorialView:(NSView*)tutorialView |
| 935 otherProfiles:(NSMutableArray*)otherProfiles | |
| 910 atYOffset:(CGFloat)yOffset | 936 atYOffset:(CGFloat)yOffset |
| 911 inContainer:(NSView*)container | 937 inContainer:(NSView*)container |
| 912 displayLock:(bool)displayLock; | 938 displayLock:(bool)displayLock; |
| 913 | 939 |
| 914 // Builds the profile chooser view. | 940 // Builds the profile chooser view. |
| 915 - (NSView*)buildProfileChooserView; | 941 - (NSView*)buildProfileChooserView; |
| 916 | 942 |
| 917 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; | 943 - (NSView*)buildTutorialViewIfNeededForItem:(const AvatarMenu::Item&)item; |
| 918 | 944 |
| 919 // Builds a tutorial card with a title label using |titleMessage|, a content | 945 // Builds a tutorial card with a title label using |titleMessage|, a content |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 960 rect:(NSRect)rect; | 986 rect:(NSRect)rect; |
| 961 | 987 |
| 962 // Creates the disclaimer text for supervised users, telling them that the | 988 // Creates the disclaimer text for supervised users, telling them that the |
| 963 // manager can view their history etc. | 989 // manager can view their history etc. |
| 964 - (NSView*)createSupervisedUserDisclaimerView; | 990 - (NSView*)createSupervisedUserDisclaimerView; |
| 965 | 991 |
| 966 // Creates a main profile card for the guest user. | 992 // Creates a main profile card for the guest user. |
| 967 - (NSView*)createGuestProfileView; | 993 - (NSView*)createGuestProfileView; |
| 968 | 994 |
| 969 // Creates an item for the profile |itemIndex| that is used in the fast profile | 995 // Creates an item for the profile |itemIndex| that is used in the fast profile |
| 970 // switcher in the middle of the bubble. | 996 // switcher view. |
| 971 - (NSButton*)createOtherProfileView:(int)itemIndex; | 997 - (NSButton*)createOtherProfileView:(int)itemIndex; |
| 972 | 998 |
| 973 // Creates the "Not you" and Lock option buttons. | 999 // Creates the following option buttons: lock profile, go incognito, and switch |
| 1000 // user/exit guest. | |
| 974 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 1001 - (NSView*)createOptionsViewWithRect:(NSRect)rect |
| 975 displayLock:(BOOL)displayLock; | 1002 displayLock:(BOOL)displayLock; |
| 1003 // For material design user menu, creates the following option buttons: lock | |
| 1004 // profile/close all windows, switch user/exit guest, and open guest profile. | |
| 1005 - (NSView*)createMaterialDesignOptionsViewWithRect:(NSRect)rect | |
| 1006 displayLock:(BOOL)displayLock; | |
| 976 | 1007 |
| 977 // Creates the account management view for the active profile. | 1008 // Creates the account management view for the active profile. |
| 978 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; | 1009 - (NSView*)createCurrentProfileAccountsView:(NSRect)rect; |
| 979 | 1010 |
| 980 // Creates the list of accounts for the active profile. | 1011 // Creates the list of accounts for the active profile. |
| 981 - (NSView*)createAccountsListWithRect:(NSRect)rect; | 1012 - (NSView*)createAccountsListWithRect:(NSRect)rect; |
| 982 | 1013 |
| 983 // Creates the Gaia sign-in/add account view. | 1014 // Creates the Gaia sign-in/add account view. |
| 984 - (NSView*)buildGaiaEmbeddedView; | 1015 - (NSView*)buildGaiaEmbeddedView; |
| 985 | 1016 |
| 986 // Creates the account removal view. | 1017 // Creates the account removal view. |
| 987 - (NSView*)buildAccountRemovalView; | 1018 - (NSView*)buildAccountRemovalView; |
| 988 | 1019 |
| 989 // Create a view that shows various options for an upgrade user who is not | 1020 // Create a view that shows various options for an upgrade user who is not |
| 990 // the same person as the currently signed in user. | 1021 // the same person as the currently signed in user. |
| 991 - (NSView*)buildSwitchUserView; | 1022 - (NSView*)buildSwitchUserView; |
| 992 | 1023 |
| 993 // Creates a button with |text| and |action|, optionally with an icon given by | 1024 // Creates a button with |text| and |action|, optionally with an icon given by |
| 994 // |imageResourceId|. | 1025 // |imageResourceId| or |image|. |
| 995 - (NSButton*)hoverButtonWithRect:(NSRect)rect | 1026 - (NSButton*)hoverButtonWithRect:(NSRect)rect |
| 996 text:(NSString*)text | 1027 text:(NSString*)text |
| 997 imageResourceId:(int)imageResourceId | 1028 imageResourceId:(int)imageResourceId |
| 998 action:(SEL)action; | 1029 action:(SEL)action; |
| 1030 - (NSButton*)hoverButtonWithRect:(NSRect)rect | |
| 1031 text:(NSString*)text | |
| 1032 image:(NSImage*)image | |
| 1033 action:(SEL)action; | |
| 999 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect | 1034 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect |
| 1000 text:(NSString*)text | 1035 text:(NSString*)text |
| 1001 action:(SEL)action; | 1036 action:(SEL)action; |
| 1002 | 1037 |
| 1003 // Creates a generic link button with |title| and an |action| positioned at | 1038 // Creates a generic link button with |title| and an |action| positioned at |
| 1004 // |frameOrigin|. | 1039 // |frameOrigin|. |
| 1005 - (NSButton*)linkButtonWithTitle:(NSString*)title | 1040 - (NSButton*)linkButtonWithTitle:(NSString*)title |
| 1006 frameOrigin:(NSPoint)frameOrigin | 1041 frameOrigin:(NSPoint)frameOrigin |
| 1007 action:(SEL)action; | 1042 action:(SEL)action; |
| 1008 | 1043 |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1033 } | 1068 } |
| 1034 | 1069 |
| 1035 - (IBAction)switchToProfile:(id)sender { | 1070 - (IBAction)switchToProfile:(id)sender { |
| 1036 // Check the event flags to see if a new window should be created. | 1071 // Check the event flags to see if a new window should be created. |
| 1037 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( | 1072 bool alwaysCreate = ui::WindowOpenDispositionFromNSEvent( |
| 1038 [NSApp currentEvent]) == NEW_WINDOW; | 1073 [NSApp currentEvent]) == NEW_WINDOW; |
| 1039 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, | 1074 avatarMenu_->SwitchToProfile([sender tag], alwaysCreate, |
| 1040 ProfileMetrics::SWITCH_PROFILE_ICON); | 1075 ProfileMetrics::SWITCH_PROFILE_ICON); |
| 1041 } | 1076 } |
| 1042 | 1077 |
| 1078 - (IBAction)switchToGuest:(id)sender { | |
| 1079 PrefService* service = g_browser_process->local_state(); | |
|
groby-ooo-7-16
2016/07/20 20:54:22
Curious - why go through the global process, inste
Jane
2016/07/20 22:03:46
It doesn't seem like profile()->GetPrefs() have th
groby-ooo-7-16
2016/07/21 00:01:46
Ah, nevermind, my brain misfired - kBrowserGuestMo
| |
| 1080 DCHECK(service); | |
| 1081 DCHECK(service->GetBoolean(prefs::kBrowserGuestModeEnabled)); | |
| 1082 profiles::SwitchToGuestProfile(ProfileManager::CreateCallback()); | |
| 1083 } | |
| 1084 | |
| 1043 - (IBAction)showUserManager:(id)sender { | 1085 - (IBAction)showUserManager:(id)sender { |
| 1044 UserManager::Show(base::FilePath(), | 1086 UserManager::Show(base::FilePath(), |
| 1045 profiles::USER_MANAGER_NO_TUTORIAL, | 1087 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1046 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1088 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 1047 [self postActionPerformed: | 1089 [self postActionPerformed: |
| 1048 ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER]; | 1090 ProfileMetrics::PROFILE_DESKTOP_MENU_OPEN_USER_MANAGER]; |
| 1049 } | 1091 } |
| 1050 | 1092 |
| 1051 - (IBAction)exitGuest:(id)sender { | 1093 - (IBAction)exitGuest:(id)sender { |
| 1052 DCHECK(browser_->profile()->IsGuestSession()); | 1094 DCHECK(browser_->profile()->IsGuestSession()); |
| 1053 UserManager::Show(base::FilePath(), | 1095 UserManager::Show(base::FilePath(), |
| 1054 profiles::USER_MANAGER_NO_TUTORIAL, | 1096 profiles::USER_MANAGER_NO_TUTORIAL, |
| 1055 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); | 1097 profiles::USER_MANAGER_SELECT_PROFILE_NO_ACTION); |
| 1056 profiles::CloseGuestProfileWindows(); | 1098 profiles::CloseGuestProfileWindows(); |
| 1057 } | 1099 } |
| 1058 | 1100 |
| 1101 - (IBAction)closeAllWindows:(id)sender { | |
| 1102 profiles::CloseProfileWindows(browser_->profile()); | |
| 1103 } | |
| 1104 | |
| 1059 - (IBAction)goIncognito:(id)sender { | 1105 - (IBAction)goIncognito:(id)sender { |
| 1060 DCHECK([self shouldShowGoIncognito]); | 1106 DCHECK([self shouldShowGoIncognito]); |
| 1061 chrome::NewIncognitoWindow(browser_); | 1107 chrome::NewIncognitoWindow(browser_); |
| 1062 [self postActionPerformed: | 1108 [self postActionPerformed: |
| 1063 ProfileMetrics::PROFILE_DESKTOP_MENU_GO_INCOGNITO]; | 1109 ProfileMetrics::PROFILE_DESKTOP_MENU_GO_INCOGNITO]; |
| 1064 } | 1110 } |
| 1065 | 1111 |
| 1066 - (IBAction)showAccountManagement:(id)sender { | 1112 - (IBAction)showAccountManagement:(id)sender { |
| 1067 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; | 1113 [self initMenuContentsWithView:profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT]; |
| 1068 } | 1114 } |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1332 NSBox* separator = | 1378 NSBox* separator = |
| 1333 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, | 1379 [self horizontalSeparatorWithFrame:NSMakeRect(0, yOffset, |
| 1334 GetFixedMenuWidth(), 0)]; | 1380 GetFixedMenuWidth(), 0)]; |
| 1335 [container addSubview:separator]; | 1381 [container addSubview:separator]; |
| 1336 return NSMaxY([separator frame]); | 1382 return NSMaxY([separator frame]); |
| 1337 } | 1383 } |
| 1338 | 1384 |
| 1339 // Builds the fast user switcher view in |container| at |yOffset| and populates | 1385 // Builds the fast user switcher view in |container| at |yOffset| and populates |
| 1340 // it with the entries for every profile in |otherProfiles|. Returns the new | 1386 // it with the entries for every profile in |otherProfiles|. Returns the new |
| 1341 // yOffset after adding the elements. | 1387 // yOffset after adding the elements. |
| 1342 - (void)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles | 1388 - (CGFloat)buildFastUserSwitcherViewWithProfiles:(NSMutableArray*)otherProfiles |
|
groby-ooo-7-16
2016/07/20 20:54:22
Is there any reason this needs to be a mutable arr
Jane
2016/07/20 22:03:46
I think it's because this array needs the dynamic
groby-ooo-7-16
2016/07/21 00:01:46
You need that only at construction time, though. T
Jane
2016/07/21 13:49:52
Done. Ah, I see what you mean! I changed it to be
| |
| 1343 atYOffset:(CGFloat)yOffset | 1389 atYOffset:(CGFloat)yOffset |
| 1344 inContainer:(NSView*)container { | 1390 inContainer:(NSView*)container { |
| 1345 // Other profiles switcher. The profiles have already been sorted | 1391 // Other profiles switcher. The profiles have already been sorted |
| 1346 // by their y-coordinate, so they can be added in the existing order. | 1392 // by their y-coordinate, so they can be added in the existing order. |
| 1347 for (NSView* otherProfileView in otherProfiles) { | 1393 for (NSView* otherProfileView in otherProfiles) { |
| 1348 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; | 1394 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; |
| 1349 [container addSubview:otherProfileView]; | 1395 [container addSubview:otherProfileView]; |
| 1350 yOffset = NSMaxY([otherProfileView frame]); | 1396 yOffset = NSMaxY([otherProfileView frame]); |
| 1351 | 1397 |
| 1352 yOffset = [self addSeparatorToContainer:container atYOffset: yOffset]; | 1398 if (!switches::IsMaterialDesignUserMenu()) |
| 1399 yOffset = [self addSeparatorToContainer:container atYOffset:yOffset]; | |
| 1353 } | 1400 } |
| 1354 | 1401 |
| 1355 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; | 1402 [container setFrameSize:NSMakeSize(GetFixedMenuWidth(), yOffset)]; |
| 1403 return yOffset; | |
| 1356 } | 1404 } |
| 1357 | 1405 |
| 1358 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView | 1406 - (void)buildProfileChooserViewWithProfileView:(NSView*)currentProfileView |
| 1359 tutorialView:(NSView*)tutorialView | 1407 tutorialView:(NSView*)tutorialView |
| 1408 otherProfiles:(NSMutableArray*)otherProfiles | |
| 1360 atYOffset:(CGFloat)yOffset | 1409 atYOffset:(CGFloat)yOffset |
| 1361 inContainer:(NSView*)container | 1410 inContainer:(NSView*)container |
| 1362 displayLock:(bool)displayLock { | 1411 displayLock:(bool)displayLock { |
| 1412 if (switches::IsMaterialDesignUserMenu()) | |
| 1413 yOffset += kRelatedControllVerticalSpacing; | |
| 1414 | |
| 1363 // Option buttons. | 1415 // Option buttons. |
| 1364 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); | 1416 NSRect rect = NSMakeRect(0, yOffset, GetFixedMenuWidth(), 0); |
| 1365 NSView* optionsView = [self createOptionsViewWithRect:rect | 1417 NSView* optionsView = |
| 1366 displayLock:displayLock]; | 1418 switches::IsMaterialDesignUserMenu() |
| 1419 ? [self createMaterialDesignOptionsViewWithRect:rect | |
| 1420 displayLock:displayLock] | |
| 1421 : [self createOptionsViewWithRect:rect displayLock:displayLock]; | |
| 1367 [container addSubview:optionsView]; | 1422 [container addSubview:optionsView]; |
| 1368 rect.origin.y = NSMaxY([optionsView frame]); | 1423 rect.origin.y = NSMaxY([optionsView frame]); |
| 1424 yOffset = rect.origin.y; | |
| 1425 | |
| 1426 // For material design user menu, add the fast user switching buttons. | |
| 1427 if (switches::IsMaterialDesignUserMenu()) { | |
| 1428 yOffset = [self buildFastUserSwitcherViewWithProfiles:otherProfiles | |
| 1429 atYOffset:yOffset | |
| 1430 inContainer:container]; | |
| 1431 yOffset += kRelatedControllVerticalSpacing; | |
| 1432 rect.origin.y = yOffset; | |
| 1433 } | |
| 1369 | 1434 |
| 1370 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; | 1435 NSBox* separator = [self horizontalSeparatorWithFrame:rect]; |
| 1371 [container addSubview:separator]; | 1436 [container addSubview:separator]; |
| 1372 yOffset = NSMaxY([separator frame]); | 1437 yOffset = NSMaxY([separator frame]); |
| 1373 | 1438 |
| 1374 // For supervised users, add the disclaimer text. | 1439 // For supervised users, add the disclaimer text. |
| 1375 if (browser_->profile()->IsSupervised()) { | 1440 if (browser_->profile()->IsSupervised()) { |
| 1376 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing | 1441 yOffset += switches::IsMaterialDesignUserMenu() ? kVerticalSpacing |
| 1377 : kSmallVerticalSpacing; | 1442 : kSmallVerticalSpacing; |
| 1378 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; | 1443 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1458 } | 1523 } |
| 1459 if (!currentProfileView) // Guest windows don't have an active profile. | 1524 if (!currentProfileView) // Guest windows don't have an active profile. |
| 1460 currentProfileView = [self createGuestProfileView]; | 1525 currentProfileView = [self createGuestProfileView]; |
| 1461 | 1526 |
| 1462 // |yOffset| is the next position at which to draw in |container| | 1527 // |yOffset| is the next position at which to draw in |container| |
| 1463 // coordinates. Add a pixel offset so that the bottom option buttons don't | 1528 // coordinates. Add a pixel offset so that the bottom option buttons don't |
| 1464 // overlap the bubble's rounded corners. | 1529 // overlap the bubble's rounded corners. |
| 1465 CGFloat yOffset = 1; | 1530 CGFloat yOffset = 1; |
| 1466 | 1531 |
| 1467 if (isFastProfileChooser) { | 1532 if (isFastProfileChooser) { |
| 1468 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() | 1533 if (!switches::IsMaterialDesignUserMenu()) { |
| 1469 atYOffset:yOffset | 1534 [self buildFastUserSwitcherViewWithProfiles:otherProfiles.get() |
| 1470 inContainer:container.get()]; | 1535 atYOffset:yOffset |
| 1536 inContainer:container.get()]; | |
|
groby-ooo-7-16
2016/07/20 20:54:22
No reason for .get(), I think.
Jane
2016/07/20 22:03:46
Done. I'm assuming all the .get()'s here? (What is
groby-ooo-7-16
2016/07/21 00:01:46
get() is usually used if the types don't match exa
Jane
2016/07/21 13:49:52
Ah, I see! Now that I modified these two methods t
| |
| 1537 } | |
| 1471 } else { | 1538 } else { |
| 1472 [self buildProfileChooserViewWithProfileView:currentProfileView | 1539 [self buildProfileChooserViewWithProfileView:currentProfileView |
| 1473 tutorialView:tutorialView | 1540 tutorialView:tutorialView |
| 1541 otherProfiles:otherProfiles.get() | |
|
groby-ooo-7-16
2016/07/20 20:54:22
see above
Jane
2016/07/20 22:03:46
Done.
| |
| 1474 atYOffset:yOffset | 1542 atYOffset:yOffset |
| 1475 inContainer:container.get() | 1543 inContainer:container.get() |
| 1476 displayLock:displayLock]; | 1544 displayLock:displayLock]; |
| 1477 } | 1545 } |
| 1478 | 1546 |
| 1479 return container.autorelease(); | 1547 return container.autorelease(); |
| 1480 } | 1548 } |
| 1481 | 1549 |
| 1482 - (NSView*)buildSigninConfirmationView { | 1550 - (NSView*)buildSigninConfirmationView { |
| 1483 ProfileMetrics::LogProfileNewAvatarMenuSignin( | 1551 ProfileMetrics::LogProfileNewAvatarMenuSignin( |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2075 return switches::IsMaterialDesignUserMenu() | 2143 return switches::IsMaterialDesignUserMenu() |
| 2076 ? [self createMaterialDesignCurrentProfileView:guestItem] | 2144 ? [self createMaterialDesignCurrentProfileView:guestItem] |
| 2077 : [self createCurrentProfileView:guestItem]; | 2145 : [self createCurrentProfileView:guestItem]; |
| 2078 } | 2146 } |
| 2079 | 2147 |
| 2080 - (NSButton*)createOtherProfileView:(int)itemIndex { | 2148 - (NSButton*)createOtherProfileView:(int)itemIndex { |
| 2081 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); | 2149 const AvatarMenu::Item& item = avatarMenu_->GetItemAt(itemIndex); |
| 2082 | 2150 |
| 2083 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), | 2151 NSRect rect = NSMakeRect(0, 0, GetFixedMenuWidth(), |
| 2084 kBlueButtonHeight + kSmallVerticalSpacing); | 2152 kBlueButtonHeight + kSmallVerticalSpacing); |
| 2153 const int imageTitleSpacing = switches::IsMaterialDesignUserMenu() | |
| 2154 ? kHorizontalSpacing | |
| 2155 : kImageTitleSpacing; | |
| 2085 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( | 2156 base::scoped_nsobject<BackgroundColorHoverButton> profileButton( |
| 2086 [[BackgroundColorHoverButton alloc] | 2157 [[BackgroundColorHoverButton alloc] |
| 2087 initWithFrame:rect | 2158 initWithFrame:rect |
| 2088 imageTitleSpacing:kImageTitleSpacing | 2159 imageTitleSpacing:imageTitleSpacing |
| 2089 backgroundColor:GetDialogBackgroundColor()]); | 2160 backgroundColor:GetDialogBackgroundColor()]); |
| 2161 if (switches::IsMaterialDesignUserMenu()) | |
| 2162 [profileButton addRightMarginSpacing:kHorizontalSpacing]; | |
| 2090 | 2163 |
| 2091 NSString* title = base::SysUTF16ToNSString( | 2164 NSString* title = base::SysUTF16ToNSString( |
| 2092 profiles::GetProfileSwitcherTextForItem(item)); | 2165 profiles::GetProfileSwitcherTextForItem(item)); |
| 2093 [profileButton setTitle:title]; | 2166 [profileButton setTitle:title]; |
| 2094 | 2167 |
| 2095 // Use the low-res, small default avatars in the fast user switcher, like | 2168 CGFloat availableWidth; |
| 2096 // we do in the menu bar. | 2169 if (switches::IsMaterialDesignUserMenu()) { |
| 2097 gfx::Image itemIcon; | 2170 int iconImageSide = 18; |
| 2098 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon); | 2171 [profileButton setDefaultImage:CreateProfileImage(item.icon, iconImageSide, |
| 2172 profiles::SHAPE_CIRCLE)]; | |
| 2173 availableWidth = rect.size.width - iconImageSide - imageTitleSpacing - | |
| 2174 2 * kHorizontalSpacing; | |
| 2175 } else { | |
| 2176 // Use the low-res, small default avatars in the fast user switcher, like | |
| 2177 // we do in the menu bar. | |
| 2178 gfx::Image itemIcon; | |
| 2179 AvatarMenu::GetImageForMenuButton(item.profile_path, &itemIcon); | |
| 2180 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide, | |
| 2181 profiles::SHAPE_SQUARE)]; | |
| 2182 availableWidth = rect.size.width - kSmallImageSide - imageTitleSpacing - | |
| 2183 kHorizontalSpacing; | |
| 2184 } | |
| 2099 | 2185 |
| 2100 [profileButton setDefaultImage:CreateProfileImage(itemIcon, kSmallImageSide, | |
| 2101 profiles::SHAPE_SQUARE)]; | |
| 2102 [profileButton setImagePosition:NSImageLeft]; | 2186 [profileButton setImagePosition:NSImageLeft]; |
| 2103 [profileButton setAlignment:NSLeftTextAlignment]; | 2187 [profileButton setAlignment:NSLeftTextAlignment]; |
| 2104 [profileButton setBordered:NO]; | 2188 [profileButton setBordered:NO]; |
| 2105 [profileButton setTag:itemIndex]; | 2189 [profileButton setTag:itemIndex]; |
| 2106 [profileButton setTarget:self]; | 2190 [profileButton setTarget:self]; |
| 2107 [profileButton setAction:@selector(switchToProfile:)]; | 2191 [profileButton setAction:@selector(switchToProfile:)]; |
| 2108 | 2192 |
| 2109 NSSize textSize = [[profileButton title] sizeWithAttributes:@{ | 2193 NSSize textSize = [[profileButton title] sizeWithAttributes:@{ |
| 2110 NSFontAttributeName : [profileButton font] | 2194 NSFontAttributeName : [profileButton font] |
| 2111 }]; | 2195 }]; |
| 2112 | 2196 |
| 2113 CGFloat availableWidth = rect.size.width - kSmallImageSide - | |
| 2114 kImageTitleSpacing - kHorizontalSpacing; | |
| 2115 | |
| 2116 if (std::ceil(textSize.width) > availableWidth) | 2197 if (std::ceil(textSize.width) > availableWidth) |
| 2117 [profileButton setToolTip:[profileButton title]]; | 2198 [profileButton setToolTip:[profileButton title]]; |
| 2118 | 2199 |
| 2119 return profileButton.autorelease(); | 2200 return profileButton.autorelease(); |
| 2120 } | 2201 } |
| 2121 | 2202 |
| 2122 - (NSView*)createOptionsViewWithRect:(NSRect)rect | 2203 - (NSView*)createOptionsViewWithRect:(NSRect)rect |
| 2123 displayLock:(BOOL)displayLock { | 2204 displayLock:(BOOL)displayLock { |
| 2124 NSRect viewRect = NSMakeRect(0, 0, | 2205 NSRect viewRect = NSMakeRect(0, 0, |
| 2125 rect.size.width, | 2206 rect.size.width, |
| 2126 kBlueButtonHeight + kSmallVerticalSpacing); | 2207 kBlueButtonHeight + kSmallVerticalSpacing); |
| 2127 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 2208 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
| 2128 | 2209 |
| 2129 if (displayLock) { | 2210 if (displayLock) { |
| 2130 NSButton* lockButton = | 2211 NSButton* lockButton = |
| 2131 [self hoverButtonWithRect:viewRect | 2212 [self hoverButtonWithRect:viewRect |
| 2132 text:l10n_util::GetNSString( | 2213 text:l10n_util::GetNSString( |
| 2133 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) | 2214 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) |
| 2134 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK | 2215 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK |
| 2135 action:@selector(lockProfile:)]; | 2216 action:@selector(lockProfile:)]; |
| 2136 [container addSubview:lockButton]; | 2217 [container addSubview:lockButton]; |
| 2137 viewRect.origin.y = NSMaxY([lockButton frame]); | 2218 viewRect.origin.y = NSMaxY([lockButton frame]); |
| 2138 | 2219 |
| 2139 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | 2220 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; |
| 2140 [container addSubview:separator]; | 2221 [container addSubview:separator]; |
| 2141 viewRect.origin.y = NSMaxY([separator frame]); | 2222 viewRect.origin.y = NSMaxY([separator frame]); |
| 2142 } | 2223 } |
| 2143 | 2224 |
| 2144 if (!switches::IsMaterialDesignUserMenu() && [self shouldShowGoIncognito]) { | 2225 if ([self shouldShowGoIncognito]) { |
| 2145 NSButton* goIncognitoButton = | 2226 NSButton* goIncognitoButton = |
| 2146 [self hoverButtonWithRect:viewRect | 2227 [self hoverButtonWithRect:viewRect |
| 2147 text:l10n_util::GetNSString( | 2228 text:l10n_util::GetNSString( |
| 2148 IDS_PROFILES_GO_INCOGNITO_BUTTON) | 2229 IDS_PROFILES_GO_INCOGNITO_BUTTON) |
| 2149 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO | 2230 imageResourceId:IDR_ICON_PROFILES_MENU_INCOGNITO |
| 2150 action:@selector(goIncognito:)]; | 2231 action:@selector(goIncognito:)]; |
| 2151 viewRect.origin.y = NSMaxY([goIncognitoButton frame]); | 2232 viewRect.origin.y = NSMaxY([goIncognitoButton frame]); |
| 2152 [container addSubview:goIncognitoButton]; | 2233 [container addSubview:goIncognitoButton]; |
| 2153 | 2234 |
| 2154 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; | 2235 NSBox* separator = [self horizontalSeparatorWithFrame:viewRect]; |
| 2155 [container addSubview:separator]; | 2236 [container addSubview:separator]; |
| 2156 viewRect.origin.y = NSMaxY([separator frame]); | 2237 viewRect.origin.y = NSMaxY([separator frame]); |
| 2157 } | 2238 } |
| 2158 | 2239 |
| 2159 NSString* text = isGuestSession_ ? | 2240 NSString* text = isGuestSession_ ? |
| 2160 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) : | 2241 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) : |
| 2161 l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON); | 2242 l10n_util::GetNSString(IDS_PROFILES_SWITCH_USERS_BUTTON); |
| 2162 if (!isGuestSession_ && switches::IsMaterialDesignUserMenu()) { | |
| 2163 text = l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON); | |
| 2164 } | |
| 2165 NSButton* switchUsersButton = | 2243 NSButton* switchUsersButton = |
| 2166 [self hoverButtonWithRect:viewRect | 2244 [self hoverButtonWithRect:viewRect |
| 2167 text:text | 2245 text:text |
| 2168 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR | 2246 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR |
| 2169 action:isGuestSession_? @selector(exitGuest:) : | 2247 action:isGuestSession_? @selector(exitGuest:) : |
| 2170 @selector(showUserManager:)]; | 2248 @selector(showUserManager:)]; |
| 2171 viewRect.origin.y = NSMaxY([switchUsersButton frame]); | 2249 viewRect.origin.y = NSMaxY([switchUsersButton frame]); |
| 2172 [container addSubview:switchUsersButton]; | 2250 [container addSubview:switchUsersButton]; |
| 2173 | 2251 |
| 2174 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; | 2252 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2209 | 2287 |
| 2210 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( | 2288 NSView* accountEmails = [self createAccountsListWithRect:NSMakeRect( |
| 2211 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; | 2289 0, rect.origin.y, rect.size.width, kAccountButtonHeight)]; |
| 2212 [container addSubview:accountEmails]; | 2290 [container addSubview:accountEmails]; |
| 2213 | 2291 |
| 2214 [container setFrameSize:NSMakeSize(rect.size.width, | 2292 [container setFrameSize:NSMakeSize(rect.size.width, |
| 2215 NSMaxY([accountEmails frame]))]; | 2293 NSMaxY([accountEmails frame]))]; |
| 2216 return container.autorelease(); | 2294 return container.autorelease(); |
| 2217 } | 2295 } |
| 2218 | 2296 |
| 2297 - (NSView*)createMaterialDesignOptionsViewWithRect:(NSRect)rect | |
|
groby-ooo-7-16
2016/07/20 20:54:22
Traditionally, this would be named create...WithFr
Jane
2016/07/20 22:03:46
Done. But there are soo many methods called create
groby-ooo-7-16
2016/07/21 00:01:46
I know - that's why I said the ship has sailed for
| |
| 2298 displayLock:(BOOL)displayLock { | |
|
groby-ooo-7-16
2016/07/20 20:54:22
showLock: instead of displayLock: is usually the c
Jane
2016/07/20 22:03:46
Done. I went ahead to change all the displayLock -
| |
| 2299 NSRect viewRect = NSMakeRect(0, 0, rect.size.width, | |
| 2300 kBlueButtonHeight + kSmallVerticalSpacing); | |
| 2301 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | |
| 2302 const int material_icon_size = 20; | |
| 2303 | |
| 2304 // Create a lock profile button when supervised users exist; otherwise, create | |
| 2305 // a button that closes all of the current profile's windows if more than one | |
| 2306 // is open. | |
| 2307 if (displayLock) { | |
| 2308 NSButton* lockButton = | |
| 2309 [self hoverButtonWithRect:viewRect | |
| 2310 text:l10n_util::GetNSString( | |
| 2311 IDS_PROFILES_PROFILE_SIGNOUT_BUTTON) | |
| 2312 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 2313 gfx::VectorIconId::LOCK, | |
| 2314 material_icon_size, gfx::kChromeIconGrey)) | |
| 2315 action:@selector(lockProfile:)]; | |
| 2316 [container addSubview:lockButton]; | |
| 2317 viewRect.origin.y = NSMaxY([lockButton frame]); | |
| 2318 } else if (!isGuestSession_) { | |
| 2319 int num_browsers = 0; | |
| 2320 for (auto* browser : *BrowserList::GetInstance()) { | |
| 2321 if (browser->profile()->GetOriginalProfile() == | |
| 2322 browser_->profile()->GetOriginalProfile()) | |
|
groby-ooo-7-16
2016/07/20 20:54:22
nit: can you hoist the rhs into a separate variabl
Jane
2016/07/20 22:03:46
Done.
| |
| 2323 num_browsers++; | |
| 2324 } | |
| 2325 if (num_browsers > 1) { | |
| 2326 NSButton* closeAllWindowsButton = [self | |
| 2327 hoverButtonWithRect:viewRect | |
| 2328 text:l10n_util::GetNSString( | |
| 2329 IDS_PROFILES_CLOSE_ALL_WINDOWS_BUTTON) | |
| 2330 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 2331 gfx::VectorIconId::CLOSE_ALL, | |
| 2332 material_icon_size, gfx::kChromeIconGrey)) | |
| 2333 action:@selector(closeAllWindows:)]; | |
| 2334 [container addSubview:closeAllWindowsButton]; | |
| 2335 viewRect.origin.y = NSMaxY([closeAllWindowsButton frame]); | |
| 2336 } | |
| 2337 } | |
| 2338 | |
| 2339 // Create a manage users/exit guest button. | |
| 2340 NSString* text = | |
| 2341 isGuestSession_ | |
| 2342 ? l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) | |
| 2343 : l10n_util::GetNSString(IDS_PROFILES_MANAGE_USERS_BUTTON); | |
| 2344 NSImage* icon = NSImageFromImageSkia( | |
| 2345 gfx::CreateVectorIcon(isGuestSession_ ? gfx::VectorIconId::CLOSE_ALL | |
| 2346 : gfx::VectorIconId::SETTINGS, | |
| 2347 material_icon_size, gfx::kChromeIconGrey)); | |
| 2348 SEL action = | |
| 2349 isGuestSession_ ? @selector(exitGuest:) : @selector(showUserManager:); | |
| 2350 NSButton* manageUsersButton = | |
| 2351 [self hoverButtonWithRect:viewRect text:text image:icon action:action]; | |
| 2352 viewRect.origin.y = NSMaxY([manageUsersButton frame]); | |
| 2353 [container addSubview:manageUsersButton]; | |
| 2354 | |
| 2355 // Create a guest profile button. | |
| 2356 if (!isGuestSession_) { | |
| 2357 PrefService* service = g_browser_process->local_state(); | |
|
groby-ooo-7-16
2016/07/20 20:54:22
See above question re: getting the prefs from |bro
Jane
2016/07/20 22:03:46
See above.
| |
| 2358 DCHECK(service); | |
| 2359 if (service->GetBoolean(prefs::kBrowserGuestModeEnabled)) { | |
| 2360 NSButton* guestProfileButton = [self | |
| 2361 hoverButtonWithRect:viewRect | |
| 2362 text:l10n_util::GetNSString( | |
| 2363 IDS_PROFILES_GUEST_PROFILE_NAME) | |
| 2364 image:NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 2365 gfx::VectorIconId::ACCOUNT_CIRCLE, | |
| 2366 material_icon_size, gfx::kChromeIconGrey)) | |
| 2367 action:@selector(switchToGuest:)]; | |
| 2368 viewRect.origin.y = NSMaxY([guestProfileButton frame]); | |
| 2369 [container addSubview:guestProfileButton]; | |
| 2370 } | |
| 2371 } | |
| 2372 | |
| 2373 [container setFrameSize:NSMakeSize(rect.size.width, viewRect.origin.y)]; | |
| 2374 return container.autorelease(); | |
| 2375 } | |
| 2376 | |
| 2219 - (NSView*)createAccountsListWithRect:(NSRect)rect { | 2377 - (NSView*)createAccountsListWithRect:(NSRect)rect { |
| 2220 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); | 2378 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); |
| 2221 currentProfileAccounts_.clear(); | 2379 currentProfileAccounts_.clear(); |
| 2222 | 2380 |
| 2223 Profile* profile = browser_->profile(); | 2381 Profile* profile = browser_->profile(); |
| 2224 std::string primaryAccount = | 2382 std::string primaryAccount = |
| 2225 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); | 2383 SigninManagerFactory::GetForProfile(profile)->GetAuthenticatedAccountId(); |
| 2226 DCHECK(!primaryAccount.empty()); | 2384 DCHECK(!primaryAccount.empty()); |
| 2227 std::vector<std::string>accounts = | 2385 std::vector<std::string>accounts = |
| 2228 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); | 2386 profiles::GetSecondaryAccountsForProfile(profile, primaryAccount); |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2458 clickedOnLink:(id)link | 2616 clickedOnLink:(id)link |
| 2459 atIndex:(NSUInteger)charIndex { | 2617 atIndex:(NSUInteger)charIndex { |
| 2460 chrome::ShowSettings(browser_); | 2618 chrome::ShowSettings(browser_); |
| 2461 return YES; | 2619 return YES; |
| 2462 } | 2620 } |
| 2463 | 2621 |
| 2464 - (NSButton*)hoverButtonWithRect:(NSRect)rect | 2622 - (NSButton*)hoverButtonWithRect:(NSRect)rect |
| 2465 text:(NSString*)text | 2623 text:(NSString*)text |
| 2466 imageResourceId:(int)imageResourceId | 2624 imageResourceId:(int)imageResourceId |
| 2467 action:(SEL)action { | 2625 action:(SEL)action { |
| 2626 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
|
groby-ooo-7-16
2016/07/20 20:54:22
nit: Reference please.
Jane
2016/07/20 22:03:46
Done.
| |
| 2627 NSImage* image = rb->GetNativeImageNamed(imageResourceId).ToNSImage(); | |
| 2628 return [self hoverButtonWithRect:rect text:text image:image action:action]; | |
| 2629 } | |
| 2630 | |
| 2631 - (NSButton*)hoverButtonWithRect:(NSRect)rect | |
| 2632 text:(NSString*)text | |
| 2633 image:(NSImage*)image | |
| 2634 action:(SEL)action { | |
| 2468 BackgroundColorHoverButton* button = | 2635 BackgroundColorHoverButton* button = |
| 2469 [self hoverButtonWithRect:rect text:text action:action]; | 2636 [self hoverButtonWithRect:rect text:text action:action]; |
| 2470 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); | |
| 2471 NSImage* image = rb->GetNativeImageNamed(imageResourceId).ToNSImage(); | |
| 2472 [button setDefaultImage:image]; | 2637 [button setDefaultImage:image]; |
| 2473 [button setHoverImage:image]; | 2638 [button setHoverImage:image]; |
| 2474 [button setPressedImage:image]; | 2639 [button setPressedImage:image]; |
| 2475 [button setImagePosition:NSImageLeft]; | 2640 [button setImagePosition:NSImageLeft]; |
| 2476 | 2641 |
| 2477 return button; | 2642 return button; |
| 2478 } | 2643 } |
| 2479 | 2644 |
| 2480 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect | 2645 - (BackgroundColorHoverButton*)hoverButtonWithRect:(NSRect)rect |
| 2481 text:(NSString*)text | 2646 text:(NSString*)text |
| 2482 action:(SEL)action { | 2647 action:(SEL)action { |
| 2483 base::scoped_nsobject<BackgroundColorHoverButton> button( | 2648 base::scoped_nsobject<BackgroundColorHoverButton> button( |
| 2484 [[BackgroundColorHoverButton alloc] | 2649 [[BackgroundColorHoverButton alloc] |
| 2485 initWithFrame:rect | 2650 initWithFrame:rect |
| 2486 imageTitleSpacing:kImageTitleSpacing | 2651 imageTitleSpacing:switches::IsMaterialDesignUserMenu() |
| 2652 ? (kHorizontalSpacing - 2.0) | |
|
groby-ooo-7-16
2016/07/20 20:54:22
Why -2.0? (Please leave a comment explaining magic
Jane
2016/07/20 22:03:46
Done. Is this clear, and is this too long of a com
groby-ooo-7-16
2016/07/21 00:01:46
It's a bit long - but not exceedingly so. If you c
| |
| 2653 : kImageTitleSpacing | |
| 2487 backgroundColor:GetDialogBackgroundColor()]); | 2654 backgroundColor:GetDialogBackgroundColor()]); |
| 2488 | 2655 |
| 2489 [button setTitle:text]; | 2656 [button setTitle:text]; |
| 2490 [button setAlignment:NSLeftTextAlignment]; | 2657 [button setAlignment:NSLeftTextAlignment]; |
| 2491 [button setBordered:NO]; | 2658 [button setBordered:NO]; |
| 2492 [button setTarget:self]; | 2659 [button setTarget:self]; |
| 2493 [button setAction:action]; | 2660 [button setAction:action]; |
| 2494 | 2661 |
| 2495 return button.autorelease(); | 2662 return button.autorelease(); |
| 2496 } | 2663 } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2582 } | 2749 } |
| 2583 | 2750 |
| 2584 - (bool)shouldShowGoIncognito { | 2751 - (bool)shouldShowGoIncognito { |
| 2585 bool incognitoAvailable = | 2752 bool incognitoAvailable = |
| 2586 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != | 2753 IncognitoModePrefs::GetAvailability(browser_->profile()->GetPrefs()) != |
| 2587 IncognitoModePrefs::DISABLED; | 2754 IncognitoModePrefs::DISABLED; |
| 2588 return incognitoAvailable && !browser_->profile()->IsGuestSession(); | 2755 return incognitoAvailable && !browser_->profile()->IsGuestSession(); |
| 2589 } | 2756 } |
| 2590 | 2757 |
| 2591 @end | 2758 @end |
| OLD | NEW |