Chromium Code Reviews| Index: chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm |
| diff --git a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm |
| index b9b30465e0500953ded1ed67e9283862bbf74ea6..7b082f77df529554ad6587df143bcbab1e00c756 100644 |
| --- a/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm |
| +++ b/chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.mm |
| @@ -4,12 +4,14 @@ |
| #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller.h" |
| +#include "base/i18n/rtl.h" |
| #include "base/mac/bundle_locations.h" |
| #include "base/mac/mac_util.h" |
| #include "base/memory/scoped_nsobject.h" |
| #include "base/string_util.h" |
| #include "base/sys_string_conversions.h" |
| #include "base/utf_string_conversions.h" |
| +#include "chrome/browser/extensions/bundle_installer.h" |
| #include "chrome/browser/extensions/extension_install_dialog.h" |
| #include "chrome/browser/ui/browser.h" |
| #include "chrome/browser/ui/browser_list.h" |
| @@ -23,9 +25,11 @@ |
| using content::OpenURLParams; |
| using content::Referrer; |
| +using extensions::BundleInstaller; |
| @interface ExtensionInstallDialogController () |
| -- (bool)isInlineInstall; |
| +- (BOOL)isBundleInstall; |
| +- (BOOL)isInlineInstall; |
| - (void)appendRatingStar:(const SkBitmap*)skiaImage; |
| @end |
| @@ -39,9 +43,9 @@ const CGFloat kWarningsSeparatorPadding = 14; |
| // contents. |
| const CGFloat kMaxControlHeight = 400; |
| -// Adjust a control's height so that its content its not clipped. Returns the |
| -// amount the control's height had to be adjusted. |
|
Robert Sesek
2012/02/27 18:59:20
Why remove this comment?
jstritar
2012/03/05 18:05:08
Updated the comment.
|
| -CGFloat AdjustControlHeightToFitContent(NSControl* control) { |
| +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; |
| @@ -50,13 +54,12 @@ CGFloat AdjustControlHeightToFitContent(NSControl* control) { |
| [control setFrameSize:NSMakeSize(currentRect.size.width, |
| currentRect.size.height + offset)]; |
| - return offset; |
| -} |
| -// Moves the control vertically by the specified amount. |
| -void OffsetControlVertically(NSControl* control, CGFloat amount) { |
| + *totalOffset += offset; |
| + |
| + // Move the control vertically by the new total offset. |
| NSPoint origin = [control frame].origin; |
| - origin.y += amount; |
| + origin.y -= *totalOffset; |
| [control setFrameOrigin:origin]; |
| } |
| @@ -72,6 +75,7 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| @synthesize iconView = iconView_; |
| @synthesize titleField = titleField_; |
| +@synthesize itemsField = itemsField_; |
| @synthesize subtitleField = subtitleField_; |
| @synthesize warningsField = warningsField_; |
| @synthesize cancelButton = cancelButton_; |
| @@ -98,6 +102,10 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| nibpath = [base::mac::FrameworkBundle() |
| pathForResource:@"ExtensionInstallPromptNoWarnings" |
| ofType:@"nib"]; |
| + } else if (prompt.type() == ExtensionInstallUI::BUNDLE_INSTALL_PROMPT) { |
| + nibpath = [base::mac::FrameworkBundle() |
| + pathForResource:@"ExtensionInstallPromptBundle" |
| + ofType:@"nib"]; |
| } else { |
| nibpath = [base::mac::FrameworkBundle() |
| pathForResource:@"ExtensionInstallPrompt" |
| @@ -162,7 +170,9 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| prompt_->GetUserCount())]; |
| } |
| - [iconView_ setImage:prompt_->icon().ToNSImage()]; |
| + // The bundle install dialog has no icon. |
| + if (![self isBundleInstall]) |
| + [iconView_ setImage:prompt_->icon().ToNSImage()]; |
| // Resize |titleField_| to fit the title. |
| CGFloat originalTitleWidth = [titleField_ frame].size.width; |
| @@ -188,7 +198,37 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| -buttonDelta.width, 0)]; |
| } |
| + // 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 |
| + // wrapping onto multiple lines. So we accumulate an offset by measuring how |
| + // big each label wants to be, and comparing it to how big it actually is. |
| + // Then we shift each label down and resize by the appropriate amount, then |
| + // finally resize the window. |
| CGFloat totalOffset = 0.0; |
| + |
| + if ([self isBundleInstall]) { |
| + [subtitleField_ setStringValue:base::SysUTF16ToNSString( |
| + prompt_->GetPermissionsHeading())]; |
| + |
| + // 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); |
| + |
| + 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(titleField_, &totalOffset); |
| + OffsetControlVerticallyToFitContent(itemsField_, &totalOffset); |
| + } |
| + |
| // If there are any warnings, then we have to do some special layout. |
| if (prompt_->GetPermissionCount() > 0) { |
| [subtitleField_ setStringValue:base::SysUTF16ToNSString( |
| @@ -205,29 +245,23 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| } |
| [warningsField_ setStringValue:joinedWarnings]; |
| - // 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 |
| - // wrapping onto multiple lines. So we accumulate an offset by measuring how |
| - // big each label wants to be, and comparing it to how big it actually is. |
| - // Then we shift each label down and resize by the appropriate amount, then |
| - // finally resize the window. |
| - |
| - // Additionally, in the store version of the dialog the icon extends past |
| - // the one-line version of the permission field. Therefore when increasing |
| - // the window size for multi-line permissions we don't have to add the full |
| - // offset, only the part that extends past the icon. |
| + // In the store version of the dialog the icon extends past the one-line |
| + // version of the permission field. Therefore when increasing the window |
| + // size for multi-line permissions we don't have to add the full offset, |
| + // only the part that extends past the icon. |
| CGFloat warningsGrowthSlack = 0; |
| - if ([warningsField_ frame].origin.y > [iconView_ frame].origin.y) { |
| + if (![self isBundleInstall] && |
| + [warningsField_ frame].origin.y > [iconView_ frame].origin.y) { |
| warningsGrowthSlack = |
| [warningsField_ frame].origin.y - [iconView_ frame].origin.y; |
| } |
| - totalOffset += AdjustControlHeightToFitContent(subtitleField_); |
| - OffsetControlVertically(subtitleField_, -totalOffset); |
| + // Adjust the controls to fit the permission warnings. |
| + OffsetControlVerticallyToFitContent(subtitleField_, &totalOffset); |
| + OffsetControlVerticallyToFitContent(warningsField_, &totalOffset); |
| - totalOffset += AdjustControlHeightToFitContent(warningsField_); |
| - OffsetControlVertically(warningsField_, -totalOffset); |
| totalOffset = MAX(totalOffset - warningsGrowthSlack, 0); |
| + |
|
Robert Sesek
2012/02/27 18:59:20
nit: remove
jstritar
2012/03/05 18:05:08
Done.
|
| } else if ([self isInlineInstall]) { |
| // Inline installs that don't have a permissions section need to hide |
| // controls related to that and shrink the window by the space they take |
| @@ -248,7 +282,7 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| currentRect.origin.y - totalOffset, |
| currentRect.size.width, |
| currentRect.size.height + totalOffset) |
| - display:NO]; |
| + display:NO]; |
| } |
| } |
| @@ -262,7 +296,11 @@ void AppendRatingStarsShim(const SkBitmap* skiaImage, void* data) { |
| [self autorelease]; |
| } |
| -- (bool)isInlineInstall { |
| +- (BOOL)isBundleInstall { |
| + return prompt_->type() == ExtensionInstallUI::BUNDLE_INSTALL_PROMPT; |
| +} |
| + |
| +- (BOOL)isInlineInstall { |
| return prompt_->type() == ExtensionInstallUI::INLINE_INSTALL_PROMPT; |
| } |