[GTK] Use CROSS_PLATFORM_CONTEXT_MENUS
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2015 16:08:32 +0000 (16:08 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 10 Nov 2015 16:08:32 +0000 (16:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=150642

Reviewed by Martin Robinson.

Source/WebCore:

Remove GTK+ implementations of old context menu classes.

* PlatformGTK.cmake:
* platform/ContextMenuItem.h:
* platform/gtk/ContextMenuGtk.cpp: Removed.
* platform/gtk/ContextMenuItemGtk.cpp: Removed.

Source/WebKit2:

Use CROSS_PLATFORM_CONTEXT_MENUS. Since we can't just use
WebContextMenuItemData, because we need to bind a GtkAction to the
menu items, this patch adds WebContextMenuItemGtk that derives
from WebContextMenuItemData and adds the GtkAction and its own
handling of submenu items. WebKitContextMenu and
WebKitContextMenuItem no longer deal with the widgets (GtkMenu and
GtkMenuItem), that are now created by WebContextMenuProxy when
building the popup menu.
This patch also removes the support for input methods submenu,
since it has been deprecated (and disabled by default) in GTK+ for
long time, it has never actually worked (because the menu items
don't have a GtkAction associated) and it makes the code more
complicated for no benefit.

* PlatformGTK.cmake:
* Shared/gtk/WebContextMenuItemGtk.cpp: Added.
(WebKit::gtkStockIDFromContextMenuAction):
(WebKit::WebContextMenuItemGtk::WebContextMenuItemGtk):
(WebKit::WebContextMenuItemGtk::~WebContextMenuItemGtk):
(WebKit::WebContextMenuItemGtk::createGtkActionIfNeeded):
* Shared/gtk/WebContextMenuItemGtk.h: Copied from Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h.
(WebKit::WebContextMenuItemGtk::gtkAction):
(WebKit::WebContextMenuItemGtk::submenuItems):
* UIProcess/API/gtk/WebKitContextMenu.cpp:
(webkitContextMenuPopulate):
(webkitContextMenuCreate): Deleted.
(webkitContextMenuSetParentItem): Deleted.
* UIProcess/API/gtk/WebKitContextMenuActions.cpp:
(webkitContextMenuActionGetForContextMenuItem):
* UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h:
* UIProcess/API/gtk/WebKitContextMenuItem.cpp:
(webkitContextMenuItemSetSubMenu):
(webkitContextMenuItemCreate):
(webkitContextMenuItemToWebContextMenuItemGtk):
(webkitContextMenuItemToWebContextMenuItemData):
(webkit_context_menu_item_new):
(webkit_context_menu_item_new_from_stock_action):
(webkit_context_menu_item_new_from_stock_action_with_label):
(webkit_context_menu_item_new_with_submenu):
(webkit_context_menu_item_new_separator):
(webkit_context_menu_item_get_action):
(webkit_context_menu_item_get_stock_action):
(webkit_context_menu_item_is_separator): Deleted.
* UIProcess/API/gtk/WebKitContextMenuItemPrivate.h:
* UIProcess/API/gtk/WebKitContextMenuPrivate.h:
* UIProcess/API/gtk/WebKitWebView.cpp:
(webkitWebViewPopulateContextMenu):
(contextMenuDismissed): Deleted.
(webkitWebViewSubmitFormRequest): Deleted.
(webkitWebViewHandleAuthenticationChallenge): Deleted.
(webkitWebViewInsecureContentDetected): Deleted.
(webkitWebViewEmitRunColorChooser): Deleted.
(webkitWebViewRequestInstallMissingMediaPlugins): Deleted.
* UIProcess/gtk/WebContextMenuProxyGtk.cpp:
(WebKit::contextMenuItemActivatedCallback):
(WebKit::WebContextMenuProxyGtk::append):
(WebKit::WebContextMenuProxyGtk::populate):
(WebKit::WebContextMenuProxyGtk::show):
(WebKit::WebContextMenuProxyGtk::WebContextMenuProxyGtk):
(WebKit::WebContextMenuProxyGtk::~WebContextMenuProxyGtk):
* UIProcess/gtk/WebContextMenuProxyGtk.h:
(WebKit::WebContextMenuProxyGtk::gtkMenu):
* WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:

Source/WTF:

Enable CROSS_PLATFORM_CONTEXT_MENUS for GTK+ port.

* wtf/Platform.h:

Tools:

Remove test for input methods submenu.

* TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@192247 268f45cc-cd09-0410-ab3c-d52691b4dbfc

23 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Platform.h
Source/WebCore/ChangeLog
Source/WebCore/PlatformGTK.cmake
Source/WebCore/platform/ContextMenuItem.h
Source/WebCore/platform/gtk/ContextMenuGtk.cpp [deleted file]
Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp [deleted file]
Source/WebKit2/ChangeLog
Source/WebKit2/PlatformGTK.cmake
Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.cpp [new file with mode: 0644]
Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.h [new file with mode: 0644]
Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp
Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItemPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuPrivate.h
Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp
Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp
Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h
Source/WebKit2/WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp

index cc60caa..65ac9a9 100644 (file)
@@ -1,3 +1,14 @@
+2015-11-10  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use CROSS_PLATFORM_CONTEXT_MENUS
+        https://bugs.webkit.org/show_bug.cgi?id=150642
+
+        Reviewed by Martin Robinson.
+
+        Enable CROSS_PLATFORM_CONTEXT_MENUS for GTK+ port.
+
+        * wtf/Platform.h:
+
 2015-11-09  Anders Carlsson  <andersca@apple.com>
 
         Introspect reply block types as well
index 0232a49..fbe6280 100644 (file)
 /* Set up a define for a common error that is intended to cause a build error -- thus the space after Error. */
 #define WTF_PLATFORM_CFNETWORK Error USE_macro_should_be_used_with_CFNETWORK
 
-#if PLATFORM(WIN)
+#if PLATFORM(WIN) || PLATFORM(GTK)
 #define USE_CROSS_PLATFORM_CONTEXT_MENUS 1
 #endif
 
index a792887..5fb5665 100644 (file)
@@ -1,3 +1,17 @@
+2015-11-10  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use CROSS_PLATFORM_CONTEXT_MENUS
+        https://bugs.webkit.org/show_bug.cgi?id=150642
+
+        Reviewed by Martin Robinson.
+
+        Remove GTK+ implementations of old context menu classes.
+
+        * PlatformGTK.cmake:
+        * platform/ContextMenuItem.h:
+        * platform/gtk/ContextMenuGtk.cpp: Removed.
+        * platform/gtk/ContextMenuItemGtk.cpp: Removed.
+
 2015-11-10  Xabier Rodriguez Calvar  <calvaris@igalia.com>
 
         [Streams API] Fix style issues
index a4d7d76..446c69b 100644 (file)
@@ -241,8 +241,6 @@ list(APPEND WebCorePlatformGTK_SOURCES
     platform/graphics/gtk/ImageBufferGtk.cpp
     platform/graphics/gtk/ImageGtk.cpp
 
-    platform/gtk/ContextMenuGtk.cpp
-    platform/gtk/ContextMenuItemGtk.cpp
     platform/gtk/CursorGtk.cpp
     platform/gtk/DataObjectGtk.cpp
     platform/gtk/DragDataGtk.cpp
index 0f4c65f..d0df094 100644 (file)
@@ -36,9 +36,6 @@
 #include <wtf/RetainPtr.h>
 OBJC_CLASS NSImage;
 OBJC_CLASS NSMenuItem;
-#elif PLATFORM(GTK)
-typedef struct _GtkMenuItem GtkMenuItem;
-typedef struct _GtkAction GtkAction;
 #endif
 #endif // ENABLE(CONTEXT_MENUS)
 
@@ -180,8 +177,6 @@ namespace WebCore {
 #if ENABLE(CONTEXT_MENUS)
 #if PLATFORM(COCOA)
     typedef NSMenuItem* PlatformMenuItemDescription;
-#elif PLATFORM(GTK)
-    typedef GtkMenuItem* PlatformMenuItemDescription;
 #else
     typedef void* PlatformMenuItemDescription;
 #endif
@@ -212,10 +207,6 @@ namespace WebCore {
         WEBCORE_EXPORT static ContextMenuItem shareMenuItem(const URL& absoluteLinkURL, const URL& downloadableMediaURL, NSImage *, const String& selectedText);
 #endif
 
-#if PLATFORM(GTK)
-        GtkAction* gtkAction() const;
-#endif
-
 #if USE(CROSS_PLATFORM_CONTEXT_MENUS)
         ContextMenuItem(ContextMenuAction, const String&, bool enabled, bool checked, const Vector<ContextMenuItem>& subMenuItems);
         explicit ContextMenuItem(const PlatformContextMenuItem&);
@@ -240,10 +231,6 @@ namespace WebCore {
 
         bool isNull() const { return !m_platformDescription; }
 
-#if PLATFORM(GTK)
-        WEBCORE_EXPORT PlatformMenuItemDescription releasePlatformDescription();
-#endif
-
         WEBCORE_EXPORT PlatformMenuItemDescription platformDescription() const;
 
         WEBCORE_EXPORT String title() const;
diff --git a/Source/WebCore/platform/gtk/ContextMenuGtk.cpp b/Source/WebCore/platform/gtk/ContextMenuGtk.cpp
deleted file mode 100644 (file)
index f2cbca0..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- *  Copyright (C) 2007 Holger Hans Peter Freyther
- * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "config.h"
-
-#if ENABLE(CONTEXT_MENUS)
-
-#include "ContextMenu.h"
-
-#include <gtk/gtk.h>
-#include <wtf/glib/GRefPtr.h>
-#include <wtf/glib/GUniquePtr.h>
-
-namespace WebCore {
-
-ContextMenu::ContextMenu()
-{
-    m_platformDescription = GTK_MENU(gtk_menu_new());
-}
-
-ContextMenu::ContextMenu(const PlatformMenuDescription menu)
-    : m_platformDescription(menu)
-{
-}
-
-ContextMenu::~ContextMenu()
-{
-    if (m_platformDescription)
-        gtk_widget_destroy(GTK_WIDGET(m_platformDescription));
-}
-
-void ContextMenu::appendItem(ContextMenuItem& item)
-{
-    ASSERT(m_platformDescription);
-
-    GRefPtr<GtkWidget> platformItem = GTK_WIDGET(item.releasePlatformDescription());
-    ASSERT(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)
-{
-    if (m_platformDescription == menu)
-        return;
-    if (m_platformDescription)
-        gtk_widget_destroy(GTK_WIDGET(m_platformDescription));
-
-    m_platformDescription = menu;
-}
-
-PlatformMenuDescription ContextMenu::platformDescription() const
-{
-    return m_platformDescription;
-}
-
-PlatformMenuDescription ContextMenu::releasePlatformDescription()
-{
-    PlatformMenuDescription description = m_platformDescription;
-    m_platformDescription = 0;
-
-    return description;
-}
-
-unsigned ContextMenu::itemCount() const
-{
-    ASSERT(m_platformDescription);
-
-    GUniquePtr<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;
-
-    GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(menu)));
-    int itemCount = g_list_length(children.get());
-    menuItemVector.reserveCapacity(itemCount);
-
-    for (GList* item = children.get(); item; item = g_list_next(item)) {
-        GtkWidget* widget = static_cast<GtkWidget*>(item->data);
-        if (!GTK_IS_MENU_ITEM(widget))
-            continue;
-        menuItemVector.append(GTK_MENU_ITEM(widget));
-    }
-
-    return menuItemVector;
-}
-
-PlatformMenuDescription platformMenuDescription(Vector<ContextMenuItem>& subMenuItems)
-{
-    GtkMenu* menu = GTK_MENU(gtk_menu_new());
-    for (size_t i = 0; i < subMenuItems.size(); i++) {
-        GtkWidget* platformItem = GTK_WIDGET(subMenuItems[i].releasePlatformDescription());
-        gtk_menu_shell_append(GTK_MENU_SHELL(menu), platformItem);
-        gtk_widget_show(platformItem);
-    }
-    return menu;
-}
-
-}
-
-#endif // ENABLE(CONTEXT_MENUS)
diff --git a/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp b/Source/WebCore/platform/gtk/ContextMenuItemGtk.cpp
deleted file mode 100644 (file)
index 8789b11..0000000
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- *  Copyright (C) 2007 Holger Hans Peter Freyther
- *  Copyright (C) 2010 Igalia S.L
- * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#include "config.h"
-
-#if ENABLE(CONTEXT_MENUS)
-
-#include "ContextMenuItem.h"
-
-#include "ContextMenu.h"
-#include <gtk/gtk.h>
-#include <wtf/glib/GRefPtr.h>
-#include <wtf/glib/GUniquePtr.h>
-#include <wtf/text/CString.h>
-
-#define WEBKIT_CONTEXT_MENU_ACTION "webkit-context-menu"
-
-namespace WebCore {
-
-static const char* gtkStockIDFromContextMenuAction(const ContextMenuAction& action)
-{
-    switch (action) {
-    case ContextMenuItemTagCopyLinkToClipboard:
-    case ContextMenuItemTagCopyImageToClipboard:
-    case ContextMenuItemTagCopyMediaLinkToClipboard:
-    case ContextMenuItemTagCopy:
-        return GTK_STOCK_COPY;
-    case ContextMenuItemTagOpenLinkInNewWindow:
-    case ContextMenuItemTagOpenImageInNewWindow:
-    case ContextMenuItemTagOpenFrameInNewWindow:
-    case ContextMenuItemTagOpenMediaInNewWindow:
-        return GTK_STOCK_OPEN;
-    case ContextMenuItemTagDownloadLinkToDisk:
-    case ContextMenuItemTagDownloadImageToDisk:
-        return GTK_STOCK_SAVE;
-    case ContextMenuItemTagGoBack:
-        return GTK_STOCK_GO_BACK;
-    case ContextMenuItemTagGoForward:
-        return GTK_STOCK_GO_FORWARD;
-    case ContextMenuItemTagStop:
-        return GTK_STOCK_STOP;
-    case ContextMenuItemTagReload:
-        return GTK_STOCK_REFRESH;
-    case ContextMenuItemTagCut:
-        return GTK_STOCK_CUT;
-    case ContextMenuItemTagPaste:
-        return GTK_STOCK_PASTE;
-    case ContextMenuItemTagDelete:
-        return GTK_STOCK_DELETE;
-    case ContextMenuItemTagSelectAll:
-        return GTK_STOCK_SELECT_ALL;
-    case ContextMenuItemTagSpellingGuess:
-        return 0;
-    case ContextMenuItemTagIgnoreSpelling:
-        return GTK_STOCK_NO;
-    case ContextMenuItemTagLearnSpelling:
-        return GTK_STOCK_OK;
-    case ContextMenuItemTagOther:
-        return GTK_STOCK_MISSING_IMAGE;
-    case ContextMenuItemTagSearchInSpotlight:
-        return GTK_STOCK_FIND;
-    case ContextMenuItemTagSearchWeb:
-        return GTK_STOCK_FIND;
-    case ContextMenuItemTagOpenWithDefaultApplication:
-        return GTK_STOCK_OPEN;
-    case ContextMenuItemPDFZoomIn:
-        return GTK_STOCK_ZOOM_IN;
-    case ContextMenuItemPDFZoomOut:
-        return GTK_STOCK_ZOOM_OUT;
-    case ContextMenuItemPDFAutoSize:
-        return GTK_STOCK_ZOOM_FIT;
-    case ContextMenuItemPDFNextPage:
-        return GTK_STOCK_GO_FORWARD;
-    case ContextMenuItemPDFPreviousPage:
-        return GTK_STOCK_GO_BACK;
-    // New tags, not part of API
-    case ContextMenuItemTagOpenLink:
-        return GTK_STOCK_OPEN;
-    case ContextMenuItemTagCheckSpelling:
-        return GTK_STOCK_SPELL_CHECK;
-    case ContextMenuItemTagFontMenu:
-        return GTK_STOCK_SELECT_FONT;
-    case ContextMenuItemTagShowFonts:
-        return GTK_STOCK_SELECT_FONT;
-    case ContextMenuItemTagBold:
-        return GTK_STOCK_BOLD;
-    case ContextMenuItemTagItalic:
-        return GTK_STOCK_ITALIC;
-    case ContextMenuItemTagUnderline:
-        return GTK_STOCK_UNDERLINE;
-    case ContextMenuItemTagShowColors:
-        return GTK_STOCK_SELECT_COLOR;
-    case ContextMenuItemTagToggleMediaControls:
-    case ContextMenuItemTagToggleMediaLoop:
-    case ContextMenuItemTagCopyImageUrlToClipboard:
-        // No icon for this.
-        return 0;
-    case ContextMenuItemTagEnterVideoFullscreen:
-        return GTK_STOCK_FULLSCREEN;
-    default:
-        return 0;
-    }
-}
-
-static PlatformMenuItemDescription createPlatformMenuItemDescription(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked)
-{
-    if (type == SeparatorType)
-        return GTK_MENU_ITEM(gtk_separator_menu_item_new());
-
-    GUniquePtr<char> actionName(g_strdup_printf("context-menu-action-%d", action));
-    GRefPtr<GtkAction> platformAction;
-
-    if (type == CheckableActionType) {
-        platformAction = adoptGRef(GTK_ACTION(gtk_toggle_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action))));
-        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(platformAction.get()), checked);
-    } else
-        platformAction = adoptGRef(gtk_action_new(actionName.get(), title.utf8().data(), 0, gtkStockIDFromContextMenuAction(action)));
-    gtk_action_set_sensitive(platformAction.get(), enabled);
-
-    GtkMenuItem* item = GTK_MENU_ITEM(gtk_action_create_menu_item(platformAction.get()));
-    g_object_set_data(G_OBJECT(item), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
-
-    return item;
-}
-
-ContextMenuItem::ContextMenuItem()
-    : m_platformDescription(nullptr)
-{
-}
-
-// Extract the ActionType from the menu item
-ContextMenuItem::ContextMenuItem(PlatformMenuItemDescription item)
-    : m_platformDescription(item)
-{
-    // Don't show accel labels in context menu items.
-    GtkAction* action = gtkAction();
-    if (!action)
-        return;
-
-    if (!gtk_action_get_accel_path(action))
-        return;
-
-    GtkWidget* child = gtk_bin_get_child(GTK_BIN(item));
-    if (GTK_IS_ACCEL_LABEL(child))
-        gtk_accel_label_set_accel_closure(GTK_ACCEL_LABEL(child), 0);
-}
-
-ContextMenuItem::ContextMenuItem(ContextMenu* subMenu)
-{
-    m_platformDescription = GTK_MENU_ITEM(gtk_menu_item_new());
-    if (subMenu)
-        setSubMenu(subMenu);
-}
-
-ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, ContextMenu* subMenu)
-{
-    m_platformDescription = createPlatformMenuItemDescription(type, action, title, true, false);
-    if (subMenu)
-        setSubMenu(subMenu);
-}
-
-ContextMenuItem::ContextMenuItem(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked)
-{
-    m_platformDescription = createPlatformMenuItemDescription(type, action, title, enabled, checked);
-}
-
-ContextMenuItem::ContextMenuItem(ContextMenuAction action, const String& title, bool enabled, bool checked, Vector<ContextMenuItem>& subMenuItems)
-{
-    m_platformDescription = createPlatformMenuItemDescription(SubmenuType, action, title, enabled, checked);
-    setSubMenu(subMenuItems);
-}
-
-ContextMenuItem::~ContextMenuItem()
-{
-}
-
-PlatformMenuItemDescription ContextMenuItem::releasePlatformDescription()
-{
-    PlatformMenuItemDescription platformDescription = m_platformDescription;
-    m_platformDescription = 0;
-    return platformDescription;
-}
-
-ContextMenuItemType ContextMenuItem::type() const
-{
-    if (GTK_IS_SEPARATOR_MENU_ITEM(m_platformDescription))
-        return SeparatorType;
-    if (GTK_IS_CHECK_MENU_ITEM(m_platformDescription))
-        return CheckableActionType;
-    if (gtk_menu_item_get_submenu(m_platformDescription))
-        return SubmenuType;
-    return ActionType;
-}
-
-void ContextMenuItem::setType(ContextMenuItemType type)
-{
-    if (type == SeparatorType)
-        m_platformDescription = GTK_MENU_ITEM(gtk_separator_menu_item_new());
-}
-
-ContextMenuAction ContextMenuItem::action() const
-{
-    return static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(m_platformDescription), WEBKIT_CONTEXT_MENU_ACTION)));
-}
-
-void ContextMenuItem::setAction(ContextMenuAction action)
-{
-    g_object_set_data(G_OBJECT(m_platformDescription), WEBKIT_CONTEXT_MENU_ACTION, GINT_TO_POINTER(action));
-}
-
-String ContextMenuItem::title() const
-{
-    GtkAction* action = gtkAction();
-    return action ? String::fromUTF8(gtk_action_get_label(action)) : String();
-}
-
-void ContextMenuItem::setTitle(const String& title)
-{
-    GtkAction* action = gtkAction();
-    if (action)
-        gtk_action_set_label(action, title.utf8().data());
-}
-
-PlatformMenuDescription ContextMenuItem::platformSubMenu() const
-{
-    GtkWidget* subMenu = gtk_menu_item_get_submenu(m_platformDescription);
-    return subMenu ? GTK_MENU(subMenu) : 0;
-}
-
-void ContextMenuItem::setSubMenu(ContextMenu* menu)
-{
-    gtk_menu_item_set_submenu(m_platformDescription, GTK_WIDGET(menu->releasePlatformDescription()));
-}
-
-void ContextMenuItem::setSubMenu(Vector<ContextMenuItem>& subMenuItems)
-{
-    ContextMenu menu(platformMenuDescription(subMenuItems));
-    setSubMenu(&menu);
-}
-
-void ContextMenuItem::setChecked(bool shouldCheck)
-{
-    GtkAction* action = gtkAction();
-    if (action && GTK_IS_TOGGLE_ACTION(action))
-        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), shouldCheck);
-}
-
-bool ContextMenuItem::checked() const
-{
-    GtkAction* action = gtkAction();
-    if (action && GTK_IS_TOGGLE_ACTION(action))
-        return gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action));
-    return false;
-}
-
-bool ContextMenuItem::enabled() const
-{
-    GtkAction* action = gtkAction();
-    return action ? gtk_action_get_sensitive(action) : false;
-}
-
-void ContextMenuItem::setEnabled(bool shouldEnable)
-{
-    GtkAction* action = gtkAction();
-    if (action)
-        gtk_action_set_sensitive(action, shouldEnable);
-}
-
-GtkAction* ContextMenuItem::gtkAction() const
-{
-    return gtk_activatable_get_related_action(GTK_ACTIVATABLE(m_platformDescription));
-}
-
-}
-
-#endif // ENABLE(CONTEXT_MENUS)
index 1e198c9..eefcf9f 100644 (file)
@@ -1,3 +1,74 @@
+2015-11-10  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use CROSS_PLATFORM_CONTEXT_MENUS
+        https://bugs.webkit.org/show_bug.cgi?id=150642
+
+        Reviewed by Martin Robinson.
+
+        Use CROSS_PLATFORM_CONTEXT_MENUS. Since we can't just use
+        WebContextMenuItemData, because we need to bind a GtkAction to the
+        menu items, this patch adds WebContextMenuItemGtk that derives
+        from WebContextMenuItemData and adds the GtkAction and its own
+        handling of submenu items. WebKitContextMenu and
+        WebKitContextMenuItem no longer deal with the widgets (GtkMenu and
+        GtkMenuItem), that are now created by WebContextMenuProxy when
+        building the popup menu.
+        This patch also removes the support for input methods submenu,
+        since it has been deprecated (and disabled by default) in GTK+ for
+        long time, it has never actually worked (because the menu items
+        don't have a GtkAction associated) and it makes the code more
+        complicated for no benefit.
+
+        * PlatformGTK.cmake:
+        * Shared/gtk/WebContextMenuItemGtk.cpp: Added.
+        (WebKit::gtkStockIDFromContextMenuAction):
+        (WebKit::WebContextMenuItemGtk::WebContextMenuItemGtk):
+        (WebKit::WebContextMenuItemGtk::~WebContextMenuItemGtk):
+        (WebKit::WebContextMenuItemGtk::createGtkActionIfNeeded):
+        * Shared/gtk/WebContextMenuItemGtk.h: Copied from Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.h.
+        (WebKit::WebContextMenuItemGtk::gtkAction):
+        (WebKit::WebContextMenuItemGtk::submenuItems):
+        * UIProcess/API/gtk/WebKitContextMenu.cpp:
+        (webkitContextMenuPopulate):
+        (webkitContextMenuCreate): Deleted.
+        (webkitContextMenuSetParentItem): Deleted.
+        * UIProcess/API/gtk/WebKitContextMenuActions.cpp:
+        (webkitContextMenuActionGetForContextMenuItem):
+        * UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h:
+        * UIProcess/API/gtk/WebKitContextMenuItem.cpp:
+        (webkitContextMenuItemSetSubMenu):
+        (webkitContextMenuItemCreate):
+        (webkitContextMenuItemToWebContextMenuItemGtk):
+        (webkitContextMenuItemToWebContextMenuItemData):
+        (webkit_context_menu_item_new):
+        (webkit_context_menu_item_new_from_stock_action):
+        (webkit_context_menu_item_new_from_stock_action_with_label):
+        (webkit_context_menu_item_new_with_submenu):
+        (webkit_context_menu_item_new_separator):
+        (webkit_context_menu_item_get_action):
+        (webkit_context_menu_item_get_stock_action):
+        (webkit_context_menu_item_is_separator): Deleted.
+        * UIProcess/API/gtk/WebKitContextMenuItemPrivate.h:
+        * UIProcess/API/gtk/WebKitContextMenuPrivate.h:
+        * UIProcess/API/gtk/WebKitWebView.cpp:
+        (webkitWebViewPopulateContextMenu):
+        (contextMenuDismissed): Deleted.
+        (webkitWebViewSubmitFormRequest): Deleted.
+        (webkitWebViewHandleAuthenticationChallenge): Deleted.
+        (webkitWebViewInsecureContentDetected): Deleted.
+        (webkitWebViewEmitRunColorChooser): Deleted.
+        (webkitWebViewRequestInstallMissingMediaPlugins): Deleted.
+        * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
+        (WebKit::contextMenuItemActivatedCallback):
+        (WebKit::WebContextMenuProxyGtk::append):
+        (WebKit::WebContextMenuProxyGtk::populate):
+        (WebKit::WebContextMenuProxyGtk::show):
+        (WebKit::WebContextMenuProxyGtk::WebContextMenuProxyGtk):
+        (WebKit::WebContextMenuProxyGtk::~WebContextMenuProxyGtk):
+        * UIProcess/gtk/WebContextMenuProxyGtk.h:
+        (WebKit::WebContextMenuProxyGtk::gtkMenu):
+        * WebProcess/InjectedBundle/API/gtk/WebKitWebPage.cpp:
+
 2015-11-09  Carlos Garcia Campos  <cgarcia@igalia.com>
 
         Unreviewed. Fix GTK+ build after r192184.
index c4081fb..2ba52c2 100644 (file)
@@ -70,6 +70,7 @@ list(APPEND WebKit2_SOURCES
     Shared/gtk/NativeWebWheelEventGtk.cpp
     Shared/gtk/PrintInfoGtk.cpp
     Shared/gtk/ProcessExecutablePathGtk.cpp
+    Shared/gtk/WebContextMenuItemGtk.cpp
     Shared/gtk/WebEventFactory.cpp
 
     Shared/linux/WebMemorySamplerLinux.cpp
diff --git a/Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.cpp b/Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.cpp
new file mode 100644 (file)
index 0000000..857b1e1
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebContextMenuItemGtk.h"
+
+#include <gtk/gtk.h>
+#include <wtf/glib/GUniquePtr.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static const char* gtkStockIDFromContextMenuAction(ContextMenuAction action)
+{
+    switch (action) {
+    case ContextMenuItemTagCopyLinkToClipboard:
+    case ContextMenuItemTagCopyImageToClipboard:
+    case ContextMenuItemTagCopyMediaLinkToClipboard:
+    case ContextMenuItemTagCopy:
+        return GTK_STOCK_COPY;
+    case ContextMenuItemTagOpenLinkInNewWindow:
+    case ContextMenuItemTagOpenImageInNewWindow:
+    case ContextMenuItemTagOpenFrameInNewWindow:
+    case ContextMenuItemTagOpenMediaInNewWindow:
+        return GTK_STOCK_OPEN;
+    case ContextMenuItemTagDownloadLinkToDisk:
+    case ContextMenuItemTagDownloadImageToDisk:
+        return GTK_STOCK_SAVE;
+    case ContextMenuItemTagGoBack:
+        return GTK_STOCK_GO_BACK;
+    case ContextMenuItemTagGoForward:
+        return GTK_STOCK_GO_FORWARD;
+    case ContextMenuItemTagStop:
+        return GTK_STOCK_STOP;
+    case ContextMenuItemTagReload:
+        return GTK_STOCK_REFRESH;
+    case ContextMenuItemTagCut:
+        return GTK_STOCK_CUT;
+    case ContextMenuItemTagPaste:
+        return GTK_STOCK_PASTE;
+    case ContextMenuItemTagDelete:
+        return GTK_STOCK_DELETE;
+    case ContextMenuItemTagSelectAll:
+        return GTK_STOCK_SELECT_ALL;
+    case ContextMenuItemTagSpellingGuess:
+        return 0;
+    case ContextMenuItemTagIgnoreSpelling:
+        return GTK_STOCK_NO;
+    case ContextMenuItemTagLearnSpelling:
+        return GTK_STOCK_OK;
+    case ContextMenuItemTagOther:
+        return GTK_STOCK_MISSING_IMAGE;
+    case ContextMenuItemTagSearchInSpotlight:
+        return GTK_STOCK_FIND;
+    case ContextMenuItemTagSearchWeb:
+        return GTK_STOCK_FIND;
+    case ContextMenuItemTagOpenWithDefaultApplication:
+        return GTK_STOCK_OPEN;
+    case ContextMenuItemPDFZoomIn:
+        return GTK_STOCK_ZOOM_IN;
+    case ContextMenuItemPDFZoomOut:
+        return GTK_STOCK_ZOOM_OUT;
+    case ContextMenuItemPDFAutoSize:
+        return GTK_STOCK_ZOOM_FIT;
+    case ContextMenuItemPDFNextPage:
+        return GTK_STOCK_GO_FORWARD;
+    case ContextMenuItemPDFPreviousPage:
+        return GTK_STOCK_GO_BACK;
+    // New tags, not part of API
+    case ContextMenuItemTagOpenLink:
+        return GTK_STOCK_OPEN;
+    case ContextMenuItemTagCheckSpelling:
+        return GTK_STOCK_SPELL_CHECK;
+    case ContextMenuItemTagFontMenu:
+        return GTK_STOCK_SELECT_FONT;
+    case ContextMenuItemTagShowFonts:
+        return GTK_STOCK_SELECT_FONT;
+    case ContextMenuItemTagBold:
+        return GTK_STOCK_BOLD;
+    case ContextMenuItemTagItalic:
+        return GTK_STOCK_ITALIC;
+    case ContextMenuItemTagUnderline:
+        return GTK_STOCK_UNDERLINE;
+    case ContextMenuItemTagShowColors:
+        return GTK_STOCK_SELECT_COLOR;
+    case ContextMenuItemTagToggleMediaControls:
+    case ContextMenuItemTagToggleMediaLoop:
+    case ContextMenuItemTagCopyImageUrlToClipboard:
+        // No icon for this.
+        return 0;
+    case ContextMenuItemTagEnterVideoFullscreen:
+        return GTK_STOCK_FULLSCREEN;
+    default:
+        return 0;
+    }
+}
+
+WebContextMenuItemGtk::WebContextMenuItemGtk(ContextMenuItemType type, ContextMenuAction action, const String& title, bool enabled, bool checked)
+    : WebContextMenuItemData(type, action, title, enabled, checked)
+{
+    createGtkActionIfNeeded();
+}
+
+WebContextMenuItemGtk::WebContextMenuItemGtk(const WebContextMenuItemData& data)
+    : WebContextMenuItemData(data.type(), data.action(), data.title(), data.enabled(), data.checked())
+{
+    createGtkActionIfNeeded();
+}
+
+WebContextMenuItemGtk::WebContextMenuItemGtk(const WebContextMenuItemGtk& data, Vector<WebContextMenuItemGtk>&& submenu)
+    : WebContextMenuItemData(SubmenuType, data.action(), data.title(), data.enabled(), false)
+{
+    m_action = data.gtkAction();
+    m_submenuItems = WTF::move(submenu);
+}
+
+WebContextMenuItemGtk::WebContextMenuItemGtk(GtkAction* action)
+    : WebContextMenuItemData(GTK_IS_TOGGLE_ACTION(action) ? CheckableActionType : ActionType, ContextMenuItemBaseApplicationTag, String::fromUTF8(gtk_action_get_label(action)), gtk_action_get_sensitive(action), GTK_IS_TOGGLE_ACTION(action) ? gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) : false)
+{
+    m_action = action;
+}
+
+WebContextMenuItemGtk::~WebContextMenuItemGtk()
+{
+}
+
+void WebContextMenuItemGtk::createGtkActionIfNeeded()
+{
+    if (type() == SeparatorType)
+        return;
+
+    GUniquePtr<char> actionName(g_strdup_printf("context-menu-action-%d", action()));
+    if (type() == CheckableActionType) {
+        m_action = adoptGRef(GTK_ACTION(gtk_toggle_action_new(actionName.get(), title().utf8().data(), nullptr, gtkStockIDFromContextMenuAction(action()))));
+        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(m_action.get()), checked());
+    } else
+        m_action = adoptGRef(gtk_action_new(actionName.get(), title().utf8().data(), 0, gtkStockIDFromContextMenuAction(action())));
+    gtk_action_set_sensitive(m_action.get(), enabled());
+}
+
+} // namespace WebKit
diff --git a/Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.h b/Source/WebKit2/Shared/gtk/WebContextMenuItemGtk.h
new file mode 100644 (file)
index 0000000..9615448
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2015 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebContextMenuItemGtk_h
+#define WebContextMenuItemGtk_h
+
+#include "APIObject.h"
+#include "WebContextMenuItemData.h"
+#include <wtf/glib/GRefPtr.h>
+
+typedef struct _GtkAction GtkAction;
+
+namespace WebKit {
+
+class WebContextMenuItemGtk : public WebContextMenuItemData {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    WebContextMenuItemGtk(WebCore::ContextMenuItemType, WebCore::ContextMenuAction, const String& title, bool enabled = true, bool checked = false);
+    WebContextMenuItemGtk(const WebContextMenuItemData&);
+    WebContextMenuItemGtk(const WebContextMenuItemGtk&, Vector<WebContextMenuItemGtk>&& submenu);
+    WebContextMenuItemGtk(GtkAction*);
+    ~WebContextMenuItemGtk();
+
+    GtkAction* gtkAction() const { return m_action.get(); }
+    const Vector<WebContextMenuItemGtk>& submenuItems() const { return m_submenuItems; }
+
+private:
+    void createGtkActionIfNeeded();
+
+    GRefPtr<GtkAction> m_action;
+    Vector<WebContextMenuItemGtk> m_submenuItems;
+};
+
+} // namespace WebKit
+
+#endif // WebContextMenuItemGtk_h
index e4f6cf0..95c1dd4 100644 (file)
@@ -68,19 +68,19 @@ static void webkit_context_menu_class_init(WebKitContextMenuClass* listClass)
     gObjectClass->dispose = webkitContextMenuDispose;
 }
 
