Bug 891882 - Enable touch event on B2G desktop r=vingtetun
☠☠ backed out by 37f9b4003991 ☠ ☠
authorFabrice Desré <fabrice@mozilla.com>
Wed, 06 Nov 2013 11:05:07 -0800
changeset 153839 8233d40249e06cb7a9c3d9f3dc6e8148d104d282
parent 153838 ed53f428d0f26a8aa83ba208fa85be4f9ece7014
child 153840 eb54f180488ea8e0f7ebb5fa63f98208af4a464c
push id2168
push userfdesre@mozilla.com
push dateWed, 06 Nov 2013 23:04:31 +0000
treeherderb2g-inbound@8233d40249e0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvingtetun
bugs891882
milestone28.0a1
Bug 891882 - Enable touch event on B2G desktop r=vingtetun
b2g/app/b2g.js
b2g/chrome/content/shell.js
toolkit/devtools/touch-events.js
--- a/b2g/app/b2g.js
+++ b/b2g/app/b2g.js
@@ -282,24 +282,20 @@ pref("media.video-queue.default-size", 3
 
 // optimize images' memory usage
 pref("image.mem.decodeondraw", true);
 pref("image.mem.allow_locking_in_content_processes", false); /* don't allow image locking */
 pref("image.mem.min_discard_timeout_ms", 86400000); /* 24h, we rely on the out of memory hook */
 pref("image.mem.max_decoded_image_kb", 30000); /* 30MB seems reasonable */
 pref("image.onload.decode.limit", 24); /* don't decode more than 24 images eagerly */
 
-// XXX this isn't a good check for "are touch events supported", but
-// we don't really have a better one at the moment.
-#ifdef MOZ_WIDGET_GONK
 // enable touch events interfaces
 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"
-#endif
 
 #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
 pref("browser.safebrowsing.malware.enabled", true);
 
--- a/b2g/chrome/content/shell.js
+++ b/b2g/chrome/content/shell.js
@@ -623,16 +623,37 @@ var shell = {
       shell.isHomeLoaded = true;
 
 #ifdef MOZ_WIDGET_GONK
       libcutils.property_set('sys.boot_completed', '1');
 #endif
 
       Services.obs.notifyObservers(null, "browser-ui-startup-complete", "");
 
+#ifndef MOZ_WIDGET_GONK
+      let require = Cu.import("resource://gre/modules/devtools/Loader.jsm", {})
+                      .devtools.require;
+      let { TouchEventHandler } = require("devtools/touch-events");
+      let frame = content.QueryInterface(Ci.nsIInterfaceRequestor)
+                         .getInterface(Ci.nsIWebNavigation)
+                         .QueryInterface(Ci.nsIDocShell).chromeEventHandler;
+      let scope = {
+        addEventListener:
+          function(type, fun, capture) {
+            frame.addEventListener(type, fun, capture);
+          },
+        removeEventListener:
+          function(type, fun) {
+            frame.removeEventListener(type, fun);
+          }
+      };
+      let touchEventHandler = new TouchEventHandler(scope);
+      touchEventHandler.start();
+#endif
+
       if ('pendingChromeEvents' in shell) {
         shell.pendingChromeEvents.forEach((shell.sendChromeEvent).bind(shell));
       }
       delete shell.pendingChromeEvents;
     });
   }
 };
 
--- a/toolkit/devtools/touch-events.js
+++ b/toolkit/devtools/touch-events.js
@@ -154,16 +154,28 @@ function TouchEventHandler (window) {
       let timeout = content.setTimeout((function contextMenu() {
         target.dispatchEvent(evt);
         this.cancelClick = true;
       }).bind(this), delay);
 
       return timeout;
     },
     sendTouchEvent: function teh_sendTouchEvent(evt, target, name) {
+      // When running OOP b2g desktop, we need to send the touch events
+      // using the mozbrowser api on the unwrapped frame.
+      if (target.localName == "iframe" && target.mozbrowser === true) {
+        let unwraped = XPCNativeWrapper.unwrap(target);
+        unwraped.sendTouchEvent(name, [0],                // event type, id
+                                [evt.pageX], [evt.pageY], // x, y
+                                [1], [1],                 // rx, ry
+                                [0], [0],                 // rotation, force
+                                1);                       // count
+        return;
+      }
+
       let document = target.ownerDocument;
       let content = this.getContent(target);
 
       let touchEvent = document.createEvent('touchevent');
       let point = document.createTouch(content, target, 0,
                                        evt.pageX, evt.pageY,
                                        evt.screenX, evt.screenY,
                                        evt.clientX, evt.clientY,