| OLD | NEW |
| 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" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_nsobject.h" | 8 #include "base/mac/scoped_nsobject.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| 11 #include "ui/app_list/app_list_view_delegate.h" | 11 #include "ui/app_list/app_list_view_delegate.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Padding on the left of the indicator icon. | 16 // Padding on the left of the indicator icon. |
| 17 const CGFloat kMenuLeftMargin = 3; | 17 const CGFloat kMenuLeftMargin = 3; |
| 18 | 18 |
| 19 } | 19 } |
| 20 | 20 |
| 21 @interface CurrentUserMenuItemView () | 21 @interface CurrentUserMenuItemView () |
| 22 | 22 |
| 23 // Adds a text label in the custom view in the menu showing the current user. | 23 // Adds a text label in the custom view in the menu showing the current user. |
| 24 - (NSTextField*)addLabelWithFrame:(NSPoint)origin | 24 - (NSTextField*)addLabelWithFrame:(NSPoint)origin |
| 25 labelText:(const string16&)labelText; | 25 labelText:(const string16&)labelText; |
| 26 | 26 |
| 27 @end | 27 @end |
| 28 | 28 |
| 29 @implementation CurrentUserMenuItemView | 29 @implementation CurrentUserMenuItemView |
| 30 | 30 |
| 31 - (id)initWithDelegate:(app_list::AppListViewDelegate*)delegate { | 31 - (id)initWithDelegate:(app_list::AppListViewDelegate*)delegate { |
| 32 DCHECK(delegate); | 32 DCHECK(delegate); |
| 33 if ((self = [super initWithFrame:NSZeroRect])) { | 33 if ((self = [super initWithFrame:NSZeroRect])) { |
| 34 NSImage* userImage = ui::ResourceBundle::GetSharedInstance(). | 34 NSImage* userImage = ui::ResourceBundle::GetSharedInstance(). |
| 35 GetNativeImageNamed(IDR_APP_LIST_USER_INDICATOR).AsNSImage(); | 35 GetNativeImageNamed(IDR_APP_LIST_USER_INDICATOR).AsNSImage(); |
| 36 NSRect imageRect = NSMakeRect(kMenuLeftMargin, 0, 0, 0); | 36 NSRect imageRect = NSMakeRect(kMenuLeftMargin, 0, 0, 0); |
| 37 imageRect.size = [userImage size]; | 37 imageRect.size = [userImage size]; |
| 38 scoped_nsobject<NSImageView> userImageView( | 38 base::scoped_nsobject<NSImageView> userImageView( |
| 39 [[NSImageView alloc] initWithFrame:imageRect]); | 39 [[NSImageView alloc] initWithFrame:imageRect]); |
| 40 [userImageView setImage:userImage]; | 40 [userImageView setImage:userImage]; |
| 41 [self addSubview:userImageView]; | 41 [self addSubview:userImageView]; |
| 42 | 42 |
| 43 NSPoint labelOrigin = NSMakePoint(NSMaxX(imageRect), 0); | 43 NSPoint labelOrigin = NSMakePoint(NSMaxX(imageRect), 0); |
| 44 NSTextField* userField = | 44 NSTextField* userField = |
| 45 [self addLabelWithFrame:labelOrigin | 45 [self addLabelWithFrame:labelOrigin |
| 46 labelText:delegate->GetCurrentUserName()]; | 46 labelText:delegate->GetCurrentUserName()]; |
| 47 | 47 |
| 48 labelOrigin.y = NSMaxY([userField frame]); | 48 labelOrigin.y = NSMaxY([userField frame]); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 59 NSMaxX(labelFrame) + NSMaxX(imageRect), | 59 NSMaxX(labelFrame) + NSMaxX(imageRect), |
| 60 NSMaxY(labelFrame))]; | 60 NSMaxY(labelFrame))]; |
| 61 } | 61 } |
| 62 return self; | 62 return self; |
| 63 } | 63 } |
| 64 | 64 |
| 65 - (NSTextField*)addLabelWithFrame:(NSPoint)origin | 65 - (NSTextField*)addLabelWithFrame:(NSPoint)origin |
| 66 labelText:(const string16&)labelText { | 66 labelText:(const string16&)labelText { |
| 67 NSRect labelFrame = NSZeroRect; | 67 NSRect labelFrame = NSZeroRect; |
| 68 labelFrame.origin = origin; | 68 labelFrame.origin = origin; |
| 69 scoped_nsobject<NSTextField> label( | 69 base::scoped_nsobject<NSTextField> label( |
| 70 [[NSTextField alloc] initWithFrame:labelFrame]); | 70 [[NSTextField alloc] initWithFrame:labelFrame]); |
| 71 [label setStringValue:base::SysUTF16ToNSString(labelText)]; | 71 [label setStringValue:base::SysUTF16ToNSString(labelText)]; |
| 72 [label setEditable:NO]; | 72 [label setEditable:NO]; |
| 73 [label setBordered:NO]; | 73 [label setBordered:NO]; |
| 74 [label setDrawsBackground:NO]; | 74 [label setDrawsBackground:NO]; |
| 75 [label setFont:[NSFont menuFontOfSize:0]]; | 75 [label setFont:[NSFont menuFontOfSize:0]]; |
| 76 [label sizeToFit]; | 76 [label sizeToFit]; |
| 77 [self addSubview:label]; | 77 [self addSubview:label]; |
| 78 return label.autorelease(); | 78 return label.autorelease(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 - (BOOL)isFlipped { | 81 - (BOOL)isFlipped { |
| 82 return YES; | 82 return YES; |
| 83 } | 83 } |
| 84 | 84 |
| 85 @end | 85 @end |
| OLD | NEW |