Commit 208e49c9 authored by Neil Fraser's avatar Neil Fraser

Add red 'X' to mouse cursor if blocks are over the trash can.

parent 1467f746
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -518,7 +518,7 @@ Blockly.Block.prototype.onMouseDown_ = function(e) {
} else {
// Left-click (or middle click)
Blockly.removeAllRanges();
Blockly.setCursorHand_(true);
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
// Look up the current translation and record it.
var xy = this.getRelativeToSurfaceXY();
this.startDragX = xy.x;
......
......@@ -312,7 +312,7 @@ Blockly.onMouseDown_ = function(e) {
* @private
*/
Blockly.onMouseUp_ = function(e) {
Blockly.setCursorHand_(false);
Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
Blockly.mainWorkspace.dragMode = false;
// Unbind the touch event if it exists.
......@@ -620,30 +620,6 @@ Blockly.playAudio = function(name, opt_volume) {
}
};
/**
* Set the mouse cursor to be either a closed hand or the default.
* @param {boolean} closed True for closed hand.
* @private
*/
Blockly.setCursorHand_ = function(closed) {
if (Blockly.readOnly) {
return;
}
/* Hotspot coordinates are baked into the CUR file, but they are still
required due to a Chrome bug.
https://code.google.com/p/chromium/issues/detail?id=1446 */
var cursor = '';
if (closed) {
cursor = 'url(' + Blockly.pathToMedia + 'handclosed.cur) 7 3, auto';
}
if (Blockly.selected) {
Blockly.selected.getSvgRoot().style.cursor = cursor;
}
// Set cursor on the SVG surface as well as block so that rapid movements
// don't result in cursor changing to an arrow momentarily.
Blockly.svg.style.cursor = cursor;
};
/**
* Return an object with all the metrics required to size scrollbars for the
* main workspace. The following properties are computed:
......
......@@ -253,7 +253,7 @@ Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) {
return;
}
// Left-click (or middle click)
Blockly.setCursorHand_(true);
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
// Record the starting offset between the current location and the mouse.
if (Blockly.RTL) {
this.dragDeltaX = this.relativeLeft_ + e.clientX;
......@@ -301,7 +301,7 @@ Blockly.Bubble.prototype.resizeMouseDown_ = function(e) {
return;
}
// Left-click (or middle click)
Blockly.setCursorHand_(true);
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
// Record the starting offset between the current location and the mouse.
if (Blockly.RTL) {
this.resizeDeltaWidth = this.width_ + e.clientX;
......
......@@ -28,6 +28,29 @@ goog.provide('Blockly.Css');
goog.require('goog.cssom');
/**
* List of cursors.
* @enum {string}
*/
Blockly.Css.Cursor = {
OPEN: 'handopen',
CLOSED: 'handclosed',
DELETE: 'handdelete'
};
/**
* Large stylesheet added by Blockly.Css.inject.
* @type Element
* @private
*/
Blockly.Css.styleSheet_ = null;
/**
* Path to media directory, with any trailing slash removed.
* @type string
* @private
*/
Blockly.Css.mediaPath_ = '';
/**
* Inject the CSS into the DOM. This is preferable over using a regular CSS
......@@ -39,15 +62,46 @@ goog.require('goog.cssom');
Blockly.Css.inject = function() {
var text = Blockly.Css.CONTENT.join('\n');
// Strip off any trailing slash (either Unix or Windows).
var path = Blockly.pathToMedia.replace(/[\\\/]$/, '');
text = text.replace(/<<<PATH>>>/g, path);
Blockly.Css.mediaPath_ = Blockly.pathToMedia.replace(/[\\\/]$/, '');
text = text.replace(/<<<PATH>>>/g, Blockly.Css.mediaPath_);
goog.cssom.addCssText(text);
var sheets = goog.cssom.getAllCssStyleSheets();
Blockly.Css.styleSheet_ = sheets[sheets.length - 1];
Blockly.Css.setCursor('handopen');
};
/**
* Set the cursor to be displayed when over something draggable.
* @param {Blockly.Cursor} cursor Enum.
*/
Blockly.Css.setCursor = function(cursor) {
if (Blockly.readOnly) {
return;
}
/*
Hotspot coordinates are baked into the CUR file, but they are still
required in the CSS due to a Chrome bug.
https://code.google.com/p/chromium/issues/detail?id=1446
*/
if (cursor == Blockly.Css.Cursor.OPEN) {
var xy = '8 5';
} else {
var xy = '7 3';
}
var rule = '.blocklyDraggable {\n' +
' cursor: url(' + Blockly.Css.mediaPath_ + '/' + cursor + '.cur)' +
' ' + xy + ', auto;\n}\n';
goog.cssom.replaceCssRule('', rule, Blockly.Css.styleSheet_, 0);
};
/**
* Array making up the CSS content for Blockly.
*/
Blockly.Css.CONTENT = [
'.blocklyDraggable {',
// Placeholder for cursor rule. Must be first rule (index 0).
'}',
'.blocklySvg {',
' background-color: #fff;',
' border: 1px solid #ddd;',
......@@ -60,15 +114,6 @@ Blockly.Css.CONTENT = [
' z-index: 999;',
'}',
'.blocklyDraggable {',
/*
Hotspot coordinates are baked into the CUR file, but they are still
required in the CSS due to a Chrome bug.
https://code.google.com/p/chromium/issues/detail?id=1446
*/
' cursor: url(<<<PATH>>>/handopen.cur) 8 5, auto;',
'}',
'.blocklyResizeSE {',
' fill: #aaa;',
' cursor: se-resize;',
......
......@@ -507,7 +507,7 @@ Blockly.Flyout.prototype.blockMouseDown_ = function(block) {
} else {
// Left-click (or middle click)
Blockly.removeAllRanges();
Blockly.setCursorHand_(true);
Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
// Record the current mouse position.
Blockly.Flyout.startDownEvent_ = e;
Blockly.Flyout.startBlock_ = block;
......
......@@ -278,6 +278,8 @@ Blockly.Trashcan.prototype.setOpen_ = function(state) {
goog.Timer.clear(this.lidTask_);
this.isOpen = state;
this.animateLid_();
Blockly.Css.setCursor(state ? Blockly.Css.Cursor.DELETE :
Blockly.Css.Cursor.CLOSED);
};
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment