From 13e4d671c3d42230d397e0b4656d3e02923383d1 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Fri, 1 Nov 2019 14:28:51 -0700 Subject: [PATCH] Moved setHighlighted and setDisabled into the path object. --- core/block_svg.js | 39 ++++------------------ core/bubble.js | 6 ++-- core/mutator.js | 1 - core/renderers/common/constants.js | 45 ++++++++++++++++++++++++++ core/renderers/common/i_path_object.js | 19 ++++++++++- core/renderers/common/path_object.js | 40 ++++++++++++++++++++++- core/renderers/common/renderer.js | 4 ++- core/renderers/geras/path_object.js | 42 +++++++++++++++++++++++- core/renderers/geras/renderer.js | 3 +- core/toolbox.js | 1 - core/trashcan.js | 1 - core/workspace_svg.js | 3 +- 12 files changed, 160 insertions(+), 44 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 4c5902ed5..2527d6756 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -76,23 +76,6 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { */ this.pathObject = workspace.getRenderer().makePathObject(this.svgGroup_); - // The next two paths are set only for backwards compatibility reasons. - /** - * The primary path of the block. - * @type {SVGElement} - * @private - */ - this.svgPath_ = this.pathObject.svgPath || null; - - /** - * The light path of the block. - * @type {SVGElement} - * @private - */ - this.svgPathLight_ = this.pathObject.svgPathLight || null; - - this.svgPath_.tooltip = this; - /** @type {boolean} */ this.rendered = false; @@ -115,7 +98,9 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { this.useDragSurface_ = Blockly.utils.is3dSupported() && !!workspace.getBlockDragSurface(); - Blockly.Tooltip.bindMouseEvents(this.svgPath_); + var svgPath = this.pathObject.svgPath; + svgPath.tooltip = this; + Blockly.Tooltip.bindMouseEvents(svgPath); Blockly.BlockSvg.superClass_.constructor.call(this, workspace, prototypeName, opt_id); @@ -1023,8 +1008,6 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { blockWorkspace.resizeContents(); // Sever JavaScript to DOM connections. this.svgGroup_ = null; - this.svgPath_ = null; - this.svgPathLight_ = null; Blockly.utils.dom.stopTextWidthCache(); }; @@ -1060,15 +1043,13 @@ Blockly.BlockSvg.prototype.updateDisabled = function() { var added = Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled'); if (added) { - this.svgPath_.setAttribute('fill', - 'url(#' + - this.workspace.getRenderer().getConstants().disabledPatternId + ')'); + this.pathObject.setDisabled(true, this.isShadow()); } } else { var removed = Blockly.utils.dom.removeClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled'); if (removed) { - this.applyColour(); + this.pathObject.setDisabled(false, this.isShadow()); } } var children = this.getChildren(false); @@ -1252,15 +1233,7 @@ Blockly.BlockSvg.prototype.setHighlighted = function(highlighted) { if (!this.rendered) { return; } - if (highlighted) { - this.svgPath_.setAttribute('filter', - 'url(#' + - this.workspace.getRenderer().getConstants().embossFilterId + ')'); - this.svgPathLight_.style.display = 'none'; - } else { - this.svgPath_.setAttribute('filter', 'none'); - this.svgPathLight_.style.display = 'inline'; - } + this.pathObject.setHighlighted(highlighted); }; /** diff --git a/core/bubble.js b/core/bubble.js index c3713d4f8..4e139bdc3 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -232,7 +232,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { */ this.bubbleGroup_ = Blockly.utils.dom.createSvgElement('g', {}, null); var filter = - {'filter': 'url(#' + this.workspace_.options.embossFilterId + ')'}; + {'filter': 'url(#' + + this.workspace_.getRenderer().getConstants().embossFilterId + ')'}; if (Blockly.utils.userAgent.JAVA_FX) { // Multiple reports that JavaFX can't handle filters. // https://github.com/google/blockly/issues/99 @@ -240,7 +241,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) { } var bubbleEmboss = Blockly.utils.dom.createSvgElement('g', filter, this.bubbleGroup_); - this.bubbleArrow_ = Blockly.utils.dom.createSvgElement('path', {}, bubbleEmboss); + this.bubbleArrow_ = Blockly.utils.dom.createSvgElement('path', {}, + bubbleEmboss); this.bubbleBack_ = Blockly.utils.dom.createSvgElement('rect', { 'class': 'blocklyDraggable', diff --git a/core/mutator.js b/core/mutator.js index 3b1a1ff4b..006aea0b8 100644 --- a/core/mutator.js +++ b/core/mutator.js @@ -154,7 +154,6 @@ Blockly.Mutator.prototype.createEditor_ = function() { // If you want to enable disabling, also remove the // event filter from workspaceChanged_ . disable: false, - disabledPatternId: this.block_.workspace.options.disabledPatternId, languageTree: quarkXml, parentWorkspace: this.block_.workspace, pathToMedia: this.block_.workspace.options.pathToMedia, diff --git a/core/renderers/common/constants.js b/core/renderers/common/constants.js index fedfd85a7..6aa0863f6 100644 --- a/core/renderers/common/constants.js +++ b/core/renderers/common/constants.js @@ -23,6 +23,7 @@ goog.provide('Blockly.blockRendering.ConstantProvider'); +goog.require('Blockly.utils.dom'); goog.require('Blockly.utils.svgPaths'); @@ -134,6 +135,34 @@ Blockly.blockRendering.ConstantProvider = function() { * @const */ this.JAGGED_TEETH_WIDTH = 6; + + /** + * The ID of the emboss filter, or the empty string if no filter is set. + * @type {string} + * @package + */ + this.embossFilterId = ''; + + /** + * The element to use for highlighting, or null if not set. + * @type {SVGElement} + * @private + */ + this.embossFilter_ = null; + + /** + * The ID of the disabled pattern, or the empty string if no pattern is set. + * @type {string} + * @package + */ + this.disabledPatternId = ''; + + /** + * The element to use for disabled blocks, or null if not set. + * @type {SVGElement} + * @private + */ + this.disabledPattern_ = null; }; /** @@ -180,6 +209,20 @@ Blockly.blockRendering.ConstantProvider.prototype.init = function() { this.OUTSIDE_CORNERS = this.makeOutsideCorners(); }; +/** + * Dispose of this constants provider. + * Delete all DOM elements that this provider created. + * @package + */ +Blockly.blockRendering.ConstantProvider.prototype.dispose = function() { + if (this.embossFilter_) { + Blockly.utils.dom.removeNode(this.embossFilter_); + } + if (this.disabledPattern_) { + Blockly.utils.dom.removeNode(this.disabledPattern_); + } +}; + /** * @return {!Object} An object containing sizing and path information about * collapsed block indicators. @@ -463,6 +506,7 @@ Blockly.blockRendering.ConstantProvider.prototype.createDom = function(svg) { 'k4': 0 }, embossFilter); this.embossFilterId = embossFilter.id; + this.embossFilter_ = embossFilter; /*