From 554fe18ab9d5a9381651957da6967462cf97c9c3 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 4 May 2016 14:49:00 -0700 Subject: [PATCH] Use direct call to comment's resize rather than event. --- core/bubble.js | 17 ++++++++++++----- core/comment.js | 41 +++++++++++++++++++++++------------------ core/toolbox.js | 4 ++-- core/workspace_svg.js | 2 +- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/core/bubble.js b/core/bubble.js index 379b9b1b..d4c1e271 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -123,6 +123,12 @@ Blockly.Bubble.onMouseUpWrapper_ = null; */ Blockly.Bubble.onMouseMoveWrapper_ = null; +/** + * Function to call on resize of bubble. + * @type {Function} + */ +Blockly.Bubble.prototype.resizeCallback_ = null; + /** * Stop binding to the global mouseup and mousemove events. * @private @@ -336,11 +342,10 @@ Blockly.Bubble.prototype.resizeMouseMove_ = function(e) { /** * Register a function as a callback event for when the bubble is resized. - * @param {Object} thisObject The value of 'this' in the callback. * @param {!Function} callback The function to call on resize. */ -Blockly.Bubble.prototype.registerResizeEvent = function(thisObject, callback) { - Blockly.bindEvent_(this.bubbleGroup_, 'resize', thisObject, callback); +Blockly.Bubble.prototype.registerResizeEvent = function(callback) { + this.resizeCallback_ = callback; }; /** @@ -467,8 +472,10 @@ Blockly.Bubble.prototype.setBubbleSize = function(width, height) { this.positionBubble_(); this.renderArrow_(); } - // Fire an event to allow the contents to resize. - Blockly.fireUiEvent(this.bubbleGroup_, 'resize'); + // Allow the contents to resize. + if (this.resizeCallback_) { + this.resizeCallback_(); + } }; /** diff --git a/core/comment.js b/core/comment.js index d1e4363b..2121530c 100644 --- a/core/comment.js +++ b/core/comment.js @@ -106,24 +106,27 @@ Blockly.Comment.prototype.createEditor_ = function() { var body = document.createElementNS(Blockly.HTML_NS, 'body'); body.setAttribute('xmlns', Blockly.HTML_NS); body.className = 'blocklyMinimalBody'; - this.textarea_ = document.createElementNS(Blockly.HTML_NS, 'textarea'); - this.textarea_.className = 'blocklyCommentTextarea'; - this.textarea_.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); - body.appendChild(this.textarea_); + var textarea = document.createElementNS(Blockly.HTML_NS, 'textarea'); + textarea.className = 'blocklyCommentTextarea'; + textarea.setAttribute('dir', this.block_.RTL ? 'RTL' : 'LTR'); + body.appendChild(textarea); + this.textarea_ = textarea; this.foreignObject_.appendChild(body); - Blockly.bindEvent_(this.textarea_, 'mouseup', this, this.textareaFocus_); + Blockly.bindEvent_(textarea, 'mouseup', this, this.textareaFocus_); // Don't zoom with mousewheel. - Blockly.bindEvent_(this.textarea_, 'wheel', this, function(e) { + Blockly.bindEvent_(textarea, 'wheel', this, function(e) { e.stopPropagation(); }); - Blockly.bindEvent_(this.textarea_, 'change', this, function(e) { - if (this.text_ != this.textarea_.value) { + Blockly.bindEvent_(textarea, 'change', this, function(e) { + if (this.text_ != textarea.value) { Blockly.Events.fire(new Blockly.Events.Change( - this.block_, 'comment', null, this.text_, this.textarea_.value)); - this.text_ = this.textarea_.value; + this.block_, 'comment', null, this.text_, textarea.value)); + this.text_ = textarea.value; } }); - + setTimeout(function() { + textarea.focus(); + }, 0); return this.foreignObject_; }; @@ -147,12 +150,14 @@ Blockly.Comment.prototype.updateEditable = function() { * @private */ Blockly.Comment.prototype.resizeBubble_ = function() { - var size = this.bubble_.getBubbleSize(); - var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; - this.foreignObject_.setAttribute('width', size.width - doubleBorderWidth); - this.foreignObject_.setAttribute('height', size.height - doubleBorderWidth); - this.textarea_.style.width = (size.width - doubleBorderWidth - 4) + 'px'; - this.textarea_.style.height = (size.height - doubleBorderWidth - 4) + 'px'; + if (this.isVisible()) { + var size = this.bubble_.getBubbleSize(); + var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH; + this.foreignObject_.setAttribute('width', size.width - doubleBorderWidth); + this.foreignObject_.setAttribute('height', size.height - doubleBorderWidth); + this.textarea_.style.width = (size.width - doubleBorderWidth - 4) + 'px'; + this.textarea_.style.height = (size.height - doubleBorderWidth - 4) + 'px'; + } }; /** @@ -183,7 +188,7 @@ Blockly.Comment.prototype.setVisible = function(visible) { /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), this.createEditor_(), this.block_.svgPath_, this.iconXY_, this.width_, this.height_); - this.bubble_.registerResizeEvent(this, this.resizeBubble_); + this.bubble_.registerResizeEvent(this.resizeBubble_.bind(this)); this.updateColour(); } else { // Dispose of the bubble. diff --git a/core/toolbox.js b/core/toolbox.js index 3951c107..8435ec5c 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -102,7 +102,7 @@ Blockly.Toolbox.prototype.init = function() { this.HtmlDiv.setAttribute('dir', workspace.RTL ? 'RTL' : 'LTR'); document.body.appendChild(this.HtmlDiv); - // Clicking on toolbar closes popups. + // Clicking on toolbox closes popups. Blockly.bindEvent_(this.HtmlDiv, 'mousedown', this, function(e) { if (Blockly.isRightButton(e) || e.target == this.HtmlDiv) { @@ -305,7 +305,7 @@ Blockly.Toolbox.prototype.clearSelection = function() { }; /** - * Return the deletion rectangle for this toolbar. + * Return the deletion rectangle for this toolbox. * @return {goog.math.Rect} Rectangle in which to delete. */ Blockly.Toolbox.prototype.getClientRect = function() { diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 2d562fd2..b44df8d4 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -532,7 +532,7 @@ Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() { }; /** - * Is the mouse event over a delete area (toolbar or non-closing flyout)? + * Is the mouse event over a delete area (toolbox or non-closing flyout)? * Opens or closes the trashcan and sets the cursor as a side effect. * @param {!Event} e Mouse move event. * @return {boolean} True if event is in a delete area.