nsIFrame* child; if (NS_SUCCEEDED(parentFrame->FirstChild(mOuter->mPresContext, nsLayoutAtoms::fixedList, &child)) && child) {
if (parentFrame->GetFirstChild(nsLayoutAtoms::fixedList)) {
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;#ifdef IBMBIDI  const nsStyleVisibility* vis = mOuter->GetStyleVisibility();  //  // Direction Style from this->GetStyleData()  // now in (vis->mDirection)  // ------------------  // NS_STYLE_DIRECTION_LTR : LTR or Default  // NS_STYLE_DIRECTION_RTL  // NS_STYLE_DIRECTION_INHERIT  //  if (vis->mDirection == NS_STYLE_DIRECTION_RTL){    // if true places the vertical scrollbar on the right false puts it on the left.    scrollBarRight = PR_FALSE;    // if true places the horizontal scrollbar on the bottom false puts it on the top.    scrollBarBottom = PR_TRUE;  }  nsHTMLReflowState* reflowState = (nsHTMLReflowState*)aState.GetReflowState();#endif // IBMBIDI  nsIFrame* frame = nsnull;  mOuter->GetFrame(&frame);  // 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);  nsSize hMinSize(0,0);  nsSize vMinSize(0,0);  /*  mHScrollbarBox->GetPrefSize(aState, hSize);  mVScrollbarBox->GetPrefSize(aState, vSize);  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);  nsGfxScrollFrame::ScrollbarStyles styles = mOuter->GetScrollbarStyles();  // Look at our style do we always have vertical or horizontal scrollbars?  if (styles.mHorizontal == NS_STYLE_OVERFLOW_SCROLL)     mHasHorizontalScrollbar = PR_TRUE;  if (styles.mVertical == NS_STYLE_OVERFLOW_SCROLL)     mHasVerticalScrollbar = PR_TRUE;  if (mHasHorizontalScrollbar)     AddHorizontalScrollbar(aState, scrollAreaRect, scrollBarBottom);  if (mHasVerticalScrollbar)     AddVerticalScrollbar(aState, scrollAreaRect, scrollBarRight);       nsRect oldScrollAreaBounds;  mScrollAreaBox->GetClientRect(oldScrollAreaBounds);  // 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 (styles.mVertical != NS_STYLE_OVERFLOW_SCROLL) {      // get the area frame is the scrollarea      GetScrolledSize(aState.GetPresContext(),&scrolledContentSize.width, &scrolledContentSize.height);    // There are two cases to consider      if (scrolledContentSize.height <= scrollAreaRect.height          || styles.mVertical != NS_STYLE_OVERFLOW_AUTO) {        if (mHasVerticalScrollbar) {          // We left room for the vertical scrollbar, but it's not needed;          // remove it.          if (RemoveVerticalScrollbar(aState, scrollAreaRect, scrollBarRight)) {            needsLayout = PR_TRUE;            SetAttribute(mVScrollbarBox, nsXULAtoms::curpos, 0);          }        }      } else {        if (!mHasVerticalScrollbar) {          // We didn't leave room for the vertical scrollbar, but it turns          // out we needed it          if (AddVerticalScrollbar(aState, scrollAreaRect, scrollBarRight))            needsLayout = PR_TRUE;        }    }    // ok layout at the right size    if (needsLayout) {       nsBoxLayoutState resizeState(aState);       resizeState.SetLayoutReason(nsBoxLayoutState::Resize);       PRBool setBack;       AdjustReflowStateForPrintPreview(aState, setBack);       LayoutBox(resizeState, mScrollAreaBox, scrollAreaRect);       AdjustReflowStateBack(aState, setBack);       needsLayout = PR_FALSE;    }  }  // if scrollbars are auto look at the horizontal case  if (styles.mHorizontal != NS_STYLE_OVERFLOW_SCROLL)  {    // get the area frame is the scrollarea      GetScrolledSize(aState.GetPresContext(),&scrolledContentSize.width, &scrolledContentSize.height);    // if the child is wider that the scroll area    // and we don't have a scrollbar add one.    if (scrolledContentSize.width > scrollAreaRect.width        && styles.mHorizontal == NS_STYLE_OVERFLOW_AUTO) {      if (!mHasHorizontalScrollbar) {           // no scrollbar?           if (AddHorizontalScrollbar(aState, scrollAreaRect, scrollBarBottom))             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");                 }#ifdef IBMBIDI      const nsStyleVisibility* ourVis = frame->GetStyleVisibility();      if (NS_STYLE_DIRECTION_RTL == ourVis->mDirection) {        nsCOMPtr<nsITextControlFrame> textControl(          do_QueryInterface(mOuter->mParent) );        if (textControl) {          needsLayout = PR_TRUE;          reflowState->mRightEdge = scrolledContentSize.width;          mScrollAreaBox->MarkDirty(aState);        }      }#endif // IBMBIDI    } else {        // if the area is smaller or equal to and we have a scrollbar then        // remove it.      if (mHasHorizontalScrollbar) {          if (RemoveHorizontalScrollbar(aState, scrollAreaRect, scrollBarBottom))             needsLayout = PR_TRUE;             SetAttribute(mHScrollbarBox, nsXULAtoms::curpos, 0);      }    }  }  // we only need to set the rect. The inner child stays the same size.  if (needsLayout) {     nsBoxLayoutState resizeState(aState);     resizeState.SetLayoutReason(nsBoxLayoutState::Resize);     PRBool setBack;     AdjustReflowStateForPrintPreview(aState, setBack);     LayoutBox(resizeState, mScrollAreaBox, scrollAreaRect);      AdjustReflowStateBack(aState, setBack);     needsLayout = PR_FALSE;#ifdef IBMBIDI     reflowState->mRightEdge = NS_UNCONSTRAINEDSIZE;#endif // IBMBIDI  }      GetScrolledSize(aState.GetPresContext(),&scrolledContentSize.width, &scrolledContentSize.height);  nsIPresContext* presContext = aState.GetPresContext();  float p2t;  presContext->GetScaledPixelsToTwips(&p2t);  mOnePixel = NSIntPixelsToTwips(1, p2t);  const nsStyleFont* font = mOuter->GetStyleFont();  const nsFont& f = font->mFont;  nsCOMPtr<nsIFontMetrics> fm;  presContext->GetMetricsFor(f, getter_AddRefs(fm));  nscoord fontHeight = 1;  NS_ASSERTION(fm,"FontMetrics is null assuming fontHeight == 1");  if (fm)    fm->GetHeight(fontHeight);  nscoord maxX = scrolledContentSize.width - scrollAreaRect.width;  nscoord maxY = scrolledContentSize.height - scrollAreaRect.height;  nsIScrollableView* scrollable = GetScrollableView(presContext);  scrollable->SetLineHeight(fontHeight);  if (mHScrollbarBox)    mHScrollbarBox->GetPrefSize(aState, hSize);    if (mVScrollbarBox)    mVScrollbarBox->GetPrefSize(aState, vSize);  // layout vertical scrollbar  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 (mHasVerticalScrollbar && mVScrollbarBox) {    SetAttribute(mVScrollbarBox, nsXULAtoms::maxpos, maxY);    SetAttribute(mVScrollbarBox, nsXULAtoms::pageincrement, nscoord(scrollAreaRect.height - fontHeight));    SetAttribute(mVScrollbarBox, nsXULAtoms::increment, fontHeight);  }  if (mVScrollbarBox) {    LayoutBox(aState, mVScrollbarBox, vRect);    mVScrollbarBox->GetPrefSize(aState, vSize);    mVScrollbarBox->GetMinSize(aState, vMinSize);  }  if (mHasVerticalScrollbar && mVScrollbarBox && (vMinSize.width > vRect.width || vMinSize.height > vRect.height)) {    if (RemoveVerticalScrollbar(aState, scrollAreaRect, scrollBarRight)) {        needsLayout = PR_TRUE;        SetAttribute(mVScrollbarBox, nsXULAtoms::curpos, 0);    }    mVScrollbarBox->GetPrefSize(aState, vSize);  }  // layout horizontal scrollbar  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 (mHasHorizontalScrollbar && mHScrollbarBox) {    SetAttribute(mHScrollbarBox, nsXULAtoms::maxpos, maxX);    SetAttribute(mHScrollbarBox, nsXULAtoms::pageincrement, nscoord(float(scrollAreaRect.width)*0.8));    SetAttribute(mHScrollbarBox, nsXULAtoms::increment, 10*mOnePixel);  }   if (mHScrollbarBox) {    LayoutBox(aState, mHScrollbarBox, hRect);    mHScrollbarBox->GetMinSize(aState, hMinSize);  }  if (mHasHorizontalScrollbar && mHScrollbarBox && (hMinSize.width > hRect.width || hMinSize.height > hRect.height)) {    if (RemoveHorizontalScrollbar(aState, scrollAreaRect, scrollBarBottom)) {      needsLayout = PR_TRUE;      SetAttribute(mHScrollbarBox, nsXULAtoms::curpos, 0);    }  }   // 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);      needsLayout = PR_FALSE;  }  // place the scrollcorner  if (mScrollCornerBox) {    nsRect r(0, 0, 0, 0);    if (clientRect.x != scrollAreaRect.x) {      // scrollbar (if any) on left      r.x = clientRect.x;      r.width = scrollAreaRect.x - clientRect.x;      NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");    } else {      // scrollbar (if any) on right      r.x = scrollAreaRect.XMost();      r.width = clientRect.XMost() - scrollAreaRect.XMost();      NS_ASSERTION(r.width >= 0, "Scroll area should be inside client rect");    }    if (clientRect.y != scrollAreaRect.y) {      // scrollbar (if any) on top      r.y = clientRect.y;      r.height = scrollAreaRect.y - clientRect.y;      NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");    } else {      // scrollbar (if any) on bottom      r.y = scrollAreaRect.YMost();      r.height = clientRect.YMost() - scrollAreaRect.YMost();      NS_ASSERTION(r.height >= 0, "Scroll area should be inside client rect");    }    LayoutBox(aState, mScrollCornerBox, r);   }  // may need to update fixed position children of the viewport,  // if the client area changed size because of some dirty reflow  // (if the reflow is initial or resize, the fixed children will  // be re-laid out anyway)  if ((oldScrollAreaBounds.width != scrollAreaRect.width      || oldScrollAreaBounds.height != scrollAreaRect.height)      && nsBoxLayoutState::Dirty == aState.GetLayoutReason()) {    nsIFrame* parentFrame = mOuter->GetParent();    if (parentFrame) {      if (parentFrame->GetType() == nsLayoutAtoms::viewportFrame) {        // Usually there are no fixed children, so don't do anything unless there's        // at least one fixed child        nsIFrame* child;        if (NS_SUCCEEDED(parentFrame->FirstChild(mOuter->mPresContext,          nsLayoutAtoms::fixedList, &child)) && child) {          // force a reflow of the fixed children          nsFrame::CreateAndPostReflowCommand(mOuter->mPresContext->PresShell(),            parentFrame,            eReflowType_UserDefined, nsnull, nsnull, nsLayoutAtoms::fixedList);        }      }    }  }    return NS_OK;}