diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 21:18:02 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-08 21:18:02 +0000 |
commit | ef9d24ab03688e51cc8bd6193034b5da88749234 (patch) | |
tree | 47d80ed803f9686308915fe8837f757504fe3745 /chrome/browser/tab_contents | |
parent | 7ccc52b7e9a9792bc72e4852de9ac7e3ac189235 (diff) | |
download | chromium_src-ef9d24ab03688e51cc8bd6193034b5da88749234.zip chromium_src-ef9d24ab03688e51cc8bd6193034b5da88749234.tar.gz chromium_src-ef9d24ab03688e51cc8bd6193034b5da88749234.tar.bz2 |
Linux: Store/restore focus in tab contents during tab swithcing.
BUG=8604
Review URL: http://codereview.chromium.org/113166
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15681 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.cc | 26 | ||||
-rw-r--r-- | chrome/browser/tab_contents/tab_contents_view_gtk.h | 8 |
2 files changed, 30 insertions, 4 deletions
diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 98143bc..d132e28 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -67,7 +67,8 @@ TabContentsView* TabContentsView::Create(TabContents* tab_contents) { TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents) : TabContentsView(tab_contents), - vbox_(gtk_vbox_new(FALSE, 0)) { + vbox_(gtk_vbox_new(FALSE, 0)), + stored_focus_widget_(NULL) { registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, Source<TabContents>(tab_contents)); registrar_.Add(this, NotificationType::TAB_CONTENTS_DISCONNECTED, @@ -192,12 +193,29 @@ void TabContentsViewGtk::SetInitialFocus() { } void TabContentsViewGtk::StoreFocus() { - NOTIMPLEMENTED(); + GtkWindow* window = GetTopLevelNativeWindow(); + if (!window) { + NOTREACHED(); + return; + } + + // Disconnect the previous destroy handler (if any). + if (stored_focus_widget_) + g_signal_handler_disconnect(stored_focus_widget_, destroy_handler_id_); + + stored_focus_widget_ = window->focus_widget; + // gtk_widget_destroyed() will set |stored_focus_widget_| to NULL when it is + // invoked during handling of the "destroy" signal. + destroy_handler_id_ = g_signal_connect(stored_focus_widget_, "destroy", + G_CALLBACK(gtk_widget_destroyed), + &stored_focus_widget_); } void TabContentsViewGtk::RestoreFocus() { - // TODO(estade): implement this function. - NOTIMPLEMENTED() << " Need to restore the focus position on this page."; + if (stored_focus_widget_) + gtk_widget_grab_focus(stored_focus_widget_); + else + SetInitialFocus(); } void TabContentsViewGtk::UpdateDragCursor(bool is_drop_target) { diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 4137f67..1dc2c76 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -87,6 +87,14 @@ class TabContentsViewGtk : public TabContentsView, scoped_ptr<SadTabGtk> sad_tab_; + // The widget that was focused the last time we were asked to store focus. + GtkWidget* stored_focus_widget_; + + // The widget for which we've stored focus might be destroyed by the time we + // want to restore focus. Thus we connect to the "destroy" signal on that + // widget. This is the handler ID for the destroy handler. + guint destroy_handler_id_; + DISALLOW_COPY_AND_ASSIGN(TabContentsViewGtk); }; |