documentation

This commit is contained in:
2026-03-16 20:04:30 +01:00
parent a7257a3492
commit 7c3b780ae9
14 changed files with 2424 additions and 583 deletions

View File

@@ -52,6 +52,7 @@ WebviewWindow::WebviewWindow(QWebEngineProfile *profile, WebviewWindow *parent)
_resized = 0;
_profile = profile;
_navigation_event_sent = false;
if (parent != nullptr) {
setWindowModality(Qt::WindowModality::WindowModal);
@@ -67,11 +68,14 @@ void WebviewWindow::navigationRequested(QWebEngineNavigationRequest &req)
QWebEngineNavigationRequest::NavigationType t = req.navigationType();
if (t == QWebEngineNavigationRequest::NavigationType::TypedNavigation ||
t == QWebEngineNavigationRequest::RedirectNavigation) {
_navigation_event_sent = false;
req.accept();
} else {
EventContainer e("navigation-request");
e["url"] = req.url().toString();
QString u = req.url().toString();
e["url"] = u;
QString type;
switch (req.navigationType()) {
@@ -94,6 +98,8 @@ void WebviewWindow::navigationRequested(QWebEngineNavigationRequest &req)
e["type"] = type;
_container->triggerEvent(_view->id(), e);
_navigation_event_sent = true;
req.reject();
}
}
@@ -208,6 +214,11 @@ void WebviewWindow::setOUToken(const QString &token)
_ou_token = token;
}
bool WebviewWindow::navigationEventSent()
{
return _navigation_event_sent;
}
void WebviewWindow::addView(WebViewQt *v, Rktwebview_qt *c)
{
_container = c;
@@ -216,36 +227,6 @@ void WebviewWindow::addView(WebViewQt *v, Rktwebview_qt *c)
QWebEnginePage *page = _view->page();
/*
if (_profile == nullptr) {
page = _view->page();
} else {
page = new QWebEnginePage(_profile, this);
_view->setPage(page);
}
// Inject event handling code for the javascript side
QWebEngineScriptCollection &col = page->scripts();
QWebEngineScript evt_script;
evt_script.setInjectionPoint(QWebEngineScript::DocumentReady);
evt_script.setName("rkt_webview_event_handling");
evt_script.setSourceCode(
"window.rkt_event_queue = [];\n"
"window.rkt_send_event = function(obj) {\n"
" console.log('Sending event: ' + obj);\n"
" window.rkt_event_queue.push(obj);\n"
"};\n"
"window.rkt_get_events = function() {\n"
" let q = window.rkt_event_queue;\n"
" window.rkt_event_queue = [];\n"
" let json_q = JSON.stringify(q);\n"
" return json_q;\n"
"};\n"
);
evt_script.setWorldId(QWebEngineScript::ApplicationWorld);
//col.insert(evt_script);
*/
connect(page, &QWebEnginePage::loadFinished, this, [this](bool ok) {
_container->pageLoaded(_view->id(), ok);
});
@@ -255,6 +236,12 @@ void WebviewWindow::addView(WebViewQt *v, Rktwebview_qt *c)
connect(page, &QWebEnginePage::navigationRequested, this, &WebviewWindow::navigationRequested);
connect(page, &QWebEnginePage::certificateError, this, &WebviewWindow::handleCertificate);
connect(page, &QWebEnginePage::windowCloseRequested, this, &WebviewWindow::closeView);
connect(page, &QWebEnginePage::linkHovered, this, &WebviewWindow::linkHovered);
connect(page, &QWebEnginePage::printRequestedByFrame, this, &WebviewWindow::evtRequested);
}
WebViewQt *WebviewWindow::view()
@@ -306,6 +293,21 @@ void WebviewWindow::openDevTools()
});
}
void WebviewWindow::linkHovered(const QUrl &u)
{
QString s = u.toString();
EventContainer hover_event("link-hovered");
hover_event["url"] = s;
_container->triggerEvent(_view->id(), hover_event);
}
void WebviewWindow::evtRequested(QWebEngineFrame frame)
{
if (frame.name() == "rkt-evt-frame") {
processJsEvents();
}
}
void WebviewWindow::moveEvent(QMoveEvent *event)
{