diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 84b9fa539..49475bf81 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -300,22 +300,37 @@ Blockly.WorkspaceSvg.prototype.targetWorkspace = null; */ 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. * @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.inverseScreenCTMDirty_) { + var ctm = this.getParentSvg().getScreenCTM(); + if (ctm) { + this.inverseScreenCTM_ = ctm.inverse(); + this.inverseScreenCTMDirty_ = false; + } + } + 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.inverseScreenCTMDirty_ = true; }; /**