mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-16 22:10:32 +00:00
safeguard canvas (#4650)
This commit is contained in:
parent
2f19c8c7e8
commit
6d0ad48224
1 changed files with 30 additions and 22 deletions
|
|
@ -67,32 +67,40 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot
|
|||
});
|
||||
},
|
||||
|
||||
/**
|
||||
* Default event handler for the basic functionalities needed on _mouseDown
|
||||
* can be overridden to do something different.
|
||||
* Scope of this implementation is: find the click position, set selectionStart
|
||||
* find selectionEnd, initialize the drawing of either cursor or selection area
|
||||
*/
|
||||
_mouseDownHandler: function(options) {
|
||||
if (!this.canvas || !this.editable || (options.e.button && options.e.button !== 1)) {
|
||||
return;
|
||||
}
|
||||
var pointer = this.canvas.getPointer(options.e);
|
||||
|
||||
this.__mousedownX = pointer.x;
|
||||
this.__mousedownY = pointer.y;
|
||||
this.__isMousedown = true;
|
||||
|
||||
if (this.selected) {
|
||||
this.setCursorByClick(options.e);
|
||||
}
|
||||
|
||||
if (this.isEditing) {
|
||||
this.__selectionStartOnMouseDown = this.selectionStart;
|
||||
if (this.selectionStart === this.selectionEnd) {
|
||||
this.abortCursorAnimation();
|
||||
}
|
||||
this.renderCursorOrSelection();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Initializes "mousedown" event handler
|
||||
*/
|
||||
initMousedownHandler: function() {
|
||||
this.on('mousedown', function(options) {
|
||||
if (!this.editable || (options.e.button && options.e.button !== 1)) {
|
||||
return;
|
||||
}
|
||||
var pointer = this.canvas.getPointer(options.e);
|
||||
|
||||
this.__mousedownX = pointer.x;
|
||||
this.__mousedownY = pointer.y;
|
||||
this.__isMousedown = true;
|
||||
|
||||
if (this.selected) {
|
||||
this.setCursorByClick(options.e);
|
||||
}
|
||||
|
||||
if (this.isEditing) {
|
||||
this.__selectionStartOnMouseDown = this.selectionStart;
|
||||
if (this.selectionStart === this.selectionEnd) {
|
||||
this.abortCursorAnimation();
|
||||
}
|
||||
this.renderCursorOrSelection();
|
||||
}
|
||||
});
|
||||
this.on('mousedown', this._mouseDownHandler);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue