diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index 88c0b8326..f71ae33f1 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -56,6 +56,7 @@ WebView::WebView(QWidget* parent) , m_progress(100) , m_page(0) , m_firstLoad(false) + , m_rwhvqt(0) { connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int))); @@ -1108,25 +1109,23 @@ void WebView::initializeActions() addAction(selectAllAction); } -void WebView::wheelEvent(QWheelEvent* event) +void WebView::_wheelEvent(QWheelEvent *event) { if (mApp->plugins()->processWheelEvent(Qz::ON_WebView, this, event)) { + event->accept(); return; } if (event->modifiers() & Qt::ControlModifier) { event->delta() > 0 ? zoomIn() : zoomOut(); event->accept(); - - return; } - - QWebEngineView::wheelEvent(event); } -void WebView::mousePressEvent(QMouseEvent* event) +void WebView::_mousePressEvent(QMouseEvent *event) { if (mApp->plugins()->processMousePress(Qz::ON_WebView, this, event)) { + event->accept(); return; } @@ -1167,18 +1166,18 @@ void WebView::mousePressEvent(QMouseEvent* event) } } #endif + break; } default: break; } - - QWebEngineView::mousePressEvent(event); } -void WebView::mouseReleaseEvent(QMouseEvent* event) +void WebView::_mouseReleaseEvent(QMouseEvent *event) { if (mApp->plugins()->processMouseRelease(Qz::ON_WebView, this, event)) { + event->accept(); return; } @@ -1202,50 +1201,46 @@ void WebView::mouseReleaseEvent(QMouseEvent* event) if (s_forceContextMenuOnMouseRelease) { QContextMenuEvent ev(QContextMenuEvent::Mouse, event->pos(), event->globalPos(), event->modifiers()); QApplication::sendEvent(this, &ev); + event->accept(); } break; default: break; } - - QWebEngineView::mouseReleaseEvent(event); } -void WebView::mouseMoveEvent(QMouseEvent* event) +void WebView::_mouseMoveEvent(QMouseEvent *event) { if (mApp->plugins()->processMouseMove(Qz::ON_WebView, this, event)) { - return; + event->accept(); } - - QWebEngineView::mouseMoveEvent(event); } -void WebView::keyPressEvent(QKeyEvent* event) +void WebView::_keyPressEvent(QKeyEvent *event) { if (mApp->plugins()->processKeyPress(Qz::ON_WebView, this, event)) { + event->accept(); return; } -#if QTWEBENGINE_DISABLED int eventKey = event->key(); switch (eventKey) { case Qt::Key_ZoomIn: zoomIn(); event->accept(); - return; + break; case Qt::Key_ZoomOut: zoomOut(); event->accept(); - return; + break; case Qt::Key_Plus: if (event->modifiers() & Qt::ControlModifier) { zoomIn(); event->accept(); - return; } break; @@ -1253,7 +1248,6 @@ void WebView::keyPressEvent(QKeyEvent* event) if (event->modifiers() & Qt::ControlModifier) { zoomOut(); event->accept(); - return; } break; @@ -1261,120 +1255,22 @@ void WebView::keyPressEvent(QKeyEvent* event) if (event->modifiers() & Qt::ControlModifier) { zoomReset(); event->accept(); - return; } break; default: break; } - - // Text navigation is handled automatically in editable elements - const QString js = QSL("document.activeElement.contentEditable==='true'||typeof document.activeElement.value != 'undefined'"); - QWebFrame* frame = page()->currentFrame(); - if (frame && frame->evaluateJavaScript(js).toBool()) - return QWebView::keyPressEvent(event); - - switch (eventKey) { - case Qt::Key_Up: - if (event->modifiers() & Qt::ShiftModifier) { - triggerPageAction(QWebPage::SelectPreviousLine); - event->accept(); - return; - } - break; - - case Qt::Key_Down: - if (event->modifiers() & Qt::ShiftModifier) { - triggerPageAction(QWebEnginePage::SelectNextLine); - event->accept(); - return; - } - break; - - case Qt::Key_Left: - if (event->modifiers() & Qt::ShiftModifier) { - if (event->modifiers() == Qt::ShiftModifier) { - triggerPageAction(QWebEnginePage::SelectPreviousChar); - } - else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { - triggerPageAction(QWebEnginePage::SelectPreviousWord); - } - event->accept(); - return; - } - break; - - case Qt::Key_Right: - if (event->modifiers() & Qt::ShiftModifier) { - if (event->modifiers() == Qt::ShiftModifier) { - triggerPageAction(QWebEnginePage::SelectNextChar); - } - else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { - triggerPageAction(QWebEnginePage::SelectNextWord); - } - event->accept(); - return; - } - break; - - case Qt::Key_Home: - if (event->modifiers() & Qt::ShiftModifier) { - if (event->modifiers() == Qt::ShiftModifier) { - triggerPageAction(QWebEnginePage::SelectStartOfLine); - } - else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { - triggerPageAction(QWebEnginePage::SelectStartOfDocument); - } - event->accept(); - return; - } - break; - - case Qt::Key_End: - if (event->modifiers() & Qt::ShiftModifier) { - if (event->modifiers() == Qt::ShiftModifier) { - triggerPageAction(QWebEnginePage::SelectEndOfLine); - } - else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { - triggerPageAction(QWebEnginePage::SelectEndOfDocument); - } - event->accept(); - return; - } - break; - - case Qt::Key_Insert: - if (event->modifiers() == Qt::ControlModifier) { - triggerPageAction(QWebEnginePage::Copy); - event->accept(); - return; - } - if (event->modifiers() == Qt::ShiftModifier) { - triggerPageAction(QWebEnginePage::Paste); - event->accept(); - return; - } - break; - - default: - break; - } -#endif - - QWebEngineView::keyPressEvent(event); } -void WebView::keyReleaseEvent(QKeyEvent* event) +void WebView::_keyReleaseEvent(QKeyEvent *event) { if (mApp->plugins()->processKeyRelease(Qz::ON_WebView, this, event)) { - return; + event->accept(); } - - QWebEngineView::keyReleaseEvent(event); } -void WebView::resizeEvent(QResizeEvent* event) +void WebView::resizeEvent(QResizeEvent *event) { QWebEngineView::resizeEvent(event); emit viewportResized(size()); @@ -1388,7 +1284,7 @@ void WebView::loadRequest(const LoadRequest &req) m_page->runJavaScript(Scripts::sendPostData(req.url(), req.data())); } -bool WebView::eventFilter(QObject* obj, QEvent* event) +bool WebView::eventFilter(QObject *obj, QEvent *event) { if (s_forceContextMenuOnMouseRelease && obj == this && event->type() == QEvent::ContextMenu) { QContextMenuEvent* ev = static_cast(event); @@ -1398,5 +1294,52 @@ bool WebView::eventFilter(QObject* obj, QEvent* event) } } + // Hack to find widget that receives input events + if (obj == this && event->type() == QEvent::ChildAdded) { + QObject *child = static_cast(event)->child(); + if (qstrcmp(child->metaObject()->className(), "QtWebEngineCore::RenderWidgetHostViewQtDelegateWidget") == 0) { + m_rwhvqt = child; + m_rwhvqt->installEventFilter(this); + } + } + + // Forward events to WebView + if (obj == m_rwhvqt) { + switch (event->type()) { + case QEvent::KeyPress: + event->setAccepted(false); + _keyPressEvent(static_cast(event)); + return event->isAccepted(); + + case QEvent::KeyRelease: + event->setAccepted(false); + _keyReleaseEvent(static_cast(event)); + return event->isAccepted(); + + case QEvent::MouseButtonPress: + event->setAccepted(false); + _mousePressEvent(static_cast(event)); + return event->isAccepted(); + + case QEvent::MouseButtonRelease: + event->setAccepted(false); + _mouseReleaseEvent(static_cast(event)); + return event->isAccepted(); + + case QEvent::MouseMove: + event->setAccepted(false); + _mouseMoveEvent(static_cast(event)); + return event->isAccepted(); + + case QEvent::Wheel: + event->setAccepted(false); + _wheelEvent(static_cast(event)); + return event->isAccepted(); + + default: + break; + } + } + return QWebEngineView::eventFilter(obj, event); } diff --git a/src/lib/webengine/webview.h b/src/lib/webengine/webview.h index a2f0f1f8c..a8f57a853 100644 --- a/src/lib/webengine/webview.h +++ b/src/lib/webengine/webview.h @@ -60,7 +60,7 @@ public: bool onBeforeUnload(); void addNotification(QWidget* notif); - bool eventFilter(QObject* obj, QEvent* event); + bool eventFilter(QObject *obj, QEvent *event); virtual QWidget* overlayWidget() = 0; @@ -140,13 +140,14 @@ protected slots: #endif protected: - void wheelEvent(QWheelEvent* event); - void mousePressEvent(QMouseEvent* event); - void mouseReleaseEvent(QMouseEvent* event); - void mouseMoveEvent(QMouseEvent* event); - void keyPressEvent(QKeyEvent* event); - void keyReleaseEvent(QKeyEvent* event); - void resizeEvent(QResizeEvent* event); + void resizeEvent(QResizeEvent *event); + + virtual void _wheelEvent(QWheelEvent *event); + virtual void _mousePressEvent(QMouseEvent *event); + virtual void _mouseReleaseEvent(QMouseEvent *event); + virtual void _mouseMoveEvent(QMouseEvent *event); + virtual void _keyPressEvent(QKeyEvent *event); + virtual void _keyReleaseEvent(QKeyEvent *event); void loadRequest(const LoadRequest &req); void applyZoom(); @@ -187,9 +188,10 @@ private: WebPage* m_page; bool m_actionsInitialized; - bool m_firstLoad; + QObject *m_rwhvqt; + static bool s_forceContextMenuOnMouseRelease; }; diff --git a/src/lib/webtab/tabbedwebview.cpp b/src/lib/webtab/tabbedwebview.cpp index 6e53a5c01..23ccff635 100644 --- a/src/lib/webtab/tabbedwebview.cpp +++ b/src/lib/webtab/tabbedwebview.cpp @@ -221,7 +221,7 @@ void TabbedWebView::setAsCurrentTab() } } -void TabbedWebView::mouseMoveEvent(QMouseEvent* event) +void TabbedWebView::_mouseMoveEvent(QMouseEvent *event) { if (m_window && m_window->isFullScreen()) { if (m_window->fullScreenNavigationVisible()) { @@ -232,5 +232,5 @@ void TabbedWebView::mouseMoveEvent(QMouseEvent* event) } } - WebView::mouseMoveEvent(event); + WebView::_mouseMoveEvent(event); } diff --git a/src/lib/webtab/tabbedwebview.h b/src/lib/webtab/tabbedwebview.h index b66610a39..af436d0a2 100644 --- a/src/lib/webtab/tabbedwebview.h +++ b/src/lib/webtab/tabbedwebview.h @@ -72,7 +72,7 @@ private slots: private: void contextMenuEvent(QContextMenuEvent* event); - void mouseMoveEvent(QMouseEvent* event); + void _mouseMoveEvent(QMouseEvent *event) Q_DECL_OVERRIDE; BrowserWindow* m_window; WebTab* m_webTab;