Chromium Code Reviews| Index: chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm b/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
| index 7bc7e0dd7f0162018f57e0037d74d6c5edac8d4e..e7e944ecf1a1363e29c6dce86563a3372cb9cd95 100644 |
| --- a/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
| +++ b/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
| @@ -49,6 +49,10 @@ const CGFloat kSignedOutWidthPadding = 2; |
| // Kern value for the avatar button title. |
| const CGFloat kTitleKern = 0.25; |
| +// Upper and lower bounds for determining if the frame's theme color is a |
| +// "dark" theme. This value is determined by trial and error. |
| +const CGFloat kFrameColorDarkUpperBound = 0.33; |
| + |
| } // namespace |
| // Button cell with a custom border given by a set of nine-patch image grids. |
| @@ -151,11 +155,14 @@ const CGFloat kTitleKern = 0.25; |
| - (void)setErrorStatus:(BOOL)hasError; |
| - (void)dealloc; |
| - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
| + |
| +// Called right after |window_| became/resigned the main window. |
| +- (void)mainWindowDidChangeNotification:(NSNotification*)aNotification; |
| @end |
| @implementation AvatarButtonController |
| -- (id)initWithBrowser:(Browser*)browser { |
| +- (id)initWithBrowser:(Browser*)browser window:(NSWindow*)window { |
| if ((self = [super initWithBrowser:browser])) { |
| ThemeService* themeService = |
| ThemeServiceFactory::GetForProfile(browser->profile()); |
| @@ -192,11 +199,22 @@ const CGFloat kTitleKern = 0.25; |
| hasError_ = profileObserver_->HasAvatarError(); |
| [self updateAvatarButtonAndLayoutParent:NO]; |
| + window_ = window; |
| + |
| NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| [center addObserver:self |
| selector:@selector(themeDidChangeNotification:) |
| name:kBrowserThemeDidChangeNotification |
| object:nil]; |
| + |
| + [center addObserver:self |
| + selector:@selector(mainWindowDidChangeNotification:) |
| + name:NSWindowDidBecomeMainNotification |
| + object:window]; |
| + [center addObserver:self |
| + selector:@selector(mainWindowDidChangeNotification:) |
| + name:NSWindowDidResignMainNotification |
| + object:window]; |
| } |
| return self; |
| } |
| @@ -215,15 +233,27 @@ const CGFloat kTitleKern = 0.25; |
| [self updateAvatarButtonAndLayoutParent:YES]; |
| } |
| +- (void)mainWindowDidChangeNotification:(NSNotification*)aNotification { |
| + [self updateAvatarButtonAndLayoutParent:NO]; |
| +} |
| + |
| - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { |
| // The button text has a black foreground and a white drop shadow for regular |
| // windows, and a light text with a dark drop shadow for guest windows |
| // which are themed with a dark background. |
| - NSColor* foregroundColor; |
| - const ui::ThemeProvider* theme = |
| + NSColor* foregroundColor = [NSColor blackColor]; |
| + const ui::ThemeProvider* themeProvider = |
| &ThemeService::GetThemeProviderForProfile(browser_->profile()); |
| - foregroundColor = theme ? theme->GetNSColor(ThemeProperties::COLOR_TAB_TEXT) |
| - : [NSColor blackColor]; |
| + const int propertyId = [window_ isMainWindow] |
| + ? ThemeProperties::COLOR_FRAME |
| + : ThemeProperties::COLOR_FRAME_INACTIVE; |
| + if (themeProvider && themeProvider->HasCustomColor(propertyId)) { |
| + NSColor* frameColor = themeProvider->GetNSColor(propertyId); |
| + frameColor = |
| + [frameColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace]; |
| + if (frameColor && [frameColor whiteComponent] < kFrameColorDarkUpperBound) |
| + foregroundColor = [NSColor whiteColor]; |
|
shrike
2017/01/26 22:10:13
It's too bad that we can't use a text color from t
spqchan
2017/01/26 22:39:37
Agree
|
| + } |
| ProfileAttributesStorage& storage = |
| g_browser_process->profile_manager()->GetProfileAttributesStorage(); |
| @@ -310,6 +340,7 @@ const CGFloat kTitleKern = 0.25; |
| - (void)bubbleWillClose:(NSNotification*)notif { |
| AvatarButton* button = base::mac::ObjCCastStrict<AvatarButton>(button_); |
| [button setIsActive:NO]; |
| + [self updateAvatarButtonAndLayoutParent:NO]; |
| [super bubbleWillClose:notif]; |
| } |