Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: chrome/browser/ui/gtk/reload_button_gtk.h

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

Powered by Google App Engine
This is Rietveld 408576698