Skip to content

Commit

Permalink
Fixes recent and old small issues (#3643)
Browse files Browse the repository at this point in the history
asturur authored Jan 22, 2017

Verified

This commit was signed with the committer’s verified signature.
1 parent f755192 commit 9e37f9b
Showing 6 changed files with 110 additions and 93 deletions.
28 changes: 11 additions & 17 deletions src/mixins/canvas_events.mixin.js
Original file line number Diff line number Diff line change
@@ -200,7 +200,7 @@
this.__onMouseDown(e);

addListener(fabric.document, 'touchend', this._onMouseUp);
addListener(fabric.document, 'touchmove', this._onMouseMove);
addListener(fabric.document, 'touchmove', this._onMouseMove, { passive: false });

removeListener(this.upperCanvasEl, 'mousemove', this._onMouseMove);
removeListener(this.upperCanvasEl, 'touchmove', this._onMouseMove);
@@ -744,29 +744,23 @@
* @param {Object} target Object that the mouse is hovering, if so.
*/
_setCursorFromEvent: function (e, target) {
if (!target) {
if (!target || !target.selectable) {
this.setCursor(this.defaultCursor);
return false;
}

var hoverCursor = target.hoverCursor || this.hoverCursor;
if (!target.selectable) {
//let's skip _findTargetCorner if object is not selectable
var hoverCursor = target.hoverCursor || this.hoverCursor,
activeGroup = this.getActiveGroup(),
// only show proper corner when group selection is not active
corner = target._findTargetCorner
&& (!activeGroup || !activeGroup.contains(target))
&& target._findTargetCorner(this.getPointer(e, true));

if (!corner) {
this.setCursor(hoverCursor);
}
else {
var activeGroup = this.getActiveGroup(),
// only show proper corner when group selection is not active
corner = target._findTargetCorner
&& (!activeGroup || !activeGroup.contains(target))
&& target._findTargetCorner(this.getPointer(e, true));

if (!corner) {
this.setCursor(hoverCursor);
}
else {
this._setCornerCursor(corner, target, e);
}
this._setCornerCursor(corner, target, e);
}
//actually unclear why it should return something
//is never evaluated
22 changes: 19 additions & 3 deletions src/mixins/itext_behavior.mixin.js
Original file line number Diff line number Diff line change
@@ -409,7 +409,11 @@
var newSelectionStart = this.getSelectionStartFromPointer(options.e),
currentStart = this.selectionStart,
currentEnd = this.selectionEnd;
if (newSelectionStart === this.__selectionStartOnMouseDown) {
if (
(newSelectionStart !== this.__selectionStartOnMouseDown || currentStart === currentEnd)
&&
(currentStart === newSelectionStart || currentEnd === newSelectionStart)
) {
return;
}
if (newSelectionStart > this.__selectionStartOnMouseDown) {
@@ -421,6 +425,7 @@
this.selectionEnd = this.__selectionStartOnMouseDown;
}
if (this.selectionStart !== currentStart || this.selectionEnd !== currentEnd) {
this.restartCursorIfNeeded();
this._fireSelectionChanged();
this._updateTextarea();
this.renderCursorOrSelection();
@@ -655,8 +660,19 @@
this.setCoords();
this._fireSelectionChanged();
this.fire('changed');
this.canvas && this.canvas.fire('text:changed', { target: this });
this.canvas && this.canvas.renderAll();
this.restartCursorIfNeeded();
if (this.canvas) {
this.canvas.fire('text:changed', { target: this });
this.canvas.renderAll();
}
},

restartCursorIfNeeded: function() {
if (!this._currentTickState || this._currentTickState.isAborted
|| !this._currentTickCompleteState || this._currentTickCompleteState.isAborted
) {
this.initDelayedCursor();
}
},

/**
68 changes: 67 additions & 1 deletion src/mixins/object_geometry.mixin.js
Original file line number Diff line number Diff line change
@@ -408,6 +408,72 @@
scaleMatrix = [scaleX, 0, 0, scaleY],
m = multiplyMatrices(scaleMatrix, skewMatrixX, true);
return multiplyMatrices(m, skewMatrixY, true);
}
},

/*
* Calculate object dimensions from its properties
* @private
* @return {Object} .x width dimension
* @return {Object} .y height dimension
*/
_getNonTransformedDimensions: function() {
var strokeWidth = this.strokeWidth,
w = this.width + strokeWidth,
h = this.height + strokeWidth;
return { x: w, y: h };
},

/*
* Calculate object bounding boxdimensions from its properties scale, skew.
* @private
* @return {Object} .x width dimension
* @return {Object} .y height dimension
*/
_getTransformedDimensions: function(skewX, skewY) {
if (typeof skewX === 'undefined') {
skewX = this.skewX;
}
if (typeof skewY === 'undefined') {
skewY = this.skewY;
}
var dimensions = this._getNonTransformedDimensions(),
dimX = dimensions.x / 2, dimY = dimensions.y / 2,
points = [
{
x: -dimX,
y: -dimY
},
{
x: dimX,
y: -dimY
},
{
x: -dimX,
y: dimY
},
{
x: dimX,
y: dimY
}],
i, transformMatrix = this._calcDimensionsTransformMatrix(skewX, skewY, false),
bbox;
for (i = 0; i < points.length; i++) {
points[i] = fabric.util.transformPoint(points[i], transformMatrix);
}
bbox = fabric.util.makeBoundingBoxFromPoints(points);
return { x: bbox.width, y: bbox.height };
},

/*
* Calculate object dimensions for controls. include padding and canvas zoom
* private
*/
_calculateCurrentDimensions: function() {
var vpt = this.getViewportTransform(),
dim = this._getTransformedDimensions(),
p = fabric.util.transformPoint(dim, vpt, true);

return p.scalarAdd(2 * this.padding);
},
});
})();
60 changes: 0 additions & 60 deletions src/mixins/object_interactivity.mixin.js
Original file line number Diff line number Diff line change
@@ -107,66 +107,6 @@
}
},

