OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
| 5 // This is the GTK implementation of InfoBubbles. InfoBubbles are like |
| 6 // dialogs, but they point to a given element on the screen. You should call |
| 7 // InfoBubbleGtk::Show, which will create and display a bubble. The object is |
| 8 // self deleting, when the bubble is closed, you will be notified via |
| 9 // InfoBubbleGtkDelegate::InfoBubbleClosing(). Then the widgets and the |
| 10 // underlying object will be destroyed. You can also close and destroy the |
| 11 // bubble by calling Close(). |
| 12 |
5 #ifndef CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ | 13 #ifndef CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ |
6 #define CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ | 14 #define CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ |
7 | 15 |
| 16 #include <gtk/gtk.h> |
| 17 |
8 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
9 | 19 |
10 #include <gtk/gtk.h> | 20 class InfoBubbleGtk; |
11 | |
12 namespace gfx { | 21 namespace gfx { |
13 class Rect; | 22 class Rect; |
14 } | 23 } |
15 | 24 |
| 25 class InfoBubbleGtkDelegate { |
| 26 public: |
| 27 // Called when the InfoBubble is closing and is about to be deleted. |
| 28 // |closed_by_escape| is true if the close is the result of pressing escape. |
| 29 virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble, |
| 30 bool closed_by_escape) = 0; |
| 31 |
| 32 // NOTE: The Views interface has CloseOnEscape, except I can't find a place |
| 33 // where it ever returns false, so we always allow you to close via escape. |
| 34 }; |
| 35 |
16 class InfoBubbleGtk { | 36 class InfoBubbleGtk { |
17 public: | 37 public: |
18 // Show an InfoBubble, pointing at the area |rect| (in screen coordinates). | 38 // Show an InfoBubble, pointing at the area |rect| (in screen coordinates). |
19 // An infobubble will try to fit on the screen, so it can point to any edge | 39 // An infobubble will try to fit on the screen, so it can point to any edge |
20 // of |rect|. The bubble will host |widget| as the content. | 40 // of |rect|. The bubble will host the |content| widget. The |delegate| |
21 static InfoBubbleGtk* Show(const gfx::Rect& rect, GtkWidget* content); | 41 // will be notified when things like closing are happening. |
| 42 static InfoBubbleGtk* Show(const gfx::Rect& rect, |
| 43 GtkWidget* content, |
| 44 InfoBubbleGtkDelegate* delegate); |
22 | 45 |
| 46 // Close the bubble if it's open. This will delete the widgets and object, |
| 47 // so you shouldn't hold a InfoBubbleGtk pointer after calling Close(). |
| 48 void Close() { Close(false); } |
| 49 |
| 50 private: |
23 InfoBubbleGtk(); | 51 InfoBubbleGtk(); |
24 virtual ~InfoBubbleGtk(); | 52 virtual ~InfoBubbleGtk(); |
25 | 53 |
26 void Close(); | |
27 | |
28 private: | |
29 // Creates the InfoBubble. | 54 // Creates the InfoBubble. |
30 void Init(const gfx::Rect& rect, GtkWidget* content); | 55 void Init(const gfx::Rect& rect, GtkWidget* content); |
31 | 56 |
32 // Closes the window notifying the delegate. |closed_by_escape| is true if | 57 // Sets the delegate. |
| 58 void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; } |
| 59 |
| 60 // Closes the window and notifies the delegate. |closed_by_escape| is true if |
33 // the close is the result of pressing escape. | 61 // the close is the result of pressing escape. |
34 void Close(bool closed_by_escape); | 62 void Close(bool closed_by_escape); |
35 | 63 |
36 static gboolean HandleConfigureThunk(GtkWidget* widget, | 64 static gboolean HandleConfigureThunk(GtkWidget* widget, |
37 GdkEventConfigure* event, | 65 GdkEventConfigure* event, |
38 gpointer user_data) { | 66 gpointer user_data) { |
39 return reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleConfigure(event); | 67 return reinterpret_cast<InfoBubbleGtk*>(user_data)->HandleConfigure(event); |
40 } | 68 } |
41 gboolean HandleConfigure(GdkEventConfigure* event); | 69 gboolean HandleConfigure(GdkEventConfigure* event); |
42 | 70 |
43 static gboolean HandleButtonPressThunk(GtkWidget* widget, | 71 static gboolean HandleButtonPressThunk(GtkWidget* widget, |
44 GdkEventButton* event, | 72 GdkEventButton* event, |
45 gpointer userdata) { | 73 gpointer userdata) { |
46 return reinterpret_cast<InfoBubbleGtk*>(userdata)-> | 74 return reinterpret_cast<InfoBubbleGtk*>(userdata)-> |
47 HandleButtonPress(event); | 75 HandleButtonPress(event); |
48 } | 76 } |
49 gboolean HandleButtonPress(GdkEventButton* event); | 77 gboolean HandleButtonPress(GdkEventButton* event); |
50 | 78 |
51 static gboolean HandleButtonReleaseThunk(GtkWidget* widget, | 79 static gboolean HandleButtonReleaseThunk(GtkWidget* widget, |
52 GdkEventButton* event, | 80 GdkEventButton* event, |
53 gpointer userdata) { | 81 gpointer userdata) { |
54 return reinterpret_cast<InfoBubbleGtk*>(userdata)-> | 82 return reinterpret_cast<InfoBubbleGtk*>(userdata)-> |
55 HandleButtonRelease(event); | 83 HandleButtonRelease(event); |
56 } | 84 } |
57 gboolean HandleButtonRelease(GdkEventButton* event); | 85 gboolean HandleButtonRelease(GdkEventButton* event); |
58 | 86 |
59 // Our GtkWindow popup window. | 87 static gboolean HandleDestroyThunk(GtkWidget* widget, |
| 88 gpointer userdata) { |
| 89 return reinterpret_cast<InfoBubbleGtk*>(userdata)-> |
| 90 HandleDestroy(); |
| 91 } |
| 92 gboolean HandleDestroy(); |
| 93 |
| 94 // The caller supplied delegate, can be NULL. |
| 95 InfoBubbleGtkDelegate* delegate_; |
| 96 |
| 97 // Our GtkWindow popup window, we don't technically "own" the widget, since |
| 98 // it deletes us when it is destroyed. |
60 GtkWidget* window_; | 99 GtkWidget* window_; |
61 | 100 |
62 // Where we want our window to be positioned on the screen. | 101 // Where we want our window to be positioned on the screen. |
63 int screen_x_; | 102 int screen_x_; |
64 int screen_y_; | 103 int screen_y_; |
65 | 104 |
66 // Have we been closed? | |
67 bool closed_; | |
68 | |
69 DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk); | 105 DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk); |
70 }; | 106 }; |
71 | 107 |
72 #endif // CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ | 108 #endif // CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ |
OLD | NEW |