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

Unified 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: asvitkine review 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/cocoa/extensions/bundle_util.mm
diff --git a/chrome/browser/ui/cocoa/extensions/bundle_util.mm b/chrome/browser/ui/cocoa/extensions/bundle_util.mm
new file mode 100644
index 0000000000000000000000000000000000000000..85af7baf549174334b90aab3d82cf084d980413e
--- /dev/null
+++ b/chrome/browser/ui/cocoa/extensions/bundle_util.mm
@@ -0,0 +1,58 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/cocoa/extensions/bundle_util.h"
+
+#include "base/mac/mac_util.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#include "ui/gfx/image/image_skia.h"
+#include "ui/gfx/image/image_skia_util_mac.h"
+#import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTweaker.h"
+
+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
+
+CGFloat PopulateBundleItemsList(
+ 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.
+ 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.
+ CGFloat offset = 0;
+ // Go over the items backwards, since Cocoa coords go from the bottom up.
+ for (size_t i = items.size(); i > 0; --i) {
+ const extensions::BundleInstaller::Item& item = items[i - 1];
+
+ NSString* title = base::SysUTF16ToNSString(item.GetNameForDisplay());
+ base::scoped_nsobject<NSTextField> titleView([[NSTextField alloc]
+ initWithFrame:NSMakeRect(kExtensionIconSize, offset, titleWidth, 0)]);
+ [titleView setBordered:NO];
+ [titleView setEditable:NO];
+ [titleView setStringValue:title];
+ [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView];
+
+ NSRect titleFrame = [titleView frame];
+ NSRect iconFrame =
+ NSMakeRect(0, offset, kExtensionIconSize, kExtensionIconSize);
+
+ // Vertically center-align icon and title.
+ CGFloat align = (iconFrame.size.height - titleFrame.size.height) / 2;
+ if (align > 0) {
+ titleFrame.origin.y += align;
+ [titleView setFrame:titleFrame];
+ } else {
+ iconFrame.origin.y -= align;
+ }
+
+ gfx::ImageSkia skiaImage = gfx::ImageSkia::CreateFrom1xBitmap(item.icon);
+ NSImage* image = gfx::NSImageFromImageSkiaWithColorSpace(
+ skiaImage, base::mac::GetSystemColorSpace());
+ base::scoped_nsobject<NSImageView> iconView(
+ [[NSImageView alloc] initWithFrame:iconFrame]);
+ [iconView setImage:image];
+
+ [itemsField addSubview:iconView];
+ [itemsField addSubview:titleView];
+
+ offset = NSMaxY(NSUnionRect(titleFrame, iconFrame));
+ }
+ return offset;
+}

Powered by Google App Engine
This is Rietveld 408576698