OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_GTK_BROWSER_TOOLBAR_GTK_H_ | 5 #ifndef CHROME_BROWSER_GTK_BROWSER_TOOLBAR_GTK_H_ |
6 #define CHROME_BROWSER_GTK_BROWSER_TOOLBAR_GTK_H_ | 6 #define CHROME_BROWSER_GTK_BROWSER_TOOLBAR_GTK_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "app/active_window_watcher_x.h" | 12 #include "app/active_window_watcher_x.h" |
13 #include "app/gtk_signal.h" | 13 #include "app/gtk_signal.h" |
14 #include "app/gtk_signal_registrar.h" | 14 #include "app/gtk_signal_registrar.h" |
15 #include "app/menus/accelerator.h" | 15 #include "app/menus/accelerator.h" |
16 #include "app/menus/simple_menu_model.h" | 16 #include "app/menus/simple_menu_model.h" |
17 #include "app/throb_animation.h" | |
18 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
19 #include "chrome/browser/command_updater.h" | 18 #include "chrome/browser/command_updater.h" |
20 #include "chrome/browser/gtk/custom_button.h" | 19 #include "chrome/browser/gtk/custom_button.h" |
21 #include "chrome/browser/gtk/menu_gtk.h" | 20 #include "chrome/browser/gtk/menu_gtk.h" |
22 #include "chrome/browser/gtk/owned_widget_gtk.h" | 21 #include "chrome/browser/gtk/owned_widget_gtk.h" |
23 #include "chrome/browser/prefs/pref_member.h" | 22 #include "chrome/browser/prefs/pref_member.h" |
24 #include "chrome/browser/wrench_menu_model.h" | 23 #include "chrome/browser/wrench_menu_model.h" |
25 #include "chrome/common/notification_observer.h" | 24 #include "chrome/common/notification_observer.h" |
26 #include "chrome/common/notification_registrar.h" | 25 #include "chrome/common/notification_registrar.h" |
27 | 26 |
28 class BackForwardButtonGtk; | 27 class BackForwardButtonGtk; |
29 class Browser; | 28 class Browser; |
30 class BrowserActionsToolbarGtk; | 29 class BrowserActionsToolbarGtk; |
31 class BrowserWindowGtk; | 30 class BrowserWindowGtk; |
32 class CustomDrawButton; | 31 class CustomDrawButton; |
33 class GtkThemeProvider; | 32 class GtkThemeProvider; |
34 class LocationBar; | 33 class LocationBar; |
35 class LocationBarViewGtk; | 34 class LocationBarViewGtk; |
36 class Profile; | 35 class Profile; |
37 class ReloadButtonGtk; | 36 class ReloadButtonGtk; |
38 class TabContents; | 37 class TabContents; |
39 class ToolbarModel; | 38 class ToolbarModel; |
40 | 39 |
41 // View class that displays the GTK version of the toolbar and routes gtk | 40 // View class that displays the GTK version of the toolbar and routes gtk |
42 // events back to the Browser. | 41 // events back to the Browser. |
43 class BrowserToolbarGtk : public CommandUpdater::CommandObserver, | 42 class BrowserToolbarGtk : public CommandUpdater::CommandObserver, |
44 public menus::AcceleratorProvider, | 43 public menus::AcceleratorProvider, |
45 public MenuGtk::Delegate, | 44 public MenuGtk::Delegate, |
46 public NotificationObserver, | 45 public NotificationObserver { |
47 public AnimationDelegate, | |
48 public ActiveWindowWatcherX::Observer { | |
49 public: | 46 public: |
50 explicit BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window); | 47 explicit BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window); |
51 virtual ~BrowserToolbarGtk(); | 48 virtual ~BrowserToolbarGtk(); |
52 | 49 |
53 // Create the contents of the toolbar. |top_level_window| is the GtkWindow | 50 // Create the contents of the toolbar. |top_level_window| is the GtkWindow |
54 // to which we attach our accelerators. | 51 // to which we attach our accelerators. |
55 void Init(Profile* profile, GtkWindow* top_level_window); | 52 void Init(Profile* profile, GtkWindow* top_level_window); |
56 | 53 |
57 // Set the various widgets' ViewIDs. | 54 // Set the various widgets' ViewIDs. |
58 void SetViewIDs(); | 55 void SetViewIDs(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 void Observe(NotificationType type, | 101 void Observe(NotificationType type, |
105 const NotificationSource& source, | 102 const NotificationSource& source, |
106 const NotificationDetails& details); | 103 const NotificationDetails& details); |
107 | 104 |
108 Profile* profile() { return profile_; } | 105 Profile* profile() { return profile_; } |
109 void SetProfile(Profile* profile); | 106 void SetProfile(Profile* profile); |
110 | 107 |
111 // Message that we should react to a state change. | 108 // Message that we should react to a state change. |
112 void UpdateTabContents(TabContents* contents, bool should_restore_state); | 109 void UpdateTabContents(TabContents* contents, bool should_restore_state); |
113 | 110 |
114 // AnimationDelegate implementation ------------------------------------------ | |
115 virtual void AnimationEnded(const Animation* animation); | |
116 virtual void AnimationProgressed(const Animation* animation); | |
117 virtual void AnimationCanceled(const Animation* animation); | |
118 | |
119 // ActiveWindowWatcher::Observer implementation ------------------------------ | |
120 virtual void ActiveWindowChanged(GdkWindow* active_window); | |
121 | |
122 private: | 111 private: |
123 // Connect/Disconnect signals for dragging a url onto the home button. | 112 // Connect/Disconnect signals for dragging a url onto the home button. |
124 void SetUpDragForHomeButton(bool enable); | 113 void SetUpDragForHomeButton(bool enable); |
125 | 114 |
126 // Sets the top corners of the toolbar to rounded, or sets them to normal, | 115 // Sets the top corners of the toolbar to rounded, or sets them to normal, |
127 // depending on the state of the browser window. Returns false if no action | 116 // depending on the state of the browser window. Returns false if no action |
128 // was taken (the roundedness was already correct), true otherwise. | 117 // was taken (the roundedness was already correct), true otherwise. |
129 bool UpdateRoundedness(); | 118 bool UpdateRoundedness(); |
130 | 119 |
131 // Calculates whether the upgrade notification dot should be faded at all | |
132 // (as opposed to solid). | |
133 bool UpgradeAnimationIsFaded(); | |
134 | |
135 // Gtk callback for the "expose-event" signal. | 120 // Gtk callback for the "expose-event" signal. |
136 // The alignment contains the toolbar. | 121 // The alignment contains the toolbar. |
137 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnAlignmentExpose, | 122 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnAlignmentExpose, |
138 GdkEventExpose*); | 123 GdkEventExpose*); |
139 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnLocationHboxExpose, | 124 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnLocationHboxExpose, |
140 GdkEventExpose*); | 125 GdkEventExpose*); |
141 | 126 |
142 // Gtk callback for the "clicked" signal. | 127 // Gtk callback for the "clicked" signal. |
143 CHROMEGTK_CALLBACK_0(BrowserToolbarGtk, void, OnButtonClick); | 128 CHROMEGTK_CALLBACK_0(BrowserToolbarGtk, void, OnButtonClick); |
144 | 129 |
145 // Gtk callback to intercept mouse clicks to the menu buttons. | 130 // Gtk callback to intercept mouse clicks to the menu buttons. |
146 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnMenuButtonPressEvent, | 131 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnMenuButtonPressEvent, |
147 GdkEventButton*); | 132 GdkEventButton*); |
148 | 133 |
149 // Used for drags onto home button. | 134 // Used for drags onto home button. |
150 CHROMEGTK_CALLBACK_6(BrowserToolbarGtk, void, OnDragDataReceived, | 135 CHROMEGTK_CALLBACK_6(BrowserToolbarGtk, void, OnDragDataReceived, |
151 GdkDragContext*, gint, gint, GtkSelectionData*, | 136 GdkDragContext*, gint, gint, GtkSelectionData*, |
152 guint, guint); | 137 guint, guint); |
153 | 138 |
154 // Used to stop the upgrade notification animation. | |
155 CHROMEGTK_CALLBACK_0(BrowserToolbarGtk, void, OnWrenchMenuShow); | |
156 | |
157 // Used to draw the upgrade notification badge. | 139 // Used to draw the upgrade notification badge. |
158 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnWrenchMenuButtonExpose, | 140 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnWrenchMenuButtonExpose, |
159 GdkEventExpose*); | 141 GdkEventExpose*); |
160 | 142 |
161 // Updates preference-dependent state. | 143 // Updates preference-dependent state. |
162 void NotifyPrefChanged(const std::string* pref); | 144 void NotifyPrefChanged(const std::string* pref); |
163 | 145 |
164 // Start the upgrade notification animation if we have detected an upgrade | |
165 // and the current toolbar is focused. | |
166 void MaybeShowUpgradeReminder(); | |
167 | |
168 static void SetSyncMenuLabel(GtkWidget* widget, gpointer userdata); | 146 static void SetSyncMenuLabel(GtkWidget* widget, gpointer userdata); |
169 | 147 |
170 // Sometimes we only want to show the location w/o the toolbar buttons (e.g., | 148 // Sometimes we only want to show the location w/o the toolbar buttons (e.g., |
171 // in a popup window). | 149 // in a popup window). |
172 bool ShouldOnlyShowLocation() const; | 150 bool ShouldOnlyShowLocation() const; |
173 | 151 |
174 // An event box that holds |toolbar_|. We need the toolbar to have its own | 152 // An event box that holds |toolbar_|. We need the toolbar to have its own |
175 // GdkWindow when we use the GTK drawing because otherwise the color from our | 153 // GdkWindow when we use the GTK drawing because otherwise the color from our |
176 // parent GdkWindow will leak through with some theme engines (such as | 154 // parent GdkWindow will leak through with some theme engines (such as |
177 // Clearlooks). | 155 // Clearlooks). |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 | 206 |
229 NotificationRegistrar registrar_; | 207 NotificationRegistrar registrar_; |
230 | 208 |
231 // A GtkEntry that isn't part of the hierarchy. We keep this for native | 209 // A GtkEntry that isn't part of the hierarchy. We keep this for native |
232 // rendering. | 210 // rendering. |
233 OwnedWidgetGtk offscreen_entry_; | 211 OwnedWidgetGtk offscreen_entry_; |
234 | 212 |
235 // Manages the home button drop signal handler. | 213 // Manages the home button drop signal handler. |
236 scoped_ptr<GtkSignalRegistrar> drop_handler_; | 214 scoped_ptr<GtkSignalRegistrar> drop_handler_; |
237 | 215 |
238 ThrobAnimation upgrade_reminder_animation_; | |
239 | |
240 // We have already shown and dismissed the upgrade reminder animation. | |
241 bool upgrade_reminder_canceled_; | |
242 | |
243 DISALLOW_COPY_AND_ASSIGN(BrowserToolbarGtk); | 216 DISALLOW_COPY_AND_ASSIGN(BrowserToolbarGtk); |
244 }; | 217 }; |
245 | 218 |
246 #endif // CHROME_BROWSER_GTK_BROWSER_TOOLBAR_GTK_H_ | 219 #endif // CHROME_BROWSER_GTK_BROWSER_TOOLBAR_GTK_H_ |
OLD | NEW |