summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2017-06-19 11:35:43 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2017-07-11 09:35:51 +0000
commitef09ea48c36e00dc2a03188936887caf95c2307e (patch)
tree923578365f885b99d09d4bb05916c91ab9059819 /src
parentc2f786d59c8171c05cc7ff8c98b8a85175e5e5a2 (diff)
Take into account the value of the --touch-events Chromium switch
In Chromium 56 the --touch-events switch controls both the availability of the Touch Events API in JavaScript (presence of 'ontouchstart' in 'window' object), and whether touch events are dispatched at all. In Chromium 57, the switch controls only the Touch Events API availability, and touch events are always dispatched. In Qt 5.9.0 which is based on Chromium 56, we always dispatched touch events, ignored the value of --touch-events, and determined the availability of the Touch Events API by checking if QTouchDevice lists any touch screen devices (essentially Chromium's --touch-events=auto option). This commit changes the behavior of WebEngine to match that of Chromium 57, so that users can choose to enable or disable the Touch Events API via the --touch-events switch, whereas the default will be 'auto' mode. Touch events will always be dispatched as usual. Users that wish to stop dispatching touch events can install an event filter on WebEngine's view focus proxy. Task-number: QTBUG-61045 Change-Id: I07404af3336619869aa87a90a1b426036548dd55 Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/web_engine_settings.cpp27
-rw-r--r--src/webengine/doc/src/qtwebengine-features.qdoc17
2 files changed, 43 insertions, 1 deletions
diff --git a/src/core/web_engine_settings.cpp b/src/core/web_engine_settings.cpp
index 58f0a3e2c..0079e02ba 100644
--- a/src/core/web_engine_settings.cpp
+++ b/src/core/web_engine_settings.cpp
@@ -48,6 +48,7 @@
#include "content/browser/gpu/gpu_process_host.h"
#include "content/public/common/content_switches.h"
#include "content/public/common/web_preferences.h"
+#include "ui/events/event_switches.h"
#include <QFont>
#include <QTimer>
@@ -97,6 +98,29 @@ static inline bool isTouchScreenAvailable() {
return touchScreenAvailable;
}
+static inline bool isTouchEventsAPIEnabled() {
+ static bool initialized = false;
+ static bool touchEventsAPIEnabled = false;
+ if (!initialized) {
+ base::CommandLine *parsedCommandLine = base::CommandLine::ForCurrentProcess();
+
+ // By default the Touch Events API support (presence of 'ontouchstart' in 'window' object)
+ // will be determined based on the availability of touch screen devices.
+ const std::string touchEventsSwitchValue =
+ parsedCommandLine->HasSwitch(switches::kTouchEvents) ?
+ parsedCommandLine->GetSwitchValueASCII(switches::kTouchEvents) :
+ switches::kTouchEventsAuto;
+
+ if (touchEventsSwitchValue == switches::kTouchEventsEnabled)
+ touchEventsAPIEnabled = true;
+ else if (touchEventsSwitchValue == switches::kTouchEventsAuto)
+ touchEventsAPIEnabled = isTouchScreenAvailable();
+
+ initialized = true;
+ }
+ return touchEventsAPIEnabled;
+}
+
WebEngineSettings::WebEngineSettings(WebEngineSettings *_parentSettings)
: m_adapter(0)
@@ -298,7 +322,8 @@ void WebEngineSettings::doApply()
void WebEngineSettings::applySettingsToWebPreferences(content::WebPreferences *prefs)
{
// Override for now
- prefs->touch_enabled = isTouchScreenAvailable();
+ prefs->touch_enabled = isTouchEventsAPIEnabled();
+ prefs->device_supports_touch = isTouchScreenAvailable();
if (prefs->viewport_enabled) {
// We should enable viewport and viewport-meta together, but since 5.7 we
// no longer have a command-line flag for viewport-meta.
diff --git a/src/webengine/doc/src/qtwebengine-features.qdoc b/src/webengine/doc/src/qtwebengine-features.qdoc
index 11d3a4ca1..b80ad6a35 100644
--- a/src/webengine/doc/src/qtwebengine-features.qdoc
+++ b/src/webengine/doc/src/qtwebengine-features.qdoc
@@ -45,6 +45,7 @@
\li \l{Pepper Plugin API}
\li \l{Print to PDF}
\li \l{Spellchecker}
+ \li \l{Touch}
\li \l{View Source}
\li \l{WebRTC}
\endlist
@@ -312,6 +313,22 @@
Support for this feature was added in Qt 5.8.0.
+ \section1 Touch
+
+ Qt WebEngine supports touch devices for navigating and interacting with web pages.
+
+ Applications can prohibit the use of touch events in the following ways:
+
+ \list
+ \li Passing the flag \c --touch-events=disabled on the command line will disable touch event
+ support in JavaScript API (meaning \c ontouchstart and related handlers will not be present
+ in the \c document.window object). Touch events will still be delivered to web pages.
+
+ \li Installing an event filter object using \l {QObject::installEventFilter} on the WebEngine
+ view focus proxy object, and filtering out all touch events.
+
+ \endlist
+
\section1 View Source
Qt WebEngine supports viewing the HTML source of a web page.