| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/ui/gtk/menu_gtk.h" | 5 #include "chrome/browser/ui/gtk/menu_gtk.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, | 277 MenuGtk::MenuGtk(MenuGtk::Delegate* delegate, |
| 278 ui::MenuModel* model) | 278 ui::MenuModel* model) |
| 279 : delegate_(delegate), | 279 : delegate_(delegate), |
| 280 model_(model), | 280 model_(model), |
| 281 dummy_accel_group_(gtk_accel_group_new()), | 281 dummy_accel_group_(gtk_accel_group_new()), |
| 282 menu_(gtk_custom_menu_new()), | 282 menu_(gtk_custom_menu_new()), |
| 283 factory_(this) { | 283 factory_(this) { |
| 284 DCHECK(model); | 284 DCHECK(model); |
| 285 g_object_ref_sink(menu_); | 285 g_object_ref_sink(menu_); |
| 286 ConnectSignalHandlers(); | 286 ConnectSignalHandlers(); |
| 287 model->SetMenuModelDelegate(this); |
| 287 BuildMenuFromModel(); | 288 BuildMenuFromModel(); |
| 288 } | 289 } |
| 289 | 290 |
| 290 MenuGtk::~MenuGtk() { | 291 MenuGtk::~MenuGtk() { |
| 291 Cancel(); | 292 Cancel(); |
| 292 | 293 |
| 293 gtk_widget_destroy(menu_); | 294 gtk_widget_destroy(menu_); |
| 294 g_object_unref(menu_); | 295 g_object_unref(menu_); |
| 295 | 296 |
| 296 STLDeleteContainerPointers(submenus_we_own_.begin(), submenus_we_own_.end()); | 297 STLDeleteContainerPointers(submenus_we_own_.begin(), submenus_we_own_.end()); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 394 |
| 394 void MenuGtk::PopupAsFromKeyEvent(GtkWidget* widget) { | 395 void MenuGtk::PopupAsFromKeyEvent(GtkWidget* widget) { |
| 395 PopupForWidget(widget, 0, gtk_get_current_event_time()); | 396 PopupForWidget(widget, 0, gtk_get_current_event_time()); |
| 396 gtk_menu_shell_select_first(GTK_MENU_SHELL(menu_), FALSE); | 397 gtk_menu_shell_select_first(GTK_MENU_SHELL(menu_), FALSE); |
| 397 } | 398 } |
| 398 | 399 |
| 399 void MenuGtk::Cancel() { | 400 void MenuGtk::Cancel() { |
| 400 gtk_menu_popdown(GTK_MENU(menu_)); | 401 gtk_menu_popdown(GTK_MENU(menu_)); |
| 401 } | 402 } |
| 402 | 403 |
| 404 void MenuGtk::OnIconChanged(int model_index) { |
| 405 gtk_container_foreach(GTK_CONTAINER(menu_), UpdateMenuIcon, &model_index); |
| 406 } |
| 407 |
| 403 void MenuGtk::UpdateMenu() { | 408 void MenuGtk::UpdateMenu() { |
| 404 gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this); | 409 gtk_container_foreach(GTK_CONTAINER(menu_), SetMenuItemInfo, this); |
| 405 } | 410 } |
| 406 | 411 |
| 407 GtkWidget* MenuGtk::BuildMenuItemWithImage(const std::string& label, | 412 GtkWidget* MenuGtk::BuildMenuItemWithImage(const std::string& label, |
| 408 GtkWidget* image) { | 413 GtkWidget* image) { |
| 409 GtkWidget* menu_item = | 414 GtkWidget* menu_item = |
| 410 gtk_image_menu_item_new_with_mnemonic(label.c_str()); | 415 gtk_image_menu_item_new_with_mnemonic(label.c_str()); |
| 411 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image); | 416 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(menu_item), image); |
| 412 return menu_item; | 417 return menu_item; |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 delegate_->CommandWillBeExecuted(); | 638 delegate_->CommandWillBeExecuted(); |
| 634 | 639 |
| 635 model->ActivatedCommand(command_id); | 640 model->ActivatedCommand(command_id); |
| 636 pressed = TRUE; | 641 pressed = TRUE; |
| 637 } | 642 } |
| 638 | 643 |
| 639 return pressed; | 644 return pressed; |
| 640 } | 645 } |
| 641 | 646 |
| 642 // static | 647 // static |
| 648 void MenuGtk::UpdateMenuIcon(GtkWidget* widget, gpointer userdata) { |
| 649 if (GTK_IS_MENU_ITEM(widget)) { |
| 650 int model_index = *static_cast<int*>(userdata); |
| 651 int menu_id; |
| 652 GetMenuItemID(widget, &menu_id); |
| 653 if (menu_id != model_index) { |
| 654 return; |
| 655 } |
| 656 SkBitmap icon; |
| 657 ui::MenuModel* model = ModelForMenuItem(GTK_MENU_ITEM(widget)); |
| 658 if (model->GetIconAt(model_index, &icon)) { |
| 659 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); |
| 660 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(widget), |
| 661 gtk_image_new_from_pixbuf(pixbuf)); |
| 662 g_object_unref(pixbuf); |
| 663 } |
| 664 } |
| 665 } |
| 666 |
| 667 // static |
| 643 void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu, | 668 void MenuGtk::WidgetMenuPositionFunc(GtkMenu* menu, |
| 644 int* x, | 669 int* x, |
| 645 int* y, | 670 int* y, |
| 646 gboolean* push_in, | 671 gboolean* push_in, |
| 647 void* void_widget) { | 672 void* void_widget) { |
| 648 GtkWidget* widget = GTK_WIDGET(void_widget); | 673 GtkWidget* widget = GTK_WIDGET(void_widget); |
| 649 GtkRequisition menu_req; | 674 GtkRequisition menu_req; |
| 650 | 675 |
| 651 gtk_widget_size_request(GTK_WIDGET(menu), &menu_req); | 676 gtk_widget_size_request(GTK_WIDGET(menu), &menu_req); |
| 652 | 677 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 gtk_widget_hide(widget); | 848 gtk_widget_hide(widget); |
| 824 } | 849 } |
| 825 | 850 |
| 826 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); | 851 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); |
| 827 if (submenu) { | 852 if (submenu) { |
| 828 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, | 853 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, |
| 829 userdata); | 854 userdata); |
| 830 } | 855 } |
| 831 } | 856 } |
| 832 } | 857 } |
| OLD | NEW |