Skip to content

Commit 7ca22cd

Browse files
committed
Clean up mouse handling code.
1 parent 31c06b4 commit 7ca22cd

1 file changed

Lines changed: 8 additions & 16 deletions

File tree

src/ui/View.js

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,7 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
282282
this._element.height = size.height;
283283
// Update _viewSize but don't notify of change.
284284
this._viewSize.set(size.width, size.height, true);
285-
// Force recalculation
286-
this._bounds = null;
287-
this._redrawNeeded = true;
285+
this._bounds = null; // Force recalculation
288286
// Call onResize handler on any size change
289287
this.fire('resize', {
290288
size: size,
@@ -571,7 +569,6 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
571569
// Injection scope for mouse events on the browser
572570
/*#*/ if (options.browser) {
573571
var tool,
574-
curPoint,
575572
prevFocus,
576573
tempFocus,
577574
dragging = false;
@@ -603,15 +600,15 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
603600
function mousedown(event) {
604601
// Get the view from the event, and store a reference to the view that
605602
// should receive keyboard input.
606-
var view = View._focused = getView(event);
607-
curPoint = viewToProject(view, event);
603+
var view = View._focused = getView(event),
604+
point = viewToProject(view, event);
608605
dragging = true;
609606
// Always first call the view's mouse handlers, as required by
610607
// CanvasView, and then handle the active tool, if any.
611608
if (view._onMouseDown)
612-
view._onMouseDown(event, curPoint);
609+
view._onMouseDown(event, point);
613610
if (tool = view._scope._tool)
614-
tool._onHandleEvent('mousedown', curPoint, event);
611+
tool._onHandleEvent('mousedown', point, event);
615612
// In the end we always call draw(), but pass checkRedraw = true, so we
616613
// only redraw the view if anything has changed in the above calls.
617614
view.draw(true);
@@ -640,15 +637,10 @@ var View = this.View = Base.extend(Callback, /** @lends View# */{
640637
if (view._onMouseMove)
641638
view._onMouseMove(event, point);
642639
if (tool = view._scope._tool) {
643-
var onlyMove = !!(!tool.onMouseDrag && tool.onMouseMove);
644-
if (dragging && !onlyMove) {
645-
if ((curPoint = point || curPoint)
646-
&& tool._onHandleEvent('mousedrag', curPoint, event))
647-
DomEvent.stop(event);
648-
} else if ((!dragging || onlyMove)
649-
&& tool._onHandleEvent('mousemove', point, event)) {
640+
// If there's no onMouseDrag, fire onMouseMove while dragging too.
641+
if (tool._onHandleEvent(dragging && tool.responds('mousedrag')
642+
? 'mousedrag' : 'mousemove', point, event))
650643
DomEvent.stop(event);
651-
}
652644
}
653645
view.draw(true);
654646
}

0 commit comments

Comments
 (0)