Record whether the workspace has been dragged (#475)

* Record whether the workspace has been dragged

This fixes #473 by differentiating between a touch on an unmovable block
and using it to drag the workspace.

* Remove isScrolling and add DRAG_BEGIN

Applied after PR review.
This commit is contained in:
Rodrigo Queiro 2016-07-12 20:34:02 +02:00 committed by Neil Fraser
parent 612e0c0aac
commit d3d0ca4fd0
4 changed files with 25 additions and 13 deletions

View file

@ -106,9 +106,9 @@ Blockly.clipboardSource_ = null;
/**
* Is the mouse dragging a block?
* 0 - No drag operation.
* 1 - Still inside the sticky DRAG_RADIUS.
* 2 - Freely draggable.
* DRAG_NONE - No drag operation.
* DRAG_STICKY - Still inside the sticky DRAG_RADIUS.
* DRAG_FREE - Freely draggable.
* @private
*/
Blockly.dragMode_ = Blockly.DRAG_NONE;
@ -190,7 +190,7 @@ Blockly.svgResize = function(workspace) {
Blockly.onMouseUp_ = function(e) {
var workspace = Blockly.getMainWorkspace();
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
workspace.isScrolling = false;
workspace.dragMode_ = Blockly.DRAG_NONE;
// Unbind the touch event if it exists.
if (Blockly.onTouchUpWrapper_) {
Blockly.unbindEvent_(Blockly.onTouchUpWrapper_);
@ -212,7 +212,7 @@ Blockly.onMouseMove_ = function(e) {
return; // Multi-touch gestures won't have e.clientX.
}
var workspace = Blockly.getMainWorkspace();
if (workspace.isScrolling) {
if (workspace.dragMode_ != Blockly.DRAG_NONE) {
var dx = e.clientX - workspace.startDragMouseX;
var dy = e.clientY - workspace.startDragMouseY;
var metrics = workspace.startDragMetrics;
@ -231,6 +231,7 @@ Blockly.onMouseMove_ = function(e) {
// Cancel the long-press if the drag has moved too far.
if (Math.sqrt(dx * dx + dy * dy) > Blockly.DRAG_RADIUS) {
Blockly.longStop_();
workspace.dragMode_ = Blockly.DRAG_FREE;
}
e.stopPropagation();
e.preventDefault();

View file

@ -154,7 +154,14 @@ Blockly.DRAG_NONE = 0;
Blockly.DRAG_STICKY = 1;
/**
* ENUM for freely draggable.
* ENUM for inside the non-sticky DRAG_RADIUS, for differentiating between
* clicks and drags.
* @const
*/
Blockly.DRAG_BEGIN = 1;
/**
* ENUM for freely draggable (outside the DRAG_RADIUS, if one applies).
* @const
*/
Blockly.DRAG_FREE = 2;

View file

@ -151,9 +151,9 @@ Blockly.Flyout.prototype.height_ = 0;
/**
* Is the flyout dragging (scrolling)?
* 0 - DRAG_NONE - no drag is ongoing or state is undetermined.
* 1 - DRAG_STICKY - still within the sticky drag radius.
* 2 - DRAG_FREE - in scroll mode (never create a new block).
* DRAG_NONE - no drag is ongoing or state is undetermined.
* DRAG_STICKY - still within the sticky drag radius.
* DRAG_FREE - in scroll mode (never create a new block).
* @private
*/
Blockly.Flyout.prototype.dragMode_ = Blockly.DRAG_NONE;

View file

@ -84,9 +84,12 @@ Blockly.WorkspaceSvg.prototype.isFlyout = false;
/**
* Is this workspace currently being dragged around?
* @type {boolean}
* DRAG_NONE - No drag operation.
* DRAG_BEGIN - Still inside the initial DRAG_RADIUS.
* DRAG_FREE - Workspace has been dragged further than DRAG_RADIUS.
* @private
*/
Blockly.WorkspaceSvg.prototype.isScrolling = false;
Blockly.WorkspaceSvg.prototype.dragMode_ = Blockly.DRAG_NONE;
/**
* Current horizontal scrolling offset.
@ -656,7 +659,7 @@ Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) {
// Right-click.
this.showContextMenu_(e);
} else if (this.scrollbar) {
this.isScrolling = true;
this.dragMode_ = Blockly.DRAG_BEGIN;
// Record the current mouse position.
this.startDragMouseX = e.clientX;
this.startDragMouseY = e.clientY;
@ -716,7 +719,8 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) {
* @return {boolean} True if currently dragging or scrolling.
*/
Blockly.WorkspaceSvg.prototype.isDragging = function() {
return Blockly.dragMode_ == Blockly.DRAG_FREE || this.isScrolling;
return Blockly.dragMode_ == Blockly.DRAG_FREE ||
this.dragMode_ == Blockly.DRAG_FREE;
};
/**