From 147e5bba1a9821ac68be9461c83af6263b426b60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 30 Mar 2011 11:30:07 +0000 Subject: [PATCH] some refactoring in the touch-specific code of draw handlers, r=sbrunner (closes #3208) git-svn-id: http://svn.openlayers.org/trunk/openlayers@11773 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Handler/Path.js | 40 +++++++++++++++++++++++++- lib/OpenLayers/Handler/Point.js | 50 +++++---------------------------- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/lib/OpenLayers/Handler/Path.js b/lib/OpenLayers/Handler/Path.js index cdc286b12c..20d997332c 100644 --- a/lib/OpenLayers/Handler/Path.js +++ b/lib/OpenLayers/Handler/Path.js @@ -44,6 +44,12 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { */ freehandToggle: 'shiftKey', + /** + * Property: timerId + * {Integer} The timer used to test the double touch. + */ + timerId: null, + /** * Constructor: OpenLayers.Handler.Path * Create a new path hander @@ -213,6 +219,38 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { return geometry; }, + /** + * method: touchstart + * handle touchstart. + * + * parameters: + * evt - {event} the browser event + * + * returns: + * {boolean} allow event propagation + */ + touchstart: function(evt) { + if (this.timerId && + this.passesTolerance(this.lastTouchPx, evt.xy, this.dblclickTolerance)) { + // double-tap, finalize the geometry + this.lastTouchPx = evt.xy; // for up() to detect dblclick and do nothing + this.finishTouchGeometry(); + window.clearTimeout(this.timerId); + this.timerId = null; + return false; + } else { + if (this.timerId) { + window.clearTimeout(this.timerId); + this.timerId = null; + } + this.timerId = window.setTimeout( + OpenLayers.Function.bind(function() { + this.timerId = null; + }, this), 300); + return OpenLayers.Handler.Point.prototype.touchstart.call(this, evt); + } + }, + /** * Method: mousedown * Handle mouse down. Add a new point to the geometry and @@ -295,7 +333,7 @@ OpenLayers.Handler.Path = OpenLayers.Class(OpenLayers.Handler.Point, { } this.stoppedDown = this.stopDown; this.mouseDown = false; - return !this.stopUp && !this.isDblclick; + return !this.stopUp; }, /** diff --git a/lib/OpenLayers/Handler/Point.js b/lib/OpenLayers/Handler/Point.js index fca102ebff..60b3ab585e 100644 --- a/lib/OpenLayers/Handler/Point.js +++ b/lib/OpenLayers/Handler/Point.js @@ -120,25 +120,12 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { touch: false, /** - * Property: timerId - * {Integer} The timer used to test the double touch. - */ - timerId: null, - - /** - * Property: last + * Property: lastTouchPx * {} The last pixel used to know the distance between * two touches (for double touch). */ - last: null, + lastTouchPx: null, - /** - * Property: dblclick - * {Boolean} The current event is a dblclick. - */ - isDblclick: false, - - /** * Constructor: OpenLayers.Handler.Point * Create a new point handler. @@ -281,6 +268,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { this.mouseDown = false; this.lastDown = null; this.lastUp = null; + this.lastTouchPx = null; this.callback(key, [this.geometryClone()]); if(cancel || !this.persist) { this.destroyFeature(); @@ -415,32 +403,8 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { */ touchstart: function(evt) { this.touch = true; - - var last = this.last; - this.last = evt.xy; - - if (this.timerId && - this.passesTolerance(last, evt.xy, this.dblclickTolerance)) { - this.isDblclick = true; - // a valid touch immediately adds a component and leaves us with a - // complete geometry - this.finishTouchGeometry(); - window.clearTimeout(this.timerId); - this.timerId = null; - return false; - } - else { - if (this.timerId) { - window.clearTimeout(this.timerId); - this.timerId = null; - } - this.isDblclick = false; - this.timerId = window.setTimeout( - OpenLayers.Function.bind(function() { - this.timerId = null; - }, this), 300); - return this.down(evt); - } + this.lastTouchPx = evt.xy; + return this.down(evt); }, /** @@ -471,7 +435,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { * {Boolean} Allow event propagation */ touchmove: function(evt) { - this.last = evt.xy; + this.lastTouchPx = evt.xy; return this.move(evt); }, @@ -503,7 +467,7 @@ OpenLayers.Handler.Point = OpenLayers.Class(OpenLayers.Handler, { * {Boolean} Allow event propagation */ touchend: function(evt) { - evt.xy = this.last; + evt.xy = this.lastTouchPx; return this.up(evt); },