Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Side by Side Diff: chrome/browser/ui/cocoa/profiles/avatar_button_controller.mm

Issue 2174973002: [Mac][MD User Menu] Revamped signin/sync error surfacing UI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: After refactoring Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_attributes_entry.h" 10 #include "chrome/browser/profiles/profile_attributes_entry.h"
11 #include "chrome/browser/profiles/profile_attributes_storage.h" 11 #include "chrome/browser/profiles/profile_attributes_storage.h"
12 #include "chrome/browser/profiles/profile_manager.h" 12 #include "chrome/browser/profiles/profile_manager.h"
13 #include "chrome/browser/profiles/profiles_state.h" 13 #include "chrome/browser/profiles/profiles_state.h"
14 #include "chrome/browser/themes/theme_service.h" 14 #include "chrome/browser/themes/theme_service.h"
15 #include "chrome/browser/themes/theme_service_factory.h" 15 #include "chrome/browser/themes/theme_service_factory.h"
16 #include "chrome/browser/ui/browser.h" 16 #include "chrome/browser/ui/browser.h"
17 #include "chrome/browser/ui/browser_window.h" 17 #include "chrome/browser/ui/browser_window.h"
18 #import "chrome/browser/ui/cocoa/browser_window_controller.h" 18 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
19 #import "chrome/browser/ui/cocoa/profiles/avatar_button.h" 19 #import "chrome/browser/ui/cocoa/profiles/avatar_button.h"
20 #include "chrome/grit/generated_resources.h" 20 #include "chrome/grit/generated_resources.h"
21 #include "components/signin/core/browser/signin_error_controller.h" 21 #include "components/signin/core/common/profile_management_switches.h"
22 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
23 #import "ui/base/cocoa/appkit_utils.h" 23 #import "ui/base/cocoa/appkit_utils.h"
24 #include "ui/base/l10n/l10n_util_mac.h" 24 #include "ui/base/l10n/l10n_util_mac.h"
25 #include "ui/base/material_design/material_design_controller.h" 25 #include "ui/base/material_design/material_design_controller.h"
26 #include "ui/base/nine_image_painter_factory.h" 26 #include "ui/base/nine_image_painter_factory.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/gfx/color_palette.h"
28 #include "ui/gfx/image/image_skia_operations.h" 29 #include "ui/gfx/image/image_skia_operations.h"
29 #include "ui/gfx/image/image_skia_util_mac.h" 30 #include "ui/gfx/image/image_skia_util_mac.h"
31 #include "ui/gfx/paint_vector_icon.h"
32 #include "ui/gfx/vector_icons_public.h"
30 33
31 namespace { 34 namespace {
32 35
33 // NSButtons have a default padding of 5px. This button should have a padding 36 // NSButtons have a default padding of 5px. This button should have a padding
34 // of 8px. 37 // of 8px.
35 const CGFloat kButtonExtraPadding = 8 - 5; 38 const CGFloat kButtonExtraPadding = 8 - 5;
36 const CGFloat kButtonHeight = 28; 39 const CGFloat kButtonHeight = 28;
37 40
38 const ui::NinePartImageIds kNormalBorderImageIds = 41 const ui::NinePartImageIds kNormalBorderImageIds =
39 IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL); 42 IMAGE_GRID(IDR_AVATAR_NATIVE_BUTTON_NORMAL);
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 139
137 [self accessibilitySetOverrideValue:l10n_util::GetNSStringF( 140 [self accessibilitySetOverrideValue:l10n_util::GetNSStringF(
138 messageId, base::SysNSStringToUTF16(title)) 141 messageId, base::SysNSStringToUTF16(title))
139 forAttribute:NSAccessibilityTitleAttribute]; 142 forAttribute:NSAccessibilityTitleAttribute];
140 } 143 }
141 144
142 @end 145 @end
143 146
144 @interface AvatarButtonController (Private) 147 @interface AvatarButtonController (Private)
145 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; 148 - (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent;
146 - (void)updateErrorStatus:(BOOL)hasError; 149 - (void)setErrorStatus:(BOOL)hasError;
147 - (void)dealloc; 150 - (void)dealloc;
148 - (void)themeDidChangeNotification:(NSNotification*)aNotification; 151 - (void)themeDidChangeNotification:(NSNotification*)aNotification;
149 @end 152 @end
150 153
151 @implementation AvatarButtonController 154 @implementation AvatarButtonController
152 155
153 - (id)initWithBrowser:(Browser*)browser { 156 - (id)initWithBrowser:(Browser*)browser {
154 if ((self = [super initWithBrowser:browser])) { 157 if ((self = [super initWithBrowser:browser])) {
155 ThemeService* themeService = 158 ThemeService* themeService =
156 ThemeServiceFactory::GetForProfile(browser->profile()); 159 ThemeServiceFactory::GetForProfile(browser->profile());
157 isThemedWindow_ = !themeService->UsingSystemTheme(); 160 isThemedWindow_ = !themeService->UsingSystemTheme();
158 161
159 AvatarButton* avatarButton = 162 AvatarButton* avatarButton =
160 [[AvatarButton alloc] initWithFrame:NSZeroRect]; 163 [[AvatarButton alloc] initWithFrame:NSZeroRect];
161 button_.reset(avatarButton); 164 button_.reset(avatarButton);
162 base::scoped_nsobject<CustomThemeButtonCell> cell( 165 base::scoped_nsobject<CustomThemeButtonCell> cell(
163 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]); 166 [[CustomThemeButtonCell alloc] initWithThemedWindow:isThemedWindow_]);
164 [avatarButton setCell:cell.get()]; 167 [avatarButton setCell:cell.get()];
165 168
166 // Check if the account already has an authentication error.
167 SigninErrorController* errorController =
168 profiles::GetSigninErrorController(browser->profile());
169 hasError_ = errorController && errorController->HasError();
170
171 [avatarButton setWantsLayer:YES]; 169 [avatarButton setWantsLayer:YES];
172 [self setView:avatarButton]; 170 [self setView:avatarButton];
173 171
174 [avatarButton setBezelStyle:NSShadowlessSquareBezelStyle]; 172 [avatarButton setBezelStyle:NSShadowlessSquareBezelStyle];
175 [avatarButton setButtonType:NSMomentaryChangeButton]; 173 [avatarButton setButtonType:NSMomentaryChangeButton];
176 [avatarButton setBordered:YES]; 174 [avatarButton setBordered:YES];
177 175
178 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin]; 176 [avatarButton setAutoresizingMask:NSViewMinXMargin | NSViewMinYMargin];
179 [avatarButton setTarget:self]; 177 [avatarButton setTarget:self];
180 [avatarButton setAction:@selector(buttonClicked:)]; 178 [avatarButton setAction:@selector(buttonClicked:)];
181 [avatarButton setRightAction:@selector(buttonRightClicked:)]; 179 [avatarButton setRightAction:@selector(buttonRightClicked:)];
182 180
181 // Check if the account already has an authentication or sync error and
182 // initialize the avatar button UI.
183 hasError_ = profileObserver_->HasAvatarError();
183 [self updateAvatarButtonAndLayoutParent:NO]; 184 [self updateAvatarButtonAndLayoutParent:NO];
184 185
185 NSNotificationCenter* center = [NSNotificationCenter defaultCenter]; 186 NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
186 [center addObserver:self 187 [center addObserver:self
187 selector:@selector(themeDidChangeNotification:) 188 selector:@selector(themeDidChangeNotification:)
188 name:kBrowserThemeDidChangeNotification 189 name:kBrowserThemeDidChangeNotification
189 object:nil]; 190 object:nil];
190 } 191 }
191 return self; 192 return self;
192 } 193 }
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 [button setHoverImage:GetImageFromResourceID( 254 [button setHoverImage:GetImageFromResourceID(
254 IDR_AVATAR_NATIVE_BUTTON_AVATAR_HOVER)]; 255 IDR_AVATAR_NATIVE_BUTTON_AVATAR_HOVER)];
255 [button setPressedImage:GetImageFromResourceID( 256 [button setPressedImage:GetImageFromResourceID(
256 IDR_AVATAR_NATIVE_BUTTON_AVATAR_PRESSED)]; 257 IDR_AVATAR_NATIVE_BUTTON_AVATAR_PRESSED)];
257 // This is a workaround for an issue in the HoverImageButton where the 258 // This is a workaround for an issue in the HoverImageButton where the
258 // button is initially sized incorrectly unless a default image is provided. 259 // button is initially sized incorrectly unless a default image is provided.
259 // See crbug.com/298501. 260 // See crbug.com/298501.
260 [button setImage:GetImageFromResourceID(IDR_AVATAR_NATIVE_BUTTON_AVATAR)]; 261 [button setImage:GetImageFromResourceID(IDR_AVATAR_NATIVE_BUTTON_AVATAR)];
261 [button setImagePosition:NSImageOnly]; 262 [button setImagePosition:NSImageOnly];
262 } else if (hasError_) { 263 } else if (hasError_) {
263 [button setDefaultImage:GetImageFromResourceID( 264 NSImage* errorIcon =
264 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR)]; 265 switches::IsMaterialDesignUserMenu()
266 ? NSImageFromImageSkia(gfx::CreateVectorIcon(
267 gfx::VectorIconId::SYNC_PROBLEM, 13, gfx::kGoogleRed700))
268 : GetImageFromResourceID(IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR);
269 [button setDefaultImage:errorIcon];
265 [button setHoverImage:nil]; 270 [button setHoverImage:nil];
266 [button setPressedImage:nil]; 271 [button setPressedImage:nil];
267 [button setImage:GetImageFromResourceID( 272 [button setImage:errorIcon];
268 IDR_ICON_PROFILES_AVATAR_BUTTON_ERROR)];
269 [button setImagePosition:NSImageRight]; 273 [button setImagePosition:NSImageRight];
270 } else { 274 } else {
271 [button setDefaultImage:nil]; 275 [button setDefaultImage:nil];
272 [button setHoverImage:nil]; 276 [button setHoverImage:nil];
273 [button setPressedImage:nil]; 277 [button setPressedImage:nil];
274 [button setImagePosition:NSNoImage]; 278 [button setImagePosition:NSNoImage];
275 } 279 }
276 280
277 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle( 281 base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
278 [[NSMutableParagraphStyle alloc] init]); 282 [[NSMutableParagraphStyle alloc] init]);
(...skipping 10 matching lines...) Expand all
289 293
290 if (layoutParent) { 294 if (layoutParent) {
291 // Because the width of the button might have changed, the parent browser 295 // Because the width of the button might have changed, the parent browser
292 // frame needs to recalculate the button bounds and redraw it. 296 // frame needs to recalculate the button bounds and redraw it.
293 [[BrowserWindowController 297 [[BrowserWindowController
294 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()] 298 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()]
295 layoutSubviews]; 299 layoutSubviews];
296 } 300 }
297 } 301 }
298 302
299 - (void)updateErrorStatus:(BOOL)hasError { 303 - (void)setErrorStatus:(BOOL)hasError {
300 hasError_ = hasError; 304 hasError_ = hasError;
301 [self updateAvatarButtonAndLayoutParent:YES]; 305 [self updateAvatarButtonAndLayoutParent:YES];
302 } 306 }
303 307
304 @end 308 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698