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

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

Issue 15955003: Menu for the OSX app launcher. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix comment Created 7 years, 6 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ui/app_list/cocoa/current_user_menu_item_view.h"
6
7 #include "base/logging.h"
8 #include "base/memory/scoped_nsobject.h"
9 #include "base/strings/sys_string_conversions.h"
10 #include "grit/ui_resources.h"
11 #include "ui/app_list/app_list_view_delegate.h"
12 #include "ui/base/resource/resource_bundle.h"
13
14 namespace {
15
16 // Padding on the left of the indicator icon.
17 const CGFloat kMenuLeftMargin = 3;
18
19 }
20
21 @interface CurrentUserMenuItemView ()
22
23 // Adds a text label in the custom view in the menu showing the current user.
24 - (NSTextField*)addLabelWithFrame:(NSPoint)origin
25 labelText:(const string16&)labelText;
26
27 @end
28
29 @implementation CurrentUserMenuItemView
30
31 - (id)initWithDelegate:(app_list::AppListViewDelegate*)delegate {
32 DCHECK(delegate);
33 if ((self = [super initWithFrame:NSZeroRect])) {
34 NSImage* userImage = ui::ResourceBundle::GetSharedInstance().
35 GetNativeImageNamed(IDR_APP_LIST_USER_INDICATOR).AsNSImage();
36 NSRect imageRect = NSMakeRect(kMenuLeftMargin, 0, 0, 0);
37 imageRect.size = [userImage size];
38 scoped_nsobject<NSImageView> userImageView(
39 [[NSImageView alloc] initWithFrame:imageRect]);
40 [userImageView setImage:userImage];
41 [self addSubview:userImageView];
42
43 NSPoint labelOrigin = NSMakePoint(NSMaxX(imageRect), 0);
44 NSTextField* userField =
45 [self addLabelWithFrame:labelOrigin
46 labelText:delegate->GetCurrentUserName()];
47
48 labelOrigin.y = NSMaxY([userField frame]);
49 NSTextField* emailField =
50 [self addLabelWithFrame:labelOrigin
51 labelText:delegate->GetCurrentUserEmail()];
52 [emailField setTextColor:[NSColor disabledControlTextColor]];
53
54 // Size the container view to fit the longest label.
55 NSRect labelFrame = [emailField frame];
56 if (NSWidth([userField frame]) > NSWidth(labelFrame))
57 labelFrame.size.width = NSWidth([userField frame]);
58 [self setFrameSize:NSMakeSize(
59 NSMaxX(labelFrame) + NSMaxX(imageRect),
60 NSMaxY(labelFrame))];
61 }
62 return self;
63 }
64
65 - (NSTextField*)addLabelWithFrame:(NSPoint)origin
66 labelText:(const string16&)labelText {
67 NSRect labelFrame = NSZeroRect;
68 labelFrame.origin = origin;
69 scoped_nsobject<NSTextField> label(
70 [[NSTextField alloc] initWithFrame:labelFrame]);
71 [label setStringValue:base::SysUTF16ToNSString(labelText)];
72 [label setEditable:NO];
73 [label setBordered:NO];
74 [label setDrawsBackground:NO];
75 [label setFont:[NSFont menuFontOfSize:0]];
76 [label sizeToFit];
77 [self addSubview:label];
78 return label.autorelease();
79 }
80
81 - (BOOL)isFlipped {
82 return YES;
83 }
84
85 @end
OLDNEW
« no previous file with comments | « ui/app_list/cocoa/current_user_menu_item_view.h ('k') | ui/base/cocoa/controls/hover_image_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698