Index: chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm b/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
index 835ba3c004dfc3cca482e2ac7f9f142dc79e1ed1..2728c241c648185dccc012113d7158d2748c5fc5 100644 |
--- a/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
+++ b/chrome/browser/ui/cocoa/extensions/extension_install_view_controller.mm |
@@ -15,6 +15,7 @@ |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/ui/browser.h" |
#import "chrome/browser/ui/chrome_style.h" |
+#include "chrome/browser/ui/cocoa/extensions/bundle_util.h" |
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
#include "chrome/common/extensions/extension_constants.h" |
#include "chrome/grit/generated_resources.h" |
@@ -102,6 +103,14 @@ NSString* const kCellAttributesKey = @"cellAttributes"; |
NSString* const kPermissionsDetailIndex = @"permissionsDetailIndex"; |
NSString* const kPermissionsDetailType = @"permissionsDetailType"; |
+// Computes the |control|'s desired height to fit its contents, constrained to |
+// be kMaxControlHeight at most. |
+CGFloat ComputeDesiredControlHeight(NSControl* control) { |
+ NSRect rect = [control frame]; |
+ rect.size.height = kMaxControlHeight; |
+ return [[control cell] cellSizeForBounds:rect].height; |
+} |
+ |
// Adjust the |control|'s height so that its content is not clipped. |
// This also adds the change in height to the |totalOffset| and shifts the |
// control down by that amount. |
@@ -109,9 +118,7 @@ void OffsetControlVerticallyToFitContent(NSControl* control, |
CGFloat* totalOffset) { |
// Adjust the control's height so that its content is not clipped. |
NSRect currentRect = [control frame]; |
- NSRect fitRect = currentRect; |
- fitRect.size.height = kMaxControlHeight; |
- CGFloat desiredHeight = [[control cell] cellSizeForBounds:fitRect].height; |
+ CGFloat desiredHeight = ComputeDesiredControlHeight(control); |
CGFloat offset = desiredHeight - NSHeight(currentRect); |
[control setFrameSize:NSMakeSize(NSWidth(currentRect), |
@@ -125,6 +132,31 @@ void OffsetControlVerticallyToFitContent(NSControl* control, |
[control setFrameOrigin:origin]; |
} |
+// Adjust the |view|'s height so that its subviews are not clipped. |
+// This also adds the change in height to the |totalOffset| and shifts the |
+// control down by that amount. |
+void OffsetViewVerticallyToFitContent(NSView* view, CGFloat* totalOffset) { |
Alexei Svitkine (slow)
2015/04/23 16:47:39
Nit: Since this is a C++ function, use hacker_styl
Marc Treib
2015/04/24 09:06:05
Done, also for the other functions below.
|
+ // Adjust the view's height so that its subviews are not clipped. |
+ CGFloat desiredHeight = 0; |
+ for (NSView* subview in [view subviews]) { |
+ int requiredHeight = NSMaxY([subview frame]); |
+ if (requiredHeight > desiredHeight) |
+ desiredHeight = requiredHeight; |
+ } |
+ NSRect currentRect = [view frame]; |
+ CGFloat offset = desiredHeight - NSHeight(currentRect); |
+ |
+ [view setFrameSize:NSMakeSize(NSWidth(currentRect), |
+ NSHeight(currentRect) + offset)]; |
+ |
+ *totalOffset += offset; |
+ |
+ // Move the view vertically by the new total offset. |
+ NSPoint origin = [view frame].origin; |
+ origin.y -= *totalOffset; |
+ [view setFrameOrigin:origin]; |
+} |
+ |
// Gets the desired height of |outlineView|. Simply using the view's frame |
// doesn't work if an animation is pending. |
CGFloat GetDesiredOutlineViewHeight(NSOutlineView* outlineView) { |
@@ -270,9 +302,7 @@ bool HasAttribute(id item, CellAttributesMask attributeMask) { |
gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
} |
- // The bundle install dialog has no icon. |
- if (![self isBundleInstall]) |
- [iconView_ setImage:prompt_->icon().ToNSImage()]; |
+ [iconView_ setImage:prompt_->icon().ToNSImage()]; |
// The dialog is laid out in the NIB exactly how we want it assuming that |
// each label fits on one line. However, for each label, we want to allow |
@@ -309,22 +339,12 @@ bool HasAttribute(id item, CellAttributesMask attributeMask) { |
} |
if ([self isBundleInstall]) { |
- // We display the list of extension names as a simple text string, seperated |
- // by newlines. |
BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState( |
BundleInstaller::Item::STATE_PENDING); |
+ PopulateBundleItemsList(items, itemsField_); |
- NSMutableString* joinedItems = [NSMutableString string]; |
- for (size_t i = 0; i < items.size(); ++i) { |
- if (i > 0) |
- [joinedItems appendString:@"\n"]; |
- [joinedItems appendString:base::SysUTF16ToNSString( |
- items[i].GetNameForDisplay())]; |
- } |
- [itemsField_ setStringValue:joinedItems]; |
- |
- // Adjust the controls to fit the list of extensions. |
- OffsetControlVerticallyToFitContent(itemsField_, &totalOffset); |
+ // Adjust the view to fit the list of extensions. |
+ OffsetViewVerticallyToFitContent(itemsField_, &totalOffset); |
} |
// If there are any warnings, retained devices or retained files, then we |