Change the blockly workspace resizing strategy. (#386)

* Add a new method to be called when the contents of the workspace change and
the scrollbars need to be adjusted but the the chrome (trash, toolbox, etc)
are expected to stay in the same place.

Change a bunch of calls to svgResize to either be removed or call the new
method instead.  This is a nice performance win since the offsetHeight/Width
call in svgResize can be expensive, especially when called as often as we do -
there was some layout thrashing.

This also paves the way for moving calls to recordDeleteAreas
(which is also expensive) to a more cacheable spot than on every
mouse down/touch event.

of things (namely the scrollbars)

* Fix size of graph demo when it first loads by calling svgResize.
The graph starts with fixed width and was relying on a resize event
to fire (which I believe was removed in commit
217c681b86).

* Fix the resizing of the code demo.  The demo's tab min-width used to
match the toolbox's width was only being set on a resize event, but
commit 217c681b86 changed how that worked.

* Fix up some comments.

* Use specific workspaces rather than Blockly.getMainWorkspace().

* Make workspace required for resizeSvgContents and update
some calls to send real workspaces rather than ones that are
null.

Remove the private tag on terminateDrag_ because it is only
actually called from outside the BlockSvg object.

* Remove a rogue period.

* Recategorize BlockSvg.terminateDrag_ to @package instead of @private so that
other developers don't use it, but it still can be used by other Blockly classes.

* Add a TODO to fix issue #307.

* Add @package to workspace resizeContents.
This commit is contained in:
picklesrus
2016-06-03 16:11:55 -07:00
parent bfa842c9a8
commit 213469a479
10 changed files with 60 additions and 44 deletions

View File

@@ -141,36 +141,24 @@ Blockly.svgSize = function(svg) {
};
/**
* Schedule a call to the resize handler. Groups of simultaneous events (e.g.
* a tree of blocks being deleted) are merged into one call.
* @param {Blockly.WorkspaceSvg} workspace Any workspace in the SVG.
* Size the workspace when the contents change. This also updates
* scrollbars accordingly.
* @param {!Blockly.WorkspaceSvg} workspace The workspace to resize.
*/
Blockly.asyncSvgResize = function(workspace) {
if (Blockly.svgResizePending_) {
return;
}
if (!workspace) {
workspace = Blockly.getMainWorkspace();
}
Blockly.svgResizePending_ = true;
setTimeout(function() {Blockly.svgResize(workspace);}, 0);
Blockly.resizeSvgContents = function(workspace) {
workspace.resizeContents();
};
/**
* Flag indicating a resize event is scheduled.
* Used to fire only one resize after multiple changes.
* @type {boolean}
* @private
*/
Blockly.svgResizePending_ = false;
/**
* Size the SVG image to completely fill its container.
* Size the SVG image to completely fill its container. Call this when the view
* actually changes sizes (e.g. on a window resize/device orientation change).
* See Blockly.resizeSvgContents to resize the workspace when the contents
* change (e.g. when a block is added or removed).
* Record the height/width of the SVG image.
* @param {!Blockly.WorkspaceSvg} workspace Any workspace in the SVG.
*/
Blockly.svgResize = function(workspace) {
Blockly.svgResizePending_ = false;
var mainWorkspace = workspace;
while (mainWorkspace.options.parentWorkspace) {
mainWorkspace = mainWorkspace.options.parentWorkspace;
@@ -316,7 +304,7 @@ Blockly.onKeyDown_ = function(e) {
* @private
*/
Blockly.terminateDrag_ = function() {
Blockly.BlockSvg.terminateDrag_();
Blockly.BlockSvg.terminateDrag();
Blockly.Flyout.terminateDrag_();
};