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

Side by Side Diff: chrome/browser/cocoa/first_run_dialog.mm

Issue 3223010: Add search engine selection dialog for Mac.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 3 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/cocoa/first_run_dialog.h" 5 #import "chrome/browser/cocoa/first_run_dialog.h"
6 6
7 #include "app/l10n_util_mac.h" 7 #include "app/l10n_util_mac.h"
8 #include "base/logging.h"
9 #include "base/mac_util.h" 8 #include "base/mac_util.h"
10 #import "base/scoped_nsobject.h" 9 #include "base/message_loop.h"
11 #include "chrome/browser/browser_process.h" 10 #include "base/ref_counted.h"
12 #include "chrome/browser/prefs/pref_service.h"
13 #include "chrome/common/pref_names.h"
14 #include "grit/locale_settings.h" 11 #include "grit/locale_settings.h"
15 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h" 12 #import "third_party/GTM/AppKit/GTMUILocalizerAndLayoutTweaker.h"
16 13
14 @interface FirstRunDialogController (PrivateMethods)
15 // Show the dialog.
16 - (void)show;
17 @end
18
17 namespace { 19 namespace {
18 20
19 // Compare function for -[NSArray sortedArrayUsingFunction:context:] that 21 // Compare function for -[NSArray sortedArrayUsingFunction:context:] that
20 // sorts the views in Y order bottom up. 22 // sorts the views in Y order bottom up.
21 NSInteger CompareFrameY(id view1, id view2, void* context) { 23 NSInteger CompareFrameY(id view1, id view2, void* context) {
22 CGFloat y1 = NSMinY([view1 frame]); 24 CGFloat y1 = NSMinY([view1 frame]);
23 CGFloat y2 = NSMinY([view2 frame]); 25 CGFloat y2 = NSMinY([view2 frame]);
24 if (y1 < y2) 26 if (y1 < y2)
25 return NSOrderedAscending; 27 return NSOrderedAscending;
26 else if (y1 > y2) 28 else if (y1 > y2)
27 return NSOrderedDescending; 29 return NSOrderedDescending;
28 else 30 else
29 return NSOrderedSame; 31 return NSOrderedSame;
30 } 32 }
31 33
34 class FirstRunShowBridge : public base::RefCounted<FirstRunShowBridge> {
35 public:
36 FirstRunShowBridge(FirstRunDialogController* controller);
37
38 void ShowDialog();
39 private:
40 FirstRunDialogController* controller_;
41 };
42
43 FirstRunShowBridge::FirstRunShowBridge(
44 FirstRunDialogController* controller) : controller_(controller) {
45 }
46
47 void FirstRunShowBridge::ShowDialog() {
48 [controller_ show];
49 MessageLoop::current()->QuitNow();
50 }
51
32 }; 52 };
33 53
34 @implementation FirstRunDialogController 54 @implementation FirstRunDialogController
35 55
36 @synthesize userDidCancel = userDidCancel_;
37 @synthesize statsEnabled = statsEnabled_; 56 @synthesize statsEnabled = statsEnabled_;
38 @synthesize statsCheckboxHidden = statsCheckboxHidden_;
39 @synthesize makeDefaultBrowser = makeDefaultBrowser_; 57 @synthesize makeDefaultBrowser = makeDefaultBrowser_;
40 @synthesize importBookmarks = importBookmarks_;
41 @synthesize browserImportSelectedIndex = browserImportSelectedIndex_;
42 @synthesize browserImportList = browserImportList_;
43 @synthesize browserImportListHidden = browserImportListHidden_;
44 58
45 - (id)init { 59 - (id)init {
46 NSString* nibpath = 60 NSString* nibpath =
47 [mac_util::MainAppBundle() pathForResource:@"FirstRunDialog" 61 [mac_util::MainAppBundle() pathForResource:@"FirstRunDialog"
48 ofType:@"nib"]; 62 ofType:@"nib"];
49 self = [super initWithWindowNibPath:nibpath owner:self]; 63 self = [super initWithWindowNibPath:nibpath owner:self];
50 if (self != nil) { 64 if (self != nil) {
51 // Bound to the dialog checkbox, default to true. 65 // Bound to the dialog checkbox, default to true.
52 statsEnabled_ = YES; 66 statsEnabled_ = YES;
53 importBookmarks_ = YES;
54
55 #if defined(GOOGLE_CHROME_BUILD)
56 // If the send stats option is controlled by enterprise configuration
57 // management, hide the checkbox.
58 const PrefService::Preference* metrics_reporting_pref =
59 g_browser_process->local_state()->FindPreference(
60 prefs::kMetricsReportingEnabled);
61 if (metrics_reporting_pref && metrics_reporting_pref->IsManaged())
62 statsCheckboxHidden_ = YES;
63 #else
64 // In Chromium builds all stats reporting is disabled so there's no reason
65 // to display the checkbox - the setting is always OFF.
66 statsCheckboxHidden_ = YES;
67 #endif // !GOOGLE_CHROME_BUILD
68 } 67 }
69 return self; 68 return self;
70 } 69 }
71 70
72 - (void)dealloc { 71 - (void)dealloc {
73 [browserImportList_ release];
74 [super dealloc]; 72 [super dealloc];
75 } 73 }
76 74
77 - (IBAction)showWindow:(id)sender { 75 - (IBAction)showWindow:(id)sender {
76 // The main MessageLoop has not yet run, but has been spun. If we call
77 // -[NSApplication runModalForWindow:] we will hang <http://crbug.com/54248>.
78 // Therefore the main MessageLoop is run so things work.
79
80 scoped_refptr<FirstRunShowBridge> bridge = new FirstRunShowBridge(self);
81 MessageLoop::current()->PostTask(
82 FROM_HERE,
83 NewRunnableMethod(bridge.get(),
84 &FirstRunShowBridge::ShowDialog));
85 MessageLoop::current()->Run();
86 }
87
88 - (void)show {
78 NSWindow* win = [self window]; 89 NSWindow* win = [self window];
79 90
80 // Only support the sizing the window once. 91 // Only support the sizing the window once.
81 DCHECK(!beenSized_) << "ShowWindow was called twice?"; 92 DCHECK(!beenSized_) << "ShowWindow was called twice?";
82 if (!beenSized_) { 93 if (!beenSized_) {
83 beenSized_ = YES; 94 beenSized_ = YES;
84 DCHECK_GT([objectsToSize_ count], 0U); 95 DCHECK_GT([objectsToSize_ count], 0U);
85 96
86 // Size everything to fit, collecting the widest growth needed (XIB provides 97 // Size everything to fit, collecting the widest growth needed (XIB provides
87 // the min size, i.e.-never shrink, just grow). 98 // the min size, i.e.-never shrink, just grow).
(...skipping 11 matching lines...) Expand all
99 110
100 // Make the window wide enough to fit everything. 111 // Make the window wide enough to fit everything.
101 if (largestWidthChange > 0.0) { 112 if (largestWidthChange > 0.0) {
102 NSView* contentView = [win contentView]; 113 NSView* contentView = [win contentView];
103 NSRect windowFrame = [contentView convertRect:[win frame] fromView:nil]; 114 NSRect windowFrame = [contentView convertRect:[win frame] fromView:nil];
104 windowFrame.size.width += largestWidthChange; 115 windowFrame.size.width += largestWidthChange;
105 windowFrame = [contentView convertRect:windowFrame toView:nil]; 116 windowFrame = [contentView convertRect:windowFrame toView:nil];
106 [win setFrame:windowFrame display:NO]; 117 [win setFrame:windowFrame display:NO];
107 } 118 }
108 119
109 // The stats checkbox (if visible) gets some really long text, so it gets 120 // The stats checkbox gets some really long text, so it gets word wrapped
110 // word wrapped and then sized. 121 // and then sized.
111 DCHECK(statsCheckbox_); 122 DCHECK(statsCheckbox_);
112 CGFloat statsCheckboxHeightChange = 0.0; 123 CGFloat statsCheckboxHeightChange = 0.0;
113 if (![self statsCheckboxHidden]) { 124 [GTMUILocalizerAndLayoutTweaker wrapButtonTitleForWidth:statsCheckbox_];
114 [GTMUILocalizerAndLayoutTweaker wrapButtonTitleForWidth:statsCheckbox_]; 125 statsCheckboxHeightChange =
115 statsCheckboxHeightChange = 126 [GTMUILocalizerAndLayoutTweaker sizeToFitView:statsCheckbox_].height;
116 [GTMUILocalizerAndLayoutTweaker sizeToFitView:statsCheckbox_].height;
117 }
118 127
119 // Walk bottom up shuffling for all the hidden views. 128 // Walk bottom up shuffling for all the hidden views.
120 NSArray* subViews = 129 NSArray* subViews =
121 [[[win contentView] subviews] sortedArrayUsingFunction:CompareFrameY 130 [[[win contentView] subviews] sortedArrayUsingFunction:CompareFrameY
122 context:NULL]; 131 context:NULL];
123 CGFloat moveDown = 0.0; 132 CGFloat moveDown = 0.0;
124 NSUInteger numSubViews = [subViews count]; 133 NSUInteger numSubViews = [subViews count];
125 for (NSUInteger idx = 0 ; idx < numSubViews ; ++idx) { 134 for (NSUInteger idx = 0 ; idx < numSubViews ; ++idx) {
126 NSView* view = [subViews objectAtIndex:idx]; 135 NSView* view = [subViews objectAtIndex:idx];
127 136
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 // while the window is open but selecting items from it (e.g. Quit) has 174 // while the window is open but selecting items from it (e.g. Quit) has
166 // no effect. I'm guessing that this is an artifact of us being a 175 // no effect. I'm guessing that this is an artifact of us being a
167 // background-only application at this stage and displaying a modal 176 // background-only application at this stage and displaying a modal
168 // window. 177 // window.
169 178
170 // Display dialog. 179 // Display dialog.
171 [win center]; 180 [win center];
172 [NSApp runModalForWindow:win]; 181 [NSApp runModalForWindow:win];
173 } 182 }
174 183
175 - (void)closeDialog { 184 - (IBAction)ok:(id)sender {
176 [[self window] close]; 185 [[self window] close];
177 [NSApp stopModal]; 186 [NSApp stopModal];
178 } 187 }
179 188
180 - (IBAction)ok:(id)sender {
181 [self closeDialog];
182 }
183
184 - (IBAction)cancel:(id)sender {
185 [self closeDialog];
186 [self setUserDidCancel:YES];
187 }
188
189 - (IBAction)learnMore:(id)sender { 189 - (IBAction)learnMore:(id)sender {
190 NSString* urlStr = l10n_util::GetNSString(IDS_LEARN_MORE_REPORTING_URL); 190 NSString* urlStr = l10n_util::GetNSString(IDS_LEARN_MORE_REPORTING_URL);
191 NSURL* learnMoreUrl = [NSURL URLWithString:urlStr]; 191 NSURL* learnMoreUrl = [NSURL URLWithString:urlStr];
192 [[NSWorkspace sharedWorkspace] openURL:learnMoreUrl]; 192 [[NSWorkspace sharedWorkspace] openURL:learnMoreUrl];
193 } 193 }
194 194
195 // Custom property getters
196
197 - (BOOL)importBookmarks {
198 // If the UI for browser import is hidden, report the choice as off.
199 if ([self browserImportListHidden]) {
200 return NO;
201 }
202 return importBookmarks_;
203 }
204
205 - (BOOL)statsEnabled {
206 // If the UI for stats is hidden, report the choice as off.
207 if ([self statsCheckboxHidden]) {
208 return NO;
209 }
210 return statsEnabled_;
211 }
212
213 @end 195 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/first_run_dialog.h ('k') | chrome/browser/cocoa/search_engine_dialog_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698