WebView: Implementing the Menu event automatically disables the default popup menu.

[GB.GTK3.WEBVIEW]
* NEW: WebView: Implementing the Menu event automatically disables the default popup menu.

[GB.QT4.WEBVIEW]
* NEW: WebView: Implementing the Menu event automatically disables the default popup menu.

[GB.QT5.WEBVIEW]
* NEW: WebView: Implementing the Menu event automatically disables the default popup menu.
This commit is contained in:
gambas 2021-01-26 16:28:47 +01:00
parent ec2fe3ee4e
commit f94a927e9c
5 changed files with 46 additions and 6 deletions

View File

@ -53,6 +53,8 @@ DECLARE_EVENT(EVENT_ERROR);
DECLARE_EVENT(EVENT_LINK);
DECLARE_EVENT(EVENT_NEW_VIEW);
static int EVENT_MENU = -1;
static void cb_title(WebKitWebView *widget, GParamSpec *pspec, CWEBVIEW *_object)
{
GB.Raise(THIS, EVENT_TITLE, 0);
@ -212,6 +214,14 @@ static void cb_javascript_finished(WebKitWebView *widget, GAsyncResult *result,
THIS->js_running = FALSE;
}
static gboolean cb_context_menu(WebKitWebView *web_view, WebKitContextMenu *context_menu, GdkEvent *event, WebKitHitTestResult *hit_test_result, void *_object)
{
if (EVENT_MENU < 0)
EVENT_MENU = GB.GetEvent(GB.GetClass(THIS), "Menu");
return GB.CanRaise(THIS, EVENT_MENU);
}
//---------------------------------------------------------------------------
#define must_patch(_widget) (true)
@ -244,6 +254,7 @@ static void create_widget(void *_object, void *parent)
g_signal_connect(G_OBJECT(WIDGET), "mouse-target-changed", G_CALLBACK(cb_link), (gpointer)THIS);
g_signal_connect(G_OBJECT(WIDGET), "create", G_CALLBACK(cb_create), (gpointer)THIS);
g_signal_connect(G_OBJECT(WIDGET), "decide-policy", G_CALLBACK(cb_decide_policy), (gpointer)THIS);
g_signal_connect(G_OBJECT(WIDGET), "context-menu", G_CALLBACK(cb_context_menu), (gpointer)THIS);
WEBVIEW_init_settings(THIS);
}

View File

@ -53,6 +53,8 @@ DECLARE_EVENT(EVENT_ERROR);
DECLARE_EVENT(EVENT_LINK);
DECLARE_EVENT(EVENT_NEW_VIEW);
static int EVENT_MENU = -1;
//static QNetworkAccessManager *_network_access_manager = 0;
static CWEBVIEW *_network_access_manager_view = 0;
//static QT_COLOR_FUNC _old_after_set_color;
@ -528,6 +530,19 @@ QWebView *MyWebView::createWindow(QWebPage::WebWindowType type)
return new_view;
}
void MyWebEngineView::contextMenuEvent(QContextMenuEvent *event)
{
void *_object = QT.GetObject(this);
if (EVENT_MENU < 0)
EVENT_MENU = GB.GetEvent(GB.GetClass(THIS), "Menu");
if (!GB.CanRaise(THIS, EVENT_MENU))
QWebView::contextMenuEvent(event);
event->accept();
}
/***************************************************************************/
CWebView CWebView::manager;

View File

@ -72,6 +72,7 @@ public:
protected:
virtual QWebView *createWindow(QWebPage::WebWindowType type);
virtual void contextMenuEvent(QContextMenuEvent *event);
};
typedef

View File

@ -31,6 +31,7 @@
#include <QWebHistory>*/
#include <QWebEngineHistory>
#include <QJsonDocument>
#include <QContextMenuEvent>
/*#include "ccookiejar.h"
#include "cwebsettings.h"
@ -65,6 +66,7 @@ DECLARE_EVENT(EVENT_ERROR);
DECLARE_EVENT(EVENT_LINK);
DECLARE_EVENT(EVENT_NEW_VIEW);
static int EVENT_MENU = -1;
/*DECLARE_EVENT(EVENT_CLICK);
DECLARE_EVENT(EVENT_LINK);
DECLARE_EVENT(EVENT_NEW_FRAME);
@ -72,6 +74,7 @@ DECLARE_EVENT(EVENT_AUTH);
DECLARE_EVENT(EVENT_DOWNLOAD);*/
/*
static QNetworkAccessManager *_network_access_manager = 0;
static CWEBVIEW *_network_access_manager_view = 0;
@ -311,11 +314,6 @@ BEGIN_METHOD_VOID(WebView_free)
END_METHOD
/*BEGIN_METHOD_VOID(WebView_init)
_old_after_set_color = QT.AfterSetColor(after_set_color);
END_METHOD*/
/*BEGIN_METHOD_VOID(WebView_exit)
@ -964,6 +962,20 @@ QWebEngineView *MyWebEngineView::createWindow(QWebEnginePage::WebWindowType type
return new_view;
}
void MyWebEngineView::contextMenuEvent(QContextMenuEvent *event)
{
void *_object = QT.GetObject(this);
if (EVENT_MENU < 0)
EVENT_MENU = GB.GetEvent(GB.GetClass(THIS), "Menu");
if (!GB.CanRaise(THIS, EVENT_MENU))
QWebEngineView::contextMenuEvent(event);
event->accept();
}
//-------------------------------------------------------------------------
MyWebPage::MyWebPage(QObject *parent) : QWebEnginePage(parent)

View File

@ -81,7 +81,8 @@ public:
MyWebEngineView(QWidget *parent);
protected:
virtual void contextMenuEvent(QContextMenuEvent *event);
virtual QWebEngineView *createWindow(QWebEnginePage::WebWindowType type);
};