From 8efc7ce7cd770a378a3d2e0ae31ff7881af32059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 16 Nov 2011 22:41:22 +0100 Subject: [PATCH] Implement Item#onMouseUp events and work on #onMouseMove. --- src/ui/CanvasView.js | 36 +++++++++++++++++++++++++----------- src/ui/View.js | 17 +++++++++-------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/ui/CanvasView.js b/src/ui/CanvasView.js index 335be296..04631133 100644 --- a/src/ui/CanvasView.js +++ b/src/ui/CanvasView.js @@ -65,17 +65,16 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ ctx.restore(); this._redrawNeeded = false; return true; - }, + } +}, new function() { // Item based mouse handling: - // Item based mouse handling: - - _hitOptions: { + var hitOptions = { fill: true, stroke: true, tolerance: 0 - }, + }; - _callEvent: function(item, event, bubble) { + function callEvent(item, event, bubble) { var called = false; while (item) { called = item.fire(event.type, event) || called; @@ -84,17 +83,32 @@ var CanvasView = View.extend(/** @lends CanvasView# */{ item = item.getParent(); } return called; - }, + } - _onMouseDown: function(event, point) { - if (this._eventCounters.mousedown) { - var hit = this._project.hitTest(point, this._hitOptions); + function handleEvent(view, type, event, point) { + if (view._eventCounters[type]) { + var hit = view._project.hitTest(point, hitOptions); if (hit && hit.item) { - this._callEvent(hit.item, new MouseEvent('mousedown', point, + callEvent(hit.item, new MouseEvent(type, point, hit.item, event), false); + return hit; } } } + + return { + _onMouseDown: function(event, point) { + handleEvent(this, 'mousedown', event, point); + }, + + _onMouseUp: function(event, point) { + handleEvent(this, 'mouseup', event, point); + }, + + _onMouseMove: function(event, point) { + handleEvent(this, 'mousemove', event, point); + } + }; }); /*#*/ if (options.server) { diff --git a/src/ui/View.js b/src/ui/View.js index e4eadfd9..17b3d32b 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -495,15 +495,16 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{ var view = View._focused; if (!view || !dragging) return; - dragging = false; + var point = viewToProject(view, event); curPoint = null; - if (tool) { - if (tool._onHandleEvent('mouseup', viewToProject(view, event), - event)) { - view.draw(true); - DomEvent.stop(event); - } - } + dragging = false; + if (view._onMouseUp) + view._onMouseUp(event, point); + // Cancel DOM-event if it was handled by our tool + if (tool && tool._onHandleEvent('mouseup', point, event)) + DomEvent.stop(event); + // See mousedown() for an explanation of why we can always call this. + view.draw(true); } function selectstart(event) {