diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 09:44:44 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-05-06 09:44:44 +0000 |
commit | bd12c913345c751026942f5d4222a6dc6ce6cafa (patch) | |
tree | d99d7f6875ff4e1320a42219955c035f601f8514 /chrome/browser/gtk/info_bubble_gtk.cc | |
parent | 5bf053ef488c81f6ec822de35cab79188c74f9dd (diff) | |
download | chromium_src-bd12c913345c751026942f5d4222a6dc6ce6cafa.zip chromium_src-bd12c913345c751026942f5d4222a6dc6ce6cafa.tar.gz chromium_src-bd12c913345c751026942f5d4222a6dc6ce6cafa.tar.bz2 |
Improvements to Linux InfoBubble and BookmarkBubble.
- Introduce a delegate to notify when the bubble is closed.
- Destroy the objects when the widgets are destroyed.
- Cleanup some style issues, add a bunch more comments.
Review URL: http://codereview.chromium.org/99276
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@15402 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk/info_bubble_gtk.cc')
-rw-r--r-- | chrome/browser/gtk/info_bubble_gtk.cc | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/chrome/browser/gtk/info_bubble_gtk.cc b/chrome/browser/gtk/info_bubble_gtk.cc index d01bd55..cff694b 100644 --- a/chrome/browser/gtk/info_bubble_gtk.cc +++ b/chrome/browser/gtk/info_bubble_gtk.cc @@ -116,17 +116,21 @@ gboolean HandleExpose(GtkWidget* widget, } // namespace // static -InfoBubbleGtk* InfoBubbleGtk::Show(const gfx::Rect& rect, GtkWidget* content) { +InfoBubbleGtk* InfoBubbleGtk::Show(const gfx::Rect& rect, + GtkWidget* content, + InfoBubbleGtkDelegate* delegate) { InfoBubbleGtk* bubble = new InfoBubbleGtk(); bubble->Init(rect, content); + bubble->set_delegate(delegate); return bubble; } InfoBubbleGtk::InfoBubbleGtk() - : window_(NULL), + : delegate_(NULL), + window_(NULL), screen_x_(0), - screen_y_(0), - closed_(false) { + screen_y_(0) { + } InfoBubbleGtk::~InfoBubbleGtk() { @@ -173,18 +177,30 @@ void InfoBubbleGtk::Init(const gfx::Rect& rect, GtkWidget* content) { G_CALLBACK(&HandleConfigureThunk), this); g_signal_connect(window_, "button-press-event", G_CALLBACK(&HandleButtonPressThunk), this); + g_signal_connect(window_, "destroy", + G_CALLBACK(&HandleDestroyThunk), this); gtk_widget_show_all(window_); + // Make sure our window has focus, is brought to the top, etc. gtk_window_present(GTK_WINDOW(window_)); + // We add a GTK (application level) grab. This means we will get all + // keyboard and mouse events for our application, even if they were delivered + // on another window. This allows us to close when the user clicks outside + // of the info bubble. We don't use an X grab since that would steal + // keystrokes from your window manager, prevent you from interacting with + // other applications, etc. gtk_grab_add(window_); } -void InfoBubbleGtk::Close() { - DCHECK(!closed_); +void InfoBubbleGtk::Close(bool closed_by_escape) { + // Notify the delegate that we're about to close. This gives the chance + // to save state / etc from the hosted widget before it's destroyed. + if (delegate_) + delegate_->InfoBubbleClosing(this, closed_by_escape); + DCHECK(window_); gtk_widget_destroy(window_); - window_ = NULL; - closed_ = true; + // |this| has been deleted, see HandleDestroy. } gboolean InfoBubbleGtk::HandleConfigure(GdkEventConfigure* event) { @@ -206,3 +222,11 @@ gboolean InfoBubbleGtk::HandleButtonPress(GdkEventButton* event) { Close(); return TRUE; } + +gboolean InfoBubbleGtk::HandleDestroy() { + // We are self deleting, we have a destroy signal setup to catch when we + // destroy the widget manually, or the window was closed via X. This will + // delete the InfoBubbleGtk object. + delete this; + return FALSE; // Propagate. +} |