| 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 "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/base_paths_linux.h" | 10 #include "base/base_paths_linux.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); | 70 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); |
| 71 | 71 |
| 72 // A GtkAccelGroup is not InitiallyUnowned, meaning we get a real reference | 72 // A GtkAccelGroup is not InitiallyUnowned, meaning we get a real reference |
| 73 // count starting at one. We don't want the lifetime to be managed by the | 73 // count starting at one. We don't want the lifetime to be managed by the |
| 74 // top level window, since the lifetime should be tied to the C++ object. | 74 // top level window, since the lifetime should be tied to the C++ object. |
| 75 // When we add the accelerator group, the window will take a reference, but | 75 // When we add the accelerator group, the window will take a reference, but |
| 76 // we still hold on to the original, and thus own a reference to the group. | 76 // we still hold on to the original, and thus own a reference to the group. |
| 77 accel_group_ = gtk_accel_group_new(); | 77 accel_group_ = gtk_accel_group_new(); |
| 78 gtk_window_add_accel_group(top_level_window, accel_group_); | 78 gtk_window_add_accel_group(top_level_window, accel_group_); |
| 79 | 79 |
| 80 toolbar_tooltips_ = gtk_tooltips_new(); | |
| 81 | |
| 82 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, | 80 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, |
| 83 IDR_BACK_D, | 81 IDR_BACK_D, |
| 84 l10n_util::GetString(IDS_TOOLTIP_BACK))); | 82 l10n_util::GetString(IDS_TOOLTIP_BACK))); |
| 85 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); | 83 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); |
| 86 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, | 84 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, |
| 87 IDR_FORWARD_H, IDR_FORWARD_D, | 85 IDR_FORWARD_H, IDR_FORWARD_D, |
| 88 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); | 86 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); |
| 89 AddAcceleratorToButton(forward_, GDK_Right, GDK_MOD1_MASK); | 87 AddAcceleratorToButton(forward_, GDK_Right, GDK_MOD1_MASK); |
| 90 | 88 |
| 91 // TODO(estade): These blank labels are kind of ghetto. Padding should be | 89 // TODO(estade): These blank labels are kind of ghetto. Padding should be |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 bool should_restore_state) { | 200 bool should_restore_state) { |
| 203 location_bar_->Update(should_restore_state ? contents : NULL); | 201 location_bar_->Update(should_restore_state ? contents : NULL); |
| 204 } | 202 } |
| 205 | 203 |
| 206 CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( | 204 CustomDrawButton* BrowserToolbarGtk::BuildToolbarButton( |
| 207 int normal_id, int active_id, int highlight_id, int depressed_id, | 205 int normal_id, int active_id, int highlight_id, int depressed_id, |
| 208 const std::wstring& localized_tooltip) { | 206 const std::wstring& localized_tooltip) { |
| 209 CustomDrawButton* button = new CustomDrawButton(normal_id, active_id, | 207 CustomDrawButton* button = new CustomDrawButton(normal_id, active_id, |
| 210 highlight_id, depressed_id); | 208 highlight_id, depressed_id); |
| 211 | 209 |
| 212 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tooltips_), | 210 gtk_widget_set_tooltip_text(button->widget(), |
| 213 GTK_WIDGET(button->widget()), | 211 WideToUTF8(localized_tooltip).c_str()); |
| 214 WideToUTF8(localized_tooltip).c_str(), | |
| 215 WideToUTF8(localized_tooltip).c_str()); | |
| 216 g_signal_connect(G_OBJECT(button->widget()), "clicked", | 212 g_signal_connect(G_OBJECT(button->widget()), "clicked", |
| 217 G_CALLBACK(OnButtonClick), this); | 213 G_CALLBACK(OnButtonClick), this); |
| 218 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 214 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
| 219 | 215 |
| 220 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); | 216 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); |
| 221 return button; | 217 return button; |
| 222 } | 218 } |
| 223 | 219 |
| 224 CustomContainerButton* BrowserToolbarGtk::BuildToolbarMenuButton( | 220 CustomContainerButton* BrowserToolbarGtk::BuildToolbarMenuButton( |
| 225 int icon_id, | 221 int icon_id, |
| 226 const std::wstring& localized_tooltip) { | 222 const std::wstring& localized_tooltip) { |
| 227 CustomContainerButton* button = new CustomContainerButton; | 223 CustomContainerButton* button = new CustomContainerButton; |
| 228 | 224 |
| 229 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 225 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 230 gtk_container_set_border_width(GTK_CONTAINER(button->widget()), 2); | 226 gtk_container_set_border_width(GTK_CONTAINER(button->widget()), 2); |
| 231 gtk_container_add(GTK_CONTAINER(button->widget()), | 227 gtk_container_add(GTK_CONTAINER(button->widget()), |
| 232 gtk_image_new_from_pixbuf(rb.LoadPixbuf(icon_id))); | 228 gtk_image_new_from_pixbuf(rb.LoadPixbuf(icon_id))); |
| 233 | 229 |
| 234 gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tooltips_), | 230 gtk_widget_set_tooltip_text(button->widget(), |
| 235 GTK_WIDGET(button->widget()), | 231 WideToUTF8(localized_tooltip).c_str()); |
| 236 WideToUTF8(localized_tooltip).c_str(), | |
| 237 WideToUTF8(localized_tooltip).c_str()); | |
| 238 g_signal_connect(G_OBJECT(button->widget()), "button-press-event", | 232 g_signal_connect(G_OBJECT(button->widget()), "button-press-event", |
| 239 G_CALLBACK(OnMenuButtonPressEvent), this); | 233 G_CALLBACK(OnMenuButtonPressEvent), this); |
| 240 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 234 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
| 241 | 235 |
| 242 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); | 236 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); |
| 243 | 237 |
| 244 return button; | 238 return button; |
| 245 } | 239 } |
| 246 | 240 |
| 247 // static | 241 // static |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 | 289 |
| 296 CustomDrawButton* BrowserToolbarGtk::BuildBackForwardButton( | 290 CustomDrawButton* BrowserToolbarGtk::BuildBackForwardButton( |
| 297 int normal_id, | 291 int normal_id, |
| 298 int active_id, | 292 int active_id, |
| 299 int highlight_id, | 293 int highlight_id, |
| 300 int depressed_id, | 294 int depressed_id, |
| 301 const std::wstring& localized_tooltip) { | 295 const std::wstring& localized_tooltip) { |
| 302 CustomDrawButton* button = new CustomDrawButton(normal_id, active_id, | 296 CustomDrawButton* button = new CustomDrawButton(normal_id, active_id, |
| 303 highlight_id, depressed_id); | 297 highlight_id, depressed_id); |
| 304 | 298 |
| 305 // TODO(erg): Mismatch between wstring and string. | 299 gtk_widget_set_tooltip_text(button->widget(), |
| 306 // gtk_tooltips_set_tip(GTK_TOOLTIPS(toolbar_tooltips_), | 300 WideToUTF8(localized_tooltip).c_str()); |
| 307 // GTK_WIDGET(back_), | |
| 308 // localized_tooltip, localized_tooltip); | |
| 309 | 301 |
| 310 g_signal_connect(G_OBJECT(button->widget()), "button-press-event", | 302 g_signal_connect(G_OBJECT(button->widget()), "button-press-event", |
| 311 G_CALLBACK(OnBackForwardPressEvent), this); | 303 G_CALLBACK(OnBackForwardPressEvent), this); |
| 312 g_signal_connect(G_OBJECT(button->widget()), "clicked", | 304 g_signal_connect(G_OBJECT(button->widget()), "clicked", |
| 313 G_CALLBACK(OnButtonClick), this); | 305 G_CALLBACK(OnButtonClick), this); |
| 314 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); | 306 GTK_WIDGET_UNSET_FLAGS(button->widget(), GTK_CAN_FOCUS); |
| 315 | 307 |
| 316 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); | 308 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); |
| 317 // Popup the menu as left-aligned relative to this widget rather than the | 309 // Popup the menu as left-aligned relative to this widget rather than the |
| 318 // default of right aligned. | 310 // default of right aligned. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 } | 351 } |
| 360 | 352 |
| 361 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { | 353 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { |
| 362 app_menu_->Popup(app_menu_button_->widget(), button_press_event); | 354 app_menu_->Popup(app_menu_button_->widget(), button_press_event); |
| 363 } | 355 } |
| 364 | 356 |
| 365 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { | 357 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { |
| 366 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 358 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
| 367 l10n_util::GetString(IDS_TOOLTIP_HOME)); | 359 l10n_util::GetString(IDS_TOOLTIP_HOME)); |
| 368 } | 360 } |
| OLD | NEW |