From 0dc32091c4402a85572d792318320a635f6d3836 Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Fri, 4 May 2018 13:22:57 -0400 Subject: [PATCH 1/2] Delay getting inverse screen CTM until needed --- core/constants.js | 6 ++++++ core/workspace_svg.js | 22 ++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/core/constants.js b/core/constants.js index 54ed1fb49..13a90b762 100644 --- a/core/constants.js +++ b/core/constants.js @@ -272,3 +272,9 @@ Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; * @const {string} */ Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; + +/** + * A constant value that we can use to mark calculated properties as dirty. + * @const {string} + */ +Blockly.DIRTY = 'dirty'; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 84b9fa539..87b4bb900 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -298,24 +298,34 @@ Blockly.WorkspaceSvg.prototype.targetWorkspace = null; * @type {SVGMatrix} * @private */ -Blockly.WorkspaceSvg.prototype.inverseScreenCTM_ = null; +Blockly.WorkspaceSvg.prototype.inverseScreenCTM_ = Blockly.DIRTY; /** * Getter for the inverted screen CTM. * @return {SVGMatrix} The matrix to use in mouseToSvg */ Blockly.WorkspaceSvg.prototype.getInverseScreenCTM = function() { + + // Defer getting the screen CTM until we actually need it, this should + // avoid forced reflows from any calls to updateInverseScreenCTM. + if (this.inverseScreenCTM_ == Blockly.DIRTY) { + var ctm = this.getParentSvg().getScreenCTM(); + if (ctm) { + this.inverseScreenCTM_ = ctm.inverse(); + } else { + // When dirty, and we can't get a CTM, set it to null. + this.inverseScreenCTM_ = null; + } + } + return this.inverseScreenCTM_; }; /** - * Update the inverted screen CTM. + * Mark the inverse screen CTM as dirty. */ Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM = function() { - var ctm = this.getParentSvg().getScreenCTM(); - if (ctm) { - this.inverseScreenCTM_ = ctm.inverse(); - } + this.inverseScreenCTM_ = Blockly.DIRTY; }; /** From 222e33eaa3e43f14200214657c9c1b1ba0d0a544 Mon Sep 17 00:00:00 2001 From: Corey Frang Date: Fri, 4 May 2018 19:39:07 -0400 Subject: [PATCH 2/2] Do not nullify inverseScreenCTM if for some reason CTM is lost --- core/constants.js | 6 ------ core/workspace_svg.js | 17 +++++++++++------ 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/core/constants.js b/core/constants.js index 13a90b762..54ed1fb49 100644 --- a/core/constants.js +++ b/core/constants.js @@ -272,9 +272,3 @@ Blockly.RENAME_VARIABLE_ID = 'RENAME_VARIABLE_ID'; * @const {string} */ Blockly.DELETE_VARIABLE_ID = 'DELETE_VARIABLE_ID'; - -/** - * A constant value that we can use to mark calculated properties as dirty. - * @const {string} - */ -Blockly.DIRTY = 'dirty'; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 87b4bb900..49475bf81 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -298,7 +298,14 @@ Blockly.WorkspaceSvg.prototype.targetWorkspace = null; * @type {SVGMatrix} * @private */ -Blockly.WorkspaceSvg.prototype.inverseScreenCTM_ = Blockly.DIRTY; +Blockly.WorkspaceSvg.prototype.inverseScreenCTM_ = null; + +/** + * Inverted screen CTM is dirty, recalculate it. + * @type {Boolean} + * @private + */ +Blockly.WorkspaceSvg.prototype.inverseScreenCTMDirty_ = true; /** * Getter for the inverted screen CTM. @@ -308,13 +315,11 @@ Blockly.WorkspaceSvg.prototype.getInverseScreenCTM = function() { // Defer getting the screen CTM until we actually need it, this should // avoid forced reflows from any calls to updateInverseScreenCTM. - if (this.inverseScreenCTM_ == Blockly.DIRTY) { + if (this.inverseScreenCTMDirty_) { var ctm = this.getParentSvg().getScreenCTM(); if (ctm) { this.inverseScreenCTM_ = ctm.inverse(); - } else { - // When dirty, and we can't get a CTM, set it to null. - this.inverseScreenCTM_ = null; + this.inverseScreenCTMDirty_ = false; } } @@ -325,7 +330,7 @@ Blockly.WorkspaceSvg.prototype.getInverseScreenCTM = function() { * Mark the inverse screen CTM as dirty. */ Blockly.WorkspaceSvg.prototype.updateInverseScreenCTM = function() { - this.inverseScreenCTM_ = Blockly.DIRTY; + this.inverseScreenCTMDirty_ = true; }; /**