From ca16d1fefe9d1725b770469975857ce2a9f5e323 Mon Sep 17 00:00:00 2001 From: Katelyn Mann Date: Wed, 4 May 2016 19:12:38 -0700 Subject: [PATCH] An alternate (and less expensive) way to keep stuff outside of the blockly div from getting selected. Use e.preventDefault instead of adding and removing classes on mousedown and mouseup. This keeps the browser from having to potentially recacluate style on mousedown and mouseup events. --- core/block_svg.js | 4 ++-- core/blockly.js | 2 +- core/css.js | 7 ------- core/scrollbar.js | 4 ++-- core/utils.js | 13 ------------- core/workspace_svg.js | 2 +- 6 files changed, 6 insertions(+), 26 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index d67e1acc1..ed867fc32 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -511,7 +511,6 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { e.stopPropagation(); return; } - Blockly.setPageSelectable(false); this.workspace.markFocused(); // Update Blockly's knowledge of its own location. Blockly.svgResize(this.workspace); @@ -556,6 +555,7 @@ Blockly.BlockSvg.prototype.onMouseDown_ = function(e) { } // This event has been handled. No need to bubble up to the document. e.stopPropagation(); + e.preventDefault(); }; /** @@ -571,7 +571,6 @@ Blockly.BlockSvg.prototype.onMouseUp_ = function(e) { Blockly.Events.fire( new Blockly.Events.Ui(this, 'click', undefined, undefined)); } - Blockly.setPageSelectable(true); Blockly.terminateDrag_(); if (Blockly.selected && Blockly.highlightedConnection_) { // Connect two blocks together. @@ -892,6 +891,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) { } // This event has been handled. No need to bubble up to the document. e.stopPropagation(); + e.preventDefault(); }; /** diff --git a/core/blockly.js b/core/blockly.js index 17305ec83..822e0e9d5 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -195,7 +195,6 @@ Blockly.onMouseUp_ = function(e) { var workspace = Blockly.getMainWorkspace(); Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN); workspace.isScrolling = false; - Blockly.setPageSelectable(true); // Unbind the touch event if it exists. if (Blockly.onTouchUpWrapper_) { Blockly.unbindEvent_(Blockly.onTouchUpWrapper_); @@ -238,6 +237,7 @@ Blockly.onMouseMove_ = function(e) { Blockly.longStop_(); } e.stopPropagation(); + e.preventDefault(); } }; diff --git a/core/css.js b/core/css.js index 7e6f8be93..f1cafb0a9 100644 --- a/core/css.js +++ b/core/css.js @@ -143,13 +143,6 @@ Blockly.Css.CONTENT = [ 'z-index: 999;', '}', - '.blocklyNonSelectable {', - 'user-select: none;', - '-moz-user-select: none;', - '-webkit-user-select: none;', - '-ms-user-select: none;', - '}', - '.blocklyTooltipDiv {', 'background-color: #ffffc7;', 'border: 1px solid #ddc;', diff --git a/core/scrollbar.js b/core/scrollbar.js index df01000c6..d2c70d722 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -446,6 +446,7 @@ Blockly.Scrollbar.prototype.onMouseDownBar_ = function(e) { this.constrainKnob_(knobValue)); this.onScroll_(); e.stopPropagation(); + e.preventDefault(); }; /** @@ -462,7 +463,6 @@ Blockly.Scrollbar.prototype.onMouseDownKnob_ = function(e) { e.stopPropagation(); return; } - Blockly.setPageSelectable(false); // Look up the current translation and record it. this.startDragKnob = parseFloat( this.svgKnob_.getAttribute(this.horizontal_ ? 'x' : 'y')); @@ -473,6 +473,7 @@ Blockly.Scrollbar.prototype.onMouseDownKnob_ = function(e) { Blockly.Scrollbar.onMouseMoveWrapper_ = Blockly.bindEvent_(document, 'mousemove', this, this.onMouseMoveKnob_); e.stopPropagation(); + e.preventDefault(); }; /** @@ -495,7 +496,6 @@ Blockly.Scrollbar.prototype.onMouseMoveKnob_ = function(e) { * @private */ Blockly.Scrollbar.prototype.onMouseUpKnob_ = function() { - Blockly.setPageSelectable(true); Blockly.hideChaff(true); if (Blockly.Scrollbar.onMouseUpWrapper_) { Blockly.unbindEvent_(Blockly.Scrollbar.onMouseUpWrapper_); diff --git a/core/utils.js b/core/utils.js index aecc851b5..e65a72a6c 100644 --- a/core/utils.js +++ b/core/utils.js @@ -289,19 +289,6 @@ Blockly.createSvgElement = function(name, attrs, parent, opt_workspace) { return e; }; -/** - * Set css classes to allow/disallow the browser from selecting/highlighting - * text, etc. on the page. - * @param {boolean} selectable Whether elements on the page can be selected. - */ -Blockly.setPageSelectable = function(selectable) { - if (selectable) { - Blockly.removeClass_(document.body, 'blocklyNonSelectable'); - } else { - Blockly.addClass_(document.body, 'blocklyNonSelectable'); - } -}; - /** * Is this event a right-click? * @param {!Event} e Mouse event. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index af0580b05..562c8a5af 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -565,7 +565,6 @@ Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) { */ Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) { this.markFocused(); - Blockly.setPageSelectable(false); if (Blockly.isTargetInput_(e)) { return; } @@ -608,6 +607,7 @@ Blockly.WorkspaceSvg.prototype.onMouseDown_ = function(e) { } // This event has been handled. No need to bubble up to the document. e.stopPropagation(); + e.preventDefault(); }; /**