| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #import <Cocoa/Cocoa.h> | |
| 6 #include "chrome/common/pref_service.h" | |
| 7 | |
| 8 @implementation NSWindow (LocalStateAdditions) | |
| 9 | |
| 10 - (void)saveWindowPositionToPrefs:(PrefService*)prefs | |
| 11 withPath:(const wchar_t*)path { | |
| 12 DCHECK(prefs); | |
| 13 // Save the origin of the window. | |
| 14 DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path); | |
| 15 NSRect frame = [self frame]; | |
| 16 windowPrefs->SetInteger(L"x", frame.origin.x); | |
| 17 windowPrefs->SetInteger(L"y", frame.origin.y); | |
| 18 } | |
| 19 | |
| 20 - (void)restoreWindowPositionFromPrefs:(PrefService*)prefs | |
| 21 withPath:(const wchar_t*)path { | |
| 22 DCHECK(prefs); | |
| 23 // Get the positioning information. | |
| 24 DictionaryValue* windowPrefs = prefs->GetMutableDictionary(path); | |
| 25 int x = 0, y = 0; | |
| 26 windowPrefs->GetInteger(L"x", &x); | |
| 27 windowPrefs->GetInteger(L"y", &y); | |
| 28 // Turn the origin (lower-left) into an upper-left window point. | |
| 29 NSPoint upperLeft = NSMakePoint(x, y + [self frame].size.height); | |
| 30 NSPoint cascadePoint = [self cascadeTopLeftFromPoint:upperLeft]; | |
| 31 // Cascade again to get the offset when opening new windows. | |
| 32 [self cascadeTopLeftFromPoint:cascadePoint]; | |
| 33 // Force a save of the pref. | |
| 34 [self saveWindowPositionToPrefs:prefs withPath:path]; | |
| 35 } | |
| 36 | |
| 37 @end | |
| OLD | NEW |