1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

Disabling touch mocking on Google sites.

- fixes issue with Google maps with menu not hiding

closes #545
This commit is contained in:
nowrep 2012-08-31 15:20:00 +02:00
parent cf2c28cfdb
commit c6d1743706
2 changed files with 47 additions and 44 deletions

View File

@ -40,6 +40,7 @@
#include <QWebHistory> #include <QWebHistory>
#include <QWebFrame> #include <QWebFrame>
#include <QClipboard> #include <QClipboard>
#include <QTouchEvent>
#include <QPrintPreviewDialog> #include <QPrintPreviewDialog>
WebView::WebView(QWidget* parent) WebView::WebView(QWidget* parent)
@ -52,11 +53,13 @@ WebView::WebView(QWidget* parent)
, m_actionReload(0) , m_actionReload(0)
, m_actionStop(0) , m_actionStop(0)
, m_actionsInitialized(false) , m_actionsInitialized(false)
, m_disableTouchMocking(false)
{ {
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted())); connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int))); connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished())); connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged())); connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged()));
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl)));
// Zoom levels same as in firefox // Zoom levels same as in firefox
m_zoomLevels << 30 << 50 << 67 << 80 << 90 << 100 << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300; m_zoomLevels << 30 << 50 << 67 << 80 << 90 << 100 << 110 << 120 << 133 << 150 << 170 << 200 << 240 << 300;
@ -373,6 +376,17 @@ void WebView::slotIconChanged()
} }
} }
void WebView::slotUrlChanged(const QUrl &url)
{
// Disable touch mocking on all google pages as it just makes it buggy
if (url.host().contains("google")) {
m_disableTouchMocking = true;
}
else {
m_disableTouchMocking = false;
}
}
void WebView::openUrlInNewWindow() void WebView::openUrlInNewWindow()
{ {
if (QAction* action = qobject_cast<QAction*>(sender())) { if (QAction* action = qobject_cast<QAction*>(sender())) {
@ -1120,7 +1134,7 @@ void WebView::setZoom(int zoom)
/// ///
bool WebView::eventFilter(QObject* obj, QEvent* event) bool WebView::eventFilter(QObject* obj, QEvent* event)
{ {
if (obj != this) { if (obj != this || m_disableTouchMocking) {
return false; return false;
} }
@ -1130,63 +1144,52 @@ bool WebView::eventFilter(QObject* obj, QEvent* event)
event->type() == QEvent::MouseMove) { event->type() == QEvent::MouseMove) {
QMouseEvent* ev = static_cast<QMouseEvent*>(event); QMouseEvent* ev = static_cast<QMouseEvent*>(event);
if (ev->type() == QEvent::MouseMove && !(ev->buttons() & Qt::LeftButton)) { if (ev->type() == QEvent::MouseMove && !(ev->buttons() & Qt::LeftButton)) {
return false; return false;
} }
if (ev->type() == QEvent::MouseButtonPress && ev->buttons() & Qt::RightButton) { if (ev->type() == QEvent::MouseButtonPress && !(ev->buttons() & Qt::LeftButton)) {
return false; return false;
} }
QEvent::Type type;
QTouchEvent::TouchPoint touchPoint; QTouchEvent::TouchPoint touchPoint;
touchPoint.setState(Qt::TouchPointMoved);
if ((ev->type() == QEvent::MouseButtonPress
|| ev->type() == QEvent::MouseButtonDblClick)) {
touchPoint.setState(Qt::TouchPointPressed);
}
else if (ev->type() == QEvent::MouseButtonRelease) {
touchPoint.setState(Qt::TouchPointReleased);
}
touchPoint.setId(0); touchPoint.setId(0);
touchPoint.setScreenPos(ev->globalPos()); touchPoint.setScreenPos(ev->globalPos());
touchPoint.setPos(ev->pos()); touchPoint.setPos(ev->pos());
touchPoint.setPressure(1); touchPoint.setPressure(1);
// If the point already exists, update it. Otherwise create it. switch (ev->type()) {
if (m_touchPoints.size() > 0 && !m_touchPoints[0].id()) { case QEvent::MouseButtonPress:
m_touchPoints[0] = touchPoint; case QEvent::MouseButtonDblClick:
} touchPoint.setState(Qt::TouchPointPressed);
else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id()) { type = QEvent::TouchBegin;
m_touchPoints[1] = touchPoint;
} break;
else {
m_touchPoints.append(touchPoint); case QEvent::MouseButtonRelease:
touchPoint.setState(Qt::TouchPointReleased);
type = QEvent::TouchEnd;
break;
case QEvent::MouseMove:
touchPoint.setState(Qt::TouchPointMoved);
type = QEvent::TouchUpdate;
break;
default:
break;
} }
if (!m_touchPoints.isEmpty()) { QList<QTouchEvent::TouchPoint> touchPoints;
QEvent::Type type = QEvent::TouchUpdate; touchPoints << touchPoint;
if (m_touchPoints.size() == 1) {
if (m_touchPoints[0].state() == Qt::TouchPointReleased) {
type = QEvent::TouchEnd;
}
else if (m_touchPoints[0].state() == Qt::TouchPointPressed) {
type = QEvent::TouchBegin;
}
}
QTouchEvent touchEv(type); QTouchEvent touchEv(type);
touchEv.setTouchPoints(m_touchPoints); touchEv.setTouchPoints(touchPoints);
QCoreApplication::sendEvent(page(), &touchEv); QCoreApplication::sendEvent(page(), &touchEv);
// After sending the event, remove all touchpoints that were released
if (m_touchPoints[0].state() == Qt::TouchPointReleased) {
m_touchPoints.removeAt(0);
}
if (m_touchPoints.size() > 1 && m_touchPoints[1].state() == Qt::TouchPointReleased) {
m_touchPoints.removeAt(1);
}
}
return false; return false;
} }

View File

@ -20,7 +20,6 @@
#include <QWebView> #include <QWebView>
#include <QWebElement> #include <QWebElement>
#include <QTouchEvent>
#include "qz_namespace.h" #include "qz_namespace.h"
@ -86,6 +85,7 @@ protected slots:
void slotLoadProgress(int progress); void slotLoadProgress(int progress);
void slotLoadFinished(); void slotLoadFinished();
void slotIconChanged(); void slotIconChanged();
void slotUrlChanged(const QUrl &url);
// Context menu slots // Context menu slots
void openUrlInNewWindow(); void openUrlInNewWindow();
@ -168,7 +168,7 @@ private:
QAction* m_actionStop; QAction* m_actionStop;
bool m_actionsInitialized; bool m_actionsInitialized;
QList<QTouchEvent::TouchPoint> m_touchPoints; bool m_disableTouchMocking;
}; };
#endif // WEBVIEW_H #endif // WEBVIEW_H