| 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 30 matching lines...) Expand all Loading... |
| 41 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 41 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
| 42 browser_->command_updater()->AddCommandObserver(IDC_STAR, this); | 42 browser_->command_updater()->AddCommandObserver(IDC_STAR, this); |
| 43 | 43 |
| 44 back_menu_model_.reset(new BackForwardMenuModelGtk( | 44 back_menu_model_.reset(new BackForwardMenuModelGtk( |
| 45 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); | 45 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); |
| 46 forward_menu_model_.reset(new BackForwardMenuModelGtk( | 46 forward_menu_model_.reset(new BackForwardMenuModelGtk( |
| 47 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); | 47 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); |
| 48 } | 48 } |
| 49 | 49 |
| 50 BrowserToolbarGtk::~BrowserToolbarGtk() { | 50 BrowserToolbarGtk::~BrowserToolbarGtk() { |
| 51 // When we created our MenuGtk objects, we pass them a pointer to our accel |
| 52 // group. Make sure to tear them down before |accel_group_|. |
| 53 page_menu_.reset(); |
| 54 app_menu_.reset(); |
| 55 back_forward_menu_.reset(); |
| 56 g_object_unref(accel_group_); |
| 51 } | 57 } |
| 52 | 58 |
| 53 void BrowserToolbarGtk::Init(Profile* profile, | 59 void BrowserToolbarGtk::Init(Profile* profile, |
| 54 GtkWindow* top_level_window) { | 60 GtkWindow* top_level_window) { |
| 55 // Make sure to tell the location bar the profile before calling its Init. | 61 // Make sure to tell the location bar the profile before calling its Init. |
| 56 SetProfile(profile); | 62 SetProfile(profile); |
| 57 | 63 |
| 58 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 64 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
| 59 | 65 |
| 60 toolbar_ = gtk_hbox_new(FALSE, 0); | 66 toolbar_ = gtk_hbox_new(FALSE, 0); |
| 61 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); | 67 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); |
| 62 // Demand we're always at least kToolbarHeight tall. | 68 // Demand we're always at least kToolbarHeight tall. |
| 63 // -1 for width means "let GTK do its normal sizing". | 69 // -1 for width means "let GTK do its normal sizing". |
| 64 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); | 70 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); |
| 65 | 71 |
| 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 |
| 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 |
| 76 // we still hold on to the original, and thus own a reference to the group. |
| 66 accel_group_ = gtk_accel_group_new(); | 77 accel_group_ = gtk_accel_group_new(); |
| 67 gtk_window_add_accel_group(top_level_window, accel_group_); | 78 gtk_window_add_accel_group(top_level_window, accel_group_); |
| 68 // Drop the initial ref on |accel_group_| so that |top_level_window| will own | |
| 69 // it. | |
| 70 g_object_unref(accel_group_); | |
| 71 | 79 |
| 72 toolbar_tooltips_ = gtk_tooltips_new(); | 80 toolbar_tooltips_ = gtk_tooltips_new(); |
| 73 | 81 |
| 74 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, | 82 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, |
| 75 IDR_BACK_D, | 83 IDR_BACK_D, |
| 76 l10n_util::GetString(IDS_TOOLTIP_BACK))); | 84 l10n_util::GetString(IDS_TOOLTIP_BACK))); |
| 77 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); | 85 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); |
| 78 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, | 86 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, |
| 79 IDR_FORWARD_H, IDR_FORWARD_D, | 87 IDR_FORWARD_H, IDR_FORWARD_D, |
| 80 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); | 88 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 } | 359 } |
| 352 | 360 |
| 353 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { | 361 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { |
| 354 app_menu_->Popup(app_menu_button_->widget(), button_press_event); | 362 app_menu_->Popup(app_menu_button_->widget(), button_press_event); |
| 355 } | 363 } |
| 356 | 364 |
| 357 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { | 365 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { |
| 358 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 366 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
| 359 l10n_util::GetString(IDS_TOOLTIP_HOME)); | 367 l10n_util::GetString(IDS_TOOLTIP_HOME)); |
| 360 } | 368 } |
| OLD | NEW |