function _sizeWin()

in trinidad-impl/src/main/javascript/META-INF/adf/jsLibs/Window.js [541:705]


function _sizeWin(
  theWindow,
  extraWidth,
  extraHeight,
  params
  )
{
  var isGecko    = _agent.isGecko;
  var isIE       = _agent.isIE;
  var isSafari   = _agent.isSafari;
  var isStandard = (isGecko || isSafari);

  if (!(isStandard || (isIE && _agent.isWindows)))
    return;

  /*
  // =-= bts theoretically, this would be all we need to do for Mozilla,
  //         but the implementation appears to be sub-optimal for our case
  if (isGecko)
  {
    theWindow.sizeToContent();
    return;
  }
  */
  var body =  theWindow.document.body;

  if (body)
  {
    // width of the inside
    var newWidth = (!isIE && (body.scrollWidth > body.clientWidth))
                     ? body.scrollWidth
                     : _getBodyWidth(body, body.offsetWidth, body.offsetLeft);
    var newHeight = 0;

    var hasWidthParam = params && (params['W'] && params['W'] > 0);
    var hasHeightParam = params && (params['H'] && params['H'] > 0);
    
    //if the width and height of the window is provided as parameter, use it directly.
    if (hasWidthParam && hasHeightParam)
      return;
    
    var hasParams = (hasHeightParam  || hasWidthParam);
    
    // if the height was not explicitly set, change to auto forcing
    // recalculation of  the offsetHeight.  FireFox doesn't always detect
    // that a PPR has changed the content size.
    var bodyStyle = body.style;
    if (!hasParams && (!bodyStyle.height || bodyStyle.height.length == 0))
    {
      bodyStyle.height = "auto";
    }

    if (isStandard)
    {
      newHeight = body.offsetHeight + (window.outerHeight - window.innerHeight);

      // random extra space added in to make this work
      newHeight += 30;

      // add in the window frame plus padding
      // =-=AEW For some bizarre reason, I'm seeing cases
      // where the window's outerWidth is much, much smaller than
      // the body's offsetWidth, which results in the Gecko
      // window shrinking.  Block this, though it'd be nice
      // to know what's really going on!
      if (window.outerWidth > body.offsetWidth)
        newWidth  += (window.outerWidth - body.offsetWidth);
    }
    else
    {
      newHeight = body.scrollHeight + (body.offsetHeight - body.clientHeight);
      // if this method supported windows with toolbars, we would need to
      // add another 67 here, rather than the aribitrary 8 pixels
      newHeight += 21;

      // add in the padding plus bogus extra size
      newWidth += body.offsetWidth - body.clientWidth + 16;
      // add in the margins (MS bogusly uses Strings for these)

      if(body.tagName=='BODY')
      {
        newHeight += parseInt(body.topMargin) + parseInt(body.bottomMargin);
        newWidth  += parseInt(body.leftMargin) + parseInt(body.rightMargin);
      }
    }
    //
    // allow the size to be a little bigger than currently necessary.
    // This is useful when we will be paging through multiple items and
    // later pages  might need a slightly larger window than the initial
    // page.
    if (extraWidth)
      newWidth += extraWidth;

    if (extraHeight)
      newHeight += extraHeight;

    // Make sure that width and height are at least as big as minimum requested
    if (params != (void 0))
    {
      if (params['W'])
      {
        var minWidth = 0 + params['W'];
        if (newWidth < minWidth)
          newWidth = minWidth;
      }

      if (params['H'])
      {
        var minHeight = 0 + params['H'];
        if (newHeight < minHeight)
          newHeight = minHeight;
      }
    }

    var newWin = _getTop(theWindow);

    // keep a bottom/right pad of at least 5% of the available screen
    var avLeft = isIE ? 0 : newWin.screen.availLeft;
    var avTop = isIE ? 0 : newWin.screen.availTop;
    var maxSHeight = newWin.screen.availHeight * 0.95;
    var maxSWidth = newWin.screen.availWidth * 0.95;
    // adjust if necessary
    if (newHeight > maxSHeight)
      newHeight = maxSHeight;
    if (newWidth > maxSWidth)
      newWidth = maxSWidth;

    // Finally, we can resize the window.
    // theWindow.parent.resizeTo(newWidth, newHeight);
    try
    {
      newWin.resizeTo(newWidth, newHeight);
    }
    catch (e)
    {
      // ignore errors. An error will be throw if the new window opened in a tab
      // instead of a new browser window as resizing the main window is prohibited by security
      ;
    }

    // Check to make sure that our resize hasn't put the
    // window partially off screen.
    var wLeft = isIE ? newWin.screenLeft: newWin.screenX;
    var wTop = isIE ? newWin.screenTop: newWin.screenY;
    var moveit = false;

    // If we are off screen horizontal or vertical, center in that direction
    if ((wLeft + newWidth) > (avLeft + maxSWidth))
    {
      wLeft = (newWin.screen.availWidth - newWidth)/2;
      moveit = true;
    }

    if ((wTop + newHeight) > (avTop + maxSHeight))
    {
      wTop = (newWin.screen.availHeight - newHeight)/2;
      moveit = true;
    }

    if (moveit)
    {
      newWin.moveTo(wLeft, wTop);
    }
  }
}