Bug 1302737 - Add rudimentary touch-scrolling support to the XUL scrollbox widget. r?jaws draft
authorKartikaya Gupta <kgupta@mozilla.com>
Tue, 27 Sep 2016 13:29:17 -0400
changeset 418074 bad907128e14038fd7a9bd95a3f9fa5fcb9b738a
parent 417914 66a77b9bfe5dcacd50eccf85de7c0e7e15ce0ffd
child 418075 be76c1a594098795e0559e647f1112a57bfc35c5
push id30580
push userkgupta@mozilla.com
push dateTue, 27 Sep 2016 17:30:01 +0000
reviewersjaws
bugs1302737
milestone52.0a1
Bug 1302737 - Add rudimentary touch-scrolling support to the XUL scrollbox widget. r?jaws MozReview-Commit-ID: 4aAnpDzMaRJ
toolkit/content/widgets/scrollbox.xml
--- a/toolkit/content/widgets/scrollbox.xml
+++ b/toolkit/content/widgets/scrollbox.xml
@@ -496,16 +496,18 @@
       </method>
 
       <!-- 0: idle
            1: scrolling right
           -1: scrolling left -->
       <field name="_isScrolling">0</field>
       <field name="_prevMouseScrolls">[null, null]</field>
 
+      <field name="_touchStart">-1</field>
+
       <method name="_stopSmoothScroll">
         <body><![CDATA[
           if (this._isScrolling) {
             this._scrollAnim.stop();
             this._isScrolling = 0;
             this._scrollTarget = null;
           }
         ]]></body>
@@ -586,16 +588,46 @@
             this._prevMouseScrolls.shift();
           this._prevMouseScrolls.push(isVertical);
         }
 
         event.stopPropagation();
         event.preventDefault();
       ]]></handler>
 
+      <handler event="touchstart"><![CDATA[
+        if (event.touches.length > 1) {
+          // Multiple touch points detected, abort.
+          this._touchStart = -1;
+        } else {
+          this._touchStart = (this.orient == "vertical"
+                ? event.touches[0].screenY
+                : event.touches[0].screenX);
+        }
+      ]]></handler>
+
+      <handler event="touchmove"><![CDATA[
+        if (event.touches.length == 1 &&
+            this._touchStart != -1) {
+          var touchPoint = (this.orient == "vertical"
+                ? event.touches[0].screenY
+                : event.touches[0].screenX);
+          var delta = this._touchStart - touchPoint;
+          if (Math.abs(delta) > 0) {
+            this.scrollByPixels(delta);
+            this._touchStart = touchPoint;
+          }
+          event.preventDefault();
+        }
+      ]]></handler>
+
+      <handler event="touchend"><![CDATA[
+        this._touchStart = -1;
+      ]]></handler>
+
       <handler event="underflow" phase="capturing"><![CDATA[
         // filter underflow events which were dispatched on nested scrollboxes
         if (event.target != this)
           return;
 
         // Ignore events that doesn't match our orientation.
         // Scrollport event orientation:
         //   0: vertical