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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/preferences_window_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/preferences_window_controller.mm
===================================================================
--- chrome/browser/cocoa/preferences_window_controller.mm (revision 28114)
+++ chrome/browser/cocoa/preferences_window_controller.mm (working copy)
@@ -4,6 +4,7 @@
#import "chrome/browser/cocoa/preferences_window_controller.h"
+#include <algorithm>
#include "app/l10n_util.h"
#include "base/mac_util.h"
#include "base/string_util.h"
@@ -41,10 +42,19 @@
@"kUserDoneEditingPrefsNotification";
namespace {
+
std::wstring GetNewTabUIURLString() {
std::wstring temp = UTF8ToWide(chrome::kChromeUINewTabURL);
return URLFixerUpper::FixupURL(temp, std::wstring());
}
+
+// Adjusts the views origin so it will be centered if in a given width parent.
+void CenterViewForWidth(NSView* view, CGFloat width) {
+ NSRect frame = [view frame];
+ frame.origin.x = (width - NSWidth(frame)) / 2.0;
+ [view setFrame:frame];
+}
+
} // namespace
//-------------------------------------------------------------------------
@@ -75,6 +85,7 @@
- (void)setMetricsRecording:(BOOL)value;
- (void)setCookieBehavior:(NSInteger)value;
- (void)setAskForSaveLocation:(BOOL)value;
+- (void)displayPreferenceView:(NSView*)subView;
@end
// A C++ class registered for changes in preferences. Bridges the
@@ -146,17 +157,32 @@
}
- (void)awakeFromNib {
- // TODO(pinkerton): save/restore size based on prefs.
- [[self window] center];
-
// Put the advanced view into the scroller and scroll it to the top.
[advancedScroller_ setDocumentView:advancedView_];
NSInteger height = [advancedView_ bounds].size.height;
[advancedView_ scrollPoint:NSMakePoint(0, height)];
- // Ensure the "basics" tab is selected regardless of what is the selected
- // tab in the nib.
- [tabView_ selectFirstTabViewItem:self];
+ // Make sure the window is wide enough to fit the the widest view
+ CGFloat widest = std::max([basicsView_ frame].size.width,
+ [personalStuffView_ frame].size.width);
+ widest = std::max(widest, [underTheHoodView_ frame].size.width);
+ NSWindow* prefsWindow = [self window];
+ NSRect frame = [prefsWindow frame];
+ frame.size.width = widest;
+ [prefsWindow setFrame:frame display:NO];
+
+ // Adjust the view origins so they show up centered.
+ CenterViewForWidth(basicsView_, widest);
+ CenterViewForWidth(personalStuffView_, widest);
+ CenterViewForWidth(underTheHoodView_, widest);
+
+ // 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
+ NSToolbarItem* firstItem = [[toolbar_ items] objectAtIndex:0];
+ [toolbar_ setSelectedItemIdentifier:[firstItem itemIdentifier]];
+ [self displayPreferenceView:basicsView_];
+
+ // TODO(pinkerton): save/restore position based on prefs.
+ [[self window] center];
}
- (void)dealloc {
@@ -166,6 +192,14 @@
[super dealloc];
}
+// Xcode 3.1.x version of Interface Builder doesn't do a lot for editing
+// toolbars in XIB. So the toolbar's delegate is set to the controller so it
+// can tell the toolbar what items are selectable.
+- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar {
pink (ping after 24hrs) 2009/10/06 21:30:21 chrome style is NSArray*, not NSArray *
+ DCHECK(toolbar == toolbar_);
+ return [[toolbar_ items] valueForKey:@"itemIdentifier"];
+}
+
// Register our interest in the preferences we're displaying so if anything
// else in the UI changes them we will be updated.
- (void)registerPrefObservers {
@@ -765,6 +799,58 @@
contextInfo:NULL];
}
+- (IBAction)toolbarButtonSelected:(id)sender {
+ DCHECK([sender isKindOfClass:[NSToolbarItem class]]);
+ NSToolbarItem* toolbarItem = sender;
+
+ NSView* prefsView = NULL;
+ // Tags are set in the nib file.
+ switch ([toolbarItem tag]) {
+ case 0: // Basics
+ prefsView = basicsView_;
+ break;
+ case 1: // Personal Stuff
+ prefsView = personalStuffView_;
+ break;
+ case 2: // Under the Hood
+ prefsView = underTheHoodView_;
+ break;
+ default:
+ NOTIMPLEMENTED();
+ }
+
+ [self displayPreferenceView:prefsView];
+}
+
+- (void)displayPreferenceView:(NSView*)prefsView {
pink (ping after 24hrs) 2009/10/06 21:30:21 function-level comment?
+ NSWindow* prefsWindow = [self window];
+ NSView* contentView = [prefsWindow contentView];
+
+ // Remove the previous view
pink (ping after 24hrs) 2009/10/06 21:30:21 period at end of sentence (all comments in this me
+ NSArray* subviews = [contentView subviews];
+ DCHECK_LE([subviews count], 1U);
+ if ([subviews count]) {
+ [[subviews objectAtIndex:0] removeFromSuperviewWithoutNeedingDisplay];
+ }
+
+ // Set the size of the window
+ NSRect windowFrame = [prefsWindow frame];
+ CGFloat titleToolbarHeight =
+ NSHeight(windowFrame) -
+ NSHeight([prefsWindow contentRectForFrameRect:windowFrame]);
+ NSRect prefsViewFrame = [prefsView frame];
+ windowFrame.size.height =
+ NSHeight(prefsViewFrame) + titleToolbarHeight;
+ DCHECK_GE(NSWidth(windowFrame), NSWidth(prefsViewFrame))
+ << "Initial width set wasn't wide enough.";
+ windowFrame.origin.y = NSMaxY([prefsWindow frame]) - NSHeight(windowFrame);
+ [prefsWindow setFrame:windowFrame display:YES];
+
+ // Add the view
+ [contentView addSubview:prefsView];
+ [prefsWindow setInitialFirstResponder:prefsView];
+}
+
// Returns whether the alternate error page checkbox should be checked based
// on the preference.
- (BOOL)showAlternateErrorPages {
« 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