Source: core/drawing/engine/engine.js

  1. /**
  2. * @fileoverview Namespace for the rendering engine. Also a
  3. * static class providing constants and static functions.
  4. */
  5. goog.provide('xrx.engine');
  6. goog.require('goog.userAgent');
  7. /**
  8. * Engine base class.
  9. * @constructor
  10. * @namespace xrx.engine
  11. * @memberof xrx
  12. */
  13. xrx.engine = function() {};
  14. /**
  15. * <a href="http://www.w3.org/TR/2014/CR-2dcontext-20140821/">The 2D Canvas rendering engine.</a>
  16. * @type {string}
  17. * @const
  18. */
  19. xrx.engine.CANVAS = 'canvas';
  20. /**
  21. * <a href="http://www.w3.org/TR/SVG/">The SVG rendering engine.</a>
  22. * @type {string}
  23. * @const
  24. */
  25. xrx.engine.SVG = 'svg';
  26. /**
  27. * <a href="http://www.w3.org/TR/NOTE-VML">The VML rendering engine.</a>
  28. * @type {string}
  29. * @const
  30. */
  31. xrx.engine.VML = 'vml';
  32. /**
  33. * Whether an eninge uses a DOM representation.
  34. * @param {(xrx.engine.CANVAS|xrx.engine.SVG|xrx.engine.VML)} engine The engine to test.
  35. * @return {boolean} Whether the engine uses a DOM representation.
  36. */
  37. xrx.engine.hasDom = function(engine) {
  38. return engine === xrx.engine.SVG || engine === xrx.engine.VML;
  39. };
  40. /**
  41. * Whether an engine is supported by the current browser.
  42. * @param {(xrx.engine.CANVAS|xrx.engine.SVG|xrx.engine.VML)} engine The engine to test.
  43. */
  44. xrx.engine.isSupported = function(engine) {
  45. if (engine === xrx.engine.CANVAS) {
  46. return !!document.createElement('canvas').getContext;
  47. } else if (engine === xrx.engine.SVG) {
  48. return !!document.createElementNS &&
  49. !!document.createElementNS(xrx.svg.Namespace['svg'], 'svg').createSVGRect;
  50. } else if (engine === xrx.engine.VML) {
  51. return !!document.namespaces;
  52. } else {
  53. throw Error('Unknown engine.');
  54. }
  55. };