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.h | |
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.h')
-rw-r--r-- | chrome/browser/gtk/info_bubble_gtk.h | 60 |
1 files changed, 48 insertions, 12 deletions
diff --git a/chrome/browser/gtk/info_bubble_gtk.h b/chrome/browser/gtk/info_bubble_gtk.h index d5a3b7b..e88946c 100644 --- a/chrome/browser/gtk/info_bubble_gtk.h +++ b/chrome/browser/gtk/info_bubble_gtk.h @@ -2,34 +2,62 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +// This is the GTK implementation of InfoBubbles. InfoBubbles are like +// dialogs, but they point to a given element on the screen. You should call +// InfoBubbleGtk::Show, which will create and display a bubble. The object is +// self deleting, when the bubble is closed, you will be notified via +// InfoBubbleGtkDelegate::InfoBubbleClosing(). Then the widgets and the +// underlying object will be destroyed. You can also close and destroy the +// bubble by calling Close(). + #ifndef CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ #define CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ -#include "base/basictypes.h" - #include <gtk/gtk.h> +#include "base/basictypes.h" + +class InfoBubbleGtk; namespace gfx { class Rect; } +class InfoBubbleGtkDelegate { + public: + // Called when the InfoBubble is closing and is about to be deleted. + // |closed_by_escape| is true if the close is the result of pressing escape. + virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble, + bool closed_by_escape) = 0; + + // NOTE: The Views interface has CloseOnEscape, except I can't find a place + // where it ever returns false, so we always allow you to close via escape. +}; + class InfoBubbleGtk { public: // Show an InfoBubble, pointing at the area |rect| (in screen coordinates). // An infobubble will try to fit on the screen, so it can point to any edge - // of |rect|. The bubble will host |widget| as the content. - static InfoBubbleGtk* Show(const gfx::Rect& rect, GtkWidget* content); + // of |rect|. The bubble will host the |content| widget. The |delegate| + // will be notified when things like closing are happening. + static InfoBubbleGtk* Show(const gfx::Rect& rect, + GtkWidget* content, + InfoBubbleGtkDelegate* delegate); + + // Close the bubble if it's open. This will delete the widgets and object, + // so you shouldn't hold a InfoBubbleGtk pointer after calling Close(). + void Close() { Close(false); } + private: InfoBubbleGtk(); virtual ~InfoBubbleGtk(); - void Close(); - - private: // Creates the InfoBubble. void Init(const gfx::Rect& rect, GtkWidget* content); - // Closes the window notifying the delegate. |closed_by_escape| is true if + // Sets the delegate. + void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; } + + // Closes the window and notifies the delegate. |closed_by_escape| is true if // the close is the result of pressing escape. void Close(bool closed_by_escape); @@ -56,16 +84,24 @@ class InfoBubbleGtk { } gboolean HandleButtonRelease(GdkEventButton* event); - // Our GtkWindow popup window. + static gboolean HandleDestroyThunk(GtkWidget* widget, + gpointer userdata) { + return reinterpret_cast<InfoBubbleGtk*>(userdata)-> + HandleDestroy(); + } + gboolean HandleDestroy(); + + // The caller supplied delegate, can be NULL. + InfoBubbleGtkDelegate* delegate_; + + // Our GtkWindow popup window, we don't technically "own" the widget, since + // it deletes us when it is destroyed. GtkWidget* window_; // Where we want our window to be positioned on the screen. int screen_x_; int screen_y_; - // Have we been closed? - bool closed_; - DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk); }; |