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

Side by Side Diff: chrome/browser/ui/cocoa/profile_menu_controller.mm

Issue 149513007: [Mac] The GAIA profile photo should be resized in the Users controller menu (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: alexei nits Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/profile_menu_controller.h" 5 #import "chrome/browser/ui/cocoa/profile_menu_controller.h"
6 6
7 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.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/avatar_menu.h" 10 #include "chrome/browser/profiles/avatar_menu.h"
11 #include "chrome/browser/profiles/avatar_menu_observer.h" 11 #include "chrome/browser/profiles/avatar_menu_observer.h"
12 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/browser/profiles/profile_info_cache.h" 13 #include "chrome/browser/profiles/profile_info_cache.h"
14 #include "chrome/browser/profiles/profile_info_interface.h" 14 #include "chrome/browser/profiles/profile_info_interface.h"
15 #include "chrome/browser/profiles/profile_info_util.h"
15 #include "chrome/browser/profiles/profile_manager.h" 16 #include "chrome/browser/profiles/profile_manager.h"
16 #include "chrome/browser/profiles/profile_metrics.h" 17 #include "chrome/browser/profiles/profile_metrics.h"
17 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
18 #include "chrome/browser/ui/browser_list.h" 19 #include "chrome/browser/ui/browser_list.h"
19 #include "chrome/browser/ui/browser_list_observer.h" 20 #include "chrome/browser/ui/browser_list_observer.h"
20 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h" 21 #include "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
21 #include "grit/generated_resources.h" 22 #include "grit/generated_resources.h"
22 #include "ui/base/l10n/l10n_util_mac.h" 23 #include "ui/base/l10n/l10n_util_mac.h"
23 #include "ui/gfx/image/image.h" 24 #include "ui/gfx/image/image.h"
24 25
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 const AvatarMenu::Item& itemData = menu_->GetItemAt(i); 123 const AvatarMenu::Item& itemData = menu_->GetItemAt(i);
123 NSString* name = base::SysUTF16ToNSString(itemData.name); 124 NSString* name = base::SysUTF16ToNSString(itemData.name);
124 SEL action = dock ? @selector(switchToProfileFromDock:) 125 SEL action = dock ? @selector(switchToProfileFromDock:)
125 : @selector(switchToProfileFromMenu:); 126 : @selector(switchToProfileFromMenu:);
126 NSMenuItem* item = [self createItemWithTitle:name 127 NSMenuItem* item = [self createItemWithTitle:name
127 action:action]; 128 action:action];
128 [item setTag:itemData.menu_index]; 129 [item setTag:itemData.menu_index];
129 if (dock) { 130 if (dock) {
130 [item setIndentationLevel:1]; 131 [item setIndentationLevel:1];
131 } else { 132 } else {
132 [item setImage:itemData.icon.ToNSImage()]; 133 gfx::Image itemIcon = itemData.icon;
134 // The image might be too large and need to be resized (i.e. if this is
135 // a signed-in user using the GAIA profile photo).
136 if (itemIcon.Width() > profiles::kAvatarIconWidth ||
137 itemIcon.Height() > profiles::kAvatarIconHeight) {
138 itemIcon = profiles::GetAvatarIconForWebUI(itemIcon, true);
139 }
140 DCHECK(itemIcon.Width() <= profiles::kAvatarIconWidth);
141 DCHECK(itemIcon.Height() <= profiles::kAvatarIconHeight);
142 [item setImage:itemIcon.ToNSImage()];
133 [item setState:itemData.active ? NSOnState : NSOffState]; 143 [item setState:itemData.active ? NSOnState : NSOffState];
134 } 144 }
135 [menu insertItem:item atIndex:i + offset]; 145 [menu insertItem:item atIndex:i + offset];
136 } 146 }
137 147
138 return YES; 148 return YES;
139 } 149 }
140 150
141 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem { 151 - (BOOL)validateMenuItem:(NSMenuItem*)menuItem {
142 // In guest mode, chrome://settings isn't available, so disallow creating 152 // In guest mode, chrome://settings isn't available, so disallow creating
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 } 249 }
240 250
241 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel { 251 - (NSMenuItem*)createItemWithTitle:(NSString*)title action:(SEL)sel {
242 base::scoped_nsobject<NSMenuItem> item( 252 base::scoped_nsobject<NSMenuItem> item(
243 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]); 253 [[NSMenuItem alloc] initWithTitle:title action:sel keyEquivalent:@""]);
244 [item setTarget:self]; 254 [item setTarget:self];
245 return [item.release() autorelease]; 255 return [item.release() autorelease];
246 } 256 }
247 257
248 @end 258 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698