summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 16:43:19 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-26 16:43:19 +0000
commit4002818e31a0a239293891f9e4865858c7e24cd7 (patch)
treeb184471ba3a64a1fa8c3fee3f5808d685f2cb569
parentd62d417537df562371bc7f7c6624004fc89af59c (diff)
downloadchromium_src-4002818e31a0a239293891f9e4865858c7e24cd7.zip
chromium_src-4002818e31a0a239293891f9e4865858c7e24cd7.tar.gz
chromium_src-4002818e31a0a239293891f9e4865858c7e24cd7.tar.bz2
Update gtk/menu2 without closing menu
* ResetMenu now simply remove all menu items. * This will closes all submenus opened. It require a lot more work to update submenus correctly. Since there is no scenario that requires this so this is good enough for our use case. BUG=chromium-os:8106 TEST=manual: on chromeos device, open network menu and change network settings. (plug-unplug ethernet) Review URL: http://codereview.chromium.org/4120002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63899 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--views/controls/menu/native_menu_gtk.cc23
1 files changed, 15 insertions, 8 deletions
diff --git a/views/controls/menu/native_menu_gtk.cc b/views/controls/menu/native_menu_gtk.cc
index 31a8c3f..12f73da 100644
--- a/views/controls/menu/native_menu_gtk.cc
+++ b/views/controls/menu/native_menu_gtk.cc
@@ -47,6 +47,13 @@ bool MenuTypeCanExecute(menus::MenuModel::ItemType type) {
type == menus::MenuModel::TYPE_RADIO;
}
+// A callback to gtk_container_foreach to remove all children.
+// See |NativeMenuGtk::ResetMenu| for the usage.
+void RemoveChildWidget(GtkWidget* widget, gpointer data) {
+ GtkWidget* parent = gtk_widget_get_parent(widget);
+ gtk_container_remove(GTK_CONTAINER(parent), widget);
+}
+
} // namespace
namespace views {
@@ -371,15 +378,15 @@ GtkWidget* NativeMenuGtk::AddMenuItemAt(int index,
}
void NativeMenuGtk::ResetMenu() {
- if (menu_) {
- g_signal_handler_disconnect(menu_, destroy_handler_id_);
- gtk_widget_destroy(menu_);
+ if (!menu_) {
+ menu_ = gtk_menu_new();
+ g_object_set_data(
+ G_OBJECT(GTK_MENU(menu_)->toplevel), kNativeMenuGtkString, this);
+ destroy_handler_id_ = g_signal_connect(
+ menu_, "destroy", G_CALLBACK(NativeMenuGtk::MenuDestroyed), host_menu_);
+ } else {
+ gtk_container_foreach(GTK_CONTAINER(menu_), RemoveChildWidget, NULL);
}
- menu_ = gtk_menu_new();
- g_object_set_data(
- G_OBJECT(GTK_MENU(menu_)->toplevel), kNativeMenuGtkString, this);
- destroy_handler_id_ = g_signal_connect(
- menu_, "destroy", G_CALLBACK(NativeMenuGtk::MenuDestroyed), host_menu_);
}
void NativeMenuGtk::UpdateMenuItemState(GtkWidget* menu_item) {