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

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

Issue 2369663002: [Material][Mac] Update User Account Button (Closed)
Patch Set: Comment update Created 4 years, 2 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"
11 #include "chrome/browser/profiles/profile_attributes_storage.h" 11 #include "chrome/browser/profiles/profile_attributes_storage.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h" 13 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/themes/theme_service.h" 14 #include "chrome/browser/themes/theme_service.h"
15 #include "chrome/browser/themes/theme_service_factory.h" 15 #include "chrome/browser/themes/theme_service_factory.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
19 #include "chrome/browser/ui/cocoa/l10n_util.h" 19 #include "chrome/browser/ui/cocoa/l10n_util.h"
20 #import "chrome/browser/ui/cocoa/profiles/avatar_button.h" 20 #import "chrome/browser/ui/cocoa/profiles/avatar_button.h"
21 #include "chrome/grit/generated_resources.h" 21 #include "chrome/grit/generated_resources.h"
22 #import "chrome/browser/themes/theme_properties.h"
22 #include "chrome/grit/theme_resources.h" 23 #include "chrome/grit/theme_resources.h"
23 #include "components/signin/core/common/profile_management_switches.h" 24 #include "components/signin/core/common/profile_management_switches.h"
24 #include "skia/ext/skia_utils_mac.h" 25 #include "skia/ext/skia_utils_mac.h"
25 #import "ui/base/cocoa/appkit_utils.h" 26 #import "ui/base/cocoa/appkit_utils.h"
26 #include "ui/base/l10n/l10n_util_mac.h" 27 #include "ui/base/l10n/l10n_util_mac.h"
27 #include "ui/base/material_design/material_design_controller.h" 28 #include "ui/base/material_design/material_design_controller.h"
28 #include "ui/base/nine_image_painter_factory.h" 29 #include "ui/base/nine_image_painter_factory.h"
29 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/gfx/color_palette.h" 31 #include "ui/gfx/color_palette.h"
31 #include "ui/gfx/image/image_skia_operations.h" 32 #include "ui/gfx/image/image_skia_operations.h"
32 #include "ui/gfx/image/image_skia_util_mac.h" 33 #include "ui/gfx/image/image_skia_util_mac.h"
33 #include "ui/gfx/paint_vector_icon.h" 34 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/gfx/vector_icons_public.h" 35 #include "ui/gfx/vector_icons_public.h"
35 36
36 namespace { 37 namespace {
37 38
38 const ui::NinePartImageIds kNormalBorderImageIds = 39 const SkColor kButtonHoverColor = SkColorSetARGB(20, 0, 0, 0);
39 IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); 40 const SkColor kButtonPressedColor = SkColorSetARGB(31, 0, 0, 0);
40 const ui::NinePartImageIds kHoverBorderImageIds = 41 const SkColor kAvatarIconColor = SkColorSetRGB(0x5a, 0x5a, 0x5a);
41 IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_HOVER);
42 const ui::NinePartImageIds kPressedBorderImageIds =
43 IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_PRESSED);
44 const ui::NinePartImageIds kThemedBorderImageIds =
45 IMAGE_GRID(IDR_AVATAR_THEMED_MAC_BUTTON_NORMAL);
46 42
47 NSImage* GetImageFromResourceID(int resourceId) { 43 // NSButtons have a default padding of 5px. The avatar buttons should have a
48 return ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 44 // padding of 6px.
49 resourceId).ToNSImage(); 45 const CGFloat kButtonHeight = 24;
50 } 46 const CGFloat kButtonExtraPadding = 6 - 5;
51 47
52 const SkColor kMaterialButtonHoverColor = SkColorSetARGB(20, 0, 0, 0); 48 // Extra padding for the signed out avatar button.
53 const SkColor kMaterialButtonPressedColor = SkColorSetARGB(31, 0, 0, 0); 49 const CGFloat kSignedOutWidthPadding = 2;
54 const SkColor kMaterialAvatarIconColor = SkColorSetRGB(0x5a, 0x5a, 0x5a);
55 50
56 CGFloat ButtonHeight() { 51 // Kern value for the avatar button title.
57 const CGFloat kButtonHeight = 28; 52 const CGFloat kTitleKern = 0.25;
58 const CGFloat kMaterialButtonHeight = 24;
59 return ui::MaterialDesignController::IsModeMaterial() ? kMaterialButtonHeight
60 : kButtonHeight;
61 }
62
63 // NSButtons have a default padding of 5px. Non-MD buttons should have a
64 // padding of 8px. Meanwhile, MD buttons should have a padding of 6px.
65 CGFloat ButtonExtraPadding() {
66 const CGFloat kDefaultPadding = 5;
67 const CGFloat kButtonExtraPadding = 8 - kDefaultPadding;
68 const CGFloat kMaterialButtonExtraPadding = 6 - kDefaultPadding;
69
70 return ui::MaterialDesignController::IsModeMaterial()
71 ? kMaterialButtonExtraPadding
72 : kButtonExtraPadding;
73 }
74
75 // Extra padding for the MD signed out avatar button.
76 const CGFloat kMaterialSignedOutWidthPadding = 2;
77
78 // Kern value for the MD avatar button title.
79 const CGFloat kMaterialTitleKern = 0.25;
80 53
81 } // namespace 54 } // namespace
82 55
83 // Button cell with a custom border given by a set of nine-patch image grids. 56 // Button cell with a custom border given by a set of nine-patch image grids.
84 @interface CustomThemeButtonCell : NSButtonCell { 57 @interface CustomThemeButtonCell : NSButtonCell {
85 @private 58 @private
86 BOOL isThemedWindow_; 59 BOOL isThemedWindow_;
87 BOOL hasError_; 60 BOOL hasError_;
88 } 61 }
89 - (void)setIsThemedWindow:(BOOL)isThemedWindow; 62 - (void)setIsThemedWindow:(BOOL)isThemedWindow;
90 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title; 63 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title;
91 64
92 @end 65 @end
93 66
94 @implementation CustomThemeButtonCell 67 @implementation CustomThemeButtonCell
95 - (id)initWithThemedWindow:(BOOL)isThemedWindow { 68 - (id)initWithThemedWindow:(BOOL)isThemedWindow {
96 if ((self = [super init])) { 69 if ((self = [super init])) {
97 isThemedWindow_ = isThemedWindow; 70 isThemedWindow_ = isThemedWindow;
98 hasError_ = false; 71 hasError_ = false;
99 } 72 }
100 return self; 73 return self;
101 } 74 }
102 75
103 - (NSSize)cellSize { 76 - (NSSize)cellSize {
104 NSSize buttonSize = [super cellSize]; 77 NSSize buttonSize = [super cellSize];
105 78
106 // An image and no error means we are drawing the generic button, which 79 // An image and no error means we are drawing the generic button, which
107 // is square. Otherwise, we are displaying the profile's name and an 80 // is square. Otherwise, we are displaying the profile's name and an
108 // optional authentication error icon. 81 // optional authentication error icon.
109 if ([self image] && !hasError_) { 82 if ([self image] && !hasError_)
110 buttonSize.width = ButtonHeight(); 83 buttonSize.width = kButtonHeight + kSignedOutWidthPadding;
111 if (ui::MaterialDesignController::IsModeMaterial()) 84 else
112 buttonSize.width += kMaterialSignedOutWidthPadding; 85 buttonSize.width += 2 * kButtonExtraPadding;
113 } else { 86
114 buttonSize.width += 2 * ButtonExtraPadding(); 87 buttonSize.height = kButtonHeight;
115 }
116 buttonSize.height = ButtonHeight();
117 return buttonSize; 88 return buttonSize;
118 } 89 }
119 90
120 - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView*)controlView { 91 - (void)drawInteriorWithFrame:(NSRect)frame inView:(NSView*)controlView {
121 NSRect frameAfterPadding = NSInsetRect(frame, ButtonExtraPadding(), 0); 92 NSRect frameAfterPadding = NSInsetRect(frame, kButtonExtraPadding, 0);
122 [super drawInteriorWithFrame:frameAfterPadding inView:controlView]; 93 [super drawInteriorWithFrame:frameAfterPadding inView:controlView];
123 } 94 }
124 95
125 - (void)drawImage:(NSImage*)image 96 - (void)drawImage:(NSImage*)image
126 withFrame:(NSRect)frame 97 withFrame:(NSRect)frame
127 inView:(NSView*)controlView { 98 inView:(NSView*)controlView {
128 // The image used in the generic button case as well as the material-designed 99 // The image used in the generic button case as well as the material-designed
129 // error icon both need to be shifted down slightly to be centered correctly. 100 // error icon both need to be shifted down slightly to be centered correctly.
130 // TODO(noms): When the assets are fixed, remove this latter offset. 101 // TODO(noms): When the assets are fixed, remove this latter offset.
131 if (!hasError_ || switches::IsMaterialDesignUserMenu()) 102 if (!hasError_ || switches::IsMaterialDesignUserMenu())
132 frame = NSOffsetRect(frame, 0, 1); 103 frame = NSOffsetRect(frame, 0, 1);
133 [super drawImage:image withFrame:frame inView:controlView]; 104 [super drawImage:image withFrame:frame inView:controlView];
134 } 105 }
135 106
136 - (void)drawBezelWithFrame:(NSRect)frame 107 - (void)drawBezelWithFrame:(NSRect)frame
137 inView:(NSView*)controlView { 108 inView:(NSView*)controlView {
138 HoverState hoverState = 109 HoverState hoverState =
139 [base::mac::ObjCCastStrict<AvatarButton>(controlView) hoverState]; 110 [base::mac::ObjCCastStrict<AvatarButton>(controlView) hoverState];
140 111
141 if (ui::MaterialDesignController::IsModeMaterial()) { 112 NSColor* backgroundColor = nil;
142 NSColor* backgroundColor = nil; 113 if (hoverState == kHoverStateMouseDown)
143 if (hoverState == kHoverStateMouseDown) { 114 backgroundColor = skia::SkColorToSRGBNSColor(kButtonPressedColor);
144 backgroundColor = skia::SkColorToSRGBNSColor(kMaterialButtonPressedColor); 115 else if (hoverState == kHoverStateMouseOver)
145 } else if (hoverState == kHoverStateMouseOver) { 116 backgroundColor = skia::SkColorToSRGBNSColor(kButtonHoverColor);
146 backgroundColor = skia::SkColorToSRGBNSColor(kMaterialButtonHoverColor);
147 }
148 117
149 if (backgroundColor) { 118 if (backgroundColor) {
150 [backgroundColor set]; 119 [backgroundColor set];
151 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:frame 120 NSBezierPath* path = [NSBezierPath bezierPathWithRoundedRect:frame
152 xRadius:2.0f 121 xRadius:2.0f
153 yRadius:2.0f]; 122 yRadius:2.0f];
154 [path fill]; 123 [path fill];
155 }
156 } else {
157 ui::NinePartImageIds imageIds = kNormalBorderImageIds;
158 if (isThemedWindow_)
159 imageIds = kThemedBorderImageIds;
160
161 if (hoverState == kHoverStateMouseDown)
162 imageIds = kPressedBorderImageIds;
163 else if (hoverState == kHoverStateMouseOver)
164 imageIds = kHoverBorderImageIds;
165 ui::DrawNinePartImage(frame, imageIds, NSCompositeSourceOver, 1.0, true);
166 } 124 }
167 } 125 }
168 126
169 - (void)drawFocusRingMaskWithFrame:(NSRect)frame inView:(NSView*)view { 127 - (void)drawFocusRingMaskWithFrame:(NSRect)frame inView:(NSView*)view {
170 // Match the bezel's shape. 128 // Match the bezel's shape.
171 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 2, 2) 129 [[NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 2, 2)
172 xRadius:2 130 xRadius:2
173 yRadius:2] fill]; 131 yRadius:2] fill];
174 } 132 }
175 133
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 base::scoped_nsobject<NSButtonCell> cell( 170 base::scoped_nsobject<NSButtonCell> cell(
213 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); 171 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]);
214 172
215 [avatarButton setCell:cell.get()]; 173 [avatarButton setCell:cell.get()];
216 174
217 [avatarButton setWantsLayer:YES]; 175 [avatarButton setWantsLayer:YES];
218 [self setView:avatarButton]; 176 [self setView:avatarButton];
219 177
220 [avatarButton setBezelStyle:NSShadowlessSquareBezelStyle]; 178 [avatarButton setBezelStyle:NSShadowlessSquareBezelStyle];
221 [avatarButton setButtonType:NSMomentaryChangeButton]; 179 [avatarButton setButtonType:NSMomentaryChangeButton];
222 if (switches::IsMaterialDesignUserMenu()) 180 [[avatarButton cell] setHighlightsBy:NSNoCellMask];
223 [[avatarButton cell] setHighlightsBy:NSNoCellMask];
224 [avatarButton setBordered:YES]; 181 [avatarButton setBordered:YES];
225 182
226 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout()) 183 if (cocoa_l10n_util::ShouldDoExperimentalRTLLayout())
227 [avatarButton setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin]; 184 [avatarButton setAutoresizingMask:NSViewMaxXMargin | NSViewMinYMargin];
228 else 185 else
229 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; 186 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
230 [avatarButton setTarget:self]; 187 [avatarButton setTarget:self];
231 [avatarButton setAction:@selector(buttonClicked:)]; 188 [avatarButton setAction:@selector(buttonClicked:)];
232 [avatarButton setRightAction:@selector(buttonRightClicked:)]; 189 [avatarButton setRightAction:@selector(buttonRightClicked:)];
233 190
(...skipping 10 matching lines...) Expand all
244 } 201 }
245 return self; 202 return self;
246 } 203 }
247 204
248 - (void)dealloc { 205 - (void)dealloc {
249 [[NSNotificationCenter defaultCenter] removeObserver:self]; 206 [[NSNotificationCenter defaultCenter] removeObserver:self];
250 [super dealloc]; 207 [super dealloc];
251 } 208 }
252 209
253 - (void)themeDidChangeNotification:(NSNotification*)aNotification { 210 - (void)themeDidChangeNotification:(NSNotification*)aNotification {
254 // Redraw the button if the window has switched between themed and native.
255 ThemeService* themeService = 211 ThemeService* themeService =
256 ThemeServiceFactory::GetForProfile(browser_->profile()); 212 ThemeServiceFactory::GetForProfile(browser_->profile());
257 BOOL updatedIsThemedWindow = !themeService->UsingSystemTheme(); 213 BOOL updatedIsThemedWindow = !themeService->UsingSystemTheme();
258 if (isThemedWindow_ != updatedIsThemedWindow) { 214 isThemedWindow_ = updatedIsThemedWindow;
259 isThemedWindow_ = updatedIsThemedWindow; 215 [[button_ cell] setIsThemedWindow:isThemedWindow_];
260 [[button_ cell] setIsThemedWindow:isThemedWindow_]; 216 [self updateAvatarButtonAndLayoutParent:YES];
261 [self updateAvatarButtonAndLayoutParent:YES];
262 }
263 } 217 }
264 218
265 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { 219 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent {
266 // The button text has a black foreground and a white drop shadow for regular 220 // The button text has a black foreground. If the window is themed, then the
267 // windows, and a light text with a dark drop shadow for guest windows 221 // text color should match the active tab's text color.
268 // which are themed with a dark background. If we're using MD, then there
269 // should be no drop shadows.
270 BOOL isMaterial = ui::MaterialDesignController::IsModeMaterial();
271
272 NSColor* foregroundColor; 222 NSColor* foregroundColor;
273 if (browser_->profile()->IsGuestSession() && isMaterial) 223 const ui::ThemeProvider* theme =
274 foregroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:0.9]; 224 &ThemeService::GetThemeProviderForProfile(browser_->profile());
275 else if (!isThemedWindow_) 225 foregroundColor = theme ? theme->GetNSColor(ThemeProperties::COLOR_TAB_TEXT)
276 foregroundColor = [NSColor blackColor]; 226 : [NSColor blackColor];
shrike 2016/09/28 21:35:30 Seems like you still need to handle the case where
spqchan 2016/09/28 21:39:36 I don't think that's necessary since Guest Session
shrike 2016/09/28 23:58:50 The only thing is the text is drawn specially (in
277 else
278 foregroundColor = [NSColor blackColor];
279 227
280 ProfileAttributesStorage& storage = 228 ProfileAttributesStorage& storage =
281 g_browser_process->profile_manager()->GetProfileAttributesStorage(); 229 g_browser_process->profile_manager()->GetProfileAttributesStorage();
282 // If there is a single local profile, then use the generic avatar button 230 // If there is a single local profile, then use the generic avatar button
283 // instead of the profile name. Never use the generic button if the active 231 // instead of the profile name. Never use the generic button if the active
284 // profile is Guest. 232 // profile is Guest.
285 bool useGenericButton = 233 bool useGenericButton =
286 !browser_->profile()->IsGuestSession() && 234 !browser_->profile()->IsGuestSession() &&
287 storage.GetNumberOfProfiles() == 1 && 235 storage.GetNumberOfProfiles() == 1 &&
288 !storage.GetAllProfilesAttributes().front()->IsAuthenticated(); 236 !storage.GetAllProfilesAttributes().front()->IsAuthenticated();
289 237
290 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ? 238 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ?
291 base::string16() : 239 base::string16() :
292 profiles::GetAvatarButtonTextForProfile(browser_->profile())); 240 profiles::GetAvatarButtonTextForProfile(browser_->profile()));
293 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle]; 241 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle];
294 242
295 AvatarButton* button = 243 AvatarButton* button =
296 base::mac::ObjCCastStrict<AvatarButton>(button_); 244 base::mac::ObjCCastStrict<AvatarButton>(button_);
297 245
298 if (useGenericButton) { 246 if (useGenericButton) {
299 if (isMaterial) { 247 NSImage* avatarIcon = NSImageFromImageSkia(gfx::CreateVectorIcon(
300 NSImage* avatarIcon = NSImageFromImageSkia( 248 gfx::VectorIconId::USER_ACCOUNT_AVATAR, 18, kAvatarIconColor));
301 gfx::CreateVectorIcon(gfx::VectorIconId::USER_ACCOUNT_AVATAR, 18, 249 [button setDefaultImage:avatarIcon];
302 kMaterialAvatarIconColor)); 250 [button setHoverImage:nil];
303 [button setDefaultImage:avatarIcon]; 251 [button setPressedImage:nil];
304 [button setHoverImage:nil];
305 [button setPressedImage:nil];
306 } else {
307 [button setDefaultImage:GetImageFromResourceID(
308 IDR_AVATAR_NATIVE_BUTTON_AVATAR)];
309 [button setHoverImage:GetImageFromResourceID(
310 IDR_AVATAR_NATIVE_BUTTON_AVATAR_HOVER)];
311 [button setPressedImage:GetImageFromResourceID(
312 IDR_AVATAR_NATIVE_BUTTON_AVATAR_PRESSED)];
313 // This is a workaround for an issue in the HoverImageButton where the
314 // button is initially sized incorrectly unless a default image is
315 // provided.
316 // See crbug.com/298501.
317 [button setImage:GetImageFromResourceID(IDR_AVATAR_NATIVE_BUTTON_AVATAR)];
318 }
319 [button setImagePosition:NSImageOnly]; 252 [button setImagePosition:NSImageOnly];
320 } else if (hasError_) { 253 } else if (hasError_) {
321 NSImage* errorIcon = 254 NSImage* errorIcon = NSImageFromImageSkia(gfx::CreateVectorIcon(
322 isMaterial 255 gfx::VectorIconId::SYNC_PROBLEM, 16, gfx::kGoogleRed700));
323 ? NSImageFromImageSkia(gfx::CreateVectorIcon(
324 gfx::VectorIconId::SYNC_PROBLEM, 16, gfx::kGoogleRed700))
325 : GetImageFromResourceID(IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR);
326 [button setDefaultImage:errorIcon]; 256 [button setDefaultImage:errorIcon];
327 [button setHoverImage:nil]; 257 [button setHoverImage:nil];
328 [button setPressedImage:nil]; 258 [button setPressedImage:nil];
329 [button setImage:errorIcon]; 259 [button setImage:errorIcon];
330 [button setImagePosition:isMaterial ? NSImageLeft : NSImageRight]; 260 [button setImagePosition:NSImageLeft];
331 } else { 261 } else {
332 [button setDefaultImage:nil]; 262 [button setDefaultImage:nil];
333 [button setHoverImage:nil]; 263 [button setHoverImage:nil];
334 [button setPressedImage:nil]; 264 [button setPressedImage:nil];
335 [button setImagePosition:NSNoImage]; 265 [button setImagePosition:NSNoImage];
336 } 266 }
337 267
338 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 268 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
339 [[NSMutableParagraphStyle alloc] init]); 269 [[NSMutableParagraphStyle alloc] init]);
340 [paragraphStyle setAlignment:NSLeftTextAlignment]; 270 [paragraphStyle setAlignment:NSLeftTextAlignment];
341 271
342 if (isMaterial) { 272 base::scoped_nsobject<NSAttributedString> attributedTitle(
343 base::scoped_nsobject<NSAttributedString> attributedTitle( 273 [[NSAttributedString alloc]
344 [[NSAttributedString alloc] 274 initWithString:buttonTitle
345 initWithString:buttonTitle 275 attributes:@{
346 attributes:@{ 276 NSForegroundColorAttributeName : foregroundColor,
347 NSForegroundColorAttributeName : foregroundColor, 277 NSParagraphStyleAttributeName : paragraphStyle,
348 NSParagraphStyleAttributeName : paragraphStyle, 278 NSKernAttributeName : [NSNumber numberWithFloat:kTitleKern]
349 NSKernAttributeName : 279 }]);
350 [NSNumber numberWithFloat:kMaterialTitleKern] 280 [button_ setAttributedTitle:attributedTitle];
351 }]);
352 [button_ setAttributedTitle:attributedTitle];
353 } else {
354 // Create the white drop shadow.
355 base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]);
356 [shadow setShadowOffset:NSMakeSize(0, -1)];
357 [shadow setShadowBlurRadius:0];
358 if (browser_->profile()->IsGuestSession())
359 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.4]];
360 else if (!isThemedWindow_)
361 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.7]];
362 else
363 [shadow setShadowColor:[NSColor colorWithCalibratedWhite:1.0 alpha:0.4]];
364 281
365 base::scoped_nsobject<NSAttributedString> attributedTitle(
366 [[NSAttributedString alloc]
367 initWithString:buttonTitle
368 attributes:@{
369 NSShadowAttributeName : shadow.get(),
370 NSForegroundColorAttributeName : foregroundColor,
371 NSParagraphStyleAttributeName : paragraphStyle
372 }]);
373 [button_ setAttributedTitle:attributedTitle];
374 }
375 [button_ sizeToFit]; 282 [button_ sizeToFit];
376 283
377 if (layoutParent) { 284 if (layoutParent) {
378 // Because the width of the button might have changed, the parent browser 285 // Because the width of the button might have changed, the parent browser
379 // frame needs to recalculate the button bounds and redraw it. 286 // frame needs to recalculate the button bounds and redraw it.
380 [[BrowserWindowController 287 [[BrowserWindowController
381 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] 288 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()]
382 layoutSubviews]; 289 layoutSubviews];
383 } 290 }
384 } 291 }
385 292
386 - (void)setErrorStatus:(BOOL)hasError { 293 - (void)setErrorStatus:(BOOL)hasError {
387 hasError_ = hasError; 294 hasError_ = hasError;
388 [self updateAvatarButtonAndLayoutParent:YES]; 295 [self updateAvatarButtonAndLayoutParent:YES];
389 } 296 }
390 297
391 @end 298 @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