| 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" |
| 11 #include "chrome/browser/profiles/profiles_state.h" | 11 #include "chrome/browser/profiles/profiles_state.h" |
| 12 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
| 13 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
| 14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
| 15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
| 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 16 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 17 #import "chrome/browser/ui/cocoa/profiles/avatar_button.h" |
| 17 #include "chrome/grit/generated_resources.h" | 18 #include "chrome/grit/generated_resources.h" |
| 18 #include "components/signin/core/browser/signin_error_controller.h" | 19 #include "components/signin/core/browser/signin_error_controller.h" |
| 19 #include "grit/theme_resources.h" | 20 #include "grit/theme_resources.h" |
| 20 #import "ui/base/cocoa/appkit_utils.h" | 21 #import "ui/base/cocoa/appkit_utils.h" |
| 21 #import "ui/base/cocoa/hover_image_button.h" | |
| 22 #include "ui/base/l10n/l10n_util_mac.h" | 22 #include "ui/base/l10n/l10n_util_mac.h" |
| 23 #include "ui/base/nine_image_painter_factory.h" | 23 #include "ui/base/nine_image_painter_factory.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 25 #include "ui/gfx/image/image_skia_operations.h" | 25 #include "ui/gfx/image/image_skia_operations.h" |
| 26 #include "ui/gfx/image/image_skia_util_mac.h" | 26 #include "ui/gfx/image/image_skia_util_mac.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 // NSButtons have a default padding of 5px. This button should have a padding | 30 // NSButtons have a default padding of 5px. This button should have a padding |
| 31 // of 8px. | 31 // of 8px. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 // slightly to be centered correctly. | 95 // slightly to be centered correctly. |
| 96 // TODO(noms): When the assets are fixed, remove this latter offset. | 96 // TODO(noms): When the assets are fixed, remove this latter offset. |
| 97 if (!hasError_) | 97 if (!hasError_) |
| 98 frame = NSOffsetRect(frame, 0, 1); | 98 frame = NSOffsetRect(frame, 0, 1); |
| 99 [super drawImage:image withFrame:frame inView:controlView]; | 99 [super drawImage:image withFrame:frame inView:controlView]; |
| 100 } | 100 } |
| 101 | 101 |
| 102 - (void)drawBezelWithFrame:(NSRect)frame | 102 - (void)drawBezelWithFrame:(NSRect)frame |
| 103 inView:(NSView*)controlView { | 103 inView:(NSView*)controlView { |
| 104 HoverState hoverState = | 104 HoverState hoverState = |
| 105 [base::mac::ObjCCastStrict<HoverImageButton>(controlView) hoverState]; | 105 [base::mac::ObjCCastStrict<AvatarButton>(controlView) hoverState]; |
| 106 ui::NinePartImageIds imageIds = kNormalBorderImageIds; | 106 ui::NinePartImageIds imageIds = kNormalBorderImageIds; |
| 107 if (isThemedWindow_) | 107 if (isThemedWindow_) |
| 108 imageIds = kThemedBorderImageIds; | 108 imageIds = kThemedBorderImageIds; |
| 109 | 109 |
| 110 if (hoverState == kHoverStateMouseDown) | 110 if (hoverState == kHoverStateMouseDown) |
| 111 imageIds = kPressedBorderImageIds; | 111 imageIds = kPressedBorderImageIds; |
| 112 else if (hoverState == kHoverStateMouseOver) | 112 else if (hoverState == kHoverStateMouseOver) |
| 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 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 139 @end | 139 @end |
| 140 | 140 |
| 141 @implementation AvatarButtonController | 141 @implementation AvatarButtonController |
| 142 | 142 |
| 143 - (id)initWithBrowser:(Browser*)browser { | 143 - (id)initWithBrowser:(Browser*)browser { |
| 144 if ((self = [super initWithBrowser:browser])) { | 144 if ((self = [super initWithBrowser:browser])) { |
| 145 ThemeService* themeService = | 145 ThemeService* themeService = |
| 146 ThemeServiceFactory::GetForProfile(browser->profile()); | 146 ThemeServiceFactory::GetForProfile(browser->profile()); |
| 147 isThemedWindow_ = !themeService->UsingSystemTheme(); | 147 isThemedWindow_ = !themeService->UsingSystemTheme(); |
| 148 | 148 |
| 149 HoverImageButton* hoverButton = | 149 AvatarButton* avatarButton = |
| 150 [[HoverImageButton alloc] initWithFrame:NSZeroRect]; | 150 [[AvatarButton alloc] initWithFrame:NSZeroRect]; |
| 151 button_.reset(hoverButton); | 151 button_.reset(avatarButton); |
| 152 base::scoped_nsobject<CustomThemeButtonCell> cell( | 152 base::scoped_nsobject<CustomThemeButtonCell> cell( |
| 153 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); | 153 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); |
| 154 [button_ setCell:cell.get()]; | 154 [avatarButton setCell:cell.get()]; |
| 155 | 155 |
| 156 // Check if the account already has an authentication error. | 156 // Check if the account already has an authentication error. |
| 157 SigninErrorController* errorController = | 157 SigninErrorController* errorController = |
| 158 profiles::GetSigninErrorController(browser->profile()); | 158 profiles::GetSigninErrorController(browser->profile()); |
| 159 hasError_ = errorController && errorController->HasError(); | 159 hasError_ = errorController && errorController->HasError(); |
| 160 | 160 |
| 161 [button_ setWantsLayer:YES]; | 161 [avatarButton setWantsLayer:YES]; |
| 162 [self setView:button_]; | 162 [self setView:avatarButton]; |
| 163 | 163 |
| 164 [button_ setBezelStyle:NSShadowlessSquareBezelStyle]; | 164 [avatarButton setBezelStyle:NSShadowlessSquareBezelStyle]; |
| 165 [button_ setButtonType:NSMomentaryChangeButton]; | 165 [avatarButton setButtonType:NSMomentaryChangeButton]; |
| 166 [button_ setBordered:YES]; | 166 [avatarButton setBordered:YES]; |
| 167 | 167 |
| 168 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 168 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 169 [button_ setTarget:self]; | 169 [avatarButton setTarget:self]; |
| 170 [button_ setAction:@selector(buttonClicked:)]; | 170 [avatarButton setAction:@selector(buttonClicked:)]; |
| 171 [avatarButton setRightAction:@selector(buttonRightClicked:)]; |
| 171 | 172 |
| 172 [self updateAvatarButtonAndLayoutParent:NO]; | 173 [self updateAvatarButtonAndLayoutParent:NO]; |
| 173 | 174 |
| 174 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 175 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 175 [center addObserver:self | 176 [center addObserver:self |
| 176 selector:@selector(themeDidChangeNotification:) | 177 selector:@selector(themeDidChangeNotification:) |
| 177 name:kBrowserThemeDidChangeNotification | 178 name:kBrowserThemeDidChangeNotification |
| 178 object:nil]; | 179 object:nil]; |
| 179 } | 180 } |
| 180 return self; | 181 return self; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 bool useGenericButton = (!browser_->profile()->IsGuestSession() && | 226 bool useGenericButton = (!browser_->profile()->IsGuestSession() && |
| 226 cache.GetNumberOfProfiles() == 1 && | 227 cache.GetNumberOfProfiles() == 1 && |
| 227 cache.GetUserNameOfProfileAtIndex(0).empty()); | 228 cache.GetUserNameOfProfileAtIndex(0).empty()); |
| 228 | 229 |
| 229 | 230 |
| 230 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ? | 231 NSString* buttonTitle = base::SysUTF16ToNSString(useGenericButton ? |
| 231 base::string16() : | 232 base::string16() : |
| 232 profiles::GetAvatarButtonTextForProfile(browser_->profile())); | 233 profiles::GetAvatarButtonTextForProfile(browser_->profile())); |
| 233 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle]; | 234 [[button_ cell] setHasError:hasError_ withTitle:buttonTitle]; |
| 234 | 235 |
| 235 HoverImageButton* button = | 236 AvatarButton* button = |
| 236 base::mac::ObjCCastStrict<HoverImageButton>(button_); | 237 base::mac::ObjCCastStrict<AvatarButton>(button_); |
| 237 if (useGenericButton) { | 238 if (useGenericButton) { |
| 238 [button setDefaultImage:GetImageFromResourceID( | 239 [button setDefaultImage:GetImageFromResourceID( |
| 239 IDR_AVATAR_MAC_BUTTON_AVATAR)]; | 240 IDR_AVATAR_MAC_BUTTON_AVATAR)]; |
| 240 [button setHoverImage:GetImageFromResourceID( | 241 [button setHoverImage:GetImageFromResourceID( |
| 241 IDR_AVATAR_MAC_BUTTON_AVATAR_HOVER)]; | 242 IDR_AVATAR_MAC_BUTTON_AVATAR_HOVER)]; |
| 242 [button setPressedImage:GetImageFromResourceID( | 243 [button setPressedImage:GetImageFromResourceID( |
| 243 IDR_AVATAR_MAC_BUTTON_AVATAR_PRESSED)]; | 244 IDR_AVATAR_MAC_BUTTON_AVATAR_PRESSED)]; |
| 244 // This is a workaround for an issue in the HoverImageButton where the | 245 // This is a workaround for an issue in the HoverImageButton where the |
| 245 // button is initially sized incorrectly unless a default image is provided. | 246 // button is initially sized incorrectly unless a default image is provided. |
| 246 // See crbug.com/298501. | 247 // See crbug.com/298501. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 layoutSubviews]; | 283 layoutSubviews]; |
| 283 } | 284 } |
| 284 } | 285 } |
| 285 | 286 |
| 286 - (void)updateErrorStatus:(BOOL)hasError { | 287 - (void)updateErrorStatus:(BOOL)hasError { |
| 287 hasError_ = hasError; | 288 hasError_ = hasError; |
| 288 [self updateAvatarButtonAndLayoutParent:YES]; | 289 [self updateAvatarButtonAndLayoutParent:YES]; |
| 289 } | 290 } |
| 290 | 291 |
| 291 @end | 292 @end |
| OLD | NEW |