nsRect vRect(clientRect); vRect.width = vSize.width; vRect.y = clientRect.y;  if (mHasHorizontalScrollbar) { vRect.height -= hSize.height; if (!scrollBarBottom) vRect.y += hSize.height; }  vRect.x = clientRect.x;  if (scrollBarRight) vRect.x += clientRect.width - vSize.width;  if (vMinSize.width > vRect.width || vMinSize.height > vRect.height) { mVScrollbarBox->Collapse(aState); } else { SetAttribute(mVScrollbarBox, nsXULAtoms::maxpos, maxY); SetAttribute(mVScrollbarBox, nsXULAtoms::pageincrement, nscoord(scrollAreaRect.height - fontHeight)); SetAttribute(mVScrollbarBox, nsXULAtoms::increment, fontHeight, PR_FALSE);  LayoutBox(aState, mVScrollbarBox, vRect); } }
SetAttribute(mVScrollbarBox, nsXULAtoms::maxpos, maxY); SetAttribute(mVScrollbarBox, nsXULAtoms::pageincrement, nscoord(scrollAreaRect.height - fontHeight)); SetAttribute(mVScrollbarBox, nsXULAtoms::increment, fontHeight, PR_FALSE); }  LayoutBox(aState, mVScrollbarBox, vRect);  if (!mHasVerticalScrollbar || (vMinSize.width > vRect.width || vMinSize.height > vRect.height)) mVScrollbarBox->Collapse(aState);    nsRect hRect(clientRect); hRect.height = hSize.height;  hRect.x = clientRect.x;  if (mHasVerticalScrollbar) { hRect.width -= vSize.width; if (!scrollBarRight) hRect.x += vSize.width; }  hRect.y = clientRect.y;  if (scrollBarBottom) hRect.y += clientRect.height - hSize.height;
nsGfxScrollFrameInner::Layout(nsBoxLayoutState& aState){  //TODO make bidi code set these from preferences  // if true places the vertical scrollbar on the right false puts it on the left.  PRBool scrollBarRight = PR_TRUE;  // if true places the horizontal scrollbar on the bottom false puts it on the top.  PRBool scrollBarBottom = PR_TRUE;  nsIFrame* frame = nsnull;  mOuter->GetFrame(&frame);  const nsStyleDisplay* styleDisplay = nsnull;  frame->GetStyleData(eStyleStruct_Display,                      (const nsStyleStruct*&)styleDisplay);   // get the content rect  nsRect clientRect(0,0,0,0);  mOuter->GetClientRect(clientRect);  // get the preferred size of the scrollbars  nsSize hSize(0,0);  nsSize vSize(0,0);  mHScrollbarBox->GetPrefSize(aState, hSize);  mVScrollbarBox->GetPrefSize(aState, vSize);  nsSize hMinSize(0,0);  nsSize vMinSize(0,0);  mHScrollbarBox->GetMinSize(aState, hMinSize);  mVScrollbarBox->GetMinSize(aState, vMinSize);  nsBox::AddMargin(mHScrollbarBox, hSize);  nsBox::AddMargin(mVScrollbarBox, vSize);  nsBox::AddMargin(mHScrollbarBox, hMinSize);  nsBox::AddMargin(mVScrollbarBox, vMinSize);  // the scroll area size starts off as big as our content area  nsRect scrollAreaRect(clientRect);  nsSize sbSize(vSize.width, hSize.height);  // Look at our style do we always have vertical or horizontal scrollbars?  if (styleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLL || styleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL)     mHasHorizontalScrollbar = PR_TRUE;  if (styleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLL || styleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL)     mHasVerticalScrollbar = PR_TRUE;  // see if we currenly have a vertical or horizotal scrollbar and subtract them  // from the scroll area size.  if (mHasHorizontalScrollbar) {      if (scrollAreaRect.height - sbSize.height < 0)      {          mHasHorizontalScrollbar = PR_FALSE;          mHScrollbarBox->Collapse(aState);      } else {          scrollAreaRect.height -= sbSize.height;          if (!scrollBarBottom)             scrollAreaRect.y += sbSize.height;      }  }  if (mHasVerticalScrollbar) {      if (scrollAreaRect.width - sbSize.width < 0)      {          mHasVerticalScrollbar = PR_FALSE;          mVScrollbarBox->Collapse(aState);      } else {          scrollAreaRect.width -= sbSize.width;          if (!scrollBarRight)             scrollAreaRect.x += sbSize.width;      }  }  // layout our the scroll area  LayoutBox(aState, mScrollAreaBox, scrollAreaRect);    // now look at the content area and see if we need scrollbars or not  PRBool needsLayout = PR_FALSE;  nsSize scrolledContentSize(0,0);  // if we have 'auto' scrollbars look at the vertical case  if (styleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLL      && styleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL) {      // get the area frame is the scrollarea      GetScrolledContentSize(scrolledContentSize);    // There are two cases to consider      if (scrolledContentSize.height <= scrollAreaRect.height          || styleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL          || styleDisplay->mOverflow == NS_STYLE_OVERFLOW_SCROLLBARS_NONE) {        if (mHasVerticalScrollbar) {          // We left room for the vertical scrollbar, but it's not needed;          // remove it.          RemoveVerticalScrollbar(sbSize, scrollAreaRect, scrollBarRight);          needsLayout = PR_TRUE;          mVScrollbarBox->Collapse(aState);        }      } else {        if (!mHasVerticalScrollbar) {          // We didn't leave room for the vertical scrollbar, but it turns          // out we needed it          if (scrollAreaRect.width - sbSize.width >= 0) {            AddVerticalScrollbar(sbSize, scrollAreaRect, scrollBarRight);            mVScrollbarBox->UnCollapse(aState);            needsLayout = PR_TRUE;          }        }    }    // ok layout at the right size    if (needsLayout) {       nsBoxLayoutState resizeState(aState);       resizeState.SetLayoutReason(nsBoxLayoutState::Resize);       LayoutBox(resizeState, mScrollAreaBox, scrollAreaRect);    }  }  needsLayout = PR_FALSE;  // if scrollbars are auto look at the horizontal case  if ((NS_STYLE_OVERFLOW_SCROLL != styleDisplay->mOverflow)      && (NS_STYLE_OVERFLOW_SCROLLBARS_HORIZONTAL != styleDisplay->mOverflow))  {    // get the area frame is the scrollarea    GetScrolledContentSize(scrolledContentSize);    // if the child is wider that the scroll area    // and we don't have a scrollbar add one.    if (scrolledContentSize.width > scrollAreaRect.width        && styleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_VERTICAL        && styleDisplay->mOverflow != NS_STYLE_OVERFLOW_SCROLLBARS_NONE) {       if (!mHasHorizontalScrollbar) {           if (scrollAreaRect.height - sbSize.height >= 0) {             AddHorizontalScrollbar(sbSize, scrollAreaRect, scrollBarBottom);             mHScrollbarBox->UnCollapse(aState);             needsLayout = PR_TRUE;           }           // if we added a horizonal scrollbar and we did not have a vertical           // there is a chance that by adding the horizonal scrollbar we will           // suddenly need a vertical scrollbar. Is a special case but its            // important.           if (!mHasVerticalScrollbar && scrolledContentSize.height > scrollAreaRect.height - sbSize.height)             printf("****Gfx Scrollbar Special case hit!!*****\n");                 }    } else {        // if the area is smaller or equal to and we have a scrollbar then        // remove it.      if (mHasHorizontalScrollbar) {          RemoveHorizontalScrollbar(sbSize, scrollAreaRect, scrollBarBottom);          mHScrollbarBox->Collapse(aState);          needsLayout = PR_TRUE;      }    }  }  // we only need to set the rect. The inner child stays the same size.  if (needsLayout) {     nsBoxLayoutState resizeState(aState);     resizeState.SetLayoutReason(nsBoxLayoutState::Resize);     LayoutBox(resizeState, mScrollAreaBox, scrollAreaRect);   }      GetScrolledContentSize(scrolledContentSize);  nsIPresContext* presContext = aState.GetPresContext();  float p2t;  presContext->GetScaledPixelsToTwips(&p2t);  mOnePixel = NSIntPixelsToTwips(1, p2t);  const nsStyleFont* font;  mOuter->GetStyleData(eStyleStruct_Font, (const nsStyleStruct*&) font);  const nsFont& f = font->mFont;  nsCOMPtr<nsIFontMetrics> fm;  presContext->GetMetricsFor(f, getter_AddRefs(fm));  nscoord fontHeight = 1;  fm->GetHeight(fontHeight);  nscoord maxX = scrolledContentSize.width - scrollAreaRect.width;  nscoord maxY = scrolledContentSize.height - scrollAreaRect.height;  nsIScrollableView* scrollable = GetScrollableView(presContext);  scrollable->SetLineHeight(fontHeight);    // layout the vertical and horizontal scrollbars  // set the scrollbars properties. Mark the scrollbars for reflow if there values change.  if (mHasVerticalScrollbar) {      nsRect vRect(clientRect);      vRect.width = vSize.width;      vRect.y = clientRect.y;      if (mHasHorizontalScrollbar) {        vRect.height -= hSize.height;        if (!scrollBarBottom)            vRect.y += hSize.height;      }      vRect.x = clientRect.x;      if (scrollBarRight)         vRect.x += clientRect.width - vSize.width;      if (vMinSize.width > vRect.width || vMinSize.height > vRect.height) {        mVScrollbarBox->Collapse(aState);      } else {        SetAttribute(mVScrollbarBox, nsXULAtoms::maxpos, maxY);        SetAttribute(mVScrollbarBox, nsXULAtoms::pageincrement, nscoord(scrollAreaRect.height - fontHeight));        SetAttribute(mVScrollbarBox, nsXULAtoms::increment, fontHeight, PR_FALSE);        LayoutBox(aState, mVScrollbarBox, vRect);      }  }  if (mHasHorizontalScrollbar) {      nsRect hRect(clientRect);      hRect.height = hSize.height;      hRect.x = clientRect.x;      if (mHasVerticalScrollbar) {         hRect.width -= vSize.width;         if (!scrollBarRight)            hRect.x += vSize.width;      }      hRect.y = clientRect.y;      if (scrollBarBottom)         hRect.y += clientRect.height - hSize.height;      if (hMinSize.width > hRect.width || hMinSize.height > hRect.height) {        mHScrollbarBox->Collapse(aState);      } else {        SetAttribute(mHScrollbarBox, nsXULAtoms::maxpos, maxX);        SetAttribute(mHScrollbarBox, nsXULAtoms::pageincrement, nscoord(float(scrollAreaRect.width)*0.8));        SetAttribute(mHScrollbarBox, nsXULAtoms::increment, 10*mOnePixel, PR_FALSE);        LayoutBox(aState, mHScrollbarBox, hRect);      }  }       return NS_OK;}  