B2G/gecko/browser/devtools/shared/LayoutHelpers.jsm
/**
   * Compute the absolute position and the dimensions of a node, relativalely
   * to the root window.
   *
   * @param nsIDOMNode aNode
   *        a DOM element to get the bounds for
   * @param nsIWindow aContentWindow
   *        the content window holding the node
   */
Compute the absolute position and the dimensions of a node, relativalely
to the root window.

@param nsIDOMNode aNode
a DOM element to get the bounds for
@param nsIWindow aContentWindow
the content window holding the node
Compute the absolute position and the dimensions of a node relativalely to the root window . @param nsIDOMNode aNode a DOM element to get the bounds for @param nsIWindow aContentWindow the content window holding the node
function LH_getRect(aNode, aContentWindow) {
    let frameWin = aNode.ownerDocument.defaultView;
    let clientRect = aNode.getBoundingClientRect();
    rect = {top: clientRect.top + aContentWindow.pageYOffset,
            left: clientRect.left + aContentWindow.pageXOffset,
            width: clientRect.width,
            height: clientRect.height};
    while (true) {
      if (frameWin.parent === frameWin || !frameWin.frameElement) {
        break;
      }
      let frameRect = frameWin.frameElement.getBoundingClientRect();
      let [offsetTop, offsetLeft] =
        this.getIframeContentOffset(frameWin.frameElement);
      rect.top += frameRect.top + offsetTop;
      rect.left += frameRect.left + offsetLeft;
      frameWin = frameWin.parent;
    }
    return rect;
  }
function LH_getRect ( aNode , aContentWindow ) { let frameWin = aNode . ownerDocument . defaultView ; let clientRect = aNode . getBoundingClientRect ( ) ; rect = { top : clientRect . top + aContentWindow . pageYOffset , left : clientRect . left + aContentWindow . pageXOffset , width : clientRect . width , height : clientRect . height } ; while ( true ) { if ( frameWin . parent === frameWin || ! frameWin . frameElement ) { break ; } let frameRect = frameWin . frameElement . getBoundingClientRect ( ) ; let [ offsetTop , offsetLeft ] = this . getIframeContentOffset ( frameWin . frameElement ) ; rect . top += frameRect . top + offsetTop ; rect . left += frameRect . left + offsetLeft ; frameWin = frameWin . parent ; } return rect ; }
Compute the absolute position and the dimensions of a node, relativalely
 to the root window.
Compute the absolute position and the dimensions of a node relativalely to the root window .
// Go up in the tree of frames to determine the correct rectangle. // clientRect is read-only, we need to be able to change properties. // We iterate through all the parent windows. // Are we in the top-level window? // We are in an iframe. // We take into account the parent iframe position and its // offset (borders and padding).