-void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<ContextMenuItem>& contextMenuItems)
+void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<WebContextMenuItemData>& contextMenuItems)
 {
     for (GList* item = menu->priv->items; item; item = g_list_next(item)) {
         WebKitContextMenuItem* menuItem = WEBKIT_CONTEXT_MENU_ITEM(item->data);
-        contextMenuItems.append(ContextMenuItem(webkitContextMenuItemRelease(menuItem)));
+        contextMenuItems.append(webkitContextMenuItemToWebContextMenuItemData(menuItem));
     }
 }
 
-void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<WebContextMenuItemData>& contextMenuItems)
+void webkitContextMenuPopulate(WebKitContextMenu* menu, Vector<WebContextMenuItemGtk>& contextMenuItems)
 {
     for (GList* item = menu->priv->items; item; item = g_list_next(item)) {
         WebKitContextMenuItem* menuItem = WEBKIT_CONTEXT_MENU_ITEM(item->data);
-        contextMenuItems.append(WebContextMenuItemData(ContextMenuItem(webkitContextMenuItemRelease(menuItem))));
+        contextMenuItems.append(webkitContextMenuItemToWebContextMenuItemGtk(menuItem));
     }
 }
 
@@ -94,16 +94,6 @@ WebKitContextMenu* webkitContextMenuCreate(const Vector<WebContextMenuItemData>&
     return menu;
 }
 
