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

Side by Side Diff: chrome/browser/ui/cocoa/extensions/bundle_util.mm

Issue 816223008: Update UI for WebStore bundle installs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@bundles_api
Patch Set: style fix Created 5 years, 8 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
(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 namespace {
15
16 const CGFloat kExtensionIconSize = 32;
17
18 } // namespace
19
20 CGFloat PopulateBundleItemsList(
21 const extensions::BundleInstaller::ItemList& items,
22 NSView* items_field) {
23 const CGFloat title_width =
24 [items_field frame].size.width - kExtensionIconSize;
25 CGFloat offset = 0;
26 // Go over the items backwards, since Cocoa coords go from the bottom up.
27 for (size_t i = items.size(); i > 0; --i) {
28 const extensions::BundleInstaller::Item& item = items[i - 1];
29
30 NSString* title = base::SysUTF16ToNSString(item.GetNameForDisplay());
31 base::scoped_nsobject<NSTextField> title_view([[NSTextField alloc]
32 initWithFrame:NSMakeRect(kExtensionIconSize, offset, title_width, 0)]);
33 [title_view setBordered:NO];
34 [title_view setEditable:NO];
35 [title_view setStringValue:title];
36 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:title_view];
37
38 NSRect title_frame = [title_view frame];
39 NSRect icon_frame =
40 NSMakeRect(0, offset, kExtensionIconSize, kExtensionIconSize);
41
42 // Vertically center-align icon and title.
43 CGFloat align = (icon_frame.size.height - title_frame.size.height) / 2;
44 if (align > 0) {
45 title_frame.origin.y += align;
46 [title_view setFrame:title_frame];
47 } else {
48 icon_frame.origin.y -= align;
49 }
50
51 gfx::ImageSkia skia_image = gfx::ImageSkia::CreateFrom1xBitmap(item.icon);
52 NSImage* image = gfx::NSImageFromImageSkiaWithColorSpace(
53 skia_image, base::mac::GetSystemColorSpace());
54 base::scoped_nsobject<NSImageView> icon_view(
55 [[NSImageView alloc] initWithFrame:icon_frame]);
56 [icon_view setImage:image];
57
58 [items_field addSubview:icon_view];
59 [items_field addSubview:title_view];
60
61 offset = NSMaxY(NSUnionRect(title_frame, icon_frame));
62 }
63 return offset;
64 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698