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_RELOAD_BUTTON_GTK_H_ | 5 #ifndef CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ |
6 #define CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ | 6 #define CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/timer.h" | 12 #include "base/timer.h" |
13 #include "chrome/browser/ui/gtk/custom_button.h" | 13 #include "chrome/browser/ui/gtk/custom_button.h" |
| 14 #include "chrome/browser/ui/gtk/menu_gtk.h" |
14 #include "content/public/browser/notification_observer.h" | 15 #include "content/public/browser/notification_observer.h" |
15 #include "content/public/browser/notification_registrar.h" | 16 #include "content/public/browser/notification_registrar.h" |
| 17 #include "ui/base/models/simple_menu_model.h" |
16 #include "ui/base/gtk/gtk_signal.h" | 18 #include "ui/base/gtk/gtk_signal.h" |
17 #include "ui/base/gtk/owned_widget_gtk.h" | 19 #include "ui/base/gtk/owned_widget_gtk.h" |
18 | 20 |
19 class Browser; | 21 class Browser; |
20 class GtkThemeService; | 22 class GtkThemeService; |
21 class LocationBarViewGtk; | 23 class LocationBarViewGtk; |
22 | 24 |
23 class ReloadButtonGtk : public content::NotificationObserver { | 25 class ReloadButtonGtk : public content::NotificationObserver, |
| 26 MenuGtk::Delegate, |
| 27 public ui::SimpleMenuModel::Delegate { |
24 public: | 28 public: |
25 enum Mode { MODE_RELOAD = 0, MODE_STOP }; | 29 enum Mode { MODE_RELOAD = 0, MODE_STOP }; |
26 | 30 |
27 ReloadButtonGtk(LocationBarViewGtk* location_bar, Browser* browser); | 31 ReloadButtonGtk(LocationBarViewGtk* location_bar, Browser* browser); |
28 virtual ~ReloadButtonGtk(); | 32 virtual ~ReloadButtonGtk(); |
29 | 33 |
30 GtkWidget* widget() const { return widget_.get(); } | 34 GtkWidget* widget() const { return widget_.get(); } |
31 | 35 |
32 // Ask for a specified button state. If |force| is true this will be applied | 36 // Ask for a specified button state. If |force| is true this will be applied |
33 // immediately. | 37 // immediately. |
34 void ChangeMode(Mode mode, bool force); | 38 void ChangeMode(Mode mode, bool force); |
35 | 39 |
36 // Provide content::NotificationObserver implementation. | 40 // Provide content::NotificationObserver implementation. |
37 virtual void Observe(int type, | 41 virtual void Observe(int type, |
38 const content::NotificationSource& source, | 42 const content::NotificationSource& source, |
39 const content::NotificationDetails& details) OVERRIDE; | 43 const content::NotificationDetails& details) OVERRIDE; |
40 | 44 |
| 45 // Provide MenuGtk::Delegate implementation. |
| 46 virtual void StoppedShowing() OVERRIDE; |
| 47 |
| 48 // Provide SimpleMenuModel::Delegate implementation. |
| 49 virtual bool IsCommandIdChecked(int command_id) const OVERRIDE; |
| 50 virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE; |
| 51 virtual bool IsCommandIdVisible(int command_id) const OVERRIDE; |
| 52 virtual bool GetAcceleratorForCommandId( |
| 53 int command_id, |
| 54 ui::Accelerator* accelerator) OVERRIDE; |
| 55 virtual void ExecuteCommand(int command_id) OVERRIDE; |
| 56 |
41 private: | 57 private: |
42 friend class ReloadButtonGtkTest; | 58 friend class ReloadButtonGtkTest; |
43 | 59 |
44 CHROMEGTK_CALLBACK_0(ReloadButtonGtk, void, OnClicked); | 60 CHROMEGTK_CALLBACK_0(ReloadButtonGtk, void, OnClicked); |
45 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, gboolean, OnExpose, GdkEventExpose*); | 61 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, gboolean, OnExpose, GdkEventExpose*); |
46 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, | 62 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, |
47 gboolean, | 63 gboolean, |
48 OnLeaveNotify, | 64 OnLeaveNotify, |
49 GdkEventCrossing*); | 65 GdkEventCrossing*); |
50 CHROMEGTK_CALLBACK_4(ReloadButtonGtk, | 66 CHROMEGTK_CALLBACK_4(ReloadButtonGtk, |
51 gboolean, | 67 gboolean, |
52 OnQueryTooltip, | 68 OnQueryTooltip, |
53 gint, | 69 gint, |
54 gint, | 70 gint, |
55 gboolean, | 71 gboolean, |
56 GtkTooltip*); | 72 GtkTooltip*); |
57 | 73 |
| 74 // Starts a timer to show the dropdown menu. |
| 75 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, |
| 76 gboolean, |
| 77 OnButtonPress, |
| 78 GdkEventButton*); |
| 79 |
| 80 // If there is a timer to show the dropdown menu, and the mouse has moved |
| 81 // sufficiently down the screen, cancel the timer and immediately show the |
| 82 // menu. |
| 83 CHROMEGTK_CALLBACK_1(ReloadButtonGtk, |
| 84 gboolean, |
| 85 OnMouseMove, |
| 86 GdkEventMotion*); |
| 87 |
58 void UpdateThemeButtons(); | 88 void UpdateThemeButtons(); |
59 | 89 |
60 void OnDoubleClickTimer(); | 90 void OnDoubleClickTimer(); |
61 void OnStopToReloadTimer(); | 91 void OnStopToReloadTimer(); |
62 | 92 |
| 93 // Shows the dropdown menu. |
| 94 void ShowReloadMenu(int button, guint32 event_time); |
| 95 |
| 96 // Do actual reload. command == 0, indicates default dehaviour. |
| 97 void DoReload(int command); |
| 98 |
| 99 // Indicates if reload menu is currently enabled. |
| 100 bool ReloadMenuEnabled(); |
| 101 void ClearCache(); |
| 102 |
63 base::OneShotTimer<ReloadButtonGtk> double_click_timer_; | 103 base::OneShotTimer<ReloadButtonGtk> double_click_timer_; |
64 base::OneShotTimer<ReloadButtonGtk> stop_to_reload_timer_; | 104 base::OneShotTimer<ReloadButtonGtk> stop_to_reload_timer_; |
65 | 105 |
66 // These may be NULL when testing. | 106 // These may be NULL when testing. |
67 LocationBarViewGtk* const location_bar_; | 107 LocationBarViewGtk* const location_bar_; |
68 Browser* const browser_; | 108 Browser* const browser_; |
69 | 109 |
70 // The mode we should be in assuming no timers are running. | 110 // The mode we should be in assuming no timers are running. |
71 Mode intended_mode_; | 111 Mode intended_mode_; |
72 | 112 |
73 // The currently-visible mode - this may differ from the intended mode. | 113 // The currently-visible mode - this may differ from the intended mode. |
74 Mode visible_mode_; | 114 Mode visible_mode_; |
75 | 115 |
76 // Used to listen for theme change notifications. | 116 // Used to listen for theme change notifications. |
77 content::NotificationRegistrar registrar_; | 117 content::NotificationRegistrar registrar_; |
78 | 118 |
79 GtkThemeService* theme_service_; | 119 GtkThemeService* theme_service_; |
80 | 120 |
81 CustomDrawButtonBase reload_; | 121 CustomDrawButtonBase reload_; |
82 CustomDrawButtonBase stop_; | 122 CustomDrawButtonBase stop_; |
83 CustomDrawHoverController hover_controller_; | 123 CustomDrawHoverController hover_controller_; |
84 | 124 |
85 ui::OwnedWidgetGtk widget_; | 125 ui::OwnedWidgetGtk widget_; |
86 | 126 |
87 // The delay times for the timers. These are members so that tests can modify | 127 // The delay times for the timers. These are members so that tests can modify |
88 // them. | 128 // them. |
89 base::TimeDelta double_click_timer_delay_; | 129 base::TimeDelta double_click_timer_delay_; |
90 base::TimeDelta stop_to_reload_timer_delay_; | 130 base::TimeDelta stop_to_reload_timer_delay_; |
91 | 131 |
| 132 // The y position of the last mouse down event. |
| 133 int y_position_of_last_press_; |
| 134 base::WeakPtrFactory<ReloadButtonGtk> weak_factory_; |
| 135 // The menu gets reset every time it is shown. |
| 136 scoped_ptr<MenuGtk> menu_; |
| 137 // The dropdown menu model. |
| 138 scoped_ptr<ui::SimpleMenuModel> menu_model_; |
| 139 // Indicates if menu is currently shown. |
| 140 bool menu_visible_; |
| 141 |
92 // TESTING ONLY | 142 // TESTING ONLY |
93 // True if we should pretend the button is hovered. | 143 // True if we should pretend the button is hovered. |
94 bool testing_mouse_hovered_; | 144 bool testing_mouse_hovered_; |
95 // Increments when we would tell the browser to "reload", so | 145 // Increments when we would tell the browser to "reload", so |
96 // test code can tell whether we did so (as there may be no |browser_|). | 146 // test code can tell whether we did so (as there may be no |browser_|). |
97 int testing_reload_count_; | 147 int testing_reload_count_; |
98 | 148 |
99 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButtonGtk); | 149 DISALLOW_IMPLICIT_CONSTRUCTORS(ReloadButtonGtk); |
100 }; | 150 }; |
101 | 151 |
102 #endif // CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ | 152 #endif // CHROME_BROWSER_UI_GTK_RELOAD_BUTTON_GTK_H_ |
OLD | NEW |