From 68ad14a047973f3c395d7a10ad8ce93f4d809fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Fri, 9 Jan 2009 09:12:37 +0000 Subject: [PATCH] Handler.RegularPolygon doesn't always call the "done" callback, r=tschaub (closes #1857) git-svn-id: http://svn.openlayers.org/trunk/openlayers@8616 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Handler/RegularPolygon.js | 6 +++++ tests/Handler/RegularPolygon.html | 34 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/OpenLayers/Handler/RegularPolygon.js b/lib/OpenLayers/Handler/RegularPolygon.js index 318564e13f..114f294582 100644 --- a/lib/OpenLayers/Handler/RegularPolygon.js +++ b/lib/OpenLayers/Handler/RegularPolygon.js @@ -274,6 +274,12 @@ OpenLayers.Handler.RegularPolygon = OpenLayers.Class(OpenLayers.Handler.Drag, { */ up: function(evt) { this.finalize(); + // the mouseup method of superclass doesn't call the + // "done" callback if there's been no move between + // down and up + if (this.start == this.last) { + this.callback("done", [evt.xy]); + } }, /** diff --git a/tests/Handler/RegularPolygon.html b/tests/Handler/RegularPolygon.html index 32fd0684e8..21e6c3684c 100644 --- a/tests/Handler/RegularPolygon.html +++ b/tests/Handler/RegularPolygon.html @@ -186,6 +186,40 @@ handler.move({xy: {x: 20, y: 15}}); } + function test_callbacks(t) { + t.plan(1); + + // setup + var map = new OpenLayers.Map("map", { + getLonLatFromPixel: function(px) { + return {lon: px.x, lat: px.y}; + } + }); + + var control = {"map": map}; + + var done = function(geom) { + t.ok(true, + "done callback called even if no move between down and up"); + }; + + var handler = new OpenLayers.Handler.RegularPolygon( + control, {"done": done}); + handler.activate(); + + var xy = new OpenLayers.Pixel(Math.random(), Math.random()); + + var isLeftClick = OpenLayers.Event.isLeftClick; + OpenLayers.Event.isLeftClick = function() { return true; }; + + // test + map.events.triggerEvent("mousedown", {"xy": xy}); + map.events.triggerEvent("mouseup", {"xy": xy}); + + // tear down + OpenLayers.Event.isLeftClick = isLeftClick; + } +