| Differences between
and this patch
- a/WebKit/gtk/ChangeLog +17 lines
Lines 1-3 a/WebKit/gtk/ChangeLog_sec1
1
2010-11-22  Carlos Garcia Campos  <cgarcia@igalia.com>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        [GTK] Add a signal to allow applications to handle its own context menu
6
        https://bugs.webkit.org/show_bug.cgi?id=49904
7
8
        * webkit/webkitwebview.cpp:
9
        (prepareMouseEventForFrame):
10
        (webkit_web_view_forward_context_menu_event):
11
        (webkit_web_view_popup_menu_handler):
12
        (webkit_web_view_button_press_event):
13
        (webkit_web_view_real_context_menu):
14
        (webkit_web_view_class_init):
15
        * webkit/webkitwebview.h:
16
        * webkitmarshal.list:
17
1
2010-11-18  Xan Lopez  <xlopez@igalia.com>
18
2010-11-18  Xan Lopez  <xlopez@igalia.com>
2
19
3
        Reviewed by Martin Robinson.
20
        Reviewed by Martin Robinson.
- a/WebKit/gtk/webkit/webkitwebview.cpp -8 / +70 lines
Lines 173-178 enum { a/WebKit/gtk/webkit/webkitwebview.cpp_sec1
173
    GEOLOCATION_POLICY_DECISION_CANCELLED,
173
    GEOLOCATION_POLICY_DECISION_CANCELLED,
174
    ONLOAD_EVENT,
174
    ONLOAD_EVENT,
175
    FRAME_CREATED,
175
    FRAME_CREATED,
176
    CONTEXT_MENU,
176
    LAST_SIGNAL
177
    LAST_SIGNAL
177
};
178
};
178
179
Lines 252-274 static Node* getFocusedNode(Frame* frame) a/WebKit/gtk/webkit/webkitwebview.cpp_sec2
252
    return 0;
253
    return 0;
253
}
254
}
254
255
255
static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webView, const PlatformMouseEvent& event)
256
static MouseEventWithHitTestResults prepareMouseEventForFrame(Frame* frame, const PlatformMouseEvent& event)
257
{
258
    HitTestRequest request(HitTestRequest::Active);
259
    IntPoint point = frame->view()->windowToContents(event.pos());
260
    return frame->document()->prepareMouseEvent(request, point, event);
261
}
262
263
static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webView, const PlatformMouseEvent& event, bool keyboardMode)
256
{
264
{
257
    Page* page = core(webView);
265
    Page* page = core(webView);
258
    page->contextMenuController()->clearContextMenu();
266
    page->contextMenuController()->clearContextMenu();
259
    Frame* focusedFrame;
267
    Frame* focusedFrame;
260
    Frame* mainFrame = page->mainFrame();
268
    Frame* mainFrame = page->mainFrame();
261
    gboolean mousePressEventResult = FALSE;
269
    gboolean mousePressEventResult = FALSE;
270
    WebKitHitTestResult* hitTestResult = 0;
262
271
263
    if (!mainFrame->view())
272
    if (!mainFrame->view())
264
        return FALSE;
273
        return FALSE;
265
274
266
    mainFrame->view()->setCursor(pointerCursor());
275
    mainFrame->view()->setCursor(pointerCursor());
267
    if (page->frameCount()) {
276
    if (page->frameCount()) {
268
        HitTestRequest request(HitTestRequest::Active);
277
        MouseEventWithHitTestResults mev = prepareMouseEventForFrame(mainFrame, event);
269
        IntPoint point = mainFrame->view()->windowToContents(event.pos());
270
        MouseEventWithHitTestResults mev = mainFrame->document()->prepareMouseEvent(request, point, event);
271
272
        Frame* targetFrame = EventHandler::subframeForTargetNode(mev.targetNode());
278
        Frame* targetFrame = EventHandler::subframeForTargetNode(mev.targetNode());
273
        if (!targetFrame)
279
        if (!targetFrame)
274
            targetFrame = mainFrame;
280
            targetFrame = mainFrame;
Lines 278-290 static gboolean webkit_web_view_forward_context_menu_event(WebKitWebView* webVie a/WebKit/gtk/webkit/webkitwebview.cpp_sec3
278
            page->focusController()->setFocusedFrame(targetFrame);
284
            page->focusController()->setFocusedFrame(targetFrame);
279
            focusedFrame = targetFrame;
285
            focusedFrame = targetFrame;
280
        }
286
        }
287
288
        if (focusedFrame == mainFrame)
289
            hitTestResult = kit(mev.hitTestResult());
281
    } else
290
    } else
282
        focusedFrame = mainFrame;
291
        focusedFrame = mainFrame;
283
292
293
    if (!hitTestResult) {
294
        MouseEventWithHitTestResults mev = prepareMouseEventForFrame(focusedFrame, event);
295
        hitTestResult = kit(mev.hitTestResult());
296
    }
297
298
    // Emit the context-menu signal
299
    gboolean handled;
300
    g_signal_emit(webView, webkit_web_view_signals[CONTEXT_MENU], 0, event.globalX(), event.globalY(), keyboardMode, hitTestResult, &handled);
301
    g_object_unref(hitTestResult);
302
    if (handled) {
303
        // User has already shown the menu.
304
        return TRUE;
305
    }
306
284
    if (focusedFrame->view() && focusedFrame->eventHandler()->handleMousePressEvent(event))
307
    if (focusedFrame->view() && focusedFrame->eventHandler()->handleMousePressEvent(event))
285
        mousePressEventResult = TRUE;
308
        mousePressEventResult = TRUE;
286
309
287
288
    bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(event);
310
    bool handledEvent = focusedFrame->eventHandler()->sendContextMenuEvent(event);
289
    if (!handledEvent)
311
    if (!handledEvent)
290
        return FALSE;
312
        return FALSE;
Lines 407-413 static gboolean webkit_web_view_popup_menu_handler(GtkWidget* widget) a/WebKit/gtk/webkit/webkitwebview.cpp_sec4
407
429
408
    PlatformMouseEvent event(location, global, RightButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());
430
    PlatformMouseEvent event(location, global, RightButton, MouseEventPressed, 0, false, false, false, false, gtk_get_current_event_time());
409
431
410
    return webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event);
