Changeset 121093 in webkit


Ignore:
Timestamp:
Jun 23, 2012 3:55:05 AM (12 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] Add ContextMenu API to WebKit2 GTK+ API
https://bugs.webkit.org/show_bug.cgi?id=81011

Reviewed by Martin Robinson.

Add WebKitWebView::context-menu signal and WebKitContextMenu and
WebKitContextMenuItem objects to customize the default menu or
buils new menus.

  • GNUmakefile.list.am: Add new files to destination.
  • UIProcess/API/gtk/WebKitContextMenu.cpp: Added.

(webkitContextMenuFinalize):
(webkit_context_menu_init):
(webkit_context_menu_class_init):
(webkitContextMenuPopulate): Populate the given vector of
ContextMenuItems with the WebKitContextMenu items releasing the
items added to the vector.
(webkitContextMenuCreate): Create a new WebKitContextMenu for the
given WKArrayRef of WKContextMenuItemRef.
(webkitContextMenuSetParentItem): Set the parent menu item of the
menu. Used when a menu is added as a submenu of a menu item.
(webkitContextMenuGetParentItem): Return the parent menu item of
the menu.
(webkit_context_menu_new): Create a new WebKitContextMenu.
(webkit_context_menu_new_with_items): Create a new
WebKitContextMenu using the given list of WebKitContextMenuItem.
(webkit_context_menu_prepend): Add item at the beginning.
(webkit_context_menu_append): Add item at the end.
(webkit_context_menu_insert): Insert item at a random position.
(webkit_context_menu_move_item): Move an existing item to a new
position.
(webkit_context_menu_get_items): Get the list of items.
(webkit_context_menu_get_n_items): Get the number of items.
(webkit_context_menu_first): Get the first item.
(webkit_context_menu_last): Get the last item.
(webkit_context_menu_get_item_at_position): Get the item at the
given position.
(webkit_context_menu_remove): Remove the given item.
(webkit_context_menu_remove_all): Remove all items.

  • UIProcess/API/gtk/WebKitContextMenu.h: Added.
  • UIProcess/API/gtk/WebKitContextMenuActions.cpp: Added.

(webkitContextMenuActionIsCheckable): Check if the given stock
action is a toggle action.
(webkitContextMenuActionGetActionTag): Get the WebCore
ContextMenuAction corresponding to the given stock action.
(webkitContextMenuActionGetForContextMenuItem): Get the stock
action corresponding to the given WebCore ContextMenuAction.
(webkitContextMenuActionGetLabel): Get the label string of the
given stock action.

  • UIProcess/API/gtk/WebKitContextMenuActions.h: Added.
  • UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h: Added.
  • UIProcess/API/gtk/WebKitContextMenuItem.cpp: Added.

(webkitContextMenuItemFinalize):
(webkit_context_menu_item_init):
(webkit_context_menu_item_class_init):
(checkAndWarnIfMenuHasParentItem): Check whether the given menu
is already inside another menu showing a warning in such case.
(webkitContextMenuItemSetSubMenu): Set the submenu of a menu item,
checking that the menu is not part of another menu and setting the
item as the parent of the submenu.
(webkitContextMenuItemCreate): Create a new WebKitContextMenuItem
for the given WKContextMenuItemRef.
(webkitContextMenuItemCreateForGtkItem): Create a new
WebKitContextMenuItem using the given GtkMenuItem.
(webkitContextMenuItemSetSubMenuFromGtkMenu): Set the given
GtkMenu as submenu of the item. This is used only to add Input
Methods submenu that is created by GTK.
(webkitContextMenuItemRelease): Release the WebCore
ContextMenuItem associated to the item.
(webkit_context_menu_item_new): Create a new WebKitContextMenuItem
for the given GtkAction.
(webkit_context_menu_item_new_from_stock_action): Create a new
WebKitContextMenuItem for a stock action.
(webkit_context_menu_item_new_from_stock_action_with_label):
Create a new WebKitContextMenuItem for a stock action using a
custom label.
(webkit_context_menu_item_new_with_submenu): Create a new
WebKitContextMenuItem with a submenu.
(webkit_context_menu_item_new_separator): Create a new separator
menu item.
(webkit_context_menu_item_get_action): Get the GtkAction of the item.
(webkit_context_menu_item_get_stock_action): Get the stock action
of the item.
(webkit_context_menu_item_is_separator): Whether item is a separator.
(webkit_context_menu_item_set_submenu): Set or replace the
submenu of the item.
(webkit_context_menu_item_get_submenu): Get the submenu of the item.

  • UIProcess/API/gtk/WebKitContextMenuItem.h: Added.
  • UIProcess/API/gtk/WebKitContextMenuItemPrivate.h: Added.
  • UIProcess/API/gtk/WebKitContextMenuPrivate.h: Added.
  • UIProcess/API/gtk/WebKitDefines.h:
  • UIProcess/API/gtk/WebKitWebView.cpp:

