OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/preferences_window_controller.h" | 5 #import "chrome/browser/cocoa/preferences_window_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
9 #include "base/mac_util.h" | 9 #include "base/mac_util.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/browser.h" | 12 #include "chrome/browser/browser.h" |
13 #include "chrome/browser/browser_list.h" | 13 #include "chrome/browser/browser_list.h" |
14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
15 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" | 15 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" |
16 #import "chrome/browser/cocoa/custom_home_pages_model.h" | 16 #import "chrome/browser/cocoa/custom_home_pages_model.h" |
17 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" | 17 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" |
18 #import "chrome/browser/cocoa/search_engine_list_model.h" | 18 #import "chrome/browser/cocoa/search_engine_list_model.h" |
19 #include "chrome/browser/extensions/extensions_service.h" | 19 #include "chrome/browser/extensions/extensions_service.h" |
20 #include "chrome/browser/metrics/metrics_service.h" | 20 #include "chrome/browser/metrics/metrics_service.h" |
21 #include "chrome/browser/metrics/user_metrics.h" | 21 #include "chrome/browser/metrics/user_metrics.h" |
22 #include "chrome/browser/net/dns_global.h" | 22 #include "chrome/browser/net/dns_global.h" |
23 #include "chrome/browser/net/url_fixer_upper.h" | 23 #include "chrome/browser/net/url_fixer_upper.h" |
| 24 #include "chrome/browser/options_window.h" |
24 #include "chrome/browser/profile.h" | 25 #include "chrome/browser/profile.h" |
25 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 26 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
26 #include "chrome/browser/session_startup_pref.h" | 27 #include "chrome/browser/session_startup_pref.h" |
27 #include "chrome/browser/shell_integration.h" | 28 #include "chrome/browser/shell_integration.h" |
28 #include "chrome/browser/tab_contents/tab_contents.h" | 29 #include "chrome/browser/tab_contents/tab_contents.h" |
29 #include "chrome/common/notification_details.h" | 30 #include "chrome/common/notification_details.h" |
30 #include "chrome/common/notification_observer.h" | 31 #include "chrome/common/notification_observer.h" |
31 #include "chrome/common/notification_type.h" | 32 #include "chrome/common/notification_type.h" |
32 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
33 #include "chrome/common/pref_service.h" | 34 #include "chrome/common/pref_service.h" |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 | 201 |
201 // Put the advanced view into the scroller and scroll it to the top. | 202 // Put the advanced view into the scroller and scroll it to the top. |
202 [advancedScroller_ setDocumentView:advancedView_]; | 203 [advancedScroller_ setDocumentView:advancedView_]; |
203 [advancedView_ scrollPoint:NSMakePoint(0, advancedContentSize.height)]; | 204 [advancedView_ scrollPoint:NSMakePoint(0, advancedContentSize.height)]; |
204 | 205 |
205 // Adjust the view origins so they show up centered. | 206 // Adjust the view origins so they show up centered. |
206 CenterViewForWidth(basicsView_, widest); | 207 CenterViewForWidth(basicsView_, widest); |
207 CenterViewForWidth(personalStuffView_, widest); | 208 CenterViewForWidth(personalStuffView_, widest); |
208 CenterViewForWidth(underTheHoodView_, widest); | 209 CenterViewForWidth(underTheHoodView_, widest); |
209 | 210 |
210 // Ensure the "basics" is selected. | 211 // Get the last visited page from local state. |
211 // TODO: change this to remember what's selected in a preference and restore | 212 OptionsPage page = static_cast<OptionsPage>(lastSelectedPage_.GetValue()); |
212 // it. | 213 if (page == OPTIONS_PAGE_DEFAULT) |
| 214 page = OPTIONS_PAGE_GENERAL; |
213 | 215 |
214 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:0]; | 216 NSUInteger pageIndex = (NSUInteger)page; |
| 217 if (pageIndex >= [[toolbar_ items] count]) |
| 218 pageIndex = 0; |
| 219 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:pageIndex]; |
215 [self displayPreferenceViewForToolbarItem:firstItem animate:NO]; | 220 [self displayPreferenceViewForToolbarItem:firstItem animate:NO]; |
216 [toolbar_ setSelectedItemIdentifier:[firstItem itemIdentifier]]; | 221 [toolbar_ setSelectedItemIdentifier:[firstItem itemIdentifier]]; |
217 | 222 |
218 // TODO(pinkerton): save/restore position based on prefs. | 223 // TODO(pinkerton): save/restore position based on prefs. |
219 [[self window] center]; | 224 [[self window] center]; |
220 } | 225 } |
221 | 226 |
222 - (void)dealloc { | 227 - (void)dealloc { |
223 [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"]; | 228 [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"]; |
224 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 229 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // know it's there). | 273 // know it's there). |
269 PrefService* local = g_browser_process->local_state(); | 274 PrefService* local = g_browser_process->local_state(); |
270 if (!local) | 275 if (!local) |
271 local = prefs_; | 276 local = prefs_; |
272 metricsRecording_.Init(prefs::kMetricsReportingEnabled, | 277 metricsRecording_.Init(prefs::kMetricsReportingEnabled, |
273 local, observer_.get()); | 278 local, observer_.get()); |
274 cookieBehavior_.Init(prefs::kCookieBehavior, prefs_, observer_.get()); | 279 cookieBehavior_.Init(prefs::kCookieBehavior, prefs_, observer_.get()); |
275 defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, | 280 defaultDownloadLocation_.Init(prefs::kDownloadDefaultDirectory, prefs_, |
276 observer_.get()); | 281 observer_.get()); |
277 askForSaveLocation_.Init(prefs::kPromptForDownload, prefs_, observer_.get()); | 282 askForSaveLocation_.Init(prefs::kPromptForDownload, prefs_, observer_.get()); |
| 283 |
| 284 // We don't need to observe changes in this value. |
| 285 lastSelectedPage_.Init(prefs::kOptionsWindowLastTabIndex, local, NULL); |
278 } | 286 } |
279 | 287 |
280 // Clean up what was registered in -registerPrefObservers. We only have to | 288 // Clean up what was registered in -registerPrefObservers. We only have to |
281 // clean up the non-PrefMember registrations. | 289 // clean up the non-PrefMember registrations. |
282 - (void)unregisterPrefObservers { | 290 - (void)unregisterPrefObservers { |
283 if (!prefs_) return; | 291 if (!prefs_) return; |
284 | 292 |
285 // Basics | 293 // Basics |
286 prefs_->RemovePrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); | 294 prefs_->RemovePrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); |
287 | 295 |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
844 - (IBAction)toolbarButtonSelected:(id)sender { | 852 - (IBAction)toolbarButtonSelected:(id)sender { |
845 DCHECK([sender isKindOfClass:[NSToolbarItem class]]); | 853 DCHECK([sender isKindOfClass:[NSToolbarItem class]]); |
846 [self displayPreferenceViewForToolbarItem:sender | 854 [self displayPreferenceViewForToolbarItem:sender |
847 animate:YES]; | 855 animate:YES]; |
848 } | 856 } |
849 | 857 |
850 // Helper to update the window to display a preferences view for a toolbaritem. | 858 // Helper to update the window to display a preferences view for a toolbaritem. |
851 - (void)displayPreferenceViewForToolbarItem:(NSToolbarItem*)toolbarItem | 859 - (void)displayPreferenceViewForToolbarItem:(NSToolbarItem*)toolbarItem |
852 animate:(BOOL)animate { | 860 animate:(BOOL)animate { |
853 NSView* prefsView = NULL; | 861 NSView* prefsView = NULL; |
| 862 OptionsPage page = OPTIONS_PAGE_DEFAULT; |
854 // Tags are set in the nib file. | 863 // Tags are set in the nib file. |
855 switch ([toolbarItem tag]) { | 864 switch ([toolbarItem tag]) { |
856 case 0: // Basics | 865 case 0: // Basics |
857 prefsView = basicsView_; | 866 prefsView = basicsView_; |
| 867 page = OPTIONS_PAGE_GENERAL; |
858 break; | 868 break; |
859 case 1: // Personal Stuff | 869 case 1: // Personal Stuff |
860 prefsView = personalStuffView_; | 870 prefsView = personalStuffView_; |
| 871 page = OPTIONS_PAGE_CONTENT; |
861 break; | 872 break; |
862 case 2: // Under the Hood | 873 case 2: // Under the Hood |
863 prefsView = underTheHoodView_; | 874 prefsView = underTheHoodView_; |
| 875 page = OPTIONS_PAGE_ADVANCED; |
864 break; | 876 break; |
865 default: | 877 default: |
866 NOTIMPLEMENTED(); | 878 NOTIMPLEMENTED(); |
867 } | 879 } |
868 | 880 |
869 NSWindow* prefsWindow = [self window]; | 881 NSWindow* prefsWindow = [self window]; |
870 NSView* contentView = [prefsWindow contentView]; | 882 NSView* contentView = [prefsWindow contentView]; |
871 | 883 |
872 // Normally there is only one view, but if the user clicks really quickly, the | 884 // Normally there is only one view, but if the user clicks really quickly, the |
873 // animation could still been running, and the last view is the one that was | 885 // animation could still been running, and the last view is the one that was |
874 // animating in. | 886 // animating in. |
875 NSArray* subviews = [contentView subviews]; | 887 NSArray* subviews = [contentView subviews]; |
876 NSView* currentPrefsView = nil; | 888 NSView* currentPrefsView = nil; |
877 if ([subviews count]) { | 889 if ([subviews count]) { |
878 currentPrefsView = [subviews lastObject]; | 890 currentPrefsView = [subviews lastObject]; |
879 } | 891 } |
880 | 892 |
881 // Make sure we aren't being told to display the same thing again. | 893 // Make sure we aren't being told to display the same thing again. |
882 if (currentPrefsView == prefsView) { | 894 if (currentPrefsView == prefsView) { |
883 return; | 895 return; |
884 } | 896 } |
885 | 897 |
| 898 // Remember new options page as current page. |
| 899 if (page != OPTIONS_PAGE_DEFAULT) |
| 900 lastSelectedPage_.SetValue(page); |
| 901 |
886 // Stop any running animation, and remove any past views that were on the way | 902 // Stop any running animation, and remove any past views that were on the way |
887 // out. | 903 // out. |
888 [animation_ stopAnimation]; | 904 [animation_ stopAnimation]; |
889 if ([subviews count]) { | 905 if ([subviews count]) { |
890 RemoveAllButLastView(subviews); | 906 RemoveAllButLastView(subviews); |
891 } | 907 } |
892 | 908 |
893 NSRect prefsViewFrame = [prefsView frame]; | 909 NSRect prefsViewFrame = [prefsView frame]; |
894 NSRect contentViewFrame = [contentView frame]; | 910 NSRect contentViewFrame = [contentView frame]; |
895 if (animate) { | 911 if (animate) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1142 [[NSNotificationCenter defaultCenter] | 1158 [[NSNotificationCenter defaultCenter] |
1143 postNotificationName:kUserDoneEditingPrefsNotification | 1159 postNotificationName:kUserDoneEditingPrefsNotification |
1144 object:self]; | 1160 object:self]; |
1145 } | 1161 } |
1146 | 1162 |
1147 - (void)controlTextDidEndEditing:(NSNotification*)notification { | 1163 - (void)controlTextDidEndEditing:(NSNotification*)notification { |
1148 [customPagesSource_ validateURLs]; | 1164 [customPagesSource_ validateURLs]; |
1149 } | 1165 } |
1150 | 1166 |
1151 @end | 1167 @end |
OLD | NEW |