mirror of
https://github.com/google/blockly.git
synced 2026-01-14 12:27:10 +01:00
Merge pull request #1844 from gnarf/delay-ctm
Delay getting inverse screen CTM until needed
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user