From ad4044cd3b7327f8437dd4869cdbd116b0e45bb4 Mon Sep 17 00:00:00 2001 From: Tim Schaub Date: Wed, 19 Sep 2007 21:01:04 +0000 Subject: [PATCH] Make the drag handler tidy up after itself a bit more. This solves the click blocking after shift-drag issue (see #1003). git-svn-id: http://svn.openlayers.org/trunk/openlayers@4400 dc9f47b5-9b13-0410-9fdd-eb0c1a62fdaf --- lib/OpenLayers/Handler/Drag.js | 11 +++++++--- tests/Handler/test_Drag.html | 38 +++++++++++++++++++++++++++++++--- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/lib/OpenLayers/Handler/Drag.js b/lib/OpenLayers/Handler/Drag.js index 0a49ed911e..4dc74911a6 100644 --- a/lib/OpenLayers/Handler/Drag.js +++ b/lib/OpenLayers/Handler/Drag.js @@ -143,9 +143,10 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { * {Boolean} Let the event propagate. */ mousedown: function (evt) { + var propagate = true; + this.dragging = false; if (this.checkModifiers(evt) && OpenLayers.Event.isLeftClick(evt)) { this.started = true; - this.dragging = false; this.start = evt.xy; this.last = evt.xy; // TBD replace with CSS classes @@ -159,9 +160,13 @@ OpenLayers.Handler.Drag = OpenLayers.Class(OpenLayers.Handler, { document.onselectstart = function() {return false;} } - return false; + propagate = false; + } else { + this.started = false; + this.start = null; + this.last = null; } - return true; + return propagate; }, /** diff --git a/tests/Handler/test_Drag.html b/tests/Handler/test_Drag.html index 843e9dd1e7..f681a21e62 100644 --- a/tests/Handler/test_Drag.html +++ b/tests/Handler/test_Drag.html @@ -87,7 +87,7 @@ } function test_Handler_Drag_callbacks(t) { - t.plan(27); + t.plan(33); var map = new OpenLayers.Map('map', {controls: []}); @@ -115,10 +115,41 @@ var handler = new OpenLayers.Handler.Drag(control, callbacks); handler.activate(); - // test mousedown var oldIsLeftClick = OpenLayers.Event.isLeftClick; var oldStop = OpenLayers.Event.stop; var oldCheckModifiers = handler.checkModifiers; + + // test mousedown with right click + OpenLayers.Event.isLeftClick = function() { + return false; + } + handler.checkModifiers = function() { + return true; + } + handler.started = true; + handler.start = {x: "foo", y: "bar"}; + handler.last = {x: "foo", y: "bar"}; + map.events.triggerEvent("mousedown", testEvents.down); + t.ok(!handler.started, "right-click sets started to false"); + t.eq(handler.start, null, "right-click sets start to null"); + t.eq(handler.last, null, "right-click sets last to null"); + + // test mousedown with improper modifier + OpenLayers.Event.isLeftClick = function() { + return true; + } + handler.checkModifiers = function() { + return false; + } + handler.started = true; + handler.start = {x: "foo", y: "bar"}; + handler.last = {x: "foo", y: "bar"}; + map.events.triggerEvent("mousedown", testEvents.down); + t.ok(!handler.started, "bad modifier sets started to false"); + t.eq(handler.start, null, "bad modifier sets start to null"); + t.eq(handler.last, null, "bad modifier sets last to null"); + + // test mousedown handler.checkModifiers = function(evt) { t.ok(evt.xy.x == testEvents.down.xy.x && evt.xy.y == testEvents.down.xy.y, @@ -151,8 +182,9 @@ t.ok(handler.last.x == testEvents.down.xy.x && handler.last.y == testEvents.down.xy.y, "mouse down sets handler.last correctly"); + + OpenLayers.Event.stop = oldStop; OpenLayers.Event.isLeftClick = oldIsLeftClick; - OpenLayers.Event.stop = oldStop; handler.checkModifiers = oldCheckModifiers; // test mousemove