Bug 798821 - On Windows, restrict enabling of W3C touch interfaces to devices that support touch input. Also convert touch pref to 3-state value. r=bsmedberg
authorJim Mathies <jmathies@mozilla.com>
Thu, 25 Oct 2012 09:57:51 -0500
changeset 120031 321ee246dc593e22d31d3a63109269e19dc6b213
parent 120030 a46d4906eee8d1db1a48f4fed5f6afd1cc292f8e
child 120032 a20072899a97aba0a18e34d3c653382776fccf38
push id273
push userlsblakk@mozilla.com
push dateThu, 14 Feb 2013 23:19:38 +0000
treeherdermozilla-release@c5e807a3f8b8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg
bugs798821
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 798821 - On Windows, restrict enabling of W3C touch interfaces to devices that support touch input. Also convert touch pref to 3-state value. r=bsmedberg
b2g/app/b2g.js
build/automation.py.in
content/events/src/nsDOMTouchEvent.cpp
dom/browser-element/BrowserElementParent.js
dom/browser-element/mochitest/browserElement_SendEvent.js
mobile/android/app/mobile.js
mobile/xul/app/mobile.js
mobile/xul/chrome/content/content.js
modules/libpref/src/init/all.js
widget/windows/nsLookAndFeel.cpp
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -268,17 +268,17 @@ pref("widget.ime.android.fullscreen_thre
 
 // optimize images' memory usage
 pref("image.mem.decodeondraw", true);
 pref("content.image.allow_locking", false);
 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"
 
 #ifdef MOZ_SAFE_BROWSING
 // Safe browsing does nothing unless this pref is set
 pref("browser.safebrowsing.enabled", true);
 
 // Prevent loading of pages identified as malware
--- a/build/automation.py.in
+++ b/build/automation.py.in
@@ -402,17 +402,17 @@ user_pref("dom.min_background_timeout_va
 user_pref("test.mousescroll", true);
 user_pref("security.default_personal_cert", "Select Automatically"); // Need to client auth test be w/o any dialogs
 user_pref("network.http.prompt-temp-redirect", false);
 user_pref("media.cache_size", 100);
 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);
 user_pref("font.size.inflation.minTwips", 0);
 
 // Only load extensions from the application and user profile
 // AddonManager.SCOPE_PROFILE + AddonManager.SCOPE_APPLICATION
 user_pref("extensions.enabledScopes", 5);
--- a/content/events/src/nsDOMTouchEvent.cpp
+++ b/content/events/src/nsDOMTouchEvent.cpp
@@ -375,24 +375,45 @@ nsDOMTouchEvent::GetCtrlKey(bool* aCtrlK
 
 NS_IMETHODIMP
 nsDOMTouchEvent::GetShiftKey(bool* aShiftKey)
 {
   *aShiftKey = static_cast<nsInputEvent*>(mEvent)->IsShift();
   return NS_OK;
 }
 
+#ifdef XP_WIN
+namespace mozilla {
+namespace widget {
+extern int32_t IsTouchDeviceSupportPresent();
+} }
+#endif
+
 bool
 nsDOMTouchEvent::PrefEnabled()
 {
   static bool sDidCheckPref = false;
   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_WARNING("dom.w3c_touch_events.enabled=2 not implemented!");
+        sPrefValue = false;
+#endif
+      } else {
+        sPrefValue = !!flag;
+      }
+    }
     if (sPrefValue) {
       nsContentUtils::InitializeTouchEventTable();
     }
   }
   return sPrefValue;
 }
 
 nsresult
