From 440db1c1e3e354aa4a53fb1e86eee57b05719c6e Mon Sep 17 00:00:00 2001 From: Jonathan Puckey Date: Wed, 9 Feb 2011 01:07:29 +0100 Subject: [PATCH] Remove try/catch clauses and add missing check for existance of onMouseUp --- src/ToolHandler.js | 115 +++++++++++++++++++-------------------------- 1 file changed, 48 insertions(+), 67 deletions(-) diff --git a/src/ToolHandler.js b/src/ToolHandler.js index fa3c8fd2..b9731527 100644 --- a/src/ToolHandler.js +++ b/src/ToolHandler.js @@ -101,74 +101,55 @@ ToolHandler = Base.extend({ }, onHandleEvent: function(type, pt, modifiers) { - try { - switch (type) { - case 'MOUSE_DOWN': - this.updateEvent(type, pt, null, null, true, false, false); - if(this.onMouseDown) - this.onMouseDown(new ToolEvent(this, type, modifiers)); - break; - case 'MOUSE_DRAG': - // In order for idleInterval drag events to work, we need to - // not check the first call for a change of position. - // Subsequent calls required by min/maxDistance functionality - // will require it, otherwise this might loop endlessly. - this.needsChange = false; - // If the mouse is moving faster than maxDistance, do not - // produce events for what is left after the first event is - // generated in case it is shorter than maxDistance, as this - // would produce weird results. matchMaxDistance controls this. - this.matchMaxDistance = false; - while (this.updateEvent(type, pt, this.minDistance, - this.maxDistance, false, this.needsChange, this.matchMaxDistance)) { - try { - if(this.onMouseDrag) - this.onMouseDrag(new ToolEvent(this, type, modifiers)); - } catch (e) { - // ScriptographerEngine.reportError(e); - } - this.needsChange = true; - this.matchMaxDistance = true; - } - break; - case 'MOUSE_UP': - // If the last mouse drag happened in a different place, call - // mouse drag first, then mouse up. - if ((this.point.x != pt.x || this.point.y != pt.y) && this.updateEvent( - 'MOUSE_DRAG', pt, this.minDistance, this.maxDistance, false, false, false)) { - try { - if(this.onMouseDrag) - this.onMouseDrag(new ToolEvent(this, type, modifiers)); - } catch (e) { - // ScriptographerEngine.reportError(e); - } - } - this.updateEvent(type, pt, null, this.maxDistance, false, - false, false); - try { - this.onMouseUp(new ToolEvent(this, type, modifiers)); - } catch (e) { - // ScriptographerEngine.reportError(e); - } - // Start with new values for TRACK_CURSOR - this.updateEvent(type, pt, null, null, true, false, false); - this.firstMove = true; - break; - case 'MOUSE_MOVE': - while (this.updateEvent(type, pt, this.minDistance, - this.maxDistance, this.firstMove, true, false)) { - try { - if(this.onMouseMove) - this.onMouseMove(new ToolEvent(this, type, modifiers)); - } catch (e) { - // ScriptographerEngine.reportError(e); - } - this.firstMove = false; - } - break; + switch (type) { + case 'MOUSE_DOWN': + this.updateEvent(type, pt, null, null, true, false, false); + if(this.onMouseDown) + this.onMouseDown(new ToolEvent(this, type, modifiers)); + break; + case 'MOUSE_DRAG': + // In order for idleInterval drag events to work, we need to + // not check the first call for a change of position. + // Subsequent calls required by min/maxDistance functionality + // will require it, otherwise this might loop endlessly. + this.needsChange = false; + // If the mouse is moving faster than maxDistance, do not + // produce events for what is left after the first event is + // generated in case it is shorter than maxDistance, as this + // would produce weird results. matchMaxDistance controls this. + this.matchMaxDistance = false; + while (this.updateEvent(type, pt, this.minDistance, + this.maxDistance, false, this.needsChange, this.matchMaxDistance)) { + if(this.onMouseDrag) + this.onMouseDrag(new ToolEvent(this, type, modifiers)); + this.needsChange = true; + this.matchMaxDistance = true; } - } catch (e) { - //ScriptographerEngine.reportError(e); + break; + case 'MOUSE_UP': + // If the last mouse drag happened in a different place, call + // mouse drag first, then mouse up. + if ((this.point.x != pt.x || this.point.y != pt.y) && this.updateEvent( + 'MOUSE_DRAG', pt, this.minDistance, this.maxDistance, false, false, false)) { + if(this.onMouseDrag) + this.onMouseDrag(new ToolEvent(this, type, modifiers)); + } + this.updateEvent(type, pt, null, this.maxDistance, false, + false, false); + if(this.onMouseUp) + this.onMouseUp(new ToolEvent(this, type, modifiers)); + // Start with new values for TRACK_CURSOR + this.updateEvent(type, pt, null, null, true, false, false); + this.firstMove = true; + break; + case 'MOUSE_MOVE': + while (this.updateEvent(type, pt, this.minDistance, + this.maxDistance, this.firstMove, true, false)) { + if(this.onMouseMove) + this.onMouseMove(new ToolEvent(this, type, modifiers)); + this.firstMove = false; + } + break; } } }); \ No newline at end of file