From 8d32f6bef3454cf1bc776adb8c8818d39f7f0e97 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 20 Aug 2019 11:41:04 -0700 Subject: [PATCH] Move Connection measurables to their own file --- blockly_uncompressed.js | 8 +- .../block_render_info.js | 4 +- .../block_rendering_rewrite/measurables.js | 79 ------------- core/renderers/measurables/connections.js | 108 ++++++++++++++++++ core/renderers/measurables/rows.js | 6 +- 5 files changed, 117 insertions(+), 88 deletions(-) create mode 100644 core/renderers/measurables/connections.js diff --git a/blockly_uncompressed.js b/blockly_uncompressed.js index 6a3db4bf0..db5e4cfe0 100644 --- a/blockly_uncompressed.js +++ b/blockly_uncompressed.js @@ -106,9 +106,11 @@ goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/ goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_rendering.js", ['Blockly.blockRendering'], ['Blockly.blockRendering.Debug', 'Blockly.blockRendering.Drawer', 'Blockly.blockRendering.RenderInfo']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/block_rendering_constants.js", ['Blockly.blockRendering.constants'], ['Blockly.utils.svgPaths']); goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/highlight_constants.js", ['Blockly.blockRendering.highlightConstants'], ['Blockly.blockRendering.constants', 'Blockly.utils.svgPaths']); -goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.OutputConnection'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']); +goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/measurables.js", ['Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Measurable']); +goog.addDependency("../../../" + dir + "/core/renderers/block_rendering_rewrite/shape_map.js", ['Blockly.blockRendering.connectionShapes'], ['Blockly.RenderedConnection']); goog.addDependency("../../../" + dir + "/core/renderers/measurables/base.js", ['Blockly.blockRendering.Measurable'], ['Blockly.blockRendering.constants']); -goog.addDependency("../../../" + dir + "/core/renderers/measurables/connections.js", [], []); +goog.addDependency("../../../" + dir + "/core/renderers/measurables/connections.js", ['Blockly.blockRendering.Connection', 'Blockly.blockRendering.OutputConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.blockRendering.NextConnection'], ['Blockly.blockRendering.Measurable', 'Blockly.blockRendering.constants']); +goog.addDependency("../../../" + dir + "/core/renderers/measurables/inputs.js", [], []); goog.addDependency("../../../" + dir + "/core/renderers/measurables/rows.js", ['Blockly.blockRendering.BottomRow', 'Blockly.blockRendering.InputRow', 'Blockly.blockRendering.Row', 'Blockly.blockRendering.SpacerRow', 'Blockly.blockRendering.TopRow'], ['Blockly.blockRendering.constants', 'Blockly.blockRendering.Input', 'Blockly.blockRendering.InRowSpacer', 'Blockly.blockRendering.Measurable', 'Blockly.blockRendering.NextConnection', 'Blockly.blockRendering.PreviousConnection', 'Blockly.RenderedConnection']); goog.addDependency("../../../" + dir + "/core/scrollbar.js", ['Blockly.Scrollbar', 'Blockly.ScrollbarPair'], ['Blockly.Touch', 'Blockly.utils', 'Blockly.utils.Coordinate', 'Blockly.utils.dom']); goog.addDependency("../../../" + dir + "/core/theme.js", ['Blockly.Theme'], []); @@ -1901,6 +1903,7 @@ goog.require('Blockly.ZoomControls'); goog.require('Blockly.blockAnimations'); goog.require('Blockly.blockRendering'); goog.require('Blockly.blockRendering.BottomRow'); +goog.require('Blockly.blockRendering.Connection'); goog.require('Blockly.blockRendering.Debug'); goog.require('Blockly.blockRendering.Drawer'); goog.require('Blockly.blockRendering.Highlighter'); @@ -1915,6 +1918,7 @@ goog.require('Blockly.blockRendering.RenderInfo'); goog.require('Blockly.blockRendering.Row'); goog.require('Blockly.blockRendering.SpacerRow'); goog.require('Blockly.blockRendering.TopRow'); +goog.require('Blockly.blockRendering.connectionShapes'); goog.require('Blockly.blockRendering.constants'); goog.require('Blockly.blockRendering.highlightConstants'); goog.require('Blockly.constants'); diff --git a/core/renderers/block_rendering_rewrite/block_render_info.js b/core/renderers/block_rendering_rewrite/block_render_info.js index 8f6823331..dbbe36b81 100644 --- a/core/renderers/block_rendering_rewrite/block_render_info.js +++ b/core/renderers/block_rendering_rewrite/block_render_info.js @@ -59,7 +59,8 @@ Blockly.blockRendering.RenderInfo = function(block) { * @type {Blockly.blockRendering.OutputConnection} */ this.outputConnection = !block.outputConnection ? null : - new Blockly.blockRendering.OutputConnection(block.outputConnection); + new Blockly.blockRendering.OutputConnection( + /** @type {Blockly.RenderedConnection} */(block.outputConnection)); /** * Whether the block should be rendered as a single line, either because it's @@ -152,7 +153,6 @@ Blockly.blockRendering.RenderInfo = function(block) { * may choose to rerender when getSize() is called). However, calling it * repeatedly may be expensive. * - * @param {!Blockly.BlockSvg} block The block to measure. * @private */ Blockly.blockRendering.RenderInfo.prototype.measure_ = function() { diff --git a/core/renderers/block_rendering_rewrite/measurables.js b/core/renderers/block_rendering_rewrite/measurables.js index 6905df843..74c886edc 100644 --- a/core/renderers/block_rendering_rewrite/measurables.js +++ b/core/renderers/block_rendering_rewrite/measurables.js @@ -1,9 +1,6 @@ goog.provide('Blockly.blockRendering.Input'); goog.provide('Blockly.blockRendering.InRowSpacer'); -goog.provide('Blockly.blockRendering.NextConnection'); -goog.provide('Blockly.blockRendering.PreviousConnection'); -goog.provide('Blockly.blockRendering.OutputConnection'); goog.require('Blockly.blockRendering.constants'); goog.require('Blockly.blockRendering.Measurable'); @@ -189,82 +186,6 @@ Blockly.blockRendering.ExternalValueInput = function(input) { goog.inherits(Blockly.blockRendering.ExternalValueInput, Blockly.blockRendering.Input); -/** - * The base class to represent a connection and the space that it takes up on - * the block. - * @param {Blockly.RenderedConnection} connectionModel The connection object on - * the block that this represents. - * @package - * @constructor - * @extends {Blockly.blockRendering.Measurable} - */ -Blockly.blockRendering.Connection = function(connectionModel) { - Blockly.blockRendering.Connection.superClass_.constructor.call(this); - this.connectionModel = connectionModel; -}; -goog.inherits(Blockly.blockRendering.Connection, - Blockly.blockRendering.Measurable); - -/** - * An object containing information about the space an output connection takes - * up during rendering. - * @param {Blockly.RenderedConnection} connectionModel The connection object on - * the block that this represents. - * @package - * @constructor - * @extends {Blockly.blockRendering.Measurable} - */ -Blockly.blockRendering.OutputConnection = function(connectionModel) { - Blockly.blockRendering.OutputConnection.superClass_.constructor.call(this, - connectionModel); - this.type = 'output connection'; - this.height = this.connectionShape.height; - this.width = this.connectionShape.width; - this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; - this.startX = this.width; -}; -goog.inherits(Blockly.blockRendering.OutputConnection, - Blockly.blockRendering.Connection); - -/** - * An object containing information about the space a previous connection takes - * up during rendering. - * @param {Blockly.RenderedConnection} connectionModel The connection object on - * the block that this represents. - * @package - * @constructor - * @extends {Blockly.blockRendering.Measurable} - */ -Blockly.blockRendering.PreviousConnection = function(connectionModel) { - Blockly.blockRendering.PreviousConnection.superClass_.constructor.call(this, - connectionModel); - this.type = 'previous connection'; - this.height = this.notchShape.height; - this.width = this.notchShape.width; - -}; -goog.inherits(Blockly.blockRendering.PreviousConnection, - Blockly.blockRendering.Connection); - -/** - * An object containing information about the space a next connection takes - * up during rendering. - * @param {Blockly.RenderedConnection} connectionModel The connection object on - * the block that this represents. - * @package - * @constructor - * @extends {Blockly.blockRendering.Measurable} - */ -Blockly.blockRendering.NextConnection = function(connectionModel) { - Blockly.blockRendering.NextConnection.superClass_.constructor.call(this, - connectionModel); - this.type = 'next connection'; - this.height = this.notchShape.height; - this.width = this.notchShape.width; -}; -goog.inherits(Blockly.blockRendering.NextConnection, - Blockly.blockRendering.Connection); - /** * An object containing information about the space a hat takes up during * rendering. diff --git a/core/renderers/measurables/connections.js b/core/renderers/measurables/connections.js new file mode 100644 index 000000000..22df503c8 --- /dev/null +++ b/core/renderers/measurables/connections.js @@ -0,0 +1,108 @@ +/** + * @license + * Visual Blocks Editor + * + * Copyright 2019 Google Inc. + * https://developers.google.com/blockly/ + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @fileoverview Objects representing connections on rendered blocks. + * @author fenichel@google.com (Rachel Fenichel) + */ + +goog.provide('Blockly.blockRendering.Connection'); +goog.provide('Blockly.blockRendering.OutputConnection'); +goog.provide('Blockly.blockRendering.PreviousConnection'); +goog.provide('Blockly.blockRendering.NextConnection'); + +goog.require('Blockly.blockRendering.Measurable'); +goog.require('Blockly.blockRendering.constants'); + +/** + * The base class to represent a connection and the space that it takes up on + * the block. + * @param {Blockly.RenderedConnection} connectionModel The connection object on + * the block that this represents. + * @package + * @constructor + * @extends {Blockly.blockRendering.Measurable} + */ +Blockly.blockRendering.Connection = function(connectionModel) { + Blockly.blockRendering.Connection.superClass_.constructor.call(this); + this.connectionModel = connectionModel; +}; +goog.inherits(Blockly.blockRendering.Connection, + Blockly.blockRendering.Measurable); + +/** + * An object containing information about the space an output connection takes + * up during rendering. + * @param {Blockly.RenderedConnection} connectionModel The connection object on + * the block that this represents. + * @package + * @constructor + * @extends {Blockly.blockRendering.Connection} + */ +Blockly.blockRendering.OutputConnection = function(connectionModel) { + Blockly.blockRendering.OutputConnection.superClass_.constructor.call(this, + connectionModel); + this.type = 'output connection'; + this.height = this.connectionShape.height; + this.width = this.connectionShape.width; + this.connectionOffsetY = Blockly.blockRendering.constants.TAB_OFFSET_FROM_TOP; + this.startX = this.width; +}; +goog.inherits(Blockly.blockRendering.OutputConnection, + Blockly.blockRendering.Connection); + +/** + * An object containing information about the space a previous connection takes + * up during rendering. + * @param {Blockly.RenderedConnection} connectionModel The connection object on + * the block that this represents. + * @package + * @constructor + * @extends {Blockly.blockRendering.Connection} + */ +Blockly.blockRendering.PreviousConnection = function(connectionModel) { + Blockly.blockRendering.PreviousConnection.superClass_.constructor.call(this, + connectionModel); + this.type = 'previous connection'; + this.height = this.notchShape.height; + this.width = this.notchShape.width; + +}; +goog.inherits(Blockly.blockRendering.PreviousConnection, + Blockly.blockRendering.Connection); + +/** + * An object containing information about the space a next connection takes + * up during rendering. + * @param {Blockly.RenderedConnection} connectionModel The connection object on + * the block that this represents. + * @package + * @constructor + * @extends {Blockly.blockRendering.Connection} + */ +Blockly.blockRendering.NextConnection = function(connectionModel) { + Blockly.blockRendering.NextConnection.superClass_.constructor.call(this, + connectionModel); + this.type = 'next connection'; + this.height = this.notchShape.height; + this.width = this.notchShape.width; +}; +goog.inherits(Blockly.blockRendering.NextConnection, + Blockly.blockRendering.Connection); diff --git a/core/renderers/measurables/rows.js b/core/renderers/measurables/rows.js index c023226ed..27a3e75f7 100644 --- a/core/renderers/measurables/rows.js +++ b/core/renderers/measurables/rows.js @@ -221,8 +221,6 @@ Blockly.blockRendering.Row.prototype.getLastSpacer = function() { * connections. * After this constructor is called, the row will contain all non-spacer * elements it needs. - * @param {!Blockly.BlockSvg} block The block for which this represents the top - * row. * @package * @constructor * @extends {Blockly.blockRendering.Row} @@ -250,7 +248,7 @@ Blockly.blockRendering.TopRow = function() { /** * The previous connection on the block, if any. - * @type {Blockly.BlockRendering.PreviousConnection} + * @type {Blockly.blockRendering.PreviousConnection} */ this.connection = null; }; @@ -321,8 +319,6 @@ Blockly.blockRendering.TopRow.prototype.measure = function() { * An object containing information about what elements are in the bottom row of * a block as well as spacing information for the top row. * Elements in a bottom row can consist of corners, spacers and next connections. - * @param {!Blockly.BlockSvg} block The block for which this represents the - * bottom row. * @package * @constructor * @extends {Blockly.blockRendering.Row}