[WIP] Fix headless loading of blocks

This commit is contained in:
Evan W. Patton
2016-11-08 12:29:59 -05:00
parent 189f87b32e
commit ac090cac09
6 changed files with 20 additions and 57 deletions

View File

@@ -263,49 +263,6 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) {
Blockly.Field.startCache();
this.rendered = true;
this.renderHere(opt_bubble);
// Render all blocks above this one (propagate a reflow).
var parentBlock = this.getParent();
if (parentBlock) {
parentBlock.render();
}
Blockly.Field.stopCache();
};
/**
* [lyn, 04/01/14] Render a tree of blocks.
* In general, this is more efficient than calling render() on all the leaves of the tree,
* because that will:
* (1) repeat the rendering of all internal nodes; and
* (2) will unnecessarily call Blockly.fireUiEvent(window, 'resize') in the
* case where the parentPointer hasn't been set yet (particularly for
* value, statement, and next connections in Xml.domToBlock).
* These two factors account for much of the slow project loading times in Blockly
* and previous versions of AI2.
*/
Blockly.BlockSvg.prototype.renderDown = function(opt_bubble) {
this.rendered = true;
// Recursively renderDown all my children (as long as I'm not collapsed)
if (! (Blockly.Instrument.avoidRenderDownOnCollapsedSubblocks && this.isCollapsed())) {
var childBlocks = this.childBlocks_;
for (var c = 0, childBlock; childBlock = childBlocks[c]; c++) {
childBlock.renderDown(opt_bubble);
}
}
// Render me after all my children have been rendered.
this.renderHere(opt_bubble);
};
/**
* Render this block. Assumes descendants have already been rendered.
*/
Blockly.BlockSvg.prototype.renderHere = function(opt_bubble) {
var start = new Date().getTime();
// Now render me (even if I am collapsed, since still need to show collapsed block)
var cursorX = Blockly.BlockSvg.SEP_SPACE_X;
if (this.RTL) {
cursorX = -cursorX;
@@ -325,16 +282,16 @@ Blockly.BlockSvg.prototype.renderHere = function(opt_bubble) {
this.renderMoveConnections_();
if (opt_bubble !== false) {
// Render all blocks above this one (propagate a reflow).
var parentBlock = this.getParent();
if (!parentBlock) {
if (parentBlock) {
parentBlock.render(true);
} else {
// Top-most block. Fire an event to allow scrollbars to resize.
this.workspace.resizeContents();
}
}
var stop = new Date().getTime();
var timeDiff = stop - start;
Blockly.Instrument.stats.renderHereCalls++;
Blockly.Instrument.stats.renderHereTime += timeDiff;
Blockly.Field.stopCache();
};
/**

View File

@@ -615,10 +615,14 @@ Blockly.BlockSvg.prototype.onMouseUp_ = function(e) {
} else if (!this.getParent() && Blockly.selected.isDeletable() &&
this.workspace.isDeleteArea(e)) {
var trashcan = this.workspace.trashcan;
if (trashcan) {
goog.Timer.callOnce(trashcan.close, 100, trashcan);
}
Blockly.selected.dispose(false, true);
Blockly.confirmDeletion(function(confirmedDelete) {
if (trashcan) {
goog.Timer.callOnce(trashcan.close, 100, trashcan);
}
if (confirmedDelete) {
Blockly.selected.dispose(false, true);
}
});
}
if (Blockly.highlightedConnection_) {
Blockly.highlightedConnection_.unhighlight();

View File

@@ -218,9 +218,6 @@ Blockly.Connection.prototype.connect_ = function(childConnection) {
}
}, Blockly.BUMP_DELAY);
}
if (block.errorIcon) {
block.errorIcon.setVisible(false);
}
}
// Restore the shadow DOM.
parentConnection.setShadowDom(shadowDom);

View File

@@ -50,7 +50,7 @@ Blockly.inject = function(container, opt_options) {
if (!goog.dom.contains(document, container)) {
throw 'Error: container is not in current document.';
}
var options = new Blockly.Options(opt_options || {});
var options = (Blockly.mainWorkspace && Blockly.mainWorkspace.options) || new Blockly.Options(opt_options || {});
var subContainer = goog.dom.createDom('div', 'injectionDiv');
container.appendChild(subContainer);
var svg = Blockly.createDom_(subContainer, options);
@@ -185,7 +185,7 @@ Blockly.createDom_ = function(container, options) {
*/
Blockly.createMainWorkspace_ = function(svg, options) {
options.parentWorkspace = null;
var mainWorkspace = new Blockly.WorkspaceSvg(options);
var mainWorkspace = Blockly.mainWorkspace || new Blockly.WorkspaceSvg(options);
mainWorkspace.scale = options.zoomOptions.startScale;
svg.appendChild(mainWorkspace.createDom('blocklyMainBackground'));
// A null translation will also apply the correct initial scale.

View File

@@ -287,6 +287,9 @@ Blockly.RenderedConnection.prototype.hideAll = function() {
for (var j = 0; j < icons.length; j++) {
icons[j].setVisible(false);
}
if (block.errorIcon) {
block.errorIcon.setVisible(false);
}
}
}
};

View File

@@ -417,10 +417,12 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
// Custom data for an advanced block.
if (block.domToMutation) {
block.domToMutation(xmlChild);
/* disabling due to this being _headless_
if (block.initSvg) {
// Mutation may have added some elements that need initalizing.
block.initSvg();
}
*/
}
break;
case 'comment':