432
    return webkit_web_view_forward_context_menu_event(WEBKIT_WEB_VIEW(widget), event, true);
411
}
433
}
412
434
413
#ifndef GTK_API_VERSION_2
435
#ifndef GTK_API_VERSION_2
Lines 803-809 static gboolean webkit_web_view_button_press_event(GtkWidget* widget, GdkEventBu a/WebKit/gtk/webkit/webkitwebview.cpp_sec5
803
    priv->previousClickTime = eventTime;
825
    priv->previousClickTime = eventTime;
804
826
805
    if (event->button == 3)
827
    if (event->button == 3)
806
        return webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event));
828
        return webkit_web_view_forward_context_menu_event(webView, PlatformMouseEvent(event), false);
807
829
808
    Frame* frame = core(webView)->mainFrame();
830
    Frame* frame = core(webView)->mainFrame();
809
    if (!frame->view())
831
    if (!frame->view())
Lines 1305-1310 static gboolean webkit_web_view_real_move_cursor (WebKitWebView* webView, GtkMov a/WebKit/gtk/webkit/webkitwebview.cpp_sec6
1305
    return true;
1327
    return true;
1306
}
1328
}
1307
1329
1330
static gboolean webkit_web_view_real_context_menu(WebKitWebView* webView, gint x, gint y, gboolean keyboardMode, WebKitHitTestResult* hitTestResult)
1331
{
1332
    return FALSE;
1333
}
1334
1308
static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView)
1335
static void webkit_web_view_real_paste_clipboard(WebKitWebView* webView)
1309
{
1336
{
1310
    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
1337
    Frame* frame = core(webView)->focusController()->focusedOrMainFrame();
Lines 2604-2609 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) a/WebKit/gtk/webkit/webkitwebview.cpp_sec7
2604
            WEBKIT_TYPE_WEB_FRAME);
2631
            WEBKIT_TYPE_WEB_FRAME);
