diff options
author | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 10:42:24 +0000 |
---|---|---|
committer | bauerb@chromium.org <bauerb@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-17 10:42:24 +0000 |
commit | eaeb284d58943f92ce1922391a0fae4ec767f18b (patch) | |
tree | 0ec1a1b5e7a30065813dea27311b57675c9f47f5 | |
parent | 97915056ed1464cf5601981bf5f9a90de5ee23e5 (diff) | |
download | chromium_src-eaeb284d58943f92ce1922391a0fae4ec767f18b.zip chromium_src-eaeb284d58943f92ce1922391a0fae4ec767f18b.tar.gz chromium_src-eaeb284d58943f92ce1922391a0fae4ec767f18b.tar.bz2 |
Change WindowSizeAutoSaver to store window size only when the window has resize controls.
BUG=51778
TEST=Automatically saved windows are correctly restored (see bug), unit test: WindowSizeAutosaverTest.*
Review URL: http://codereview.chromium.org/3115005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56328 0039d316-1c4b-4281-b951-d872f2087c98
8 files changed, 26 insertions, 44 deletions
diff --git a/chrome/browser/autofill/autofill_dialog_controller_mac.mm b/chrome/browser/autofill/autofill_dialog_controller_mac.mm index 24a08ec..fe28c53 100644 --- a/chrome/browser/autofill/autofill_dialog_controller_mac.mm +++ b/chrome/browser/autofill/autofill_dialog_controller_mac.mm @@ -718,8 +718,7 @@ void PersonalDataManagerObserver::OnPersonalDataLoaded() { sizeSaver_.reset([[WindowSizeAutosaver alloc] initWithWindow:[self window] prefService:g_browser_process->local_state() - path:prefs::kAutoFillDialogPlacement - state:kSaveWindowPos]); + path:prefs::kAutoFillDialogPlacement]); } [NSApp runModalForWindow:[self window]]; diff --git a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm index 21c7a20..2ad5819 100644 --- a/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm +++ b/chrome/browser/cocoa/keyword_editor_cocoa_controller.mm @@ -156,8 +156,7 @@ typedef std::map<Profile*,KeywordEditorCocoaController*> ProfileControllerMap; sizeSaver_.reset([[WindowSizeAutosaver alloc] initWithWindow:[self window] prefService:g_browser_process->local_state() - path:prefs::kKeywordEditorWindowPlacement - state:kSaveWindowRect]); + path:prefs::kKeywordEditorWindowPlacement]); } } return self; diff --git a/chrome/browser/cocoa/page_info_window_controller.mm b/chrome/browser/cocoa/page_info_window_controller.mm index fc98b02..263e8ea 100644 --- a/chrome/browser/cocoa/page_info_window_controller.mm +++ b/chrome/browser/cocoa/page_info_window_controller.mm @@ -40,8 +40,7 @@ const NSInteger kWindowWidth = 460; sizeSaver_.reset([[WindowSizeAutosaver alloc] initWithWindow:[self window] prefService:g_browser_process->local_state() - path:prefs::kPageInfoWindowPlacement - state:kSaveWindowPos]); + path:prefs::kPageInfoWindowPlacement]); } } return self; diff --git a/chrome/browser/cocoa/preferences_window_controller.mm b/chrome/browser/cocoa/preferences_window_controller.mm index c4f95bc..f0e6aa0 100644 --- a/chrome/browser/cocoa/preferences_window_controller.mm +++ b/chrome/browser/cocoa/preferences_window_controller.mm @@ -693,8 +693,7 @@ class ManagedPrefsBannerState : public ManagedPrefsBannerBase { sizeSaver_.reset([[WindowSizeAutosaver alloc] initWithWindow:[self window] prefService:g_browser_process->local_state() - path:prefs::kPreferencesWindowPlacement - state:kSaveWindowRect]); + path:prefs::kPreferencesWindowPlacement]); } // Initialize the banner gradient and stroke color. diff --git a/chrome/browser/cocoa/task_manager_mac.mm b/chrome/browser/cocoa/task_manager_mac.mm index a56195b..07cfafca 100644 --- a/chrome/browser/cocoa/task_manager_mac.mm +++ b/chrome/browser/cocoa/task_manager_mac.mm @@ -110,8 +110,7 @@ class SortHelper { size_saver_.reset([[WindowSizeAutosaver alloc] initWithWindow:[self window] prefService:g_browser_process->local_state() - path:prefs::kTaskManagerWindowPlacement - state:kSaveWindowRect]); + path:prefs::kTaskManagerWindowPlacement]); } [self showWindow:self]; } diff --git a/chrome/browser/cocoa/window_size_autosaver.h b/chrome/browser/cocoa/window_size_autosaver.h index be4dfc1..6556e58 100644 --- a/chrome/browser/cocoa/window_size_autosaver.h +++ b/chrome/browser/cocoa/window_size_autosaver.h @@ -9,15 +9,6 @@ class PrefService; @class NSWindow; -enum WindowSizeAutosaverState { - - // Autosave only the window's bottom-right corner. - kSaveWindowPos, - - // Autosave the whole window rect, i.e. both position and size. - kSaveWindowRect, -}; - // WindowSizeAutosaver is a helper class that makes it easy to let windows // autoremember their position or position and size in a PrefService object. // To use this, add a |scoped_nsobject<WindowSizeAutosaver>| to your window @@ -33,13 +24,11 @@ enum WindowSizeAutosaverState { NSWindow* window_; // weak PrefService* prefService_; // weak const char* path_; - WindowSizeAutosaverState state_; } - (id)initWithWindow:(NSWindow*)window prefService:(PrefService*)prefs - path:(const char*)path - state:(WindowSizeAutosaverState)state; + path:(const char*)path; @end #endif // CHROME_BROWSER_COCOA_WINDOW_SIZE_AUTOSAVER_H_ diff --git a/chrome/browser/cocoa/window_size_autosaver.mm b/chrome/browser/cocoa/window_size_autosaver.mm index 581f6fc..d4f633e 100644 --- a/chrome/browser/cocoa/window_size_autosaver.mm +++ b/chrome/browser/cocoa/window_size_autosaver.mm @@ -25,13 +25,11 @@ const int kMinWindowHeight = 17; - (id)initWithWindow:(NSWindow*)window prefService:(PrefService*)prefs - path:(const char*)path - state:(WindowSizeAutosaverState)state { + path:(const char*)path { if ((self = [super init])) { window_ = window; prefService_ = prefs; path_ = path; - state_ = state; [self restore]; [[NSNotificationCenter defaultCenter] @@ -56,7 +54,7 @@ const int kMinWindowHeight = 17; - (void)save:(NSNotification*)notification { DictionaryValue* windowPrefs = prefService_->GetMutableDictionary(path_); NSRect frame = [window_ frame]; - if (state_ == kSaveWindowRect) { + if ([window_ styleMask] & NSResizableWindowMask) { // Save the origin of the window. windowPrefs->SetInteger("left", NSMinX(frame)); windowPrefs->SetInteger("right", NSMaxX(frame)); @@ -65,19 +63,17 @@ const int kMinWindowHeight = 17; // keep the top < bottom invariant, store top in bottom and vice versa. windowPrefs->SetInteger("top", NSMinY(frame)); windowPrefs->SetInteger("bottom", NSMaxY(frame)); - } else if (state_ == kSaveWindowPos) { + } else { // Save the origin of the window. windowPrefs->SetInteger("x", frame.origin.x); windowPrefs->SetInteger("y", frame.origin.y); - } else { - NOTREACHED(); } } - (void)restore { // Get the positioning information. DictionaryValue* windowPrefs = prefService_->GetMutableDictionary(path_); - if (state_ == kSaveWindowRect) { + if ([window_ styleMask] & NSResizableWindowMask) { int x1, x2, y1, y2; if (!windowPrefs->GetInteger("left", &x1) || !windowPrefs->GetInteger("right", &x2) || @@ -97,7 +93,7 @@ const int kMinWindowHeight = 17; // Make sure the window is on-screen. [window_ cascadeTopLeftFromPoint:NSZeroPoint]; } - } else if (state_ == kSaveWindowPos) { + } else { int x, y; if (!windowPrefs->GetInteger("x", &x) || !windowPrefs->GetInteger("y", &y)) @@ -105,8 +101,6 @@ const int kMinWindowHeight = 17; // Turn the origin (lower-left) into an upper-left window point. NSPoint upperLeft = NSMakePoint(x, y + NSHeight([window_ frame])); [window_ cascadeTopLeftFromPoint:upperLeft]; - } else { - NOTREACHED(); } } diff --git a/chrome/browser/cocoa/window_size_autosaver_unittest.mm b/chrome/browser/cocoa/window_size_autosaver_unittest.mm index 163b5a1..40ec5a8 100644 --- a/chrome/browser/cocoa/window_size_autosaver_unittest.mm +++ b/chrome/browser/cocoa/window_size_autosaver_unittest.mm @@ -21,7 +21,8 @@ class WindowSizeAutosaverTest : public CocoaTest { path_ = "WindowSizeAutosaverTest"; window_ = [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 101, 150, 151) - styleMask:NSTitledWindowMask + styleMask:NSTitledWindowMask| + NSResizableWindowMask backing:NSBackingStoreBuffered defer:NO]; browser_helper_.profile()->GetPrefs()->RegisterDictionaryPref(path_); @@ -45,6 +46,14 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesPos) { // Check to make sure there is no existing pref for window placement. ASSERT_TRUE(pref->GetDictionary(path_) == NULL); + // Replace the window with one that doesn't have resize controls. + [window_ close]; + window_ = + [[NSWindow alloc] initWithContentRect:NSMakeRect(100, 101, 150, 151) + styleMask:NSTitledWindowMask + backing:NSBackingStoreBuffered + defer:NO]; + // Ask the window to save its position, then check that a preference // exists. We're technically passing in a pointer to the user prefs // and not the local state prefs, but a PrefService* is a @@ -56,8 +65,7 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesPos) { scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] initWithWindow:window_ prefService:pref - path:path_ - state:kSaveWindowPos]); + path:path_]); EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); @@ -75,8 +83,7 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesPos) { scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] initWithWindow:window_ prefService:pref - path:path_ - state:kSaveWindowPos]); + path:path_]); EXPECT_EQ(300, NSMinX([window_ frame])); EXPECT_EQ(310, NSMinY([window_ frame])); EXPECT_EQ(160, NSWidth([window_ frame])); @@ -115,8 +122,7 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesRect) { scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] initWithWindow:window_ prefService:pref - path:path_ - state:kSaveWindowRect]); + path:path_]); EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); @@ -134,8 +140,7 @@ TEST_F(WindowSizeAutosaverTest, RestoresAndSavesRect) { scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] initWithWindow:window_ prefService:pref - path:path_ - state:kSaveWindowRect]); + path:path_]); EXPECT_EQ(300, NSMinX([window_ frame])); EXPECT_EQ(310, NSMinY([window_ frame])); EXPECT_EQ(250, NSWidth([window_ frame])); @@ -175,8 +180,7 @@ TEST_F(WindowSizeAutosaverTest, DoesNotRestoreButClearsEmptyRect) { scoped_nsobject<WindowSizeAutosaver> sizeSaver([[WindowSizeAutosaver alloc] initWithWindow:window_ prefService:pref - path:path_ - state:kSaveWindowRect]); + path:path_]); EXPECT_EQ(NSMinX(frame), NSMinX([window_ frame])); EXPECT_EQ(NSMinY(frame), NSMinY([window_ frame])); EXPECT_EQ(NSWidth(frame), NSWidth([window_ frame])); |