Source: core/drawing/engine/svg/svgCanvas.js

  1. /**
  2. * @fileoverview SVG rendering class representing a canvas.
  3. * @private
  4. */
  5. goog.provide('xrx.svg.Canvas');
  6. goog.require('goog.dom.DomHelper');
  7. goog.require('goog.style');
  8. goog.require('xrx.svg.Namespace');
  9. goog.require('xrx.svg.Container');
  10. /**
  11. * SVG rendering class representing a canvas.
  12. * @param {SVGElement} element The SVG element.
  13. * @constructor
  14. * @extends xrx.svg.Element
  15. * @private
  16. */
  17. xrx.svg.Canvas = function(element) {
  18. goog.base(this, element);
  19. /**
  20. * The canvas width.
  21. * @type {number}
  22. */
  23. this.width_ = 0;
  24. /**
  25. * The canvas height.
  26. * @type {number}
  27. */
  28. this.height_ = 0;
  29. };
  30. goog.inherits(xrx.svg.Canvas, xrx.svg.Container);
  31. /**
  32. * Returns the root element of this canvas to be used as
  33. * the event target.
  34. * @return {SVGElement} The event target element.
  35. */
  36. xrx.svg.Canvas.prototype.getEventTarget = function() {
  37. return this.element_;
  38. };
  39. /**
  40. * Returns the width of the canvas.
  41. * @return {number} The width.
  42. */
  43. xrx.svg.Canvas.prototype.getWidth = function() {
  44. return this.width_;
  45. };
  46. /**
  47. * Sets the width of the canvas.
  48. * @param {number} width the width.
  49. */
  50. xrx.svg.Canvas.prototype.setWidth = function(width) {
  51. this.width_ = width;
  52. this.element_.setAttribute('width', width);
  53. };
  54. /**
  55. * Returns the height of the canvas.
  56. * @return {number} The height.
  57. */
  58. xrx.svg.Canvas.prototype.getHeight = function() {
  59. return this.height_;
  60. };
  61. /**
  62. * Sets the height of the canvas.
  63. * @param {number} width the height.
  64. */
  65. xrx.svg.Canvas.prototype.setHeight = function(height) {
  66. this.height_ = height;
  67. this.element_.setAttribute('height', height);
  68. };
  69. xrx.svg.Canvas.prototype.startDrawing = function() {
  70. };
  71. xrx.svg.Canvas.prototype.finishDrawing = function() {
  72. };
  73. /**
  74. * Creates a new canvas.
  75. * @param {HTMLElement} parent The parent HTML element to which the canvas
  76. * shall be appended.
  77. */
  78. xrx.svg.Canvas.create = function(parent) {
  79. var element = document.createElementNS(xrx.svg.Namespace['svg'], 'svg');
  80. goog.style.setStyle(element, 'overflow', 'hidden');
  81. return new xrx.svg.Canvas(element);
  82. };
  83. xrx.svg.Canvas.prototype.disposeInternal = function() {
  84. goog.base(this, 'disposeInternal');
  85. };