diff options
author | derat@google.com <derat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 21:52:28 +0000 |
---|---|---|
committer | derat@google.com <derat@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-29 21:52:28 +0000 |
commit | a5eb6fc090ff177d70e886b263f02055aedd04dc (patch) | |
tree | 1167f8ea3616706d118df8c1a5f22f30d2bae3c5 /chrome | |
parent | 7d1e0d0bd5b0a3d56471bbfa7542aff36607463d (diff) | |
download | chromium_src-a5eb6fc090ff177d70e886b263f02055aedd04dc.zip chromium_src-a5eb6fc090ff177d70e886b263f02055aedd04dc.tar.gz chromium_src-a5eb6fc090ff177d70e886b263f02055aedd04dc.tar.bz2 |
Linux: Save and restore bookmark manager and task manager window size.
To test, did the following under Metacity/GNOME:
- remove window_placement prefs from "Local State" file
- start chrome
- open bookmark manager with Ctrl-Shift-B
- resize window to be small and close it
- reopen bookmark manager and confirm that its window is the same
size as when closed
- maximize bookmark manager and close it
- reopen bookmark manager and confirm that it's still small
- minimize bookmark manager before closing it; confirm that the
size remains the same
- restart chrome and confirm that the window size is still saved
- repeat the above tests with the task manager (which is a bit
quicker, since it doesn't allow maximizing or minimizing)
BUG=15488
TEST=see above
Review URL: http://codereview.chromium.org/160330
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@22001 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_prefs.cc | 7 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 213 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.h | 125 | ||||
-rw-r--r-- | chrome/browser/gtk/task_manager_gtk.cc | 48 | ||||
-rw-r--r-- | chrome/browser/gtk/task_manager_gtk.h | 3 |
5 files changed, 308 insertions, 88 deletions
diff --git a/chrome/browser/browser_prefs.cc b/chrome/browser/browser_prefs.cc index 348f250..57175d6 100644 --- a/chrome/browser/browser_prefs.cc +++ b/chrome/browser/browser_prefs.cc @@ -27,10 +27,13 @@ #include "chrome/browser/tab_contents/tab_contents.h" #if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port -#include "chrome/browser/task_manager.h" #include "chrome/browser/views/frame/browser_view.h" #endif +#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX) +#include "chrome/browser/task_manager.h" +#endif + #if defined(OS_WIN) #include "chrome/browser/views/keyword_editor_view.h" #endif @@ -52,6 +55,8 @@ void RegisterAllPrefs(PrefService* user_prefs, PrefService* local_state) { PageInfoModel::RegisterPrefs(local_state); #if defined(TOOLKIT_VIEWS) // TODO(port): whittle this down as we port BrowserView::RegisterBrowserViewPrefs(local_state); +#endif +#if defined(TOOLKIT_VIEWS) || defined(OS_LINUX) TaskManager::RegisterPrefs(local_state); #endif diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index a59e8ab..e1f39d27 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -100,13 +100,6 @@ class ImportObserverImpl : public ImportObserver { DISALLOW_COPY_AND_ASSIGN(ImportObserverImpl); }; -void OnWindowDestroy(GtkWidget* widget, - BookmarkManagerGtk* bookmark_manager) { - DCHECK_EQ(bookmark_manager, manager); - delete manager; - manager = NULL; -} - void SetMenuBarStyle() { static bool style_was_set = false; @@ -329,8 +322,6 @@ BookmarkManagerGtk::BookmarkManagerGtk(Profile* profile) ignore_rightclicks_(false) { InitWidgets(); gtk_util::SetWindowIcon(GTK_WINDOW(window_)); - g_signal_connect(window_, "destroy", - G_CALLBACK(OnWindowDestroy), this); model_->AddObserver(this); if (model_->IsLoaded()) @@ -348,19 +339,25 @@ void BookmarkManagerGtk::InitWidgets() { window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window_), l10n_util::GetStringUTF8(IDS_BOOKMARK_MANAGER_TITLE).c_str()); + g_signal_connect( + window_, "configure-event", G_CALLBACK(OnWindowConfiguredThunk), this); + g_signal_connect( + window_, "destroy", G_CALLBACK(OnWindowDestroyedThunk), this); + g_signal_connect( + window_, "window-state-event", G_CALLBACK(OnWindowStateChangedThunk), + this); // Add this window to its own unique window group to allow for // window-to-parent modality. gtk_window_group_add_window(gtk_window_group_new(), GTK_WINDOW(window_)); g_object_unref(gtk_window_get_group(GTK_WINDOW(window_))); - // Set the default size of the bookmark manager. - int width, height; - gtk_util::GetWidgetSizeFromResources(window_, - IDS_BOOKMARK_MANAGER_DIALOG_WIDTH_CHARS, - IDS_BOOKMARK_MANAGER_DIALOG_HEIGHT_LINES, - &width, &height); - gtk_window_set_default_size(GTK_WINDOW(window_), width, height); + SetInitialWindowSize(); + + gint x = 0, y = 0, width = 1, height = 1; + gtk_window_get_position(GTK_WINDOW(window_), &x, &y); + gtk_window_get_size(GTK_WINDOW(window_), &width, &height); + window_bounds_.SetRect(x, y, width, height); // Build the organize and tools menus. organize_ = gtk_menu_item_new_with_label( @@ -551,6 +548,36 @@ GtkWidget* BookmarkManagerGtk::MakeRightPane() { return scrolled; } +void BookmarkManagerGtk::SetInitialWindowSize() { + // If we previously saved the window's bounds, use them. + if (g_browser_process->local_state()) { + const DictionaryValue* placement_pref = + g_browser_process->local_state()->GetDictionary( + prefs::kBookmarkManagerPlacement); + int top = 0, left = 0, bottom = 1, right = 1; + if (placement_pref && + placement_pref->GetInteger(L"top", &top) && + placement_pref->GetInteger(L"left", &left) && + placement_pref->GetInteger(L"bottom", &bottom) && + placement_pref->GetInteger(L"right", &right)) { + int width = std::max(1, right - left); + int height = std::max(1, bottom - top); + gtk_window_resize(GTK_WINDOW(window_), width, height); + return; + } + } + + // Otherwise, just set a default size (GTK will override this if it's not + // large enough to hold the window's contents). + int width = 1, height = 1; + gtk_util::GetWidgetSizeFromResources( + window_, + IDS_BOOKMARK_MANAGER_DIALOG_WIDTH_CHARS, + IDS_BOOKMARK_MANAGER_DIALOG_HEIGHT_LINES, + &width, &height); + gtk_window_set_default_size(GTK_WINDOW(window_), width, height); +} + void BookmarkManagerGtk::ResetOrganizeMenu(bool left) { organize_is_for_left_ = left; const BookmarkNode* parent = GetFolder(); @@ -882,8 +909,13 @@ void BookmarkManagerGtk::OnRightSelectionChanged(GtkTreeSelection* selection, // statuc void BookmarkManagerGtk::OnLeftTreeViewDragReceived( - GtkWidget* tree_view, GdkDragContext* context, gint x, gint y, - GtkSelectionData* selection_data, guint target_type, guint time, + GtkWidget* tree_view, + GdkDragContext* context, + gint x, + gint y, + GtkSelectionData* selection_data, + guint target_type, + guint time, BookmarkManagerGtk* bm) { gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; @@ -911,8 +943,8 @@ void BookmarkManagerGtk::OnLeftTreeViewDragReceived( GtkTreeIter iter; gtk_tree_model_get_iter(GTK_TREE_MODEL(bm->left_store_), &iter, path); - const BookmarkNode* folder = bm->GetNodeAt( - GTK_TREE_MODEL(bm->left_store_), &iter); + const BookmarkNode* folder = + bm->GetNodeAt(GTK_TREE_MODEL(bm->left_store_), &iter); for (std::vector<const BookmarkNode*>::iterator it = nodes.begin(); it != nodes.end(); ++it) { // Don't try to drop a node into one of its descendants. @@ -925,8 +957,12 @@ void BookmarkManagerGtk::OnLeftTreeViewDragReceived( } // static -gboolean BookmarkManagerGtk::OnLeftTreeViewDragMotion(GtkWidget* tree_view, - GdkDragContext* context, gint x, gint y, guint time, +gboolean BookmarkManagerGtk::OnLeftTreeViewDragMotion( + GtkWidget* tree_view, + GdkDragContext* context, + gint x, + gint y, + guint time, BookmarkManagerGtk* bm) { GtkTreePath* path; GtkTreeViewDropPosition pos; @@ -950,8 +986,11 @@ gboolean BookmarkManagerGtk::OnLeftTreeViewDragMotion(GtkWidget* tree_view, } // static -void BookmarkManagerGtk::OnLeftTreeViewRowCollapsed(GtkTreeView *tree_view, - GtkTreeIter* iter, GtkTreePath* path, BookmarkManagerGtk* bm) { +void BookmarkManagerGtk::OnLeftTreeViewRowCollapsed( + GtkTreeView *tree_view, + GtkTreeIter* iter, + GtkTreePath* path, + BookmarkManagerGtk* bm) { // If a selection still exists, do nothing. if (gtk_tree_selection_get_selected(bm->left_selection(), NULL, NULL)) return; @@ -962,8 +1001,11 @@ void BookmarkManagerGtk::OnLeftTreeViewRowCollapsed(GtkTreeView *tree_view, // static void BookmarkManagerGtk::OnRightTreeViewDragGet( GtkWidget* tree_view, - GdkDragContext* context, GtkSelectionData* selection_data, - guint target_type, guint time, BookmarkManagerGtk* bm) { + GdkDragContext* context, + GtkSelectionData* selection_data, + guint target_type, + guint time, + BookmarkManagerGtk* bm) { // No selection, do nothing. This shouldn't get hit, but if it does an early // return avoids a crash. if (gtk_tree_selection_count_selected_rows(bm->right_selection()) == 0) { @@ -972,13 +1014,20 @@ void BookmarkManagerGtk::OnRightTreeViewDragGet( } bookmark_utils::WriteBookmarksToSelection(bm->GetRightSelection(), - selection_data, target_type, bm->profile_); + selection_data, + target_type, + bm->profile_); } // static void BookmarkManagerGtk::OnRightTreeViewDragReceived( - GtkWidget* tree_view, GdkDragContext* context, gint x, gint y, - GtkSelectionData* selection_data, guint target_type, guint time, + GtkWidget* tree_view, + GdkDragContext* context, + gint x, + gint y, + GtkSelectionData* selection_data, + guint target_type, + guint time, BookmarkManagerGtk* bm) { gboolean dnd_success = FALSE; gboolean delete_selection_data = FALSE; @@ -1047,13 +1096,17 @@ void BookmarkManagerGtk::OnRightTreeViewDragReceived( void BookmarkManagerGtk::OnRightTreeViewDragBegin( GtkWidget* tree_view, GdkDragContext* drag_context, - BookmarkManagerGtk* bookmark_manager) { + BookmarkManagerGtk* bm) { gtk_drag_set_icon_stock(drag_context, GTK_STOCK_DND, 0, 0); } // static gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion( - GtkWidget* tree_view, GdkDragContext* context, gint x, gint y, guint time, + GtkWidget* tree_view, + GdkDragContext* context, + gint x, + gint y, + guint time, BookmarkManagerGtk* bm) { GtkTreePath* path; GtkTreeViewDropPosition pos; @@ -1082,8 +1135,11 @@ gboolean BookmarkManagerGtk::OnRightTreeViewDragMotion( } // static -void BookmarkManagerGtk::OnRightTreeViewRowActivated(GtkTreeView* tree_view, - GtkTreePath* path, GtkTreeViewColumn* column, BookmarkManagerGtk* bm) { +void BookmarkManagerGtk::OnRightTreeViewRowActivated( + GtkTreeView* tree_view, + GtkTreePath* path, + GtkTreeViewColumn* column, + BookmarkManagerGtk* bm) { std::vector<const BookmarkNode*> nodes = bm->GetRightSelection(); if (nodes.empty()) return; @@ -1096,15 +1152,19 @@ void BookmarkManagerGtk::OnRightTreeViewRowActivated(GtkTreeView* tree_view, } // static -void BookmarkManagerGtk::OnLeftTreeViewFocusIn(GtkTreeView* tree_view, - GdkEventFocus* event, BookmarkManagerGtk* bm) { +void BookmarkManagerGtk::OnLeftTreeViewFocusIn( + GtkTreeView* tree_view, + GdkEventFocus* event, + BookmarkManagerGtk* bm) { if (!bm->organize_is_for_left_) bm->ResetOrganizeMenu(true); } // static -void BookmarkManagerGtk::OnRightTreeViewFocusIn(GtkTreeView* tree_view, - GdkEventFocus* event, BookmarkManagerGtk* bm) { +void BookmarkManagerGtk::OnRightTreeViewFocusIn( + GtkTreeView* tree_view, + GdkEventFocus* event, + BookmarkManagerGtk* bm) { if (bm->organize_is_for_left_) bm->ResetOrganizeMenu(false); } @@ -1127,12 +1187,11 @@ void BookmarkManagerGtk::OnRightTreeViewFocusIn(GtkTreeView* tree_view, // propagation. // // static -gboolean BookmarkManagerGtk::OnRightTreeViewButtonPress(GtkWidget* tree_view, - GdkEventButton* event, BookmarkManagerGtk* bm) { +gboolean BookmarkManagerGtk::OnRightTreeViewButtonPress( + GtkWidget* tree_view, GdkEventButton* event, BookmarkManagerGtk* bm) { // Always let cached mousedown events through. - if (bm->sending_delayed_mousedown_) { + if (bm->sending_delayed_mousedown_) return FALSE; - } if (event->button != 1) return FALSE; @@ -1164,14 +1223,17 @@ gboolean BookmarkManagerGtk::OnRightTreeViewButtonPress(GtkWidget* tree_view, } // static -gboolean BookmarkManagerGtk::OnRightTreeViewMotion(GtkWidget* tree_view, - GdkEventMotion* event, BookmarkManagerGtk* bm) { +gboolean BookmarkManagerGtk::OnRightTreeViewMotion( + GtkWidget* tree_view, GdkEventMotion* event, BookmarkManagerGtk* bm) { // This handler is only used for the multi-drag workaround. if (!bm->delaying_mousedown_) return FALSE; if (gtk_drag_check_threshold(tree_view, - bm->mousedown_event_.x, bm->mousedown_event_.y, event->x, event->y)) { + bm->mousedown_event_.x, + bm->mousedown_event_.y, + event->x, + event->y)) { bm->delaying_mousedown_ = false; GtkTargetList* targets = GtkDndUtil::GetTargetListFromCodeMask( GtkDndUtil::CHROME_BOOKMARK_ITEM | @@ -1186,8 +1248,8 @@ gboolean BookmarkManagerGtk::OnRightTreeViewMotion(GtkWidget* tree_view, } // static -gboolean BookmarkManagerGtk::OnTreeViewButtonPress(GtkWidget* tree_view, - GdkEventButton* button, BookmarkManagerGtk* bm) { +gboolean BookmarkManagerGtk::OnTreeViewButtonPress( + GtkWidget* tree_view, GdkEventButton* button, BookmarkManagerGtk* bm) { if (button->button != 3) return FALSE; @@ -1213,8 +1275,8 @@ gboolean BookmarkManagerGtk::OnTreeViewButtonPress(GtkWidget* tree_view, } // static -gboolean BookmarkManagerGtk::OnTreeViewButtonRelease(GtkWidget* tree_view, - GdkEventButton* button, BookmarkManagerGtk* bm) { +gboolean BookmarkManagerGtk::OnTreeViewButtonRelease( + GtkWidget* tree_view, GdkEventButton* button, BookmarkManagerGtk* bm) { if (bm->delaying_mousedown_ && (tree_view == bm->right_tree_view_)) bm->SendDelayedMousedown(); @@ -1222,8 +1284,8 @@ gboolean BookmarkManagerGtk::OnTreeViewButtonRelease(GtkWidget* tree_view, } // static -gboolean BookmarkManagerGtk::OnTreeViewKeyPress(GtkWidget* tree_view, - GdkEventKey* key, BookmarkManagerGtk* bm) { +gboolean BookmarkManagerGtk::OnTreeViewKeyPress( + GtkWidget* tree_view, GdkEventKey* key, BookmarkManagerGtk* bm) { if (key->keyval != GDK_Delete) return FALSE; @@ -1237,8 +1299,8 @@ gboolean BookmarkManagerGtk::OnTreeViewKeyPress(GtkWidget* tree_view, } // static -void BookmarkManagerGtk::OnImportItemActivated(GtkMenuItem* menuitem, - BookmarkManagerGtk* bm) { +void BookmarkManagerGtk::OnImportItemActivated( + GtkMenuItem* menuitem, BookmarkManagerGtk* bm) { SelectFileDialog::FileTypeInfo file_type_info; file_type_info.extensions.resize(1); file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); @@ -1252,8 +1314,8 @@ void BookmarkManagerGtk::OnImportItemActivated(GtkMenuItem* menuitem, } // static -void BookmarkManagerGtk::OnExportItemActivated(GtkMenuItem* menuitem, - BookmarkManagerGtk* bm) { +void BookmarkManagerGtk::OnExportItemActivated( + GtkMenuItem* menuitem, BookmarkManagerGtk* bm) { SelectFileDialog::FileTypeInfo file_type_info; file_type_info.extensions.resize(1); file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("html")); @@ -1271,6 +1333,49 @@ void BookmarkManagerGtk::OnExportItemActivated(GtkMenuItem* menuitem, reinterpret_cast<void*>(IDS_BOOKMARK_MANAGER_EXPORT_MENU)); } +gboolean BookmarkManagerGtk::OnWindowDestroyed(GtkWidget* window) { + DCHECK_EQ(this, manager); + + if (g_browser_process->local_state()) { + DictionaryValue* placement_pref = + g_browser_process->local_state()->GetMutableDictionary( + prefs::kBookmarkManagerPlacement); + // Note that we store left/top for consistency with Windows, but that we + // *don't* restore them. + placement_pref->SetInteger(L"left", window_bounds_.x()); + placement_pref->SetInteger(L"top", window_bounds_.y()); + placement_pref->SetInteger(L"right", window_bounds_.right()); + placement_pref->SetInteger(L"bottom", window_bounds_.bottom()); + placement_pref->SetBoolean(L"maximized", false); + } + + delete manager; + manager = NULL; + return FALSE; +} + +gboolean BookmarkManagerGtk::OnWindowStateChanged(GtkWidget* window, + GdkEventWindowState* event) { + DCHECK_EQ(this, manager); + window_state_ = event->new_window_state; + return FALSE; +} + +gboolean BookmarkManagerGtk::OnWindowConfigured(GtkWidget* window, + GdkEventConfigure* event) { + DCHECK_EQ(this, manager); + + // Don't save the size if we're in an abnormal state. + if (!(window_state_ & (GDK_WINDOW_STATE_MAXIMIZED | + GDK_WINDOW_STATE_WITHDRAWN | + GDK_WINDOW_STATE_FULLSCREEN | + GDK_WINDOW_STATE_ICONIFIED))) { + window_bounds_.SetRect(event->x, event->y, event->width, event->height); + } + + return FALSE; +} + void BookmarkManagerGtk::FileSelected(const FilePath& path, int index, void* params) { int id = reinterpret_cast<intptr_t>(params); diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h index 738a4e5..e09681a 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.h +++ b/chrome/browser/gtk/bookmark_manager_gtk.h @@ -10,6 +10,7 @@ #include "app/table_model_observer.h" #include "base/basictypes.h" +#include "base/gfx/rect.h" #include "base/ref_counted.h" #include "base/task.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" @@ -74,6 +75,10 @@ class BookmarkManagerGtk : public BookmarkModelObserver, void InitWidgets(); GtkWidget* MakeLeftPane(); GtkWidget* MakeRightPane(); + + // Set |window_|'s initial size, using its previous size if that was saved. + void SetInitialWindowSize(); + // If |left|, then make the organize menu refer to that which is selected in // the left pane, otherwise use the right pane selection. void ResetOrganizeMenu(bool left); @@ -149,76 +154,126 @@ class BookmarkManagerGtk : public BookmarkModelObserver, void OnSearchTextChanged(); static void OnSearchTextChangedThunk(GtkWidget* search_entry, - BookmarkManagerGtk* bookmark_manager) { + BookmarkManagerGtk* bookmark_manager) { bookmark_manager->OnSearchTextChanged(); } // TreeView signal handlers. static void OnLeftSelectionChanged(GtkTreeSelection* selection, - BookmarkManagerGtk* bookmark_manager); + BookmarkManagerGtk* bm); static void OnRightSelectionChanged(GtkTreeSelection* selection, - BookmarkManagerGtk* bookmark_manager); + BookmarkManagerGtk* bm); - static void OnLeftTreeViewDragReceived( - GtkWidget* tree_view, GdkDragContext* context, gint x, gint y, - GtkSelectionData* selection_data, guint target_type, guint time, - BookmarkManagerGtk* bookmark_manager); + static void OnLeftTreeViewDragReceived(GtkWidget* tree_view, + GdkDragContext* context, + gint x, + gint y, + GtkSelectionData* selection_data, + guint target_type, + guint time, + BookmarkManagerGtk* bm); static gboolean OnLeftTreeViewDragMotion(GtkWidget* tree_view, - GdkDragContext* context, gint x, gint y, guint time, - BookmarkManagerGtk* bookmark_manager); + GdkDragContext* context, + gint x, + gint y, + guint time, + BookmarkManagerGtk* bm); static void OnLeftTreeViewRowCollapsed(GtkTreeView* tree_view, - GtkTreeIter* iter, GtkTreePath* path, - BookmarkManagerGtk* bookmark_manager); + GtkTreeIter* iter, + GtkTreePath* path, + BookmarkManagerGtk* bm); static void OnRightTreeViewDragGet(GtkWidget* tree_view, - GdkDragContext* context, GtkSelectionData* selection_data, - guint target_type, guint time, BookmarkManagerGtk* bookmark_manager); - - static void OnRightTreeViewDragReceived( - GtkWidget* tree_view, GdkDragContext* context, gint x, gint y, - GtkSelectionData* selection_data, guint target_type, guint time, - BookmarkManagerGtk* bookmark_manager); + GdkDragContext* context, + GtkSelectionData* selection_data, + guint target_type, + guint time, + BookmarkManagerGtk* bm); + + static void OnRightTreeViewDragReceived(GtkWidget* tree_view, + GdkDragContext* context, + gint x, + gint y, + GtkSelectionData* selection_data, + guint target_type, + guint time, + BookmarkManagerGtk* bm); static void OnRightTreeViewDragBegin(GtkWidget* tree_view, - GdkDragContext* drag_context, BookmarkManagerGtk* bookmark_manager); + GdkDragContext* drag_context, + BookmarkManagerGtk* bm); static gboolean OnRightTreeViewDragMotion(GtkWidget* tree_view, - GdkDragContext* context, gint x, gint y, guint time, - BookmarkManagerGtk* bookmark_manager); + GdkDragContext* context, + gint x, + gint y, + guint time, + BookmarkManagerGtk* bm); static void OnRightTreeViewRowActivated(GtkTreeView* tree_view, - GtkTreePath* path, GtkTreeViewColumn* column, - BookmarkManagerGtk* bookmark_manager); + GtkTreePath* path, + GtkTreeViewColumn* column, + BookmarkManagerGtk* bm); static void OnRightTreeViewFocusIn(GtkTreeView* tree_view, - GdkEventFocus* event, BookmarkManagerGtk* bookmark_manager); + GdkEventFocus* event, + BookmarkManagerGtk* bm); static void OnLeftTreeViewFocusIn(GtkTreeView* tree_view, - GdkEventFocus* event, BookmarkManagerGtk* bookmark_manager); + GdkEventFocus* event, + BookmarkManagerGtk* bm); static gboolean OnRightTreeViewButtonPress(GtkWidget* tree_view, - GdkEventButton* event, BookmarkManagerGtk* bookmark_manager); + GdkEventButton* event, + BookmarkManagerGtk* bm); static gboolean OnRightTreeViewMotion(GtkWidget* tree_view, - GdkEventMotion* event, BookmarkManagerGtk* bookmark_manager); + GdkEventMotion* event, + BookmarkManagerGtk* bm); static gboolean OnTreeViewButtonPress(GtkWidget* tree_view, - GdkEventButton* button, BookmarkManagerGtk* bookmark_manager); + GdkEventButton* button, + BookmarkManagerGtk* bm); static gboolean OnTreeViewButtonRelease(GtkWidget* tree_view, - GdkEventButton* button, BookmarkManagerGtk* bookmark_manager); + GdkEventButton* button, + BookmarkManagerGtk* bm); static gboolean OnTreeViewKeyPress(GtkWidget* tree_view, - GdkEventKey* key, BookmarkManagerGtk* bookmark_manager); + GdkEventKey* key, + BookmarkManagerGtk* bm); // Tools menu item callbacks. static void OnImportItemActivated(GtkMenuItem* menuitem, - BookmarkManagerGtk* bookmark_manager); + BookmarkManagerGtk* bm); static void OnExportItemActivated(GtkMenuItem* menuitem, - BookmarkManagerGtk* bookmark_manager); + BookmarkManagerGtk* bm); + + // Window callbacks. + static gboolean OnWindowDestroyedThunk(GtkWidget* window, gpointer self) { + return reinterpret_cast<BookmarkManagerGtk*>(self)-> + OnWindowDestroyed(window); + } + gboolean OnWindowDestroyed(GtkWidget* window); + + static gboolean OnWindowStateChangedThunk(GtkWidget* window, + GdkEventWindowState* event, + gpointer self) { + return reinterpret_cast<BookmarkManagerGtk*>(self)-> + OnWindowStateChanged(window, event); + } + gboolean OnWindowStateChanged(GtkWidget* window, GdkEventWindowState* event); + + static gboolean OnWindowConfiguredThunk(GtkWidget* window, + GdkEventConfigure* event, + gpointer self) { + return reinterpret_cast<BookmarkManagerGtk*>(self)-> + OnWindowConfigured(window, event); + } + gboolean OnWindowConfigured(GtkWidget* window, GdkEventConfigure* event); GtkWidget* window_; GtkWidget* search_entry_; @@ -242,6 +297,12 @@ class BookmarkManagerGtk : public BookmarkModelObserver, GtkTreeViewColumn* path_column_; scoped_ptr<BookmarkTableModel> right_tree_model_; + // |window_|'s current position and size. + gfx::Rect window_bounds_; + + // Flags describing |window_|'s current state. + GdkWindowState window_state_; + // The Organize menu item. GtkWidget* organize_; // The submenu the item pops up. diff --git a/chrome/browser/gtk/task_manager_gtk.cc b/chrome/browser/gtk/task_manager_gtk.cc index 012705e..5e55a2af 100644 --- a/chrome/browser/gtk/task_manager_gtk.cc +++ b/chrome/browser/gtk/task_manager_gtk.cc @@ -11,8 +11,11 @@ #include "app/l10n_util.h" #include "base/gfx/gtk_util.h" #include "base/logging.h" +#include "chrome/browser/browser_process.h" #include "chrome/browser/gtk/menu_gtk.h" #include "chrome/common/gtk_util.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" #include "grit/chromium_strings.h" #include "grit/generated_resources.h" @@ -360,12 +363,37 @@ void TaskManagerGtk::Init() { gtk_container_add(GTK_CONTAINER(scrolled), treeview_); - gtk_window_resize(GTK_WINDOW(dialog_), kDefaultWidth, kDefaultHeight); + SetInitialDialogSize(); gtk_widget_show_all(dialog_); model_->AddObserver(this); } +void TaskManagerGtk::SetInitialDialogSize() { + // If we previously saved the dialog's bounds, use them. + if (g_browser_process->local_state()) { + const DictionaryValue* placement_pref = + g_browser_process->local_state()->GetDictionary( + prefs::kTaskManagerWindowPlacement); + int top = 0, left = 0, bottom = 1, right = 1; + if (placement_pref && + placement_pref->GetInteger(L"top", &top) && + placement_pref->GetInteger(L"left", &left) && + placement_pref->GetInteger(L"bottom", &bottom) && + placement_pref->GetInteger(L"right", &right)) { + gtk_window_resize(GTK_WINDOW(dialog_), + std::max(1, right - left), + std::max(1, bottom - top)); + return; + } + } + + // Otherwise, just set a default size (GTK will override this if it's not + // large enough to hold the window's contents). + gtk_window_set_default_size( + GTK_WINDOW(dialog_), kDefaultWidth, kDefaultHeight); +} + void TaskManagerGtk::ConnectAccelerators() { GtkAccelGroup* accel_group = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(dialog_), accel_group); @@ -510,6 +538,24 @@ void TaskManagerGtk::ActivateFocusedTab() { void TaskManagerGtk::OnResponse(GtkDialog* dialog, gint response_id, TaskManagerGtk* task_manager) { if (response_id == GTK_RESPONSE_DELETE_EVENT) { + // Store the dialog's size so we can restore it the next time it's opened. + if (g_browser_process->local_state()) { + gint x = 0, y = 0, width = 1, height = 1; + gtk_window_get_position(GTK_WINDOW(dialog), &x, &y); + gtk_window_get_size(GTK_WINDOW(dialog), &width, &height); + + DictionaryValue* placement_pref = + g_browser_process->local_state()->GetMutableDictionary( + prefs::kTaskManagerWindowPlacement); + // Note that we store left/top for consistency with Windows, but that we + // *don't* restore them. + placement_pref->SetInteger(L"left", x); + placement_pref->SetInteger(L"top", y); + placement_pref->SetInteger(L"right", x + width); + placement_pref->SetInteger(L"bottom", y + height); + placement_pref->SetBoolean(L"maximized", false); + } + instance_ = NULL; delete task_manager; } else if (response_id == kTaskManagerResponseKill) { diff --git a/chrome/browser/gtk/task_manager_gtk.h b/chrome/browser/gtk/task_manager_gtk.h index 6d4c366..e5ce387 100644 --- a/chrome/browser/gtk/task_manager_gtk.h +++ b/chrome/browser/gtk/task_manager_gtk.h @@ -33,6 +33,9 @@ class TaskManagerGtk : public TaskManagerModelObserver { // Initializes the task manager dialog. void Init(); + // Set |dialog_|'s initial size, using its previous size if that was saved. + void SetInitialDialogSize(); + // Connects the ctrl-w accelerator to the dialog. void ConnectAccelerators(); |