From dce5b2a30773bbf508afda54601dd84e8cb691ce Mon Sep 17 00:00:00 2001
From: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Date: Thu, 11 Sep 2014 17:26:37 +0200
Subject: [PATCH] Enable JavaScript touch events

They are disabled by default at the moment, enable them conditionally
to a touch screen being available.

Change-Id: I5827fe2326b7bc019fa5613121d1cfa666608e52
Reviewed-by: Andras Becsi <andras.becsi@digia.com>
---
 src/core/web_engine_settings.cpp | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp
index 76eb7f25e..6af3210bf 100644
--- a/src/core/web_engine_settings.cpp
+++ b/src/core/web_engine_settings.cpp
@@ -42,6 +42,7 @@
 
 #include <QFont>
 #include <QTimer>
+#include <QTouchDevice>
 
 static const int batchTimerTimeout = 100;
 
@@ -68,6 +69,21 @@ private:
 
 #include "web_engine_settings.moc"
 
+static inline bool isTouchScreenAvailable() {
+    static bool initialized = false;
+    static bool touchScreenAvailable = false;
+    if (!initialized) {
+        Q_FOREACH (const QTouchDevice *d, QTouchDevice::devices()) {
+            if (d->type() == QTouchDevice::TouchScreen) {
+                touchScreenAvailable = true;
+                break;
+            }
+        }
+        initialized = true;
+    }
+    return touchScreenAvailable;
+}
+
 
 WebEngineSettings::WebEngineSettings(WebEngineSettingsDelegate *delegate)
     : m_adapter(0)
@@ -245,6 +261,7 @@ void WebEngineSettings::applySettingsToWebPreferences(WebPreferences *prefs)
 {
     // Override for now
     prefs->java_enabled = false;
+    prefs->touch_enabled = isTouchScreenAvailable();
 
     // Attributes mapping.
     prefs->loads_images_automatically = testAttribute(AutoLoadImages);
-- 
GitLab