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

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

Issue 9700043: When sizing to fit the extension install dialog title, expand the height instead of the width. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_dialog_controller. h" 5 #import "chrome/browser/ui/cocoa/extensions/extension_install_dialog_controller. h"
6 6
7 #include "base/i18n/rtl.h" 7 #include "base/i18n/rtl.h"
8 #include "base/mac/bundle_locations.h" 8 #include "base/mac/bundle_locations.h"
9 #include "base/mac/mac_util.h" 9 #include "base/mac/mac_util.h"
10 #include "base/memory/scoped_nsobject.h" 10 #include "base/memory/scoped_nsobject.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 [ratingCountField_ setStringValue:base::SysUTF16ToNSString( 170 [ratingCountField_ setStringValue:base::SysUTF16ToNSString(
171 prompt_->GetRatingCount())]; 171 prompt_->GetRatingCount())];
172 [userCountField_ setStringValue:base::SysUTF16ToNSString( 172 [userCountField_ setStringValue:base::SysUTF16ToNSString(
173 prompt_->GetUserCount())]; 173 prompt_->GetUserCount())];
174 } 174 }
175 175
176 // The bundle install dialog has no icon. 176 // The bundle install dialog has no icon.
177 if (![self isBundleInstall]) 177 if (![self isBundleInstall])
178 [iconView_ setImage:prompt_->icon().ToNSImage()]; 178 [iconView_ setImage:prompt_->icon().ToNSImage()];
179 179
180 // Resize |titleField_| to fit the title. 180 // The dialog is laid out in the NIB exactly how we want it assuming that
181 CGFloat originalTitleWidth = [titleField_ frame].size.width; 181 // each label fits on one line. However, for each label, we want to allow
182 [titleField_ sizeToFit]; 182 // wrapping onto multiple lines. So we accumulate an offset by measuring how
183 CGFloat newTitleWidth = [titleField_ frame].size.width; 183 // big each label wants to be, and comparing it to how big it actually is.
184 if (newTitleWidth > originalTitleWidth) { 184 // Then we shift each label down and resize by the appropriate amount, then
185 NSRect frame = [[self window] frame]; 185 // finally resize the window.
186 frame.size.width += newTitleWidth - originalTitleWidth; 186 CGFloat totalOffset = 0.0;
187 [[self window] setFrame:frame display:NO]; 187
188 } 188 OffsetControlVerticallyToFitContent(titleField_, &totalOffset);
189 189
190 // Resize |okButton_| and |cancelButton_| to fit the button labels, but keep 190 // Resize |okButton_| and |cancelButton_| to fit the button labels, but keep
191 // them right-aligned. 191 // them right-aligned.
192 NSSize buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_]; 192 NSSize buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:okButton_];
193 if (buttonDelta.width) { 193 if (buttonDelta.width) {
194 [okButton_ setFrame:NSOffsetRect([okButton_ frame], -buttonDelta.width, 0)]; 194 [okButton_ setFrame:NSOffsetRect([okButton_ frame], -buttonDelta.width, 0)];
195 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], 195 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame],
196 -buttonDelta.width, 0)]; 196 -buttonDelta.width, 0)];
197 } 197 }
198 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_]; 198 buttonDelta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:cancelButton_];
199 if (buttonDelta.width) { 199 if (buttonDelta.width) {
200 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame], 200 [cancelButton_ setFrame:NSOffsetRect([cancelButton_ frame],
201 -buttonDelta.width, 0)]; 201 -buttonDelta.width, 0)];
202 } 202 }
203 203
204 // The dialog is laid out in the NIB exactly how we want it assuming that
205 // each label fits on one line. However, for each label, we want to allow
206 // wrapping onto multiple lines. So we accumulate an offset by measuring how
207 // big each label wants to be, and comparing it to how big it actually is.
208 // Then we shift each label down and resize by the appropriate amount, then
209 // finally resize the window.
210 CGFloat totalOffset = 0.0;
211
212 if ([self isBundleInstall]) { 204 if ([self isBundleInstall]) {
213 [subtitleField_ setStringValue:base::SysUTF16ToNSString( 205 [subtitleField_ setStringValue:base::SysUTF16ToNSString(
214 prompt_->GetPermissionsHeading())]; 206 prompt_->GetPermissionsHeading())];
215 207
216 // We display the list of extension names as a simple text string, seperated 208 // We display the list of extension names as a simple text string, seperated
217 // by newlines. 209 // by newlines.
218 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState( 210 BundleInstaller::ItemList items = prompt_->bundle()->GetItemsWithState(
219 BundleInstaller::Item::STATE_PENDING); 211 BundleInstaller::Item::STATE_PENDING);
220 212
221 NSMutableString* joinedItems = [NSMutableString string]; 213 NSMutableString* joinedItems = [NSMutableString string];
222 for (size_t i = 0; i < items.size(); ++i) { 214 for (size_t i = 0; i < items.size(); ++i) {
223 if (i > 0) 215 if (i > 0)
224 [joinedItems appendString:@"\n"]; 216 [joinedItems appendString:@"\n"];
225 [joinedItems appendString:base::SysUTF16ToNSString( 217 [joinedItems appendString:base::SysUTF16ToNSString(
226 items[i].GetNameForDisplay())]; 218 items[i].GetNameForDisplay())];
227 } 219 }
228 [itemsField_ setStringValue:joinedItems]; 220 [itemsField_ setStringValue:joinedItems];
229 221
230 // Adjust the controls to fit the list of extensions. 222 // Adjust the controls to fit the list of extensions.
231 OffsetControlVerticallyToFitContent(titleField_, &totalOffset);
232 OffsetControlVerticallyToFitContent(itemsField_, &totalOffset); 223 OffsetControlVerticallyToFitContent(itemsField_, &totalOffset);
233 } 224 }
234 225
235 // If there are any warnings, then we have to do some special layout. 226 // If there are any warnings, then we have to do some special layout.
236 if (prompt_->GetPermissionCount() > 0) { 227 if (prompt_->GetPermissionCount() > 0) {
237 [subtitleField_ setStringValue:base::SysUTF16ToNSString( 228 [subtitleField_ setStringValue:base::SysUTF16ToNSString(
238 prompt_->GetPermissionsHeading())]; 229 prompt_->GetPermissionsHeading())];
239 230
240 // We display the permission warnings as a simple text string, separated by 231 // We display the permission warnings as a simple text string, separated by
241 // newlines. 232 // newlines.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 ExtensionInstallDialogController* controller = 338 ExtensionInstallDialogController* controller =
348 [[ExtensionInstallDialogController alloc] 339 [[ExtensionInstallDialogController alloc]
349 initWithParentWindow:native_window 340 initWithParentWindow:native_window
350 profile:profile 341 profile:profile
351 delegate:delegate 342 delegate:delegate
352 prompt:prompt]; 343 prompt:prompt];
353 344
354 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455) 345 // TODO(mihaip): Switch this to be tab-modal (http://crbug.com/95455)
355 [controller runAsModalSheet]; 346 [controller runAsModalSheet];
356 } 347 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698