bubble.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /**
  2. * @license
  3. * Visual Blocks Editor
  4. *
  5. * Copyright 2012 Google Inc.
  6. * https://developers.google.com/blockly/
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * @fileoverview Object representing a UI bubble.
  22. * @author fraser@google.com (Neil Fraser)
  23. */
  24. 'use strict';
  25. goog.provide('Blockly.Bubble');
  26. goog.require('Blockly.Touch');
  27. goog.require('Blockly.Workspace');
  28. goog.require('goog.dom');
  29. goog.require('goog.math');
  30. goog.require('goog.math.Coordinate');
  31. goog.require('goog.userAgent');
  32. /**
  33. * Class for UI bubble.
  34. * @param {!Blockly.WorkspaceSvg} workspace The workspace on which to draw the
  35. * bubble.
  36. * @param {!Element} content SVG content for the bubble.
  37. * @param {Element} shape SVG element to avoid eclipsing.
  38. * @param {!goog.math.Coodinate} anchorXY Absolute position of bubble's anchor
  39. * point.
  40. * @param {?number} bubbleWidth Width of bubble, or null if not resizable.
  41. * @param {?number} bubbleHeight Height of bubble, or null if not resizable.
  42. * @constructor
  43. */
  44. Blockly.Bubble = function(workspace, content, shape, anchorXY,
  45. bubbleWidth, bubbleHeight) {
  46. this.workspace_ = workspace;
  47. this.content_ = content;
  48. this.shape_ = shape;
  49. var angle = Blockly.Bubble.ARROW_ANGLE;
  50. if (this.workspace_.RTL) {
  51. angle = -angle;
  52. }
  53. this.arrow_radians_ = goog.math.toRadians(angle);
  54. var canvas = workspace.getBubbleCanvas();
  55. canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight)));
  56. this.setAnchorLocation(anchorXY);
  57. if (!bubbleWidth || !bubbleHeight) {
  58. var bBox = /** @type {SVGLocatable} */ (this.content_).getBBox();
  59. bubbleWidth = bBox.width + 2 * Blockly.Bubble.BORDER_WIDTH;
  60. bubbleHeight = bBox.height + 2 * Blockly.Bubble.BORDER_WIDTH;
  61. }
  62. this.setBubbleSize(bubbleWidth, bubbleHeight);
  63. // Render the bubble.
  64. this.positionBubble_();
  65. this.renderArrow_();
  66. this.rendered_ = true;
  67. if (!workspace.options.readOnly) {
  68. Blockly.bindEventWithChecks_(this.bubbleBack_, 'mousedown', this,
  69. this.bubbleMouseDown_);
  70. if (this.resizeGroup_) {
  71. Blockly.bindEventWithChecks_(this.resizeGroup_, 'mousedown', this,
  72. this.resizeMouseDown_);
  73. }
  74. }
  75. };
  76. /**
  77. * Width of the border around the bubble.
  78. */
  79. Blockly.Bubble.BORDER_WIDTH = 6;
  80. /**
  81. * Determines the thickness of the base of the arrow in relation to the size
  82. * of the bubble. Higher numbers result in thinner arrows.
  83. */
  84. Blockly.Bubble.ARROW_THICKNESS = 5;
  85. /**
  86. * The number of degrees that the arrow bends counter-clockwise.
  87. */
  88. Blockly.Bubble.ARROW_ANGLE = 20;
  89. /**
  90. * The sharpness of the arrow's bend. Higher numbers result in smoother arrows.
  91. */
  92. Blockly.Bubble.ARROW_BEND = 4;
  93. /**
  94. * Distance between arrow point and anchor point.
  95. */
  96. Blockly.Bubble.ANCHOR_RADIUS = 8;
  97. /**
  98. * Wrapper function called when a mouseUp occurs during a drag operation.
  99. * @type {Array.<!Array>}
  100. * @private
  101. */
  102. Blockly.Bubble.onMouseUpWrapper_ = null;
  103. /**
  104. * Wrapper function called when a mouseMove occurs during a drag operation.
  105. * @type {Array.<!Array>}
  106. * @private
  107. */
  108. Blockly.Bubble.onMouseMoveWrapper_ = null;
  109. /**
  110. * Function to call on resize of bubble.
  111. * @type {Function}
  112. */
  113. Blockly.Bubble.prototype.resizeCallback_ = null;
  114. /**
  115. * Stop binding to the global mouseup and mousemove events.
  116. * @private
  117. */
  118. Blockly.Bubble.unbindDragEvents_ = function() {
  119. if (Blockly.Bubble.onMouseUpWrapper_) {
  120. Blockly.unbindEvent_(Blockly.Bubble.onMouseUpWrapper_);
  121. Blockly.Bubble.onMouseUpWrapper_ = null;
  122. }
  123. if (Blockly.Bubble.onMouseMoveWrapper_) {
  124. Blockly.unbindEvent_(Blockly.Bubble.onMouseMoveWrapper_);
  125. Blockly.Bubble.onMouseMoveWrapper_ = null;
  126. }
  127. };
  128. /*
  129. * Handle a mouse-up event while dragging a bubble's border or resize handle.
  130. * @param {!Event} e Mouse up event.
  131. * @private
  132. */
  133. Blockly.Bubble.bubbleMouseUp_ = function(/*e*/) {
  134. Blockly.Touch.clearTouchIdentifier();
  135. Blockly.Css.setCursor(Blockly.Css.Cursor.OPEN);
  136. Blockly.Bubble.unbindDragEvents_();
  137. };
  138. /**
  139. * Flag to stop incremental rendering during construction.
  140. * @private
  141. */
  142. Blockly.Bubble.prototype.rendered_ = false;
  143. /**
  144. * Absolute coordinate of anchor point.
  145. * @type {goog.math.Coordinate}
  146. * @private
  147. */
  148. Blockly.Bubble.prototype.anchorXY_ = null;
  149. /**
  150. * Relative X coordinate of bubble with respect to the anchor's centre.
  151. * In RTL mode the initial value is negated.
  152. * @private
  153. */
  154. Blockly.Bubble.prototype.relativeLeft_ = 0;
  155. /**
  156. * Relative Y coordinate of bubble with respect to the anchor's centre.
  157. * @private
  158. */
  159. Blockly.Bubble.prototype.relativeTop_ = 0;
  160. /**
  161. * Width of bubble.
  162. * @private
  163. */
  164. Blockly.Bubble.prototype.width_ = 0;
  165. /**
  166. * Height of bubble.
  167. * @private
  168. */
  169. Blockly.Bubble.prototype.height_ = 0;
  170. /**
  171. * Automatically position and reposition the bubble.
  172. * @private
  173. */
  174. Blockly.Bubble.prototype.autoLayout_ = true;
  175. /**
  176. * Create the bubble's DOM.
  177. * @param {!Element} content SVG content for the bubble.
  178. * @param {boolean} hasResize Add diagonal resize gripper if true.
  179. * @return {!Element} The bubble's SVG group.
  180. * @private
  181. */
  182. Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
  183. /* Create the bubble. Here's the markup that will be generated:
  184. <g>
  185. <g filter="url(#blocklyEmbossFilter837493)">
  186. <path d="... Z" />
  187. <rect class="blocklyDraggable" rx="8" ry="8" width="180" height="180"/>
  188. </g>
  189. <g transform="translate(165, 165)" class="blocklyResizeSE">
  190. <polygon points="0,15 15,15 15,0"/>
  191. <line class="blocklyResizeLine" x1="5" y1="14" x2="14" y2="5"/>
  192. <line class="blocklyResizeLine" x1="10" y1="14" x2="14" y2="10"/>
  193. </g>
  194. [...content goes here...]
  195. </g>
  196. */
  197. this.bubbleGroup_ = Blockly.createSvgElement('g', {}, null);
  198. var filter =
  199. {'filter': 'url(#' + this.workspace_.options.embossFilterId + ')'};
  200. if (goog.userAgent.getUserAgentString().indexOf('JavaFX') != -1) {
  201. // Multiple reports that JavaFX can't handle filters. UserAgent:
  202. // Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.44
  203. // (KHTML, like Gecko) JavaFX/8.0 Safari/537.44
  204. // https://github.com/google/blockly/issues/99
  205. filter = {};
  206. }
  207. var bubbleEmboss = Blockly.createSvgElement('g',
  208. filter, this.bubbleGroup_);
  209. this.bubbleArrow_ = Blockly.createSvgElement('path', {}, bubbleEmboss);
  210. this.bubbleBack_ = Blockly.createSvgElement('rect',
  211. {'class': 'blocklyDraggable', 'x': 0, 'y': 0,
  212. 'rx': Blockly.Bubble.BORDER_WIDTH, 'ry': Blockly.Bubble.BORDER_WIDTH},
  213. bubbleEmboss);
  214. if (hasResize) {
  215. this.resizeGroup_ = Blockly.createSvgElement('g',
  216. {'class': this.workspace_.RTL ?
  217. 'blocklyResizeSW' : 'blocklyResizeSE'},
  218. this.bubbleGroup_);
  219. var resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH;
  220. Blockly.createSvgElement('polygon',
  221. {'points': '0,x x,x x,0'.replace(/x/g, resizeSize.toString())},
  222. this.resizeGroup_);
  223. Blockly.createSvgElement('line',
  224. {'class': 'blocklyResizeLine',
  225. 'x1': resizeSize / 3, 'y1': resizeSize - 1,
  226. 'x2': resizeSize - 1, 'y2': resizeSize / 3}, this.resizeGroup_);
  227. Blockly.createSvgElement('line',
  228. {'class': 'blocklyResizeLine',
  229. 'x1': resizeSize * 2 / 3, 'y1': resizeSize - 1,
  230. 'x2': resizeSize - 1, 'y2': resizeSize * 2 / 3}, this.resizeGroup_);
  231. } else {
  232. this.resizeGroup_ = null;
  233. }
  234. this.bubbleGroup_.appendChild(content);
  235. return this.bubbleGroup_;
  236. };
  237. /**
  238. * Handle a mouse-down on bubble's border.
  239. * @param {!Event} e Mouse down event.
  240. * @private
  241. */
  242. Blockly.Bubble.prototype.bubbleMouseDown_ = function(e) {
  243. this.promote_();
  244. Blockly.Bubble.unbindDragEvents_();
  245. if (Blockly.isRightButton(e)) {
  246. // No right-click.
  247. e.stopPropagation();
  248. return;
  249. } else if (Blockly.isTargetInput_(e)) {
  250. // When focused on an HTML text input widget, don't trap any events.
  251. return;
  252. }
  253. // Left-click (or middle click)
  254. Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
  255. this.workspace_.startDrag(e, new goog.math.Coordinate(
  256. this.workspace_.RTL ? -this.relativeLeft_ : this.relativeLeft_,
  257. this.relativeTop_));
  258. Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEventWithChecks_(document,
  259. 'mouseup', this, Blockly.Bubble.bubbleMouseUp_);
  260. Blockly.Bubble.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_(document,
  261. 'mousemove', this, this.bubbleMouseMove_);
  262. Blockly.hideChaff();
  263. // This event has been handled. No need to bubble up to the document.
  264. e.stopPropagation();
  265. };
  266. /**
  267. * Drag this bubble to follow the mouse.
  268. * @param {!Event} e Mouse move event.
  269. * @private
  270. */
  271. Blockly.Bubble.prototype.bubbleMouseMove_ = function(e) {
  272. this.autoLayout_ = false;
  273. var newXY = this.workspace_.moveDrag(e);
  274. this.relativeLeft_ = this.workspace_.RTL ? -newXY.x : newXY.x;
  275. this.relativeTop_ = newXY.y;
  276. this.positionBubble_();
  277. this.renderArrow_();
  278. };
  279. /**
  280. * Handle a mouse-down on bubble's resize corner.
  281. * @param {!Event} e Mouse down event.
  282. * @private
  283. */
  284. Blockly.Bubble.prototype.resizeMouseDown_ = function(e) {
  285. this.promote_();
  286. Blockly.Bubble.unbindDragEvents_();
  287. if (Blockly.isRightButton(e)) {
  288. // No right-click.
  289. e.stopPropagation();
  290. return;
  291. }
  292. // Left-click (or middle click)
  293. Blockly.Css.setCursor(Blockly.Css.Cursor.CLOSED);
  294. this.workspace_.startDrag(e, new goog.math.Coordinate(
  295. this.workspace_.RTL ? -this.width_ : this.width_, this.height_));
  296. Blockly.Bubble.onMouseUpWrapper_ = Blockly.bindEventWithChecks_(document,
  297. 'mouseup', this, Blockly.Bubble.bubbleMouseUp_);
  298. Blockly.Bubble.onMouseMoveWrapper_ = Blockly.bindEventWithChecks_(document,
  299. 'mousemove', this, this.resizeMouseMove_);
  300. Blockly.hideChaff();
  301. // This event has been handled. No need to bubble up to the document.
  302. e.stopPropagation();
  303. };
  304. /**
  305. * Resize this bubble to follow the mouse.
  306. * @param {!Event} e Mouse move event.
  307. * @private
  308. */
  309. Blockly.Bubble.prototype.resizeMouseMove_ = function(e) {
  310. this.autoLayout_ = false;
  311. var newXY = this.workspace_.moveDrag(e);
  312. this.setBubbleSize(this.workspace_.RTL ? -newXY.x : newXY.x, newXY.y);
  313. if (this.workspace_.RTL) {
  314. // RTL requires the bubble to move its left edge.
  315. this.positionBubble_();
  316. }
  317. };
  318. /**
  319. * Register a function as a callback event for when the bubble is resized.
  320. * @param {!Function} callback The function to call on resize.
  321. */
  322. Blockly.Bubble.prototype.registerResizeEvent = function(callback) {
  323. this.resizeCallback_ = callback;
  324. };
  325. /**
  326. * Move this bubble to the top of the stack.
  327. * @private
  328. */
  329. Blockly.Bubble.prototype.promote_ = function() {
  330. var svgGroup = this.bubbleGroup_.parentNode;
  331. svgGroup.appendChild(this.bubbleGroup_);
  332. };
  333. /**
  334. * Notification that the anchor has moved.
  335. * Update the arrow and bubble accordingly.
  336. * @param {!goog.math.Coordinate} xy Absolute location.
  337. */
  338. Blockly.Bubble.prototype.setAnchorLocation = function(xy) {
  339. this.anchorXY_ = xy;
  340. if (this.rendered_) {
  341. this.positionBubble_();
  342. }
  343. };
  344. /**
  345. * Position the bubble so that it does not fall off-screen.
  346. * @private
  347. */
  348. Blockly.Bubble.prototype.layoutBubble_ = function() {
  349. // Compute the preferred bubble location.
  350. var relativeLeft = -this.width_ / 4;
  351. var relativeTop = -this.height_ - Blockly.BlockSvg.MIN_BLOCK_Y;
  352. // Prevent the bubble from being off-screen.
  353. var metrics = this.workspace_.getMetrics();
  354. metrics.viewWidth /= this.workspace_.scale;
  355. metrics.viewLeft /= this.workspace_.scale;
  356. var anchorX = this.anchorXY_.x;
  357. if (this.workspace_.RTL) {
  358. if (anchorX - metrics.viewLeft - relativeLeft - this.width_ <
  359. Blockly.Scrollbar.scrollbarThickness) {
  360. // Slide the bubble right until it is onscreen.
  361. relativeLeft = anchorX - metrics.viewLeft - this.width_ -
  362. Blockly.Scrollbar.scrollbarThickness;
  363. } else if (anchorX - metrics.viewLeft - relativeLeft >
  364. metrics.viewWidth) {
  365. // Slide the bubble left until it is onscreen.
  366. relativeLeft = anchorX - metrics.viewLeft - metrics.viewWidth;
  367. }
  368. } else {
  369. if (anchorX + relativeLeft < metrics.viewLeft) {
  370. // Slide the bubble right until it is onscreen.
  371. relativeLeft = metrics.viewLeft - anchorX;
  372. } else if (metrics.viewLeft + metrics.viewWidth <
  373. anchorX + relativeLeft + this.width_ +
  374. Blockly.BlockSvg.SEP_SPACE_X +
  375. Blockly.Scrollbar.scrollbarThickness) {
  376. // Slide the bubble left until it is onscreen.
  377. relativeLeft = metrics.viewLeft + metrics.viewWidth - anchorX -
  378. this.width_ - Blockly.Scrollbar.scrollbarThickness;
  379. }
  380. }
  381. if (this.anchorXY_.y + relativeTop < metrics.viewTop) {
  382. // Slide the bubble below the block.
  383. var bBox = /** @type {SVGLocatable} */ (this.shape_).getBBox();
  384. relativeTop = bBox.height;
  385. }
  386. this.relativeLeft_ = relativeLeft;
  387. this.relativeTop_ = relativeTop;
  388. };
  389. /**
  390. * Move the bubble to a location relative to the anchor's centre.
  391. * @private
  392. */
  393. Blockly.Bubble.prototype.positionBubble_ = function() {
  394. var left = this.anchorXY_.x;
  395. if (this.workspace_.RTL) {
  396. left -= this.relativeLeft_ + this.width_;
  397. } else {
  398. left += this.relativeLeft_;
  399. }
  400. var top = this.relativeTop_ + this.anchorXY_.y;
  401. this.bubbleGroup_.setAttribute('transform',
  402. 'translate(' + left + ',' + top + ')');
  403. };
  404. /**
  405. * Get the dimensions of this bubble.
  406. * @return {!Object} Object with width and height properties.
  407. */
  408. Blockly.Bubble.prototype.getBubbleSize = function() {
  409. return {width: this.width_, height: this.height_};
  410. };
  411. /**
  412. * Size this bubble.
  413. * @param {number} width Width of the bubble.
  414. * @param {number} height Height of the bubble.
  415. */
  416. Blockly.Bubble.prototype.setBubbleSize = function(width, height) {
  417. var doubleBorderWidth = 2 * Blockly.Bubble.BORDER_WIDTH;
  418. // Minimum size of a bubble.
  419. width = Math.max(width, doubleBorderWidth + 45);
  420. height = Math.max(height, doubleBorderWidth + 20);
  421. this.width_ = width;
  422. this.height_ = height;
  423. this.bubbleBack_.setAttribute('width', width);
  424. this.bubbleBack_.setAttribute('height', height);
  425. if (this.resizeGroup_) {
  426. if (this.workspace_.RTL) {
  427. // Mirror the resize group.
  428. var resizeSize = 2 * Blockly.Bubble.BORDER_WIDTH;
  429. this.resizeGroup_.setAttribute('transform', 'translate(' +
  430. resizeSize + ',' + (height - doubleBorderWidth) + ') scale(-1 1)');
  431. } else {
  432. this.resizeGroup_.setAttribute('transform', 'translate(' +
  433. (width - doubleBorderWidth) + ',' +
  434. (height - doubleBorderWidth) + ')');
  435. }
  436. }
  437. if (this.rendered_) {
  438. if (this.autoLayout_) {
  439. this.layoutBubble_();
  440. }
  441. this.positionBubble_();
  442. this.renderArrow_();
  443. }
  444. // Allow the contents to resize.
  445. if (this.resizeCallback_) {
  446. this.resizeCallback_();
  447. }
  448. };
  449. /**
  450. * Draw the arrow between the bubble and the origin.
  451. * @private
  452. */
  453. Blockly.Bubble.prototype.renderArrow_ = function() {
  454. var steps = [];
  455. // Find the relative coordinates of the center of the bubble.
  456. var relBubbleX = this.width_ / 2;
  457. var relBubbleY = this.height_ / 2;
  458. // Find the relative coordinates of the center of the anchor.
  459. var relAnchorX = -this.relativeLeft_;
  460. var relAnchorY = -this.relativeTop_;
  461. if (relBubbleX == relAnchorX && relBubbleY == relAnchorY) {
  462. // Null case. Bubble is directly on top of the anchor.
  463. // Short circuit this rather than wade through divide by zeros.
  464. steps.push('M ' + relBubbleX + ',' + relBubbleY);
  465. } else {
  466. // Compute the angle of the arrow's line.
  467. var rise = relAnchorY - relBubbleY;
  468. var run = relAnchorX - relBubbleX;
  469. if (this.workspace_.RTL) {
  470. run *= -1;
  471. }
  472. var hypotenuse = Math.sqrt(rise * rise + run * run);
  473. var angle = Math.acos(run / hypotenuse);
  474. if (rise < 0) {
  475. angle = 2 * Math.PI - angle;
  476. }
  477. // Compute a line perpendicular to the arrow.
  478. var rightAngle = angle + Math.PI / 2;
  479. if (rightAngle > Math.PI * 2) {
  480. rightAngle -= Math.PI * 2;
  481. }
  482. var rightRise = Math.sin(rightAngle);
  483. var rightRun = Math.cos(rightAngle);
  484. // Calculate the thickness of the base of the arrow.
  485. var bubbleSize = this.getBubbleSize();
  486. var thickness = (bubbleSize.width + bubbleSize.height) /
  487. Blockly.Bubble.ARROW_THICKNESS;
  488. thickness = Math.min(thickness, bubbleSize.width, bubbleSize.height) / 4;
  489. // Back the tip of the arrow off of the anchor.
  490. var backoffRatio = 1 - Blockly.Bubble.ANCHOR_RADIUS / hypotenuse;
  491. relAnchorX = relBubbleX + backoffRatio * run;
  492. relAnchorY = relBubbleY + backoffRatio * rise;
  493. // Coordinates for the base of the arrow.
  494. var baseX1 = relBubbleX + thickness * rightRun;
  495. var baseY1 = relBubbleY + thickness * rightRise;
  496. var baseX2 = relBubbleX - thickness * rightRun;
  497. var baseY2 = relBubbleY - thickness * rightRise;
  498. // Distortion to curve the arrow.
  499. var swirlAngle = angle + this.arrow_radians_;
  500. if (swirlAngle > Math.PI * 2) {
  501. swirlAngle -= Math.PI * 2;
  502. }
  503. var swirlRise = Math.sin(swirlAngle) *
  504. hypotenuse / Blockly.Bubble.ARROW_BEND;
  505. var swirlRun = Math.cos(swirlAngle) *
  506. hypotenuse / Blockly.Bubble.ARROW_BEND;
  507. steps.push('M' + baseX1 + ',' + baseY1);
  508. steps.push('C' + (baseX1 + swirlRun) + ',' + (baseY1 + swirlRise) +
  509. ' ' + relAnchorX + ',' + relAnchorY +
  510. ' ' + relAnchorX + ',' + relAnchorY);
  511. steps.push('C' + relAnchorX + ',' + relAnchorY +
  512. ' ' + (baseX2 + swirlRun) + ',' + (baseY2 + swirlRise) +
  513. ' ' + baseX2 + ',' + baseY2);
  514. }
  515. steps.push('z');
  516. this.bubbleArrow_.setAttribute('d', steps.join(' '));
  517. };
  518. /**
  519. * Change the colour of a bubble.
  520. * @param {string} hexColour Hex code of colour.
  521. */
  522. Blockly.Bubble.prototype.setColour = function(hexColour) {
  523. this.bubbleBack_.setAttribute('fill', hexColour);
  524. this.bubbleArrow_.setAttribute('fill', hexColour);
  525. };
  526. /**
  527. * Dispose of this bubble.
  528. */
  529. Blockly.Bubble.prototype.dispose = function() {
  530. Blockly.Bubble.unbindDragEvents_();
  531. // Dispose of and unlink the bubble.
  532. goog.dom.removeNode(this.bubbleGroup_);
  533. this.bubbleGroup_ = null;
  534. this.bubbleArrow_ = null;
  535. this.bubbleBack_ = null;
  536. this.resizeGroup_ = null;
  537. this.workspace_ = null;
  538. this.content_ = null;
  539. this.shape_ = null;
  540. };