From fc32a6757ac97a24fe05417d87ac33b74788a273 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Tue, 21 Jun 2011 00:42:39 +0100 Subject: [PATCH] Always use View.focused in handlers without caching view locally, as it can be modified elsewhere. --- src/ui/View.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/ui/View.js b/src/ui/View.js index 3db4cd3f..96d6c1d6 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -371,25 +371,24 @@ var View = this.View = Base.extend({ */ onResize: null }, new function() { // Injection scope for mouse handlers - var view, - tool, + var tool, timer, curPoint, dragging = false; - function viewToArtwork(event) { + function viewToArtwork(view, event) { return view.viewToArtwork(DomEvent.getOffset(event, view._canvas)); } function mousemove(event) { - DomEvent.stop(event); + var view = View.focused; if (!view || !(tool = view._scope.tool)) return; // If the event was triggered by a touch screen device, prevent the // default behaviour, as it will otherwise scroll the page: if (event && event.targetTouches) DomEvent.preventDefault(event); - var point = event && viewToArtwork(event); + var point = event && viewToArtwork(view, event); var onlyMove = !!(!tool.onMouseDrag && tool.onMouseMove); if (dragging && !onlyMove) { curPoint = point || curPoint; @@ -404,6 +403,7 @@ var View = this.View = Base.extend({ } function mouseup(event) { + var view = View.focused; if (!view || !dragging) return; dragging = false; @@ -411,9 +411,8 @@ var View = this.View = Base.extend({ if (tool) { if (timer != null) timer = clearInterval(timer); - if (tool.onHandleEvent('mouseup', viewToArtwork(event), event)) + if (tool.onHandleEvent('mouseup', viewToArtwork(view, event), event)) view.draw(true); - DomEvent.stop(event); } } @@ -439,14 +438,14 @@ var View = this.View = Base.extend({ return { _createEvents: function() { - var that = this; + var view = this; function mousedown(event) { // Tell the Key class which view should receive keyboard input. - view = View.focused = that; + View.focused = view; if (!(tool = view._scope.tool)) return; - curPoint = viewToArtwork(event); + curPoint = viewToArtwork(view, event); if (tool.onHandleEvent('mousedown', curPoint, event)) view.draw(true); if (tool.eventInterval != null)