Chromium Code Reviews| 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" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 13 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
| 14 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" | 14 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" |
| 15 #include "chrome/browser/gtk/custom_button.h" | 15 #include "chrome/browser/gtk/custom_button.h" |
| 16 #include "chrome/browser/gtk/location_bar_view_gtk.h" | 16 #include "chrome/browser/gtk/location_bar_view_gtk.h" |
| 17 #include "chrome/browser/gtk/standard_menus.h" | 17 #include "chrome/browser/gtk/standard_menus.h" |
| 18 #include "chrome/browser/net/url_fixer_upper.h" | 18 #include "chrome/browser/net/url_fixer_upper.h" |
| 19 #include "chrome/common/l10n_util.h" | 19 #include "chrome/common/l10n_util.h" |
| 20 #include "chrome/common/resource_bundle.h" | 20 #include "chrome/common/resource_bundle.h" |
| 21 #include "grit/chromium_strings.h" | 21 #include "grit/chromium_strings.h" |
| 22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 23 #include "grit/theme_resources.h" |
| 24 | 24 |
| 25 const int BrowserToolbarGtk::kToolbarHeight = 38; | 25 const int BrowserToolbarGtk::kToolbarHeight = 38; |
| 26 // For the back/forward dropdown menus, the time in milliseconds between | 26 // For the back/forward dropdown menus, the time in milliseconds between |
| 27 // when the user clicks and the popup menu appears. | 27 // when the user clicks and the popup menu appears. |
| 28 static const int kMenuTimerDelay = 500; | 28 static const int kMenuTimerDelay = 500; |
| 29 | 29 |
| 30 gboolean OnAccelerator(GtkAccelGroup* accel_group, | |
| 31 GObject* acceleratable, | |
| 32 guint keyval, | |
| 33 GdkModifierType modifier, | |
| 34 gpointer userdata) { | |
| 35 BrowserToolbarGtk* self = reinterpret_cast<BrowserToolbarGtk*>(userdata); | |
| 36 switch (keyval) { | |
| 37 case GDK_l: | |
| 38 self->GetLocationBar()->FocusLocation(); | |
| 39 return TRUE; | |
| 40 case GDK_k: | |
| 41 self->GetLocationBar()->FocusSearch(); | |
| 42 return TRUE; | |
| 43 default: | |
| 44 return FALSE; | |
| 45 } | |
| 46 } | |
| 47 | |
| 48 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser) | 30 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser) |
| 49 : toolbar_(NULL), | 31 : toolbar_(NULL), |
| 50 location_bar_(new LocationBarViewGtk(browser->command_updater(), | 32 location_bar_(new LocationBarViewGtk(browser->command_updater(), |
| 51 browser->toolbar_model())), | 33 browser->toolbar_model())), |
| 52 model_(browser->toolbar_model()), | 34 model_(browser->toolbar_model()), |
| 53 browser_(browser), | 35 browser_(browser), |
| 54 profile_(NULL), | 36 profile_(NULL), |
| 55 show_menu_factory_(this) { | 37 show_menu_factory_(this) { |
| 56 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 38 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
| 57 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 39 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
| 58 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); | 40 browser_->command_updater()->AddCommandObserver(IDC_RELOAD, this); |
| 59 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 41 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
| 60 browser_->command_updater()->AddCommandObserver(IDC_STAR, this); | 42 browser_->command_updater()->AddCommandObserver(IDC_STAR, this); |
| 61 | 43 |
| 62 back_menu_model_.reset(new BackForwardMenuModelGtk( | 44 back_menu_model_.reset(new BackForwardMenuModelGtk( |
| 63 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); | 45 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); |
| 64 forward_menu_model_.reset(new BackForwardMenuModelGtk( | 46 forward_menu_model_.reset(new BackForwardMenuModelGtk( |
| 65 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); | 47 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); |
| 66 } | 48 } |
| 67 | 49 |
| 68 BrowserToolbarGtk::~BrowserToolbarGtk() { | 50 BrowserToolbarGtk::~BrowserToolbarGtk() { |
| 69 } | 51 } |
| 70 | 52 |
| 71 void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) { | 53 void BrowserToolbarGtk::Init(Profile* profile, |
| 54 GtkWindow* top_level_window) { | |
| 72 // Make sure to tell the location bar the profile before calling its Init. | 55 // Make sure to tell the location bar the profile before calling its Init. |
| 73 SetProfile(profile); | 56 SetProfile(profile); |
| 74 | 57 |
| 75 accel_group_ = accel_group; | |
| 76 | |
| 77 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 58 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
| 78 | 59 |
| 79 toolbar_ = gtk_hbox_new(FALSE, 0); | 60 toolbar_ = gtk_hbox_new(FALSE, 0); |
| 80 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); | 61 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); |
| 81 // Demand we're always at least kToolbarHeight tall. | 62 // Demand we're always at least kToolbarHeight tall. |
| 82 // -1 for width means "let GTK do its normal sizing". | 63 // -1 for width means "let GTK do its normal sizing". |
| 83 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); | 64 gtk_widget_set_size_request(toolbar_, -1, kToolbarHeight); |
| 84 | 65 |
| 66 accel_group_ = gtk_accel_group_new(); | |
| 67 gtk_window_add_accel_group(top_level_window, accel_group_); | |
| 68 // The window now owns |accel_group_|. | |
|
Dean McNamee
2009/03/16 19:19:02
this makes it sound like add_accel took ownership.
| |
| 69 g_object_unref(accel_group_); | |
| 70 | |
| 85 toolbar_tooltips_ = gtk_tooltips_new(); | 71 toolbar_tooltips_ = gtk_tooltips_new(); |
| 86 | 72 |
| 87 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, | 73 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, |
| 88 IDR_BACK_D, | 74 IDR_BACK_D, |
| 89 l10n_util::GetString(IDS_TOOLTIP_BACK))); | 75 l10n_util::GetString(IDS_TOOLTIP_BACK))); |
| 90 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); | 76 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); |
| 91 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, | 77 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, |
| 92 IDR_FORWARD_H, IDR_FORWARD_D, | 78 IDR_FORWARD_H, IDR_FORWARD_D, |
| 93 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); | 79 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); |
| 94 AddAcceleratorToButton(forward_, GDK_Right, GDK_MOD1_MASK); | 80 AddAcceleratorToButton(forward_, GDK_Right, GDK_MOD1_MASK); |
| 95 | 81 |
| 82 // TODO(estade): These blank labels are kind of ghetto. Padding should be | |
| 83 // handled differently (via spacing parameters or padding widgets that use | |
| 84 // gtk_widget_set_size_request). | |
| 96 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); | 85 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); |
| 97 | 86 |
| 98 reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, | 87 reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, |
| 99 l10n_util::GetString(IDS_TOOLTIP_RELOAD))); | 88 l10n_util::GetString(IDS_TOOLTIP_RELOAD))); |
| 100 AddAcceleratorToButton(reload_, GDK_r, GDK_CONTROL_MASK); | 89 AddAcceleratorToButton(reload_, GDK_r, GDK_CONTROL_MASK); |
| 101 | 90 |
| 102 // TODO(port): we need to dynamically react to changes in show_home_button_ | 91 // TODO(port): we need to dynamically react to changes in show_home_button_ |
| 103 // and hide/show home appropriately. But we don't have a UI for it yet. | 92 // and hide/show home appropriately. But we don't have a UI for it yet. |
| 104 if (*show_home_button_) | 93 if (*show_home_button_) |
| 105 home_.reset(MakeHomeButton()); | 94 home_.reset(MakeHomeButton()); |
| 106 | 95 |
| 107 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); | 96 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); |
| 108 | 97 |
| 109 star_.reset(BuildToolbarButton(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D, | 98 star_.reset(BuildToolbarButton(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D, |
| 110 l10n_util::GetString(IDS_TOOLTIP_STAR))); | 99 l10n_util::GetString(IDS_TOOLTIP_STAR))); |
| 111 | 100 |
| 112 location_bar_->Init(); | 101 location_bar_->Init(); |
| 113 gtk_box_pack_start(GTK_BOX(toolbar_), location_bar_->widget(), TRUE, TRUE, 0); | 102 gtk_box_pack_start(GTK_BOX(toolbar_), location_bar_->widget(), TRUE, TRUE, 0); |
| 114 | 103 |
| 115 // Map ctrl-l for setting focus to the location entry. | |
| 116 gtk_accel_group_connect( | |
| 117 accel_group_, GDK_l, GDK_CONTROL_MASK, GtkAccelFlags(0), | |
| 118 g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL)); | |
| 119 // Map ctrl-k for setting focus to a search in the location entry. | |
| 120 gtk_accel_group_connect( | |
| 121 accel_group_, GDK_k, GDK_CONTROL_MASK, GtkAccelFlags(0), | |
| 122 g_cclosure_new(G_CALLBACK(OnAccelerator), this, NULL)); | |
| 123 | |
| 124 go_.reset(BuildToolbarButton(IDR_GO, IDR_GO_P, IDR_GO_H, 0, L"")); | 104 go_.reset(BuildToolbarButton(IDR_GO, IDR_GO_P, IDR_GO_H, 0, L"")); |
| 125 | 105 |
| 126 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); | 106 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); |
| 127 | 107 |
| 128 page_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_PAGE, | 108 page_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_PAGE, |
| 129 l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); | 109 l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); |
| 130 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); | 110 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); |
| 131 | 111 |
| 132 app_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_CHROME, | 112 app_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_CHROME, |
| 133 l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, | 113 l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 } | 350 } |
| 371 | 351 |
| 372 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { | 352 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { |
| 373 app_menu_->Popup(app_menu_button_->widget(), button_press_event); | 353 app_menu_->Popup(app_menu_button_->widget(), button_press_event); |
| 374 } | 354 } |
| 375 | 355 |
| 376 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { | 356 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { |
| 377 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 357 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
| 378 l10n_util::GetString(IDS_TOOLTIP_HOME)); | 358 l10n_util::GetString(IDS_TOOLTIP_HOME)); |
| 379 } | 359 } |
| OLD | NEW |