--- a/dom/browser-element/BrowserElementParent.js
+++ b/dom/browser-element/BrowserElementParent.js
@@ -30,16 +30,25 @@ function getBoolPref(prefName, def) {
   try {
     return Services.prefs.getBoolPref(prefName);
   }
   catch(err) {
     return 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)
     return;
 
   // Recursively expose our children.
   Object.keys(obj).forEach(function(key) {
     exposeAll(obj[key]);
@@ -231,17 +240,19 @@ function BrowserElementParent(frameLoade
         return self._sendDOMRequest(msgName);
       }
     };
   }
 
   // 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);
   defineMethod('goForward', this._goForward);
   defineMethod('reload', this._reload);
   defineMethod('stop', this._stop);
   defineMethod('getScreenshot', this._getScreenshot);
   defineDOMRequestMethod('getCanGoBack', 'get-can-go-back');
--- a/dom/browser-element/mochitest/browserElement_SendEvent.js
+++ b/dom/browser-element/mochitest/browserElement_SendEvent.js
@@ -31,17 +31,17 @@ function runTest() {
         ok(true, "Receive a mousemove event.");
         iframe.sendMouseEvent("mouseup", 10, 10, 0, 1, 0);
         break;
       case "#mouseup":
         ok(true, "Receive a mouseup event.");
         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 {
           SimpleTest.finish();
         }
         break;
       case "#touchstart":
         ok(true, "Receive a touchstart event.");
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -542,17 +542,17 @@ pref("widget.ime.android.landscape_fulls
 pref("widget.ime.android.fullscreen_threshold", 250); // in hundreths of inches
 
 // optimize images memory usage
 pref("image.mem.decodeondraw", true);
 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);
 pref("browser.safebrowsing.malware.enabled", true);
 pref("browser.safebrowsing.debug", false);
 
 pref("browser.safebrowsing.updateURL", "http://safebrowsing.clients.google.com/safebrowsing/downloads?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2");
 pref("browser.safebrowsing.keyURL", "https://sb-ssl.google.com/safebrowsing/newkey?client=SAFEBROWSING_ID&appver=%VERSION%&pver=2.2");
--- a/mobile/xul/app/mobile.js
+++ b/mobile/xul/app/mobile.js
@@ -574,17 +574,17 @@ pref("widget.ime.android.landscape_fulls
 pref("widget.ime.android.fullscreen_threshold", 250); // in hundreths of inches
 
 // optimize images memory usage
 pref("image.mem.decodeondraw", true);
 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"
 
 #ifdef MOZ_SAFE_BROWSING
 // Safe browsing does nothing unless this pref is set
 pref("browser.safebrowsing.enabled", true);
 
 // Prevent loading of pages identified as malware
--- a/mobile/xul/chrome/content/content.js
+++ b/mobile/xul/chrome/content/content.js
@@ -1361,17 +1361,17 @@ var TouchEventHandler = {
       // first "touchmove" event.  After it's cancelled, it stays cancelled
       // until the next touchstart event.
       if (cancelled || aMessage.name == "Browser:MouseMove")
         this.isCancellable = false;
     }
   },
 
   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");
     let scrollOffset = ContentScroll.getScrollOffset(aElement.ownerDocument.defaultView);
     let point = content.document.createTouch(content, aElement, 0,
                                              aData.x, aData.y, aData.x, aData.y, aData.x - scrollOffset.x, aData.y - scrollOffset.y,
                                              1, 1, 0, 0);
     let touches = content.document.createTouchList(point);
--- a/modules/libpref/src/init/all.js
+++ b/modules/libpref/src/init/all.js
@@ -3745,18 +3745,19 @@ pref("dom.mozAlarms.enabled", false);
 // WebNetworkStats
 pref("dom.mozNetworkStats.enabled", false);
 
 // WebSettings
 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.
 pref("browser.dom.window.dump.enabled", false);
 
 // SPS Profiler
 pref("profiler.enabled", false);
 pref("profiler.interval", 10);
--- a/widget/windows/nsLookAndFeel.cpp
+++ b/widget/windows/nsLookAndFeel.cpp
@@ -34,28 +34,32 @@ static nsresult GetColorFromTheme(nsUXTh
 }
 
 static int32_t GetSystemParam(long flag, int32_t def)
 {
     DWORD value; 
     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()
 {
 }
 
 nsresult
 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
@@ -371,17 +375,17 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
         break;
     case eIntID_TreeScrollLinesMax:
         aResult = 3;
         break;
     case eIntID_WindowsClassic:
         aResult = !IsAppThemed();
         break;
     case eIntID_TouchEnabled:
-        aResult = IsTouchPresent();
+        aResult = IsTouchDeviceSupportPresent();
         break;
     case eIntID_WindowsDefaultTheme:
         aResult = nsUXThemeData::IsDefaultWindowTheme();
         break;
     case eIntID_WindowsThemeIdentifier:
         aResult = nsUXThemeData::GetNativeThemeId();
         break;
     case eIntID_MacGraphiteTheme: