B2G/gecko/browser/devtools/tilt/TiltUtils.jsm
/**
   * Traverses a document object model & calculates useful info for each node.
   *
   * @param {Window} aContentWindow
   *                 the window content holding the document
   * @param {Object} aProperties
   *                 optional, an object containing the following properties:
   *        {Object} invisibleElements
   *                 elements which should be ignored
   *        {Number} minSize
   *                 the minimum dimensions needed for a node to be traversed
   *        {Number} maxX
   *                 the maximum left position of an element
   *        {Number} maxY
   *                 the maximum top position of an element
   *
   * @return {Array} list containing nodes depths, coordinates and local names
   */
Traverses a document object model & calculates useful info for each node.
@param {Window} aContentWindow
the window content holding the document
@param {Object} aProperties
optional, an object containing the following properties:
{Object} invisibleElements
elements which should be ignored
{Number} minSize
the minimum dimensions needed for a node to be traversed
{Number} maxX
the maximum left position of an element
{Number} maxY
the maximum top position of an element

@return {Array} list containing nodes depths, coordinates and local names
Traverses a document object model & calculates useful info for each node . @param { Window } aContentWindow the window content holding the document @param { Object } aProperties optional an object containing the following properties : { Object } invisibleElements elements which should be ignored { Number } minSize the minimum dimensions needed for a node to be traversed { Number } maxX the maximum left position of an element { Number } maxY the maximum top position of an element @return { Array } list containing nodes depths coordinates and local names
function TUD_traverse(aContentWindow, aProperties)
  {
    aProperties = aProperties || {};
    let aInvisibleElements = aProperties.invisibleElements || {};
    let aMinSize = aProperties.minSize || -1;
    let aMaxX = aProperties.maxX || Number.MAX_VALUE;
    let aMaxY = aProperties.maxY || Number.MAX_VALUE;
    let nodes = aContentWindow.document.childNodes;
    let store = { info: [], nodes: [] };
    let depth = 0;
    while (nodes.length) {
      let queue = [];
      for (let i = 0, len = nodes.length; i < len; i++) {
        let node = nodes[i];
        let name = node.localName;
        if (!name || aInvisibleElements[name]) {
          continue;
        }
        let coord = LayoutHelpers.getRect(node, aContentWindow);
        if (!coord) {
          continue;
        }
        if (coord.left > aMaxX || coord.top > aMaxY) {
          continue;
        }
        if (coord.width > aMinSize && coord.height > aMinSize) {
          store.info.push({ depth: depth, coord: coord, name: name });
          store.nodes.push(node);
        }
        Array.prototype.push.apply(queue, name === "iframe" || name === "frame" ?
                                          node.contentDocument.childNodes :
                                          node.childNodes);
      }
      nodes = queue;
      depth++;
    }
    return store;
  }
function TUD_traverse ( aContentWindow , aProperties ) { aProperties = aProperties || { } ; let aInvisibleElements = aProperties . invisibleElements || { } ; let aMinSize = aProperties . minSize || - 1 ; let aMaxX = aProperties . maxX || Number . MAX_VALUE ; let aMaxY = aProperties . maxY || Number . MAX_VALUE ; let nodes = aContentWindow . document . childNodes ; let store = { info : [ ] , nodes : [ ] } ; let depth = 0 ; while ( nodes . length ) { let queue = [ ] ; for ( let i = 0 , len = nodes . length ; i < len ; i ++ ) { let node = nodes [ i ] ; let name = node . localName ; if ( ! name || aInvisibleElements [ name ] ) { continue ; } let coord = LayoutHelpers . getRect ( node , aContentWindow ) ; if ( ! coord ) { continue ; } if ( coord . left > aMaxX || coord . top > aMaxY ) { continue ; } if ( coord . width > aMinSize && coord . height > aMinSize ) { store . info . push ( { depth : depth , coord : coord , name : name } ) ; store . nodes . push ( node ) ; } Array . prototype . push . apply ( queue , name === "iframe" || name === "frame" ? node . contentDocument . childNodes : node . childNodes ) ; } nodes = queue ; depth ++ ; } return store ; }
Traverses a document object model & calculates useful info for each node.
Traverses a document object model & calculates useful info for each node .
// make sure the properties parameter is a valid object // skip some nodes to avoid visualization meshes that are too bloated // get the x, y, width and height coordinates of the node // the maximum size slices the traversal where needed // use this node only if it actually has visible dimensions // save the necessary details into a list to be returned later // prepare the queue array