[OpenLayers-Commits] r11827 - in trunk/openlayers:
lib/OpenLayers/Handler tests/Handler
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Thu Mar 31 05:01:07 EDT 2011
Author: sbrunner
Date: 2011-03-31 02:01:05 -0700 (Thu, 31 Mar 2011)
New Revision: 11827
Modified:
trunk/openlayers/lib/OpenLayers/Handler/Point.js
trunk/openlayers/tests/Handler/Point.html
Log:
Cleanup mouse event on touch devices, r=erilem (closes #3215)
Modified: trunk/openlayers/lib/OpenLayers/Handler/Point.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Handler/Point.js 2011-03-31 08:28:28 UTC (rev 11826)
+++ trunk/openlayers/lib/OpenLayers/Handler/Point.js 2011-03-31 09:01:05 UTC (rev 11827)
@@ -219,6 +219,7 @@
this.layer.destroy(false);
}
this.layer = null;
+ this.touch = false;
return true;
},
@@ -385,9 +386,6 @@
* {Boolean} Allow event propagation
*/
mousedown: function(evt) {
- if (this.touch) {
- return;
- }
return this.down(evt);
},
@@ -402,7 +400,18 @@
* {Boolean} Allow event propagation
*/
touchstart: function(evt) {
- this.touch = true;
+ if (!this.touch) {
+ this.touch = true;
+ // unregister mouse listeners
+ this.map.events.un({
+ mousedown: this.mousedown,
+ mouseup: this.mouseup,
+ mousemove: this.mousemove,
+ click: this.click,
+ dblclick: this.dblclick,
+ scope: this
+ });
+ }
this.lastTouchPx = evt.xy;
return this.down(evt);
},
@@ -418,9 +427,6 @@
* {Boolean} Allow event propagation
*/
mousemove: function(evt) {
- if (this.touch) {
- return;
- }
return this.move(evt);
},
@@ -450,9 +456,6 @@
* {Boolean} Allow event propagation
*/
mouseup: function(evt) {
- if (this.touch) {
- return;
- }
return this.up(evt);
},
Modified: trunk/openlayers/tests/Handler/Point.html
===================================================================
--- trunk/openlayers/tests/Handler/Point.html 2011-03-31 08:28:28 UTC (rev 11826)
+++ trunk/openlayers/tests/Handler/Point.html 2011-03-31 09:01:05 UTC (rev 11827)
@@ -417,6 +417,88 @@
"handler.point is null after destroy");
}
+ function test_touchstart(t) {
+ // a test to verify that the touchstart function does
+ // unregister the mouse listeners when it's called the
+ // first time
+
+ t.plan(4);
+
+ // set up
+
+ var map = new OpenLayers.Map("map", {
+ resolutions: [1]
+ });
+ var layer = new OpenLayers.Layer.Vector("foo", {
+ maxExtent: new OpenLayers.Bounds(-10, -10, 10, 10),
+ isBaseLayer: true
+ });
+ map.addLayer(layer);
+ var control = new OpenLayers.Control({});
+ var handler = new OpenLayers.Handler.Point(control, {});
+ control.handler = handler;
+ map.addControl(control);
+ map.setCenter(new OpenLayers.LonLat(0, 0), 0);
+ handler.activate();
+
+ function allRegistered() {
+ var eventTypes = ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick'],
+ eventType,
+ listeners,
+ listener,
+ flag;
+ for(var i=0, ilen=eventTypes.length; i<ilen; i++) {
+ flag = false;
+ eventType = eventTypes[i];
+ listeners = map.events.listeners[eventType];
+ for(var j=0, jlen=listeners.length; j<jlen; j++) {
+ listener = listeners[j];
+ if(listener.func === handler[eventType] && listener.obj === handler) {
+ flag = true;
+ break;
+ }
+ }
+ if(!flag) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ function noneRegistered() {
+ var eventTypes = ['mousedown', 'mouseup', 'mousemove', 'click', 'dblclick'],
+ eventType,
+ listeners,
+ listener;
+ for(var i=0, ilen=eventTypes.length; i<ilen; i++) {
+ eventType = eventTypes[i];
+ listeners = map.events.listeners[eventType];
+ for(var j=0, jlen=listeners.length; j<jlen; j++) {
+ listener = listeners[j];
+ if(listener.func === handler[eventType] && listener.obj === handler) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ // test
+
+ t.ok(allRegistered(), 'mouse listeners are registered');
+ handler.touchstart({xy: new OpenLayers.Pixel(0, 0)});
+ t.ok(noneRegistered(), 'mouse listeners are unregistered');
+ t.ok(handler.touch, 'handler.touch is set');
+
+ handler.deactivate();
+ t.ok(!handler.touch, 'handler.touch is not set');
+
+ // tear down
+
+ map.destroy();
+ }
+
+
//
// Sequence tests
//
More information about the Commits
mailing list