diff options
Diffstat (limited to 'chrome/browser/cocoa/nswindow_local_state.mm')
-rw-r--r-- | chrome/browser/cocoa/nswindow_local_state.mm | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/nswindow_local_state.mm b/chrome/browser/cocoa/nswindow_local_state.mm new file mode 100644 index 0000000..7fdfff6 --- /dev/null +++ b/chrome/browser/cocoa/nswindow_local_state.mm @@ -0,0 +1,37 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Cocoa/Cocoa.h> +#include "chrome/common/pref_service.h" + +@implementation NSWindow (LocalStateAdditions) + +- (void)saveWindowPositionToPrefs:(PrefService*)prefs + withPath:(const wchar_t*)path { + DCHECK(prefs); + // Save the origin of the window. + DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path); + NSRect frame = [self frame]; + windowPrefs->SetInteger(L"x", frame.origin.x); + windowPrefs->SetInteger(L"y", frame.origin.y); +} + +- (void)restoreWindowPositionFromPrefs:(PrefService*)prefs + withPath:(const wchar_t*)path { + DCHECK(prefs); + // Get the positioning information. + DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path); + int x = 0, y = 0; + windowPrefs->GetInteger(L"x", &x); + windowPrefs->GetInteger(L"y", &y); + // Turn the origin (lower-left) into an upper-left window point. + NSPoint upperLeft = NSMakePoint(x, y + [self frame].size.height); + NSPoint cascadePoint = [self cascadeTopLeftFromPoint:upperLeft]; + // Cascade again to get the offset when opening new windows. + [self cascadeTopLeftFromPoint:cascadePoint]; + // Force a save of the pref. + [self saveWindowPositionToPrefs:prefs withPath:path]; +} + +@end |