Bug 751147 - Remove touch.js from b2g/. r=gal
authorVivien Nicolas <21@vingtetun.org>
Fri, 04 May 2012 20:02:05 +0200
changeset 93202 f40b62992061606735aed9cfd0c997ed374ee09e
parent 93201 9b5be1d4148980c45f20b7f9273cb3cc26db22c9
child 93203 720241124387467888b3727b66b655846b2087a9
push id22616
push userMs2ger@gmail.com
push dateSat, 05 May 2012 08:59:35 +0000
treeherdermozilla-central@ea4c62f4c063 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgal
bugs751147
milestone15.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 751147 - Remove touch.js from b2g/. r=gal
b2g/chrome/content/shell.xul
b2g/chrome/content/touch.js
b2g/chrome/jar.mn
--- a/b2g/chrome/content/shell.xul
+++ b/b2g/chrome/content/shell.xul
@@ -11,19 +11,16 @@
 #ifdef ANDROID
         sizemode="fullscreen"
 #endif
         style="background: black; overflow: hidden;"
         onload="shell.start();"
         onunload="shell.stop();">
 
   <script type="application/javascript" src="chrome://browser/content/shell.js"/>
-#ifndef MOZ_TOUCH
-  <script type="application/javascript" src="chrome://browser/content/touch.js"/>
-#endif
 
   <browser id="homescreen"
            type="content-primary"
            flex="1"
            style="overflow: hidden;"
            src="data:text/html;charset=utf-8,%3C!DOCTYPE html>%3Cbody style='background:black;'>"/>
 </window>
 
