OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/bind.h" | 9 #include "base/bind.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
(...skipping 723 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 if (event && event->type == GDK_BUTTON_RELEASE) | 734 if (event && event->type == GDK_BUTTON_RELEASE) |
735 event_flags = event_utils::EventFlagsFromGdkState(event->button.state); | 735 event_flags = event_utils::EventFlagsFromGdkState(event->button.state); |
736 model->ActivatedAt(id, event_flags); | 736 model->ActivatedAt(id, event_flags); |
737 | 737 |
738 if (event) | 738 if (event) |
739 gdk_event_free(event); | 739 gdk_event_free(event); |
740 } | 740 } |
741 | 741 |
742 void MenuGtk::OnMenuShow(GtkWidget* widget) { | 742 void MenuGtk::OnMenuShow(GtkWidget* widget) { |
743 model_->MenuWillShow(); | 743 model_->MenuWillShow(); |
744 MessageLoop::current()->PostTask( | 744 base::MessageLoop::current()->PostTask( |
745 FROM_HERE, | 745 FROM_HERE, base::Bind(&MenuGtk::UpdateMenu, weak_factory_.GetWeakPtr())); |
746 base::Bind(&MenuGtk::UpdateMenu, weak_factory_.GetWeakPtr())); | |
747 } | 746 } |
748 | 747 |
749 void MenuGtk::OnMenuHidden(GtkWidget* widget) { | 748 void MenuGtk::OnMenuHidden(GtkWidget* widget) { |
750 if (delegate_) | 749 if (delegate_) |
751 delegate_->StoppedShowing(); | 750 delegate_->StoppedShowing(); |
752 model_->MenuClosed(); | 751 model_->MenuClosed(); |
753 } | 752 } |
754 | 753 |
755 gboolean MenuGtk::OnMenuFocusOut(GtkWidget* widget, GdkEventFocus* event) { | 754 gboolean MenuGtk::OnMenuFocusOut(GtkWidget* widget, GdkEventFocus* event) { |
756 gtk_widget_hide(menu_); | 755 gtk_widget_hide(menu_); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
791 | 790 |
792 void MenuGtk::OnSubMenuHidden(GtkWidget* submenu) { | 791 void MenuGtk::OnSubMenuHidden(GtkWidget* submenu) { |
793 // Increase the reference count of the old submenu, and schedule it to be | 792 // Increase the reference count of the old submenu, and schedule it to be |
794 // deleted later. We get this hide notification before we've processed menu | 793 // deleted later. We get this hide notification before we've processed menu |
795 // activations, so if we were to delete the submenu now, we might lose the | 794 // activations, so if we were to delete the submenu now, we might lose the |
796 // activation. This also lets us reuse the menu if it is shown again before | 795 // activation. This also lets us reuse the menu if it is shown again before |
797 // it gets deleted; in that case, OnSubMenuHiddenCallback() just decrements | 796 // it gets deleted; in that case, OnSubMenuHiddenCallback() just decrements |
798 // the reference count again. Note that the delay is just an optimization; we | 797 // the reference count again. Note that the delay is just an optimization; we |
799 // could use PostTask() and this would still work correctly. | 798 // could use PostTask() and this would still work correctly. |
800 g_object_ref(G_OBJECT(submenu)); | 799 g_object_ref(G_OBJECT(submenu)); |
801 MessageLoop::current()->PostDelayedTask( | 800 base::MessageLoop::current()->PostDelayedTask( |
802 FROM_HERE, | 801 FROM_HERE, |
803 base::Bind(&MenuGtk::OnSubMenuHiddenCallback, submenu), | 802 base::Bind(&MenuGtk::OnSubMenuHiddenCallback, submenu), |
804 base::TimeDelta::FromSeconds(2)); | 803 base::TimeDelta::FromSeconds(2)); |
805 } | 804 } |
806 | 805 |
807 namespace { | 806 namespace { |
808 | 807 |
809 // Remove all descendant submenu-model data pointers. | 808 // Remove all descendant submenu-model data pointers. |
810 void RemoveSubMenuModels(GtkWidget* menu_item, void* unused) { | 809 void RemoveSubMenuModels(GtkWidget* menu_item, void* unused) { |
811 if (!GTK_IS_MENU_ITEM(menu_item)) | 810 if (!GTK_IS_MENU_ITEM(menu_item)) |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 gtk_widget_hide(widget); | 944 gtk_widget_hide(widget); |
946 } | 945 } |
947 | 946 |
948 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); | 947 GtkWidget* submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); |
949 if (submenu) { | 948 if (submenu) { |
950 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, | 949 gtk_container_foreach(GTK_CONTAINER(submenu), &SetMenuItemInfo, |
951 userdata); | 950 userdata); |
952 } | 951 } |
953 } | 952 } |
954 } | 953 } |
OLD | NEW |