OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #include "chrome/browser/gtk/browser_toolbar_gtk.h" | 5 #include "chrome/browser/gtk/browser_toolbar_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <X11/XF86keysym.h> | 8 #include <X11/XF86keysym.h> |
9 | 9 |
10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/base_paths_linux.h" | 13 #include "base/base_paths_linux.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "chrome/app/chrome_dll_resource.h" | 15 #include "chrome/app/chrome_dll_resource.h" |
16 #include "chrome/browser/browser.h" | 16 #include "chrome/browser/browser.h" |
17 #include "chrome/browser/browser_theme_provider.h" | 17 #include "chrome/browser/browser_theme_provider.h" |
18 #include "chrome/browser/gtk/back_forward_button_gtk.h" | 18 #include "chrome/browser/gtk/back_forward_button_gtk.h" |
19 #include "chrome/browser/gtk/browser_window_gtk.h" | 19 #include "chrome/browser/gtk/browser_window_gtk.h" |
20 #include "chrome/browser/gtk/custom_button.h" | 20 #include "chrome/browser/gtk/custom_button.h" |
21 #include "chrome/browser/gtk/go_button_gtk.h" | 21 #include "chrome/browser/gtk/go_button_gtk.h" |
22 #include "chrome/browser/gtk/gtk_chrome_button.h" | 22 #include "chrome/browser/gtk/gtk_chrome_button.h" |
23 #include "chrome/browser/gtk/gtk_dnd_util.h" | 23 #include "chrome/browser/gtk/gtk_dnd_util.h" |
| 24 #include "chrome/browser/gtk/gtk_theme_provider.h" |
24 #include "chrome/browser/gtk/location_bar_view_gtk.h" | 25 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
25 #include "chrome/browser/gtk/nine_box.h" | 26 #include "chrome/browser/gtk/nine_box.h" |
26 #include "chrome/browser/gtk/standard_menus.h" | 27 #include "chrome/browser/gtk/standard_menus.h" |
27 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | 28 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
28 #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" | 29 #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" |
29 #include "chrome/browser/net/url_fixer_upper.h" | 30 #include "chrome/browser/net/url_fixer_upper.h" |
30 #include "chrome/browser/profile.h" | 31 #include "chrome/browser/profile.h" |
31 #include "chrome/common/gtk_util.h" | 32 #include "chrome/common/gtk_util.h" |
32 #include "chrome/common/notification_details.h" | 33 #include "chrome/common/notification_details.h" |
33 #include "chrome/common/notification_type.h" | 34 #include "chrome/common/notification_type.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 back_.reset(new BackForwardButtonGtk(browser_, false)); | 118 back_.reset(new BackForwardButtonGtk(browser_, false)); |
118 gtk_box_pack_start(GTK_BOX(back_forward_hbox_), back_->widget(), FALSE, | 119 gtk_box_pack_start(GTK_BOX(back_forward_hbox_), back_->widget(), FALSE, |
119 FALSE, 0); | 120 FALSE, 0); |
120 | 121 |
121 forward_.reset(new BackForwardButtonGtk(browser_, true)); | 122 forward_.reset(new BackForwardButtonGtk(browser_, true)); |
122 gtk_box_pack_start(GTK_BOX(back_forward_hbox_), forward_->widget(), FALSE, | 123 gtk_box_pack_start(GTK_BOX(back_forward_hbox_), forward_->widget(), FALSE, |
123 FALSE, 0); | 124 FALSE, 0); |
124 gtk_box_pack_start(GTK_BOX(toolbar_), back_forward_hbox_, FALSE, FALSE, 0); | 125 gtk_box_pack_start(GTK_BOX(toolbar_), back_forward_hbox_, FALSE, FALSE, 0); |
125 | 126 |
126 reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, | 127 reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, |
127 l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD))); | 128 l10n_util::GetStringUTF8(IDS_TOOLTIP_RELOAD), |
| 129 GTK_STOCK_REFRESH)); |
128 | 130 |
129 home_.reset(BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 131 home_.reset(BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
130 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME))); | 132 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME), |
| 133 GTK_STOCK_HOME)); |
131 gtk_util::SetButtonTriggersNavigation(home_->widget()); | 134 gtk_util::SetButtonTriggersNavigation(home_->widget()); |
132 SetUpDragForHomeButton(); | 135 SetUpDragForHomeButton(); |
133 | 136 |
134 // Group the start, omnibox, and go button into an hbox. | 137 // Group the start, omnibox, and go button into an hbox. |
135 GtkWidget* omnibox_hbox_ = gtk_hbox_new(FALSE, 0); | 138 GtkWidget* omnibox_hbox_ = gtk_hbox_new(FALSE, 0); |
136 star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR))); | 139 star_.reset(BuildStarButton(l10n_util::GetStringUTF8(IDS_TOOLTIP_STAR))); |
137 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), star_->widget(), FALSE, FALSE, 0); | 140 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), star_->widget(), FALSE, FALSE, 0); |
138 | 141 |
139 location_bar_->Init(); | 142 location_bar_->Init(); |
140 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), location_bar_->widget(), TRUE, | 143 gtk_box_pack_start(GTK_BOX(omnibox_hbox_), location_bar_->widget(), TRUE, |
(...skipping 14 matching lines...) Expand all Loading... |
155 | 158 |
156 GtkWidget* chrome_menu = BuildToolbarMenuButton(IDR_MENU_CHROME, | 159 GtkWidget* chrome_menu = BuildToolbarMenuButton(IDR_MENU_CHROME, |
157 l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP, | 160 l10n_util::GetStringFUTF8(IDS_APPMENU_TOOLTIP, |
158 WideToUTF16(l10n_util::GetString(IDS_PRODUCT_NAME))), | 161 WideToUTF16(l10n_util::GetString(IDS_PRODUCT_NAME))), |
159 &app_menu_button_); | 162 &app_menu_button_); |
160 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); | 163 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); |
161 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); | 164 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); |
162 | 165 |
163 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); | 166 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); |
164 | 167 |
| 168 // Force all the CustomDrawButtons to load the correct rendering style. |
| 169 UserChangedTheme(); |
| 170 |
165 gtk_widget_show_all(toolbar_); | 171 gtk_widget_show_all(toolbar_); |
166 | 172 |
167 if (show_home_button_.GetValue()) { | 173 if (show_home_button_.GetValue()) { |
168 gtk_widget_show(home_->widget()); | 174 gtk_widget_show(home_->widget()); |
169 } else { | 175 } else { |
170 gtk_widget_hide(home_->widget()); | 176 gtk_widget_hide(home_->widget()); |
171 } | 177 } |
172 } | 178 } |
173 | 179 |
174 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { | 180 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 273 |
268 profile_ = profile; | 274 profile_ = profile; |
269 location_bar_->SetProfile(profile); | 275 location_bar_->SetProfile(profile); |
270 } | 276 } |
271 | 277 |
272 void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, | 278 void BrowserToolbarGtk::UpdateTabContents(TabContents* contents, |
273 bool should_restore_state) { | 279 bool should_restore_state) { |
274 location_bar_->Update(should_restore_state ? contents : NULL); | 280 location_bar_->Update(should_restore_state ? contents : NULL); |
275 } | 281 } |
276 | 282 |
| 283 void BrowserToolbarGtk::UserChangedTheme() { |
| 284 bool use_gtk = GtkThemeProvider::UseSystemThemeGraphics(profile_); |
| 285 back_->SetUseSystemTheme(use_gtk); |
| 286 forward_->SetUseSystemTheme(use_gtk); |
| 287 reload_->SetUseSystemTheme(use_gtk); |
| 288 home_->SetUseSystemTheme(use_gtk); |
| 289 |
| 290 gtk_chrome_button_set_use_gtk_rendering( |
| 291 GTK_CHROME_BUTTON(page_menu_button_.get()), use_gtk); |
| 292 gtk_chrome_button_set_use_gtk_rendering( |
| 293 GTK_CHROME_BUTTON(app_menu_button_.get()), use_gtk); |
| 294 } |
| 295 |
277 gfx::Rect BrowserToolbarGtk::GetPopupBounds() const { | 296 gfx::Rect BrowserToolbarGtk::GetPopupBounds() const { |
278 GtkWidget* star = star_->widget(); | 297 GtkWidget* star = star_->widget(); |
279 GtkWidget* go = go_->widget(); | 298 GtkWidget* go = go_->widget(); |
280 | 299 |
281 // TODO(deanm): The go and star buttons probably share the same window, | 300 // TODO(deanm): The go and star buttons probably share the same window, |
282 // so this could be optimized to only one origin request. | 301 // so this could be optimized to only one origin request. |
283 gint go_x, go_y; | 302 gint go_x, go_y; |
284 gdk_window_get_origin(go->window, &go_x, &go_y); | 303 gdk_window_get_origin(go->window, &go_x, &go_y); |
285 go_x += go->allocation.x + go->allocation.width; // Right edge. | 304 go_x += go->allocation.x + go->allocation.width; // Right edge. |
286 | 305 |
287 gint star_x, star_y; | 306 gint star_x, star_y; |
288 gdk_window_get_origin(star->window, &star_x, &star_y); | 307 gdk_window_get_origin(star->window, &star_x, &star_y); |
289 star_x += star->allocation.x; // Left edge. | 308 star_x += star->allocation.x; // Left edge. |
290 star_y += star->allocation.y + star->allocation.height; // Bottom edge. | 309 star_y += star->allocation.y + star->allocation.height; // Bottom edge. |
291 | 310 |
292 return gfx::Rect(star_x + kPopupLeftRightMargin, star_y + kPopupTopMargin, | 311 return gfx::Rect(star_x + kPopupLeftRightMargin, star_y + kPopupTopMargin, |
293 go_x - star_x - (2 * kPopupLeftRightMargin), 0); | 312 go_x - star_x - (2 * kPopupLeftRightMargin), 0); |
294 } | 313 } |
295 | 314 |
296 // BrowserToolbarGtk, private -------------------------------------------------- | 315 // BrowserToolbarGtk, private -------------------------------------------------- |
297 | 316 |
298 CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( | 317 CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( |
299 int normal_id, int active_id, int highlight_id, int depressed_id, | 318 int normal_id, int active_id, int highlight_id, int depressed_id, |
300 const std::string& localized_tooltip) { | 319 const std::string& localized_tooltip, const char* stock_id) { |
301 CustomDrawButton* button = new CustomDrawButton(normal_id, active_id, | 320 CustomDrawButton* button = new CustomDrawButton(normal_id, active_id, |
302 highlight_id, depressed_id); | 321 highlight_id, depressed_id, stock_id); |
303 | 322 |
304 gtk_widget_set_tooltip_text(button->widget(), | 323 gtk_widget_set_tooltip_text(button->widget(), |
305 localized_tooltip.c_str()); | 324 localized_tooltip.c_str()); |
306 g_signal_connect(button->widget(), "clicked", | 325 g_signal_connect(button->widget(), "clicked", |
307 G_CALLBACK(OnButtonClick), this); | 326 G_CALLBACK(OnButtonClick), this); |
308 g_signal_connect(button->widget(), "button-release-event", | 327 g_signal_connect(button->widget(), "button-release-event", |
309 G_CALLBACK(OnButtonRelease), this); | 328 G_CALLBACK(OnButtonRelease), this); |
310 | 329 |
311 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); | 330 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); |
312 return button; | 331 return button; |
(...skipping 12 matching lines...) Expand all Loading... |
325 } | 344 } |
326 | 345 |
327 GtkWidget* BrowserToolbarGtk::BuildToolbarMenuButton( | 346 GtkWidget* BrowserToolbarGtk::BuildToolbarMenuButton( |
328 int icon_id, | 347 int icon_id, |
329 const std::string& localized_tooltip, | 348 const std::string& localized_tooltip, |
330 OwnedWidgetGtk* owner) { | 349 OwnedWidgetGtk* owner) { |
331 GtkWidget* button = gtk_chrome_button_new(); | 350 GtkWidget* button = gtk_chrome_button_new(); |
332 owner->Own(button); | 351 owner->Own(button); |
333 | 352 |
334 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 353 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
335 gtk_container_set_border_width(GTK_CONTAINER(button), 2); | 354 if (!GtkThemeProvider::UseSystemThemeGraphics(profile_)) |
| 355 gtk_container_set_border_width(GTK_CONTAINER(button), 2); |
336 gtk_container_add(GTK_CONTAINER(button), | 356 gtk_container_add(GTK_CONTAINER(button), |
337 gtk_image_new_from_pixbuf(rb.GetPixbufNamed(icon_id))); | 357 gtk_image_new_from_pixbuf(rb.GetPixbufNamed(icon_id))); |
338 | 358 |
339 gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); | 359 gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); |
340 g_signal_connect(button, "button-press-event", | 360 g_signal_connect(button, "button-press-event", |
341 G_CALLBACK(OnMenuButtonPressEvent), this); | 361 G_CALLBACK(OnMenuButtonPressEvent), this); |
342 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); | 362 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); |
343 | 363 |
344 return button; | 364 return button; |
345 } | 365 } |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 UTF8ToWide(url.spec())); | 460 UTF8ToWide(url.spec())); |
441 } | 461 } |
442 } | 462 } |
443 | 463 |
444 void BrowserToolbarGtk::InitNineBox() { | 464 void BrowserToolbarGtk::InitNineBox() { |
445 // TODO(estade): use |profile_|? | 465 // TODO(estade): use |profile_|? |
446 background_ninebox_.reset(new NineBox( | 466 background_ninebox_.reset(new NineBox( |
447 browser_->profile()->GetThemeProvider(), | 467 browser_->profile()->GetThemeProvider(), |
448 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); | 468 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); |
449 } | 469 } |
OLD | NEW |