blob: 42bc9486a2b4fb0dafd7756618716e8937635232 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
|