summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/page_info_window_controller.mm
diff options
context:
space:
mode:
authorpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 14:19:09 +0000
committerpinkerton@chromium.org <pinkerton@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-21 14:19:09 +0000
commit61e76d9bf46423e8dcb6f77e8e91262af55b7a03 (patch)
treea02f4e6e9812331d7026705f4f08ba740607fa90 /chrome/browser/cocoa/page_info_window_controller.mm
parent1c9b152007f05e1767b05986e5cb69fbb2629e43 (diff)
downloadchromium_src-61e76d9bf46423e8dcb6f77e8e91262af55b7a03.zip
chromium_src-61e76d9bf46423e8dcb6f77e8e91262af55b7a03.tar.gz
chromium_src-61e76d9bf46423e8dcb6f77e8e91262af55b7a03.tar.bz2
Make the page info window remember its placement origin on the Mac
* Store x/y origin in the local state PrefService * Offset new windows when creating them so they don't overlap * Add a unit test for remembering window placement * Refactor PageInfoWindowControllerTest to make use of SetUp() Patch from Robert Sesek (rsesek@chromium.org) BUG=none TEST=Open a page info window and move it. Open another and it should open in the new location. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23954 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/page_info_window_controller.mm')
-rw-r--r--chrome/browser/cocoa/page_info_window_controller.mm49
1 files changed, 49 insertions, 0 deletions
diff --git a/chrome/browser/cocoa/page_info_window_controller.mm b/chrome/browser/cocoa/page_info_window_controller.mm
index afbdea8..9f3b813 100644
--- a/chrome/browser/cocoa/page_info_window_controller.mm
+++ b/chrome/browser/cocoa/page_info_window_controller.mm
@@ -5,7 +5,16 @@
#import "chrome/browser/cocoa/page_info_window_controller.h"
#include "base/mac_util.h"
+#include "base/values.h"
+#include "chrome/browser/browser_process.h"
#include "chrome/browser/cocoa/page_info_window_mac.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
+
+@interface PageInfoWindowController (Private)
+// Saves the window preference to the local state.
+- (void)saveWindowPositionToLocalState;
+@end
@implementation PageInfoWindowController
@synthesize identityImg = identityImg_;
@@ -33,6 +42,22 @@
}
- (void)awakeFromNib {
+ if (g_browser_process && g_browser_process->local_state()) {
+ // Get the positioning information.
+ PrefService* prefs = g_browser_process->local_state();
+ DictionaryValue* windowPrefs =
+ prefs->GetMutableDictionary(prefs::kPageInfoWindowPlacement);
+ 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 window] frame].size.height);
+ NSPoint cascadePoint = [[self window] cascadeTopLeftFromPoint:upperLeft];
+ // Cascade again to get the offset when opening new windows.
+ [[self window] cascadeTopLeftFromPoint:cascadePoint];
+ [self saveWindowPositionToLocalState]; // Force a save of the pref.
+ }
+
// By default, assume we have no history information.
[self setShowHistoryBox:NO];
}
@@ -88,4 +113,28 @@
[self autorelease];
}
+// The last page info window that was moved will determine the location of the
+// next new one.
+- (void)windowDidMove:(NSNotification*)notif {
+ [self saveWindowPositionToLocalState];
+}
+
+// Saves the window preference to the local state.
+- (void)saveWindowPositionToLocalState {
+ if (!g_browser_process || !g_browser_process->local_state())
+ return;
+ [self saveWindowPositionToPrefs:g_browser_process->local_state()];
+}
+
+// Saves the window's origin into the given PrefService. Caller is responsible
+// for making sure |prefs| is not NULL.
+- (void)saveWindowPositionToPrefs:(PrefService*)prefs {
+ // Save the origin of the window.
+ DictionaryValue* windowPrefs = prefs->GetMutableDictionary(
+ prefs::kPageInfoWindowPlacement);
+ NSRect frame = [[self window] frame];
+ windowPrefs->SetInteger(L"x", frame.origin.x);
+ windowPrefs->SetInteger(L"y", frame.origin.y);
+}
+
@end