B2G/gecko/browser/devtools/shared/LayoutHelpers.jsm
/**
   * Compute the position and the dimensions for the visible portion
   * of a node, relativalely to the root window.
   *
   * @param nsIDOMNode aNode
   *        a DOM element to be highlighted
   */
Compute the position and the dimensions for the visible portion
of a node, relativalely to the root window.

@param nsIDOMNode aNode
a DOM element to be highlighted
Compute the position and the dimensions for the visible portion of a node relativalely to the root window . @param nsIDOMNode aNode a DOM element to be highlighted
function LH_getDirectyRect(aNode) {
    let frameWin = aNode.ownerDocument.defaultView;
    let clientRect = aNode.getBoundingClientRect();
    rect = {top: clientRect.top,
            left: clientRect.left,
            width: clientRect.width,
            height: clientRect.height};
    while (true) {
      let diffx = frameWin.innerWidth - (rect.left + rect.width);
      if (diffx < 0) {
        rect.width += diffx;
      }
      let diffy = frameWin.innerHeight - (rect.top + rect.height);
      if (diffy < 0) {
        rect.height += diffy;
      }
      if (rect.left < 0) {
        rect.width += rect.left;
        rect.left = 0;
      }
      if (rect.top < 0) {
        rect.height += rect.top;
        rect.top = 0;
      }
      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_getDirectyRect ( aNode ) { let frameWin = aNode . ownerDocument . defaultView ; let clientRect = aNode . getBoundingClientRect ( ) ; rect = { top : clientRect . top , left : clientRect . left , width : clientRect . width , height : clientRect . height } ; while ( true ) { let diffx = frameWin . innerWidth - ( rect . left + rect . width ) ; if ( diffx < 0 ) { rect . width += diffx ; } let diffy = frameWin . innerHeight - ( rect . top + rect . height ) ; if ( diffy < 0 ) { rect . height += diffy ; } if ( rect . left < 0 ) { rect . width += rect . left ; rect . left = 0 ; } if ( rect . top < 0 ) { rect . height += rect . top ; rect . top = 0 ; } 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 position and the dimensions for the visible portion
 of a node, relativalely to the root window.
Compute the position and the dimensions for the visible portion 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. // Does the selection overflow on the right of its window? // Does the selection overflow on the bottom of its window? // Does the selection overflow on the left of its window? // Does the selection overflow on the top of its window? // Selection has been clipped to fit in its own window. // 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).