1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +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 <QWebFrame>
#include <QClipboard>
#include <QTouchEvent>
#include <QPrintPreviewDialog>
WebView::WebView(QWidget* parent)
@ -52,11 +53,13 @@ WebView::WebView(QWidget* parent)
, m_actionReload(0)
, m_actionStop(0)
, m_actionsInitialized(false)
, m_disableTouchMocking(false)
{
connect(this, SIGNAL(loadStarted()), this, SLOT(slotLoadStarted()));
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotLoadProgress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished()));
connect(this, SIGNAL(iconChanged()), this, SLOT(slotIconChanged()));
connect(this, SIGNAL(urlChanged(QUrl)), this, SLOT(slotUrlChanged(QUrl)));
// Zoom levels same as in firefox
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()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
@ -1120,7 +1134,7 @@ void WebView::setZoom(int zoom)
///
bool WebView::eventFilter(QObject* obj, QEvent* event)
{
if (obj != this) {
if (obj != this || m_disableTouchMocking) {
return false;
}
@ -1130,64 +1144,53 @@ bool WebView::eventFilter(QObject* obj, QEvent* event)
event->type() == QEvent::MouseMove) {
QMouseEvent* ev = static_cast<QMouseEvent*>(event);
if (ev->type() == QEvent::MouseMove && !(ev->buttons() & Qt::LeftButton)) {
return false;
}
if (ev->type() == QEvent::MouseButtonPress && ev->buttons() & Qt::RightButton) {
if (ev->type() == QEvent::MouseButtonPress && !(ev->buttons() & Qt::LeftButton)) {
return false;
}
QEvent::Type type;
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.setScreenPos(ev->globalPos());
touchPoint.setPos(ev->pos());
touchPoint.setPressure(1);
// If the point already exists, update it. Otherwise create it.
if (m_touchPoints.size() > 0 && !m_touchPoints[0].id()) {
m_touchPoints[0] = touchPoint;
}
else if (m_touchPoints.size() > 1 && !m_touchPoints[1].id()) {
m_touchPoints[1] = touchPoint;
}
else {
m_touchPoints.append(touchPoint);
switch (ev->type()) {
case QEvent::MouseButtonPress:
case QEvent::MouseButtonDblClick:
touchPoint.setState(Qt::TouchPointPressed);
type = QEvent::TouchBegin;
break;
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()) {
QEvent::Type type = QEvent::TouchUpdate;
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;
}
}
QList<QTouchEvent::TouchPoint> touchPoints;
touchPoints << touchPoint;
QTouchEvent touchEv(type);
touchEv.setTouchPoints(m_touchPoints);
touchEv.setTouchPoints(touchPoints);
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;
}

View File

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