Code review

This commit is contained in:
DD 2018-02-16 17:32:13 -05:00
parent 534eb28e83
commit 92023c45ce
4 changed files with 45 additions and 31 deletions

View file

@ -79,7 +79,7 @@ Blockly.BlockDragger = function(block, workspace) {
this.wouldDeleteBlock_ = false;
/**
* Whether the currently dragged block is to the right of the workspace. Keep
* Whether the currently dragged block is outside of the workspace. Keep
* track so that we can fire events only when this changes.
* @type {boolean}
* @private
@ -197,7 +197,7 @@ Blockly.BlockDragger.prototype.dragBlock = function(e, currentDragDeltaXY) {
this.dragIcons_(delta);
this.deleteArea_ = this.workspace_.isDeleteArea(e);
var isOutside = this.workspace_.isOutside(e);
var isOutside = !this.workspace_.isInsideBlocksArea(e);
this.draggedConnectionManager_.update(delta, this.deleteArea_, isOutside);
if (isOutside !== this.wasOutside_) {
this.fireDragOutsideEvent_(isOutside);
@ -218,7 +218,7 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) {
// Make sure internal state is fresh.
this.dragBlock(e, currentDragDeltaXY);
this.dragIconData_ = [];
var isOutside = this.workspace_.isOutside(e);
var isOutside = this.wasOutside_;
this.fireEndDragEvent_(isOutside);
this.draggingBlock_.setMouseThroughStyle(false);
@ -284,8 +284,7 @@ Blockly.BlockDragger.prototype.endBlockDrag = function(e, currentDragDeltaXY) {
};
/**
* Fire an event when the dragged blocks move to the right of the workspace, or back into
* the workspace.
* Fire an event when the dragged blocks move outside or back into the blocks workspace
* @param {?boolean} isOutside True if the drag is going outside the visible area.
* @private
*/
@ -342,7 +341,7 @@ Blockly.BlockDragger.prototype.maybeDeleteBlock_ = function() {
/**
* Update the cursor (and possibly the trash can lid) to reflect whether the
* dragging block would be deleted if released immediately.
* @param {boolean} isOutside True if the cursor is to the right of the workspace
* @param {boolean} isOutside True if the cursor is outside of the blocks workspace
* @private
*/
Blockly.BlockDragger.prototype.updateCursorDuringBlockDrag_ = function(isOutside) {

View file

@ -153,7 +153,7 @@ Blockly.DraggedConnectionManager.prototype.applyConnections = function() {
* in workspace units.
* @param {?number} deleteArea One of {@link Blockly.DELETE_AREA_TRASH},
* {@link Blockly.DELETE_AREA_TOOLBOX}, or {@link Blockly.DELETE_AREA_NONE}.
* @param {?boolean} isOutside True if the drag is going outside the workspace to the right.
* @param {?boolean} isOutside True if the drag is going outside the blocks workspace
* @package
*/
Blockly.DraggedConnectionManager.prototype.update = function(dxy, deleteArea, isOutside) {

View file

@ -95,7 +95,17 @@ Blockly.Events.BLOCK_CHANGE = Blockly.Events.CHANGE;
* @const
*/
Blockly.Events.MOVE = 'move';
/**
* Name of event that drags a block outside of or into the blocks workspace
* @const
*/
Blockly.Events.DRAG_OUTSIDE = 'dragOutside';
/**
* Name of event that ends a block drag
* @const
*/
Blockly.Events.END_DRAG = 'endDrag';
/**
@ -926,17 +936,10 @@ Blockly.Events.DragOutside.prototype.isNull = function() {
return false;
};
/**
* Run a drag outside event.
*/
Blockly.Events.DragOutside.prototype.run = function() {
console.error('Not implemented');
};
/**
* Class for a block end drag event.
* @param {Blockly.Block} block The moved block. Null for a blank event.
* @param {boolean} isOutside True if the moved block is to the right of the
* @param {boolean} isOutside True if the moved block is outside of the
* blocks workspace.
* @extends {Blockly.Events.Abstract}
* @constructor
@ -1001,13 +1004,6 @@ Blockly.Events.EndDrag.prototype.isNull = function() {
return false;
};
/**
* Run a drag event.
*/
Blockly.Events.EndDrag.prototype.run = function() {
console.error('Not implemented');
};
/**
* Class for a UI event.
* @param {Blockly.Block} block The affected block.

View file

@ -51,6 +51,7 @@ goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.math.Coordinate');
goog.require('goog.userAgent');
goog.require('goog.math.Rect');
/**
@ -448,7 +449,7 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
if (this.grid_) {
this.grid_.update(this.scale);
}
this.recordDeleteAreas();
this.recordCachedAreas();
return this.svgGroup_;
};
@ -609,7 +610,7 @@ Blockly.WorkspaceSvg.prototype.getFlyout = function() {
*/
Blockly.WorkspaceSvg.prototype.updateScreenCalculations_ = function() {
this.updateInverseScreenCTM();
this.recordDeleteAreas();
this.recordCachedAreas();
};
/**
@ -1075,10 +1076,18 @@ Blockly.WorkspaceSvg.prototype.createVariable = function(name, opt_type, opt_id)
return newVar;
};
/**
* Update cached areas for this workspace.
*/
Blockly.WorkspaceSvg.prototype.recordCachedAreas = function() {
this.recordBlocksArea_();
this.recordDeleteAreas_();
};
/**
* Make a list of all the delete areas for this workspace.
*/
Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() {
Blockly.WorkspaceSvg.prototype.recordDeleteAreas_ = function() {
if (this.trashcan) {
this.deleteAreaTrash_ = this.trashcan.getClientRect();
} else {
@ -1093,6 +1102,14 @@ Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() {
}
};
/**
* Record where all of blocks GUI is on the screen
*/
Blockly.WorkspaceSvg.prototype.recordBlocksArea_ = function() {
var bounds = this.svgGroup_.getBoundingClientRect();
this.blocksArea_ = new goog.math.Rect(bounds.left, bounds.top, bounds.width, bounds.height);
};
/**
* Is the mouse event over a delete area (toolbox or non-closing flyout)?
* @param {!Event} e Mouse move event.
@ -1111,14 +1128,16 @@ Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) {
};
/**
* Is the mouse event outside the blocks UI, to the right of the workspace?
* Is the mouse event inside the blocks UI?
* @param {!Event} e Mouse move event.
* @return {boolean} True if event is outside the blocks UI.
* @return {boolean} True if event is within the bounds of the blocks UI or delete area
*/
Blockly.WorkspaceSvg.prototype.isOutside = function(e) {
var mousePoint = Blockly.utils.mouseToSvg(e, this.getParentSvg(),
this.getInverseScreenCTM());
return this.getParentSvg().width.baseVal.value < mousePoint.x;
Blockly.WorkspaceSvg.prototype.isInsideBlocksArea = function(e) {
var xy = new goog.math.Coordinate(e.clientX, e.clientY);
if (this.isDeleteArea(e) || (this.blocksArea_ && this.blocksArea_.contains(xy))) {
return true;
}
return false;
};
/**