(webkit_web_view_class_init): Add WebKitWebView::context-menu signal.
(getUnicodeMenuItemPosition): Helper function that returns the
position of the unicode menu item in the proposed context menu.
(webkitWebViewCreateAndAppendInputMethodsMenuItem): Use
WebKitContextMenu API to add the input methods submenu to the
default context menu.
(webkitWebViewPopulateContextMenu): Create a WebKitContextMenu for
the default context menu and emit WebKitWebView::context-menu
signal. Then populate the context menu proxy with the resulting
WebKitContextMenu.

  • UIProcess/API/gtk/WebKitWebView.h:
  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseButtonPressEvent): In case of right click save
the event to be used by context menu signal.
(webkitWebViewBaseTakeContextMenuEvent): Return and release the
saved button event.

  • UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
  • UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add sections for

WebKitContextMenu and WebKitContextMenuItem.

  • UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
  • UIProcess/API/gtk/docs/webkit2gtk.types: Add

webkit_context_menu_get_type and webkit_context_menu_item_get_type.

  • UIProcess/API/gtk/tests/GNUmakefile.am: Add new test for context menu.
  • UIProcess/API/gtk/tests/TestContextMenu.cpp: Added.

(testContextMenuDefaultMenu):
(testContextMenuPopulateMenu):
(testContextMenuCustomMenu):
(testContextMenuDisableMenu):
(testContextMenuSubMenu):
(beforeAll):
(afterAll):

  • UIProcess/API/gtk/tests/TestMain.h:

(Test::addLogFatalFlag): Add a log level flag to the mask of flags
causing the program to abort.
(Test::removeLogFatalFlag): Remove a log level flag to the mask of
flags causing the program to abort.

  • UIProcess/API/gtk/tests/WebViewTest.cpp:

(WebViewTest::quitMainLoop): Finish the main loop.
(WebViewTest::quitMainLoopAfterProcessingPendingEvents): Finish
the main loop when all pending events have been processed.
(quitMainLoopIdleCallback):
(WebViewTest::wait):

  • UIProcess/API/gtk/tests/WebViewTest.h:
  • UIProcess/API/gtk/webkit2.h: Include WebKitContextMenu.h,

WebKitContextMenuItem.h and WebKitContextMenuActions.h.

  • UIProcess/API/gtk/webkit2marshal.list:
  • UIProcess/gtk/WebContextMenuProxyGtk.cpp:

(WebKit::WebContextMenuProxyGtk::showContextMenu): Attach the
popup menu to the view widget before showing it.