/*
* Calculate object dimensions from its properties
* @private
*/
_getNonTransformedDimensions: function() {
var strokeWidth = this.strokeWidth,
w = this.width + strokeWidth,
h = this.height + strokeWidth;
return { x: w, y: h };
},

/*
* @private
*/
_getTransformedDimensions: function(skewX, skewY) {
if (typeof skewX === 'undefined') {
skewX = this.skewX;
}
if (typeof skewY === 'undefined') {
skewY = this.skewY;
}
var dimensions = this._getNonTransformedDimensions(),
dimX = dimensions.x / 2, dimY = dimensions.y / 2,
points = [
{
x: -dimX,
y: -dimY
},
{
x: dimX,
y: -dimY
},
{
x: -dimX,
y: dimY
},
{
x: dimX,
y: dimY
}],
i, transformMatrix = this._calcDimensionsTransformMatrix(skewX, skewY, false),
bbox;
for (i = 0; i < points.length; i++) {
points[i] = fabric.util.transformPoint(points[i], transformMatrix);
}
bbox = fabric.util.makeBoundingBoxFromPoints(points);
return { x: bbox.width, y: bbox.height };
},

/*
* private
*/
_calculateCurrentDimensions: function() {
var vpt = this.getViewportTransform(),
dim = this._getTransformedDimensions(),
p = fabric.util.transformPoint(dim, vpt, true);

return p.scalarAdd(2 * this.padding);
},

/**
* Draws a colored layer behind the object, inside its selection borders.
* Requires public options: padding, selectionBackgroundColor
5 changes: 3 additions & 2 deletions src/shapes/object.class.js
Original file line number Diff line number Diff line change
@@ -1189,8 +1189,9 @@
else {
if (this.dirty || (this.statefullCache && this.hasStateChanged('cacheProperties'))) {
if (!skipCanvas) {
var dim = this._getNonTransformedDimensions();
this._cacheContext.clearRect(-dim.x / 2, -dim.y / 2, dim.x, dim.y);
var width = this.cacheWidth / this.zoomX;
var height = this.cacheHeight / this.zoomY;
this._cacheContext.clearRect(-width / 2, -height / 2, width, height);
}
return true;
}
20 changes: 10 additions & 10 deletions src/shapes/path_group.class.js
Original file line number Diff line number Diff line change
@@ -256,22 +256,22 @@
* @param {Function} [callback] Callback to invoke when an fabric.PathGroup instance is created
*/
fabric.PathGroup.fromObject = function(object, callback) {
var originalPaths = object.paths;
delete object.paths;
// remove this pattern from 2.0 accepts only object
if (typeof object.paths === 'string') {
fabric.loadSVGFromURL(object.paths, function (elements) {

var pathUrl = object.paths;
delete object.paths;

if (typeof orignalPaths === 'string') {
fabric.loadSVGFromURL(originalPaths, function (elements) {
var pathUrl = originalPaths;
var pathGroup = fabric.util.groupSVGElements(elements, object, pathUrl);

object.paths = originalPaths;
callback(pathGroup);
});
}
else {
fabric.util.enlivenObjects(object.paths, function(enlivenedObjects) {
delete object.paths;
callback(new fabric.PathGroup(enlivenedObjects, object));
fabric.util.enlivenObjects(originalPaths, function(enlivenedObjects) {
var pathGroup = new fabric.PathGroup(enlivenedObjects, object);
object.paths = originalPaths;
callback(pathGroup);
});
}
};

0 comments on commit 9e37f9b

Please sign in to comment.