| 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 | 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 | 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 | 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 | 8 // self deleting, when the bubble is closed, you will be notified via |
| 9 // InfoBubbleGtkDelegate::InfoBubbleClosing(). Then the widgets and the | 9 // InfoBubbleGtkDelegate::InfoBubbleClosing(). Then the widgets and the |
| 10 // underlying object will be destroyed. You can also close and destroy the | 10 // underlying object will be destroyed. You can also close and destroy the |
| 11 // bubble by calling Close(). | 11 // bubble by calling Close(). |
| 12 | 12 |
| 13 #ifndef CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ | 13 #ifndef CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ |
| 14 #define CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ | 14 #define CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ |
| 15 | 15 |
| 16 #include <gtk/gtk.h> | 16 #include <gtk/gtk.h> |
| 17 | 17 |
| 18 #include "base/basictypes.h" | 18 #include "base/basictypes.h" |
| 19 #include "chrome/common/notification_registrar.h" | 19 #include "chrome/common/notification_registrar.h" |
| 20 | 20 |
| 21 class GtkThemeProvider; |
| 21 class InfoBubbleGtk; | 22 class InfoBubbleGtk; |
| 22 namespace gfx { | 23 namespace gfx { |
| 23 class Rect; | 24 class Rect; |
| 24 } | 25 } |
| 25 | 26 |
| 26 class InfoBubbleGtkDelegate { | 27 class InfoBubbleGtkDelegate { |
| 27 public: | 28 public: |
| 28 // Called when the InfoBubble is closing and is about to be deleted. | 29 // Called when the InfoBubble is closing and is about to be deleted. |
| 29 // |closed_by_escape| is true if the close is the result of pressing escape. | 30 // |closed_by_escape| is true if the close is the result of pressing escape. |
| 30 virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble, | 31 virtual void InfoBubbleClosing(InfoBubbleGtk* info_bubble, |
| 31 bool closed_by_escape) = 0; | 32 bool closed_by_escape) = 0; |
| 32 | 33 |
| 33 // NOTE: The Views interface has CloseOnEscape, except I can't find a place | 34 // NOTE: The Views interface has CloseOnEscape, except I can't find a place |
| 34 // where it ever returns false, so we always allow you to close via escape. | 35 // where it ever returns false, so we always allow you to close via escape. |
| 35 }; | 36 }; |
| 36 | 37 |
| 37 class InfoBubbleGtk : public NotificationObserver { | 38 class InfoBubbleGtk : public NotificationObserver { |
| 38 public: | 39 public: |
| 39 // Show an InfoBubble, pointing at the area |rect| (in screen coordinates). | 40 // Show an InfoBubble, pointing at the area |rect| (in screen coordinates). |
| 40 // An infobubble will try to fit on the screen, so it can point to any edge | 41 // An infobubble will try to fit on the screen, so it can point to any edge |
| 41 // of |rect|. The bubble will host the |content| widget. The |delegate| | 42 // of |rect|. The bubble will host the |content| widget. The |delegate| |
| 42 // will be notified when things like closing are happening. | 43 // will be notified when things like closing are happening. |
| 43 static InfoBubbleGtk* Show(GtkWindow* transient_toplevel, | 44 static InfoBubbleGtk* Show(GtkWindow* transient_toplevel, |
| 44 const gfx::Rect& rect, | 45 const gfx::Rect& rect, |
| 45 GtkWidget* content, | 46 GtkWidget* content, |
| 47 GtkThemeProvider* provider, |
| 46 InfoBubbleGtkDelegate* delegate); | 48 InfoBubbleGtkDelegate* delegate); |
| 47 | 49 |
| 48 // Close the bubble if it's open. This will delete the widgets and object, | 50 // Close the bubble if it's open. This will delete the widgets and object, |
| 49 // so you shouldn't hold a InfoBubbleGtk pointer after calling Close(). | 51 // so you shouldn't hold a InfoBubbleGtk pointer after calling Close(). |
| 50 void Close() { Close(false); } | 52 void Close() { Close(false); } |
| 51 | 53 |
| 52 // NotificationObserver implementation. | 54 // NotificationObserver implementation. |
| 53 virtual void Observe(NotificationType type, | 55 virtual void Observe(NotificationType type, |
| 54 const NotificationSource& source, | 56 const NotificationSource& source, |
| 55 const NotificationDetails& details); | 57 const NotificationDetails& details); |
| 56 | 58 |
| 57 // This returns the toplevel GtkWindow that is the transient parent of | 59 // This returns the toplevel GtkWindow that is the transient parent of |
| 58 // |bubble_window|, or NULL if |bubble_window| isn't the GdkWindow | 60 // |bubble_window|, or NULL if |bubble_window| isn't the GdkWindow |
| 59 // for an InfoBubbleGtk. | 61 // for an InfoBubbleGtk. |
| 60 static GtkWindow* GetToplevelForInfoBubble(const GdkWindow* bubble_window); | 62 static GtkWindow* GetToplevelForInfoBubble(const GdkWindow* bubble_window); |
| 61 | 63 |
| 62 private: | 64 private: |
| 63 InfoBubbleGtk(); | 65 explicit InfoBubbleGtk(GtkThemeProvider* provider); |
| 64 virtual ~InfoBubbleGtk(); | 66 virtual ~InfoBubbleGtk(); |
| 65 | 67 |
| 66 // Creates the InfoBubble. | 68 // Creates the InfoBubble. |
| 67 void Init(GtkWindow* transient_toplevel, | 69 void Init(GtkWindow* transient_toplevel, |
| 68 const gfx::Rect& rect, | 70 const gfx::Rect& rect, |
| 69 GtkWidget* content); | 71 GtkWidget* content); |
| 70 | 72 |
| 71 // Sets the delegate. | 73 // Sets the delegate. |
| 72 void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; } | 74 void set_delegate(InfoBubbleGtkDelegate* delegate) { delegate_ = delegate; } |
| 73 | 75 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 } | 116 } |
| 115 gboolean HandleDestroy(); | 117 gboolean HandleDestroy(); |
| 116 | 118 |
| 117 // The caller supplied delegate, can be NULL. | 119 // The caller supplied delegate, can be NULL. |
| 118 InfoBubbleGtkDelegate* delegate_; | 120 InfoBubbleGtkDelegate* delegate_; |
| 119 | 121 |
| 120 // Our GtkWindow popup window, we don't technically "own" the widget, since | 122 // Our GtkWindow popup window, we don't technically "own" the widget, since |
| 121 // it deletes us when it is destroyed. | 123 // it deletes us when it is destroyed. |
| 122 GtkWidget* window_; | 124 GtkWidget* window_; |
| 123 | 125 |
| 126 // Provides colors and stuff. |
| 127 GtkThemeProvider* theme_provider_; |
| 128 |
| 124 // The accel group attached to |window_|, to handle closing with escape. | 129 // The accel group attached to |window_|, to handle closing with escape. |
| 125 GtkAccelGroup* accel_group_; | 130 GtkAccelGroup* accel_group_; |
| 126 | 131 |
| 127 // Where we want our window to be positioned on the screen. | 132 // Where we want our window to be positioned on the screen. |
| 128 int screen_x_; | 133 int screen_x_; |
| 129 int screen_y_; | 134 int screen_y_; |
| 130 | 135 |
| 131 NotificationRegistrar registrar_; | 136 NotificationRegistrar registrar_; |
| 132 | 137 |
| 133 DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk); | 138 DISALLOW_COPY_AND_ASSIGN(InfoBubbleGtk); |
| 134 }; | 139 }; |
| 135 | 140 |
| 136 #endif // CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ | 141 #endif // CHROME_BROWSER_GTK_INFO_BUBBLE_GTK_H_ |
| OLD | NEW |