diff options
author | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-16 20:36:36 +0000 |
---|---|---|
committer | thomasvl@chromium.org <thomasvl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-03-16 20:36:36 +0000 |
commit | d77f5a92acbac46b12cbcc81e90314e701d1c95a (patch) | |
tree | 841d3ab1f7f313b723f9352b4d52f3f441aa3ee4 /chrome/browser/cocoa/first_run_dialog.mm | |
parent | 3ddbd145ccbf4cd58e70f6594cdcce1f46999367 (diff) | |
download | chromium_src-d77f5a92acbac46b12cbcc81e90314e701d1c95a.zip chromium_src-d77f5a92acbac46b12cbcc81e90314e701d1c95a.tar.gz chromium_src-d77f5a92acbac46b12cbcc81e90314e701d1c95a.tar.bz2 |
[Mac] First run dialog cleanup
- coding style fixes for ivars
- fixed some 10.6 toolchain warnings from the xib
- provide custom getters for two properties to always return false when the matching controls are hidden.
- Autosize the window to handle any possible l10n now
- Make headers, buttons, and all by the stats/breakpad checkbox force the window to grow as needed.
- Wrap the stats/breakpad checkbox to the resulting width (it will never fit otherwise).
- Layout/shuffling things based on the views that get hidden (no other browsers to import from, not stats pref).
BUG=37743
TEST=text isn't clipped in any language
Review URL: http://codereview.chromium.org/995002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@41758 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/first_run_dialog.mm')
-rw-r--r-- | chrome/browser/cocoa/first_run_dialog.mm | 146 |
1 files changed, 134 insertions, 12 deletions
diff --git a/chrome/browser/cocoa/first_run_dialog.mm b/chrome/browser/cocoa/first_run_dialog.mm index 1a4a87b..e63262e 100644 --- a/chrome/browser/cocoa/first_run_dialog.mm +++ b/chrome/browser/cocoa/first_run_dialog.mm @@ -9,16 +9,35 @@ #include "base/mac_util.h" #import "base/scoped_nsobject.h" #include "grit/locale_settings.h" +#import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" + +namespace { + +// Compare function for -[NSArray sortedArrayUsingFunction:context:] that +// sorts the views in Y order bottom up. +NSInteger CompareFrameY(id view1, id view2, void* context) { + CGFloat y1 = NSMinY([view1 frame]); + CGFloat y2 = NSMinY([view2 frame]); + if (y1 < y2) + return NSOrderedAscending; + else if (y1 > y2) + return NSOrderedDescending; + else + return NSOrderedSame; +} + +}; @implementation FirstRunDialogController -@synthesize userDidCancel = user_did_cancel_; -@synthesize statsEnabled = stats_enabled_; -@synthesize makeDefaultBrowser = make_default_browser_; -@synthesize importBookmarks = import_bookmarks_; -@synthesize browserImportSelectedIndex = browser_import_selected_index_; -@synthesize browserImportList = browser_import_list_; -@synthesize browserImportListHidden = browser_import_list_hidden_; +@synthesize userDidCancel = userDidCancel_; +@synthesize statsEnabled = statsEnabled_; +@synthesize statsCheckboxHidden = statsCheckboxHidden_; +@synthesize makeDefaultBrowser = makeDefaultBrowser_; +@synthesize importBookmarks = importBookmarks_; +@synthesize browserImportSelectedIndex = browserImportSelectedIndex_; +@synthesize browserImportList = browserImportList_; +@synthesize browserImportListHidden = browserImportListHidden_; - (id)init { NSString* nibpath = @@ -27,24 +46,110 @@ self = [super initWithWindowNibPath:nibpath owner:self]; if (self != nil) { // Bound to the dialog checkbox, default to true. - stats_enabled_ = YES; - import_bookmarks_ = YES; + statsEnabled_ = YES; + importBookmarks_ = YES; #if !defined(GOOGLE_CHROME_BUILD) // In Chromium builds all stats reporting is disabled so there's no reason // to display the checkbox - the setting is always OFF. - usage_stats_checkbox_hidden_ = YES; + statsCheckboxHidden_ = YES; #endif // !GOOGLE_CHROME_BUILD } return self; } - (void)dealloc { - [browser_import_list_ release]; + [browserImportList_ release]; [super dealloc]; } - (IBAction)showWindow:(id)sender { + NSWindow* win = [self window]; + + // Only support the sizing the window once. + DCHECK(!beenSized_) << "ShowWindow was called twice?"; + if (!beenSized_) { + beenSized_ = YES; + DCHECK_GT([objectsToSize_ count], 0U); + + // Size everything to fit, collecting the widest growth needed (XIB provides + // the min size, i.e.-never shrink, just grow). + CGFloat largestWidthChange = 0.0; + for (NSView* view in objectsToSize_) { + DCHECK_NE(statsCheckbox_, view) << "Stats checkbox shouldn't be in list"; + if (![view isHidden]) { + NSSize delta = [GTMUILocalizerAndLayoutTweaker sizeToFitView:view]; + DCHECK_EQ(delta.height, 0.0) + << "Didn't expect anything to change heights"; + if (largestWidthChange < delta.width) + largestWidthChange = delta.width; + } + } + + // Make the window wide enough to fit everything. + if (largestWidthChange > 0.0) { + NSView* contentView = [win contentView]; + NSRect windowFrame = [contentView convertRect:[win frame] fromView:nil]; + windowFrame.size.width += largestWidthChange; + windowFrame = [contentView convertRect:windowFrame toView:nil]; + [win setFrame:windowFrame display:NO]; + } + + // The stats checkbox (if visible) gets some really long text, so it gets + // word wrapped and then sized. + DCHECK(statsCheckbox_); + CGFloat statsCheckboxHeightChange = 0.0; + if (![self statsCheckboxHidden]) { + [GTMUILocalizerAndLayoutTweaker wrapButtonTitleForWidth:statsCheckbox_]; + statsCheckboxHeightChange = + [GTMUILocalizerAndLayoutTweaker sizeToFitView:statsCheckbox_].height; + } + + // Walk bottom up shuffling for all the hidden views. + NSArray* subViews = + [[[win contentView] subviews] sortedArrayUsingFunction:CompareFrameY + context:NULL]; + CGFloat moveDown = 0.0; + NSUInteger numSubViews = [subViews count]; + for (NSUInteger idx = 0 ; idx < numSubViews ; ++idx) { + NSView* view = [subViews objectAtIndex:idx]; + + // If the view is hidden, collect the amount to move everything above it + // down, if it's not hidden, apply any shift down. + if ([view isHidden]) { + DCHECK_GT((numSubViews - 1), idx) + << "Don't support top view being hidden"; + NSView* nextView = [subViews objectAtIndex:(idx + 1)]; + CGFloat viewBottom = [view frame].origin.y; + CGFloat nextViewBottom = [nextView frame].origin.y; + moveDown += nextViewBottom - viewBottom; + } else { + if (moveDown != 0.0) { + NSPoint origin = [view frame].origin; + origin.y -= moveDown; + [view setFrameOrigin:origin]; + } + } + // Special case, if this is the stats checkbox, everything above it needs + // to get moved up by the amount it changed height. + if (view == statsCheckbox_) { + moveDown -= statsCheckboxHeightChange; + } + } + + // Resize the window for any height change from hidden views, etc. + if (moveDown != 0.0) { + NSView* contentView = [win contentView]; + [contentView setAutoresizesSubviews:NO]; + NSRect windowFrame = [contentView convertRect:[win frame] fromView:nil]; + windowFrame.size.height -= moveDown; + windowFrame = [contentView convertRect:windowFrame toView:nil]; + [win setFrame:windowFrame display:NO]; + [contentView setAutoresizesSubviews:YES]; + } + + } + // Neat weirdness in the below code - the Application menu stays enabled // while the window is open but selecting items from it (e.g. Quit) has // no effect. I'm guessing that this is an artifact of us being a @@ -52,7 +157,6 @@ // window. // Display dialog. - NSWindow* win = [self window]; [win center]; [NSApp runModalForWindow:win]; } @@ -77,4 +181,22 @@ [[NSWorkspace sharedWorkspace] openURL:learnMoreUrl]; } +// Custom property getters + +- (BOOL)importBookmarks { + // If the UI for browser import is hidden, report the choice as off. + if ([self browserImportListHidden]) { + return NO; + } + return importBookmarks_; +} + +- (BOOL)statsEnabled { + // If the UI for stats is hidden, report the choice as off. + if ([self statsCheckboxHidden]) { + return NO; + } + return statsEnabled_; +} + @end |