| 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 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 #include <X11/XF86keysym.h> | 9 #include <X11/XF86keysym.h> |
| 10 | 10 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 menu_bar_helper_.Add(app_menu_button_.get()); | 219 menu_bar_helper_.Add(app_menu_button_.get()); |
| 220 app_menu_image_ = gtk_image_new_from_pixbuf( | 220 app_menu_image_ = gtk_image_new_from_pixbuf( |
| 221 theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_CHROME)); | 221 theme_provider_->GetRTLEnabledPixbufNamed(IDR_MENU_CHROME)); |
| 222 gtk_container_add(GTK_CONTAINER(chrome_menu), app_menu_image_); | 222 gtk_container_add(GTK_CONTAINER(chrome_menu), app_menu_image_); |
| 223 | 223 |
| 224 app_menu_.reset(new MenuGtk(this, &app_menu_model_)); | 224 app_menu_.reset(new MenuGtk(this, &app_menu_model_)); |
| 225 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); | 225 gtk_box_pack_start(GTK_BOX(menus_hbox_), chrome_menu, FALSE, FALSE, 0); |
| 226 | 226 |
| 227 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); | 227 gtk_box_pack_start(GTK_BOX(toolbar_), menus_hbox_, FALSE, FALSE, 0); |
| 228 | 228 |
| 229 // Page and app menu accelerators. | |
| 230 GtkAccelGroup* accel_group = gtk_accel_group_new(); | |
| 231 gtk_window_add_accel_group(top_level_window, accel_group); | |
| 232 // Drop the initial ref on |accel_group| so |window_| will own it. | |
| 233 g_object_unref(accel_group); | |
| 234 // I would use "popup-menu" here, but GTK complains. I would use "activate", | |
| 235 // but the docs say never to connect to that signal. | |
| 236 gtk_widget_add_accelerator(page_menu, "clicked", accel_group, | |
| 237 GDK_e, GDK_MOD1_MASK, | |
| 238 static_cast<GtkAccelFlags>(0)); | |
| 239 gtk_widget_add_accelerator(chrome_menu, "clicked", accel_group, | |
| 240 GDK_f, GDK_MOD1_MASK, | |
| 241 static_cast<GtkAccelFlags>(0)); | |
| 242 | |
| 243 if (ShouldOnlyShowLocation()) { | 229 if (ShouldOnlyShowLocation()) { |
| 244 gtk_widget_show(event_box_); | 230 gtk_widget_show(event_box_); |
| 245 gtk_widget_show(alignment_); | 231 gtk_widget_show(alignment_); |
| 246 gtk_widget_show(toolbar_); | 232 gtk_widget_show(toolbar_); |
| 247 gtk_widget_show_all(location_hbox); | 233 gtk_widget_show_all(location_hbox); |
| 248 gtk_widget_hide(star_->widget()); | 234 gtk_widget_hide(star_->widget()); |
| 249 gtk_widget_hide(go_->widget()); | 235 gtk_widget_hide(go_->widget()); |
| 250 } else { | 236 } else { |
| 251 gtk_widget_show_all(event_box_); | 237 gtk_widget_show_all(event_box_); |
| 252 | 238 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 } | 279 } |
| 294 | 280 |
| 295 void BrowserToolbarGtk::UpdateForBookmarkBarVisibility( | 281 void BrowserToolbarGtk::UpdateForBookmarkBarVisibility( |
| 296 bool show_bottom_padding) { | 282 bool show_bottom_padding) { |
| 297 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_), | 283 gtk_alignment_set_padding(GTK_ALIGNMENT(alignment_), |
| 298 ShouldOnlyShowLocation() ? 0 : kTopPadding, | 284 ShouldOnlyShowLocation() ? 0 : kTopPadding, |
| 299 !show_bottom_padding || ShouldOnlyShowLocation() ? 0 : kTopPadding, | 285 !show_bottom_padding || ShouldOnlyShowLocation() ? 0 : kTopPadding, |
| 300 kLeftRightPadding, kLeftRightPadding); | 286 kLeftRightPadding, kLeftRightPadding); |
| 301 } | 287 } |
| 302 | 288 |
| 289 void BrowserToolbarGtk::ShowPageMenu() { |
| 290 PopupForButton(page_menu_button_.get()); |
| 291 } |
| 292 |
| 293 void BrowserToolbarGtk::ShowAppMenu() { |
| 294 PopupForButton(app_menu_button_.get()); |
| 295 } |
| 296 |
| 303 // CommandUpdater::CommandObserver --------------------------------------------- | 297 // CommandUpdater::CommandObserver --------------------------------------------- |
| 304 | 298 |
| 305 void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) { | 299 void BrowserToolbarGtk::EnabledStateChangedForCommand(int id, bool enabled) { |
| 306 GtkWidget* widget = NULL; | 300 GtkWidget* widget = NULL; |
| 307 switch (id) { | 301 switch (id) { |
| 308 case IDC_BACK: | 302 case IDC_BACK: |
| 309 widget = back_->widget(); | 303 widget = back_->widget(); |
| 310 break; | 304 break; |
| 311 case IDC_FORWARD: | 305 case IDC_FORWARD: |
| 312 widget = forward_->widget(); | 306 widget = forward_->widget(); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 | 499 |
| 506 GtkWidget* BrowserToolbarGtk::BuildToolbarMenuButton( | 500 GtkWidget* BrowserToolbarGtk::BuildToolbarMenuButton( |
| 507 const std::string& localized_tooltip, | 501 const std::string& localized_tooltip, |
| 508 OwnedWidgetGtk* owner) { | 502 OwnedWidgetGtk* owner) { |
| 509 GtkWidget* button = theme_provider_->BuildChromeButton(); | 503 GtkWidget* button = theme_provider_->BuildChromeButton(); |
| 510 owner->Own(button); | 504 owner->Own(button); |
| 511 | 505 |
| 512 gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); | 506 gtk_widget_set_tooltip_text(button, localized_tooltip.c_str()); |
| 513 g_signal_connect(button, "button-press-event", | 507 g_signal_connect(button, "button-press-event", |
| 514 G_CALLBACK(OnMenuButtonPressEvent), this); | 508 G_CALLBACK(OnMenuButtonPressEvent), this); |
| 515 g_signal_connect(button, "clicked", | |
| 516 G_CALLBACK(OnMenuClicked), this); | |
| 517 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); | 509 GTK_WIDGET_UNSET_FLAGS(button, GTK_CAN_FOCUS); |
| 518 | 510 |
| 519 return button; | 511 return button; |
| 520 } | 512 } |
| 521 | 513 |
| 522 void BrowserToolbarGtk::SetUpDragForHomeButton() { | 514 void BrowserToolbarGtk::SetUpDragForHomeButton() { |
| 523 gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, | 515 gtk_drag_dest_set(home_->widget(), GTK_DEST_DEFAULT_ALL, |
| 524 NULL, 0, GDK_ACTION_COPY); | 516 NULL, 0, GDK_ACTION_COPY); |
| 525 static const int targets[] = { GtkDndUtil::TEXT_PLAIN, | 517 static const int targets[] = { GtkDndUtil::TEXT_PLAIN, |
| 526 GtkDndUtil::TEXT_URI_LIST, -1 }; | 518 GtkDndUtil::TEXT_URI_LIST, -1 }; |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 GTK_STATE_ACTIVE); | 647 GTK_STATE_ACTIVE); |
| 656 MenuGtk* menu = button == toolbar->page_menu_button_.get() ? | 648 MenuGtk* menu = button == toolbar->page_menu_button_.get() ? |
| 657 toolbar->page_menu_.get() : toolbar->app_menu_.get(); | 649 toolbar->page_menu_.get() : toolbar->app_menu_.get(); |
| 658 menu->Popup(button, reinterpret_cast<GdkEvent*>(event)); | 650 menu->Popup(button, reinterpret_cast<GdkEvent*>(event)); |
| 659 toolbar->menu_bar_helper_.MenuStartedShowing(button, menu->widget()); | 651 toolbar->menu_bar_helper_.MenuStartedShowing(button, menu->widget()); |
| 660 | 652 |
| 661 return TRUE; | 653 return TRUE; |
| 662 } | 654 } |
| 663 | 655 |
| 664 // static | 656 // static |
| 665 gboolean BrowserToolbarGtk::OnMenuClicked(GtkWidget* button, | |
| 666 BrowserToolbarGtk* toolbar) { | |
| 667 toolbar->PopupForButton(button); | |
| 668 | |
| 669 return TRUE; | |
| 670 } | |
| 671 | |
| 672 // static | |
| 673 void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, | 657 void BrowserToolbarGtk::OnDragDataReceived(GtkWidget* widget, |
| 674 GdkDragContext* drag_context, gint x, gint y, | 658 GdkDragContext* drag_context, gint x, gint y, |
| 675 GtkSelectionData* data, guint info, guint time, | 659 GtkSelectionData* data, guint info, guint time, |
| 676 BrowserToolbarGtk* toolbar) { | 660 BrowserToolbarGtk* toolbar) { |
| 677 if (info != GtkDndUtil::TEXT_PLAIN) { | 661 if (info != GtkDndUtil::TEXT_PLAIN) { |
| 678 NOTIMPLEMENTED() << "Only support plain text drops for now, sorry!"; | 662 NOTIMPLEMENTED() << "Only support plain text drops for now, sorry!"; |
| 679 return; | 663 return; |
| 680 } | 664 } |
| 681 | 665 |
| 682 GURL url(reinterpret_cast<char*>(data->data)); | 666 GURL url(reinterpret_cast<char*>(data->data)); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 menu->PopupAsFromKeyEvent(button); | 717 menu->PopupAsFromKeyEvent(button); |
| 734 menu_bar_helper_.MenuStartedShowing(button, menu->widget()); | 718 menu_bar_helper_.MenuStartedShowing(button, menu->widget()); |
| 735 } | 719 } |
| 736 | 720 |
| 737 void BrowserToolbarGtk::PopupForButtonNextTo(GtkWidget* button, | 721 void BrowserToolbarGtk::PopupForButtonNextTo(GtkWidget* button, |
| 738 GtkMenuDirectionType dir) { | 722 GtkMenuDirectionType dir) { |
| 739 GtkWidget* other_button = button == page_menu_button_.get() ? | 723 GtkWidget* other_button = button == page_menu_button_.get() ? |
| 740 app_menu_button_.get() : page_menu_button_.get(); | 724 app_menu_button_.get() : page_menu_button_.get(); |
| 741 PopupForButton(other_button); | 725 PopupForButton(other_button); |
| 742 } | 726 } |
| OLD | NEW |