-WebKitContextMenu* webkitContextMenuCreate(const Vector<ContextMenuItem>& items)
-{
-    WebKitContextMenu* menu = webkit_context_menu_new();
-    for (const auto& item : items)
-        webkit_context_menu_prepend(menu, webkitContextMenuItemCreate(item));
-    menu->priv->items = g_list_reverse(menu->priv->items);
-
-    return menu;
-}
-
 void webkitContextMenuSetParentItem(WebKitContextMenu* menu, WebKitContextMenuItem* item)
 {
     menu->priv->parentItem = item;
index 4ed20fa..cf1ddf9 100644 (file)
@@ -135,9 +135,9 @@ ContextMenuAction webkitContextMenuActionGetActionTag(WebKitContextMenuAction ac
     return ContextMenuItemBaseApplicationTag;
 }
 
-WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenuItem* menuItem)
+WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(const WebKit::WebContextMenuItemGtk& menuItem)
 {
-    switch (menuItem->action()) {
+    switch (menuItem.action()) {
     case ContextMenuItemTagNoAction:
         return WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION;
     case ContextMenuItemTagOpenLink:
@@ -203,10 +203,10 @@ WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenu
     case ContextMenuItemTagInspectElement:
         return WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT;
     case ContextMenuItemTagOpenMediaInNewWindow:
-        return menuItem->title() == contextMenuItemTagOpenVideoInNewWindow() ?
+        return menuItem.title() == contextMenuItemTagOpenVideoInNewWindow() ?
             WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW : WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW;
     case ContextMenuItemTagCopyMediaLinkToClipboard:
-        return menuItem->title() == contextMenuItemTagCopyVideoLinkToClipboard() ?
+        return menuItem.title() == contextMenuItemTagCopyVideoLinkToClipboard() ?
             WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD : WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD;
     case ContextMenuItemTagToggleMediaControls:
         return WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS;
@@ -215,12 +215,12 @@ WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(ContextMenu
     case ContextMenuItemTagEnterVideoFullscreen:
         return WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN;
     case ContextMenuItemTagMediaPlayPause:
-        return menuItem->title() == contextMenuItemTagMediaPlay() ?
+        return menuItem.title() == contextMenuItemTagMediaPlay() ?
             WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY : WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE;
     case ContextMenuItemTagMediaMute:
         return WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE;
     case ContextMenuItemTagDownloadMediaToDisk:
-        return menuItem->title() == contextMenuItemTagDownloadVideoToDisk() ?
+        return menuItem.title() == contextMenuItemTagDownloadVideoToDisk() ?
             WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK : WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK;
     case ContextMenuItemBaseApplicationTag:
         return WEBKIT_CONTEXT_MENU_ACTION_CUSTOM;
index f753bb9..e00b8e2 100644 (file)
 #ifndef WebKitContextMenuActionsPrivate_h
 #define WebKitContextMenuActionsPrivate_h
 
+#include "WebContextMenuItemGtk.h"
 #include "WebKitContextMenuActions.h"
-#include <WebCore/ContextMenuItem.h>
 
 bool webkitContextMenuActionIsCheckable(WebKitContextMenuAction);
 WebCore::ContextMenuAction webkitContextMenuActionGetActionTag(WebKitContextMenuAction);
-WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(WebCore::ContextMenuItem*);
+WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(const WebKit::WebContextMenuItemGtk&);
 String webkitContextMenuActionGetLabel(WebKitContextMenuAction);
 
 #endif // WebKitPrintOperationPrivate_h
index 6e7a27c..576a468 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "APIArray.h"
 #include "WebContextMenuItem.h"
-#include "WebContextMenuItemData.h"
+#include "WebContextMenuItemGtk.h"
 #include "WebKitContextMenuActionsPrivate.h"
 #include "WebKitContextMenuItemPrivate.h"
 #include "WebKitContextMenuPrivate.h"
@@ -56,7 +56,7 @@ struct _WebKitContextMenuItemPrivate {
             webkitContextMenuSetParentItem(subMenu.get(), 0);
     }
 
-    std::unique_ptr<ContextMenuItem> menuItem;
+    std::unique_ptr<WebContextMenuItemGtk> menuItem;
     GRefPtr<WebKitContextMenu> subMenu;
 };
 
@@ -84,7 +84,7 @@ static void webkitContextMenuItemSetSubMenu(WebKitContextMenuItem* item, GRefPtr
         return;
 
     if (item->priv->subMenu)
-        webkitContextMenuSetParentItem(item->priv->subMenu.get(), 0);
+        webkitContextMenuSetParentItem(item->priv->subMenu.get(), nullptr);
     item->priv->subMenu = subMenu;
     if (subMenu)
         webkitContextMenuSetParentItem(subMenu.get(), item);
@@ -94,7 +94,7 @@ WebKitContextMenuItem* webkitContextMenuItemCreate(const WebContextMenuItemData&
 {
     WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
 
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(itemData.type(), itemData.action(), itemData.title(), itemData.enabled(), itemData.checked());
+    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(itemData);
     const Vector<WebContextMenuItemData>& subMenu = itemData.submenu();
     if (!subMenu.isEmpty())
         webkitContextMenuItemSetSubMenu(item, adoptGRef(webkitContextMenuCreate(subMenu)));
@@ -102,60 +102,26 @@ WebKitContextMenuItem* webkitContextMenuItemCreate(const WebContextMenuItemData&
     return item;
 }
 
-WebKitContextMenuItem* webkitContextMenuItemCreate(const ContextMenuItem& coreItem)
+WebContextMenuItemGtk webkitContextMenuItemToWebContextMenuItemGtk(WebKitContextMenuItem* item)
 {
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
-
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(coreItem.type(), coreItem.action(), coreItem.title(), coreItem.enabled(), coreItem.checked());
-    if (coreItem.type() == WebCore::SubmenuType) {
-        Vector<ContextMenuItem> subMenu = contextMenuItemVector(coreItem.platformSubMenu());
-        webkitContextMenuItemSetSubMenu(item, adoptGRef(webkitContextMenuCreate(subMenu)));
+    if (item->priv->subMenu) {
+        Vector<WebContextMenuItemGtk> subMenuItems;
+        webkitContextMenuPopulate(item->priv->subMenu.get(), subMenuItems);
+        return WebContextMenuItemGtk(*item->priv->menuItem, WTF::move(subMenuItems));
     }
 
-    return item;
-}
-
-static WebKitContextMenuItem* webkitContextMenuItemCreateForGtkItem(GtkMenuItem* menuItem)
-{
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(menuItem);
-    webkitContextMenuItemSetSubMenuFromGtkMenu(item, GTK_MENU(gtk_menu_item_get_submenu(menuItem)));
-
-    return item;
+    return *item->priv->menuItem;
 }
 
-void webkitContextMenuItemSetSubMenuFromGtkMenu(WebKitContextMenuItem* item, GtkMenu* subMenu)
-{
-    if (!subMenu)
-        return;
-
-    GUniquePtr<GList> children(gtk_container_get_children(GTK_CONTAINER(subMenu)));
-    if (!g_list_length(children.get()))
-        return;
-
-    webkitContextMenuItemSetSubMenu(item, adoptGRef(webkit_context_menu_new()));
-    for (GList* listItem = children.get(); listItem; listItem = g_list_next(listItem)) {
-        GRefPtr<GtkWidget> widget = GTK_WIDGET(listItem->data);
-        if (!GTK_IS_MENU_ITEM(widget.get()))
-            continue;
-
-        gtk_container_remove(GTK_CONTAINER(subMenu), widget.get());
-        GtkMenuItem* menuItem = GTK_MENU_ITEM(widget.leakRef());
-        g_object_force_floating(G_OBJECT(menuItem));
-        webkit_context_menu_append(item->priv->subMenu.get(), webkitContextMenuItemCreateForGtkItem(menuItem));
-    }
-}
-
-GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem* item)
+WebContextMenuItemData webkitContextMenuItemToWebContextMenuItemData(WebKitContextMenuItem* item)
 {
     if (item->priv->subMenu) {
-        Vector<ContextMenuItem> subMenuItems;
+        Vector<WebContextMenuItemData> subMenuItems;
         webkitContextMenuPopulate(item->priv->subMenu.get(), subMenuItems);
-        ContextMenu subMenu(platformMenuDescription(subMenuItems));
-        item->priv->menuItem->setSubMenu(&subMenu);
+        return WebContextMenuItemData(item->priv->menuItem->action(), item->priv->menuItem->title(), item->priv->menuItem->enabled(), subMenuItems);
     }
 
-    return item->priv->menuItem->releasePlatformDescription();
+    return WebContextMenuItemData(item->priv->menuItem->type(), item->priv->menuItem->action(), item->priv->menuItem->title(), item->priv->menuItem->enabled(), item->priv->menuItem->checked());
 }
 
 /**
@@ -168,11 +134,10 @@ GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem* item)
  */
 WebKitContextMenuItem* webkit_context_menu_item_new(GtkAction* action)
 {
-    g_return_val_if_fail(GTK_IS_ACTION(action), 0);
+    g_return_val_if_fail(GTK_IS_ACTION(action), nullptr);
 
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(GTK_MENU_ITEM(gtk_action_create_menu_item(action)));
-    item->priv->menuItem->setAction(ContextMenuItemBaseApplicationTag);
+    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
+    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(action);
 
     return item;
 }
@@ -195,11 +160,11 @@ WebKitContextMenuItem* webkit_context_menu_item_new(GtkAction* action)
  */
 WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action(WebKitContextMenuAction action)
 {
-    g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, 0);
+    g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, nullptr);
 
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
+    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
     ContextMenuItemType type = webkitContextMenuActionIsCheckable(action) ? CheckableActionType : ActionType;
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(type, webkitContextMenuActionGetActionTag(action), webkitContextMenuActionGetLabel(action));
+    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(type, webkitContextMenuActionGetActionTag(action), webkitContextMenuActionGetLabel(action));
 
     return item;
 }
@@ -217,11 +182,11 @@ WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action(WebKitCont
  */
 WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action_with_label(WebKitContextMenuAction action, const gchar* label)
 {
-    g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, 0);
+    g_return_val_if_fail(action > WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION && action < WEBKIT_CONTEXT_MENU_ACTION_CUSTOM, nullptr);
 
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
+    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
     ContextMenuItemType type = webkitContextMenuActionIsCheckable(action) ? CheckableActionType : ActionType;
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(type, webkitContextMenuActionGetActionTag(action), String::fromUTF8(label));
+    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(type, webkitContextMenuActionGetActionTag(action), String::fromUTF8(label));
 
     return item;
 }
@@ -237,14 +202,14 @@ WebKitContextMenuItem* webkit_context_menu_item_new_from_stock_action_with_label
  */
 WebKitContextMenuItem* webkit_context_menu_item_new_with_submenu(const gchar* label, WebKitContextMenu* submenu)
 {
-    g_return_val_if_fail(label, 0);
-    g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU(submenu), 0);
+    g_return_val_if_fail(label, nullptr);
+    g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU(submenu), nullptr);
 
     if (checkAndWarnIfMenuHasParentItem(submenu))
-        return 0;
+        return nullptr;
 
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(SubmenuType, ContextMenuItemBaseApplicationTag, String::fromUTF8(label));
+    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
+    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(SubmenuType, ContextMenuItemBaseApplicationTag, String::fromUTF8(label));
     item->priv->subMenu = submenu;
     webkitContextMenuSetParentItem(submenu, item);
 
@@ -260,8 +225,8 @@ WebKitContextMenuItem* webkit_context_menu_item_new_with_submenu(const gchar* la
  */
 WebKitContextMenuItem* webkit_context_menu_item_new_separator(void)
 {
-    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, NULL));
-    item->priv->menuItem = std::make_unique<ContextMenuItem>(SeparatorType, ContextMenuItemTagNoAction, String());
+    WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(g_object_new(WEBKIT_TYPE_CONTEXT_MENU_ITEM, nullptr));
+    item->priv->menuItem = std::make_unique<WebContextMenuItemGtk>(SeparatorType, ContextMenuItemTagNoAction, String());
 
     return item;
 }
@@ -277,7 +242,7 @@ WebKitContextMenuItem* webkit_context_menu_item_new_separator(void)
  */
 GtkAction* webkit_context_menu_item_get_action(WebKitContextMenuItem* item)
 {
-    g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), 0);
+    g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), nullptr);
 
     return item->priv->menuItem->gtkAction();
 }
