Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" | 5 #import "chrome/browser/ui/cocoa/extensions/extension_install_view_controller.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/mac/bundle_locations.h" | 9 #include "base/mac/bundle_locations.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chrome/browser/extensions/bundle_installer.h" | 14 #include "chrome/browser/extensions/bundle_installer.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/ui/browser.h" | 16 #include "chrome/browser/ui/browser.h" |
| 17 #import "chrome/browser/ui/chrome_style.h" | 17 #import "chrome/browser/ui/chrome_style.h" |
| 18 #include "chrome/browser/ui/cocoa/extensions/bundle_util.h" | |
| 18 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | 19 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" |
| 19 #include "chrome/common/extensions/extension_constants.h" | 20 #include "chrome/common/extensions/extension_constants.h" |
| 20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
| 21 #include "content/public/browser/page_navigator.h" | 22 #include "content/public/browser/page_navigator.h" |
| 22 #include "extensions/common/extension.h" | 23 #include "extensions/common/extension.h" |
| 23 #include "extensions/common/extension_urls.h" | 24 #include "extensions/common/extension_urls.h" |
| 24 #include "skia/ext/skia_utils_mac.h" | 25 #include "skia/ext/skia_utils_mac.h" |
| 25 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 26 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
| 26 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 27 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 // Maximum height we will adjust controls to when trying to accomodate their | 96 // Maximum height we will adjust controls to when trying to accomodate their |
| 96 // contents. | 97 // contents. |
| 97 const CGFloat kMaxControlHeight = 250; | 98 const CGFloat kMaxControlHeight = 250; |
| 98 | 99 |
| 99 NSString* const kTitleKey = @"title"; | 100 NSString* const kTitleKey = @"title"; |
| 100 NSString* const kChildrenKey = @"children"; | 101 NSString* const kChildrenKey = @"children"; |
| 101 NSString* const kCellAttributesKey = @"cellAttributes"; | 102 NSString* const kCellAttributesKey = @"cellAttributes"; |
| 102 NSString* const kPermissionsDetailIndex = @"permissionsDetailIndex"; | 103 NSString* const kPermissionsDetailIndex = @"permissionsDetailIndex"; |
| 103 NSString* const kPermissionsDetailType = @"permissionsDetailType"; | 104 NSString* const kPermissionsDetailType = @"permissionsDetailType"; |
| 104 | 105 |
| 106 // Computes the |control|'s desired height to fit its contents, constrained to | |
| 107 // be kMaxControlHeight at most. | |
| 108 CGFloat ComputeDesiredControlHeight(NSControl* control) { | |
| 109 NSRect rect = [control frame]; | |
| 110 rect.size.height = kMaxControlHeight; | |
| 111 return [[control cell] cellSizeForBounds:rect].height; | |
| 112 } | |
| 113 | |
| 105 // Adjust the |control|'s height so that its content is not clipped. | 114 // Adjust the |control|'s height so that its content is not clipped. |
| 106 // This also adds the change in height to the |totalOffset| and shifts the | 115 // This also adds the change in height to the |totalOffset| and shifts the |
| 107 // control down by that amount. | 116 // control down by that amount. |
| 108 void OffsetControlVerticallyToFitContent(NSControl* control, | 117 void OffsetControlVerticallyToFitContent(NSControl* control, |
| 109 CGFloat* totalOffset) { | 118 CGFloat* totalOffset) { |
| 110 // Adjust the control's height so that its content is not clipped. | 119 // Adjust the control's height so that its content is not clipped. |
| 111 NSRect currentRect = [control frame]; | 120 NSRect currentRect = [control frame]; |
| 112 NSRect fitRect = currentRect; | 121 CGFloat desiredHeight = ComputeDesiredControlHeight(control); |
| 113 fitRect.size.height = kMaxControlHeight; | |
| 114 CGFloat desiredHeight = [[control cell] cellSizeForBounds:fitRect].height; | |
| 115 CGFloat offset = desiredHeight - NSHeight(currentRect); | 122 CGFloat offset = desiredHeight - NSHeight(currentRect); |
| 116 | 123 |
| 117 [control setFrameSize:NSMakeSize(NSWidth(currentRect), | 124 [control setFrameSize:NSMakeSize(NSWidth(currentRect), |
| 118 NSHeight(currentRect) + offset)]; | 125 NSHeight(currentRect) + offset)]; |
| 119 | 126 |
| 120 *totalOffset += offset; | 127 *totalOffset += offset; |
| 121 | 128 |
| 122 // Move the control vertically by the new total offset. | 129 // Move the control vertically by the new total offset. |
| 123 NSPoint origin = [control frame].origin; | 130 NSPoint origin = [control frame].origin; |
| 124 origin.y -= *totalOffset; | 131 origin.y -= *totalOffset; |
| 125 [control setFrameOrigin:origin]; | 132 [control setFrameOrigin:origin]; |
| 126 } | 133 } |
| 127 | 134 |
| 135 // Adjust the |view|'s height so that its subviews are not clipped. | |
| 136 // This also adds the change in height to the |totalOffset| and shifts the | |
| 137 // control down by that amount. | |
| 138 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.
| |
| 139 // Adjust the view's height so that its subviews are not clipped. | |
| 140 CGFloat desiredHeight = 0; | |
| 141 for (NSView* subview in [view subviews]) { | |
| 142 int requiredHeight = NSMaxY([subview frame]); | |
| 143 if (requiredHeight > desiredHeight) | |
| 144 desiredHeight = requiredHeight; | |
| 145 } | |
| 146 NSRect currentRect = [view frame]; | |
| 147 CGFloat offset = desiredHeight - NSHeight(currentRect); | |
| 148 | |
| 149 [view setFrameSize:NSMakeSize(NSWidth(currentRect), | |
| 150 NSHeight(currentRect) + offset)]; | |
| 151 | |
| 152 *totalOffset += offset; | |
| 153 | |
| 154 // Move the view vertically by the new total offset. | |
| 155 NSPoint origin = [view frame].origin; | |
| 156 origin.y -= *totalOffset; | |
| 157 [view setFrameOrigin:origin]; | |
| 158 } | |
| 159 | |
| 128 // Gets the desired height of |outlineView|. Simply using the view's frame | 160 // Gets the desired height of |outlineView|. Simply using the view's frame |
| 129 // doesn't work if an animation is pending. | 161 // doesn't work if an animation is pending. |
| 130 CGFloat GetDesiredOutlineViewHeight(NSOutlineView* outlineView) { | 162 CGFloat GetDesiredOutlineViewHeight(NSOutlineView* outlineView) { |
| 131 CGFloat height = 0; | 163 CGFloat height = 0; |
| 132 for (NSInteger i = 0; i < [outlineView numberOfRows]; ++i) | 164 for (NSInteger i = 0; i < [outlineView numberOfRows]; ++i) |
| 133 height += NSHeight([outlineView rectOfRow:i]); | 165 height += NSHeight([outlineView rectOfRow:i]); |
| 134 return height; | 166 return height; |
| 135 } | 167 } |
| 136 | 168 |
| 137 void OffsetOutlineViewVerticallyToFitContent(NSOutlineView* outlineView, | 169 void OffsetOutlineViewVerticallyToFitContent(NSOutlineView* outlineView, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 prompt_->AppendRatingStars(AppendRatingStarsShim, self); | 295 prompt_->AppendRatingStars(AppendRatingStarsShim, self); |
| 264 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( | 296 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( |
| 265 prompt_->GetRatingCount())]; | 297 prompt_->GetRatingCount())]; |
| 266 [userCountField_ setStringValue:base::SysUTF16ToNSString( | 298 [userCountField_ setStringValue:base::SysUTF16ToNSString( |
| 267 prompt_->GetUserCount())]; | 299 prompt_->GetUserCount())]; |
| 268 [[storeLinkButton_ cell] setUnderlineOnHover:YES]; | 300 [[storeLinkButton_ cell] setUnderlineOnHover:YES]; |
| 269 [[storeLinkButton_ cell] setTextColor: | 301 [[storeLinkButton_ cell] setTextColor: |
| 270 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; | 302 gfx::SkColorToCalibratedNSColor(chrome_style::GetLinkColor())]; |
| 271 } | 303 } |
| 272 | 304 |
| 273 // The bundle install dialog has no icon. | 305 [iconView_ setImage:prompt_->icon().ToNSImage()]; |
| 274 if (![self isBundleInstall]) | |
| 275 [iconView_ setImage:prompt_->icon().ToNSImage()]; | |
| 276 | 306 |
| 277 // The dialog is laid out in the NIB exactly how we want it assuming that | 307 // The dialog is laid out in the NIB exactly how we want it assuming that |
| 278 // each label fits on one line. However, for each label, we want to allow | 308 // each label fits on one line. However, for each label, we want to allow |
| 279 // wrapping onto multiple lines. So we accumulate an offset by measuring how | 309 // wrapping onto multiple lines. So we accumulate an offset by measuring how |
| 280 // big each label wants to be, and comparing it to how big it actually is. | 310 // big each label wants to be, and comparing it to how big it actually is. |
| 281 // Then we shift each label down and resize by the appropriate amount, then | 311 // Then we shift each label down and resize by the appropriate amount, then |
| 282 // finally resize the window. | 312 // finally resize the window. |
| 283 CGFloat totalOffset = 0.0; | 313 CGFloat totalOffset = 0.0; |
| 284 | 314 |
| 285 OffsetControlVerticallyToFitContent(titleField_, &totalOffset); | 315 OffsetControlVerticallyToFitContent(titleField_, &totalOffset); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 302 NSMaxX(okButtonRect) - NSWidth(cancelButtonRect); | 332 NSMaxX(okButtonRect) - NSWidth(cancelButtonRect); |
| 303 [cancelButton_ setFrame:cancelButtonRect]; | 333 [cancelButton_ setFrame:cancelButtonRect]; |
| 304 } | 334 } |
| 305 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; | 335 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; |
| 306 if (buttonDelta.width) { | 336 if (buttonDelta.width) { |
| 307 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], | 337 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], |
| 308 -buttonDelta.width, 0)]; | 338 -buttonDelta.width, 0)]; |
| 309 } | 339 } |
| 310 | 340 |
| 311 if ([self isBundleInstall]) { | 341 if ([self isBundleInstall]) { |
| 312 // We display the list of extension names as a simple text string, seperated | |
| 313 // by newlines. | |
| 314 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState( | 342 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState( |
| 315 BundleInstaller::Item::STATE_PENDING); | 343 BundleInstaller::Item::STATE_PENDING); |
| 344 PopulateBundleItemsList(items, itemsField_); | |
| 316 | 345 |
| 317 NSMutableString* joinedItems = [NSMutableString string]; | 346 // Adjust the view to fit the list of extensions. |
| 318 for (size_t i = 0; i < items.size(); ++i) { | 347 OffsetViewVerticallyToFitContent(itemsField_, &totalOffset); |
| 319 if (i > 0) | |
| 320 [joinedItems appendString:@"\n"]; | |
| 321 [joinedItems appendString:base::SysUTF16ToNSString( | |
| 322 items[i].GetNameForDisplay())]; | |
| 323 } | |
| 324 [itemsField_ setStringValue:joinedItems]; | |
| 325 | |
| 326 // Adjust the controls to fit the list of extensions. | |
| 327 OffsetControlVerticallyToFitContent(itemsField_, &totalOffset); | |
| 328 } | 348 } |
| 329 | 349 |
| 330 // If there are any warnings, retained devices or retained files, then we | 350 // If there are any warnings, retained devices or retained files, then we |
| 331 // have to do some special layout. | 351 // have to do some special layout. |
| 332 if (prompt_->ShouldShowPermissions() || prompt_->GetRetainedFileCount() > 0) { | 352 if (prompt_->ShouldShowPermissions() || prompt_->GetRetainedFileCount() > 0) { |
| 333 NSSize spacing = [outlineView_ intercellSpacing]; | 353 NSSize spacing = [outlineView_ intercellSpacing]; |
| 334 spacing.width += 2; | 354 spacing.width += 2; |
| 335 spacing.height += 2; | 355 spacing.height += 2; |
| 336 [outlineView_ setIntercellSpacing:spacing]; | 356 [outlineView_ setIntercellSpacing:spacing]; |
| 337 [[[[outlineView_ tableColumns] objectAtIndex:0] dataCell] setWraps:YES]; | 357 [[[[outlineView_ tableColumns] objectAtIndex:0] dataCell] setWraps:YES]; |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 } | 834 } |
| 815 | 835 |
| 816 - (void)accessibilityPerformAction:(NSString*)action { | 836 - (void)accessibilityPerformAction:(NSString*)action { |
| 817 if ([action isEqualToString:NSAccessibilityPressAction]) | 837 if ([action isEqualToString:NSAccessibilityPressAction]) |
| 818 [self handleLinkClicked]; | 838 [self handleLinkClicked]; |
| 819 else | 839 else |
| 820 [super accessibilityPerformAction:action]; | 840 [super accessibilityPerformAction:action]; |
| 821 } | 841 } |
| 822 | 842 |
| 823 @end | 843 @end |
| OLD | NEW |