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)

git-svn-id: http://svn.openlayers.org/trunk/openlayers@11507 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf
This commit is contained in:
Tim Schaub
2011-02-25 14:52:56 +00:00
parent b34dbcb903
commit 960ef3de18
2 changed files with 52 additions and 23 deletions

View File

@@ -85,23 +85,22 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
/**
* 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
@@ -130,7 +129,7 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
// 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 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
* {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 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
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 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
* an empty "touches" property.
*/
touchmove: function(evt) {
this.last = evt;
this.last = this.getEventInfo(evt);
},
/**
@@ -287,13 +286,14 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
*/
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 {
@@ -366,6 +366,35 @@ OpenLayers.Handler.Click = OpenLayers.Class(OpenLayers.Handler, {
}
},
/**
* 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.