| 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_view_gtk.h" | 5 #include "chrome/browser/gtk/browser_toolbar_view_gtk.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/base_paths_linux.h" | 10 #include "base/base_paths_linux.h" |
| 9 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
| 11 #include "chrome/browser/browser.h" | 13 #include "chrome/browser/browser.h" |
| 12 #include "chrome/browser/gtk/custom_button.h" | 14 #include "chrome/browser/gtk/custom_button.h" |
| 13 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" | 15 #include "chrome/browser/gtk/back_forward_menu_model_gtk.h" |
| 14 #include "chrome/browser/gtk/standard_menus.h" | 16 #include "chrome/browser/gtk/standard_menus.h" |
| 15 #include "chrome/browser/net/url_fixer_upper.h" | 17 #include "chrome/browser/net/url_fixer_upper.h" |
| 16 #include "chrome/common/l10n_util.h" | 18 #include "chrome/common/l10n_util.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 39 | 41 |
| 40 back_menu_model_.reset(new BackForwardMenuModelGtk( | 42 back_menu_model_.reset(new BackForwardMenuModelGtk( |
| 41 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); | 43 browser, BackForwardMenuModel::BACKWARD_MENU_DELEGATE)); |
| 42 forward_menu_model_.reset(new BackForwardMenuModelGtk( | 44 forward_menu_model_.reset(new BackForwardMenuModelGtk( |
| 43 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); | 45 browser, BackForwardMenuModel::FORWARD_MENU_DELEGATE)); |
| 44 } | 46 } |
| 45 | 47 |
| 46 BrowserToolbarGtk::~BrowserToolbarGtk() { | 48 BrowserToolbarGtk::~BrowserToolbarGtk() { |
| 47 } | 49 } |
| 48 | 50 |
| 49 void BrowserToolbarGtk::Init(Profile* profile) { | 51 void BrowserToolbarGtk::Init(Profile* profile, GtkAccelGroup* accel_group) { |
| 52 accel_group_ = accel_group; |
| 53 |
| 50 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); | 54 show_home_button_.Init(prefs::kShowHomeButton, profile->GetPrefs(), this); |
| 51 | 55 |
| 52 toolbar_ = gtk_hbox_new(FALSE, 0); | 56 toolbar_ = gtk_hbox_new(FALSE, 0); |
| 53 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); | 57 gtk_container_set_border_width(GTK_CONTAINER(toolbar_), 4); |
| 54 // TODO(evanm): this setting of the x-size to 0 makes it so the window | 58 // TODO(evanm): this setting of the x-size to 0 makes it so the window |
| 55 // can be resized arbitrarily small. We should figure out what we want | 59 // can be resized arbitrarily small. We should figure out what we want |
| 56 // with respect to resizing before engineering around it, though. | 60 // with respect to resizing before engineering around it, though. |
| 57 gtk_widget_set_size_request(toolbar_, 0, kToolbarHeight); | 61 gtk_widget_set_size_request(toolbar_, 0, kToolbarHeight); |
| 58 | 62 |
| 59 toolbar_tooltips_ = gtk_tooltips_new(); | 63 toolbar_tooltips_ = gtk_tooltips_new(); |
| 60 | 64 |
| 61 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, | 65 back_.reset(BuildBackForwardButton(IDR_BACK, IDR_BACK_P, IDR_BACK_H, |
| 62 IDR_BACK_D, | 66 IDR_BACK_D, |
| 63 l10n_util::GetString(IDS_TOOLTIP_BACK))); | 67 l10n_util::GetString(IDS_TOOLTIP_BACK))); |
| 68 AddAcceleratorToButton(back_, GDK_Left, GDK_MOD1_MASK); |
| 64 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, | 69 forward_.reset(BuildBackForwardButton(IDR_FORWARD, IDR_FORWARD_P, |
| 65 IDR_FORWARD_H, IDR_FORWARD_D, | 70 IDR_FORWARD_H, IDR_FORWARD_D, |
| 66 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); | 71 l10n_util::GetString(IDS_TOOLTIP_FORWARD))); |
| 72 AddAcceleratorToButton(forward_, GDK_Right, GDK_MOD1_MASK); |
| 67 | 73 |
| 68 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); | 74 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); |
| 69 | 75 |
| 70 reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, | 76 reload_.reset(BuildToolbarButton(IDR_RELOAD, IDR_RELOAD_P, IDR_RELOAD_H, 0, |
| 71 l10n_util::GetString(IDS_TOOLTIP_RELOAD))); | 77 l10n_util::GetString(IDS_TOOLTIP_RELOAD))); |
| 78 AddAcceleratorToButton(reload_, GDK_r, GDK_CONTROL_MASK); |
| 72 | 79 |
| 73 // TODO(port): we need to dynamically react to changes in show_home_button_ | 80 // TODO(port): we need to dynamically react to changes in show_home_button_ |
| 74 // and hide/show home appropriately. But we don't have a UI for it yet. | 81 // and hide/show home appropriately. But we don't have a UI for it yet. |
| 75 if (*show_home_button_) | 82 if (*show_home_button_) |
| 76 home_.reset(MakeHomeButton()); | 83 home_.reset(MakeHomeButton()); |
| 77 | 84 |
| 78 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); |
| 79 | 86 |
| 80 star_.reset(BuildToolbarButton(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D, | 87 star_.reset(BuildToolbarButton(IDR_STAR, IDR_STAR_P, IDR_STAR_H, IDR_STAR_D, |
| 81 l10n_util::GetString(IDS_TOOLTIP_STAR))); | 88 l10n_util::GetString(IDS_TOOLTIP_STAR))); |
| 82 | 89 |
| 83 entry_ = gtk_entry_new(); | 90 entry_ = gtk_entry_new(); |
| 84 gtk_widget_set_size_request(entry_, 0, 27); | 91 gtk_widget_set_size_request(entry_, 0, 27); |
| 85 g_signal_connect(G_OBJECT(entry_), "activate", | 92 g_signal_connect(G_OBJECT(entry_), "activate", |
| 86 G_CALLBACK(OnEntryActivate), this); | 93 G_CALLBACK(OnEntryActivate), this); |
| 94 gtk_widget_add_accelerator( |
| 95 entry_, "grab-focus", accel_group_, GDK_l, |
| 96 GDK_CONTROL_MASK, GtkAccelFlags(0)); |
| 97 |
| 87 gtk_box_pack_start(GTK_BOX(toolbar_), entry_, TRUE, TRUE, 0); | 98 gtk_box_pack_start(GTK_BOX(toolbar_), entry_, TRUE, TRUE, 0); |
| 88 | 99 |
| 89 go_.reset(BuildToolbarButton(IDR_GO, IDR_GO_P, IDR_GO_H, 0, L"")); | 100 go_.reset(BuildToolbarButton(IDR_GO, IDR_GO_P, IDR_GO_H, 0, L"")); |
| 90 | 101 |
| 91 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); | 102 gtk_box_pack_start(GTK_BOX(toolbar_), gtk_label_new(" "), FALSE, FALSE, 0); |
| 92 | 103 |
| 93 page_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_PAGE, | 104 page_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_PAGE, |
| 94 l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); | 105 l10n_util::GetString(IDS_PAGEMENU_TOOLTIP))); |
| 106 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu(), accel_group_)); |
| 107 |
| 95 app_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_CHROME, | 108 app_menu_button_.reset(BuildToolbarMenuButton(IDR_MENU_CHROME, |
| 96 l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, | 109 l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, |
| 97 l10n_util::GetString(IDS_PRODUCT_NAME)))); | 110 l10n_util::GetString(IDS_PRODUCT_NAME)))); |
| 111 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu(), accel_group_)); |
| 98 | 112 |
| 99 SetProfile(profile); | 113 SetProfile(profile); |
| 100 } | 114 } |
| 101 | 115 |
| 102 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { | 116 void BrowserToolbarGtk::AddToolbarToBox(GtkWidget* box) { |
| 103 gtk_box_pack_start(GTK_BOX(box), toolbar_, FALSE, FALSE, 0); | 117 gtk_box_pack_start(GTK_BOX(box), toolbar_, FALSE, FALSE, 0); |
| 104 } | 118 } |
| 105 | 119 |
| 106 void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) { | 120 void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) { |
| 107 GtkWidget* widget = NULL; | 121 GtkWidget* widget = NULL; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 G_CALLBACK(OnButtonClick), this); | 305 G_CALLBACK(OnButtonClick), this); |
| 292 | 306 |
| 293 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); | 307 gtk_box_pack_start(GTK_BOX(toolbar_), button->widget(), FALSE, FALSE, 0); |
| 294 // Popup the menu as left-aligned relative to this widget rather than the | 308 // Popup the menu as left-aligned relative to this widget rather than the |
| 295 // default of right aligned. | 309 // default of right aligned. |
| 296 g_object_set_data(G_OBJECT(button->widget()), "left-align-popup", | 310 g_object_set_data(G_OBJECT(button->widget()), "left-align-popup", |
| 297 reinterpret_cast<void*>(true)); | 311 reinterpret_cast<void*>(true)); |
| 298 return button; | 312 return button; |
| 299 } | 313 } |
| 300 | 314 |
| 315 void BrowserToolbarGtk::AddAcceleratorToButton( |
| 316 const scoped_ptr<CustomDrawButton>& button, |
| 317 unsigned int accelerator, |
| 318 unsigned int accelerator_mod) { |
| 319 gtk_widget_add_accelerator( |
| 320 button->widget(), "clicked", accel_group_, accelerator, |
| 321 GdkModifierType(accelerator_mod), GtkAccelFlags(0)); |
| 322 } |
| 323 |
| 301 // static | 324 // static |
| 302 gboolean BrowserToolbarGtk::OnBackForwardPressEvent(GtkWidget* widget, | 325 gboolean BrowserToolbarGtk::OnBackForwardPressEvent(GtkWidget* widget, |
| 303 GdkEventButton* event, | 326 GdkEventButton* event, |
| 304 BrowserToolbarGtk* toolbar) { | 327 BrowserToolbarGtk* toolbar) { |
| 305 // TODO(port): only allow left clicks to open the menu. | 328 // TODO(port): only allow left clicks to open the menu. |
| 306 MessageLoop::current()->PostDelayedTask(FROM_HERE, | 329 MessageLoop::current()->PostDelayedTask(FROM_HERE, |
| 307 toolbar->show_menu_factory_.NewRunnableMethod( | 330 toolbar->show_menu_factory_.NewRunnableMethod( |
| 308 &BrowserToolbarGtk::ShowBackForwardMenu, | 331 &BrowserToolbarGtk::ShowBackForwardMenu, |
| 309 widget, event->button), | 332 widget, event->button), |
| 310 kMenuTimerDelay); | 333 kMenuTimerDelay); |
| 311 return FALSE; | 334 return FALSE; |
| 312 } | 335 } |
| 313 | 336 |
| 314 void BrowserToolbarGtk::ShowBackForwardMenu(GtkWidget* widget, | 337 void BrowserToolbarGtk::ShowBackForwardMenu(GtkWidget* widget, |
| 315 gint button_type) { | 338 gint button_type) { |
| 316 if (widget == back_->widget()) { | 339 if (widget == back_->widget()) { |
| 317 back_forward_menu_.reset(new MenuGtk(back_menu_model_.get())); | 340 back_forward_menu_.reset(new MenuGtk(back_menu_model_.get())); |
| 318 } else { | 341 } else { |
| 319 back_forward_menu_.reset(new MenuGtk(forward_menu_model_.get())); | 342 back_forward_menu_.reset(new MenuGtk(forward_menu_model_.get())); |
| 320 } | 343 } |
| 321 | 344 |
| 322 back_forward_menu_->Popup(widget, button_type, gtk_get_current_event_time()); | 345 back_forward_menu_->Popup(widget, button_type, gtk_get_current_event_time()); |
| 323 } | 346 } |
| 324 | 347 |
| 325 void BrowserToolbarGtk::RunPageMenu(GdkEvent* button_press_event) { | 348 void BrowserToolbarGtk::RunPageMenu(GdkEvent* button_press_event) { |
| 326 if (page_menu_ == NULL) { | |
| 327 page_menu_.reset(new MenuGtk(this, GetStandardPageMenu())); | |
| 328 } | |
| 329 | |
| 330 page_menu_->Popup(page_menu_button_->widget(), button_press_event); | 349 page_menu_->Popup(page_menu_button_->widget(), button_press_event); |
| 331 } | 350 } |
| 332 | 351 |
| 333 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { | 352 void BrowserToolbarGtk::RunAppMenu(GdkEvent* button_press_event) { |
| 334 if (app_menu_ == NULL) { | |
| 335 app_menu_.reset(new MenuGtk(this, GetStandardAppMenu())); | |
| 336 } | |
| 337 | |
| 338 app_menu_->Popup(app_menu_button_->widget(), button_press_event); | 353 app_menu_->Popup(app_menu_button_->widget(), button_press_event); |
| 339 } | 354 } |
| 340 | 355 |
| 341 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { | 356 CustomDrawButton* BrowserToolbarGtk::MakeHomeButton() { |
| 342 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, | 357 return BuildToolbarButton(IDR_HOME, IDR_HOME_P, IDR_HOME_H, 0, |
| 343 l10n_util::GetString(IDS_TOOLTIP_HOME)); | 358 l10n_util::GetString(IDS_TOOLTIP_HOME)); |
| 344 } | 359 } |
| OLD | NEW |