Chromium Code Reviews| 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.h" | |
|
groby-ooo-7-16
2014/08/15 00:38:35
Do you need this?
noms (inactive)
2014/08/15 19:26:47
Done.
| |
| 21 #include "ui/base/l10n/l10n_util_mac.h" | |
| 19 #include "ui/base/nine_image_painter_factory.h" | 22 #include "ui/base/nine_image_painter_factory.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/gfx/image/image_skia_operations.h" | 24 #include "ui/gfx/image/image_skia_operations.h" |
| 22 #include "ui/gfx/image/image_skia_util_mac.h" | 25 #include "ui/gfx/image/image_skia_util_mac.h" |
| 23 | 26 |
| 24 namespace { | 27 namespace { |
| 25 | 28 |
| 26 const CGFloat kButtonPadding = 12; | 29 const CGFloat kButtonPadding = 12; |
| 27 const CGFloat kButtonDefaultPadding = 5; | 30 const CGFloat kButtonDefaultPadding = 5; |
| 28 const CGFloat kButtonHeight = 27; | 31 const CGFloat kButtonHeight = 27; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 } else { | 142 } else { |
| 140 authenticationErrorImage_.reset(); | 143 authenticationErrorImage_.reset(); |
| 141 } | 144 } |
| 142 } | 145 } |
| 143 | 146 |
| 144 @end | 147 @end |
| 145 | 148 |
| 146 @interface AvatarButtonController (Private) | 149 @interface AvatarButtonController (Private) |
| 147 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; | 150 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
| 148 - (void)updateErrorStatus:(BOOL)hasError; | 151 - (void)updateErrorStatus:(BOOL)hasError; |
| 152 - (void)updateAccessibilityValue:(BOOL)hasError; | |
| 149 - (void)dealloc; | 153 - (void)dealloc; |
| 150 - (void)themeDidChangeNotification:(NSNotification*)aNotification; | 154 - (void)themeDidChangeNotification:(NSNotification*)aNotification; |
| 151 @end | 155 @end |
| 152 | 156 |
| 153 @implementation AvatarButtonController | 157 @implementation AvatarButtonController |
| 154 | 158 |
| 155 - (id)initWithBrowser:(Browser*)browser { | 159 - (id)initWithBrowser:(Browser*)browser { |
| 156 if ((self = [super initWithBrowser:browser])) { | 160 if ((self = [super initWithBrowser:browser])) { |
| 157 ThemeService* themeService = | 161 ThemeService* themeService = |
| 158 ThemeServiceFactory::GetForProfile(browser->profile()); | 162 ThemeServiceFactory::GetForProfile(browser->profile()); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 182 [button_ setBordered:YES]; | 186 [button_ setBordered:YES]; |
| 183 // This is a workaround for an issue in the HoverImageButton where the | 187 // This is a workaround for an issue in the HoverImageButton where the |
| 184 // button is initially sized incorrectly unless a default image is provided. | 188 // button is initially sized incorrectly unless a default image is provided. |
| 185 [button_ setImage:GetImageFromResourceID(IDR_AVATAR_MAC_BUTTON_DROPARROW)]; | 189 [button_ setImage:GetImageFromResourceID(IDR_AVATAR_MAC_BUTTON_DROPARROW)]; |
| 186 [button_ setImagePosition:NSImageRight]; | 190 [button_ setImagePosition:NSImageRight]; |
| 187 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; | 191 [button_ setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; |
| 188 [button_ setTarget:self]; | 192 [button_ setTarget:self]; |
| 189 [button_ setAction:@selector(buttonClicked:)]; | 193 [button_ setAction:@selector(buttonClicked:)]; |
| 190 | 194 |
| 191 [self updateAvatarButtonAndLayoutParent:NO]; | 195 [self updateAvatarButtonAndLayoutParent:NO]; |
| 196 [self updateAccessibilityValue: | |
| 197 errorController && errorController->HasError()]; | |
| 192 | 198 |
| 193 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; | 199 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; |
| 194 [center addObserver:self | 200 [center addObserver:self |
| 195 selector:@selector(themeDidChangeNotification:) | 201 selector:@selector(themeDidChangeNotification:) |
| 196 name:kBrowserThemeDidChangeNotification | 202 name:kBrowserThemeDidChangeNotification |
| 197 object:nil]; | 203 object:nil]; |
| 198 } | 204 } |
| 199 return self; | 205 return self; |
| 200 } | 206 } |
| 201 | 207 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 257 // frame needs to recalculate the button bounds and redraw it. | 263 // frame needs to recalculate the button bounds and redraw it. |
| 258 [[BrowserWindowController | 264 [[BrowserWindowController |
| 259 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] | 265 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] |
| 260 layoutSubviews]; | 266 layoutSubviews]; |
| 261 } | 267 } |
| 262 } | 268 } |
| 263 | 269 |
| 264 - (void)updateErrorStatus:(BOOL)hasError { | 270 - (void)updateErrorStatus:(BOOL)hasError { |
| 265 [[button_ cell] setHasError:hasError]; | 271 [[button_ cell] setHasError:hasError]; |
| 266 [self updateAvatarButtonAndLayoutParent:YES]; | 272 [self updateAvatarButtonAndLayoutParent:YES]; |
| 273 [self updateAccessibilityValue:hasError]; | |
| 274 } | |
| 275 | |
| 276 - (void)updateAccessibilityValue:(BOOL)hasError { | |
|
groby-ooo-7-16
2014/08/15 00:38:35
That's a horrible name, sorry. How about setAccess
noms (inactive)
2014/08/15 19:26:47
Acknowledged.
| |
| 277 base::string16 buttonTitle = base::SysNSStringToUTF16([button_ title]); | |
|
groby-ooo-7-16
2014/08/15 00:38:35
Silly question - why get this outside the if(), si
noms (inactive)
2014/08/15 19:26:47
No good reason
On 2014/08/15 00:38:35, groby wrot
| |
| 278 if (hasError) { | |
| 279 [[button_ cell] | |
| 280 accessibilitySetOverrideValue:l10n_util::GetNSStringF( | |
|
groby-ooo-7-16
2014/08/15 00:38:35
Why not do all this magic in the cell - that way i
noms (inactive)
2014/08/15 19:26:47
Hmm, because the cell didn't have the title but th
| |
| 281 IDS_PROFILES_ACCOUNT_BUTTON_AUTH_ERROR_ACCESSIBLE_NAME, buttonTitle) | |
| 282 forAttribute:NSAccessibilityTitleAttribute]; | |
| 283 } else { | |
| 284 [[button_ cell] | |
| 285 accessibilitySetOverrideValue:[button_ title] | |
| 286 forAttribute:NSAccessibilityTitleAttribute]; | |
| 287 } | |
| 267 } | 288 } |
| 268 | 289 |
| 269 @end | 290 @end |
| OLD | NEW |