1
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:
David Rosca 2016-10-25 19:16:10 +02:00
parent 3e4941ef0b
commit b9a7c773f1

View File

@ -1079,13 +1079,6 @@ void WebView::_keyPressEvent(QKeyEvent *event)
}
break;
case Qt::Key_Escape:
if (isFullScreen()) {
triggerPageAction(QWebEnginePage::ExitFullScreen);
event->accept();
}
break;
default:
break;
}
@ -1096,6 +1089,18 @@ void WebView::_keyReleaseEvent(QKeyEvent *event)
if (mApp->plugins()->processKeyRelease(Qz::ON_WebView, this, event)) {
event->accept();
}
switch (event->key()) {
case Qt::Key_Escape:
if (isFullScreen()) {
triggerPageAction(QWebEnginePage::ExitFullScreen);
event->accept();
}
break;
default:
break;
}
}
void WebView::_contextMenuEvent(QContextMenuEvent *event)
@ -1143,25 +1148,24 @@ 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
if (obj == m_rwhvqt) {
#define HANDLE_EVENT(f, t) \
{ \
bool wasAccepted = event->isAccepted(); \
event->setAccepted(false); \
f(static_cast<t*>(event)); \
bool ret = event->isAccepted(); \
event->setAccepted(wasAccepted); \
return ret; \
}
{ \
bool wasAccepted = event->isAccepted(); \
event->setAccepted(false); \
f(static_cast<t*>(event)); \
bool ret = event->isAccepted(); \
event->setAccepted(wasAccepted); \
return ret; \
}
if (obj == m_rwhvqt) {
switch (event->type()) {
case QEvent::KeyPress:
HANDLE_EVENT(_keyPressEvent, QKeyEvent);
case QEvent::KeyRelease:
HANDLE_EVENT(_keyReleaseEvent, QKeyEvent);
case QEvent::MouseButtonPress:
HANDLE_EVENT(_mousePressEvent, QMouseEvent);
@ -1177,10 +1181,22 @@ bool WebView::eventFilter(QObject *obj, QEvent *event)
default:
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
if (obj == this) {
switch (event->type()) {