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/profiles/profiles_state.h" | 9 #include "chrome/browser/profiles/profiles_state.h" |
10 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
11 #include "chrome/browser/themes/theme_service_factory.h" | 11 #include "chrome/browser/themes/theme_service_factory.h" |
12 #include "chrome/browser/ui/browser.h" | 12 #include "chrome/browser/ui/browser.h" |
13 #include "chrome/browser/ui/browser_window.h" | 13 #include "chrome/browser/ui/browser_window.h" |
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
15 #include "components/signin/core/browser/signin_error_controller.h" | 15 #include "components/signin/core/browser/signin_error_controller.h" |
| 16 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 17 #include "grit/theme_resources.h" |
17 #import "ui/base/cocoa/appkit_utils.h" | 18 #import "ui/base/cocoa/appkit_utils.h" |
18 #import "ui/base/cocoa/hover_image_button.h" | 19 #import "ui/base/cocoa/hover_image_button.h" |
| 20 #include "ui/base/l10n/l10n_util_mac.h" |
19 #include "ui/base/nine_image_painter_factory.h" | 21 #include "ui/base/nine_image_painter_factory.h" |
20 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
22 #include "ui/gfx/image/image_skia_util_mac.h" | 24 #include "ui/gfx/image/image_skia_util_mac.h" |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 const CGFloat kButtonPadding = 12; | 28 const CGFloat kButtonPadding = 12; |
27 const CGFloat kButtonDefaultPadding = 5; | 29 const CGFloat kButtonDefaultPadding = 5; |
28 const CGFloat kButtonHeight = 27; | 30 const CGFloat kButtonHeight = 27; |
(...skipping 15 matching lines...) Expand all Loading... |
44 | 46 |
45 } // namespace | 47 } // namespace |
46 | 48 |
47 // Button cell with a custom border given by a set of nine-patch image grids. | 49 // Button cell with a custom border given by a set of nine-patch image grids. |
48 @interface CustomThemeButtonCell : NSButtonCell { | 50 @interface CustomThemeButtonCell : NSButtonCell { |
49 @private | 51 @private |
50 BOOL isThemedWindow_; | 52 BOOL isThemedWindow_; |
51 base::scoped_nsobject<NSImage> authenticationErrorImage_; | 53 base::scoped_nsobject<NSImage> authenticationErrorImage_; |
52 } | 54 } |
53 - (void)setIsThemedWindow:(BOOL)isThemedWindow; | 55 - (void)setIsThemedWindow:(BOOL)isThemedWindow; |
54 - (void)setHasError:(BOOL)hasError; | 56 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title; |
55 | 57 |
56 @end | 58 @end |
57 | 59 |
58 @implementation CustomThemeButtonCell | 60 @implementation CustomThemeButtonCell |
59 - (id)initWithThemedWindow:(BOOL)isThemedWindow { | 61 - (id)initWithThemedWindow:(BOOL)isThemedWindow { |
60 if ((self = [super init])) { | 62 if ((self = [super init])) { |
61 isThemedWindow_ = isThemedWindow; | 63 isThemedWindow_ = isThemedWindow; |
62 authenticationErrorImage_.reset(); | 64 authenticationErrorImage_.reset(); |
63 } | 65 } |
64 return self; | 66 return self; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 imageIds = kPressedBorderImageIds; | 126 imageIds = kPressedBorderImageIds; |
125 else if (hoverState == kHoverStateMouseOver) | 127 else if (hoverState == kHoverStateMouseOver) |
126 imageIds = kHoverBorderImageIds; | 128 imageIds = kHoverBorderImageIds; |
127 ui::DrawNinePartImage(frame, imageIds, NSCompositeSourceOver, 1.0, true); | 129 ui::DrawNinePartImage(frame, imageIds, NSCompositeSourceOver, 1.0, true); |
128 } | 130 } |
129 | 131 |
130 - (void)setIsThemedWindow:(BOOL)isThemedWindow { | 132 - (void)setIsThemedWindow:(BOOL)isThemedWindow { |
131 isThemedWindow_ = isThemedWindow; | 133 isThemedWindow_ = isThemedWindow; |
132 } | 134 } |
133 | 135 |
134 - (void)setHasError:(BOOL)hasError { | 136 - (void)setHasError:(BOOL)hasError withTitle:(NSString*)title { |
135 if (hasError) { | 137 if (hasError) { |
136 authenticationErrorImage_.reset( | 138 authenticationErrorImage_.reset( |
137 [ui::ResourceBundle::GetSharedInstance().GetImageNamed( | 139 [ui::ResourceBundle::GetSharedInstance().GetImageNamed( |
138 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToNSImage() retain]); | 140 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR).ToNSImage() retain]); |
| 141 [self accessibilitySetOverrideValue:l10n_util::GetNSStringF( |
| 142 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME, |
| 143 base::SysNSStringToUTF16(title)) |
| 144 forAttribute:NSAccessibilityTitleAttribute]; |
139 } else { | 145 } else { |
140 authenticationErrorImage_.reset(); | 146 authenticationErrorImage_.reset(); |
| 147 [self accessibilitySetOverrideValue:title |
| 148 forAttribute:NSAccessibilityTitleAttribute]; |
141 } | 149 } |
142 } | 150 } |
143 | 151 |
144 @end | 152 @end |
145 | 153 |
146 @interface AvatarButtonController (Private) | 154 @interface AvatarButtonController (Private) |
147 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; | 155 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
148 - (void)updateErrorStatus:(BOOL)hasError; | 156 - (void)updateErrorStatus:(BOOL)hasError; |
149 - (void)dealloc; | 157 - (void)dealloc; |
150 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 158 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
(...skipping 14 matching lines...) Expand all Loading... |
165 [hoverButton setHoverImage:GetImageFromResourceID( | 173 [hoverButton setHoverImage:GetImageFromResourceID( |
166 IDR_AVATAR_MAC_BUTTON_DROPARROW_HOVER)]; | 174 IDR_AVATAR_MAC_BUTTON_DROPARROW_HOVER)]; |
167 [hoverButton setPressedImage:GetImageFromResourceID( | 175 [hoverButton setPressedImage:GetImageFromResourceID( |
168 IDR_AVATAR_MAC_BUTTON_DROPARROW_PRESSED)]; | 176 IDR_AVATAR_MAC_BUTTON_DROPARROW_PRESSED)]; |
169 | 177 |
170 button_.reset(hoverButton); | 178 button_.reset(hoverButton); |
171 base::scoped_nsobject<CustomThemeButtonCell> cell( | 179 base::scoped_nsobject<CustomThemeButtonCell> cell( |
172 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); | 180 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); |
173 SigninErrorController* errorController = | 181 SigninErrorController* errorController = |
174 profiles::GetSigninErrorController(browser->profile()); | 182 profiles::GetSigninErrorController(browser->profile()); |
175 if (errorController) | 183 |
176 [cell setHasError:errorController->HasError()]; | |
177 [button_ setCell:cell.get()]; | 184 [button_ setCell:cell.get()]; |
178 [self setView:button_]; | 185 [self setView:button_]; |
179 | 186 |
180 [button_ setBezelStyle:NSShadowlessSquareBezelStyle]; | 187 [button_ setBezelStyle:NSShadowlessSquareBezelStyle]; |
181 [button_ setButtonType:NSMomentaryChangeButton]; | 188 [button_ setButtonType:NSMomentaryChangeButton]; |
182 [button_ setBordered:YES]; | 189 [button_ setBordered:YES]; |
183 // This is a workaround for an issue in the HoverImageButton where the | 190 // This is a workaround for an issue in the HoverImageButton where the |
184 // button is initially sized incorrectly unless a default image is provided. | 191 // button is initially sized incorrectly unless a default image is provided. |
185 [button_ setImage:GetImageFromResourceID(IDR_AVATAR_MAC_BUTTON_DROPARROW)]; | 192 [button_ setImage:GetImageFromResourceID(IDR_AVATAR_MAC_BUTTON_DROPARROW)]; |
186 [button_ setImagePosition:NSImageRight]; | 193 [button_ setImagePosition:NSImageRight]; |
187 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 194 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
188 [button_ setTarget:self]; | 195 [button_ setTarget:self]; |
189 [button_ setAction:@selector(buttonClicked:)]; | 196 [button_ setAction:@selector(buttonClicked:)]; |
190 | 197 |
191 [self updateAvatarButtonAndLayoutParent:NO]; | 198 [self updateAvatarButtonAndLayoutParent:NO]; |
| 199 if (errorController) |
| 200 [cell setHasError:errorController->HasError() withTitle:[button_ title]]; |
192 | 201 |
193 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 202 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
194 [center addObserver:self | 203 [center addObserver:self |
195 selector:@selector(themeDidChangeNotification:) | 204 selector:@selector(themeDidChangeNotification:) |
196 name:kBrowserThemeDidChangeNotification | 205 name:kBrowserThemeDidChangeNotification |
197 object:nil]; | 206 object:nil]; |
198 } | 207 } |
199 return self; | 208 return self; |
200 } | 209 } |
201 | 210 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 if (layoutParent) { | 264 if (layoutParent) { |
256 // Because the width of the button might have changed, the parent browser | 265 // Because the width of the button might have changed, the parent browser |
257 // frame needs to recalculate the button bounds and redraw it. | 266 // frame needs to recalculate the button bounds and redraw it. |
258 [[BrowserWindowController | 267 [[BrowserWindowController |
259 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] | 268 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] |
260 layoutSubviews]; | 269 layoutSubviews]; |
261 } | 270 } |
262 } | 271 } |
263 | 272 |
264 - (void)updateErrorStatus:(BOOL)hasError { | 273 - (void)updateErrorStatus:(BOOL)hasError { |
265 [[button_ cell] setHasError:hasError]; | 274 [[button_ cell] setHasError:hasError withTitle:[button_ title]]; |
266 [self updateAvatarButtonAndLayoutParent:YES]; | 275 [self updateAvatarButtonAndLayoutParent:YES]; |
267 } | 276 } |
268 | 277 |
269 @end | 278 @end |
OLD | NEW |