Bug 590246 - Multitouch swipe gestures [r=mfinkle]
authorMatt Brubeck <mbrubeck@mozilla.com>
Wed, 25 Aug 2010 09:03:07 -0700
changeset 66491 df42ce97ff6a78a12b6f3e0f573c7a52720f5f6b
parent 66490 a65def5b42dad444a51cd1c16aa1d080b05dd2dd
child 66492 de3fe66f230096296672b3f02b12f244f3036e68
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs590246
Bug 590246 - Multitouch swipe gestures [r=mfinkle]
mobile/chrome/content/InputHandler.js
mobile/chrome/content/browser.js
--- a/mobile/chrome/content/InputHandler.js
+++ b/mobile/chrome/content/InputHandler.js
@@ -122,16 +122,17 @@ function InputHandler(browserViewContain
   this._suppressNextClick = false;
 
   /* these handle dragging of both chrome elements and content */
   window.addEventListener("mousedown", this, true);
   window.addEventListener("mouseup", this, true);
   window.addEventListener("mousemove", this, true);
   window.addEventListener("click", this, true);
   window.addEventListener("contextmenu", this, false);
+  window.addEventListener("MozSwipeGesture", this, true);
   window.addEventListener("MozMagnifyGestureStart", this, true);
   window.addEventListener("MozMagnifyGestureUpdate", this, true);
   window.addEventListener("MozMagnifyGesture", this, true);
 
   /* these handle key strokes in the browser view (where page content appears) */
   browserViewContainer.addEventListener("keypress", this, false);
   browserViewContainer.addEventListener("keyup", this, false);
   browserViewContainer.addEventListener("keydown", this, false);
@@ -1233,16 +1234,34 @@ GestureModule.prototype = {
    * receive gesture events.
    *
    * @param nsIDOMEvent information structure
    */
   handleEvent: function handleEvent(aEvent) {
     try {
       let consume = false;
       switch (aEvent.type) {
+        case "MozSwipeGesture":
+          let gesture = Ci.nsIDOMSimpleGestureEvent;
+          switch (aEvent.direction) {
+            case gesture.DIRECTION_UP:
+              Browser.scrollContentToTop();
+              break;
+            case gesture.DIRECTION_DOWN:
+              Browser.scrollContentToBottom();
+              break;
+            case gesture.DIRECTION_LEFT:
+              CommandUpdater.doCommand("cmd_back");
+              break;
+            case gesture.DIRECTION_RIGHT:
+              CommandUpdater.doCommand("cmd_forward");
+              break;
+          }
+          break;
+
         case "MozMagnifyGestureStart":
           consume = true;
           this._pinchStart(aEvent);
           break;
 
         case "MozMagnifyGestureUpdate":
           consume = true;
           if (this._ignoreNextUpdate)
--- a/mobile/chrome/content/browser.js
+++ b/mobile/chrome/content/browser.js
@@ -668,16 +668,28 @@ var Browser = {
   },
 
   scrollContentToTop: function scrollContentToTop() {
     this.contentScrollboxScroller.scrollTo(0, 0);
     this.pageScrollboxScroller.scrollTo(0, 0);
     this._browserView.onAfterVisibleMove();
   },
 
+  // cmd_scrollBottom does not work in Fennec (Bug 590535).
+  scrollContentToBottom: function scrollContentToTop() {
+    let x = {}, y = {};
+    this.contentScrollboxScroller.getScrolledSize(x, y);
+    this.contentScrollboxScroller.scrollTo(0, y.value);
+
+    this.pageScrollboxScroller.getScrolledSize(x, y);
+    this.pageScrollboxScroller.scrollTo(0, y.value);
+
+    this._browserView.onAfterVisibleMove();
+  },
+
   /** Let current browser's scrollbox know about where content has been panned. */
   scrollBrowserToContent: function scrollBrowserToContent() {
     let browser = this.selectedBrowser;
     if (browser) {
       let scroll = Browser.getScrollboxPosition(Browser.contentScrollboxScroller);
       browser.messageManager.sendAsyncMessage("Content:ScrollTo", { x: scroll.x, y: scroll.y });
     }
   },