mirror of
https://invent.kde.org/network/falkon.git
synced 2024-11-11 09:32:12 +01:00
WebView: Fix handling of key events
Unhandled key events are sent to parent of QWebEngineView. Hack with event filter on RenderWidgetHostViewQtDelegateWidget no longer works for key events, so we need to install event filter on view parent and handle key events there. Downside is, that we can now only handle events that are not handled by page itself.
This commit is contained in:
parent
3e4941ef0b
commit
b9a7c773f1
|
@ -1079,13 +1079,6 @@ void WebView::_keyPressEvent(QKeyEvent *event)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Qt::Key_Escape:
|
|
||||||
if (isFullScreen()) {
|
|
||||||
triggerPageAction(QWebEnginePage::ExitFullScreen);
|
|
||||||
event->accept();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1096,6 +1089,18 @@ void WebView::_keyReleaseEvent(QKeyEvent *event)
|
||||||
if (mApp->plugins()->processKeyRelease(Qz::ON_WebView, this, event)) {
|
if (mApp->plugins()->processKeyRelease(Qz::ON_WebView, this, event)) {
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
switch (event->key()) {
|
||||||
|
case Qt::Key_Escape:
|
||||||
|
if (isFullScreen()) {
|
||||||
|
triggerPageAction(QWebEnginePage::ExitFullScreen);
|
||||||
|
event->accept();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebView::_contextMenuEvent(QContextMenuEvent *event)
|
void WebView::_contextMenuEvent(QContextMenuEvent *event)
|
||||||
|
@ -1143,8 +1148,12 @@ bool WebView::eventFilter(QObject *obj, QEvent *event)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Keyboard events are sent to parent widget
|
||||||
|
if (obj == this && event->type() == QEvent::ParentChange && parent()) {
|
||||||
|
parent()->installEventFilter(this);
|
||||||
|
}
|
||||||
|
|
||||||
// Forward events to WebView
|
// Forward events to WebView
|
||||||
if (obj == m_rwhvqt) {
|
|
||||||
#define HANDLE_EVENT(f, t) \
|
#define HANDLE_EVENT(f, t) \
|
||||||
{ \
|
{ \
|
||||||
bool wasAccepted = event->isAccepted(); \
|
bool wasAccepted = event->isAccepted(); \
|
||||||
|
@ -1155,13 +1164,8 @@ bool WebView::eventFilter(QObject *obj, QEvent *event)
|
||||||
return ret; \
|
return ret; \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj == m_rwhvqt) {
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
case QEvent::KeyPress:
|
|
||||||
HANDLE_EVENT(_keyPressEvent, QKeyEvent);
|
|
||||||
|
|
||||||
case QEvent::KeyRelease:
|
|
||||||
HANDLE_EVENT(_keyReleaseEvent, QKeyEvent);
|
|
||||||
|
|
||||||
case QEvent::MouseButtonPress:
|
case QEvent::MouseButtonPress:
|
||||||
HANDLE_EVENT(_mousePressEvent, QMouseEvent);
|
HANDLE_EVENT(_mousePressEvent, QMouseEvent);
|
||||||
|
|
||||||
|
@ -1177,10 +1181,22 @@ bool WebView::eventFilter(QObject *obj, QEvent *event)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef HANDLE_EVENT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (obj == parentWidget()) {
|
||||||
|
switch (event->type()) {
|
||||||
|
case QEvent::KeyPress:
|
||||||
|
HANDLE_EVENT(_keyPressEvent, QKeyEvent);
|
||||||
|
|
||||||
|
case QEvent::KeyRelease:
|
||||||
|
HANDLE_EVENT(_keyReleaseEvent, QKeyEvent);
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#undef HANDLE_EVENT
|
||||||
|
|
||||||
// Block already handled events
|
// Block already handled events
|
||||||
if (obj == this) {
|
if (obj == this) {
|
||||||
switch (event->type()) {
|
switch (event->type()) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user