- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / gtk / browser_toolbar_gtk.h
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.
4
5 #ifndef CHROME_BROWSER_UI_GTK_BROWSER_TOOLBAR_GTK_H_
6 #define CHROME_BROWSER_UI_GTK_BROWSER_TOOLBAR_GTK_H_
7
8 #include <gtk/gtk.h>
9 #include <string>
10
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"
26
27 class BackForwardButtonGtk;
28 class Browser;
29 class BrowserActionsToolbarGtk;
30 class BrowserWindowGtk;
31 class CustomDrawButton;
32 class GtkThemeService;
33 class LocationBar;
34 class LocationBarViewGtk;
35 class ReloadButtonGtk;
36
37 namespace content {
38 class WebContents;
39 }
40
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 {
47  public:
48   BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window);
49   virtual ~BrowserToolbarGtk();
50
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);
54
55   // Set the various widgets' ViewIDs.
56   void SetViewIDs();
57
58   void Show();
59   void Hide();
60
61   // Getter for the containing widget.
62   GtkWidget* widget() {
63     return event_box_;
64   }
65
66   // Getter for associated browser object.
67   Browser* browser() {
68     return browser_;
69   }
70
71   virtual LocationBar* GetLocationBar() const;
72
73   ReloadButtonGtk* GetReloadButton() { return reload_.get(); }
74
75   GtkWidget* GetAppMenuButton() { return wrench_menu_button_->widget(); }
76
77   BrowserActionsToolbarGtk* GetBrowserActionsToolbar() {
78     return actions_toolbar_.get();
79   }
80
81   LocationBarViewGtk* GetLocationBarView() { return location_bar_.get(); }
82
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);
86
87   void ShowAppMenu();
88
89   // Overridden from CommandObserver:
90   virtual void EnabledStateChangedForCommand(int id, bool enabled) OVERRIDE;
91
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;
96
97   // Overridden from ui::AcceleratorProvider:
98   virtual bool GetAcceleratorForCommandId(
99       int id,
100       ui::Accelerator* accelerator) OVERRIDE;
101
102   // content::NotificationObserver implementation.
103   virtual void Observe(int type,
104                        const content::NotificationSource& source,
105                        const content::NotificationDetails& details) OVERRIDE;
106
107   // Whether the wrench/hotdogs menu is currently visible to the user.
108   bool IsWrenchMenuShowing() const;
109
110   // Message that we should react to a state change.
111   void UpdateWebContents(content::WebContents* contents);
112
113  private:
114   void OnZoomLevelChanged(const content::HostZoomMap::ZoomLevelChange& host);
115
116   // Connect/Disconnect signals for dragging a url onto the home button.
117   void SetUpDragForHomeButton();
118
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();
123
124   // Gtk callback for the "expose-event" signal.
125   // The alignment contains the toolbar.
126   CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnAlignmentExpose,
127                        GdkEventExpose*);
128   CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnLocationHboxExpose,
129                        GdkEventExpose*);
130
131   // Gtk callback for the "clicked" signal.
132   CHROMEGTK_CALLBACK_0(BrowserToolbarGtk, void, OnButtonClick);
133
134   // Gtk callback to intercept mouse clicks to the menu buttons.
135   CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnMenuButtonPressEvent,
136                        GdkEventButton*);
137
138   // Used for drags onto home button.
139   CHROMEGTK_CALLBACK_6(BrowserToolbarGtk, void, OnDragDataReceived,
140                        GdkDragContext*, gint, gint, GtkSelectionData*,
141                        guint, guint);
142
143   // Used to draw the upgrade notification badge.
144   CHROMEGTK_CALLBACK_1(BrowserToolbarGtk, gboolean, OnWrenchMenuButtonExpose,
145                        GdkEventExpose*);
146
147   static void SetSyncMenuLabel(GtkWidget* widget, gpointer userdata);
148
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;
152
153   // Rebuilds the wrench menu.
154   void RebuildWrenchMenu();
155
156   void UpdateShowHomeButton();
157
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
161   // Clearlooks).
162   GtkWidget* event_box_;
163
164   // This widget handles padding around the outside of the toolbar.
165   GtkWidget* alignment_;
166
167   // Gtk widgets. The toolbar is an hbox with each of the other pieces of the
168   // toolbar placed side by side.
169   GtkWidget* toolbar_;
170
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_;
176
177   // Contains all the widgets of the location bar.
178   GtkWidget* location_hbox_;
179
180   // The location bar view.
181   scoped_ptr<LocationBarViewGtk> location_bar_;
182
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_;
189
190   // The image shown in GTK+ mode in the wrench button.
191   GtkWidget* wrench_menu_image_;
192
193   GtkThemeService* theme_service_;
194
195   scoped_ptr<MenuGtk> wrench_menu_;
196
197   scoped_ptr<WrenchMenuModel> wrench_menu_model_;
198
199   // Flag to invalidate the wrench menu model.
200   bool is_wrench_menu_model_valid_;
201
202   Browser* browser_;
203   BrowserWindowGtk* window_;
204
205   // Controls whether or not a home button should be shown on the toolbar.
206   BooleanPrefMember show_home_button_;
207
208   // Preferences controlling the configured home page.
209   StringPrefMember home_page_;
210   BooleanPrefMember home_page_is_new_tab_page_;
211
212   scoped_ptr<content::HostZoomMap::Subscription> zoom_subscription_;
213   content::NotificationRegistrar registrar_;
214
215   // A GtkEntry that isn't part of the hierarchy. We keep this for native
216   // rendering.
217   ui::OwnedWidgetGtk offscreen_entry_;
218
219   // Manages the home button drop signal handler.
220   scoped_ptr<ui::GtkSignalRegistrar> drop_handler_;
221
222   DISALLOW_COPY_AND_ASSIGN(BrowserToolbarGtk);
223 };
224
225 #endif  // CHROME_BROWSER_UI_GTK_BROWSER_TOOLBAR_GTK_H_