| 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/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_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 imageIds = kHoverBorderImageIds; | 113 imageIds = kHoverBorderImageIds; |
| 114 ui::DrawNinePartImage(frame, imageIds, NSCompositeSourceOver, 1.0, true); | 114 ui::DrawNinePartImage(frame, imageIds, NSCompositeSourceOver, 1.0, true); |
| 115 } | 115 } |
| 116 | 116 |
| 117 - (void)setIsThemedWindow:(BOOL)isThemedWindow { | 117 - (void)setIsThemedWindow:(BOOL)isThemedWindow { |
| 118 isThemedWindow_ = isThemedWindow; | 118 isThemedWindow_ = isThemedWindow; |
| 119 } | 119 } |
| 120 | 120 |
| 121 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title { | 121 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title { |
| 122 hasError_ = hasError; | 122 hasError_ = hasError; |
| 123 if (hasError) { | 123 int messageId = hasError ? |
| 124 [self accessibilitySetOverrideValue:l10n_util::GetNSStringF( | 124 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME : |
| 125 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME, | 125 IDS_PROFILES_NEW_AVATAR_BUTTON_ACCESSIBLE_NAME; |
| 126 base::SysNSStringToUTF16(title)) | 126 |
| 127 forAttribute:NSAccessibilityTitleAttribute]; | 127 [self accessibilitySetOverrideValue:l10n_util::GetNSStringF( |
| 128 } else { | 128 messageId, base::SysNSStringToUTF16(title)) |
| 129 [self accessibilitySetOverrideValue:title | 129 forAttribute:NSAccessibilityTitleAttribute]; |
| 130 forAttribute:NSAccessibilityTitleAttribute]; | |
| 131 } | |
| 132 } | 130 } |
| 133 | 131 |
| 134 @end | 132 @end |
| 135 | 133 |
| 136 @interface AvatarButtonController (Private) | 134 @interface AvatarButtonController (Private) |
| 137 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; | 135 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
| 138 - (void)updateErrorStatus:(BOOL)hasError; | 136 - (void)updateErrorStatus:(BOOL)hasError; |
| 139 - (void)dealloc; | 137 - (void)dealloc; |
| 140 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 138 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
| 141 @end | 139 @end |
| (...skipping 10 matching lines...) Expand all Loading... |
| 152 [[HoverImageButton alloc] initWithFrame:NSZeroRect]; | 150 [[HoverImageButton alloc] initWithFrame:NSZeroRect]; |
| 153 button_.reset(hoverButton); | 151 button_.reset(hoverButton); |
| 154 base::scoped_nsobject<CustomThemeButtonCell> cell( | 152 base::scoped_nsobject<CustomThemeButtonCell> cell( |
| 155 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); | 153 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); |
| 156 [button_ setCell:cell.get()]; | 154 [button_ setCell:cell.get()]; |
| 157 | 155 |
| 158 // Check if the account already has an authentication error. | 156 // Check if the account already has an authentication error. |
| 159 SigninErrorController* errorController = | 157 SigninErrorController* errorController = |
| 160 profiles::GetSigninErrorController(browser->profile()); | 158 profiles::GetSigninErrorController(browser->profile()); |
| 161 hasError_ = errorController && errorController->HasError(); | 159 hasError_ = errorController && errorController->HasError(); |
| 162 [cell setHasError:hasError_ withTitle:nil]; | |
| 163 | 160 |
| 164 [button_ setWantsLayer:YES]; | 161 [button_ setWantsLayer:YES]; |
| 165 [self setView:button_]; | 162 [self setView:button_]; |
| 166 | 163 |
| 167 [button_ setBezelStyle:NSShadowlessSquareBezelStyle]; | 164 [button_ setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 168 [button_ setButtonType:NSMomentaryChangeButton]; | 165 [button_ setButtonType:NSMomentaryChangeButton]; |
| 169 [button_ setBordered:YES]; | 166 [button_ setBordered:YES]; |
| 170 | 167 |
| 171 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 168 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 172 [button_ setTarget:self]; | 169 [button_ setTarget:self]; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // instead of the profile name. Never use the generic button if the active | 223 // instead of the profile name. Never use the generic button if the active |
| 227 // profile is Guest. | 224 // profile is Guest. |
| 228 bool useGenericButton = (!browser_->profile()->IsGuestSession() && | 225 bool useGenericButton = (!browser_->profile()->IsGuestSession() && |
| 229 cache.GetNumberOfProfiles() == 1 && | 226 cache.GetNumberOfProfiles() == 1 && |
| 230 cache.GetUserNameOfProfileAtIndex(0).empty()); | 227 cache.GetUserNameOfProfileAtIndex(0).empty()); |
| 231 | 228 |
| 232 | 229 |
| 233 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ? | 230 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ? |
| 234 base::string16() : | 231 base::string16() : |
| 235 profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 232 profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 233 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle]; |
| 236 | 234 |
| 237 HoverImageButton* button = | 235 HoverImageButton* button = |
| 238 base::mac::ObjCCastStrict<HoverImageButton>(button_); | 236 base::mac::ObjCCastStrict<HoverImageButton>(button_); |
| 239 if (useGenericButton) { | 237 if (useGenericButton) { |
| 240 [button setDefaultImage:GetImageFromResourceID( | 238 [button setDefaultImage:GetImageFromResourceID( |
| 241 IDR_AVATAR_MAC_BUTTON_AVATAR)]; | 239 IDR_AVATAR_MAC_BUTTON_AVATAR)]; |
| 242 [button setHoverImage:GetImageFromResourceID( | 240 [button setHoverImage:GetImageFromResourceID( |
| 243 IDR_AVATAR_MAC_BUTTON_AVATAR_HOVER)]; | 241 IDR_AVATAR_MAC_BUTTON_AVATAR_HOVER)]; |
| 244 [button setPressedImage:GetImageFromResourceID( | 242 [button setPressedImage:GetImageFromResourceID( |
| 245 IDR_AVATAR_MAC_BUTTON_AVATAR_PRESSED)]; | 243 IDR_AVATAR_MAC_BUTTON_AVATAR_PRESSED)]; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Because the width of the button might have changed, the parent browser | 278 // Because the width of the button might have changed, the parent browser |
| 281 // frame needs to recalculate the button bounds and redraw it. | 279 // frame needs to recalculate the button bounds and redraw it. |
| 282 [[BrowserWindowController | 280 [[BrowserWindowController |
| 283 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] | 281 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] |
| 284 layoutSubviews]; | 282 layoutSubviews]; |
| 285 } | 283 } |
| 286 } | 284 } |
| 287 | 285 |
| 288 - (void)updateErrorStatus:(BOOL)hasError { | 286 - (void)updateErrorStatus:(BOOL)hasError { |
| 289 hasError_ = hasError; | 287 hasError_ = hasError; |
| 290 [[button_ cell] setHasError:hasError withTitle:[button_ title]]; | |
| 291 [self updateAvatarButtonAndLayoutParent:YES]; | 288 [self updateAvatarButtonAndLayoutParent:YES]; |
| 292 } | 289 } |
| 293 | 290 |
| 294 @end | 291 @end |
| OLD | NEW |