OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ |
6 #define CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ | 6 #define CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/timer.h" | 9 #include "base/timer.h" |
10 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" | 10 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" |
11 #include "ui/base/gtk/gtk_signal.h" | 11 #include "ui/base/gtk/gtk_signal.h" |
12 | 12 |
13 class TabContents; | 13 class TabContents; |
14 | 14 |
15 typedef struct _GtkWidget GtkWidget; | 15 typedef struct _GtkWidget GtkWidget; |
16 | 16 |
17 class ZoomBubbleGtk { | 17 class ZoomBubbleGtk { |
18 public: | 18 public: |
19 // Shows the zoom bubble, pointing at |anchor_widget|. | 19 // Shows the zoom bubble, pointing at |anchor_widget|. |
20 static void Show(GtkWidget* anchor, TabContents* tab_contents, | 20 static void Show(GtkWidget* anchor, TabContents* tab_contents, |
21 bool auto_close); | 21 bool auto_close); |
22 | 22 |
23 // Closes the zoom bubble. | 23 // Closes the zoom bubble. |
24 static void Close(); | 24 static void Close(); |
25 | 25 |
| 26 // Whether the zoom bubble is currently showing. |
| 27 static bool IsShowing(); |
| 28 |
26 private: | 29 private: |
27 ZoomBubbleGtk(GtkWidget* anchor, TabContents* tab_contents, bool auto_close); | 30 ZoomBubbleGtk(GtkWidget* anchor, TabContents* tab_contents, bool auto_close); |
28 virtual ~ZoomBubbleGtk(); | 31 virtual ~ZoomBubbleGtk(); |
29 | 32 |
30 // Convenience method to start |timer_| if |auto_close_| is true. | 33 // Convenience method to start |timer_| if |auto_close_| is true. |
31 void StartTimerIfNecessary(); | 34 void StartTimerIfNecessary(); |
32 | 35 |
33 // Stops any close timer if |timer_| is currently running. | 36 // Stops any close timer if |timer_| is currently running. |
34 void StopTimerIfNecessary(); | 37 void StopTimerIfNecessary(); |
35 | 38 |
36 // Refreshes the bubble by changing the zoom percentage appropriately and | 39 // Refreshes the bubble by changing the zoom percentage appropriately and |
37 // resetting the timer if necessary. | 40 // resetting the timer if necessary. |
38 void Refresh(); | 41 void Refresh(); |
39 | 42 |
40 // Closes the zoom bubble. | 43 // Closes the zoom bubble. |
41 void CloseBubble(); | 44 void CloseBubble(); |
42 | 45 |
43 // Notified when the bubble is destroyed so this instance can be deleted. | 46 // Notified when the bubble is destroyed so this instance can be deleted. |
44 CHROMEGTK_CALLBACK_0(ZoomBubbleGtk, void, OnDestroy); | 47 CHROMEGTK_CALLBACK_0(ZoomBubbleGtk, void, OnDestroy); |
45 | 48 |
46 // Fired when the reset link is clicked. | 49 // Fired when the reset link is clicked. |
47 CHROMEGTK_CALLBACK_0(ZoomBubbleGtk, void, OnSetDefaultLinkClick); | 50 CHROMEGTK_CALLBACK_0(ZoomBubbleGtk, void, OnSetDefaultLinkClick); |
48 | 51 |
49 // Fired when the mouse enters or leaves the widget. | 52 // Fired when the mouse enters or leaves the widget. |
50 CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseEnter, | 53 CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseEnter, |
51 GdkEventCrossing*); | 54 GdkEventCrossing*); |
52 CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseLeave, | 55 CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseLeave, |
53 GdkEventCrossing*); | 56 GdkEventCrossing*); |
54 | 57 |
| 58 // Friend the tests so they can check access the static bubble. |
| 59 friend class ZoomBubbleGtkTest; |
| 60 |
| 61 // Pointer to singleton object (NULL if no bubble is open). |
| 62 static ZoomBubbleGtk* g_bubble; |
| 63 |
55 // Whether the currently displayed bubble will automatically close. | 64 // Whether the currently displayed bubble will automatically close. |
56 bool auto_close_; | 65 bool auto_close_; |
57 | 66 |
58 // Whether the mouse is currently inside the bubble. | 67 // Whether the mouse is currently inside the bubble. |
59 bool mouse_inside_; | 68 bool mouse_inside_; |
60 | 69 |
61 // Timer used to close the bubble when |auto_close_| is true. | 70 // Timer used to close the bubble when |auto_close_| is true. |
62 base::OneShotTimer<ZoomBubbleGtk> timer_; | 71 base::OneShotTimer<ZoomBubbleGtk> timer_; |
63 | 72 |
64 // The TabContents for the page whose zoom has changed. | 73 // The TabContents for the page whose zoom has changed. |
65 TabContents* tab_contents_; | 74 TabContents* tab_contents_; |
66 | 75 |
67 // An event box that wraps the content of the bubble. | 76 // An event box that wraps the content of the bubble. |
68 GtkWidget* event_box_; | 77 GtkWidget* event_box_; |
69 | 78 |
70 // Label showing zoom percentage. | 79 // Label showing zoom percentage. |
71 GtkWidget* label_; | 80 GtkWidget* label_; |
72 | 81 |
73 // The BubbleGtk object containing the zoom bubble's content. | 82 // The BubbleGtk object containing the zoom bubble's content. |
74 BubbleGtk* bubble_; | 83 BubbleGtk* bubble_; |
75 | 84 |
76 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleGtk); | 85 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleGtk); |
77 }; | 86 }; |
78 | 87 |
79 #endif // CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ | 88 #endif // CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ |
OLD | NEW |