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

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

Issue 2347283003: [Material][Mac] Adjust User Account Button (Closed)
Patch Set: Fix for avi Created 4 years, 3 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const CGFloat kMaterialButtonExtraPadding = 6 - kDefaultPadding; 67 const CGFloat kMaterialButtonExtraPadding = 6 - kDefaultPadding;
68 68
69 return ui::MaterialDesignController::IsModeMaterial() 69 return ui::MaterialDesignController::IsModeMaterial()
70 ? kMaterialButtonExtraPadding 70 ? kMaterialButtonExtraPadding
71 : kButtonExtraPadding; 71 : kButtonExtraPadding;
72 } 72 }
73 73
74 // Extra padding for the MD signed out avatar button. 74 // Extra padding for the MD signed out avatar button.
75 const CGFloat kMaterialSignedOutWidthPadding = 2; 75 const CGFloat kMaterialSignedOutWidthPadding = 2;
76 76
77 // Kern value for the MD avatar button title.
78 const CGFloat kMaterialTitleKern = 0.25;
79
77 } // namespace 80 } // namespace
78 81
79 // Button cell with a custom border given by a set of nine-patch image grids. 82 // Button cell with a custom border given by a set of nine-patch image grids.
80 @interface CustomThemeButtonCell : NSButtonCell { 83 @interface CustomThemeButtonCell : NSButtonCell {
81 @private 84 @private
82 BOOL isThemedWindow_; 85 BOOL isThemedWindow_;
83 BOOL hasError_; 86 BOOL hasError_;
84 } 87 }
85 - (void)setIsThemedWindow:(BOOL)isThemedWindow; 88 - (void)setIsThemedWindow:(BOOL)isThemedWindow;
86 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title; 89 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title;
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (isThemedWindow_ != updatedIsThemedWindow) { 254 if (isThemedWindow_ != updatedIsThemedWindow) {
252 isThemedWindow_ = updatedIsThemedWindow; 255 isThemedWindow_ = updatedIsThemedWindow;
253 [[button_ cell] setIsThemedWindow:isThemedWindow_]; 256 [[button_ cell] setIsThemedWindow:isThemedWindow_];
254 [self updateAvatarButtonAndLayoutParent:YES]; 257 [self updateAvatarButtonAndLayoutParent:YES];
255 } 258 }
256 } 259 }
257 260
258 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 261 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
259 // The button text has a black foreground and a white drop shadow for regular 262 // The button text has a black foreground and a white drop shadow for regular
260 // windows, and a light text with a dark drop shadow for guest windows 263 // windows, and a light text with a dark drop shadow for guest windows
261 // which are themed with a dark background. 264 // which are themed with a dark background. If we're using MD, then there
262 base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); 265 // should be no drop shadows.
263 [shadow setShadowOffset:NSMakeSize(0, -1)]; 266 BOOL isMaterial = ui::MaterialDesignController::IsModeMaterial();
264 [shadow setShadowBlurRadius:0];
265 267
266 NSColor* foregroundColor; 268 NSColor* foregroundColor;
267 if (browser_->profile()->IsGuestSession() && 269 if (browser_->profile()->IsGuestSession() && isMaterial)
268 !ui::MaterialDesignController::IsModeMaterial()) {
269 foregroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.9]; 270 foregroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.9];
270 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.4]]; 271 else if (!isThemedWindow_)
271 } else if (!isThemedWindow_) {
272 foregroundColor = [NSColor blackColor]; 272 foregroundColor = [NSColor blackColor];
273 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.7]]; 273 else
274 } else {
275 foregroundColor = [NSColor blackColor]; 274 foregroundColor = [NSColor blackColor];
276 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.4]];
277 }
278 275
279 ProfileAttributesStorage& storage = 276 ProfileAttributesStorage& storage =
280 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 277 g_browser_process->profile_manager()->GetProfileAttributesStorage();
281 // If there is a single local profile, then use the generic avatar button 278 // If there is a single local profile, then use the generic avatar button
282 // instead of the profile name. Never use the generic button if the active 279 // instead of the profile name. Never use the generic button if the active
283 // profile is Guest. 280 // profile is Guest.
284 bool useGenericButton = 281 bool useGenericButton =
285 !browser_->profile()->IsGuestSession() && 282 !browser_->profile()->IsGuestSession() &&
286 storage.GetNumberOfProfiles() == 1 && 283 storage.GetNumberOfProfiles() == 1 &&
287 !storage.GetAllProfilesAttributes().front()->IsAuthenticated(); 284 !storage.GetAllProfilesAttributes().front()->IsAuthenticated();
288 285
289
290 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ? 286 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ?
291 base::string16() : 287 base::string16() :
292 profiles::GetAvatarButtonTextForProfile(browser_->profile())); 288 profiles::GetAvatarButtonTextForProfile(browser_->profile()));
293 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle]; 289 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle];
294 290
295 AvatarButton* button = 291 AvatarButton* button =
296 base::mac::ObjCCastStrict<AvatarButton>(button_); 292 base::mac::ObjCCastStrict<AvatarButton>(button_);
297 293
298 if (useGenericButton) { 294 if (useGenericButton) {
299 if (ui::MaterialDesignController::IsModeMaterial()) { 295 if (isMaterial) {
300 NSImage* avatarIcon = NSImageFromImageSkia( 296 NSImage* avatarIcon = NSImageFromImageSkia(
301 gfx::CreateVectorIcon(gfx::VectorIconId::USER_ACCOUNT_AVATAR, 18, 297 gfx::CreateVectorIcon(gfx::VectorIconId::USER_ACCOUNT_AVATAR, 18,
302 kMaterialAvatarIconColor)); 298 kMaterialAvatarIconColor));
303 [button setDefaultImage:avatarIcon]; 299 [button setDefaultImage:avatarIcon];
304 [button setHoverImage:nil]; 300 [button setHoverImage:nil];
305 [button setPressedImage:nil]; 301 [button setPressedImage:nil];
306 } else { 302 } else {
307 [button setDefaultImage:GetImageFromResourceID( 303 [button setDefaultImage:GetImageFromResourceID(
308 IDR_AVATAR_NATIVE_BUTTON_AVATAR)]; 304 IDR_AVATAR_NATIVE_BUTTON_AVATAR)];
309 [button setHoverImage:GetImageFromResourceID( 305 [button setHoverImage:GetImageFromResourceID(
310 IDR_AVATAR_NATIVE_BUTTON_AVATAR_HOVER)]; 306 IDR_AVATAR_NATIVE_BUTTON_AVATAR_HOVER)];
311 [button setPressedImage:GetImageFromResourceID( 307 [button setPressedImage:GetImageFromResourceID(
312 IDR_AVATAR_NATIVE_BUTTON_AVATAR_PRESSED)]; 308 IDR_AVATAR_NATIVE_BUTTON_AVATAR_PRESSED)];
313 // This is a workaround for an issue in the HoverImageButton where the 309 // This is a workaround for an issue in the HoverImageButton where the
314 // button is initially sized incorrectly unless a default image is 310 // button is initially sized incorrectly unless a default image is
315 // provided. 311 // provided.
316 // See crbug.com/298501. 312 // See crbug.com/298501.
317 [button setImage:GetImageFromResourceID(IDR_AVATAR_NATIVE_BUTTON_AVATAR)]; 313 [button setImage:GetImageFromResourceID(IDR_AVATAR_NATIVE_BUTTON_AVATAR)];
318 } 314 }
319 [button setImagePosition:NSImageOnly]; 315 [button setImagePosition:NSImageOnly];
320 } else if (hasError_) { 316 } else if (hasError_) {
321 BOOL isMaterial = ui::MaterialDesignController::IsModeMaterial();
322 NSImage* errorIcon = 317 NSImage* errorIcon =
323 isMaterial 318 isMaterial
324 ? NSImageFromImageSkia(gfx::CreateVectorIcon( 319 ? NSImageFromImageSkia(gfx::CreateVectorIcon(
325 gfx::VectorIconId::SYNC_PROBLEM, 16, gfx::kGoogleRed700)) 320 gfx::VectorIconId::SYNC_PROBLEM, 16, gfx::kGoogleRed700))
326 : GetImageFromResourceID(IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR); 321 : GetImageFromResourceID(IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR);
327 [button setDefaultImage:errorIcon]; 322 [button setDefaultImage:errorIcon];
328 [button setHoverImage:nil]; 323 [button setHoverImage:nil];
329 [button setPressedImage:nil]; 324 [button setPressedImage:nil];
330 [button setImage:errorIcon]; 325 [button setImage:errorIcon];
331 [button setImagePosition:isMaterial ? NSImageLeft : NSImageRight]; 326 [button setImagePosition:isMaterial ? NSImageLeft : NSImageRight];
332 } else { 327 } else {
333 [button setDefaultImage:nil]; 328 [button setDefaultImage:nil];
334 [button setHoverImage:nil]; 329 [button setHoverImage:nil];
335 [button setPressedImage:nil]; 330 [button setPressedImage:nil];
336 [button setImagePosition:NSNoImage]; 331 [button setImagePosition:NSNoImage];
337 } 332 }
338 333
339 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 334 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
340 [[NSMutableParagraphStyle alloc] init]); 335 [[NSMutableParagraphStyle alloc] init]);
341 [paragraphStyle setAlignment:NSLeftTextAlignment]; 336 [paragraphStyle setAlignment:NSLeftTextAlignment];
342 337
343 base::scoped_nsobject<NSAttributedString> attributedTitle( 338 if (isMaterial) {
344 [[NSAttributedString alloc] 339 base::scoped_nsobject<NSAttributedString> attributedTitle(
345 initWithString:buttonTitle 340 [[NSAttributedString alloc]
346 attributes:@{ NSShadowAttributeName : shadow.get(), 341 initWithString:buttonTitle
347 NSForegroundColorAttributeName : foregroundColor, 342 attributes:@{
348 NSParagraphStyleAttributeName : paragraphStyle }]); 343 NSForegroundColorAttributeName : foregroundColor,
349 [button_ setAttributedTitle:attributedTitle]; 344 NSParagraphStyleAttributeName : paragraphStyle,
345 NSKernAttributeName :
346 [NSNumber numberWithFloat:kMaterialTitleKern]
347 }]);
348 [button_ setAttributedTitle:attributedTitle];
349 } else {
350 // Create the white drop shadow.
351 base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]);
352 [shadow setShadowOffset:NSMakeSize(0, -1)];
353 [shadow setShadowBlurRadius:0];
354 if (browser_->profile()->IsGuestSession())
355 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.4]];
356 else if (!isThemedWindow_)
357 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.7]];
358 else
359 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.4]];
360
361 base::scoped_nsobject<NSAttributedString> attributedTitle(
362 [[NSAttributedString alloc]
363 initWithString:buttonTitle
364 attributes:@{
365 NSShadowAttributeName : shadow.get(),
366 NSForegroundColorAttributeName : foregroundColor,
367 NSParagraphStyleAttributeName : paragraphStyle
368 }]);
369 [button_ setAttributedTitle:attributedTitle];
370 }
350 [button_ sizeToFit]; 371 [button_ sizeToFit];
351 372
352 if (layoutParent) { 373 if (layoutParent) {
353 // Because the width of the button might have changed, the parent browser 374 // Because the width of the button might have changed, the parent browser
354 // frame needs to recalculate the button bounds and redraw it. 375 // frame needs to recalculate the button bounds and redraw it.
355 [[BrowserWindowController 376 [[BrowserWindowController
356 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] 377 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()]
357 layoutSubviews]; 378 layoutSubviews];
358 } 379 }
359 } 380 }
360 381
361 - (void)setErrorStatus:(BOOL)hasError { 382 - (void)setErrorStatus:(BOOL)hasError {
362 hasError_ = hasError; 383 hasError_ = hasError;
363 [self updateAvatarButtonAndLayoutParent:YES]; 384 [self updateAvatarButtonAndLayoutParent:YES];
364 } 385 }
365 386
366 @end 387 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698