deleted file mode 100644
--- a/b2g/chrome/content/touch.js
+++ /dev/null
@@ -1,201 +0,0 @@
-/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /
-/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-(function touchEventHandler() {
-  let debugging = false;
-  function debug(str) {
-    if (debugging)
-      dump(str + '\n');
-  };
-
-  let contextMenuTimeout = 0;
-
-  // This guard is used to not re-enter the events processing loop for
-  // self dispatched events
-  let ignoreEvents = false;
-
-  // During a 'touchstart' and the first 'touchmove' mouse events can be
-  // prevented for the current touch sequence.
-  let canPreventMouseEvents = false;
-
-  // Used to track the first mousemove and to cancel click dispatc if it's not
-  // true.
-  let isNewTouchAction = false;
-
-  // If this is set to true all mouse events will be cancelled by calling
-  // both evt.preventDefault() and evt.stopPropagation().
-  // This will not prevent a contextmenu event to be fired.
-  // This can be turned on if canPreventMouseEvents is true and the consumer
-  // application call evt.preventDefault();
-  let preventMouseEvents = false;
-
-  let TouchEventHandler = {
-    events: ['mousedown', 'mousemove', 'mouseup', 'click', 'unload'],
-    start: function teh_start() {
-      this.events.forEach((function(evt) {
-        shell.contentBrowser.addEventListener(evt, this, true);
-      }).bind(this));
-    },
-    stop: function teh_stop() {
-      this.events.forEach((function(evt) {
-        shell.contentBrowser.removeEventListener(evt, this, true);
-      }).bind(this));
-    },
-    handleEvent: function teh_handleEvent(evt) {
-      if (evt.button || ignoreEvents)
-        return;
-
-      let eventTarget = this.target;
-      let type = '';
-      switch (evt.type) {
-        case 'mousedown':
-          debug('mousedown:');
-
-          this.target = evt.target;
-          this.timestamp = evt.timeStamp;
-
-          preventMouseEvents = false;
-          canPreventMouseEvents = true;
-          isNewTouchAction = true;
-
-          contextMenuTimeout =
-            this.sendContextMenu(evt.target, evt.pageX, evt.pageY, 2000);
-          this.startX = evt.pageX;
-          this.startY = evt.pageY;
-          type = 'touchstart';
-          break;
-
-        case 'mousemove':
-          if (!eventTarget)
-            return;
-
-          // On device a mousemove event if fired right after the mousedown
-          // because of the size of the finger, so let's ignore what happens
-          // below 5ms
-          if (evt.timeStamp - this.timestamp < 30)
-            break;
-
-          if (isNewTouchAction) {
-            canPreventMouseEvents = true;
-            isNewTouchAction = false;
-          }
-
-          if (Math.abs(this.startX - evt.pageX) > 15 ||
-              Math.abs(this.startY - evt.pageY) > 15)
-            window.clearTimeout(contextMenuTimeout);
-          type = 'touchmove';
-          break;
-
-        case 'mouseup':
-          if (!eventTarget)
-            return;
-          debug('mouseup:');
-
-          window.clearTimeout(contextMenuTimeout);
-          this.target = null;
-          type = 'touchend';
-          break;
-
-        case 'unload':
-          if (!eventTarget)
-            return;
-
-          window.clearTimeout(contextMenuTimeout);
-          this.target = null;
-          TouchEventHandler.stop();
-          return;
-
-        case 'click':
-          if (isNewTouchAction) {
-            // Mouse events has been cancelled so dispatch a sequence
-            // of events to where touchend has been fired
-            if (preventMouseEvents) {
-              evt.preventDefault();
-              evt.stopPropagation();
-
-              let target = evt.target;
-              ignoreEvents = true;
-              window.setTimeout(function dispatchMouseEvents(self) {
-                self.fireMouseEvent('mousemove', evt);
-                self.fireMouseEvent('mousedown', evt);
-                self.fireMouseEvent('mouseup', evt);
-                ignoreEvents = false;
-              }, 0, this);
-            }
-
-            debug('click: fire');
-          }
-          return;
-      }
-
-      let target = eventTarget || this.target;
-      if (target && type) {
-        let touchEvent = this.sendTouchEvent(evt, target, type);
-        if (touchEvent.defaultPrevented && canPreventMouseEvents)
-          preventMouseEvents = true;
-      }
-
-      if (preventMouseEvents) {
-        evt.preventDefault();
-        evt.stopPropagation();
-
-        if (type != 'touchmove')
-          debug('cancelled (fire ' + type + ')');
-      }
-    },
-    fireMouseEvent: function teh_fireMouseEvent(type, evt)  {
-      debug(type + ': fire');
-
-      let content = evt.target.ownerDocument.defaultView;
-      var utils = content.QueryInterface(Ci.nsIInterfaceRequestor)
-                         .getInterface(Ci.nsIDOMWindowUtils);
-      utils.sendMouseEvent(type, evt.pageX, evt.pageY, 0, 1, 0, true);
-    },
-    sendContextMenu: function teh_sendContextMenu(target, x, y, delay) {
-      let doc = target.ownerDocument;
-      let evt = doc.createEvent('MouseEvent');
-      evt.initMouseEvent('contextmenu', true, true, doc.defaultView,
-                         0, x, y, x, y, false, false, false, false,
-                         0, null);
-
-      let timeout = window.setTimeout((function contextMenu() {
-        debug('fire context-menu');
-
-        target.dispatchEvent(evt);
-        if (!evt.defaultPrevented)
-          return;
-
-        doc.releaseCapture();
-        this.target = null;
-
-        isNewTouchAction = false;
-      }).bind(this), delay);
-      return timeout;
-    },
-    sendTouchEvent: function teh_sendTouchEvent(evt, target, name) {
-      let touchEvent = document.createEvent('touchevent');
-      let point = document.createTouch(window, target, 0,
-                                     evt.pageX, evt.pageY,
-                                     evt.screenX, evt.screenY,
-                                     evt.clientX, evt.clientY,
-                                     1, 1, 0, 0);
-      let touches = document.createTouchList(point);
-      let targetTouches = touches;
-      let changedTouches = touches;
-      touchEvent.initTouchEvent(name, true, true, window, 0,
-                                false, false, false, false,
-                                touches, targetTouches, changedTouches);
-      target.dispatchEvent(touchEvent);
-      return touchEvent;
-    }
-  };
-
-  window.addEventListener('ContentStart', function touchStart(evt) {
-    window.removeEventListener('ContentStart', touchStart);
-    TouchEventHandler.start();
-  });
-})();
-
--- a/b2g/chrome/jar.mn
+++ b/b2g/chrome/jar.mn
@@ -2,19 +2,16 @@
 
 chrome.jar:
 % content branding %content/branding/
 % content browser %content/
 
   content/dbg-browser-actors.js         (content/dbg-browser-actors.js)
 * content/shell.xul                     (content/shell.xul)
 * content/shell.js                      (content/shell.js)
-#ifndef MOZ_TOUCH
-  content/touch.js                      (content/touch.js)
-#endif
   content/webapi.js                     (content/webapi.js)
   content/content.css                   (content/content.css)
 
 % override chrome://global/content/netError.xhtml chrome://browser/content/netError.xhtml
 % override chrome://global/skin/netError.css chrome://browser/content/netError.css
   content/netError.xhtml                (content/netError.xhtml)
   content/netError.css                  (content/netError.css)
   content/images/errorpage-larry-black.png (content/images/errorpage-larry-black.png)