Location:
trunk/Source/WebKit2
Files:
10 added
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r121083 r121093  
     12012-06-23  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] Add ContextMenu API to WebKit2 GTK+ API
     4        https://bugs.webkit.org/show_bug.cgi?id=81011
     5
     6        Reviewed by Martin Robinson.
     7
     8        Add WebKitWebView::context-menu signal and WebKitContextMenu and
     9        WebKitContextMenuItem objects to customize the default menu or
     10        buils new menus.
     11
     12        * GNUmakefile.list.am: Add new files to destination.
     13        * UIProcess/API/gtk/WebKitContextMenu.cpp: Added.
     14        (webkitContextMenuFinalize):
     15        (webkit_context_menu_init):
     16        (webkit_context_menu_class_init):
     17        (webkitContextMenuPopulate): Populate the given vector of
     18        ContextMenuItems with the WebKitContextMenu items releasing the
     19        items added to the vector.
     20        (webkitContextMenuCreate): Create a new WebKitContextMenu for the
     21        given WKArrayRef of WKContextMenuItemRef.
     22        (webkitContextMenuSetParentItem): Set the parent menu item of the
     23        menu. Used when a menu is added as a submenu of a menu item.
     24        (webkitContextMenuGetParentItem): Return the parent menu item of
     25        the menu.
     26        (webkit_context_menu_new): Create a new WebKitContextMenu.
     27        (webkit_context_menu_new_with_items): Create a new
     28        WebKitContextMenu using the given list of WebKitContextMenuItem.
     29        (webkit_context_menu_prepend): Add item at the beginning.
     30        (webkit_context_menu_append): Add item at the end.
     31        (webkit_context_menu_insert): Insert item at a random position.
     32        (webkit_context_menu_move_item): Move an existing item to a new
     33        position.
     34        (webkit_context_menu_get_items): Get the list of items.
     35        (webkit_context_menu_get_n_items): Get the number of items.
     36        (webkit_context_menu_first): Get the first item.
     37        (webkit_context_menu_last): Get the last item.
     38        (webkit_context_menu_get_item_at_position): Get the item at the
     39        given position.
     40        (webkit_context_menu_remove): Remove the given item.
     41        (webkit_context_menu_remove_all): Remove all items.
     42        * UIProcess/API/gtk/WebKitContextMenu.h: Added.
     43        * UIProcess/API/gtk/WebKitContextMenuActions.cpp: Added.
     44        (webkitContextMenuActionIsCheckable): Check if the given stock
     45        action is a toggle action.
     46        (webkitContextMenuActionGetActionTag): Get the WebCore
     47        ContextMenuAction corresponding to the given stock action.
     48        (webkitContextMenuActionGetForContextMenuItem): Get the stock
     49        action corresponding to the given WebCore ContextMenuAction.
     50        (webkitContextMenuActionGetLabel): Get the label string of the
     51        given stock action.
     52        * UIProcess/API/gtk/WebKitContextMenuActions.h: Added.
     53        * UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h: Added.
     54        * UIProcess/API/gtk/WebKitContextMenuItem.cpp: Added.
     55        (webkitContextMenuItemFinalize):
     56        (webkit_context_menu_item_init):
     57        (webkit_context_menu_item_class_init):
     58        (checkAndWarnIfMenuHasParentItem): Check whether the given menu
     59        is already inside another menu showing a warning in such case.
     60        (webkitContextMenuItemSetSubMenu): Set the submenu of a menu item,
     61        checking that the menu is not part of another menu and setting the
     62        item as the parent of the submenu.
     63        (webkitContextMenuItemCreate): Create a new WebKitContextMenuItem
     64        for the given WKContextMenuItemRef.
     65        (webkitContextMenuItemCreateForGtkItem): Create a new
     66        WebKitContextMenuItem using the given GtkMenuItem.
     67        (webkitContextMenuItemSetSubMenuFromGtkMenu): Set the given
     68        GtkMenu as submenu of the item. This is used only to add Input
     69        Methods submenu that is created by GTK.
     70        (webkitContextMenuItemRelease): Release the WebCore
     71        ContextMenuItem associated to the item.
     72        (webkit_context_menu_item_new): Create a new WebKitContextMenuItem
     73        for the given GtkAction.
     74        (webkit_context_menu_item_new_from_stock_action): Create a new
     75        WebKitContextMenuItem for a stock action.
     76        (webkit_context_menu_item_new_from_stock_action_with_label):
     77        Create a new WebKitContextMenuItem for a stock action using a
     78        custom label.
     79        (webkit_context_menu_item_new_with_submenu): Create a new
     80        WebKitContextMenuItem with a submenu.
     81        (webkit_context_menu_item_new_separator): Create a new separator
     82        menu item.
     83        (webkit_context_menu_item_get_action): Get the GtkAction of the item.
     84        (webkit_context_menu_item_get_stock_action): Get the stock action
     85        of the item.
     86        (webkit_context_menu_item_is_separator): Whether item is a separator.
     87        (webkit_context_menu_item_set_submenu): Set or replace the
     88        submenu of the item.
     89        (webkit_context_menu_item_get_submenu): Get the submenu of the item.
     90        * UIProcess/API/gtk/WebKitContextMenuItem.h: Added.
     91        * UIProcess/API/gtk/WebKitContextMenuItemPrivate.h: Added.
     92        * UIProcess/API/gtk/WebKitContextMenuPrivate.h: Added.
     93        * UIProcess/API/gtk/WebKitDefines.h:
     94        * UIProcess/API/gtk/WebKitWebView.cpp:
     95        (webkit_web_view_class_init): Add WebKitWebView::context-menu signal.
     96        (getUnicodeMenuItemPosition): Helper function that returns the
     97        position of the unicode menu item in the proposed context menu.
     98        (webkitWebViewCreateAndAppendInputMethodsMenuItem): Use
     99        WebKitContextMenu API to add the input methods submenu to the
     100        default context menu.
     101        (webkitWebViewPopulateContextMenu): Create a WebKitContextMenu for
     102        the default context menu and emit WebKitWebView::context-menu
     103        signal. Then populate the context menu proxy with the resulting
     104        WebKitContextMenu.
     105        * UIProcess/API/gtk/WebKitWebView.h:
     106        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     107        (webkitWebViewBaseButtonPressEvent): In case of right click save
     108        the event to be used by context menu signal.
     109        (webkitWebViewBaseTakeContextMenuEvent): Return and release the
     110        saved button event.
     111        * UIProcess/API/gtk/WebKitWebViewBasePrivate.h:
     112        * UIProcess/API/gtk/docs/webkit2gtk-docs.sgml: Add sections for
     113        WebKitContextMenu and WebKitContextMenuItem.
     114        * UIProcess/API/gtk/docs/webkit2gtk-sections.txt: Add new symbols.
     115        * UIProcess/API/gtk/docs/webkit2gtk.types: Add
     116        webkit_context_menu_get_type and webkit_context_menu_item_get_type.
     117        * UIProcess/API/gtk/tests/GNUmakefile.am: Add new test for context menu.
     118        * UIProcess/API/gtk/tests/TestContextMenu.cpp: Added.
     119        (testContextMenuDefaultMenu):
     120        (testContextMenuPopulateMenu):
     121        (testContextMenuCustomMenu):
     122        (testContextMenuDisableMenu):
     123        (testContextMenuSubMenu):
     124        (beforeAll):
     125        (afterAll):
     126        * UIProcess/API/gtk/tests/TestMain.h:
     127        (Test::addLogFatalFlag): Add a log level flag to the mask of flags
     128        causing the program to abort.
     129        (Test::removeLogFatalFlag): Remove a log level flag to the mask of
     130        flags causing the program to abort.
     131        * UIProcess/API/gtk/tests/WebViewTest.cpp:
     132        (WebViewTest::quitMainLoop): Finish the main loop.
     133        (WebViewTest::quitMainLoopAfterProcessingPendingEvents): Finish
     134        the main loop when all pending events have been processed.
     135        (quitMainLoopIdleCallback):
     136        (WebViewTest::wait):
     137        * UIProcess/API/gtk/tests/WebViewTest.h:
     138        * UIProcess/API/gtk/webkit2.h: Include WebKitContextMenu.h,
     139        WebKitContextMenuItem.h and WebKitContextMenuActions.h.
     140        * UIProcess/API/gtk/webkit2marshal.list:
     141        * UIProcess/gtk/WebContextMenuProxyGtk.cpp:
     142        (WebKit::WebContextMenuProxyGtk::showContextMenu): Attach the
     143        popup menu to the view widget before showing it.
     144
    11452012-06-22  Alexandru Chiculita  <achicu@adobe.com>
    2146
  • trunk/Source/WebKit2/GNUmakefile.list.am

    r120963 r121093  
    9090        $(WebKit2)/UIProcess/API/gtk/WebKitBackForwardList.h \
    9191        $(WebKit2)/UIProcess/API/gtk/WebKitBackForwardListItem.h \
     92        $(WebKit2)/UIProcess/API/gtk/WebKitContextMenu.h \
     93        $(WebKit2)/UIProcess/API/gtk/WebKitContextMenuActions.h \
     94        $(WebKit2)/UIProcess/API/gtk/WebKitContextMenuItem.h \
    9295        $(WebKit2)/UIProcess/API/gtk/WebKitCookieManager.h \
    9396        $(WebKit2)/UIProcess/API/gtk/WebKitDefines.h \
     
    579582        Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListItem.cpp \
    580583        Source/WebKit2/UIProcess/API/gtk/WebKitBackForwardListPrivate.h \
     584        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.cpp \
     585        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenu.h \
     586        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuPrivate.h \
     587        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.cpp \
     588        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActions.h \
     589        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuActionsPrivate.h \
    581590        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuClient.cpp \
    582591        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuClient.h \
     592        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.cpp \
     593        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItem.h \
     594        Source/WebKit2/UIProcess/API/gtk/WebKitContextMenuItemPrivate.h \
    583595        Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.h \
    584596        Source/WebKit2/UIProcess/API/gtk/WebKitCookieManager.cpp \
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitDefines.h

    r109329 r121093  
    3333#include <glib.h>
    3434
    35 typedef struct _WebKitPrintOperation WebKitPrintOperation;
    36 typedef struct _WebKitFindController WebKitFindController;
    37 typedef struct _WebKitWebView        WebKitWebView;
     35typedef struct _WebKitPrintOperation  WebKitPrintOperation;
     36typedef struct _WebKitFindController  WebKitFindController;
     37typedef struct _WebKitWebView         WebKitWebView;
     38typedef struct _WebKitContextMenu     WebKitContextMenu;
     39typedef struct _WebKitContextMenuItem WebKitContextMenuItem;
    3840
    3941#ifdef G_OS_WIN32
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.cpp

    r120908 r121093  
    2626#include "WebKitBackForwardListPrivate.h"
    2727#include "WebKitContextMenuClient.h"
     28#include "WebKitContextMenuItemPrivate.h"
     29#include "WebKitContextMenuPrivate.h"
    2830#include "WebKitEnumTypes.h"
    2931#include "WebKitError.h"
     
    5153#include <JavaScriptCore/APICast.h>
    5254#include <WebCore/DragIcon.h>
     55#include <WebCore/GOwnPtrGtk.h>
    5356#include <WebCore/GtkUtilities.h>
    5457#include <glib/gi18n-lib.h>
     
    8487
    8588    RUN_FILE_CHOOSER,
     89
     90    CONTEXT_MENU,
    8691
    8792    LAST_SIGNAL
     
    983988                     G_TYPE_BOOLEAN, 1, /* number of parameters */
    984989                     WEBKIT_TYPE_FILE_CHOOSER_REQUEST);
     990
     991    /**
     992     * WebKitWebView::context-menu:
     993     * @web_view: the #WebKitWebView on which the signal is emitted
     994     * @context_menu: the proposed #WebKitContextMenu
     995     * @event: the #GdkEvent that triggered the context menu
     996     * @hit_test_result: a #WebKitHitTestResult
     997     *
     998     * Emmited when a context menu is about to be displayed to give the application
     999     * a chance to customize the proposed menu, prevent the menu from being displayed
     1000     * or build its own context menu.
     1001     * <itemizedlist>
     1002     * <listitem><para>
     1003     *  To customize the proposed menu you can use webkit_context_menu_prepend(),
     1004     *  webkit_context_menu_append() or webkit_context_menu_insert() to add new
     1005     *  #WebKitContextMenuItem<!-- -->s to @context_menu, webkit_context_menu_move_item()
     1006     *  to reorder existing items, or webkit_context_menu_remove() to remove an
     1007     *  existing item. The signal handler should return %FALSE, and the menu represented
     1008     *  by @context_menu will be shown.
     1009     * </para></listitem>
     1010     * <listitem><para>
     1011     *  To prevent the menu from being displayed you can just connect to this signal
     1012     *  and return %TRUE so that the proposed menu will not be shown.
     1013     * </para></listitem>
     1014     * <listitem><para>
     1015     *  To build your own menu, you can remove all items from the proposed menu with
     1016     *  webkit_context_menu_remove_all(), add your own items and return %FALSE so
     1017     *  that the menu will be shown. You can also ignore the proposed #WebKitContextMenu,
     1018     *  build your own #GtkMenu and return %TRUE to prevent the proposed menu from being shown.
     1019     * </para></listitem>
     1020     * <listitem><para>
     1021     *  If you just want the default menu to be shown always, simply don't connect to this
     1022     *  signal because showing the proposed context menu is the default behaviour.
     1023     * </para></listitem>
     1024     * </itemizedlist>
     1025     *
     1026     * If the signal handler returns %FALSE the context menu represented by @context_menu
     1027     * will be shown, if it return %TRUE the context menu will not be shown.
     1028     *
     1029     * The proposed #WebKitContextMenu passed in @context_menu argument is only valid
     1030     * during the signal emission.
     1031     *
     1032     * Returns: %TRUE to stop other handlers from being invoked for the event.
     1033     *    %FALSE to propagate the event further.
     1034     */
     1035    signals[CONTEXT_MENU] =
     1036        g_signal_new("context-menu",
     1037                     G_TYPE_FROM_CLASS(webViewClass),
     1038                     G_SIGNAL_RUN_LAST,
     1039                     G_STRUCT_OFFSET(WebKitWebViewClass, context_menu),
     1040                     g_signal_accumulator_true_handled, 0,
     1041                     webkit_marshal_BOOLEAN__OBJECT_BOXED_OBJECT,
     1042                     G_TYPE_BOOLEAN, 3,
     1043                     WEBKIT_TYPE_CONTEXT_MENU,
     1044                     GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
     1045                     WEBKIT_TYPE_HIT_TEST_RESULT);
    9851046}
    9861047
     
    12321293}
    12331294
    1234 static void webkitWebViewCreateAndAppendDefaultMenuItems(WebKitWebView* webView, WKArrayRef wkProposedMenu, Vector<ContextMenuItem>& contextMenuItems)
    1235 {
    1236     for (size_t i = 0; i < WKArrayGetSize(wkProposedMenu); ++i) {
    1237         WKContextMenuItemRef wkItem = static_cast<WKContextMenuItemRef>(WKArrayGetItemAtIndex(wkProposedMenu, i));
    1238         contextMenuItems.append(toImpl(wkItem)->data()->core());
    1239     }
    1240 }
    1241 
    12421295static bool webkitWebViewShouldShowInputMethodsMenu(WebKitWebView* webView)
    12431296{
     
    12511304}
    12521305
    1253 static void webkitWebViewCreateAndAppendInputMethodsMenuItem(WebKitWebView* webView, Vector<ContextMenuItem>& contextMenuItems)
     1306static int getUnicodeMenuItemPosition(WebKitContextMenu* contextMenu)
     1307{
     1308    GList* items = webkit_context_menu_get_items(contextMenu);
     1309    GList* iter;
     1310    int i = 0;
     1311    for (iter = items, i = 0; iter; iter = g_list_next(iter), ++i) {
     1312        WebKitContextMenuItem* item = WEBKIT_CONTEXT_MENU_ITEM(iter->data);
     1313
     1314        if (webkit_context_menu_item_is_separator(item))
     1315            continue;
     1316        if (webkit_context_menu_item_get_stock_action(item) == WEBKIT_CONTEXT_MENU_ACTION_UNICODE)
     1317            return i;
     1318    }
     1319    return -1;
     1320}
     1321
     1322static void webkitWebViewCreateAndAppendInputMethodsMenuItem(WebKitWebView* webView, WebKitContextMenu* contextMenu)
    12541323{
    12551324    if (!webkitWebViewShouldShowInputMethodsMenu(webView))
    12561325        return;
     1326
     1327    // Place the im context menu item right before the unicode menu item
     1328    // if it's present.
     1329    int unicodeMenuItemPosition = getUnicodeMenuItemPosition(contextMenu);
     1330    if (unicodeMenuItemPosition == -1)
     1331        webkit_context_menu_append(contextMenu, webkit_context_menu_item_new_separator());
    12571332
    12581333    GtkIMContext* imContext = webkitWebViewBaseGetIMContext(WEBKIT_WEB_VIEW_BASE(webView));
    12591334    GtkMenu* imContextMenu = GTK_MENU(gtk_menu_new());
    12601335    gtk_im_multicontext_append_menuitems(GTK_IM_MULTICONTEXT(imContext), GTK_MENU_SHELL(imContextMenu));
    1261     ContextMenu subMenu(imContextMenu);
    1262 
    1263     ContextMenuItem separator(SeparatorType, ContextMenuItemTagNoAction, String());
    1264     contextMenuItems.append(separator);
    1265     ContextMenuItem menuItem(SubmenuType, ContextMenuItemTagNoAction, _("Input _Methods"), &subMenu);
    1266     contextMenuItems.append(menuItem);
     1336    WebKitContextMenuItem* menuItem = webkit_context_menu_item_new_from_stock_action(WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS);
     1337    webkitContextMenuItemSetSubMenuFromGtkMenu(menuItem, imContextMenu);
     1338    webkit_context_menu_insert(contextMenu, menuItem, unicodeMenuItemPosition);
    12671339}
    12681340
    12691341void webkitWebViewPopulateContextMenu(WebKitWebView* webView, WKArrayRef wkProposedMenu, WKHitTestResultRef wkHitTestResult)
    12701342{
    1271     WebContextMenuProxyGtk* contextMenu = webkitWebViewBaseGetActiveContextMenuProxy(WEBKIT_WEB_VIEW_BASE(webView));
     1343    WebKitWebViewBase* webViewBase = WEBKIT_WEB_VIEW_BASE(webView);
     1344    WebContextMenuProxyGtk* contextMenuProxy = webkitWebViewBaseGetActiveContextMenuProxy(webViewBase);
    12721345    ASSERT(contextMenu);
    12731346
     1347    GRefPtr<WebKitContextMenu> contextMenu = adoptGRef(webkitContextMenuCreate(wkProposedMenu));
     1348    if (WKHitTestResultIsContentEditable(wkHitTestResult))
     1349        webkitWebViewCreateAndAppendInputMethodsMenuItem(webView, contextMenu.get());
     1350
     1351    GRefPtr<WebKitHitTestResult> hitTestResult = adoptGRef(webkitHitTestResultCreate(wkHitTestResult));
     1352    GOwnPtr<GdkEvent> contextMenuEvent(webkitWebViewBaseTakeContextMenuEvent(webViewBase));
     1353
     1354    gboolean returnValue;
     1355    g_signal_emit(webView, signals[CONTEXT_MENU], 0, contextMenu.get(), contextMenuEvent.get(), hitTestResult.get(), &returnValue);
     1356    if (returnValue)
     1357        return;
     1358
    12741359    Vector<ContextMenuItem> contextMenuItems;
    1275     webkitWebViewCreateAndAppendDefaultMenuItems(webView, wkProposedMenu, contextMenuItems);
    1276     if (WKHitTestResultIsContentEditable(wkHitTestResult))
    1277         webkitWebViewCreateAndAppendInputMethodsMenuItem(webView, contextMenuItems);
    1278 
    1279     contextMenu->populate(contextMenuItems);
     1360    webkitContextMenuPopulate(contextMenu.get(), contextMenuItems);
     1361    contextMenuProxy->populate(contextMenuItems);
     1362
     1363    // Clear the menu to make sure it's useless after signal emission.
     1364    webkit_context_menu_remove_all(contextMenu.get());
    12801365}
    12811366
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebView.h

    r120908 r121093  
    160160    gboolean   (* run_file_chooser)      (WebKitWebView             *web_view,
    161161                                          WebKitFileChooserRequest  *request);
     162    gboolean   (* context_menu)         (WebKitWebView              *web_view,
     163                                         WebKitContextMenu          *context_menu,
     164                                         GdkEvent                   *event,
     165                                         WebKitHitTestResult        *hit_test_result);
    162166
    163167    /* Padding for future expansion */
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r120305 r121093  
    4747#include <WebCore/DragData.h>
    4848#include <WebCore/DragIcon.h>
     49#include <WebCore/GOwnPtrGtk.h>
    4950#include <WebCore/GtkClickCounter.h>
    5051#include <WebCore/GtkDragAndDropHelper.h>
     
    9596    GtkWidget* inspectorView;
    9697    unsigned inspectorViewHeight;
     98    GOwnPtr<GdkEvent> contextMenuEvent;
    9799    WebContextMenuProxyGtk* activeContextMenuProxy;
    98100};
     
    449451    if (!priv->clickCounter.shouldProcessButtonEvent(buttonEvent))
    450452        return TRUE;
     453
     454    // If it's a right click event save it as a possible context menu event.
     455    if (buttonEvent->button == 3)
     456        priv->contextMenuEvent.set(gdk_event_copy(reinterpret_cast<GdkEvent*>(buttonEvent)));
    451457    priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(reinterpret_cast<GdkEvent*>(buttonEvent),
    452458                                                     priv->clickCounter.clickCountForGdkButtonEvent(widget, buttonEvent)));
     
    785791    return webkitWebViewBase->priv->activeContextMenuProxy;
    786792}
     793
     794GdkEvent* webkitWebViewBaseTakeContextMenuEvent(WebKitWebViewBase* webkitWebViewBase)
     795{
     796    return webkitWebViewBase->priv->contextMenuEvent.release();
     797}
  • trunk/Source/WebKit2/UIProcess/API/gtk/WebKitWebViewBasePrivate.h

    r120305 r121093  
    5050void webkitWebViewBaseSetActiveContextMenuProxy(WebKitWebViewBase*, WebContextMenuProxyGtk*);
    5151WebContextMenuProxyGtk* webkitWebViewBaseGetActiveContextMenuProxy(WebKitWebViewBase*);
     52GdkEvent* webkitWebViewBaseTakeContextMenuEvent(WebKitWebViewBase*);
    5253
    5354#endif // WebKitWebViewBasePrivate_h
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-docs.sgml

    r119837 r121093  
    3838    <xi:include href="xml/WebKitURISchemeRequest.xml"/>
    3939    <xi:include href="xml/WebKitVersion.xml"/>
     40    <xi:include href="xml/WebKitContextMenu.xml"/>
     41    <xi:include href="xml/WebKitContextMenuItem.xml"/>
    4042  </chapter>
    4143
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk-sections.txt

    r120908 r121093  
    747747WEBKIT_CHECK_VERSION
    748748</SECTION>
     749
     750<SECTION>
     751<FILE>WebKitContextMenu</FILE>
     752WebKitContextMenu
     753webkit_context_menu_new
     754webkit_context_menu_new_with_items
     755webkit_context_menu_prepend
     756webkit_context_menu_append
     757webkit_context_menu_insert
     758webkit_context_menu_move_item
     759webkit_context_menu_get_items
     760webkit_context_menu_get_n_items
     761webkit_context_menu_first
     762webkit_context_menu_last
     763webkit_context_menu_get_item_at_position
     764webkit_context_menu_remove
     765webkit_context_menu_remove_all
     766
     767<SUBSECTION Standard>
     768WebKitContextMenuClass
     769WEBKIT_TYPE_CONTEXT_MENU
     770WEBKIT_CONTEXT_MENU
     771WEBKIT_IS_CONTEXT_MENU
     772WEBKIT_CONTEXT_MENU_CLASS
     773WEBKIT_IS_CONTEXT_MENU_CLASS
     774WEBKIT_CONTEXT_MENU_GET_CLASS
     775
     776<SUBSECTION Private>
     777WebKitContextMenuPrivate
     778webkit_context_menu_get_type
     779</SECTION>
     780
     781<SECTION>
     782<FILE>WebKitContextMenuItem</FILE>
     783WebKitContextMenuItem
     784WebKitContextMenuAction
     785webkit_context_menu_item_new
     786webkit_context_menu_item_new_from_stock_action
     787webkit_context_menu_item_new_from_stock_action_with_label
     788webkit_context_menu_item_new_with_submenu
     789webkit_context_menu_item_new_separator
     790webkit_context_menu_item_get_action
     791webkit_context_menu_item_get_stock_action
     792webkit_context_menu_item_is_separator
     793webkit_context_menu_item_set_submenu
     794webkit_context_menu_item_get_submenu
     795
     796<SUBSECTION Standard>
     797WebKitContextMenuItemClass
     798WEBKIT_TYPE_CONTEXT_MENU_ITEM
     799WEBKIT_CONTEXT_MENU_ITEM
     800WEBKIT_IS_CONTEXT_MENU_ITEM
     801WEBKIT_CONTEXT_MENU_ITEM_CLASS
     802WEBKIT_IS_CONTEXT_MENU_ITEM_CLASS
     803WEBKIT_CONTEXT_MENU_ITEM_GET_CLASS
     804
     805<SUBSECTION Private>
     806WebKitContextMenuItemPrivate
     807webkit_context_menu_item_get_type
     808</SECTION>
  • trunk/Source/WebKit2/UIProcess/API/gtk/docs/webkit2gtk.types

    r119700 r121093  
    2020webkit_web_inspector_get_type
    2121webkit_uri_scheme_request_get_type
     22webkit_context_menu_get_type
     23webkit_context_menu_item_get_type
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/GNUmakefile.am

    r119837 r121093  
    33TEST_PROGS += \
    44        Programs/WebKit2APITests/TestBackForwardList \
     5        Programs/WebKit2APITests/TestContextMenu \
    56        Programs/WebKit2APITests/TestCookieManager \
    67        Programs/WebKit2APITests/TestDownloads \
     
    168169Programs_WebKit2APITests_TestWebKitVersion_LDFLAGS = $(webkit2_tests_ldflags)
    169170
     171Programs_WebKit2APITests_TestContextMenu_SOURCES = \
     172        Source/WebKit2/UIProcess/API/gtk/tests/TestContextMenu.cpp
     173Programs_WebKit2APITests_TestContextMenu_CPPFLAGS = $(webkit2_tests_cppflags)
     174Programs_WebKit2APITests_TestContextMenu_LDADD = $(webkit2_tests_ldadd)
     175Programs_WebKit2APITests_TestContextMenu_LDFLAGS = $(webkit2_tests_ldflags)
     176
    170177endif # ENABLE_WEBKIT2
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/TestMain.h

    r112221 r121093  
    7676    }
    7777
     78    void addLogFatalFlag(unsigned flag)
     79    {
     80        unsigned fatalMask = g_log_set_always_fatal(static_cast<GLogLevelFlags>(G_LOG_FATAL_MASK));
     81        fatalMask |= flag;
     82        g_log_set_always_fatal(static_cast<GLogLevelFlags>(fatalMask));
     83    }
     84
     85    void removeLogFatalFlag(unsigned flag)
     86    {
     87        unsigned fatalMask = g_log_set_always_fatal(static_cast<GLogLevelFlags>(G_LOG_FATAL_MASK));
     88        fatalMask &= ~flag;
     89        g_log_set_always_fatal(static_cast<GLogLevelFlags>(fatalMask));
     90    }
     91
    7892    HashSet<GObject*> m_watchedObjects;
    7993};
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.cpp

    r118146 r121093  
    4444}
    4545
    46 static gboolean testLoadTimeoutFinishLoop(GMainLoop* loop)
    47 {
    48     g_main_loop_quit(loop);
    49     return FALSE;
    50 }
    51 
    5246void WebViewTest::loadURI(const char* uri)
    5347{
     
    113107}
    114108
     109void WebViewTest::quitMainLoop()
     110{
     111    g_main_loop_quit(m_mainLoop);
     112}
     113
     114void WebViewTest::quitMainLoopAfterProcessingPendingEvents()
     115{
     116    while (gtk_events_pending())
     117        gtk_main_iteration();
     118    quitMainLoop();
     119}
     120
     121static gboolean quitMainLoopIdleCallback(WebViewTest* test)
     122{
     123    test->quitMainLoop();
     124    return FALSE;
     125}
     126
    115127void WebViewTest::wait(double seconds)
    116128{
    117     g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(testLoadTimeoutFinishLoop), m_mainLoop);
     129    g_timeout_add_seconds(seconds, reinterpret_cast<GSourceFunc>(quitMainLoopIdleCallback), m_mainLoop);
    118130    g_main_loop_run(m_mainLoop);
    119131}
  • trunk/Source/WebKit2/UIProcess/API/gtk/tests/WebViewTest.h

    r118146 r121093  
    4141    void goToBackForwardListItem(WebKitBackForwardListItem*);
    4242
     43    void quitMainLoop();
     44    void quitMainLoopAfterProcessingPendingEvents();
    4345    void wait(double seconds);
    4446    void waitUntilLoadFinished();
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2.h

    r119837 r121093  
    2626#include <webkit2/WebKitBackForwardList.h>
    2727#include <webkit2/WebKitBackForwardListItem.h>
     28#include <webkit2/WebKitContextMenu.h>
     29#include <webkit2/WebKitContextMenuActions.h>
     30#include <webkit2/WebKitContextMenuItem.h>
    2831#include <webkit2/WebKitCookieManager.h>
    2932#include <webkit2/WebKitDefines.h>
  • trunk/Source/WebKit2/UIProcess/API/gtk/webkit2marshal.list

    r113697 r121093  
    22BOOLEAN:ENUM,STRING,POINTER
    33BOOLEAN:OBJECT
     4BOOLEAN:OBJECT,BOXED,OBJECT
    45BOOLEAN:OBJECT,ENUM
    56BOOLEAN:STRING
  • trunk/Source/WebKit2/UIProcess/gtk/WebContextMenuProxyGtk.cpp

    r120305 r121093  
    9393    NativeWebMouseEvent* mouseEvent = m_page->currentlyProcessedMouseDownEvent();
    9494    const GdkEvent* event = mouseEvent ? mouseEvent->nativeEvent() : 0;
     95    gtk_menu_attach_to_widget(m_menu.platformDescription(), GTK_WIDGET(m_webView), 0);
    9596    gtk_menu_popup(m_menu.platformDescription(), 0, 0, reinterpret_cast<GtkMenuPositionFunc>(menuPositionFunction), this,
    9697                   event ? event->button.button : 3, event ? event->button.time : GDK_CURRENT_TIME);
Note: See TracChangeset for help on using the changeset viewer.