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 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ 7 8 #include <gtk/gtk.h> 9 10 #include "base/basictypes.h" 11 #include "base/timer/timer.h" 12 #include "chrome/browser/ui/gtk/bubble/bubble_gtk.h" 13 #include "content/public/browser/notification_observer.h" 14 #include "content/public/browser/notification_registrar.h" 15 #include "ui/base/gtk/gtk_signal.h" 16 17 typedef struct _GtkWidget GtkWidget; 18 19 class FullscreenController; 20 21 namespace content { 22 class NotificationDetails; 23 class NotificationSource; 24 class WebContents; 25 } 26 27 class ZoomBubbleGtk : public content::NotificationObserver { 28 public: 29 // Shows the zoom bubble below |anchor_widget| with an arrow pointing at 30 // |anchor_widget|. If |anchor_widget| is a toplevel window, the bubble will 31 // fixed positioned in the top right of corner of the widget with no arrow. 32 static void ShowBubble(content::WebContents* web_contents, 33 bool auto_close); 34 35 // Whether the zoom bubble is currently showing. 36 static bool IsShowing(); 37 38 // Closes the zoom bubble (if there is one). 39 static void CloseBubble(); 40 41 private: 42 ZoomBubbleGtk(GtkWidget* anchor, 43 content::WebContents* web_contents, 44 bool auto_close, 45 FullscreenController* fullscreen_controller); 46 47 virtual ~ZoomBubbleGtk(); 48 49 // content::NotificationObserver: 50 virtual void Observe(int type, 51 const content::NotificationSource& source, 52 const content::NotificationDetails& details) OVERRIDE; 53 54 // Convenience method to start |timer_| if |auto_close_| is true. 55 void StartTimerIfNecessary(); 56 57 // Stops any close timer if |timer_| is currently running. 58 void StopTimerIfNecessary(); 59 60 // Refreshes the bubble by changing the zoom percentage appropriately and 61 // resetting the timer if necessary. 62 void Refresh(); 63 64 // Closes the zoom bubble. 65 void Close(); 66 67 // Notified when the bubble is destroyed so this instance can be deleted. 68 CHROMEGTK_CALLBACK_0(ZoomBubbleGtk, void, OnDestroy); 69 70 // Fired when the reset link is clicked. 71 CHROMEGTK_CALLBACK_0(ZoomBubbleGtk, void, OnSetDefaultLinkClick); 72 73 // Fired when the mouse enters or leaves the widget. 74 CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseEnter, 75 GdkEventCrossing*); 76 CHROMEGTK_CALLBACK_1(ZoomBubbleGtk, gboolean, OnMouseLeave, 77 GdkEventCrossing*); 78 79 // Whether the currently displayed bubble will automatically close. 80 bool auto_close_; 81 82 // Whether the mouse is currently inside the bubble. 83 bool mouse_inside_; 84 85 // Timer used to close the bubble when |auto_close_| is true. 86 base::OneShotTimer<ZoomBubbleGtk> timer_; 87 88 // The WebContents for the page whose zoom has changed. 89 content::WebContents* web_contents_; 90 91 // An event box that wraps the content of the bubble. 92 GtkWidget* event_box_; 93 94 // Label showing zoom percentage. 95 GtkWidget* label_; 96 97 // The BubbleGtk object containing the zoom bubble's content. 98 BubbleGtk* bubble_; 99 100 // Used to register for fullscreen change notifications. 101 content::NotificationRegistrar registrar_; 102 103 DISALLOW_COPY_AND_ASSIGN(ZoomBubbleGtk); 104 }; 105 106 #endif // CHROME_BROWSER_UI_GTK_ZOOM_BUBBLE_GTK_H_ 107