diff --git a/src/canvas.class.js b/src/canvas.class.js index 5adaa13f51f..e8bbf7ca645 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -1545,9 +1545,16 @@ * @chainable */ deactivateAllWithDispatch: function (e) { + var allObjects = this.getObjects(), + i = 0, + len = allObjects.length, + obj; + for ( ; i < len; i++) { + obj = allObjects[i]; + obj && obj.set('active', false); + } this.discardActiveGroup(e); this.discardActiveObject(e); - this.deactivateAll(); return this; }, diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index e88147620dc..df992e35f4d 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -11,7 +11,12 @@ tl: 7 // nw }, addListener = fabric.util.addListener, - removeListener = fabric.util.removeListener; + removeListener = fabric.util.removeListener, + RIGHT_CLICK = 3, MIDDLE_CLICK = 2, LEFT_CLICK = 1; + + function checkClick(e, value) { + return 'which' in e ? e.which === value : e.button === value - 1; + } fabric.util.object.extend(fabric.Canvas.prototype, /** @lends fabric.Canvas.prototype */ { @@ -303,15 +308,33 @@ * @param {Event} e Event object fired on mouseup */ __onMouseUp: function (e) { - var target, searchTarget = true, transform = this._currentTransform, - groupSelector = this._groupSelector, - isClick = (!groupSelector || (groupSelector.left === 0 && groupSelector.top === 0)); + + var target; + // if right/middle click just fire events and return + // target undefined will make the _handleEvent search the target + if (checkClick(e, RIGHT_CLICK)) { + if (this.fireRightClick) { + this._handleEvent(e, 'up', target, RIGHT_CLICK); + } + return; + } + + if (checkClick(e, MIDDLE_CLICK)) { + if (this.fireMiddleClick) { + this._handleEvent(e, 'up', target, MIDDLE_CLICK); + } + return; + } if (this.isDrawingMode && this._isCurrentlyDrawing) { this._onMouseUpInDrawingMode(e); return; } + var searchTarget = true, transform = this._currentTransform, + groupSelector = this._groupSelector, + isClick = (!groupSelector || (groupSelector.left === 0 && groupSelector.top === 0)); + if (transform) { this._finalizeCurrentTransform(); searchTarget = !transform.actionPerformed; @@ -352,15 +375,16 @@ }, /** + * @private * Handle event firing for target and subtargets * @param {Event} e event from mouse * @param {String} eventType event to fire (up, down or move) * @param {fabric.Object} targetObj receiving event */ - _handleEvent: function(e, eventType, targetObj) { + _handleEvent: function(e, eventType, targetObj, button) { var target = typeof targetObj === 'undefined' ? this.findTarget(e) : targetObj, targets = this.targets || [], - options = { e: e, target: target, subTargets: targets }; + options = { e: e, target: target, subTargets: targets, button: button || LEFT_CLICK }; this.fire('mouse:' + eventType, options); target && target.fire('mouse' + eventType, options); for (var i = 0; i < targets.length; i++) { @@ -466,18 +490,16 @@ var target = this.findTarget(e); // if right click just fire events - var isRightClick = 'which' in e ? e.which === 3 : e.button === 2; - if (isRightClick) { + if (checkClick(e, RIGHT_CLICK)) { if (this.fireRightClick) { - this._handleEvent(e, 'down', target ? target : null); + this._handleEvent(e, 'down', target ? target : null, RIGHT_CLICK); } return; } - var isMiddleClick = 'which' in e ? e.which === 2 : e.button === 1; - if (isMiddleClick) { + if (checkClick(e, MIDDLE_CLICK)) { if (this.fireMiddleClick) { - this._handleEvent(e, 'down', target ? target : null); + this._handleEvent(e, 'down', target ? target : null, MIDDLE_CLICK); } return; } diff --git a/src/mixins/itext_click_behavior.mixin.js b/src/mixins/itext_click_behavior.mixin.js index 83009309545..eea9335ba7e 100644 --- a/src/mixins/itext_click_behavior.mixin.js +++ b/src/mixins/itext_click_behavior.mixin.js @@ -20,7 +20,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot this.__newClickTime = +new Date(); var newPointer = this.canvas.getPointer(options.e); - if (this.isTripleClick(newPointer)) { + if (this.isTripleClick(newPointer, options.e)) { this.fire('tripleclick', options); this._stopEvent(options.e); } @@ -83,7 +83,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot */ initMousedownHandler: function() { this.on('mousedown', function(options) { - if (!this.editable) { + if (!this.editable || (options.e.button && options.e.button !== 1)) { return; } var pointer = this.canvas.getPointer(options.e); @@ -122,7 +122,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot initMouseupHandler: function() { this.on('mouseup', function(options) { this.__isMousedown = false; - if (!this.editable || this._isObjectMoved(options.e)) { + if (!this.editable || this._isObjectMoved(options.e) || (options.e.button && options.e.button !== 1)) { return; }