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:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user