Bug 1302737 - Add rudimentary touch-scrolling support to the XUL scrollbox widget. r?jaws
MozReview-Commit-ID: 4aAnpDzMaRJ
--- 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