B2G/gecko/browser/devtools/tilt/TiltUtils.jsm
/**
   * Helper method, allowing to easily create and manage a canvas element.
   * If the width and height params are falsy, they default to the parent node
   * client width and height.
   *
   * @param {Document} aParentNode
   *                   the parent node used to create the canvas
   *                   if not specified, it will be reused from the cache
   * @param {Object} aProperties
   *                 optional, object containing some of the following props:
   *       {Boolean} focusable
   *                 optional, true to make the canvas focusable
   *       {Boolean} append
   *                 optional, true to append the canvas to the parent node
   *        {Number} width
   *                 optional, specifies the width of the canvas
   *        {Number} height
   *                 optional, specifies the height of the canvas
   *        {String} id
   *                 optional, id for the created canvas element
   *
   * @return {HTMLCanvasElement} the newly created canvas element
   */
Helper method, allowing to easily create and manage a canvas element.
If the width and height params are falsy, they default to the parent node
client width and height.



@return {HTMLCanvasElement} the newly created canvas element
Helper method allowing to easily create and manage a canvas element . If the width and height params are falsy they default to the parent node client width and height . @return { HTMLCanvasElement } the newly created canvas element
function TUD_initCanvas(aParentNode, aProperties)
  {
    if (!(aParentNode = aParentNode || this.parentNode)) {
      return null;
    }
    aProperties = aProperties || {};
    this.parentNode = aParentNode;
    let canvas = aParentNode.ownerDocument.
      createElementNS("http://www.w3.org/1999/xhtml", "canvas");
    let width = aProperties.width || aParentNode.clientWidth;
    let height = aProperties.height || aParentNode.clientHeight;
    let id = aProperties.id || null;
    canvas.setAttribute("style", "min-width: 1px; min-height: 1px;");
    canvas.setAttribute("width", width);
    canvas.setAttribute("height", height);
    canvas.setAttribute("id", id);
    if (aProperties.focusable) {
      canvas.setAttribute("tabindex", "1");
      canvas.style.outline = "none";
    }
    if (aProperties.append) {
      aParentNode.appendChild(canvas);
    }
    return canvas;
  }
function TUD_initCanvas ( aParentNode , aProperties ) { if ( ! ( aParentNode = aParentNode || this . parentNode ) ) { return null ; } aProperties = aProperties || { } ; this . parentNode = aParentNode ; let canvas = aParentNode . ownerDocument . createElementNS ( "http://www.w3.org/1999/xhtml" , "canvas" ) ; let width = aProperties . width || aParentNode . clientWidth ; let height = aProperties . height || aParentNode . clientHeight ; let id = aProperties . id || null ; canvas . setAttribute ( "style" , "min-width: 1px; min-height: 1px;" ) ; canvas . setAttribute ( "width" , width ) ; canvas . setAttribute ( "height" , height ) ; canvas . setAttribute ( "id" , id ) ; if ( aProperties . focusable ) { canvas . setAttribute ( "tabindex" , "1" ) ; canvas . style . outline = "none" ; } if ( aProperties . append ) { aParentNode . appendChild ( canvas ) ; } return canvas ; }
Helper method, allowing to easily create and manage a canvas element.
Helper method allowing to easily create and manage a canvas element .
// check to see if the parent node element is valid // make sure the properties parameter is a valid object // cache this parent node so that it can be reused // create the canvas element // the canvas is unfocusable by default, we may require otherwise // append the canvas element to the current parent node, if specified