1 // Copyright (c) 2011 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_RELOAD_BUTTON_GTK_H_ 6 #define CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ 7 #pragma once 8 9 #include <gtk/gtk.h> 10 11 #include "base/basictypes.h" 12 #include "base/timer.h" 13 #include "chrome/browser/ui/gtk/custom_button.h" 14 #include "chrome/browser/ui/gtk/owned_widget_gtk.h" 15 #include "content/common/notification_observer.h" 16 #include "content/common/notification_registrar.h" 17 #include "ui/base/gtk/gtk_signal.h" 18 19 class Browser; 20 class GtkThemeService; 21 class LocationBarViewGtk; 22 class Task; 23 24 class ReloadButtonGtk : public NotificationObserver { 25 public: 26 enum Mode { MODE_RELOAD = 0, MODE_STOP }; 27 28 ReloadButtonGtk(LocationBarViewGtk* location_bar, Browser* browser); 29 ~ReloadButtonGtk(); 30 widget()31 GtkWidget* widget() const { return widget_.get(); } 32 33 // Ask for a specified button state. If |force| is true this will be applied 34 // immediately. 35 void ChangeMode(Mode mode, bool force); 36 37 // Provide NotificationObserver implementation. 38 virtual void Observe(NotificationType type, 39 const NotificationSource& source, 40 const NotificationDetails& /* details */); 41 42 private: 43 friend class ReloadButtonGtkTest; 44 45 CHROMEGTK_CALLBACK_0(ReloadButtonGtk, void, OnClicked); 46 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, gboolean, OnExpose, GdkEventExpose*); 47 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, 48 gboolean, 49 OnLeaveNotify, 50 GdkEventCrossing*); 51 CHROMEGTK_CALLBACK_4(ReloadButtonGtk, 52 gboolean, 53 OnQueryTooltip, 54 gint, 55 gint, 56 gboolean, 57 GtkTooltip*); 58 59 void UpdateThemeButtons(); 60 61 void OnDoubleClickTimer(); 62 void OnStopToReloadTimer(); 63 64 base::OneShotTimer<ReloadButtonGtk> double_click_timer_; 65 base::OneShotTimer<ReloadButtonGtk> stop_to_reload_timer_; 66 67 // These may be NULL when testing. 68 LocationBarViewGtk* const location_bar_; 69 Browser* const browser_; 70 71 // The mode we should be in assuming no timers are running. 72 Mode intended_mode_; 73 74 // The currently-visible mode - this may differ from the intended mode. 75 Mode visible_mode_; 76 77 // Used to listen for theme change notifications. 78 NotificationRegistrar registrar_; 79 80 GtkThemeService* theme_service_; 81 82 CustomDrawButtonBase reload_; 83 CustomDrawButtonBase stop_; 84 CustomDrawHoverController hover_controller_; 85 86 OwnedWidgetGtk widget_; 87 88 // The delay times for the timers. These are members so that tests can modify 89 // them. 90 base::TimeDelta double_click_timer_delay_; 91 base::TimeDelta stop_to_reload_timer_delay_; 92 93 // TESTING ONLY 94 // True if we should pretend the button is hovered. 95 bool testing_mouse_hovered_; 96 // Increments when we would tell the browser to "reload", so 97 // test code can tell whether we did so (as there may be no |browser_|). 98 int testing_reload_count_; 99 100 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButtonGtk); 101 }; 102 103 #endif // CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ 104