Index: chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
diff --git a/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm b/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
index efec9e26d994f4de61c49ccfdcf0a7787c549291..7d43df8934cf046662dc73e3ede9818fd7894d1c 100644 |
--- a/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
+++ b/chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm |
@@ -12,6 +12,7 @@ |
#include "chrome/browser/ui/browser.h" |
#include "chrome/browser/ui/browser_window.h" |
#import "chrome/browser/ui/cocoa/browser_window_controller.h" |
+#include "components/signin/core/browser/signin_error_controller.h" |
#include "grit/generated_resources.h" |
#include "grit/theme_resources.h" |
#import "ui/base/cocoa/appkit_utils.h" |
@@ -19,6 +20,8 @@ |
#include "ui/base/l10n/l10n_util_mac.h" |
#include "ui/base/nine_image_painter_factory.h" |
#include "ui/base/resource/resource_bundle.h" |
+#include "ui/gfx/image/image_skia_operations.h" |
+#include "ui/gfx/image/image_skia_util_mac.h" |
#include "ui/gfx/text_elider.h" |
namespace { |
@@ -28,6 +31,8 @@ const CGFloat kButtonDefaultPadding = 5; |
const CGFloat kButtonHeight = 27; |
const CGFloat kButtonTitleImageSpacing = 10; |
const CGFloat kMaxButtonContentWidth = 100; |
+const CGFloat kAuthErrorIconWidth = 13; |
+const CGFloat kAuthErrorIconHeight = 11; |
const ui::NinePartImageIds kNormalBorderImageIds = |
IMAGE_GRID(IDR_AVATAR_MAC_BUTTON_NORMAL); |
@@ -49,21 +54,35 @@ NSImage* GetImageFromResourceID(int resourceId) { |
@interface CustomThemeButtonCell : NSButtonCell { |
@private |
BOOL isThemedWindow_; |
+ BOOL hasError_; |
+ base::scoped_nsobject<NSImage> authErrorImage_; |
} |
- (void)setIsThemedWindow:(BOOL)isThemedWindow; |
+- (void)setHasError:(BOOL)hasError; |
+ |
@end |
@implementation CustomThemeButtonCell |
- (id)initWithThemedWindow:(BOOL)isThemedWindow { |
if ((self = [super init])) { |
isThemedWindow_ = isThemedWindow; |
+ hasError_ = NO; |
+ |
+ gfx::ImageSkia icon = gfx::ImageSkiaOperations::CreateResizedImage( |
+ *ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
+ IDR_ICON_PROFILES_ACCOUNT_BUTTON_ERROR).ToImageSkia(), |
+ skia::ImageOperations::RESIZE_BEST, |
+ gfx::Size(kAuthErrorIconWidth, kAuthErrorIconHeight)); |
+ authErrorImage_.reset([gfx::NSImageFromImageSkia(icon) retain]); |
} |
return self; |
} |
- (NSSize)cellSize { |
NSSize buttonSize = [super cellSize]; |
- buttonSize.width += 2 * kButtonPadding - 2 * kButtonDefaultPadding; |
+ CGFloat errorImageWidth = hasError_ ? kAuthErrorIconWidth : 0; |
msw
2014/06/03 04:15:31
nit: errorWidth or imageWidth for a one-liner belo
noms (inactive)
2014/06/06 20:33:43
Done.
|
+ buttonSize.width += |
+ 2 * (kButtonPadding - kButtonDefaultPadding) + errorImageWidth; |
buttonSize.height = kButtonHeight; |
return buttonSize; |
} |
@@ -73,13 +92,29 @@ NSImage* GetImageFromResourceID(int resourceId) { |
inView:(NSView*)controlView { |
frame.origin.x = kButtonPadding; |
// Ensure there's always a padding between the text and the image. |
- frame.size.width -= kButtonTitleImageSpacing; |
+ frame.size.width -= hasError_ ? 2 * kButtonTitleImageSpacing : |
+ kButtonTitleImageSpacing; |
return [super drawTitle:title withFrame:frame inView:controlView]; |
} |
- (void)drawImage:(NSImage*)image |
withFrame:(NSRect)frame |
inView:(NSView*)controlView { |
+ // If there's an auth error, draw a warning icon before the cell image. |
+ if (hasError_) { |
+ NSSize imageSize = [authErrorImage_ size]; |
+ NSRect rect = NSMakeRect( |
+ frame.origin.x - imageSize.width - kButtonTitleImageSpacing, |
+ (kButtonHeight - imageSize.height) / 2, |
+ imageSize.width, |
+ imageSize.height); |
+ [authErrorImage_ drawInRect:rect |
+ fromRect:NSZeroRect |
+ operation:NSCompositeSourceOver |
+ fraction:1.0 |
+ respectFlipped:YES |
+ hints:nil]; |
+ } |
// For the x-offset, we need to undo the default padding and apply the |
// new one. For the y-offset, increasing the button height means we need |
// to move the image a little down to align it nicely with the text; this |
@@ -106,11 +141,17 @@ NSImage* GetImageFromResourceID(int resourceId) { |
- (void)setIsThemedWindow:(BOOL)isThemedWindow { |
isThemedWindow_ = isThemedWindow; |
} |
+ |
+- (void)setHasError:(BOOL)hasError { |
+ hasError_ = hasError; |
+} |
+ |
@end |
@interface AvatarButtonController (Private) |
- (base::string16)getElidedAvatarName; |
- (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
+- (void)updateErrorStatus:(BOOL)hasError; |
- (void)dealloc; |
- (void)themeDidChangeNotification:(NSNotification*)aNotification; |
@end |
@@ -135,6 +176,10 @@ NSImage* GetImageFromResourceID(int resourceId) { |
button_.reset(hoverButton); |
base::scoped_nsobject<CustomThemeButtonCell> cell( |
[[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); |
+ SigninErrorController* error = |
+ profiles::GetSigninErrorController(browser->profile()); |
+ if (error) |
+ [cell setHasError:error->HasError()]; |
msw
2014/06/03 04:15:31
ditto nit: should the button state be set if |erro
noms (inactive)
2014/06/06 20:33:43
As mentioned before, |error| can't be nil once, an
|
[button_ setCell:cell.get()]; |
[self setView:button_]; |
@@ -156,7 +201,6 @@ NSImage* GetImageFromResourceID(int resourceId) { |
selector:@selector(themeDidChangeNotification:) |
name:kBrowserThemeDidChangeNotification |
object:nil]; |
- |
} |
return self; |
} |
@@ -192,7 +236,6 @@ NSImage* GetImageFromResourceID(int resourceId) { |
// The button text has a black foreground and a white drop shadow for regular |
// windows, and a light text with a dark drop shadow for guest windows |
// which are themed with a dark background. |
- // TODO(noms): Figure out something similar for themed windows, if possible. |
msw
2014/06/03 04:15:31
Why is this no more applicable?
noms (inactive)
2014/06/06 20:33:43
Left over todo that never got updated :) The code
|
base::scoped_nsobject<NSShadow> shadow([[NSShadow alloc] init]); |
[shadow setShadowOffset:NSMakeSize(0, -1)]; |
[shadow setShadowBlurRadius:0]; |
@@ -242,4 +285,9 @@ NSImage* GetImageFromResourceID(int resourceId) { |
} |
} |
+- (void)updateErrorStatus:(BOOL)hasError { |
+ [[button_ cell] setHasError:hasError]; |
+ [self updateAvatarButtonAndLayoutParent:YES]; |
+} |
+ |
@end |