Bug 1302736 - Add rudimentary touch-scrolling support to the XUL tree widget. r=dao
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 29 Sep 2016 10:05:24 -0400
changeset 315833 7de1a998b12ee384adec77550f7364eef1283660
parent 315832 fe97a239ab5a2c8111712ca86a9ed3fdb5f4e942
child 315834 40b602b3a8701ad3a4323072cb64a2d40a97c65a
push id30757
push usercbook@mozilla.com
push dateFri, 30 Sep 2016 10:02:43 +0000
treeherdermozilla-central@5ffed033557e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1302736
milestone52.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 1302736 - Add rudimentary touch-scrolling support to the XUL tree widget. r=dao MozReview-Commit-ID: 7dHpl3EsRZk
toolkit/content/widgets/tree.xml
--- a/toolkit/content/widgets/tree.xml
+++ b/toolkit/content/widgets/tree.xml
@@ -125,16 +125,18 @@
 
       <property name="_selectDelay"
                 onset="this.setAttribute('_selectDelay', val);"
                 onget="return this.getAttribute('_selectDelay') || 50;"/>
       <field name="_columnsDirty">true</field>
       <field name="_lastKeyTime">0</field>
       <field name="_incrementalString">""</field>
 
+      <field name="_touchY">-1</field>
+
       <method name="_ensureColumnOrder">
         <body><![CDATA[
           if (!this._columnsDirty)
             return;
 
           if (this.columns) {
             // update the ordinal position of each column to assure that it is
             // an odd number and 2 positions above its next sibling
@@ -679,16 +681,50 @@
             }
           }
           return this.changeOpenState(this.currentIndex);
         ]]></body>
       </method>
     </implementation>
 
     <handlers>
+      <handler event="touchstart">
+        <![CDATA[
+          if (event.touches.length > 1) {
+            // Multiple touch points detected, abort. In particular this aborts
+            // the panning gesture when the user puts a second finger down after
+            // already panning with one finger. Aborting at this point prevents
+            // the pan gesture from being resumed until all fingers are lifted
+            // (as opposed to when the user is back down to one finger).
+            this._touchY = -1;
+          } else {
+            this._touchY = event.touches[0].screenY;
+          }
+        ]]>
+      </handler>
+      <handler event="touchmove">
+        <![CDATA[
+          if (event.touches.length == 1 &&
+              this._touchY >= 0) {
+            var deltaY = this._touchY - event.touches[0].screenY;
+            var lines = Math.trunc(deltaY / this.treeBoxObject.rowHeight);
+            if (Math.abs(lines) > 0) {
+              this.treeBoxObject.scrollByLines(lines);
+              deltaY -= lines * this.treeBoxObject.rowHeight;
+              this._touchY = event.touches[0].screenY + deltaY;
+            }
+            event.preventDefault();
+          }
+        ]]>
+      </handler>
+      <handler event="touchend">
+        <![CDATA[
+          this._touchY = -1;
+        ]]>
+      </handler>
       <handler event="MozMousePixelScroll" preventdefault="true"/>
       <handler event="DOMMouseScroll" preventdefault="true">
         <![CDATA[
           if (this._editingColumn)
             return;
           if (event.axis == event.HORIZONTAL_AXIS)
             return;