summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-30 02:09:06 +0000
committerevan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-30 02:09:06 +0000
commitd1ae59cb64ba63a447f0010596a9e66d1e449e83 (patch)
tree6e86bc43468746dea226ff64672bbde4cc5eeb4b
parent196bb4b9c21defec2cf6059584563ee9e347dea6 (diff)
downloadchromium_src-d1ae59cb64ba63a447f0010596a9e66d1e449e83.zip
chromium_src-d1ae59cb64ba63a447f0010596a9e66d1e449e83.tar.gz
chromium_src-d1ae59cb64ba63a447f0010596a9e66d1e449e83.tar.bz2
linux: save window positions.
I followed the Windows code rather than the Mac code, and saved whenever the window is moved. Note that we only restore window *size*, not position. We looked at every software we could find and none restored position. BUG=12374 Review URL: http://codereview.chromium.org/115932 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17277 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/browser_window_gtk.cc38
-rw-r--r--chrome/browser/gtk/browser_window_gtk.h3
-rw-r--r--chrome/browser/window_sizer.cc5
3 files changed, 36 insertions, 10 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc
index 243a7a2..feea0fa 100644
--- a/chrome/browser/gtk/browser_window_gtk.cc
+++ b/chrome/browser/gtk/browser_window_gtk.cc
@@ -399,9 +399,7 @@ void BrowserWindowGtk::Close() {
if (!CanClose())
return;
- // TODO(tc): We should store the window position, perhaps using
- // gtk_window_set_role.
- // SaveWindowPosition();
+ SaveWindowPosition();
GtkWidget* window = GTK_WIDGET(window_);
// To help catch bugs in any event handlers that might get fired during the
@@ -694,10 +692,12 @@ void BrowserWindowGtk::DestroyBrowser() {
void BrowserWindowGtk::OnBoundsChanged(const gfx::Rect& bounds) {
bounds_ = bounds;
+ SaveWindowPosition();
}
void BrowserWindowGtk::OnStateChanged(GdkWindowState state) {
state_ = state;
+ SaveWindowPosition();
}
bool BrowserWindowGtk::CanClose() const {
@@ -751,8 +751,11 @@ void BrowserWindowGtk::SetGeometryHints() {
else
gtk_window_unmaximize(window_);
- gfx::Rect rect = browser_->GetSavedWindowBounds();
- SetBounds(rect);
+ gfx::Rect bounds = browser_->GetSavedWindowBounds();
+ // Note that calling SetBounds() here is incorrect, as that sets a forced
+ // position on the window and we intentionally *don't* do that. We tested
+ // many programs and none of them restored their position on Linux.
+ gtk_window_resize(window_, bounds.width(), bounds.height());
}
void BrowserWindowGtk::SetWindowIcon() {
@@ -791,6 +794,31 @@ void BrowserWindowGtk::SetCustomFrame(bool custom_frame) {
}
}
+void BrowserWindowGtk::SaveWindowPosition() {
+ // Browser::SaveWindowPlacement is used for session restore.
+ if (browser_->ShouldSaveWindowPlacement())
+ browser_->SaveWindowPlacement(bounds_, IsMaximized());
+
+ // We also need to save the placement for startup.
+ // This is a web of calls between views and delegates on Windows, but the
+ // crux of the logic follows. See also cocoa/browser_window_controller.mm.
+ if (!g_browser_process->local_state())
+ return;
+
+ std::wstring window_name = browser_->GetWindowPlacementKey();
+ DictionaryValue* window_preferences =
+ g_browser_process->local_state()->GetMutableDictionary(
+ window_name.c_str());
+ // Note that we store left/top for consistency with Windows, but that we
+ // *don't* obey them; we only use them for computing width/height. See
+ // comments in SetGeometryHints().
+ window_preferences->SetInteger(L"left", bounds_.x());
+ window_preferences->SetInteger(L"top", bounds_.y());
+ window_preferences->SetInteger(L"right", bounds_.right());
+ window_preferences->SetInteger(L"bottom", bounds_.bottom());
+ window_preferences->SetBoolean(L"maximized", IsMaximized());
+}
+
// static
gboolean BrowserWindowGtk::OnGtkAccelerator(GtkAccelGroup* accel_group,
GObject* acceleratable,
diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h
index ac51bec..d2c0589 100644
--- a/chrome/browser/gtk/browser_window_gtk.h
+++ b/chrome/browser/gtk/browser_window_gtk.h
@@ -139,6 +139,9 @@ class BrowserWindowGtk : public BrowserWindow,
// Triggers relayout of the content.
void SetCustomFrame(bool custom_frame);
+ // Save the window position in the prefs.
+ void SaveWindowPosition();
+
// Callback for when the "content area" vbox needs to be redrawn.
// The content area includes the toolbar and web page but not the tab strip.
// It has a soft gray border when we have a custom frame.
diff --git a/chrome/browser/window_sizer.cc b/chrome/browser/window_sizer.cc
index e005676..74956d2 100644
--- a/chrome/browser/window_sizer.cc
+++ b/chrome/browser/window_sizer.cc
@@ -11,11 +11,6 @@
#include "chrome/common/pref_names.h"
#include "chrome/common/pref_service.h"
-// TODO(port): Port this to Linux.
-// This requires creating window_sizer_linux.cc, creating a subclass
-// of WindowSizer::MonitorInfoProvider, and providing implementations
-// of GetDefaultMonitorInfoProvider() and GetDefaultPopupOrigin().
-
///////////////////////////////////////////////////////////////////////////////
// An implementation of WindowSizer::StateProvider that gets the last active
// and persistent state from the browser window and the user's profile.