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.
5 #ifndef CHROME_BROWSER_UI_GTK_BROWSER_TOOLBAR_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_BROWSER_TOOLBAR_GTK_H_
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/prefs/pref_member.h"
14 #include "chrome/browser/command_observer.h"
15 #include "chrome/browser/ui/gtk/custom_button.h"
16 #include "chrome/browser/ui/gtk/menu_gtk.h"
17 #include "chrome/browser/ui/toolbar/wrench_menu_model.h"
18 #include "content/public/browser/host_zoom_map.h"
19 #include "content/public/browser/notification_observer.h"
20 #include "content/public/browser/notification_registrar.h"
21 #include "ui/base/accelerators/accelerator.h"
22 #include "ui/base/gtk/gtk_signal.h"
23 #include "ui/base/gtk/gtk_signal_registrar.h"
24 #include "ui/base/gtk/owned_widget_gtk.h"
25 #include "ui/base/models/simple_menu_model.h"
27 class BackForwardButtonGtk
;
29 class BrowserActionsToolbarGtk
;
30 class BrowserWindowGtk
;
31 class CustomDrawButton
;
32 class GtkThemeService
;
34 class LocationBarViewGtk
;
35 class ReloadButtonGtk
;
41 // View class that displays the GTK version of the toolbar and routes gtk
42 // events back to the Browser.
43 class BrowserToolbarGtk
: public CommandObserver
,
44 public ui::AcceleratorProvider
,
45 public MenuGtk::Delegate
,
46 public content::NotificationObserver
{
48 BrowserToolbarGtk(Browser
* browser
, BrowserWindowGtk
* window
);
49 virtual ~BrowserToolbarGtk();
51 // Create the contents of the toolbar. |top_level_window| is the GtkWindow
52 // to which we attach our accelerators.
53 void Init(GtkWindow
* top_level_window
);
55 // Set the various widgets' ViewIDs.
61 // Getter for the containing widget.
66 // Getter for associated browser object.
71 virtual LocationBar
* GetLocationBar() const;
73 ReloadButtonGtk
* GetReloadButton() { return reload_
.get(); }
75 GtkWidget
* GetAppMenuButton() { return wrench_menu_button_
->widget(); }
77 BrowserActionsToolbarGtk
* GetBrowserActionsToolbar() {
78 return actions_toolbar_
.get();
81 LocationBarViewGtk
* GetLocationBarView() { return location_bar_
.get(); }
83 // We have to show padding on the bottom of the toolbar when the bookmark
84 // is in floating mode. Otherwise the bookmark bar will paint it for us.
85 void UpdateForBookmarkBarVisibility(bool show_bottom_padding
);
89 // Overridden from CommandObserver:
90 virtual void EnabledStateChangedForCommand(int id
, bool enabled
) OVERRIDE
;
92 // Overridden from MenuGtk::Delegate:
93 virtual void StoppedShowing() OVERRIDE
;
94 virtual GtkIconSet
* GetIconSetForId(int idr
) OVERRIDE
;
95 virtual bool AlwaysShowIconForCmd(int command_id
) const OVERRIDE
;
97 // Overridden from ui::AcceleratorProvider:
98 virtual bool GetAcceleratorForCommandId(
100 ui::Accelerator
* accelerator
) OVERRIDE
;
102 // content::NotificationObserver implementation.
103 virtual void Observe(int type
,
104 const content::NotificationSource
& source
,
105 const content::NotificationDetails
& details
) OVERRIDE
;
107 // Whether the wrench/hotdogs menu is currently visible to the user.
108 bool IsWrenchMenuShowing() const;
110 // Message that we should react to a state change.
111 void UpdateWebContents(content::WebContents
* contents
);
114 void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange
& host
);
116 // Connect/Disconnect signals for dragging a url onto the home button.
117 void SetUpDragForHomeButton();
119 // Sets the top corners of the toolbar to rounded, or sets them to normal,
120 // depending on the state of the browser window. Returns false if no action
121 // was taken (the roundedness was already correct), true otherwise.
122 bool UpdateRoundedness();
124 // Gtk callback for the "expose-event" signal.
125 // The alignment contains the toolbar.
126 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk
, gboolean
, OnAlignmentExpose
,
128 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk
, gboolean
, OnLocationHboxExpose
,
131 // Gtk callback for the "clicked" signal.
132 CHROMEGTK_CALLBACK_0(BrowserToolbarGtk
, void, OnButtonClick
);
134 // Gtk callback to intercept mouse clicks to the menu buttons.
135 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk
, gboolean
, OnMenuButtonPressEvent
,
138 // Used for drags onto home button.
139 CHROMEGTK_CALLBACK_6(BrowserToolbarGtk
, void, OnDragDataReceived
,
140 GdkDragContext
*, gint
, gint
, GtkSelectionData
*,
143 // Used to draw the upgrade notification badge.
144 CHROMEGTK_CALLBACK_1(BrowserToolbarGtk
, gboolean
, OnWrenchMenuButtonExpose
,
147 static void SetSyncMenuLabel(GtkWidget
* widget
, gpointer userdata
);
149 // Sometimes we only want to show the location w/o the toolbar buttons (e.g.,
150 // in a popup window).
151 bool ShouldOnlyShowLocation() const;
153 // Rebuilds the wrench menu.
154 void RebuildWrenchMenu();
156 void UpdateShowHomeButton();
158 // An event box that holds |toolbar_|. We need the toolbar to have its own
159 // GdkWindow when we use the GTK drawing because otherwise the color from our
160 // parent GdkWindow will leak through with some theme engines (such as
162 GtkWidget
* event_box_
;
164 // This widget handles padding around the outside of the toolbar.
165 GtkWidget
* alignment_
;
167 // Gtk widgets. The toolbar is an hbox with each of the other pieces of the
168 // toolbar placed side by side.
171 // All widgets to the left or right of the |location_hbox_|. We put the
172 // widgets on either side of location_hbox_ in their own toolbar so we can
173 // set their minimum sizes independently of |location_hbox_| which needs to
174 // grow/shrink in GTK+ mode.
175 GtkWidget
* toolbar_left_
;
177 // Contains all the widgets of the location bar.
178 GtkWidget
* location_hbox_
;
180 // The location bar view.
181 scoped_ptr
<LocationBarViewGtk
> location_bar_
;
183 // All the buttons in the toolbar.
184 scoped_ptr
<BackForwardButtonGtk
> back_
, forward_
;
185 scoped_ptr
<CustomDrawButton
> home_
;
186 scoped_ptr
<ReloadButtonGtk
> reload_
;
187 scoped_ptr
<BrowserActionsToolbarGtk
> actions_toolbar_
;
188 scoped_ptr
<CustomDrawButton
> wrench_menu_button_
;
190 // The image shown in GTK+ mode in the wrench button.
191 GtkWidget
* wrench_menu_image_
;
193 GtkThemeService
* theme_service_
;
195 scoped_ptr
<MenuGtk
> wrench_menu_
;
197 scoped_ptr
<WrenchMenuModel
> wrench_menu_model_
;
199 // Flag to invalidate the wrench menu model.
200 bool is_wrench_menu_model_valid_
;
203 BrowserWindowGtk
* window_
;
205 // Controls whether or not a home button should be shown on the toolbar.
206 BooleanPrefMember show_home_button_
;
208 // Preferences controlling the configured home page.
209 StringPrefMember home_page_
;
210 BooleanPrefMember home_page_is_new_tab_page_
;
212 scoped_ptr
<content::HostZoomMap::Subscription
> zoom_subscription_
;
213 content::NotificationRegistrar registrar_
;
215 // A GtkEntry that isn't part of the hierarchy. We keep this for native
217 ui::OwnedWidgetGtk offscreen_entry_
;
219 // Manages the home button drop signal handler.
220 scoped_ptr
<ui::GtkSignalRegistrar
> drop_handler_
;
222 DISALLOW_COPY_AND_ASSIGN(BrowserToolbarGtk
);
225 #endif // CHROME_BROWSER_UI_GTK_BROWSER_TOOLBAR_GTK_H_