@@ -297,7 +262,7 @@ WebKitContextMenuAction webkit_context_menu_item_get_stock_action(WebKitContextM
 {
     g_return_val_if_fail(WEBKIT_IS_CONTEXT_MENU_ITEM(item), WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION);
 
-    return webkitContextMenuActionGetForContextMenuItem(item->priv->menuItem.get());
+    return webkitContextMenuActionGetForContextMenuItem(*item->priv->menuItem);
 }
 
 /**
index 7d85f25..be452fd 100644 (file)
 #ifndef WebKitContextMenuItemPrivate_h
 #define WebKitContextMenuItemPrivate_h
 
-#include "WebContextMenuItemData.h"
+#include "WebContextMenuItemGtk.h"
 #include "WebKitContextMenuItem.h"
 #include "WebKitPrivate.h"
 
 WebKitContextMenuItem* webkitContextMenuItemCreate(const WebKit::WebContextMenuItemData&);
-WebKitContextMenuItem* webkitContextMenuItemCreate(const WebCore::ContextMenuItem&);
-GtkMenuItem* webkitContextMenuItemRelease(WebKitContextMenuItem*);
-void webkitContextMenuItemSetSubMenuFromGtkMenu(WebKitContextMenuItem*, GtkMenu*);
+WebKit::WebContextMenuItemGtk webkitContextMenuItemToWebContextMenuItemGtk(WebKitContextMenuItem*);
+WebKit::WebContextMenuItemData webkitContextMenuItemToWebContextMenuItemData(WebKitContextMenuItem*);
 
 #endif // WebKitContextMenuItemPrivate_h
index e0baab1..3e4cae7 100644 (file)
 #ifndef WebKitContextMenuPrivate_h
 #define WebKitContextMenuPrivate_h
 
-#include "WebContextMenuItemData.h"
+#include "WebContextMenuItemGtk.h"
 #include "WebKitContextMenu.h"
 #include "WebKitPrivate.h"
 
 WebKitContextMenu* webkitContextMenuCreate(const Vector<WebKit::WebContextMenuItemData>&);
-WebKitContextMenu* webkitContextMenuCreate(const Vector<WebCore::ContextMenuItem>&);
-void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebCore::ContextMenuItem>&);
+void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebKit::WebContextMenuItemGtk>&);
 void webkitContextMenuPopulate(WebKitContextMenu*, Vector<WebKit::WebContextMenuItemData>&);
 void webkitContextMenuSetParentItem(WebKitContextMenu*, WebKitContextMenuItem*);
 WebKitContextMenuItem* webkitContextMenuGetParentItem(WebKitContextMenu*);
index db40186..bc9ac3d 100644 (file)
@@ -2027,52 +2027,6 @@ void webkitWebViewRunFileChooserRequest(WebKitWebView* webView, WebKitFileChoose
     g_signal_emit(webView, signals[RUN_FILE_CHOOSER], 0, request, &returnValue);
 }
 
-static bool webkitWebViewShouldShowInputMethodsMenu(WebKitWebView* webView)
-{
-    GtkSettings* settings = gtk_widget_get_settings(GTK_WIDGET(webView));
-    if (!settings)
-        return true;
-
-    gboolean showInputMethodMenu;
-    g_object_get(settings, "gtk-show-input-method-menu", &showInputMethodMenu, NULL);
-    return showInputMethodMenu;
-}
-
-static int getUnicodeMenuItemPosition(WebKitContextMenu* contextMenu)
-{
-    GList* items = webkit_context_menu_get_items(contextMenu);
-    GList* iter;
-    int i = 0;
-    for (iter = items, i = 0; iter; iter = g_list_next(iter), ++i) {
-        WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(iter->data);
-
-        if (webkit_context_menu_item_is_separator(item))
-            continue;
-        if (webkit_context_menu_item_get_stock_action(item) == WEBKIT_CONTEXT_MENU_ACTION_UNICODE)
-            return i;
-    }
-    return -1;
-}
-
-static void webkitWebViewCreateAndAppendInputMethodsMenuItem(WebKitWebView* webView, WebKitContextMenu* contextMenu)
-{
-    if (!webkitWebViewShouldShowInputMethodsMenu(webView))
-        return;
-
-    // Place the im context menu item right before the unicode menu item
-    // if it's present.
-    int unicodeMenuItemPosition = getUnicodeMenuItemPosition(contextMenu);
-    if (unicodeMenuItemPosition == -1)
-        webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator());
-
-    GtkIMContext* imContext = webkitWebViewBaseGetIMContext(WEBKIT_WEB_VIEW_BASE(webView));
-    GtkMenu* imContextMenu = GTK_MENU(gtk_menu_new());
-    gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(imContext), GTK_MENU_SHELL(imContextMenu));
-    WebKitContextMenuItem* menuItem = webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
-    webkitContextMenuItemSetSubMenuFromGtkMenu(menuItem, imContextMenu);
-    webkit_context_menu_insert(contextMenu, menuItem, unicodeMenuItemPosition);
-}
-
 static void contextMenuDismissed(GtkMenuShell*, WebKitWebView* webView)
 {
     g_signal_emit(webView, signals[CONTEXT_MENU_DISMISSED], 0, NULL);
@@ -2085,21 +2039,17 @@ void webkitWebViewPopulateContextMenu(WebKitWebView* webView, const Vector<WebCo
     ASSERT(contextMenuProxy);
 
     GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(proposedMenu));
-    if (hitTestResultData.isContentEditable)
-        webkitWebViewCreateAndAppendInputMethodsMenuItem(webView, contextMenu.get());
-
-    GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(hitTestResultData));
-    GUniquePtr<GdkEvent> contextMenuEvent(webkitWebViewBaseTakeContextMenuEvent(webViewBase));
-
     if (userData)
         webkit_context_menu_set_user_data(WEBKIT_CONTEXT_MENU(contextMenu.get()), userData);
 
+    GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(hitTestResultData));
+    GUniquePtr<GdkEvent> contextMenuEvent(webkitWebViewBaseTakeContextMenuEvent(webViewBase));
     gboolean returnValue;
     g_signal_emit(webView, signals[CONTEXT_MENU], 0, contextMenu.get(), contextMenuEvent.get(), hitTestResult.get(), &returnValue);
     if (returnValue)
         return;
 
-    Vector<ContextMenuItem> contextMenuItems;
+    Vector<WebContextMenuItemGtk> contextMenuItems;
     webkitContextMenuPopulate(contextMenu.get(), contextMenuItems);
     contextMenuProxy->populate(contextMenuItems);
 
index 5001d19..23acbed 100644 (file)
@@ -49,8 +49,8 @@ namespace WebKit {
 static void contextMenuItemActivatedCallback(GtkAction* action, WebPageProxy* page)
 {
     gboolean isToggle = GTK_IS_TOGGLE_ACTION(action);
-    WebKit::WebContextMenuItemData item(isToggle ? WebCore::CheckableActionType : WebCore::ActionType,
-        static_cast<WebCore::ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), gContextMenuActionId))),
+    WebContextMenuItemData item(isToggle ? CheckableActionType : ActionType,
+        static_cast<ContextMenuAction>(GPOINTER_TO_INT(g_object_get_data(G_OBJECT(action), gContextMenuActionId))),
         String::fromUTF8(gtk_action_get_label(action)), gtk_action_get_sensitive(action),
         isToggle ? gtk_toggle_action_get_active(GTK_TOGGLE_ACTION(action)) : false);
     page->contextMenuItemSelected(item);
@@ -85,59 +85,73 @@ static void contextMenuItemVisibilityChanged(GtkAction*, GParamSpec*, WebContext
         gtk_widget_hide(lastItemVisibleSeparator);
 }
 
-void WebContextMenuProxyGtk::append(ContextMenuItem& menuItem)
+void WebContextMenuProxyGtk::append(GtkMenu* menu, const WebContextMenuItemGtk& menuItem)
 {
     unsigned long signalHandlerId;
-    GtkAction* action = menuItem.gtkAction();
-    if (action) {
+    GtkWidget* gtkMenuItem;
+    if (GtkAction* action = menuItem.gtkAction()) {
+        gtkMenuItem = gtk_action_create_menu_item(action);
+
         switch (menuItem.type()) {
         case ActionType:
         case CheckableActionType:
             g_object_set_data(G_OBJECT(action), gContextMenuActionId, GINT_TO_POINTER(menuItem.action()));
             signalHandlerId = g_signal_connect(action, "activate", G_CALLBACK(contextMenuItemActivatedCallback), m_page);
             m_signalHandlers.set(signalHandlerId, action);
-            // Fall through.
-        case SubmenuType:
             signalHandlerId = g_signal_connect(action, "notify::visible", G_CALLBACK(contextMenuItemVisibilityChanged), this);
             m_signalHandlers.set(signalHandlerId, action);
             break;
+        case SubmenuType: {
+            signalHandlerId = g_signal_connect(action, "notify::visible", G_CALLBACK(contextMenuItemVisibilityChanged), this);
+            m_signalHandlers.set(signalHandlerId, action);
+            GtkMenu* submenu = GTK_MENU(gtk_menu_new());
+            for (const auto& item : menuItem.submenuItems())
+                append(submenu, item);
+            gtk_menu_item_set_submenu(GTK_MENU_ITEM(gtkMenuItem), GTK_WIDGET(submenu));
+            break;
+        }
         case SeparatorType:
+            ASSERT_NOT_REACHED();
             break;
         }
+    } else {
+        ASSERT(menuItem.type() == SeparatorType);
+        gtkMenuItem = gtk_separator_menu_item_new();
     }
 
-    m_menu.appendItem(menuItem);
+    gtk_menu_shell_append(GTK_MENU_SHELL(menu), gtkMenuItem);
+    gtk_widget_show(gtkMenuItem);
 }
 
 // Populate the context menu ensuring that:
 //  - There aren't separators next to each other.
 //  - There aren't separators at the beginning of the menu.
 //  - There aren't separators at the end of the menu.
-void WebContextMenuProxyGtk::populate(Vector<ContextMenuItem>& items)
+void WebContextMenuProxyGtk::populate(Vector<WebContextMenuItemGtk>& items)
 {
     bool previousIsSeparator = false;
     bool isEmpty = true;
     for (size_t i = 0; i < items.size(); i++) {
-        ContextMenuItem& menuItem = items.at(i);
+        WebContextMenuItemGtk& menuItem = items.at(i);
         if (menuItem.type() == SeparatorType) {
             previousIsSeparator = true;
             continue;
         }
 
         if (previousIsSeparator && !isEmpty)
-            append(items.at(i - 1));
+            append(m_menu, items.at(i - 1));
         previousIsSeparator = false;
 
-        append(menuItem);
+        append(m_menu, menuItem);
         isEmpty = false;
     }
 }
 
 void WebContextMenuProxyGtk::populate(const Vector<RefPtr<WebContextMenuItem>>& items)
 {
-    for (size_t i = 0; i < items.size(); i++) {
-        ContextMenuItem menuitem = items.at(i)->data().core();
-        append(menuitem);
+    for (const auto& item : items) {
+        WebContextMenuItemGtk menuitem(item->data());
+        append(m_menu, menuitem);
     }
 }
 
@@ -160,7 +174,9 @@ void WebContextMenuProxyGtk::show()
     if (!items.isEmpty())
         populate(items);
 
-    if (!m_menu.itemCount())
+    unsigned childCount = 0;
+    gtk_container_foreach(GTK_CONTAINER(m_menu), [](GtkWidget*, gpointer data) { (*static_cast<unsigned*>(data))++; }, &childCount);
+    if (!childCount)
         return;
 
     m_popupPosition = convertWidgetPointToScreenPoint(m_webView, m_context.menuLocation());
@@ -168,8 +184,8 @@ void WebContextMenuProxyGtk::show()
     // Display menu initiated by right click (mouse button pressed = 3).
     NativeWebMouseEvent* mouseEvent = m_page->currentlyProcessedMouseDownEvent();
     const GdkEvent* event = mouseEvent ? mouseEvent->nativeEvent() : 0;
-    gtk_menu_attach_to_widget(m_menu.platformDescription(), GTK_WIDGET(m_webView), 0);
-    gtk_menu_popup(m_menu.platformDescription(), 0, 0, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this,
+    gtk_menu_attach_to_widget(m_menu, GTK_WIDGET(m_webView), nullptr);
+    gtk_menu_popup(m_menu, nullptr, nullptr, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this,
                    event ? event->button.button : 3, event ? event->button.time : GDK_CURRENT_TIME);
 }
 
@@ -177,19 +193,20 @@ WebContextMenuProxyGtk::WebContextMenuProxyGtk(GtkWidget* webView, WebPageProxy&
     : WebContextMenuProxy(context, userData)
     , m_webView(webView)
     , m_page(&page)
+    , m_menu(GTK_MENU(gtk_menu_new()))
 {
     webkitWebViewBaseSetActiveContextMenuProxy(WEBKIT_WEB_VIEW_BASE(m_webView), this);
 }
 
 WebContextMenuProxyGtk::~WebContextMenuProxyGtk()
 {
-    gtk_menu_popdown(m_menu.platformDescription());
+    gtk_menu_popdown(m_menu);
 
     for (auto& handler : m_signalHandlers)
         g_signal_handler_disconnect(handler.value, handler.key);
     m_signalHandlers.clear();
 
-    m_menu.setPlatformDescription(nullptr);
+    gtk_widget_destroy(GTK_WIDGET(m_menu));
 }
 
 void WebContextMenuProxyGtk::menuPositionFunction(GtkMenu* menu, gint* x, gint* y, gboolean* pushIn, WebContextMenuProxyGtk* popupMenu)
index 8f3bb8a..9c8893e 100644 (file)
@@ -28,8 +28,8 @@
 
 #if ENABLE(CONTEXT_MENUS)
 
+#include "WebContextMenuItemGtk.h"
 #include "WebContextMenuProxy.h"
-#include <WebCore/ContextMenu.h>
 #include <WebCore/IntPoint.h>
 #include <wtf/HashMap.h>
 
@@ -44,18 +44,18 @@ public:
     WebContextMenuProxyGtk(GtkWidget*, WebPageProxy&, const ContextMenuContextData&, const UserData&);
     ~WebContextMenuProxyGtk();
 
-    void populate(Vector<WebCore::ContextMenuItem>&);
-    GtkMenu* gtkMenu() const { return m_menu.platformDescription(); }
+    void populate(Vector<WebContextMenuItemGtk>&);
+    GtkMenu* gtkMenu() const { return m_menu; }
 
 private:
     virtual void show() override;
-    void append(WebCore::ContextMenuItem&);
+    void append(GtkMenu*, const WebContextMenuItemGtk&);
     void populate(const Vector<RefPtr<WebContextMenuItem>>&);
     static void menuPositionFunction(GtkMenu*, gint*, gint*, gboolean*, WebContextMenuProxyGtk*);
 
     GtkWidget* m_webView;
     WebPageProxy* m_page;
-    WebCore::ContextMenu m_menu;
+    GtkMenu* m_menu;
     WebCore::IntPoint m_popupPosition;
     HashMap<unsigned long, GtkAction*> m_signalHandlers;
 };
index 0931cbf..f5fa107 100644 (file)
@@ -264,7 +264,7 @@ public:
 private:
     bool getCustomMenuFromDefaultItems(WebPage&, const WebCore::HitTestResult& hitTestResult, const Vector<WebCore::ContextMenuItem>& defaultMenu, Vector<WebContextMenuItemData>& newMenu, RefPtr<API::Object>& userData) override
     {
-        GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(defaultMenu));
+        GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(kitItems(defaultMenu)));
         GRefPtr<WebKitWebHitTestResult> webHitTestResult = adoptGRef(webkitWebHitTestResultCreate(hitTestResult));
         gboolean returnValue;
         g_signal_emit(m_webPage, signals[CONTEXT_MENU], 0, contextMenu.get(), webHitTestResult.get(), &returnValue);
index cceb4a9..8c24f57 100644 (file)
@@ -1,3 +1,14 @@
+2015-11-10  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        [GTK] Use CROSS_PLATFORM_CONTEXT_MENUS
+        https://bugs.webkit.org/show_bug.cgi?id=150642
+
+        Reviewed by Martin Robinson.
+
+        Remove test for input methods submenu.
+
+        * TestWebKitAPI/Tests/WebKit2Gtk/TestContextMenu.cpp:
+
 2015-11-09  Joonghun Park  <jh718.park@samsung.com>
 
         Unreviewed, add myself to the committers list.
index f2f0d6a..e08ec79 100644 (file)
@@ -93,17 +93,6 @@ public:
         return 0;
     }
 
-    bool shouldShowInputMethodsMenu()
-    {
-        GtkSettings* settings = gtk_widget_get_settings(GTK_WIDGET(m_webView));
-        if (!settings)
-            return true;
-
-        gboolean showInputMethodMenu;
-        g_object_get(settings, "gtk-show-input-method-menu", &showInputMethodMenu, NULL);
-        return showInputMethodMenu;
-    }
-
     void checkActionState(GtkAction* action, unsigned state)
     {
         if (state & Visible)
@@ -348,8 +337,6 @@ public:
             iter = checkCurrentItemIsSeparatorAndGetNext(iter);
             iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL, Visible | Enabled);
             iter = checkCurrentItemIsSeparatorAndGetNext(iter);
-            if (shouldShowInputMethodsMenu())
-                iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS, Visible | Enabled);
             iter = checkCurrentItemIsStockActionAndGetNext(iter, WEBKIT_CONTEXT_MENU_ACTION_UNICODE, Visible | Enabled);
             break;
         case Selection: