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

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

Issue 242162: First step in l10n for the prefs window.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 2 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 | « chrome/browser/cocoa/preferences_window_controller.h ('k') | 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) 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 "app/l10n_util.h" 8 #include "app/l10n_util.h"
8 #include "base/mac_util.h" 9 #include "base/mac_util.h"
9 #include "base/string_util.h" 10 #include "base/string_util.h"
10 #include "base/sys_string_conversions.h" 11 #include "base/sys_string_conversions.h"
11 #include "chrome/browser/browser.h" 12 #include "chrome/browser/browser.h"
12 #include "chrome/browser/browser_list.h" 13 #include "chrome/browser/browser_list.h"
13 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
14 #import "chrome/browser/cocoa/clear_browsing_data_controller.h" 15 #import "chrome/browser/cocoa/clear_browsing_data_controller.h"
15 #import "chrome/browser/cocoa/custom_home_pages_model.h" 16 #import "chrome/browser/cocoa/custom_home_pages_model.h"
16 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h" 17 #import "chrome/browser/cocoa/keyword_editor_cocoa_controller.h"
(...skipping 17 matching lines...) Expand all
34 #include "chrome/installer/util/google_update_settings.h" 35 #include "chrome/installer/util/google_update_settings.h"
35 #include "grit/chromium_strings.h" 36 #include "grit/chromium_strings.h"
36 #include "grit/generated_resources.h" 37 #include "grit/generated_resources.h"
37 #include "grit/locale_settings.h" 38 #include "grit/locale_settings.h"
38 #include "net/base/cookie_policy.h" 39 #include "net/base/cookie_policy.h"
39 40
40 NSString* const kUserDoneEditingPrefsNotification = 41 NSString* const kUserDoneEditingPrefsNotification =
41 @"kUserDoneEditingPrefsNotification"; 42 @"kUserDoneEditingPrefsNotification";
42 43
43 namespace { 44 namespace {
45
44 std::wstring GetNewTabUIURLString() { 46 std::wstring GetNewTabUIURLString() {
45 std::wstring temp = UTF8ToWide(chrome::kChromeUINewTabURL); 47 std::wstring temp = UTF8ToWide(chrome::kChromeUINewTabURL);
46 return URLFixerUpper::FixupURL(temp, std::wstring()); 48 return URLFixerUpper::FixupURL(temp, std::wstring());
47 } 49 }
50
51 // Adjusts the views origin so it will be centered if in a given width parent.
52 void CenterViewForWidth(NSView* view, CGFloat width) {
53 NSRect frame = [view frame];
54 frame.origin.x = (width - NSWidth(frame)) / 2.0;
55 [view setFrame:frame];
56 }
57
48 } // namespace 58 } // namespace
49 59
50 //------------------------------------------------------------------------- 60 //-------------------------------------------------------------------------
51 61
52 @interface PreferencesWindowController(Private) 62 @interface PreferencesWindowController(Private)
53 // Callback when preferences are changed. |prefName| is the name of the 63 // Callback when preferences are changed. |prefName| is the name of the
54 // pref that has changed. 64 // pref that has changed.
55 - (void)prefChanged:(std::wstring*)prefName; 65 - (void)prefChanged:(std::wstring*)prefName;
56 // Record the user performed a certain action and save the preferences. 66 // Record the user performed a certain action and save the preferences.
57 - (void)recordUserAction:(const wchar_t*)action; 67 - (void)recordUserAction:(const wchar_t*)action;
(...skipping 10 matching lines...) Expand all
68 - (void)setShowPageOptionsButtons:(BOOL)value; 78 - (void)setShowPageOptionsButtons:(BOOL)value;
69 - (void)setPasswordManagerEnabledIndex:(NSInteger)value; 79 - (void)setPasswordManagerEnabledIndex:(NSInteger)value;
70 - (void)setFormAutofillEnabledIndex:(NSInteger)value; 80 - (void)setFormAutofillEnabledIndex:(NSInteger)value;
71 - (void)setShowAlternateErrorPages:(BOOL)value; 81 - (void)setShowAlternateErrorPages:(BOOL)value;
72 - (void)setUseSuggest:(BOOL)value; 82 - (void)setUseSuggest:(BOOL)value;
73 - (void)setDnsPrefetch:(BOOL)value; 83 - (void)setDnsPrefetch:(BOOL)value;
74 - (void)setSafeBrowsing:(BOOL)value; 84 - (void)setSafeBrowsing:(BOOL)value;
75 - (void)setMetricsRecording:(BOOL)value; 85 - (void)setMetricsRecording:(BOOL)value;
76 - (void)setCookieBehavior:(NSInteger)value; 86 - (void)setCookieBehavior:(NSInteger)value;
77 - (void)setAskForSaveLocation:(BOOL)value; 87 - (void)setAskForSaveLocation:(BOOL)value;
88 - (void)displayPreferenceView:(NSView*)subView;
78 @end 89 @end
79 90
80 // A C++ class registered for changes in preferences. Bridges the 91 // A C++ class registered for changes in preferences. Bridges the
81 // notification back to the PWC. 92 // notification back to the PWC.
82 class PrefObserverBridge : public NotificationObserver { 93 class PrefObserverBridge : public NotificationObserver {
83 public: 94 public:
84 PrefObserverBridge(PreferencesWindowController* controller) 95 PrefObserverBridge(PreferencesWindowController* controller)
85 : controller_(controller) { } 96 : controller_(controller) { }
86 // Overridden from NotificationObserver: 97 // Overridden from NotificationObserver:
87 virtual void Observe(NotificationType type, 98 virtual void Observe(NotificationType type,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 object:searchEngineModel_.get()]; 150 object:searchEngineModel_.get()];
140 151
141 // This needs to be done before awakeFromNib: because the bindings set up 152 // This needs to be done before awakeFromNib: because the bindings set up
142 // in the nib rely on it. 153 // in the nib rely on it.
143 [self registerPrefObservers]; 154 [self registerPrefObservers];
144 } 155 }
145 return self; 156 return self;
146 } 157 }
147 158
148 - (void)awakeFromNib { 159 - (void)awakeFromNib {
149 // TODO(pinkerton): save/restore size based on prefs.
150 [[self window] center];
151
152 // Put the advanced view into the scroller and scroll it to the top. 160 // Put the advanced view into the scroller and scroll it to the top.
153 [advancedScroller_ setDocumentView:advancedView_]; 161 [advancedScroller_ setDocumentView:advancedView_];
154 NSInteger height = [advancedView_ bounds].size.height; 162 NSInteger height = [advancedView_ bounds].size.height;
155 [advancedView_ scrollPoint:NSMakePoint(0, height)]; 163 [advancedView_ scrollPoint:NSMakePoint(0, height)];
156 164
157 // Ensure the "basics" tab is selected regardless of what is the selected 165 // Make sure the window is wide enough to fit the the widest view
158 // tab in the nib. 166 CGFloat widest = std::max([basicsView_ frame].size.width,
159 [tabView_ selectFirstTabViewItem:self]; 167 [personalStuffView_ frame].size.width);
168 widest = std::max(widest, [underTheHoodView_ frame].size.width);
169 NSWindow* prefsWindow = [self window];
170 NSRect frame = [prefsWindow frame];
171 frame.size.width = widest;
172 [prefsWindow setFrame:frame display:NO];
173
174 // Adjust the view origins so they show up centered.
175 CenterViewForWidth(basicsView_, widest);
176 CenterViewForWidth(personalStuffView_, widest);
177 CenterViewForWidth(underTheHoodView_, widest);
178
179 // Ensure the "basics" is selected.
pink (ping after 24hrs) 2009/10/06 21:30:21 add a TODO here to record the selected view when c
180 NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:0];
181 [toolbar_ setSelectedItemIdentifier:[firstItem itemIdentifier]];
182 [self displayPreferenceView:basicsView_];
183
184 // TODO(pinkerton): save/restore position based on prefs.
185 [[self window] center];
160 } 186 }
161 187
162 - (void)dealloc { 188 - (void)dealloc {
163 [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"]; 189 [customPagesSource_ removeObserver:self forKeyPath:@"customHomePages"];
164 [[NSNotificationCenter defaultCenter] removeObserver:self]; 190 [[NSNotificationCenter defaultCenter] removeObserver:self];
165 [self unregisterPrefObservers]; 191 [self unregisterPrefObservers];
166 [super dealloc]; 192 [super dealloc];
167 } 193 }
168 194
195 // Xcode 3.1.x version of Interface Builder doesn't do a lot for editing
196 // toolbars in XIB. So the toolbar's delegate is set to the controller so it
197 // can tell the toolbar what items are selectable.
198 - (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {
pink (ping after 24hrs) 2009/10/06 21:30:21 chrome style is NSArray*, not NSArray *
199 DCHECK(toolbar == toolbar_);
200 return [[toolbar_ items] valueForKey:@"itemIdentifier"];
201 }
202
169 // Register our interest in the preferences we're displaying so if anything 203 // Register our interest in the preferences we're displaying so if anything
170 // else in the UI changes them we will be updated. 204 // else in the UI changes them we will be updated.
171 - (void)registerPrefObservers { 205 - (void)registerPrefObservers {
172 if (!prefs_) return; 206 if (!prefs_) return;
173 207
174 // Basics panel 208 // Basics panel
175 prefs_->AddPrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get()); 209 prefs_->AddPrefObserver(prefs::kURLsToRestoreOnStartup, observer_.get());
176 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get()); 210 restoreOnStartup_.Init(prefs::kRestoreOnStartup, prefs_, observer_.get());
177 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage, 211 newTabPageIsHomePage_.Init(prefs::kHomePageIsNewTabPage,
178 prefs_, observer_.get()); 212 prefs_, observer_.get());
(...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after
758 NSString* path = base::SysWideToNSString(defaultDownloadLocation_.GetValue()); 792 NSString* path = base::SysWideToNSString(defaultDownloadLocation_.GetValue());
759 [panel beginSheetForDirectory:path 793 [panel beginSheetForDirectory:path
760 file:nil 794 file:nil
761 types:nil 795 types:nil
762 modalForWindow:[self window] 796 modalForWindow:[self window]
763 modalDelegate:self 797 modalDelegate:self
764 didEndSelector:@selector(downloadPathPanelDidEnd:code:context:) 798 didEndSelector:@selector(downloadPathPanelDidEnd:code:context:)
765 contextInfo:NULL]; 799 contextInfo:NULL];
766 } 800 }
767 801
802 - (IBAction)toolbarButtonSelected:(id)sender {
803 DCHECK([sender isKindOfClass:[NSToolbarItem class]]);
804 NSToolbarItem* toolbarItem = sender;
805
806 NSView* prefsView = NULL;
807 // Tags are set in the nib file.
808 switch ([toolbarItem tag]) {
809 case 0: // Basics
810 prefsView = basicsView_;
811 break;
812 case 1: // Personal Stuff
813 prefsView = personalStuffView_;
814 break;
815 case 2: // Under the Hood
816 prefsView = underTheHoodView_;
817 break;
818 default:
819 NOTIMPLEMENTED();
820 }
821
822 [self displayPreferenceView:prefsView];
823 }
824
825 - (void)displayPreferenceView:(NSView*)prefsView {
pink (ping after 24hrs) 2009/10/06 21:30:21 function-level comment?
826 NSWindow* prefsWindow = [self window];
827 NSView* contentView = [prefsWindow contentView];
828
829 // Remove the previous view
pink (ping after 24hrs) 2009/10/06 21:30:21 period at end of sentence (all comments in this me
830 NSArray* subviews = [contentView subviews];
831 DCHECK_LE([subviews count], 1U);
832 if ([subviews count]) {
833 [[subviews objectAtIndex:0] removeFromSuperviewWithoutNeedingDisplay];
834 }
835
836 // Set the size of the window
837 NSRect windowFrame = [prefsWindow frame];
838 CGFloat titleToolbarHeight =
839 NSHeight(windowFrame) -
840 NSHeight([prefsWindow contentRectForFrameRect:windowFrame]);
841 NSRect prefsViewFrame = [prefsView frame];
842 windowFrame.size.height =
843 NSHeight(prefsViewFrame) + titleToolbarHeight;
844 DCHECK_GE(NSWidth(windowFrame), NSWidth(prefsViewFrame))
845 << "Initial width set wasn't wide enough.";
846 windowFrame.origin.y = NSMaxY([prefsWindow frame]) - NSHeight(windowFrame);
847 [prefsWindow setFrame:windowFrame display:YES];
848
849 // Add the view
850 [contentView addSubview:prefsView];
851 [prefsWindow setInitialFirstResponder:prefsView];
852 }
853
768 // Returns whether the alternate error page checkbox should be checked based 854 // Returns whether the alternate error page checkbox should be checked based
769 // on the preference. 855 // on the preference.
770 - (BOOL)showAlternateErrorPages { 856 - (BOOL)showAlternateErrorPages {
771 return alternateErrorPages_.GetValue() ? YES : NO; 857 return alternateErrorPages_.GetValue() ? YES : NO;
772 } 858 }
773 859
774 // Sets the backend pref for whether or not the alternate error page checkbox 860 // Sets the backend pref for whether or not the alternate error page checkbox
775 // should be displayed based on |value|. 861 // should be displayed based on |value|.
776 - (void)setShowAlternateErrorPages:(BOOL)value { 862 - (void)setShowAlternateErrorPages:(BOOL)value {
777 if (value) 863 if (value)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 [[NSNotificationCenter defaultCenter] 1033 [[NSNotificationCenter defaultCenter]
948 postNotificationName:kUserDoneEditingPrefsNotification 1034 postNotificationName:kUserDoneEditingPrefsNotification
949 object:self]; 1035 object:self];
950 } 1036 }
951 1037
952 - (void)controlTextDidEndEditing:(NSNotification*)notification { 1038 - (void)controlTextDidEndEditing:(NSNotification*)notification {
953 [customPagesSource_ validateURLs]; 1039 [customPagesSource_ validateURLs];
954 } 1040 }
955 1041
956 @end 1042 @end
OLDNEW
« no previous file with comments | « chrome/browser/cocoa/preferences_window_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698