Commit ede63636 authored by Neil Fraser's avatar Neil Fraser

Simplify workspace resizing.

parent 89d1aafd
This diff is collapsed.
......@@ -264,10 +264,7 @@ Blockly.svgResize = function(workspace) {
svg.setAttribute('height', height + 'px');
svg.cachedHeight_ = height;
}
// Update the scrollbars (if they exist).
if (mainWorkspace.scrollbar) {
mainWorkspace.scrollbar.resize();
}
mainWorkspace.resize();
};
/**
......
......@@ -138,10 +138,6 @@ Blockly.Flyout.prototype.init = function(workspace) {
this.hide();
// If the document resizes, reposition the flyout.
this.eventWrappers_.concat(Blockly.bindEvent_(window,
goog.events.EventType.RESIZE, this, this.position_));
this.position_();
this.eventWrappers_.concat(Blockly.bindEvent_(this.svgGroup_,
'wheel', this, this.wheel_));
// Safari needs mousewheel.
......@@ -234,9 +230,8 @@ Blockly.Flyout.prototype.setMetrics_ = function(yRatio) {
/**
* Move the toolbox to the edge of the workspace.
* @private
*/
Blockly.Flyout.prototype.position_ = function() {
Blockly.Flyout.prototype.position = function() {
if (!this.isVisible()) {
return;
}
......@@ -489,7 +484,7 @@ Blockly.Flyout.prototype.reflow = function() {
block.flyoutRect_.setAttribute('y', blockXY.y);
}
}
// Record the width for .getMetrics_ and .position_.
// Record the width for .getMetrics_ and .position.
this.width_ = flyoutWidth;
// Fire a resize event to update the flyout's scrollbar.
Blockly.fireUiEvent(window, 'resize');
......
......@@ -285,11 +285,13 @@ Blockly.createDom_ = function(container, options) {
<rect width="1" height="1" stroke="#888" />
</pattern>
*/
// MSIE freaks if it sees a 0x0 pattern, so set empty patterns to 100x100.
var safeSpacing = options.gridOptions['spacing'] || 100;
var gridPattern = Blockly.createSvgElement('pattern',
{'id': 'blocklyGridPattern' + String(Math.random()).substring(2),
'patternUnits': 'userSpaceOnUse',
'width': options.gridOptions['spacing'] || 100,
'height': options.gridOptions['spacing'] || 100}, defs);
'width': safeSpacing,
'height': safeSpacing}, defs);
if (options.gridOptions['length'] > 0 && options.gridOptions['spacing'] > 0) {
var half = Math.floor(options.gridOptions['spacing'] / 2) + .5;
var start = half - options.gridOptions['length'] / 2;
......
......@@ -138,21 +138,19 @@ Blockly.Toolbox.prototype.init = function() {
this.HtmlDiv.style.display = 'block';
this.populate_(workspace.options.languageTree);
tree.render(this.HtmlDiv);
// If the document resizes, reposition the toolbox.
var thisToolbox = this;
goog.events.listen(window, goog.events.EventType.RESIZE,
function() {thisToolbox.position_();});
this.position_();
this.position();
};
/**
* Move the toolbox to the edge.
* @private
*/
Blockly.Toolbox.prototype.position_ = function() {
var svg = this.workspace_.options.svg;
Blockly.Toolbox.prototype.position = function() {
var treeDiv = this.HtmlDiv;
if (!treeDiv) {
// Not initialized yet.
return;
}
var svg = this.workspace_.options.svg;
var svgBox = goog.style.getBorderBox(svg);
var svgSize = Blockly.svgSize(svg);
if (this.workspace_.RTL) {
......@@ -167,6 +165,7 @@ Blockly.Toolbox.prototype.position_ = function() {
// For some reason the LTR toolbox now reports as 1px too wide.
this.width -= 1;
}
this.flyout_.position();
};
/**
......
......@@ -201,8 +201,6 @@ Blockly.Trashcan.prototype.createDom = function() {
*/
Blockly.Trashcan.prototype.init = function() {
this.setOpen_(false);
// If the document resizes, reposition the trash can.
Blockly.bindEvent_(window, 'resize', this, this.position_);
};
/**
......@@ -221,9 +219,8 @@ Blockly.Trashcan.prototype.dispose = function() {
/**
* Move the trash can to the bottom-right corner.
* @private
*/
Blockly.Trashcan.prototype.position_ = function() {
Blockly.Trashcan.prototype.position = function() {
var metrics = this.workspace_.getMetrics();
if (!metrics) {
// There are no metrics available (workspace is probably not visible).
......@@ -242,7 +239,7 @@ Blockly.Trashcan.prototype.position_ = function() {
};
/**
* Return the deletion rectangle for this trashcan.
* Return the deletion rectangle for this trash can.
* @return {goog.math.Rect} Rectangle in which to delete.
*/
Blockly.Trashcan.prototype.getRect = function() {
......
......@@ -198,6 +198,24 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function() {
this.svgGroup_.insertBefore(svgFlyout, this.svgBlockCanvas_);
};
/**
* Resize this workspace and its containing objects.
*/
Blockly.WorkspaceSvg.prototype.resize = function() {
if (this.toolbox_) {
this.toolbox_.position();
}
if (this.flyout_) {
this.flyout_.position();
}
if (this.trashcan) {
this.trashcan.position();
}
if (this.scrollbar) {
this.scrollbar.resize();
}
};
/**
* Get the SVG element that forms the drawing surface.
* @return {!Element} SVG element.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment