From 46b1310743893b591ef04a407980361d62d9dab5 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Sat, 14 May 2016 03:44:37 -0700 Subject: [PATCH] Fix trashcan hotspot in RTL. --- core/trashcan.js | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/core/trashcan.js b/core/trashcan.js index 8d295f898..0a2954308 100644 --- a/core/trashcan.js +++ b/core/trashcan.js @@ -83,6 +83,20 @@ Blockly.Trashcan.prototype.MARGIN_SIDE_ = 20; */ Blockly.Trashcan.prototype.MARGIN_HOTSPOT_ = 10; +/** + * Location of trashcan in sprite image. + * @type {number} + * @private + */ +Blockly.Trashcan.prototype.SPRITE_LEFT_ = 0; + +/** + * Location of trashcan in sprite image. + * @type {number} + * @private + */ +Blockly.Trashcan.prototype.SPRITE_TOP_ = 32; + /** * Current open/close state of the lid. * @type {boolean} @@ -161,7 +175,8 @@ Blockly.Trashcan.prototype.createDom = function() { 'y': this.LID_HEIGHT_}, clip); var body = Blockly.createSvgElement('image', - {'width': Blockly.SPRITE.width, 'height': Blockly.SPRITE.height, 'y': -32, + {'width': Blockly.SPRITE.width, 'x': -this.SPRITE_LEFT_, + 'height': Blockly.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')'}, this.svgGroup_); body.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', @@ -173,7 +188,8 @@ Blockly.Trashcan.prototype.createDom = function() { Blockly.createSvgElement('rect', {'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip); this.svgLid_ = Blockly.createSvgElement('image', - {'width': Blockly.SPRITE.width, 'height': Blockly.SPRITE.height, 'y': -32, + {'width': Blockly.SPRITE.width, 'x': -this.SPRITE_LEFT_, + 'height': Blockly.SPRITE.height, 'y': -this.SPRITE_TOP_, 'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')'}, this.svgGroup_); this.svgLid_.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', @@ -250,10 +266,11 @@ Blockly.Trashcan.prototype.position = function() { */ Blockly.Trashcan.prototype.getClientRect = function() { var trashRect = this.svgGroup_.getBoundingClientRect(); - return new goog.math.Rect(trashRect.left - this.MARGIN_HOTSPOT_, - trashRect.top - this.MARGIN_HOTSPOT_, - trashRect.width + 2 * this.MARGIN_HOTSPOT_, - trashRect.height + 2 * this.MARGIN_HOTSPOT_); + var left = trashRect.left + this.SPRITE_LEFT_ - this.MARGIN_HOTSPOT_; + var top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_; + var width = this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_; + var height = this.LID_HEIGHT_ + this.BODY_HEIGHT_ + 2 * this.MARGIN_HOTSPOT_; + return new goog.math.Rect(left, top, width, height); };