BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / constrained_window / constrained_window_control_utils.mm
blob2be3ee7c49f48460d32b10d816b290a9435cd606
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
3 // found in the LICENSE file.
5 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_control_utils.h"
7 #include "base/mac/scoped_nsobject.h"
8 #include "skia/ext/skia_utils_mac.h"
10 namespace constrained_window {
12 NSTextField* CreateLabel() {
13   NSTextField* label =
14       [[[NSTextField alloc] initWithFrame:NSZeroRect] autorelease];
15   [label setEditable:NO];
16   [label setSelectable:NO];
17   [label setBezeled:NO];
18   [label setDrawsBackground:NO];
19   return label;
22 NSAttributedString* GetAttributedLabelString(
23     NSString* string,
24     ui::ResourceBundle::FontStyle fontStyle,
25     NSTextAlignment alignment,
26     NSLineBreakMode lineBreakMode) {
27   if (!string)
28     return nil;
30   const gfx::Font& font =
31       ui::ResourceBundle::GetSharedInstance().GetFont(fontStyle);
32   base::scoped_nsobject<NSMutableParagraphStyle> paragraphStyle(
33       [[NSMutableParagraphStyle alloc] init]);
34   [paragraphStyle setAlignment:alignment];
35   [paragraphStyle setLineBreakMode:lineBreakMode];
37   NSDictionary* attributes = @{
38       NSFontAttributeName:            font.GetNativeFont(),
39       NSParagraphStyleAttributeName:  paragraphStyle.get()
40   };
41   return [[[NSAttributedString alloc] initWithString:string
42                                           attributes:attributes] autorelease];
45 }  // namespace constrained_window