Name all the GLib timeout sources
[WebKit-https.git] / Source / WebCore / platform / gtk / ContextMenuGtk.cpp
index 6f168fe..8c002c4 100644 (file)
  */
 
 #include "config.h"
+
+#if ENABLE(CONTEXT_MENUS)
+
 #include "ContextMenu.h"
 
-#include "GOwnPtr.h"
 #include <gtk/gtk.h>
+#include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GRefPtr.h>
 
 namespace WebCore {
 
@@ -45,10 +49,14 @@ void ContextMenu::appendItem(ContextMenuItem& item)
 {
     ASSERT(m_platformDescription);
 
-    GtkMenuItem* platformItem = item.releasePlatformDescription();
+    GRefPtr<GtkWidget> platformItem = GTK_WIDGET(item.releasePlatformDescription());
     ASSERT(platformItem);
-    gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), GTK_WIDGET(platformItem));
-    gtk_widget_show(GTK_WIDGET(platformItem));
+
+    if (GtkWidget* parent = gtk_widget_get_parent(platformItem.get()))
+        gtk_container_remove(GTK_CONTAINER(parent), platformItem.get());
+
+    gtk_menu_shell_append(GTK_MENU_SHELL(m_platformDescription), platformItem.get());
+    gtk_widget_show(platformItem.get());
 }
 
 void ContextMenu::setPlatformDescription(PlatformMenuDescription menu)
@@ -75,6 +83,14 @@ PlatformMenuDescription ContextMenu::releasePlatformDescription()
     return description;
 }
 
+unsigned ContextMenu::itemCount() const
+{
+    ASSERT(m_platformDescription);
+
+    GOwnPtr<GList> children(gtk_container_get_children(GTK_CONTAINER(m_platformDescription)));
+    return g_list_length(children.get());
+}
+
 Vector<ContextMenuItem> contextMenuItemVector(const PlatformMenuDescription menu)
 {
     Vector<ContextMenuItem> menuItemVector;
@@ -87,7 +103,7 @@ Vector<ContextMenuItem> contextMenuItemVector(const PlatformMenuDescription menu
         GtkWidget* widget = static_cast<GtkWidget*>(item->data);
         if (!GTK_IS_MENU_ITEM(widget))
             continue;
-        menuItemVector.append(ContextMenuItem(GTK_MENU_ITEM(widget)));
+        menuItemVector.append(GTK_MENU_ITEM(widget));
     }
 
     return menuItemVector;
@@ -105,3 +121,5 @@ PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>& subMenu
 }
 
 }
+
+#endif // ENABLE(CONTEXT_MENUS)