diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-15 21:33:31 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-15 21:33:31 +0000 |
commit | 24316bc454a892383ca1db4c3a9af79993b8a413 (patch) | |
tree | ec2f5d3c08b64ab676908eb3b855522f2f0b29bc /chrome/browser/gtk/focus_store_gtk.h | |
parent | f77348368cac4d8d230156533311d4ae0f2cc3d2 (diff) | |
download | chromium_src-24316bc454a892383ca1db4c3a9af79993b8a413.zip chromium_src-24316bc454a892383ca1db4c3a9af79993b8a413.tar.gz chromium_src-24316bc454a892383ca1db4c3a9af79993b8a413.tar.bz2 |
Linux: Make findbar restore focus to last focused widget on close.
Factor out some common code to FocusStoreGtk so it can be shared by anyone who cares about remembering which widget last had focus. Currently used in FindBarGtk and TabContentsViewGtk.
Review URL: http://codereview.chromium.org/115391
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16189 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/focus_store_gtk.h')
-rw-r--r-- | chrome/browser/gtk/focus_store_gtk.h | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/chrome/browser/gtk/focus_store_gtk.h b/chrome/browser/gtk/focus_store_gtk.h new file mode 100644 index 0000000..7cb7efc --- /dev/null +++ b/chrome/browser/gtk/focus_store_gtk.h @@ -0,0 +1,78 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GTK_FOCUS_STORE_GTK_H_ +#define CHROME_BROWSER_GTK_FOCUS_STORE_GTK_H_ + +#include "base/basictypes.h" + +typedef struct _GtkWidget GtkWidget; + +class FocusStoreGtk { + public: + FocusStoreGtk(); + + virtual ~FocusStoreGtk(); + + GtkWidget* widget() const { return widget_; } + + // Save the widget that is currently focused for |widget|'s toplevel (NOT + // |widget|). Call with NULL to clear |widget_|. + void Store(GtkWidget* widget); + + private: + // Disconnect the previous destroy handler (if any). + void DisconnectDestroyHandler(); + + // The widget which last had focus. + GtkWidget* 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 ID for the destroy handler. + unsigned int destroy_handler_id_; + + DISALLOW_COPY_AND_ASSIGN(FocusStoreGtk); +}; + +#endif // CHROME_BROWSER_GTK_FOCUS_STORE_GTK_H_ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_GTK_FOCUS_STORE_GTK_H_ +#define CHROME_BROWSER_GTK_FOCUS_STORE_GTK_H_ + +#include "base/basictypes.h" + +typedef struct _GtkWidget GtkWidget; + +class FocusStoreGtk { + public: + FocusStoreGtk(); + + virtual ~FocusStoreGtk(); + + GtkWidget* widget() const { return widget_; } + + // Save the widget that is currently focused for |widget|'s toplevel (NOT + // |widget|). Call with NULL to clear |widget_|. + void Store(GtkWidget* widget); + + private: + // Disconnect the previous destroy handler (if any). + void DisconnectDestroyHandler(); + + // The widget which last had focus. + GtkWidget* 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 ID for the destroy handler. + unsigned int destroy_handler_id_; + + DISALLOW_COPY_AND_ASSIGN(FocusStoreGtk); +}; + +#endif // CHROME_BROWSER_GTK_FOCUS_STORE_GTK_H_ |