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

Side by Side Diff: ui/app_list/cocoa/current_user_menu_item_view.mm

Issue 22268009: Move signin status and current user information into AppListModel. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rework Created 7 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ui/app_list/cocoa/current_user_menu_item_view.h" 5 #import "ui/app_list/cocoa/current_user_menu_item_view.h"
6 6
7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h" 7 #include "base/mac/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "grit/ui_resources.h" 8 #include "grit/ui_resources.h"
11 #include "ui/app_list/app_list_view_delegate.h"
12 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
13 10
14 namespace { 11 namespace {
15 12
16 // Padding on the left of the indicator icon. 13 // Padding on the left of the indicator icon.
17 const CGFloat kMenuLeftMargin = 3; 14 const CGFloat kMenuLeftMargin = 3;
18 15
19 } 16 }
20 17
21 @interface CurrentUserMenuItemView () 18 @interface CurrentUserMenuItemView ()
22 19
23 // Adds a text label in the custom view in the menu showing the current user. 20 // Adds a text label in the custom view in the menu showing the current user.
24 - (NSTextField*)addLabelWithFrame:(NSPoint)origin 21 - (NSTextField*)addLabelWithFrame:(NSPoint)origin
25 labelText:(const string16&)labelText; 22 labelText:(NSString*)labelText;
26 23
27 @end 24 @end
28 25
29 @implementation CurrentUserMenuItemView 26 @implementation CurrentUserMenuItemView
30 27
31 - (id)initWithDelegate:(app_list::AppListViewDelegate*)delegate { 28 - (id)initWithCurrentUser:(NSString*)userName
32 DCHECK(delegate); 29 userEmail:(NSString*)userEmail {
33 if ((self = [super initWithFrame:NSZeroRect])) { 30 if ((self = [super initWithFrame:NSZeroRect])) {
34 NSImage* userImage = ui::ResourceBundle::GetSharedInstance(). 31 NSImage* userImage = ui::ResourceBundle::GetSharedInstance().
35 GetNativeImageNamed(IDR_APP_LIST_USER_INDICATOR).AsNSImage(); 32 GetNativeImageNamed(IDR_APP_LIST_USER_INDICATOR).AsNSImage();
36 NSRect imageRect = NSMakeRect(kMenuLeftMargin, 0, 0, 0); 33 NSRect imageRect = NSMakeRect(kMenuLeftMargin, 0, 0, 0);
37 imageRect.size = [userImage size]; 34 imageRect.size = [userImage size];
38 base::scoped_nsobject<NSImageView> userImageView( 35 base::scoped_nsobject<NSImageView> userImageView(
39 [[NSImageView alloc] initWithFrame:imageRect]); 36 [[NSImageView alloc] initWithFrame:imageRect]);
40 [userImageView setImage:userImage]; 37 [userImageView setImage:userImage];
41 [self addSubview:userImageView]; 38 [self addSubview:userImageView];
42 39
43 NSPoint labelOrigin = NSMakePoint(NSMaxX(imageRect), 0); 40 NSPoint labelOrigin = NSMakePoint(NSMaxX(imageRect), 0);
44 NSTextField* userField = 41 NSTextField* userField =
45 [self addLabelWithFrame:labelOrigin 42 [self addLabelWithFrame:labelOrigin
46 labelText:delegate->GetCurrentUserName()]; 43 labelText:userName];
47 44
48 labelOrigin.y = NSMaxY([userField frame]); 45 labelOrigin.y = NSMaxY([userField frame]);
49 NSTextField* emailField = 46 NSTextField* emailField =
50 [self addLabelWithFrame:labelOrigin 47 [self addLabelWithFrame:labelOrigin
51 labelText:delegate->GetCurrentUserEmail()]; 48 labelText:userEmail];
52 [emailField setTextColor:[NSColor disabledControlTextColor]]; 49 [emailField setTextColor:[NSColor disabledControlTextColor]];
53 50
54 // Size the container view to fit the longest label. 51 // Size the container view to fit the longest label.
55 NSRect labelFrame = [emailField frame]; 52 NSRect labelFrame = [emailField frame];
56 if (NSWidth([userField frame]) > NSWidth(labelFrame)) 53 if (NSWidth([userField frame]) > NSWidth(labelFrame))
57 labelFrame.size.width = NSWidth([userField frame]); 54 labelFrame.size.width = NSWidth([userField frame]);
58 [self setFrameSize:NSMakeSize( 55 [self setFrameSize:NSMakeSize(
59 NSMaxX(labelFrame) + NSMaxX(imageRect), 56 NSMaxX(labelFrame) + NSMaxX(imageRect),
60 NSMaxY(labelFrame))]; 57 NSMaxY(labelFrame))];
61 } 58 }
62 return self; 59 return self;
63 } 60 }
64 61
65 - (NSTextField*)addLabelWithFrame:(NSPoint)origin 62 - (NSTextField*)addLabelWithFrame:(NSPoint)origin
66 labelText:(const string16&)labelText { 63 labelText:(NSString*)labelText {
67 NSRect labelFrame = NSZeroRect; 64 NSRect labelFrame = NSZeroRect;
68 labelFrame.origin = origin; 65 labelFrame.origin = origin;
69 base::scoped_nsobject<NSTextField> label( 66 base::scoped_nsobject<NSTextField> label(
70 [[NSTextField alloc] initWithFrame:labelFrame]); 67 [[NSTextField alloc] initWithFrame:labelFrame]);
71 [label setStringValue:base::SysUTF16ToNSString(labelText)]; 68 [label setStringValue:labelText];
72 [label setEditable:NO]; 69 [label setEditable:NO];
73 [label setBordered:NO]; 70 [label setBordered:NO];
74 [label setDrawsBackground:NO]; 71 [label setDrawsBackground:NO];
75 [label setFont:[NSFont menuFontOfSize:0]]; 72 [label setFont:[NSFont menuFontOfSize:0]];
76 [label sizeToFit]; 73 [label sizeToFit];
77 [self addSubview:label]; 74 [self addSubview:label];
78 return label.autorelease(); 75 return label.autorelease();
79 } 76 }
80 77
81 - (BOOL)isFlipped { 78 - (BOOL)isFlipped {
82 return YES; 79 return YES;
83 } 80 }
84 81
85 @end 82 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698