diff --git a/b2g/app/b2g.js b/b2g/app/b2g.js index 1ae138bfa933..8b811694f0a4 100644 --- a/b2g/app/b2g.js +++ b/b2g/app/b2g.js @@ -279,7 +279,7 @@ pref("image.mem.min_discard_timeout_ms", 10000); pref("image.mem.max_decoded_image_kb", 5120); /* 5MB */ // enable touch events interfaces -pref("dom.w3c_touch_events.enabled", true); +pref("dom.w3c_touch_events.enabled", 1); pref("dom.w3c_touch_events.safetyX", 0); // escape borders in units of 1/240" pref("dom.w3c_touch_events.safetyY", 120); // escape borders in units of 1/240" diff --git a/build/automation.py.in b/build/automation.py.in index 038d2f5ff9e4..3537ed00d777 100644 --- a/build/automation.py.in +++ b/build/automation.py.in @@ -407,7 +407,7 @@ user_pref("security.warn_viewing_mixed", false); user_pref("app.update.enabled", false); user_pref("app.update.staging.enabled", false); user_pref("browser.panorama.experienced_first_run", true); // Assume experienced -user_pref("dom.w3c_touch_events.enabled", true); +user_pref("dom.w3c_touch_events.enabled", 1); user_pref("toolkit.telemetry.prompted", 2); // Existing tests assume there is no font size inflation. user_pref("font.size.inflation.emPerLine", 0); diff --git a/content/events/src/nsDOMTouchEvent.cpp b/content/events/src/nsDOMTouchEvent.cpp index ccf48644f3dd..1241411d0f9d 100644 --- a/content/events/src/nsDOMTouchEvent.cpp +++ b/content/events/src/nsDOMTouchEvent.cpp @@ -373,6 +373,13 @@ nsDOMTouchEvent::GetShiftKey(bool* aShiftKey) return NS_OK; } +#ifdef XP_WIN +namespace mozilla { +namespace widget { +extern int32_t IsTouchDeviceSupportPresent(); +} } +#endif + bool nsDOMTouchEvent::PrefEnabled() { @@ -380,7 +387,20 @@ nsDOMTouchEvent::PrefEnabled() static bool sPrefValue = false; if (!sDidCheckPref) { sDidCheckPref = true; - sPrefValue = Preferences::GetBool("dom.w3c_touch_events.enabled", false); + int32_t flag = 0; + if (NS_SUCCEEDED(Preferences::GetInt("dom.w3c_touch_events.enabled", + &flag))) { + if (flag == 2) { +#ifdef XP_WIN + // On Windows we auto-detect based on device support. + sPrefValue = mozilla::widget::IsTouchDeviceSupportPresent(); +#else + NS_ERROR("Not implemented"); +#endif + } else { + sPrefValue = !!flag; + } + } if (sPrefValue) { nsContentUtils::InitializeTouchEventTable(); } diff --git a/dom/browser-element/BrowserElementParent.js b/dom/browser-element/BrowserElementParent.js index 0f376fba3498..3b9e0726acf1 100644 --- a/dom/browser-element/BrowserElementParent.js +++ b/dom/browser-element/BrowserElementParent.js @@ -35,6 +35,15 @@ function getBoolPref(prefName, def) { } } +function getIntPref(prefName, def) { + try { + return Services.prefs.getIntPref(prefName); + } + catch(err) { + return def; + } +} + function exposeAll(obj) { // Filter for Objects and Arrays. if (typeof obj !== "object" || !obj) @@ -236,7 +245,9 @@ function BrowserElementParent(frameLoader, hasRemoteFrame) { // Define methods on the frame element. defineMethod('setVisible', this._setVisible); defineMethod('sendMouseEvent', this._sendMouseEvent); - if (getBoolPref(TOUCH_EVENTS_ENABLED_PREF, false)) { + + // 0 = disabled, 1 = enabled, 2 - auto detect + if (getIntPref(TOUCH_EVENTS_ENABLED_PREF, 0) != 0) { defineMethod('sendTouchEvent', this._sendTouchEvent); } defineMethod('goBack', this._goBack); diff --git a/dom/browser-element/mochitest/browserElement_SendEvent.js b/dom/browser-element/mochitest/browserElement_SendEvent.js index 591f1cd1b5e5..fde2d24749ed 100644 --- a/dom/browser-element/mochitest/browserElement_SendEvent.js +++ b/dom/browser-element/mochitest/browserElement_SendEvent.js @@ -36,7 +36,7 @@ function runTest() { break; case "#click": ok(true, "Receive a click event."); - if (SpecialPowers.getBoolPref("dom.w3c_touch_events.enabled")) { + if (SpecialPowers.getIntPref("dom.w3c_touch_events.enabled") != 0) { iframe.sendTouchEvent("touchstart", [1], [10], [10], [2], [2], [20], [0.5], 1, 0); } else { diff --git a/mobile/android/app/mobile.js b/mobile/android/app/mobile.js index 1aa10a8f3581..d62fdb8884e5 100644 --- a/mobile/android/app/mobile.js +++ b/mobile/android/app/mobile.js @@ -539,7 +539,7 @@ pref("content.image.allow_locking", false); pref("image.mem.min_discard_timeout_ms", 10000); // enable touch events interfaces -pref("dom.w3c_touch_events.enabled", true); +pref("dom.w3c_touch_events.enabled", 1); #ifdef MOZ_SAFE_BROWSING pref("browser.safebrowsing.enabled", true); diff --git a/mobile/xul/app/mobile.js b/mobile/xul/app/mobile.js index eb87df53bef7..ae77196e307a 100644 --- a/mobile/xul/app/mobile.js +++ b/mobile/xul/app/mobile.js @@ -582,7 +582,7 @@ pref("content.image.allow_locking", false); pref("image.mem.min_discard_timeout_ms", 10000); // enable touch events interfaces -pref("dom.w3c_touch_events.enabled", true); +pref("dom.w3c_touch_events.enabled", 1); pref("dom.w3c_touch_events.safetyX", 5); // escape borders in units of 1/240" pref("dom.w3c_touch_events.safetyY", 20); // escape borders in units of 1/240" diff --git a/mobile/xul/chrome/content/content.js b/mobile/xul/chrome/content/content.js index 45717737d4ed..cff1ee0a465b 100644 --- a/mobile/xul/chrome/content/content.js +++ b/mobile/xul/chrome/content/content.js @@ -1366,7 +1366,7 @@ var TouchEventHandler = { }, sendEvent: function(aName, aData, aElement) { - if (!Services.prefs.getBoolPref("dom.w3c_touch_events.enabled")) + if (!Services.prefs.getIntPref("dom.w3c_touch_events.enabled")) return true; let evt = content.document.createEvent("touchevent"); diff --git a/modules/libpref/src/init/all.js b/modules/libpref/src/init/all.js index 930bb2073171..ce1fd6cac71b 100644 --- a/modules/libpref/src/init/all.js +++ b/modules/libpref/src/init/all.js @@ -3744,8 +3744,9 @@ pref("dom.mozSettings.enabled", false); pref("dom.mozPermissionSettings.enabled", false); // W3C touch events +// 0 - disabled, 1 - enabled, 2 - autodetect (win) #ifdef XP_WIN -pref("dom.w3c_touch_events.enabled", true); +pref("dom.w3c_touch_events.enabled", 2); #endif // enable JS dump() function. diff --git a/widget/windows/nsLookAndFeel.cpp b/widget/windows/nsLookAndFeel.cpp index ab37d44b0435..a3210764884b 100644 --- a/widget/windows/nsLookAndFeel.cpp +++ b/widget/windows/nsLookAndFeel.cpp @@ -39,18 +39,22 @@ static int32_t GetSystemParam(long flag, int32_t def) return ::SystemParametersInfo(flag, 0, &value, 0) ? value : def; } -static int32_t IsTouchPresent() +namespace mozilla { +namespace widget { +// This is in use here and in nsDOMTouchEvent.cpp +int32_t IsTouchDeviceSupportPresent() { int32_t touchCapabilities; touchCapabilities = ::GetSystemMetrics(SM_DIGITIZER); return ((touchCapabilities & NID_READY) && (touchCapabilities & (NID_EXTERNAL_TOUCH | NID_INTEGRATED_TOUCH))); } +} } nsLookAndFeel::nsLookAndFeel() : nsXPLookAndFeel() { mozilla::Telemetry::Accumulate(mozilla::Telemetry::TOUCH_ENABLED_DEVICE, - IsTouchPresent()); + IsTouchDeviceSupportPresent()); } nsLookAndFeel::~nsLookAndFeel() @@ -376,7 +380,7 @@ nsLookAndFeel::GetIntImpl(IntID aID, int32_t &aResult) aResult = !IsAppThemed(); break; case eIntID_TouchEnabled: - aResult = IsTouchPresent(); + aResult = IsTouchDeviceSupportPresent(); break; case eIntID_WindowsDefaultTheme: aResult = nsUXThemeData::IsDefaultWindowTheme();