diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-06-19 11:35:43 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@qt.io> | 2017-07-11 09:35:51 +0000 |
commit | ef09ea48c36e00dc2a03188936887caf95c2307e (patch) | |
tree | 923578365f885b99d09d4bb05916c91ab9059819 /src/core/web_engine_settings.cpp | |
parent | c2f786d59c8171c05cc7ff8c98b8a85175e5e5a2 (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/core/web_engine_settings.cpp')
-rw-r--r-- | src/core/web_engine_settings.cpp | 27 |
1 files changed, 26 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. |