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