Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(279)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm

Issue 2636473003: [Mac] Update the Text Color for the Avatar Button (Closed)
Patch Set: Fixed tests Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/avatar_button_controller.h" 5 #import "chrome/browser/ui/cocoa/profiles/avatar_button_controller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
9 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/profiles/profile_attributes_entry.h" 10 #include "chrome/browser/profiles/profile_attributes_entry.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 // NSButtons have a default padding of 5px. Buttons should have a padding of 42 // NSButtons have a default padding of 5px. Buttons should have a padding of
43 // 6px. 43 // 6px.
44 const CGFloat kButtonExtraPadding = 6 - 5; 44 const CGFloat kButtonExtraPadding = 6 - 5;
45 45
46 // Extra padding for the signed out avatar button. 46 // Extra padding for the signed out avatar button.
47 const CGFloat kSignedOutWidthPadding = 2; 47 const CGFloat kSignedOutWidthPadding = 2;
48 48
49 // Kern value for the avatar button title. 49 // Kern value for the avatar button title.
50 const CGFloat kTitleKern = 0.25; 50 const CGFloat kTitleKern = 0.25;
51 51
52 // Upper and lower bounds for determining if the frame's theme color is a
53 // "dark" theme. This value is determined by trial and error.
54 const CGFloat kFrameColorDarkUpperBound = 0.33;
55
52 } // namespace 56 } // namespace
53 57
54 // Button cell with a custom border given by a set of nine-patch image grids. 58 // Button cell with a custom border given by a set of nine-patch image grids.
55 @interface CustomThemeButtonCell : NSButtonCell { 59 @interface CustomThemeButtonCell : NSButtonCell {
56 @private 60 @private
57 BOOL isThemedWindow_; 61 BOOL isThemedWindow_;
58 BOOL hasError_; 62 BOOL hasError_;
59 } 63 }
60 - (void)setIsThemedWindow:(BOOL)isThemedWindow; 64 - (void)setIsThemedWindow:(BOOL)isThemedWindow;
61 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title; 65 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 forAttribute:NSAccessibilityTitleAttribute]; 148 forAttribute:NSAccessibilityTitleAttribute];
145 } 149 }
146 150
147 @end 151 @end
148 152
149 @interface AvatarButtonController (Private) 153 @interface AvatarButtonController (Private)
150 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 154 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
151 - (void)setErrorStatus:(BOOL)hasError; 155 - (void)setErrorStatus:(BOOL)hasError;
152 - (void)dealloc; 156 - (void)dealloc;
153 - (void)themeDidChangeNotification:(NSNotification*)aNotification; 157 - (void)themeDidChangeNotification:(NSNotification*)aNotification;
158
159 // Called right after |window_| became/resigned the main window.
160 - (void)mainWindowDidChangeNotification:(NSNotification*)aNotification;
154 @end 161 @end
155 162
156 @implementation AvatarButtonController 163 @implementation AvatarButtonController
157 164
158 - (id)initWithBrowser:(Browser*)browser { 165 - (id)initWithBrowser:(Browser*)browser window:(NSWindow*)window {
159 if ((self = [super initWithBrowser:browser])) { 166 if ((self = [super initWithBrowser:browser])) {
160 ThemeService* themeService = 167 ThemeService* themeService =
161 ThemeServiceFactory::GetForProfile(browser->profile()); 168 ThemeServiceFactory::GetForProfile(browser->profile());
162 isThemedWindow_ = !themeService->UsingSystemTheme(); 169 isThemedWindow_ = !themeService->UsingSystemTheme();
163 170
164 AvatarButton* avatarButton = 171 AvatarButton* avatarButton =
165 [[AvatarButton alloc] initWithFrame:NSZeroRect]; 172 [[AvatarButton alloc] initWithFrame:NSZeroRect];
166 button_.reset(avatarButton); 173 button_.reset(avatarButton);
167 174
168 base::scoped_nsobject<NSButtonCell> cell( 175 base::scoped_nsobject<NSButtonCell> cell(
(...skipping 16 matching lines...) Expand all
185 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; 192 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
186 [avatarButton setTarget:self]; 193 [avatarButton setTarget:self];
187 [avatarButton setAction:@selector(buttonClicked:)]; 194 [avatarButton setAction:@selector(buttonClicked:)];
188 [avatarButton setRightAction:@selector(buttonClicked:)]; 195 [avatarButton setRightAction:@selector(buttonClicked:)];
189 196
190 // Check if the account already has an authentication or sync error and 197 // Check if the account already has an authentication or sync error and
191 // initialize the avatar button UI. 198 // initialize the avatar button UI.
192 hasError_ = profileObserver_->HasAvatarError(); 199 hasError_ = profileObserver_->HasAvatarError();
193 [self updateAvatarButtonAndLayoutParent:NO]; 200 [self updateAvatarButtonAndLayoutParent:NO];
194 201
202 window_ = window;
203
195 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 204 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
196 [center addObserver:self 205 [center addObserver:self
197 selector:@selector(themeDidChangeNotification:) 206 selector:@selector(themeDidChangeNotification:)
198 name:kBrowserThemeDidChangeNotification 207 name:kBrowserThemeDidChangeNotification
199 object:nil]; 208 object:nil];
209
210 [center addObserver:self
211 selector:@selector(mainWindowDidChangeNotification:)
212 name:NSWindowDidBecomeMainNotification
213 object:window];
214 [center addObserver:self
215 selector:@selector(mainWindowDidChangeNotification:)
216 name:NSWindowDidResignMainNotification
217 object:window];
200 } 218 }
201 return self; 219 return self;
202 } 220 }
203 221
204 - (void)dealloc { 222 - (void)dealloc {
205 [[NSNotificationCenter defaultCenter] removeObserver:self]; 223 [[NSNotificationCenter defaultCenter] removeObserver:self];
206 [super dealloc]; 224 [super dealloc];
207 } 225 }
208 226
209 - (void)themeDidChangeNotification:(NSNotification*)aNotification { 227 - (void)themeDidChangeNotification:(NSNotification*)aNotification {
210 ThemeService* themeService = 228 ThemeService* themeService =
211 ThemeServiceFactory::GetForProfile(browser_->profile()); 229 ThemeServiceFactory::GetForProfile(browser_->profile());
212 BOOL updatedIsThemedWindow = !themeService->UsingSystemTheme(); 230 BOOL updatedIsThemedWindow = !themeService->UsingSystemTheme();
213 isThemedWindow_ = updatedIsThemedWindow; 231 isThemedWindow_ = updatedIsThemedWindow;
214 [[button_ cell] setIsThemedWindow:isThemedWindow_]; 232 [[button_ cell] setIsThemedWindow:isThemedWindow_];
215 [self updateAvatarButtonAndLayoutParent:YES]; 233 [self updateAvatarButtonAndLayoutParent:YES];
216 } 234 }
217 235
236 - (void)mainWindowDidChangeNotification:(NSNotification*)aNotification {
237 [self updateAvatarButtonAndLayoutParent:NO];
238 }
239
218 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 240 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
219 // The button text has a black foreground and a white drop shadow for regular 241 // The button text has a black foreground and a white drop shadow for regular
220 // windows, and a light text with a dark drop shadow for guest windows 242 // windows, and a light text with a dark drop shadow for guest windows
221 // which are themed with a dark background. 243 // which are themed with a dark background.
222 NSColor* foregroundColor; 244 NSColor* foregroundColor = [NSColor blackColor];
223 const ui::ThemeProvider* theme = 245 const ui::ThemeProvider* themeProvider =
224 &ThemeService::GetThemeProviderForProfile(browser_->profile()); 246 &ThemeService::GetThemeProviderForProfile(browser_->profile());
225 foregroundColor = theme ? theme->GetNSColor(ThemeProperties::COLOR_TAB_TEXT) 247 const int propertyId = [window_ isMainWindow]
226 : [NSColor blackColor]; 248 ? ThemeProperties::COLOR_FRAME
249 : ThemeProperties::COLOR_FRAME_INACTIVE;
250 if (themeProvider && themeProvider->HasCustomColor(propertyId)) {
251 NSColor* frameColor = themeProvider->GetNSColor(propertyId);
252 frameColor =
253 [frameColor colorUsingColorSpaceName:NSCalibratedWhiteColorSpace];
254 if (frameColor && [frameColor whiteComponent] < kFrameColorDarkUpperBound)
255 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
256 }
227 257
228 ProfileAttributesStorage& storage = 258 ProfileAttributesStorage& storage =
229 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 259 g_browser_process->profile_manager()->GetProfileAttributesStorage();
230 // If there is a single local profile, then use the generic avatar button 260 // If there is a single local profile, then use the generic avatar button
231 // instead of the profile name. Never use the generic button if the active 261 // instead of the profile name. Never use the generic button if the active
232 // profile is Guest. 262 // profile is Guest.
233 bool useGenericButton = 263 bool useGenericButton =
234 !browser_->profile()->IsGuestSession() && 264 !browser_->profile()->IsGuestSession() &&
235 storage.GetNumberOfProfiles() == 1 && 265 storage.GetNumberOfProfiles() == 1 &&
236 !storage.GetAllProfilesAttributes().front()->IsAuthenticated(); 266 !storage.GetAllProfilesAttributes().front()->IsAuthenticated();
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 withServiceType:serviceType 333 withServiceType:serviceType
304 fromAccessPoint:accessPoint]; 334 fromAccessPoint:accessPoint];
305 335
306 AvatarButton* button = base::mac::ObjCCastStrict<AvatarButton>(button_); 336 AvatarButton* button = base::mac::ObjCCastStrict<AvatarButton>(button_);
307 [button setIsActive:[[menuController_ window] isVisible]]; 337 [button setIsActive:[[menuController_ window] isVisible]];
308 } 338 }
309 339
310 - (void)bubbleWillClose:(NSNotification*)notif { 340 - (void)bubbleWillClose:(NSNotification*)notif {
311 AvatarButton* button = base::mac::ObjCCastStrict<AvatarButton>(button_); 341 AvatarButton* button = base::mac::ObjCCastStrict<AvatarButton>(button_);
312 [button setIsActive:NO]; 342 [button setIsActive:NO];
343 [self updateAvatarButtonAndLayoutParent:NO];
313 [super bubbleWillClose:notif]; 344 [super bubbleWillClose:notif];
314 } 345 }
315 346
316 @end 347 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698