2605
2632
2606
    /*
2633
    /*
2634
     * WebKitWebView::context-menu
2635
     * @webView: the object which received the signal
2636
     * @x: the X coordinate of the position where the context menu should be shown
2637
     * @y: the Y coordinate of the position where the context menu should be shown
2638
     * @keyboard_mode: %TRUE if the context menu was trigged using the keyboard
2639
     * @hit_test_result: a #WebKitHitTestResult with the context of the current position.
2640
     *
2641
     * Emmited when a context menu is about to be displayed to give the application
2642
     * a chance to create and handle its own context menu. If you only want to add custom
2643
     * options to the default context menu you should use #WebKitWebView::populate-popup
2644
     * instead. When keyboard_mode is %TRUE the given coordinates should be used to
2645
     * position the popup menu, when the context menu has been triggered by a mouse event
2646
     * you could either use the given coordinates or pass %NULL to the #GtkMenuPositionFunc
2647
     * parameter of gtk_menu_popup() function.
2648
     * When the signal is handled and a popup menu has been created by the application,
2649
     * %TRUE should be returned. Note that when the context menu is handled by the
2650
     * application, the "enable-default-context-menu" setting will be ignored and
2651
     * #WebKitWebView::populate-popup signal won't be emitted.
2652
     * If you don't want any context menu to be shown, you can simply connect to this signal
2653
     * and return %TRUE without doing anything else.
2654
     *
2655
     * Since: 1.3.7
2656
     */
2657
    webkit_web_view_signals[CONTEXT_MENU] = g_signal_new("context-menu",
2658
            G_TYPE_FROM_CLASS(webViewClass),
2659
            (GSignalFlags)G_SIGNAL_RUN_LAST,
2660
            G_STRUCT_OFFSET(WebKitWebViewClass, context_menu),
2661
            NULL, NULL,
2662
            webkit_marshal_BOOLEAN__INT_INT_BOOLEAN_OBJECT,
2663
            G_TYPE_BOOLEAN, 4,
2664
            G_TYPE_INT, G_TYPE_INT, G_TYPE_BOOLEAN,
2665
            WEBKIT_TYPE_HIT_TEST_RESULT);
2666
2667
    /*
2607
     * implementations of virtual methods
2668
     * implementations of virtual methods
2608
     */
2669
     */
2609
    webViewClass->create_web_view = webkit_web_view_real_create_web_view;
2670
    webViewClass->create_web_view = webkit_web_view_real_create_web_view;
Lines 2623-2628 static void webkit_web_view_class_init(WebKitWebViewClass* webViewClass) a/WebKit/gtk/webkit/webkitwebview.cpp_sec8
2623
    webViewClass->undo = webkit_web_view_real_undo;
2684
    webViewClass->undo = webkit_web_view_real_undo;
2624
    webViewClass->redo = webkit_web_view_real_redo;
2685
    webViewClass->redo = webkit_web_view_real_redo;
2625
    webViewClass->move_cursor = webkit_web_view_real_move_cursor;
2686
    webViewClass->move_cursor = webkit_web_view_real_move_cursor;
2687
    webViewClass->context_menu = webkit_web_view_real_context_menu;
2626
2688
2627
    GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
2689
    GObjectClass* objectClass = G_OBJECT_CLASS(webViewClass);
2628
    objectClass->dispose = webkit_web_view_dispose;
2690
    objectClass->dispose = webkit_web_view_dispose;
- a/WebKit/gtk/webkit/webkitwebview.h +5 lines
Lines 127-132 struct _WebKitWebViewClass { a/WebKit/gtk/webkit/webkitwebview.h_sec1
127
    gboolean                   (* move_cursor)            (WebKitWebView        *web_view,
127
    gboolean                   (* move_cursor)            (WebKitWebView        *web_view,
128
                                                           GtkMovementStep       step,
128
                                                           GtkMovementStep       step,
129
                                                           gint                  count);
129
                                                           gint                  count);
130
    gboolean                   (*context_menu)            (WebKitWebView        *web_view,
131
                                                           gint                  x,
132
                                                           gint                  y,
133
                                                           gboolean              keyboard_mode,
134
                                                           WebKitHitTestResult  *hit_test_result);
130
135
131
    /*
136
    /*
132
     * internal
137
     * internal
- a/WebKit/gtk/webkitmarshal.list +1 lines
Lines 1-5 a/WebKit/gtk/webkitmarshal.list_sec1
1
BOOLEAN:ENUM,INT
1
BOOLEAN:ENUM,INT
2
BOOLEAN:INT,INT,STRING
2
BOOLEAN:INT,INT,STRING
3
BOOLEAN:INT,INT,BOOLEAN,OBJECT
3
BOOLEAN:OBJECT
4
BOOLEAN:OBJECT
4
BOOLEAN:OBJECT,OBJECT
5
BOOLEAN:OBJECT,OBJECT
5
BOOLEAN:OBJECT,OBJECT,OBJECT,OBJECT
6
BOOLEAN:OBJECT,OBJECT,OBJECT,OBJECT

Return to Bug 49904