OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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 #include "chrome/browser/ui/cocoa/extensions/bundle_util.h" | |
6 | |
7 #include "base/mac/mac_util.h" | |
8 #include "base/mac/scoped_nsobject.h" | |
9 #include "base/strings/sys_string_conversions.h" | |
10 #include "ui/gfx/image/image_skia.h" | |
11 #include "ui/gfx/image/image_skia_util_mac.h" | |
12 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | |
13 | |
14 const CGFloat kExtensionIconSize = 32; | |
Alexei Svitkine (slow)
2015/04/22 16:52:27
Put in an anon namespace.
Marc Treib
2015/04/23 09:47:07
Done. FTR though, it's not necessary here, since f
| |
15 | |
16 CGFloat PopulateBundleItemsList( | |
17 NSView* itemsField, const extensions::BundleInstaller::ItemList& items) { | |
Alexei Svitkine (slow)
2015/04/22 16:52:27
1 param per line.
Marc Treib
2015/04/23 09:47:07
Done.
| |
18 const CGFloat titleWidth = [itemsField frame].size.width - kExtensionIconSize; | |
Alexei Svitkine (slow)
2015/04/22 16:52:27
C++ naming convention in free standing functions (
Marc Treib
2015/04/23 09:47:07
Done.
| |
19 CGFloat offset = 0; | |
20 // Go over the items backwards, since Cocoa coords go from the bottom up. | |
21 for (size_t i = items.size(); i > 0; --i) { | |
22 const extensions::BundleInstaller::Item& item = items[i - 1]; | |
23 | |
24 NSString* title = base::SysUTF16ToNSString(item.GetNameForDisplay()); | |
25 base::scoped_nsobject<NSTextField> titleView([[NSTextField alloc] | |
26 initWithFrame:NSMakeRect(kExtensionIconSize, offset, titleWidth, 0)]); | |
27 [titleView setBordered:NO]; | |
28 [titleView setEditable:NO]; | |
29 [titleView setStringValue:title]; | |
30 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; | |
31 | |
32 NSRect titleFrame = [titleView frame]; | |
33 NSRect iconFrame = | |
34 NSMakeRect(0, offset, kExtensionIconSize, kExtensionIconSize); | |
35 | |
36 // Vertically center-align icon and title. | |
37 CGFloat align = (iconFrame.size.height - titleFrame.size.height) / 2; | |
38 if (align > 0) { | |
39 titleFrame.origin.y += align; | |
40 [titleView setFrame:titleFrame]; | |
41 } else { | |
42 iconFrame.origin.y -= align; | |
43 } | |
44 | |
45 gfx::ImageSkia skiaImage = gfx::ImageSkia::CreateFrom1xBitmap(item.icon); | |
46 NSImage* image = gfx::NSImageFromImageSkiaWithColorSpace( | |
47 skiaImage, base::mac::GetSystemColorSpace()); | |
48 base::scoped_nsobject<NSImageView> iconView( | |
49 [[NSImageView alloc] initWithFrame:iconFrame]); | |
50 [iconView setImage:image]; | |
51 | |
52 [itemsField addSubview:iconView]; | |
53 [itemsField addSubview:titleView]; | |
54 | |
55 offset = NSMaxY(NSUnionRect(titleFrame, iconFrame)); | |
56 } | |
57 return offset; | |
58 } | |
OLD | NEW |