[OpenLayers-Commits] r11507 - in trunk/openlayers:
lib/OpenLayers/Handler tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Fri Feb 25 09:53:00 EST 2011
Author: tschaub
Date: 2011-02-25 06:52:56 -0800 (Fri, 25 Feb 2011)
New Revision: 11507
Modified:
trunk/openlayers/lib/OpenLayers/Handler/Click.js
trunk/openlayers/tests/Handler/Click.html
Log:
Don't store touch events. The same event is used between touchstart, touchmove, and touchend. Instead, we store event details on the handler and use those when needed. p=bbinet, r=me (closes #3120)
Modified: trunk/openlayers/lib/OpenLayers/Handler/Click.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Click.js 2011-02-25 14:35:43 UTC (rev 11506)
+++ trunk/openlayers/lib/OpenLayers/Handler/Click.js 2011-02-25 14:52:56 UTC (rev 11507)
@@ -85,24 +85,23 @@
/**
* Property: down
- * {<OpenLayers.Pixel>} The pixel location of the last mousedown.
+ * {Object} Object that store relevant information about the last
+ * mousedown or touchstart. Its 'xy' OpenLayers.Pixel property gives
+ * the average location of the mouse/touch event. Its 'touches'
+ * property records clientX/clientY of each touches.
*/
down: null,
/**
* Property: last
- * {<OpenLayers.Pixel>} The pixel for the last touchmove. This is
- * used to
+ * {Object} Object that store relevant information about the last
+ * touchmove. Its 'xy' OpenLayers.Pixel property gives
+ * the average location of the mouse/touch event. Its 'touches'
+ * property records clientX/clientY of each touches.
*/
last: null,
/**
- * Property: touch
- * {Boolean} Are we on a touch enabled device? Default is false.
- */
- touch: false,
-
- /**
* Property: rightclickTimerId
* {Number} The id of the right mouse timeout waiting to clear the
* <delayedEvent>.
@@ -130,7 +129,7 @@
// optionally register for mouseup and mousedown
if(this.pixelTolerance != null) {
this.mousedown = function(evt) {
- this.down = evt;
+ this.down = this.getEventInfo(evt);
return true;
};
}
@@ -154,8 +153,7 @@
* {Boolean} Continue propagating this event.
*/
touchstart: function(evt) {
- this.touch = true;
- this.down = evt;
+ this.down = this.getEventInfo(evt);
this.last = null;
return true;
},
@@ -244,8 +242,9 @@
dblclick: function(evt) {
// for touch devices trigger dblclick only for
// "one finger" touch
- if(this.passesTolerance(evt) &&
- (!evt.lastTouches || evt.lastTouches.length == 1)) {
+ var last = this.down || this.last;
+ if (this.passesTolerance(evt) &&
+ (!last || !last.touches || last.touches.length == 1)) {
if(this["double"]) {
this.callback('dblclick', [evt]);
}
@@ -260,7 +259,7 @@
* an empty "touches" property.
*/
touchmove: function(evt) {
- this.last = evt;
+ this.last = this.getEventInfo(evt);
},
/**
@@ -287,13 +286,14 @@
*/
click: function(evt) {
// Sencha Touch emulates click events, see ticket 3079 for more info
- if (this.touch === true && evt.type === "click") {
+ if (this.down && this.down.touches && evt.type === "click") {
return !this.stopSingle;
}
if(this.passesTolerance(evt)) {
if(this.timerId != null) {
// already received a click
- if(evt.lastTouches) {
+ var last = this.down || this.last;
+ if (last && last.touches && last.touches.length > 0) {
// touch device - we may trigger dblclick
this.dblclick(evt);
} else {
@@ -367,6 +367,35 @@
},
/**
+ * Method: getEventInfo
+ * This method allows us to store event information without storing the
+ * actual event. In touch devices (at least), the same event is
+ * modified between touchstart, touchmove, and touchend.
+ *
+ * Returns:
+ * {Object} An object with event related info.
+ */
+ getEventInfo: function(evt) {
+ var touches;
+ if (evt.touches) {
+ var len = evt.touches.length;
+ touches = new Array(len);
+ var touch;
+ for (var i=0; i<len; i++) {
+ touch = evt.touches[i];
+ touches[i] = {
+ clientX: touch.clientX,
+ clientY: touch.clientY
+ };
+ }
+ }
+ return {
+ xy: evt.xy,
+ touches: touches
+ };
+ },
+
+ /**
* APIMethod: deactivate
* Deactivate the handler.
*
Modified: trunk/openlayers/tests/Handler/Click.html
===================================================================
--- trunk/openlayers/tests/Handler/Click.html 2011-02-25 14:35:43 UTC (rev 11506)
+++ trunk/openlayers/tests/Handler/Click.html 2011-02-25 14:52:56 UTC (rev 11507)
@@ -316,14 +316,14 @@
log = null;
handler.touchstart({xy: {x: 1, y: 1}, touches: ["foo"]});
- handler.touchend({});
+ handler.touchend({touches: ["foo"]});
t.delay_call(1, function() {
t.ok(log != null, "click callback called");
if(log != null) {
t.eq(log.x, 1, "evt.xy.x as expected");
t.eq(log.y, 1, "evt.xy.y as expected");
- t.eq(log.lastTouches, ["foo"], "evt.lastTouches as expected");
+ t.ok(log.lastTouches, "evt.lastTouches as expected");
}
// tear down
map.destroy();
@@ -359,7 +359,7 @@
handler.touchstart({xy: {x: 1, y: 1}, touches: ["foo"]});
handler.touchend({type: "click"});
- t.eq(handler.touch, true, "Touch property should be true");
+ t.eq(!!handler.down.touches, true, "Handler down touches property should be truthy");
t.ok(log.dblclick == undefined, "dblclick callback not called with simulated click");
@@ -395,9 +395,9 @@
// test
log = {};
- handler.touchstart({xy: {x: 1, y: 1}, touches: ["foo"]});
+ handler.touchstart({xy: {x: 1, y: 1}, touches: [{clientX:0, clientY:10}]});
handler.touchend({});
- handler.touchstart({xy: {x: 1, y: 1}, touches: ["foo"]});
+ handler.touchstart({xy: {x: 1, y: 1}, touches: [{clientX:0, clientY:10}]});
handler.touchend({});
t.eq(log.click, undefined, "click callback not called");
@@ -405,7 +405,7 @@
if(log.dblclick != undefined) {
t.eq(log.dblclick.x, 1, "evt.xy.x as expected");
t.eq(log.dblclick.y, 1, "evt.xy.y as expected");
- t.eq(log.dblclick.lastTouches, ["foo"], "evt.lastTouches as expected");
+ t.ok(log.dblclick.lastTouches, "evt.lastTouches on evt");
}
// tear down
More information about the Commits
mailing list