コード例 #1
0
static gboolean webViewMotionNotifyEvent(GtkWidget* widget, GdkEventMotion* event)
{
    WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
    webView->handleMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */);

    return FALSE;
}
コード例 #2
0
static gboolean webViewButtonReleaseEvent(GtkWidget* widget, GdkEventButton* event)
{
    WebView* webView = webViewWidgetGetWebViewInstance(WEB_VIEW_WIDGET(widget));
    gtk_widget_grab_focus(widget);
    webView->handleMouseEvent(reinterpret_cast<GdkEvent*>(event), 0 /* currentClickCount */);

    return FALSE;
}
コード例 #3
0
static gboolean webViewButtonPressEvent(GtkWidget* widget, GdkEventButton* buttonEvent)
{
    if (buttonEvent->button == 3) {
        // FIXME: [GTK] Add context menu support for Webkit2.
        // https://bugs.webkit.org/show_bug.cgi?id=54827
        notImplemented();
        return FALSE;
    }

    gtk_widget_grab_focus(widget);

    // For double and triple clicks GDK sends both a normal button press event
    // and a specific type (like GDK_2BUTTON_PRESS). If we detect a special press
    // coming up, ignore this event as it certainly generated the double or triple
    // click. The consequence of not eating this event is two DOM button press events
    // are generated.
    GOwnPtr<GdkEvent> nextEvent(gdk_event_peek());
    if (nextEvent && (nextEvent->any.type == GDK_2BUTTON_PRESS || nextEvent->any.type == GDK_3BUTTON_PRESS))
        return TRUE;

    gint doubleClickDistance = 250;
    gint doubleClickTime = 5;
    GtkSettings* settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget));
    g_object_get(settings,
                 "gtk-double-click-distance", &doubleClickDistance,
                 "gtk-double-click-time", &doubleClickTime, NULL);

    // GTK+ only counts up to triple clicks, but WebCore wants to know about
    // quadruple clicks, quintuple clicks, ad infinitum. Here, we replicate the
    // GDK logic for counting clicks.
    GdkEvent* event(reinterpret_cast<GdkEvent*>(buttonEvent));
    guint32 eventTime = getEventTime(event);
    WebViewWidget* webViewWidget = WEB_VIEW_WIDGET(widget);
    WebViewWidgetPrivate* priv = webViewWidget->priv;
    if ((event->type == GDK_2BUTTON_PRESS || event->type == GDK_3BUTTON_PRESS)
        || ((abs(buttonEvent->x - priv->previousClickPoint.x()) < doubleClickDistance)
            && (abs(buttonEvent->y - priv->previousClickPoint.y()) < doubleClickDistance)
            && (eventTime - priv->previousClickTime < static_cast<guint>(doubleClickTime))
            && (buttonEvent->button == priv->previousClickButton)))
        priv->currentClickCount++;
    else
        priv->currentClickCount = 1;

    WebView* webView = webViewWidgetGetWebViewInstance(webViewWidget);
    webView->handleMouseEvent(event, priv->currentClickCount);

    gdouble x, y;
    gdk_event_get_coords(event, &x, &y);
    priv->previousClickPoint = IntPoint(x, y);
    priv->previousClickButton = buttonEvent->button;
    priv->previousClickTime = eventTime;

    return FALSE;
}