diff options
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); }; |