| 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 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "app/resource_bundle.h" | 10 #include "app/resource_bundle.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/base_paths_linux.h" | 12 #include "base/base_paths_linux.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
| 15 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 16 #include "chrome/browser/browser_theme_provider.h" |
| 16 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" | 17 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" |
| 17 #include "chrome/browser/gtk/custom_button.h" | 18 #include "chrome/browser/gtk/custom_button.h" |
| 18 #include "chrome/browser/gtk/go_button_gtk.h" | 19 #include "chrome/browser/gtk/go_button_gtk.h" |
| 19 #include "chrome/browser/gtk/gtk_chrome_button.h" | 20 #include "chrome/browser/gtk/gtk_chrome_button.h" |
| 20 #include "chrome/browser/gtk/location_bar_view_gtk.h" | 21 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
| 21 #include "chrome/browser/gtk/nine_box.h" | 22 #include "chrome/browser/gtk/nine_box.h" |
| 22 #include "chrome/browser/gtk/standard_menus.h" | 23 #include "chrome/browser/gtk/standard_menus.h" |
| 23 #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" | 24 #include "chrome/browser/gtk/toolbar_star_toggle_gtk.h" |
| 24 #include "chrome/browser/net/url_fixer_upper.h" | 25 #include "chrome/browser/net/url_fixer_upper.h" |
| 25 #include "chrome/browser/profile.h" | 26 #include "chrome/browser/profile.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 SetProfile(profile); | 92 SetProfile(profile); |
| 92 | 93 |
| 93 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 94 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
| 94 | 95 |
| 95 toolbar_ = gtk_hbox_new(FALSE, 0); | 96 toolbar_ = gtk_hbox_new(FALSE, 0); |
| 96 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); | 97 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); |
| 97 // Demand we're always at least kToolbarHeight tall. | 98 // Demand we're always at least kToolbarHeight tall. |
| 98 // -1 for width means "let GTK do its normal sizing". | 99 // -1 for width means "let GTK do its normal sizing". |
| 99 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); | 100 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); |
| 100 g_signal_connect(G_OBJECT(toolbar_), "expose-event", | 101 g_signal_connect(G_OBJECT(toolbar_), "expose-event", |
| 101 G_CALLBACK(&OnContentAreaExpose), this); | 102 G_CALLBACK(&OnToolbarExpose), this); |
| 102 | 103 |
| 103 // A GtkAccelGroup is not InitiallyUnowned, meaning we get a real reference | 104 // A GtkAccelGroup is not InitiallyUnowned, meaning we get a real reference |
| 104 // count starting at one. We don't want the lifetime to be managed by the | 105 // count starting at one. We don't want the lifetime to be managed by the |
| 105 // top level window, since the lifetime should be tied to the C++ object. | 106 // top level window, since the lifetime should be tied to the C++ object. |
| 106 // When we add the accelerator group, the window will take a reference, but | 107 // When we add the accelerator group, the window will take a reference, but |
| 107 // we still hold on to the original, and thus own a reference to the group. | 108 // we still hold on to the original, and thus own a reference to the group. |
| 108 accel_group_ = gtk_accel_group_new(); | 109 accel_group_ = gtk_accel_group_new(); |
| 109 gtk_window_add_accel_group(top_level_window, accel_group_); | 110 gtk_window_add_accel_group(top_level_window, accel_group_); |
| 110 | 111 |
| 111 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, | 112 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 | 309 |
| 309 gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); | 310 gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); |
| 310 g_signal_connect(G_OBJECT(button), "button-press-event", | 311 g_signal_connect(G_OBJECT(button), "button-press-event", |
| 311 G_CALLBACK(OnMenuButtonPressEvent), this); | 312 G_CALLBACK(OnMenuButtonPressEvent), this); |
| 312 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); | 313 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); |
| 313 | 314 |
| 314 gtk_box_pack_start(GTK_BOX(toolbar_), button, FALSE, FALSE, 0); | 315 gtk_box_pack_start(GTK_BOX(toolbar_), button, FALSE, FALSE, 0); |
| 315 } | 316 } |
| 316 | 317 |
| 317 // static | 318 // static |
| 318 gboolean BrowserToolbarGtk::OnContentAreaExpose(GtkWidget* widget, | 319 gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget, |
| 319 GdkEventExpose* e, | 320 GdkEventExpose* e, |
| 320 BrowserToolbarGtk* toolbar) { | 321 BrowserToolbarGtk* toolbar) { |
| 321 // TODO(deanm): We should improve the tiling performance, or not use NineBox. | |
| 322 // For now at least honor the damage rect to avoid unnecessary painting. | |
| 323 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 322 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 323 // It would be more intuitive to pass |e->area.y| rather than 0, but the |
| 324 // toolbar is supposed to blend in with the active tab, so we have to pass |
| 325 // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the |
| 326 // tab strip. Since the toolbar's GdkWindow has the same origin as the tab |
| 327 // strip's GdkWindow, we can just pass 0. |
| 324 toolbar->background_ninebox_.get()->RenderTopCenterStrip(cr, | 328 toolbar->background_ninebox_.get()->RenderTopCenterStrip(cr, |
| 325 e->area.x, -2, e->area.width); | 329 e->area.x, 0, e->area.width); |
| 326 cairo_destroy(cr); | 330 cairo_destroy(cr); |
| 327 | 331 |
| 328 return FALSE; // Allow subwidgets to paint. | 332 return FALSE; // Allow subwidgets to paint. |
| 329 } | 333 } |
| 330 | 334 |
| 331 // static | 335 // static |
| 332 void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, | 336 void BrowserToolbarGtk::OnButtonClick(GtkWidget* button, |
| 333 BrowserToolbarGtk* toolbar) { | 337 BrowserToolbarGtk* toolbar) { |
| 334 int tag = -1; | 338 int tag = -1; |
| 335 if (button == toolbar->back_->widget()) | 339 if (button == toolbar->back_->widget()) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 440 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { | 444 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { |
| 441 app_menu_->Popup(app_menu_button_.get(), button_press_event); | 445 app_menu_->Popup(app_menu_button_.get(), button_press_event); |
| 442 } | 446 } |
| 443 | 447 |
| 444 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { | 448 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { |
| 445 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 449 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
| 446 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME)); | 450 l10n_util::GetStringUTF8(IDS_TOOLTIP_HOME)); |
| 447 } | 451 } |
| 448 | 452 |
| 449 void BrowserToolbarGtk::InitNineBox() { | 453 void BrowserToolbarGtk::InitNineBox() { |
| 454 // TODO(estade): use |profile_|? |
| 450 background_ninebox_.reset(new NineBox( | 455 background_ninebox_.reset(new NineBox( |
| 451 IDR_CONTENT_TOP_LEFT_CORNER, | 456 browser_->profile()->GetThemeProvider(), |
| 452 IDR_CONTENT_TOP_CENTER, | 457 0, IDR_THEME_TOOLBAR, 0, 0, 0, 0, 0, 0, 0)); |
| 453 IDR_CONTENT_TOP_RIGHT_CORNER, | |
| 454 IDR_CONTENT_LEFT_SIDE, | |
| 455 0, | |
| 456 IDR_CONTENT_RIGHT_SIDE, | |
| 457 IDR_CONTENT_BOTTOM_LEFT_CORNER, | |
| 458 IDR_CONTENT_BOTTOM_CENTER, | |
| 459 IDR_CONTENT_BOTTOM_RIGHT_CORNER)); | |
| 460 } | 458 } |
| OLD | NEW |